Game Development Reference
In-Depth Information
m_pScriptContext->Prepare(pOnUpdateFunction);
m_pScriptContext->SetArgFloat(0, deltaTime);
int retCode = m_pScriptContext->Execute();
if(retCode != asEXECUTION_FINISHED)
{
// OnUpdate didn't finish executing.
}
}
}
With the game objects now being updated every frame, their behavior is alive inside the script engine. However,
you still can't visualize it. The Java-based user interface doesn't know what's happening in the script world just yet.
One way to change that situation is to gather an updated collection of game objects from the script engine and send it
via JNI. The GUI will then replace its current object collection with the updated one. As a first step, let's implement the
GetUpdatedObjects member function, which builds a collection of game objects from the current state in the script
engine, as shown in Listing 12-18.
Listing 12-18. The GetUpdatedObjects Function
void GPTScriptEngine::
GetUpdatedObjects(std::vector<GameObject>& updatedObjects)
{
// For each script, call the GetProperties function
for (size_t i = 0; i < m_scriptModules.size(); ++i)
{
asIScriptModule* pScriptModule =
m_scriptModules[i].pModule;
asIScriptFunction* pGetPropertiesFunction =
pScriptModule->GetFunctionByDecl(
"void GetPropertyValues(
int&out id, float&out x,
float&out y,
int&out color)");
m_pScriptContext->Prepare(pGetPropertiesFunction);
GameObject obj;
obj.id = m_scriptModules[i].id;
m_pScriptContext->SetArgAddress(0, &obj.x);
m_pScriptContext->SetArgAddress(1, &obj.y);
m_pScriptContext->SetArgAddress(2, &obj.color);
int retCode = m_pScriptContext->Execute();
if(retCode != asEXECUTION_FINISHED)
{
// GetProperties didn't finish executing.
continue;
}
updatedObjects.push_back(obj);
}
}
 
Search WWH ::




Custom Search