virtual void Serialize(ISerializer& serialize) { JSContext* cx = GetSimContext().GetScriptInterface().GetContext(); JSAutoRequest rq(cx); serialize.NumberU32_Unbounded("num commands", (u32)m_LocalQueue.size()); for (size_t i = 0; i < m_LocalQueue.size(); ++i) { serialize.NumberI32_Unbounded("player", m_LocalQueue[i].player); serialize.ScriptVal("data", &m_LocalQueue[i].data); } }
void CComponentTypeScript::Serialize(ISerializer& serialize) { // If the component set Serialize = null, then do no work here if (m_HasNullSerialize) return; JSContext* cx = m_ScriptInterface.GetContext(); JSAutoRequest rq(cx); // Support a custom "Serialize" function, which returns a new object that will be // serialized instead of the component itself if (m_HasCustomSerialize) { JS::RootedValue val(cx); if (!m_ScriptInterface.CallFunction(m_Instance, "Serialize", &val)) LOGERROR("Script Serialize call failed"); serialize.ScriptVal("object", &val); } else { serialize.ScriptVal("object", &m_Instance); } }