Codegen
Codegen is a small Python script to help with syncing up C++ entity
serialization code and entdef files.
How to use
Open command prompt in you project's directory and run the codegen.py
C:\garden>codegen.py make StickyFroggy
The program will prompt you with the filename of the new file to be created.
Press y to accept.
Tramway SDK Code generator v0.1.1
Create file C:\garden\src\stickyfroggy.h? [y/n]
The program will now have created the files /src/stickyfroggy.h
and /src/stickyfroggy.cpp.
Let's open up stickyfroggy.h and take a look inside:
// Generated by Tramway SDK Code generator
#include <framework/entity.h>
#include <framework/serialization.h>
#include <templates/macros.h>
using namespace tram;
class StickyFroggy : public Entity {
public:
StickyFroggy(const SharedEntityData&, const ValueArray&);
TRAM_SDK_ENTITY_NAME("stickyfroggy")
void UpdateParameters();
void SetParameters();
void Load();
void Unload();
void Serialize();
void EventHandler(Event& evt);
void MessageHandler(Message& msg);
name_t GetType();
static void Register();
};
Let's add some properties to the class!
class StickyFroggy : public Entity {
public:
StickyFroggy(const SharedEntityData&, const ValueArray&);
TRAM_SDK_ENTITY_NAME("stickyfroggy")
void UpdateParameters();
void SetParameters();
void Load();
void Unload();
void Serialize();
void EventHandler(Event& evt);
void MessageHandler(Message& msg);
name_t GetType();
static void Register();
private:
TRAM_SDK_KEY_VALUE("model", "frog-marker")
TRAM_SDK_PROPERTY("viewmodel", FIELD_SERIALIZE)
name_t viewmodel = "frog";
TRAM_SDK_PROPERTY("stickiness", FIELD_SERIALIZE)
float stickiness = 1.5f;
TRAM_SDK_PROPERTY("roll", FIELD_SERIALIZE)
bool egg;
TRAM_SDK_VIRTUAL_PROPERTY(int32_t, "egg-count", FIELD_SERIALIZE, 11)
};
After editing entity properties, we need to create/regenerate code and data
files
C:\codegen.py refresh StickyFroggy
This command creates or overwrites these files
/src/stickyfroggy.inl
/data/stickyfroggy.[number].entdef
If you want, you can take a look at the generated code in
stickyfroggy.inl file, but don't bother editing it — it
will be overwritten every time you run the refresh command.
Let's look at the generated .entdef file
begin
# this comes from TRAM_SDK_ENTITY_NAME() macro
name stickyfroggy
# this comes from TRAM_SDK_KEY_VALUE() macro
model frog-marker
# these come from TRAM_SDK_PROPERTY()
# and TRAM_SDK_VIRTUAL_PROPERTY() macros
field string viewmodel
field float stickiness
field bool roll
field int egg-count
# this is randomly generated index
version 193035075
end
Supported types
name_t
bool
int
float
double
int8_t
int16_t
int32_t
uint8_t
uint16_t
uint32_t
vec2
vec3
vec4
quat
|