MCPcopy Create free account
hub / github.com/MergHQ/CRYENGINE / BuildSynchTable

Method BuildSynchTable

Code/CryEngine/CryAction/Network/ScriptRMI.cpp:382–447  ·  view source on GitHub ↗

setup the meta-table for synched variables

Source from the content-addressed store, hash-verified

380
381// setup the meta-table for synched variables
382bool CScriptRMI::BuildSynchTable(SmartScriptTable vars, SmartScriptTable cls, const char* name)
383{
384 IScriptSystem* pSS = vars->GetScriptSystem();
385 SmartScriptTable synched(pSS);
386 SmartScriptTable defaultValues(pSS);
387
388 // TODO: Improve
389 IScriptTable::SUserFunctionDesc fd;
390 fd.pFunctor = functor_ret(SynchedNewIndexFunction);
391 fd.sFunctionName = "__newindex";
392 fd.sGlobalName = "<net-dispatch>";
393 fd.sFunctionParams = "(...)";
394 synched->AddFunction(fd);
395
396 std::vector<SSynchedPropertyInfo> properties;
397
398 IScriptTable::Iterator iter = vars->BeginIteration();
399 while (vars->MoveNext(iter))
400 {
401 if (iter.sKey)
402 {
403 int type;
404 if (!vars->GetValue(iter.sKey, type))
405 {
406 vars->EndIteration(iter);
407 pSS->RaiseError("No type for %s", iter.sKey);
408 return false;
409 }
410 size_t len = strlen(iter.sKey);
411 if (len > MaxSynchedPropertyNameLength)
412 {
413 vars->EndIteration(iter);
414 pSS->RaiseError("Synched var name '%s' too long (max is %d)",
415 iter.sKey, (int)MaxSynchedPropertyNameLength);
416 return false;
417 }
418 SSynchedPropertyInfo info;
419 cry_strcpy(info.name, iter.sKey);
420 info.type = (EScriptSerializeType) type;
421 properties.push_back(info);
422
423 if (info.type == eSST_String)
424 defaultValues->SetValue(iter.sKey, "");
425 else
426 defaultValues->SetValue(iter.sKey, 0);
427 }
428 }
429 vars->EndIteration(iter);
430
431 if (properties.empty())
432 return true;
433
434 fd.pFunctor = NULL;
435 fd.pUserDataFunc = SerializeFunction;
436 fd.nDataSize = sizeof(SSynchedPropertyInfo) * properties.size();
437 fd.pDataBuffer = &properties[0];
438 fd.sFunctionName = SERIALIZE_FUNCTION;
439 fd.sFunctionParams = "(...)";

Callers

nothing calls this directly

Calls 14

functor_retFunction · 0.85
strlenFunction · 0.85
cry_strcpyFunction · 0.85
AddFunctionMethod · 0.80
BeginIterationMethod · 0.80
EndIterationMethod · 0.80
RaiseErrorMethod · 0.80
GetScriptSystemMethod · 0.45
MoveNextMethod · 0.45
GetValueMethod · 0.45
push_backMethod · 0.45
SetValueMethod · 0.45

Tested by

no test coverage detected