Dynamic reloading script

Started by
35 comments, last by WitchLord 11 years, 7 months ago
It is difficult for making ?
Advertisement
Just creating classes without calling the default constructor is simple enough and I'll be able to include it for version 2.24.0. It will be a method on the engine, similar to the CreateScriptObject(), maybe CreateDummyScriptObject(), or CreateScriptObjectShell() where it will simply do the minimal memory initialization to clear handles and allocate memory for members.

I'm not entirely sure if it is enough to do just that, or if something else will be required to make things fully working. I'll continue to analyse this over the time.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I, too, for some reason think that this is not enough, need try it!
wait for the new version!


[edit] I analyze this! Empty constructor is really need!

Example this code
Before reload ref_a.val == 10 after ref_a.val == -1


A ref_a;
B @r;

class A
{
int val;
}
class B
{
B(){
ref_a.val = -1;
}
}

void startGame()
{
@r = B();
ref_a.val = 10;
}

void reloaded()
{
output( "ref_a: " + ref_a.val );
}

Yes, this has the same problem. The serializer sets the value in ref_a correctly to 10, then when recreating the object referred to by r, the constructor overwrites that value again.

Obviously if the object is created with the new method, and then the CSerializer doesn't initialize all the members, for example if a new member has been introduced in the script, then script may not work as expected afterwards. But I guess that is expected. I'll see if it is easy to warn in case this happens.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I have finally implemented the new method CreateUninitializedScriptObject and modified CSerializer to use it.

You'll find the changes in revision 1327.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've added the new methods to store additional objects now.

I chose to use the name AddExtraObjectToStore() as I thought it was more clear on the meaning of the function.

You can get the changes in revision 1329.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hy Andreas!

I find two bugs, frist:


file: serealizer.cpp line: 98

void *newPtr = m_engine->CreateScriptObject( type->GetTypeId() );

change to:

void *newPtr = m_engine->CreateUninitializedScriptObject( type->GetTypeId() );


second:


file: serealizer.cpp line: 357

if( type->GetFactoryCount() == 0 )
{
(void**)m_restorePtr = m_handlePtr;
}

change to:

if( type->GetFactoryCount() == 0 )
{
m_children[0]->m_restorePtr = m_handlePtr;
}


full source: http://www.everfall.com/paste/id.php?9kzqvaefx31w
Thanks. I'll apply these fixed in the next check-in to the SVN.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement