entity per world
This commit is contained in:
1 parent
16ba641d8a
commit
b70e2d21d2
15 files changed
+694
-19
No files matched your search
@@ -21,6 +21,48 @@ internal void serialize(Archive& ar, uint16 /*version*/, Entity& entity)
|
||||
SERIALIZE(ar, position, entity.position);
|
||||
}
|
||||
|
||||
String format_entity_id(NonNullPtr<Arena> arena, EntityID entity_id)
|
||||
{
|
||||
// Format:
|
||||
// U = UserID
|
||||
// LC = Local Entity Counter
|
||||
// UU_LCLCLCLCLCLCLC
|
||||
uint8 user_id = get_user_id(entity_id);
|
||||
uint64 counter = get_local_counter(entity_id);
|
||||
|
||||
constexpr size_t kBufferSize = 18;
|
||||
char* buffer = ArenaPushArray<char>(arena, kBufferSize);
|
||||
Assert(buffer);
|
||||
|
||||
juliet_snprintf(buffer, kBufferSize, "%02X_%014llX", (unsigned int)user_id, counter);
|
||||
return { buffer, kBufferSize - 1 };
|
||||
}
|
||||
|
||||
bool parse_entity_id(String str, EntityID& out_id)
|
||||
{
|
||||
bool result = false;
|
||||
out_id = kInvalid_entity_id;
|
||||
|
||||
if (!(str.Size != 17 || str.Str == nullptr || str.Str[2] != '_'))
|
||||
{
|
||||
char user_hex[3]{ str.Str[0], str.Str[1], '\0' };
|
||||
char* end = user_hex;
|
||||
uint8 user_id = strtoul(user_hex, &end, 16);
|
||||
if (end != user_hex && user_id != kInvalid_user_id)
|
||||
{
|
||||
char* counter_hex = str.Str + 3;
|
||||
end = counter_hex;
|
||||
uint64 counter = strtoull(counter_hex, &end, 16);
|
||||
if (end != counter_hex && counter < kEntityID_user_id_mask)
|
||||
{
|
||||
out_id = make_entity_id(user_id, counter);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const Class* resolve_entity_class(uint8 kind, uint32 crc)
|
||||
{
|
||||
Assert(kind <= ENTITY(Count));
|
||||
|
||||
Reference in new issue
Block a user