Original Post
Hi. Are there are any performance penalties by using several modules? I'm using AS for gamescripting and the idea is to have a controller for every gameobject. Since the controller would have some defined variables that would be unique for each gameobject I thought that maybe I could put each controller in it's own Module. The downside is that if I have 100 gameobjects using the "SpinController" I would end up with 100 copies of the same code in 100 different modules. (Sounds like a waste of memory to me.) This is what the SpinController could look like... An alternative would be to let the GameObject handle these variables so that the Controller work against those instead, that way I would only need one single SpinController. Something like this... These "Properties" that I store in the GameObject is already implemented and would work, but I'm afraid that could affect the performance a bit since these Properties was more meant for "once in a while" state changes etc... Do anyone cope with these kind of things and have any advice or suggestions? //Sweenie
/// SpinController ///
int numRotations;
float currentRotation;
void Update(GameObject@ go, float dt)
{
go.GetSceneNode("MainNode").Yaw(45.0*dt);
currentRotation += 45.0*dt;
if(currentRotation > 360.0)
{
numRotations += 1;
currentRotation = 0.0;
}
}
/// SpinController ///
void Update(GameObject@ go, float dt)
{
go.GetSceneNode("MainNode").Yaw(45.0*dt);
float currentRotation = go.Properties.GetFloat("CurrentRotation");
int numRotations = go.Properties.GetInt("NumRotations");
currentRotation += 45.0*dt;
if(currentRotation > 360.0)
{
numRotations += 1;
currentRotation = 0.0;
}
go.Properties.SetFloat("CurrentRotation",currentRotations);
go.Properties.SetInt("NumRotations",numRotations);
}