Changeset View
Standalone View
source/ps/GameSetup/GameSetup.cpp
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/VertexBufferManager.h" | #include "renderer/VertexBufferManager.h" | ||||
#include "renderer/ModelRenderer.h" | #include "renderer/ModelRenderer.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptStats.h" | #include "scriptinterface/ScriptStats.h" | ||||
#include "scriptinterface/ScriptConversions.h" | #include "scriptinterface/ScriptConversions.h" | ||||
#include "scriptinterface/ScriptRuntime.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "lobby/IXmppClient.h" | #include "lobby/IXmppClient.h" | ||||
#include "soundmanager/scripting/JSInterface_Sound.h" | #include "soundmanager/scripting/JSInterface_Sound.h" | ||||
#include "soundmanager/ISoundManager.h" | #include "soundmanager/ISoundManager.h" | ||||
#include "tools/atlas/GameInterface/GameLoop.h" | #include "tools/atlas/GameInterface/GameLoop.h" | ||||
#include "tools/atlas/GameInterface/View.h" | #include "tools/atlas/GameInterface/View.h" | ||||
#if !(OS_WIN || OS_MACOSX || OS_ANDROID) // assume all other platforms use X11 for wxWidgets | #if !(OS_WIN || OS_MACOSX || OS_ANDROID) // assume all other platforms use X11 for wxWidgets | ||||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Lines | else | ||||
// 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); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static void InitVfs(const CmdLineArgs& args, int flags) | static void InitVfs(const CmdLineArgs& args, int flags) | ||||
{ | { | ||||
TIMER(L"InitVfs"); | TIMER(L"InitVfs"); | ||||
elexis: You cant parse JSON without a spidermonkey context because the result needs to be allocated… | |||||
Not Done Inline ActionsWe could if we had a library to do it. wraitii: We could if we had a library to do it. | |||||
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? | |||||
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. | |||||
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… | |||||
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… | |||||
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… | |||||
const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0; | const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0; | ||||
const Paths paths(args); | const Paths paths(args); | ||||
OsPath logs(paths.Logs()); | OsPath logs(paths.Logs()); | ||||
CreateDirectories(logs, 0700); | CreateDirectories(logs, 0700); | ||||
Show All 10 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)); | ||||
ImarokUnsubmitted Not Done Inline ActionsAlso needs a CacheEnabledModVersions call? Imarok: Also needs a `CacheEnabledModVersions` call? | |||||
wraitiiUnsubmitted 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… | |||||
elexisAuthorUnsubmitted 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… | |||||
wraitiiUnsubmitted 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 465 Lines • ▼ Show 20 Lines | bool Init(const CmdLineArgs& args, int flags) | ||||
CONFIG_Init(args); | CONFIG_Init(args); | ||||
// Using a global object for the runtime is a workaround until Simulation and AI use | // Using a global object for the runtime is a workaround until Simulation and AI use | ||||
// their own threads and also their own runtimes. | // their own threads and also their own runtimes. | ||||
const int runtimeSize = 384 * 1024 * 1024; | const int runtimeSize = 384 * 1024 * 1024; | ||||
const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; | const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; | ||||
g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger); | g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger); | ||||
Mod::CacheEnabledModVersions(g_ScriptRuntime); | |||||
// Special command-line mode to dump the entity schemas instead of running the game. | // Special command-line mode to dump the entity schemas instead of running the game. | ||||
// (This must be done after loading VFS etc, but should be done before wasting time | // (This must be done after loading VFS etc, but should be done before wasting time | ||||
// on anything else.) | // on anything else.) | ||||
if (args.Has("dumpSchema")) | if (args.Has("dumpSchema")) | ||||
{ | { | ||||
CSimulation2 sim(NULL, g_ScriptRuntime, NULL); | CSimulation2 sim(NULL, g_ScriptRuntime, NULL); | ||||
sim.LoadDefaultScripts(); | sim.LoadDefaultScripts(); | ||||
std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc); | std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc); | ||||
▲ Show 20 Lines • Show All 729 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