34#include <unordered_map>
59 if (size_ + count > storage_.size()) storage_.resize(size_ + count);
60 T* at = storage_.data() + size_;
65 std::size_t
size()
const {
return size_; }
66 const T*
data()
const {
return storage_.data(); }
67 const T&
operator[](std::size_t index)
const {
return storage_[index]; }
70 std::size_t
capacity()
const {
return storage_.capacity(); }
73 std::vector<T> storage_;
74 std::size_t size_ = 0;
90 virtual void emit(
const float* positions,
const float* uvs,
int vertexCount,
91 const std::uint16_t* indices,
int indexCount,
92 std::uint32_t texture,
int blendMode,
const float rgba[4]) = 0;
117 MeshBatch&
open(std::uint32_t texture,
int blendMode,
bool premultipliedColor =
false) {
118 if (active_ == slots_.size()) slots_.emplace_back();
131 std::size_t
size()
const {
return active_; }
140 total.
slots = slots_.size();
143 total.
indices += slot.indices.capacity();
149 std::vector<MeshBatch> slots_;
150 std::size_t active_ = 0;
168 void emit(
const float* positions,
const float* uvs,
int vertexCount,
169 const std::uint16_t* indices,
int indexCount,
170 std::uint32_t texture,
int blendMode,
const float rgba[4])
override {
171 if (vertexCount <= 0 || indexCount <= 0)
return;
173 MeshBatch& batch = batchFor(texture, blendMode, vertexCount);
178 for (
int i = 0; i < vertexCount; ++i, vertex +=
VERTEX_FLOATS) {
179 vertex[0] = positions[i * 2];
180 vertex[1] = positions[i * 2 + 1];
181 vertex[2] = uvs[i * 2];
182 vertex[3] = uvs[i * 2 + 1];
189 std::uint16_t* index = batch.
indices.
append(
static_cast<std::size_t
>(indexCount));
190 for (
int i = 0; i < indexCount; ++i) {
191 index[i] =
static_cast<std::uint16_t
>(base + indices[i]);
196 MeshBatch& batchFor(std::uint32_t texture,
int blendMode,
int incomingVertices) {
197 if (batches_.
size() > 0) {
199 const bool sameState = texture == open.
texture && blendMode == open.
blendMode
204 if (sameState && fits)
return open;
206 return batches_.
open(texture, blendMode, premultipliedColor_);
210 bool premultipliedColor_ =
false;
224 const int id = next_++;
225 items_.emplace(
id, std::move(value));
230 auto it = items_.find(
id);
231 return it == items_.end() ?
nullptr : &it->second;
234 bool erase(
int id) {
return items_.erase(
id) > 0; }
238 template <
class Pred>
240 for (
auto it = items_.begin(); it != items_.end();) {
241 it = pred(it->second) ? items_.erase(it) : std::next(it);
248 std::unordered_map<int, T> items_;
261 buffer_ = text ? text :
"";
262 return buffer_.c_str();
269 for (
int i = 0; i < count; ++i) {
270 if (i > 0) buffer_ +=
',';
271 const char* name = nameAt(i);
273 buffer_ += name ? name :
"";
277 return buffer_.c_str();
282 std::string&
raw() {
return buffer_; }
318 values_.push_back(floatValue);
324 int count()
const {
return count_; }
325 const float*
values()
const {
return values_.data(); }
328 std::size_t
byteLength()
const {
return values_.size() *
sizeof(float); }
330 return index >= 0 && index < count_ ? &strings_[static_cast<std::size_t>(index)] :
nullptr;
334 void pushBits(
int value) {
336 std::memcpy(&bits, &value,
sizeof(bits));
337 values_.push_back(bits);
340 std::vector<float> values_;
341 std::vector<EventStrings> strings_;
void setPremultipliedColor(bool value) override
BatchCollector(BatchList &into)
void emit(const float *positions, const float *uvs, int vertexCount, const std::uint16_t *indices, int indexCount, std::uint32_t texture, int blendMode, const float rgba[4]) override
MeshBatch & open(std::uint32_t texture, int blendMode, bool premultipliedColor=false)
const MeshBatch & operator[](std::size_t index) const
const MeshBatch * begin() const
Capacity capacity() const
MeshBatch & back()
The batch still open — meaningful only while size() is nonzero.
const MeshBatch * end() const
T * append(std::size_t count)
Room for count more, to write through. The next append invalidates it.
std::size_t capacity() const
What it can take before it allocates again.
const T & operator[](std::size_t index) const
static constexpr int MAX_PER_UPDATE
void push(int kind, int track, float floatValue, int intValue, EventStrings strings)
std::size_t byteLength() const
const float * values() const
const EventStrings * strings(int index) const
const char * publishArray(int count, Fn nameAt)
["a","b"] from an indexed getter — how name lists cross the boundary.
const char * publish(const char *text)
constexpr int VERTEX_FLOATS
Interleaved x,y,u,v,r,g,b,a per vertex — the layout the SDK reads back.
constexpr std::size_t MAX_BATCH_VERTICES
16-bit indices, so a batch closes before one would wrap.
What the list can take before it allocates again.
The strings one queued event borrowed from its runtime's own data.
const char * animationName
One draw's worth of geometry.
Buffer< std::uint16_t > indices
Where a runtime pours the triangles it posed.
virtual void emit(const float *positions, const float *uvs, int vertexCount, const std::uint16_t *indices, int indexCount, std::uint32_t texture, int blendMode, const float rgba[4])=0
virtual ~TriangleSink()=default
virtual void setPremultipliedColor(bool)