# Add initial basic player AI framework.

Support direct access to serializer streams, so serializers can be
nested.
Make component script "this.template" read-only.
Stop globally-subscribed component scripts receiving messages posted to
local components, to reduce out-of-sync risks.
Move pathfinder data out of entity template directory.
Fix GuiInterface deserialization.

This was SVN commit r8865.
This commit is contained in:
Ykkrosh
2011-01-12 12:29:00 +00:00
parent 1051d10f54
commit dd501b2a5a
70 changed files with 1681 additions and 267 deletions
@@ -61,67 +61,15 @@ template<> jsval ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, IComponent
return OBJECT_TO_JSVAL(obj);
}
static jsval ConvertCParamNode(JSContext* cx, CParamNode const& val)
template<> jsval ScriptInterface::ToJSVal<CParamNode>(JSContext* cx, CParamNode const& val)
{
const std::map<std::string, CParamNode>& children = val.GetChildren();
if (children.empty())
{
// Empty node - map to undefined
if (val.ToString().empty())
return JSVAL_VOID;
// Just a string
utf16string text(val.ToString().begin(), val.ToString().end());
JSString* str = JS_InternUCStringN(cx, reinterpret_cast<const jschar*>(text.data()), text.length());
if (str)
return STRING_TO_JSVAL(str);
// TODO: report error
return JSVAL_VOID;
}
// Got child nodes - convert this node into a hash-table-style object:
JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
if (!obj)
return JSVAL_VOID; // TODO: report error
CScriptValRooted objRoot(cx, OBJECT_TO_JSVAL(obj));
for (std::map<std::string, CParamNode>::const_iterator it = children.begin(); it != children.end(); ++it)
{
jsval childVal = ConvertCParamNode(cx, it->second);
if (!JS_SetProperty(cx, obj, it->first.c_str(), &childVal))
return JSVAL_VOID; // TODO: report error
}
// If the node has a string too, add that as an extra property
if (!val.ToString().empty())
{
utf16string text(val.ToString().begin(), val.ToString().end());
JSString* str = JS_InternUCStringN(cx, reinterpret_cast<const jschar*>(text.data()), text.length());
if (!str)
return JSVAL_VOID; // TODO: report error
jsval childVal = STRING_TO_JSVAL(str);
if (!JS_SetProperty(cx, obj, "_string", &childVal))
return JSVAL_VOID; // TODO: report error
}
jsval rval = val.ToJSVal(cx, true);
// Prevent modifications to the object, so that it's safe to share between
// components and to reconstruct on deserialization
//JS_SealObject(cx, obj, JS_TRUE);
// TODO: need to re-enable this when it works safely (e.g. it doesn't seal the
// global object too (via the parent chain))
if (JSVAL_IS_OBJECT(rval))
JS_DeepFreezeObject(cx, JSVAL_TO_OBJECT(rval));
return OBJECT_TO_JSVAL(obj);
}
template<> jsval ScriptInterface::ToJSVal<CParamNode>(JSContext* cx, CParamNode const& val)
{
// If there's a cached value, then return it
if (!JSVAL_IS_VOID(val.GetScriptVal().get()))
return val.GetScriptVal().get();
jsval rval = ConvertCParamNode(cx, val);
val.SetScriptVal(CScriptValRooted(cx, rval));
return rval;
}