Load map descriptions from their XML file.

Add basic hold-fire stance, and use it for some test maps.
Add JSON data container to map XML files, to simplify the interaction
between scripts and maps.
Fix fixed-point printing so it roundtrips safely through map files.
Fix camera startup positions in old-format maps.

This was SVN commit r7844.
This commit is contained in:
Ykkrosh
2010-08-04 21:15:41 +00:00
parent a5171d9145
commit 65bcedb9fc
21 changed files with 415 additions and 28 deletions
@@ -22,6 +22,7 @@
#include "AutoRooters.h"
#include "lib/debug.h"
#include "lib/utf8.h"
#include "ps/CLogger.h"
#include "ps/Profile.h"
#include "ps/utf16string.h"
@@ -628,6 +629,58 @@ std::wstring ScriptInterface::ToString(jsval obj)
return source;
}
CScriptValRooted ScriptInterface::ParseJSON(const utf16string& string)
{
jsval vp;
JSONParser* parser = JS_BeginJSONParse(m->m_cx, &vp);
if (!parser)
{
LOGERROR(L"ParseJSON failed to begin");
return CScriptValRooted();
}
if (!JS_ConsumeJSONText(m->m_cx, parser, string.c_str(), string.size()))
{
LOGERROR(L"ParseJSON failed to consume");
return CScriptValRooted();
}
if (!JS_FinishJSONParse(m->m_cx, parser, JSVAL_NULL))
{
LOGERROR(L"ParseJSON failed to finish");
return CScriptValRooted();
}
return CScriptValRooted(m->m_cx, vp);
}
struct Stringifier
{
static JSBool callback(const jschar *buf, uint32 len, void *data)
{
utf16string str(buf, buf+len);
std::wstring strw(str.begin(), str.end());
LibError err; // ignore Unicode errors
static_cast<Stringifier*>(data)->stream << utf8_from_wstring(strw, &err);
return JS_TRUE;
}
std::stringstream stream;
};
std::string ScriptInterface::StringifyJSON(jsval obj)
{
Stringifier str;
if (!JS_Stringify(m->m_cx, &obj, NULL, INT_TO_JSVAL(2), &Stringifier::callback, &str))
{
LOGERROR(L"StringifyJSON failed");
return "";
}
return str.stream.str();
}
void ScriptInterface::ReportError(const char* msg)
{
// JS_ReportError by itself doesn't seem to set a JS-style exception, and so