Added getFPS(), so the GUI can draw the FPS counter. Also added getLanguageID(), so it knows what language it's using
This was SVN commit r1122.
This commit is contained in:
parent
959600b0d1
commit
3a3a5b6c34
@ -9,7 +9,10 @@
|
||||
#include "ps/CLogger.h"
|
||||
#define LOG_CATEGORY "i18n"
|
||||
|
||||
// Yay, global variables. (The user only ever wants to be using one language
|
||||
// at a time, so this is sufficient)
|
||||
I18n::CLocale_interface* g_CurrentLocale = NULL;
|
||||
std::string g_CurrentLocaleName;
|
||||
|
||||
bool I18n::LoadLanguage(const char* name)
|
||||
{
|
||||
@ -24,6 +27,7 @@ bool I18n::LoadLanguage(const char* name)
|
||||
assert(locale_ptr);
|
||||
delete g_CurrentLocale;
|
||||
g_CurrentLocale = locale_ptr;
|
||||
g_CurrentLocaleName = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -103,9 +107,17 @@ bool I18n::LoadLanguage(const char* name)
|
||||
// Store the new CLocale*, and stop the auto_ptr from deleting it
|
||||
g_CurrentLocale = locale.release();
|
||||
|
||||
// Remember the name
|
||||
g_CurrentLocaleName = name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* I18n::CurrentLanguageName()
|
||||
{
|
||||
return g_CurrentLocaleName.c_str();
|
||||
}
|
||||
|
||||
void I18n::Shutdown()
|
||||
{
|
||||
delete g_CurrentLocale;
|
||||
|
@ -7,5 +7,6 @@ extern I18n::CLocale_interface* g_CurrentLocale;
|
||||
namespace I18n
|
||||
{
|
||||
bool LoadLanguage(const char* name);
|
||||
const char* CurrentLanguageName();
|
||||
void Shutdown();
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ JSFunctionSpec ScriptFunctionTable[] =
|
||||
{"joinGame", joinGame, 0, 0, 0 },
|
||||
{"startServer", startServer, 0, 0, 0 },
|
||||
{"loadLanguage", loadLanguage, 1, 0, 0 },
|
||||
{"getLanguageID", getLanguageID, 0, 0, 0 },
|
||||
{"getFPS", getFPS, 0, 0, 0 },
|
||||
{"buildTime", buildTime, 0, 0, 0 },
|
||||
|
||||
{"exit", exitProgram, 0, 0, 0 },
|
||||
@ -375,6 +377,25 @@ JSBool loadLanguage(JSContext* cx, JSObject* UNUSEDPARAM(globalObject), unsigned
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool getLanguageID(JSContext* cx, JSObject* UNUSEDPARAM(globalObject), unsigned int UNUSEDPARAM(argc), jsval* UNUSEDPARAM(argv), jsval* rval)
|
||||
{
|
||||
JSString* s = JS_NewStringCopyZ(cx, I18n::CurrentLanguageName());
|
||||
if (!s)
|
||||
{
|
||||
JS_ReportError(cx, "Error creating string");
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(s);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
extern "C" extern int fps;
|
||||
JSBool getFPS(JSContext* UNUSEDPARAM(cx), JSObject* UNUSEDPARAM(globalObject), unsigned int UNUSEDPARAM(argc), jsval* UNUSEDPARAM(argv), jsval* rval)
|
||||
{
|
||||
*rval = INT_TO_JSVAL(fps);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool buildTime(JSContext* context, JSObject* UNUSEDPARAM(globalObject), unsigned int argc, jsval* argv, jsval* rval)
|
||||
{
|
||||
if (argc > 1)
|
||||
|
@ -4,43 +4,50 @@
|
||||
|
||||
#include "ScriptingHost.h"
|
||||
|
||||
typedef JSBool JSFunc(JSContext* /*context*/, JSObject* /*globalObject*/, unsigned int /*argc*/, jsval* /*argv*/, jsval* /*rval*/);
|
||||
|
||||
// Functions to be called from Javascript:
|
||||
|
||||
JSBool WriteLog(JSContext * context, JSObject * globalObject, unsigned int argc, jsval *argv, jsval *rval);
|
||||
JSFunc WriteLog;
|
||||
|
||||
JSBool getEntityByHandle( JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval );
|
||||
JSBool getEntityTemplate( JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval );
|
||||
JSBool setTimeout( JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval );
|
||||
JSBool setInterval( JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval );
|
||||
JSBool cancelInterval( JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval );
|
||||
JSFunc getEntityByHandle;
|
||||
JSFunc getEntityTemplate;
|
||||
JSFunc setTimeout;
|
||||
JSFunc setInterval;
|
||||
JSFunc cancelInterval;
|
||||
|
||||
// Returns the sort-of-global object associated with the current GUI
|
||||
JSBool getGUIGlobal(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc getGUIGlobal;
|
||||
|
||||
// Returns the global object, e.g. for setting global variables.
|
||||
JSBool getGlobal(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc getGlobal;
|
||||
|
||||
JSBool setCursor(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc setCursor;
|
||||
|
||||
JSBool startServer(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSBool joinGame(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSBool startGame(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSBool endGame(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc startServer;
|
||||
JSFunc joinGame;
|
||||
JSFunc startGame;
|
||||
JSFunc endGame;
|
||||
|
||||
// Replaces the current language (locale) with a new one
|
||||
JSBool loadLanguage(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc loadLanguage;
|
||||
|
||||
// Returns the current language's name, in the same form as passed to loadLanguage
|
||||
JSFunc getLanguageID;
|
||||
|
||||
JSFunc getFPS;
|
||||
|
||||
// Returns a string that says when ScriptGlue.cpp was last recompiled
|
||||
JSBool buildTime(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc buildTime;
|
||||
|
||||
// Tells the main loop to stop looping
|
||||
JSBool exitProgram(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc exitProgram;
|
||||
|
||||
// Crashes.
|
||||
JSBool crash(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc crash;
|
||||
|
||||
// Tries to print the amount of remaining video memory. (I don't like starting functions with underscores).
|
||||
JSBool js_mem(JSContext* context, JSObject* globalObject, unsigned int argc, jsval* argv, jsval* rval);
|
||||
JSFunc js_mem;
|
||||
|
||||
extern JSFunctionSpec ScriptFunctionTable[];
|
||||
extern JSPropertySpec ScriptGlobalTable[];
|
||||
|
Loading…
Reference in New Issue
Block a user