I have a class named "Actor" that has a pointer to class "Transform" that represent actors position;
here is Actor.h:
class Actor
{
public:
Actor();
void Update();
void Render();
void Start();
int AddRef();
int Release();
asILockableSharedBool *GetWeakRefFlag();
void Send(CScriptHandle msg, Actor *other);
const char * GetName() { return this->m_name; }
int GetX() { return this->x3; }
int GetY() { return this->y; }
void SetX(int _x) { this->x3 = _x; }
public:
int refCount;
asILockableSharedBool *weakRefFlag;
const char *m_name;
int x3;;
int y;
int z;
bool active;
AngelCore::AngelTools::AngelMathHelper::Vector<3> rotation;
AngelCore::AngelTools::AngelMathHelper::Vector<3> Position;
asIScriptObject *controller;
Transform *t;
~Actor();
};
And Actor.cpp
asILockableSharedBool *Actor::GetWeakRefFlag()
{
if (!weakRefFlag)
weakRefFlag = asCreateLockableSharedBool();
return weakRefFlag;
}
void Actor::Start()
{
//this->t = new Transform();
scriptMgr->Start(controller);
}
int Actor::AddRef()
{
return ++refCount;
}
int Actor::Release()
{
if (--refCount == 0)
{
delete this;
return 0;
}
return refCount;
}
void Actor::Send(CScriptHandle msg, Actor *other)
{
if (other && other->controller)
scriptMgr->OnSendMessage(other->controller, msg, this);
}
Actor::Actor()
{
refCount = 1;
this->t = new Transform();
//t->position->y = 150;
this->x3= 21000;
this->y = 510;
controller = 0;
//this->active = true;
weakRefFlag = 0;
}
void Actor::Update()
{
scriptMgr->Update(controller);
//HERE I WANT THIS VALUE BE SAME AS IN SCRIPT******************************************************
std::cout << "\n\n\nCurrent : " << this->t->position->x;
}
and Transform.h:
class Transform
{
public:
Transform();
~Transform();
public:
AngelCore::AngelTools::AngelMathHelper::Vector<3> *position;
AngelCore::AngelTools::AngelMathHelper::Vector<3> rotation;
AngelCore::AngelTools::AngelMathHelper::Vector<3> scalling;
};
in my script manager i register "t" as one of actors properties:
engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
// Set the message callback to print the human readable messages that the engine gives in case of errors
r = engine->SetMessageCallback(asMETHOD(ScriptManager, MessageCallback), this, asCALL_THISCALL); assert( r >= 0 );
// Register the string type
RegisterStdString(engine);
// Register the generic handle type, called 'ref' in the script
RegisterScriptHandle(engine);
// Register the weak ref template type
RegisterScriptWeakRef(engine);
// Register the game object. The scripts cannot create these directly, so there is no factory function.
r = engine->RegisterObjectType("Actor", sizeof(Actor), asOBJ_REF | asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_ADDREF, "void f()", asMETHOD(Actor, AddRef), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_RELEASE, "void f()", asMETHOD(Actor, Release), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asMETHOD(Actor, GetWeakRefFlag), asCALL_THISCALL); assert( r >= 0 );
// The object's position is read-only to the script. The position is updated with the Move method
r = engine->RegisterObjectMethod("Actor", "int get_x() const", asMETHOD(Actor, GetX), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("Actor", "int get_y() const", asMETHOD(Actor, GetY), asCALL_THISCALL); assert( r >= 0 );
RegisterType<Transform>("Transform");
RegisterType<Vector3>("Vector3");
RegisterType<Vector2>("Vector2");
RegisterType<Vector4>("Vector4");
r = engine->RegisterObjectProperty("Vector3", "float x", asOFFSET(Vector3, x));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Vector3", "float y", asOFFSET(Vector3, y));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Vector3", "float z", asOFFSET(Vector3, z));
?
r = engine->RegisterObjectProperty("Vector2", "float x", asOFFSET(Vector2, x));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Vector2", "float y", asOFFSET(Vector2, y));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Vector4", "float x", asOFFSET(Vector4, x));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Vector4", "float y", asOFFSET(Vector4, y));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Vector4", "float z", asOFFSET(Vector4, z));
r = engine->RegisterObjectProperty("Vector4", "float w", asOFFSET(Vector4, w));
//REGISTER TRANSFORM POSITION /*/*/*/*/**************************************************************
r = engine->RegisterObjectProperty("Transform", "Vector3 @position", asOFFSET(Transform, position));
//r = engine->RegisterGlobalProperty("Vector3 &data", data);
if (r < 0) return r;
r = engine->RegisterObjectProperty("Transform", "Vector3 rotation", asOFFSET(Transform, rotation));
if (r < 0) return r;
r = engine->RegisterObjectProperty("Transform", "Vector3 scalling", asOFFSET(Transform, scalling));
if (r < 0) return r;
//assert(r >= 0);
engine->RegisterObjectProperty("Actor", "Vector3 Position", asOFFSET(Actor, Position));
//HERE I REGISTER t /*//*/*/*/*/*/*/*/*/*********************************************************************
engine->RegisterObjectProperty("Actor", "Transform @transform", asOFFSET(Actor, t));
above is registeration of all properties so far.
my problem is when i change actors transform from script file like below the actual actor transform in .cpp file is not changed!
void Start()
{
self.transform.position.x=42242;
self.transform.rotation.y=1;
self.transform.scalling.z=2;
DebugString("StartCalled \n \n ++++++++++++++++++++");
self.active=false;
self.Position.x=10000;
}
void Update()
{
bool data;
DebugString("Active : " + self.active);
DebugString("\n Transform PositionY:" + self.transform.position.x);// IT PRINTS 42242 BUT IN ACTOR.cpp IT PRINTS A DEFAULT UNKOWN VALUE
//I WANT THESE TO VALUE BE SAME!
?
DebugString("\n Transform RotationX:" + self.transform.rotation.y);
DebugString("\n Transform ScallingZ:" + self.transform.scalling.z);
//self.transform.position.y++;
}
what is the problem?
?I have to mention that when I delete pointers and register properties normally it works well.