Skip to content

Commit

Permalink
Added field typename metadata to component traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
fLindahl committed Mar 20, 2024
1 parent 3851d97 commit 7e7ecb5
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions code/application/basegamefeature/components/orientation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ struct Orientation::Traits
"z",
"w"
};
static constexpr const char* field_typenames[num_fields] = {
"float",
"float",
"float",
"float"
};
using field_types = std::tuple<float, float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Orientation, x),
Expand Down
5 changes: 5 additions & 0 deletions code/application/basegamefeature/components/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct Position::Traits
"y",
"z"
};
static constexpr const char* field_typenames[num_fields] = {
"float",
"float",
"float"
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Position, x),
Expand Down
5 changes: 5 additions & 0 deletions code/application/basegamefeature/components/scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ struct Scale::Traits
"y",
"z"
};
static constexpr const char* field_typenames[num_fields] = {
"float",
"float",
"float"
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Scale, x),
Expand Down
10 changes: 10 additions & 0 deletions code/application/basegamefeature/components/velocity.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ struct Velocity::Traits
"y",
"z"
};
static constexpr const char* field_typenames[num_fields] = {
"float",
"float",
"float"
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(Velocity, x),
Expand All @@ -66,6 +71,11 @@ struct AngularVelocity::Traits
"y",
"z"
};
static constexpr const char* field_typenames[num_fields] = {
"float",
"float",
"float"
};
using field_types = std::tuple<float, float, float>;
static constexpr size_t field_byte_offsets[num_fields] = {
offsetof(AngularVelocity, x),
Expand Down
3 changes: 3 additions & 0 deletions code/application/game/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class ComponentInterface : public MemDb::Attribute
this->fullyQualifiedName = T::Traits::fully_qualified_name;
this->numFields = T::Traits::num_fields;
this->fieldNames = (const char**)T::Traits::field_names;
this->fieldTypenames = (const char**)T::Traits::field_typenames;
this->fieldByteOffsets = (const size_t*)T::Traits::field_byte_offsets;
}

Expand All @@ -91,13 +92,15 @@ class ComponentInterface : public MemDb::Attribute
const char* GetName() const { return componentName; }
const char* GetFullyQualifiedName() const { return fullyQualifiedName; }
const char** GetFieldNames() const { return fieldNames; };
const char** GetFieldTypenames() const { return fieldTypenames; };
const size_t* GetFieldByteOffsets() const { return fieldByteOffsets; };
size_t const GetNumFields() const { return numFields; };

private:
const char* componentName = nullptr;
const char* fullyQualifiedName = nullptr;
const char** fieldNames = nullptr;
const char** fieldTypenames = nullptr;
const size_t* fieldByteOffsets = nullptr;
size_t numFields = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions code/application/game/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ struct Entity::Traits
static constexpr const char* field_names[num_fields] = {
"id"
};
static constexpr const char* field_typenames[num_fields] = {
"uint"
};
static constexpr size_t field_byte_offsets[num_fields] = { 0 };

/// This is the column that the entity "owner" will reside in, in every table.
Expand Down
10 changes: 10 additions & 0 deletions fips-files/generators/IDLC/idlcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ def WriteComponentHeaderDeclarations(f, document):
for v in c.variables:
f.WriteLine(' "{}",'.format(v.name))
f.WriteLine('};')
f.WriteLine('static constexpr const char* field_typenames[num_fields] = {')
for i, v in enumerate(c.variables):
f.Write(' "{}"'.format(IDLTypes.GetCppTypeString(v.type)))
if i < (len(c.variables) - 1):
f.WriteLine(",")
else:
f.WriteLine("")
f.WriteLine('};')

f.WriteLine('using field_types = std::tuple<')
for i, v in enumerate(c.variables):
f.Write(' {}'.format(IDLTypes.GetCppTypeString(v.type)))
Expand All @@ -156,6 +165,7 @@ def WriteComponentHeaderDeclarations(f, document):
f.WriteLine('};')
else:
f.WriteLine('static constexpr const char** field_names = nullptr;')
f.WriteLine('static constexpr const char** field_typenames = nullptr;')
f.WriteLine('static constexpr size_t* field_byte_offsets = nullptr;')


Expand Down
2 changes: 1 addition & 1 deletion fips-files/generators/NIDL.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version = 141
Version = 142

import sys
if __name__ == '__main__':
Expand Down

0 comments on commit 7e7ecb5

Please sign in to comment.