9#include "net/wire/bit_stream.h"
11namespace Vkm::Engine {
49 NetSchema() =
default;
50 ~NetSchema() =
default;
52 NetSchema(
const NetSchema& other) =
delete;
53 NetSchema& operator=(
const NetSchema& other) =
delete;
55 NetSchema(NetSchema && other) =
delete;
56 NetSchema& operator=(NetSchema && other) =
delete;
60 static NetSchema&
get();
76 const std::vector<NetType>&
types()
const {
return m_types; }
78 size_t size()
const {
return m_types.size(); }
120 std::vector<NetType> m_types;
126 type.
name = std::move(name);
131 netEncode(scene.
get<T>(entity), writer);
135 T* held = scene.
tryGet<T>(entity);
136 if (!held) held = &scene.
add<T>(entity, T{});
137 netDecode(*held, reader);
138 return !reader.failed();
141 add(std::move(type));
Reads back what a BitWriter wrote, in the same order.
Definition bit_stream.h:145
Packs values to the bit into a byte buffer.
Definition bit_stream.h:19
static NetSchema & get()
The registry every end consults. Filled by ScriptModule::setupNetwork, read thereafter.
void clear()
Drops everything.
Definition schema.h:114
static constexpr size_t MAX_TYPES
Most component types one game may replicate.
Definition schema.h:46
const std::vector< NetType > & types() const
Everything registered, in wire order.
Definition schema.h:76
void replicate(std::string name)
Add T to what replicates.
Definition schema.h:124
int indexOf(std::string_view name) const
Wire index of name, or -1.
uint32_t fingerprint() const
A number that differs when the lists differ, or the codecs' layout does.
std::string describe() const
Every name in order, for the log line that follows a refusal.
Central registry managing entities and an open set of component types.
Definition scene.h:29
T * tryGet(EntityId entity)
The entity's T, or null when it has none.
Definition scene.h:206
T & get(EntityId entity)
Get a mutable reference to an entity's component of type T.
Definition scene.h:176
bool has(EntityId entity) const
Check if an entity has a component of type T.
Definition scene.h:162
auto & add(EntityId entity, T &&component)
Give an entity a component it does not have yet.
Definition scene.h:128
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
One replicated component type, reduced to what the wire needs.
Definition schema.h:18
std::string name
The serializable identity, as everywhere else in the engine.
Definition schema.h:19
bool(* has)(const Scene &, EntityId)
Does this entity carry one? Decides its bit in a snapshot's mask.
Definition schema.h:22
bool(* decode)(Scene &, EntityId, BitReader &)
Decode onto this entity, adding the component when it is missing.
Definition schema.h:28
void(* encode)(const Scene &, EntityId, BitWriter &)
Encode this entity's component. Asked only of an entity has said yes to.
Definition schema.h:25