Skip to content

Commit

Permalink
Put editor behind cli flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammie committed Jan 11, 2024
1 parent 2230f01 commit 453ab82
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class StormEngine(ConanFile):
# conan-center
requires = ["zlib/1.2.13", "spdlog/1.9.2", "fast_float/3.4.0", "mimalloc/2.0.3", "sentry-native/0.6.5", "tomlplusplus/3.3.0", "nlohmann_json/3.11.2",
"imgui/1.90-docking",
"cli11/2.3.2",
# storm.jfrog.io
"directx/9.0@storm/prebuilt", "fmod/2.02.05@storm/prebuilt"]
# aux dependencies (e.g. for tests)
Expand Down
1 change: 1 addition & 0 deletions src/apps/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ STORM_SETUP(
sentry-native
${SDL2_LIBRARIES}
zlib
cli11

# system
${SYSTEM_DEPS}
Expand Down
16 changes: 16 additions & 0 deletions src/apps/engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mimalloc-new-delete.h>
#include <mimalloc.h>
#include <spdlog/spdlog.h>
#include <CLI/CLI.hpp>

#include "core_private.h"
#include "fs.h"
Expand Down Expand Up @@ -120,6 +121,20 @@ void HandleWindowEvent(const storm::OSWindow::Event &event)

int main(int argc, char *argv[])
{
CLI::App app("Storm Engine");

bool enable_editor = false;
app.add_flag("--editor", enable_editor, "Enable in-game editor");

try
{
app.parse(argc, argv);
}
catch (const CLI::ParseError &e)
{
return app.exit(e);
}

// Prevent multiple instances
#ifdef _WIN32 // CreateEventA
if (!CreateEventA(nullptr, false, false, "Global\\FBBD2286-A9F1-4303-B60C-743C3D7AA7BE") ||
Expand Down Expand Up @@ -171,6 +186,7 @@ int main(int argc, char *argv[])

// Init core
core_private = static_cast<CorePrivate *>(&core);
core_private->EnableEditor(enable_editor);
core_private->Init();

// Read config
Expand Down
1 change: 1 addition & 0 deletions src/libs/core/include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Core
virtual ~Core() = default;

virtual void InitializeEditor(IDirect3DDevice9 *device) = 0;
virtual bool IsEditorEnabled() = 0;

// return application window
virtual storm::OSWindow *GetWindow() = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/core/include/core_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ class CorePrivate : public Core
virtual void collectCrashInfo() const = 0;

virtual void SetWindow(std::shared_ptr<storm::OSWindow> window) = 0;

virtual void EnableEditor(bool enable) = 0;
};
10 changes: 10 additions & 0 deletions src/libs/core/src/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ void CoreImpl::InitializeEditor(IDirect3DDevice9 *device)
editor_ = std::make_unique<storm::editor::EngineEditor>(GetWindow()->SDLHandle(), device);
}

bool CoreImpl::IsEditorEnabled()
{
return isEditorEnabled_;
}

void CoreImpl::EnableEditor(bool enable)
{
isEditorEnabled_ = enable;
}

void CoreImpl::InitBase()
{
LoadClassesTable();
Expand Down
3 changes: 3 additions & 0 deletions src/libs/core/src/core_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CoreImpl final : public CorePrivate
public:
void Init() override;
void InitializeEditor(IDirect3DDevice9 *device) override;
bool IsEditorEnabled() override;
void EnableEditor(bool enable) override;

void InitBase() override;
void ReleaseBase() override;
Expand Down Expand Up @@ -169,6 +171,7 @@ class CoreImpl final : public CorePrivate
char gstring[MAX_PATH]{}; // general purpose string
bool State_loading;
bool bEnableTimeScale{};
bool isEditorEnabled_ = false;

SERVICES_LIST Services_List; // list for subsequent calls RunStart/RunEnd service functions

Expand Down
5 changes: 4 additions & 1 deletion src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,10 @@ bool DX9RENDER::InitDevice(bool windowed, HWND _hwnd, int32_t width, int32_t hei
effects_.setDevice(d3d9);
#endif

core.InitializeEditor(d3d9);
if (core.IsEditorEnabled() )
{
core.InitializeEditor(d3d9);
}

// Create render targets for POST PROCESS effects
d3d9->GetRenderTarget(0, &pOriginalScreenSurface);
Expand Down
7 changes: 6 additions & 1 deletion src/libs/xinterface/src/xinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,12 @@ void XINTERFACE::LoadIni()
vMouse[2].tu = vMouse[3].tu = 1.f;
vMouse[0].tv = vMouse[2].tv = 0.f;
vMouse[1].tv = vMouse[3].tv = 1.f;

#ifdef _WIN32 // FIX_LINUX Cursor
if (auto *editor = core.GetEditor(); editor == nullptr || !editor->IsFocused())
{
ShowCursor(false);
}
#endif
// set blind parameters
m_fBlindSpeed = ini->GetFloat(section, "BlindTime", 1.f);
if (m_fBlindSpeed <= 0.0001f)
Expand Down

0 comments on commit 453ab82

Please sign in to comment.