Dynamic Classes
- Extend Dynamic to create your own Dynamic Classes
- A
Class Builder to quickly generate basic Dynamic Classes
- You dont have to muck around with Dynamic Member Offsets to improve performance
- All of the same features that come with Dynamic Objects
I just finished a basic web based
class builder.
Generate this methodmap...
Code:
#if defined _dynamic_class_person_
#endinput
#endif
#define _dynamic_class_person_
methodmap Person < Dynamic
{
public Person()
{
// First we make a new dymanic object
Dynamic myclass = Dynamic(128, 0);
// Next we will define all the members
// -> We do this to force the offsets to always be in the same location
// over multiple instances of the same class.
myclass.SetString("Name", "Some guy that knows you", 256);
myclass.SetInt("Age", 27);
myclass.SetFloat("Height", 6.2100000);
return view_as<Person>(myclass);
}
// Note that I use static offsets to access members.
// -> This improves performance by caching member offsets
// -> This is why we force the members in during the contructor
// -> Failure to force members in the constructor will cause corruption
public bool GetName(char[] buffer, int length)
{
static int offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Name");
if (offset == INVALID_DYNAMIC_OFFSET)
return false;
}
this.GetStringByOffset(offset, buffer, length);
return true;
}
public void SetName(const char[] buffer)
{
static int offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Name");
if (offset == INVALID_DYNAMIC_OFFSET)
{
this.SetString("Name", buffer);
return;
}
}
this.SetStringByOffset(offset, buffer);
}
property int Age
{
public get()
{
static int offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Age");
if (offset == INVALID_DYNAMIC_OFFSET)
return 27;
}
return this.GetIntByOffset(offset, 27);
}
public set(int value)
{
static int offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Age");
if (offset == INVALID_DYNAMIC_OFFSET)
{
this.SetInt("Age", value);
return;
}
}
this.SetIntByOffset(offset, value);
}
}
property float Height
{
public get()
{
static int offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Height");
if (offset == INVALID_DYNAMIC_OFFSET)
return 6.2100000;
}
return this.GetFloatByOffset(offset, 6.2100000);
}
public set(float value)
{
static int offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Height");
if (offset == INVALID_DYNAMIC_OFFSET)
{
this.SetFloat("Height", value);
return;
}
}
this.SetFloatByOffset(offset, value);
}
}
}
__________________