Rise
The Vieneo Province
Loading...
Searching...
No Matches
ShipDrawBatch.h
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3#include <cstring>
4#include <limits>
5
7{
8 unsigned last = 0, primitives = 0;
9};
10
11// Re-evaluate every frame: independently moving parts separate as soon as
12// their transforms differ. No component state or triangle order is changed.
13template<class Component> ShipDrawBatch FindShipDrawBatch(const Component* components, unsigned count, unsigned first)
14{
15 const auto& initial = components[first];
16 ShipDrawBatch result{first, initial.primitives};
17 if (!initial.visible || !initial.primitives) return result;
18 for (unsigned next = first + 1; next < count; ++next)
19 {
20 const auto& candidate = components[next];
21 if (!candidate.visible || !candidate.primitives || candidate.type != initial.type ||
22 candidate.texture != initial.texture || candidate.useLightMap != initial.useLightMap ||
23 std::memcmp(&candidate.speedRetract, &initial.speedRetract, sizeof(initial.speedRetract)) ||
24 std::memcmp(&candidate.matWorld, &initial.matWorld, sizeof(initial.matWorld)) ||
25 uint64_t(initial.startvertex) + uint64_t(result.primitives) * 3 != candidate.startvertex ||
26 uint64_t(result.primitives) + candidate.primitives > (std::numeric_limits<unsigned>::max)())
27 break;
28 result.last = next;
29 result.primitives += candidate.primitives;
30 }
31 return result;
32}
ShipDrawBatch FindShipDrawBatch(const Component *components, unsigned count, unsigned first)
unsigned primitives
unsigned last