Changeset View
Standalone View
source/ps/GameSetup/GameSetup.cpp
Show First 20 Lines • Show All 355 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
const bool init_mods = (flags & INIT_MODS) == INIT_MODS; | const bool init_mods = (flags & INIT_MODS) == INIT_MODS; | ||||
const bool add_user = !InDevelopmentCopy() && !args.Has("noUserMod"); | const bool add_user = !InDevelopmentCopy() && !args.Has("noUserMod"); | ||||
const bool add_public = (flags & INIT_MODS_PUBLIC) == INIT_MODS_PUBLIC; | const bool add_public = (flags & INIT_MODS_PUBLIC) == INIT_MODS_PUBLIC; | ||||
if (!init_mods) | if (!init_mods) | ||||
{ | { | ||||
// Add the user mod if it should be present | // Add the user mod if it should be present | ||||
if (add_user && (g_modsLoaded.empty() || g_modsLoaded.back() != "user")) | if (add_user && (g_modsToLoad.empty() || g_modsToLoad.back() != "user")) | ||||
g_modsLoaded.push_back("user"); | g_modsToLoad.push_back("user"); | ||||
return g_modsLoaded; | return g_modsToLoad; | ||||
} | } | ||||
g_modsLoaded = args.GetMultiple("mod"); | g_modsToLoad = args.GetMultiple("mod"); | ||||
if (add_public) | if (add_public) | ||||
g_modsLoaded.insert(g_modsLoaded.begin(), "public"); | g_modsToLoad.insert(g_modsToLoad.begin(), "public"); | ||||
g_modsLoaded.insert(g_modsLoaded.begin(), "mod"); | g_modsToLoad.insert(g_modsToLoad.begin(), "mod"); | ||||
// Add the user mod if not explicitly disabled or we have a dev copy so | // Add the user mod if not explicitly disabled or we have a dev copy so | ||||
// that saved files end up in version control and not in the user mod. | // that saved files end up in version control and not in the user mod. | ||||
if (add_user) | if (add_user) | ||||
g_modsLoaded.push_back("user"); | g_modsToLoad.push_back("user"); | ||||
return g_modsLoaded; | return g_modsToLoad; | ||||
} | } | ||||
void MountMods(const Paths& paths, const std::vector<CStr>& mods) | void MountMods(const Paths& paths, const std::vector<CStr>& mods) | ||||
{ | { | ||||
OsPath modPath = paths.RData()/"mods"; | OsPath modPath = paths.RData()/"mods"; | ||||
OsPath modUserPath = paths.UserData()/"mods"; | OsPath modUserPath = paths.UserData()/"mods"; | ||||
for (size_t i = 0; i < mods.size(); ++i) | for (size_t i = 0; i < mods.size(); ++i) | ||||
{ | { | ||||
Show All 12 Lines | if (InDevelopmentCopy()) | ||||
g_VFS->Mount(L"", modUserPath / modName/"", userFlags, priority); | g_VFS->Mount(L"", modUserPath / modName/"", userFlags, priority); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
g_VFS->Mount(L"", modPath / modName/"", baseFlags, priority); | g_VFS->Mount(L"", modPath / modName/"", baseFlags, priority); | ||||
// Ensure that user modified files are loaded, if they are present | // Ensure that user modified files are loaded, if they are present | ||||
g_VFS->Mount(L"", modUserPath / modName/"", userFlags, priority+1); | g_VFS->Mount(L"", modUserPath / modName/"", userFlags, priority+1); | ||||
} | } | ||||
CVFSFile modinfo; | |||||
if (modinfo.Load(g_VFS, "mod.json", false) != PSRETURN_OK) | |||||
continue; | |||||
// HERE IS WHERE WE WOULD PARSE JSON | |||||
elexis: You cant parse JSON without a spidermonkey context because the result needs to be allocated… | |||||
wraitiiUnsubmitted Not Done Inline ActionsWe could if we had a library to do it. wraitii: We could if we had a library to do it. | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsHow are you going to save a JS value without JS? elexis: How are you going to save a JS value without JS? | |||||
wraitiiUnsubmitted Not Done Inline ActionsI don't need a Js value, I want the version string here. wraitii: I don't need a Js value, I want the version string here. | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsIn C++ you need a type before you can read from it. A JS C++ library that doesn't parse all possible JSON strings is not a JS library. I'm currently trying to just create a new scriptinterface, but the g_ScriptRuntime isn't initialized when InitVFS is called yet too, so it's kind of a dead end. elexis: In C++ you need a type before you can read from it. A JS C++ library that doesn't parse all… | |||||
wraitiiUnsubmitted Not Done Inline ActionsSorry I feel like there's a misunderstanding here. I don't need a "JS Library", I just need something that parses JSON into something usable by C++, so that I can use the mod version and put it in my C++ thingy.
Are you referring to Spidermonkey? I feel like initialising a spider monkey runtime just for parsing "mod.json" to C++ is extremely overkill. We could initialise Spidermonkey at the very startup, and use it instead, but that feels like a bit of an anti-pattern. My approach is to parse mod.json in C++ without relying on the JS runtime. wraitii: Sorry I feel like there's a misunderstanding here. I don't need a "JS Library", I just need… | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsJSON = JavaScript Object Notation and it can hold any natively serializable JS object.
Importing a new library seems more lightweight?
Not sure what you mean with anti-pattern here. Initializing one thing before the other before using it seems right.
I don't feel understood. As I said, think about the data structures that are required to hold any JS object that can be expressed in JSON. elexis: JSON = JavaScript Object Notation and it can hold any natively serializable JS object.
> I… | |||||
/* JS::RootedValue json(cx); | |||||
if (!scriptInterface.ParseJSON(modinfo.GetAsString(), &json)) | |||||
continue; | |||||
*/ | |||||
CStr version; | |||||
// scriptInterface.GetProperty(json, "version", version); | |||||
g_modsMounted[modName.string8()] = version; | |||||
} | } | ||||
} | } | ||||
static void InitVfs(const CmdLineArgs& args, int flags) | static void InitVfs(const CmdLineArgs& args, int flags) | ||||
{ | { | ||||
TIMER(L"InitVfs"); | TIMER(L"InitVfs"); | ||||
const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0; | const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0; | ||||
Show All 16 Lines | static void InitVfs(const CmdLineArgs& args, int flags) | ||||
g_VFS = CreateVfs(); | g_VFS = CreateVfs(); | ||||
const OsPath readonlyConfig = paths.RData()/"config"/""; | const OsPath readonlyConfig = paths.RData()/"config"/""; | ||||
g_VFS->Mount(L"config/", readonlyConfig); | g_VFS->Mount(L"config/", readonlyConfig); | ||||
// Engine localization files. | // Engine localization files. | ||||
g_VFS->Mount(L"l10n/", paths.RData()/"l10n"/""); | g_VFS->Mount(L"l10n/", paths.RData()/"l10n"/""); | ||||
MountMods(paths, GetMods(args, flags)); | MountMods(paths, GetMods(args, flags)); | ||||
Not Done Inline ActionsAlso needs a CacheEnabledModVersions call? Imarok: Also needs a `CacheEnabledModVersions` call? | |||||
Not Done Inline ActionsIt's actually done in Init below. The decoupling is annoying but necessary atm, I think this should be fixed later. wraitii: It's actually done in Init below. The decoupling is annoying but necessary atm, I think this… | |||||
Not Done Inline ActionsThe problem that there is no ScriptRuntime at this point was mentioned already Imarok, no? elexis: The problem that there is no ScriptRuntime at this point was mentioned already Imarok, no?
If… | |||||
Not Done Inline ActionsAgreed. wraitii: Agreed. | |||||
// We mount these dirs last as otherwise writing could result in files being placed in a mod's dir. | // We mount these dirs last as otherwise writing could result in files being placed in a mod's dir. | ||||
g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); | g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); | ||||
g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH); | g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH); | ||||
// Mounting with highest priority, so that a mod supplied user.cfg is harmless | // Mounting with highest priority, so that a mod supplied user.cfg is harmless | ||||
g_VFS->Mount(L"config/", readonlyConfig, 0, (size_t)-1); | g_VFS->Mount(L"config/", readonlyConfig, 0, (size_t)-1); | ||||
if(readonlyConfig != paths.Config()) | if(readonlyConfig != paths.Config()) | ||||
g_VFS->Mount(L"config/", paths.Config(), 0, (size_t)-1); | g_VFS->Mount(L"config/", paths.Config(), 0, (size_t)-1); | ||||
▲ Show 20 Lines • Show All 498 Lines • ▼ Show 20 Lines | #endif | ||||
if (!args.Has("mod") && (flags & INIT_MODS) == INIT_MODS) | if (!args.Has("mod") && (flags & INIT_MODS) == INIT_MODS) | ||||
{ | { | ||||
CStr modstring; | CStr modstring; | ||||
CFG_GET_VAL("mod.enabledmods", modstring); | CFG_GET_VAL("mod.enabledmods", modstring); | ||||
if (!modstring.empty()) | if (!modstring.empty()) | ||||
{ | { | ||||
std::vector<CStr> mods; | std::vector<CStr> mods; | ||||
boost::split(mods, modstring, boost::is_any_of(" "), boost::token_compress_on); | boost::split(mods, modstring, boost::is_any_of(" "), boost::token_compress_on); | ||||
std::swap(g_modsLoaded, mods); | std::swap(g_modsToLoad, mods); | ||||
// Abort init and restart | // Abort init and restart | ||||
RestartEngine(); | RestartEngine(); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
new L10n; | new L10n; | ||||
▲ Show 20 Lines • Show All 695 Lines • Show Last 20 Lines |
You cant parse JSON without a spidermonkey context because the result needs to be allocated somewhere and is a JS value