Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ComponentManager.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
m_CurrentlyHotloading = hotload; | m_CurrentlyHotloading = hotload; | ||||
CVFSFile file; | CVFSFile file; | ||||
PSRETURN loadOk = file.Load(g_VFS, filename); | PSRETURN loadOk = file.Load(g_VFS, filename); | ||||
if (loadOk != PSRETURN_OK) // VFS will log the failed file and the reason | if (loadOk != PSRETURN_OK) // VFS will log the failed file and the reason | ||||
return false; | return false; | ||||
std::string content = file.DecodeUTF8(); // assume it's UTF-8 | std::string content = file.DecodeUTF8(); // assume it's UTF-8 | ||||
bool ok = m_ScriptInterface.LoadScript(filename, content); | bool ok = m_ScriptInterface.LoadScript(filename, content); | ||||
m_CurrentlyHotloading = false; | |||||
Itms: This was a huge oversight! | |||||
wraitiiUnsubmitted Not Done Inline ActionsTBH this feels like it could be committed separately, but not a huge problem. wraitii: TBH this feels like it could be committed separately, but not a huge problem. | |||||
return ok; | return ok; | ||||
} | } | ||||
void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor, bool reRegister, bool systemComponent) | void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor, bool reRegister, bool systemComponent) | ||||
{ | { | ||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | ||||
JSContext* cx = componentManager->m_ScriptInterface.GetContext(); | JSContext* cx = componentManager->m_ScriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | void CComponentManager::Script_RegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor) | ||||
componentManager->Script_RegisterComponentType_Common(pCxPrivate, iid, cname, ctor, false, false); | componentManager->Script_RegisterComponentType_Common(pCxPrivate, iid, cname, ctor, false, false); | ||||
componentManager->m_ScriptInterface.SetGlobal(cname.c_str(), ctor, componentManager->m_CurrentlyHotloading); | componentManager->m_ScriptInterface.SetGlobal(cname.c_str(), ctor, componentManager->m_CurrentlyHotloading); | ||||
} | } | ||||
void CComponentManager::Script_RegisterSystemComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor) | void CComponentManager::Script_RegisterSystemComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor) | ||||
{ | { | ||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | ||||
componentManager->Script_RegisterComponentType_Common(pCxPrivate, iid, cname, ctor, false, true); | componentManager->Script_RegisterComponentType_Common(pCxPrivate, iid, cname, ctor, false, true); | ||||
componentManager->m_ScriptInterface.SetGlobal(cname.c_str(), ctor, componentManager->m_CurrentlyHotloading); | componentManager->m_ScriptInterface.SetGlobal(cname.c_str(), ctor, componentManager->m_CurrentlyHotloading); | ||||
Not Done Inline ActionsThis makes me think we should use enums (or possibly #define XXX true) instead, reading true, true, true isn't very helpful. wraitii: This makes me think we should use enums (or possibly #define XXX true) instead, reading `true… | |||||
Done Inline ActionsIdeally, those would be named parameters, true by default, but we can't export facultative parameters from C++ to JS ? Itms: Ideally, those would be named parameters, `true` by default, but we can't export facultative… | |||||
Not Done Inline ActionsA flag int? elexis: A flag int? | |||||
} | } | ||||
void CComponentManager::Script_ReRegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor) | void CComponentManager::Script_ReRegisterComponentType(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor) | ||||
{ | { | ||||
Script_RegisterComponentType_Common(pCxPrivate, iid, cname, ctor, true, false); | Script_RegisterComponentType_Common(pCxPrivate, iid, cname, ctor, true, false); | ||||
} | } | ||||
void CComponentManager::Script_RegisterInterface(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name) | void CComponentManager::Script_RegisterInterface(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name) | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void CComponentManager::Script_RegisterMessageType(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name) | ||||
size_t id = componentManager->m_MessageTypeIdsByName.size() + 1; | size_t id = componentManager->m_MessageTypeIdsByName.size() + 1; | ||||
componentManager->RegisterMessageType((MessageTypeId)id, name.c_str()); | componentManager->RegisterMessageType((MessageTypeId)id, name.c_str()); | ||||
componentManager->m_ScriptInterface.SetGlobal(("MT_" + name).c_str(), (int)id); | componentManager->m_ScriptInterface.SetGlobal(("MT_" + name).c_str(), (int)id); | ||||
} | } | ||||
void CComponentManager::Script_RegisterGlobal(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name, JS::HandleValue value) | void CComponentManager::Script_RegisterGlobal(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name, JS::HandleValue value) | ||||
{ | { | ||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | ||||
// Set the value, and accept duplicates only if hotloading (otherwise it's an error, | |||||
// in order to detect accidental duplicate definitions of globals) | |||||
componentManager->m_ScriptInterface.SetGlobal(name.c_str(), value, componentManager->m_CurrentlyHotloading); | componentManager->m_ScriptInterface.SetGlobal(name.c_str(), value, componentManager->m_CurrentlyHotloading); | ||||
} | } | ||||
IComponent* CComponentManager::Script_QueryInterface(ScriptInterface::CxPrivate* pCxPrivate, int ent, int iid) | IComponent* CComponentManager::Script_QueryInterface(ScriptInterface::CxPrivate* pCxPrivate, int ent, int iid) | ||||
{ | { | ||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | ||||
IComponent* component = componentManager->QueryInterface((entity_id_t)ent, iid); | IComponent* component = componentManager->QueryInterface((entity_id_t)ent, iid); | ||||
return component; | return component; | ||||
▲ Show 20 Lines • Show All 776 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This was a huge oversight!