Skip to content

Commit

Permalink
the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
wraitii committed Jul 29, 2018
1 parent 2465160 commit f231c1d
Show file tree
Hide file tree
Showing 62 changed files with 816 additions and 850 deletions.
5 changes: 4 additions & 1 deletion binaries/data/mods/public/gui/gamesetup/gamesetup.js
Expand Up @@ -2274,8 +2274,11 @@ function launchGame()
if (assignBox.list_data[assignBox.selected] == "guid:local")
playerID = +i + 1;
}

warn("up to here");
warn(uneval(playerID));
warn(uneval(g_GameAttributes));
Engine.StartGame(g_GameAttributes, playerID);
warn("up to here");
Engine.SwitchGuiPage("page_loading.xml", {
"attribs": g_GameAttributes,
"playerAssignments": g_PlayerAssignments
Expand Down
8 changes: 5 additions & 3 deletions binaries/data/mods/public/gui/manual/manual.js
@@ -1,7 +1,10 @@
var hasCallback = false;

warn ("here");

function init(data)
{
warn("here");
Engine.GetGUIObjectByName("mainText").caption = Engine.TranslateLines(Engine.ReadFile("gui/" + data.page + ".txt"));
if (data.callback)
hasCallback = true;
Expand All @@ -12,9 +15,8 @@ function init(data)
var urlButton = Engine.GetGUIObjectByName("url");
var callback = function(url)
{
return function()
openURL(url);
}(data.url);
return () => openURL(url);
} (data.url);
urlButton.onPress = callback;
urlButton.hidden = false;
}
Expand Down
1 change: 1 addition & 0 deletions binaries/data/mods/public/gui/pregame/mainmenu.js
Expand Up @@ -2,6 +2,7 @@ var currentSubmenuType; // contains submenu type
var MARGIN = 4; // menu border size
var g_ShowSplashScreens;

warn("now");
/**
* Available backdrops
*/
Expand Down
14 changes: 7 additions & 7 deletions build/premake/extern_libs5.lua
Expand Up @@ -588,7 +588,7 @@ extern_lib_defs = {
links { "mozjs-45" }
else
pkgconfig.add_links("nspr")
pkgconfig.add_links("mozjs-45")
pkgconfig.add_links("mozjs-62")
end
else
if os.istarget("macosx") then
Expand All @@ -597,17 +597,17 @@ extern_lib_defs = {
end

filter { "Debug", "action:vs2013" }
links { "mozjs38-ps-debug-vc120" }
links { "mozjs62-ps-debug-vc120" }
filter { "Release", "action:vs2013" }
links { "mozjs38-ps-release-vc120" }
links { "mozjs62-ps-release-vc120" }
filter { "Debug", "action:vs2015" }
links { "mozjs38-ps-debug-vc140" }
links { "mozjs62-ps-debug-vc140" }
filter { "Release", "action:vs2015" }
links { "mozjs38-ps-release-vc140" }
links { "mozjs62-ps-release-vc140" }
filter { "Debug", "action:not vs*" }
links { "mozjs38-ps-debug" }
links { "mozjs62-ps-debug" }
filter { "Release", "action:not vs*" }
links { "mozjs45-ps-release" }
links { "mozjs62-ps-release" }
filter { }
add_source_lib_paths("spidermonkey")
end
Expand Down
5 changes: 4 additions & 1 deletion build/premake/premake5.lua
Expand Up @@ -183,6 +183,9 @@ function project_set_build_flags()
-- being used as a DLL (which is currently not the case in 0ad)
defines { "LIB_STATIC_LINK" }

-- flags { "C++14" }
cppdialect "c++14"

-- various platform-specific build flags
if os.istarget("windows") then

Expand Down Expand Up @@ -277,7 +280,7 @@ function project_set_build_flags()

buildoptions {
-- Enable C++11 standard.
"-std=c++0x"
-- "-std=c++0x"
}

if arch == "arm" then
Expand Down
2 changes: 1 addition & 1 deletion build/premake/premake5/modules/xcode/xcode_common.lua
Expand Up @@ -970,7 +970,7 @@

function xcode.XCBuildConfiguration_CppLanguageStandard(settings, cfg)
if cfg.cppdialect and cfg.cppdialect ~= "Default" then
settings['CLANG_CXX_LANGUAGE_STANDARD'] = cfg.cppdialect
settings['CLANG_CXX_LANGUAGE_STANDARD'] = "c++14"
end
end

Expand Down
7 changes: 5 additions & 2 deletions source/gui/CGUI.cpp
Expand Up @@ -1314,13 +1314,15 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::un
// Check for a 'file' parameter
CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8());

LOGWARNING("FILE %s", file.ToUTF8().c_str());

// If there is a file specified, open and execute it
if (!file.empty())
{
Paths.insert(file);
try
{
m_ScriptInterface->LoadGlobalScriptFile(file);
LOGWARNING("%i %s", m_ScriptInterface->LoadGlobalScriptFile(file), file.ToUTF8().c_str());
}
catch (PSERROR_Scripting& e)
{
Expand All @@ -1330,6 +1332,7 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::un

// If it has a directory attribute, read all JS files in that directory
CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8());
LOGWARNING("DIR %s", directory.ToUTF8().c_str());
if (!directory.empty())
{
VfsPaths pathnames;
Expand All @@ -1340,7 +1343,7 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::un
if (Paths.insert(path).second)
try
{
m_ScriptInterface->LoadGlobalScriptFile(path);
m_ScriptInterface->LoadGlobalScriptFile(path), path.string8().c_str();
}
catch (PSERROR_Scripting& e)
{
Expand Down
1 change: 1 addition & 0 deletions source/gui/CGUI.h
Expand Up @@ -45,6 +45,7 @@ struct SGUIStyle
std::map<CStr, CStrW> m_SettingsDefaults;
};

class ScriptRuntimeForThread;
class JSObject; // The GUI stores a JSObject*, so needs to know that JSObject exists
class IGUIObject;
class CGUISpriteInstance;
Expand Down
16 changes: 15 additions & 1 deletion source/gui/GUIManager.cpp
Expand Up @@ -177,6 +177,10 @@ void CGUIManager::DisplayMessageBox(int width, int height, const CStrW& title, c
PushPage(L"page_msgbox.xml", m_ScriptInterface->WriteStructuredClone(data));
}

#include "js/Realm.h"

extern thread_local ScriptRuntimeForThread* g_ThreadScriptRuntime;

void CGUIManager::LoadPage(SGUIPage& page)
{
// If we're hotloading then try to grab some data from the previous page
Expand All @@ -193,6 +197,8 @@ void CGUIManager::LoadPage(SGUIPage& page)
hotloadData = scriptInterface->WriteStructuredClone(hotloadDataVal);
}

ScriptAutoRealm realm;

page.inputs.clear();
page.gui.reset(new CGUI());

Expand Down Expand Up @@ -267,6 +273,10 @@ void CGUIManager::LoadPage(SGUIPage& page)
if (hotloadData)
scriptInterface->ReadStructuredClone(hotloadData, &hotloadDataVal);

scriptInterface->CallFunctionVoid(global, "init", initDataVal, hotloadDataVal);
scriptInterface->CallFunctionVoid(global, "uneval", global);

LOGWARNING("has %i", scriptInterface->HasProperty(global, "init"));
if (scriptInterface->HasProperty(global, "init") &&
!scriptInterface->CallFunctionVoid(global, "init", initDataVal, hotloadDataVal))
LOGERROR("GUI page '%s': Failed to call init() function", utf8_from_wstring(page.name));
Expand Down Expand Up @@ -340,6 +350,8 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
PROFILE("handleInputBeforeGui");
JSContext* cx = top()->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
ScriptAutoRealm realm(top()->GetScriptInterface());

JS::RootedValue global(cx, top()->GetGlobalObject());
if (top()->GetScriptInterface()->CallFunction(global, "handleInputBeforeGui", handled, *ev, top()->FindObjectUnderMouse()))
if (handled)
Expand All @@ -348,6 +360,7 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)

{
PROFILE("handle event in native GUI");
ScriptAutoRealm realm(top()->GetScriptInterface());
InReaction r = top()->HandleEvent(ev);
if (r != IN_PASS)
return r;
Expand All @@ -357,6 +370,7 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
// We can't take the following lines out of this scope because top() may be another gui page than it was when calling handleInputBeforeGui!
JSContext* cx = top()->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
ScriptAutoRealm realm(top()->GetScriptInterface());
JS::RootedValue global(cx, top()->GetGlobalObject());

PROFILE("handleInputAfterGui");
Expand Down Expand Up @@ -395,7 +409,7 @@ void CGUIManager::TickObjects()

// We share the script runtime with everything else that runs in the same thread.
// This call makes sure we trigger GC regularly even if the simulation is not running.
m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(1.0f);
m_ScriptInterface->MaybeIncrementalGC(1.0f);

// Save an immutable copy so iterators aren't invalidated by tick handlers
PageStackType pageStack = m_PageStack;
Expand Down
7 changes: 6 additions & 1 deletion source/gui/IGUIObject.cpp
Expand Up @@ -74,7 +74,7 @@ IGUIObject::~IGUIObject()
void IGUIObject::SetGUI(CGUI* const& pGUI)
{
if (!m_pGUI)
JS_AddExtraGCRootsTracer(pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
JS_AddExtraGCRootsTracer(pGUI->GetScriptInterface()->GetContext(), Trace, this);
m_pGUI = pGUI;
}

Expand Down Expand Up @@ -456,6 +456,7 @@ void IGUIObject::ScriptEvent(const CStr& Action)

JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
ScriptAutoRealm realm(m_pGUI->GetScriptInterface());

// Set up the 'mouse' parameter
JS::RootedValue mouse(cx);
Expand All @@ -469,6 +470,7 @@ void IGUIObject::ScriptEvent(const CStr& Action)
JS::RootedObject obj(cx, GetJSObject());
JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
JS::RootedValue result(cx);

bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
if (!ok)
{
Expand All @@ -485,6 +487,7 @@ void IGUIObject::ScriptEvent(const CStr& Action, JS::HandleValue Argument)

JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);

JS::AutoValueVector paramData(cx);
paramData.append(Argument.get());
JS::RootedObject obj(cx, GetJSObject());
Expand All @@ -501,13 +504,15 @@ JSObject* IGUIObject::GetJSObject()
{
JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
ScriptAutoRealm realm(m_pGUI->GetScriptInterface());
// Cache the object when somebody first asks for it, because otherwise
// we end up doing far too much object allocation. TODO: Would be nice to
// not have these objects hang around forever using up memory, though.
if (!m_JSObject.initialized())
{
m_JSObject.init(cx, m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject"));
JS_SetPrivate(m_JSObject.get(), this);
m_JSObject = js::Wrapper::New(cx, m_JSObject, &JSI_IGUIObject::singleton);
}
return m_JSObject.get();
}
Expand Down
2 changes: 1 addition & 1 deletion source/gui/IGUIObject.h
Expand Up @@ -85,7 +85,7 @@ class IGUIObject

// Allow getProperty to access things like GetParent()
friend bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp);
friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result);
friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue vp, JS::ObjectOpResult& result);
friend bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp);

public:
Expand Down

0 comments on commit f231c1d

Please sign in to comment.