Polyphase Game Engine
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <string>
5
6#include "PolyphaseAPI.h"
7#include "EngineTypes.h"
8#include "Property.h"
9
10extern void OctPreInitialize(EngineConfig& config);
11extern void OctPostInitialize();
12extern void OctPreUpdate();
13extern void OctPostUpdate();
14extern void OctPreShutdown();
15extern void OctPostShutdown();
16
17// W1: Hook registration indirection. Today the engine static-lib path resolves
18// the six Oct* externs above at exe-link time (Standalone/Main.cpp,
19// Template/Main.cpp, or a user game's Main.cpp provides the defs). That extern
20// model can't cross the engine-DLL boundary, so the engine routes its hook
21// calls through this small function-pointer struct instead.
22//
23// - Static-lib builds (POLYPHASE_DLL_BUILD undefined): Engine/Source/Engine/OctHookAutoRegister.cpp
24// takes the address of the externs at static-init time and calls RegisterOctHooks().
25// Zero source change required of existing game projects.
26// - DLL builds (POLYPHASE_DLL_BUILD=1): the engine DLL has no Oct* externs in
27// its TUs. The consuming exe (POLYPHASE_DLL_CONSUMER=1) defines its own Oct*
28// and registers them via the DLL-exported RegisterOctHooks() at exe static
29// init — see Standalone/Source/Main.cpp.
31{
32 void (*preInitialize)(EngineConfig&) = nullptr;
33 void (*postInitialize)() = nullptr;
34 void (*preUpdate)() = nullptr;
35 void (*postUpdate)() = nullptr;
36 void (*preShutdown)() = nullptr;
37 void (*postShutdown)() = nullptr;
38};
41
42bool Initialize();
43
44bool Update();
45
46void Shutdown();
47
48void Quit();
49
50POLYPHASE_API class World* GetWorld(int32_t index);
53
54// Resolves shipped engine content ("Assets/", "Scripts/") to a readable path.
55// Prefers the root-relative "Engine/<subDir>" and falls back to
56// "<projectDir>Engine/<subDir>", which is where console packages end up when
57// they're deployed into a per-project folder on an SD card.
58POLYPHASE_API std::string GetEngineContentDir(const char* subDir);
59
63
64POLYPHASE_API const class Clock* GetAppClock();
65
66// Default scene names to search for when no explicit scene is specified
67// Developers can modify this list to add custom default scene names
68extern const std::vector<std::string>& GetDefaultSceneNames();
69void SetDefaultSceneNames(const std::vector<std::string>& names);
70
71
72bool IsShuttingDown();
73
74void LoadProject(const std::string& path, bool discoverAssets = true);
75
76// Close the currently-loaded project — symmetric counterpart to LoadProject.
77// Ends PIE, closes edit scenes, purges asset state, unloads the project
78// directory, clears loaded Lua scripts, and (when unloadNativeAddons=true)
79// FreeLibrary's every loaded native addon DLL. Leaves engine state empty
80// (mProjectDirectory == ""); the editor falls back to its no-project UI.
81// LoadProject calls this internally before loading a new path; callers that
82// just want the close half (e.g. Tools > Close Project, Tier-2 recovery)
83// invoke it directly. Editor-only — shipped runtimes have no close concept.
84#if EDITOR
85void CloseProject(bool unloadNativeAddons = true);
86#endif
87
88void EnableConsole(bool enable);
89
90void ResizeWindow(uint32_t width, uint32_t height);
91
93bool IsPlaying();
94
96// True only for -serve: a long-running headless process that loads native
97// addons and serves ControllerServer's REST API, as opposed to a one-shot
98// -headless -build cook. Implies IsHeadless().
100
101bool IsGameTickEnabled();
102
103void ReloadAllScripts(bool restartComponents = true);
104
105#if EDITOR
106void SetScriptHotReloadEnabled(bool enabled);
108#endif
109
110void SetPaused(bool paused);
111bool IsPaused();
112void FrameStep();
113
114void SetTimeDilation(float timeDilation);
115float GetTimeDilation();
116
117void GarbageCollect();
118
119void GatherGlobalProperties(std::vector<Property>& props);
120
123
124void WriteEngineConfig(std::string path = "");
125void ReadEngineConfig(std::string path = "");
126void ResetEngineConfig();
127
128// Rewrite the .octp project file's `name=` line in place. Preserves other lines
129// (assets=, solution=, etc.). Used to keep the .octp in sync when the project
130// name is edited via AppSettings, since the .octp is what packaging reads.
131void WriteProjectFile(const std::string& path, const std::string& newName);
132
133void ReadCommandLineArgs(int32_t argc, char** argv);
134
135
136#if LUA_ENABLED
137POLYPHASE_API lua_State* GetLua();
138#endif
bool IsScriptHotReloadEnabled()
Definition Engine.cpp:2008
void SetScriptHotReloadEnabled(bool enabled)
Definition Engine.cpp:1997
void OctPreShutdown()
Definition Main.cpp:105
POLYPHASE_API const class Clock * GetAppClock()
Definition Engine.cpp:1423
POLYPHASE_API const OctGameHooks & GetOctHooks()
Definition Engine.cpp:1418
const std::vector< std::string > & GetDefaultSceneNames()
Definition Engine.cpp:117
void WriteProjectFile(const std::string &path, const std::string &newName)
Definition Engine.cpp:2066
POLYPHASE_API bool IsHeadless()
Definition Engine.cpp:430
void SetTimeDilation(float timeDilation)
Definition Engine.cpp:2031
void ReadCommandLineArgs(int32_t argc, char **argv)
Definition Engine.cpp:440
bool Update()
Definition Engine.cpp:995
POLYPHASE_API void RegisterOctHooks(const OctGameHooks &hooks)
Definition Engine.cpp:1413
bool Initialize()
Definition Engine.cpp:635
void SetPaused(bool paused)
Definition Engine.cpp:2016
void ReadEngineConfig(std::string path="")
Definition Engine.cpp:2178
void WriteEngineConfig(std::string path="")
Definition Engine.cpp:2117
void FrameStep()
Definition Engine.cpp:2026
POLYPHASE_API class World * GetWorld(int32_t index)
Definition Engine.cpp:1380
void SetDefaultSceneNames(const std::vector< std::string > &names)
Definition Engine.cpp:122
void OctPostShutdown()
Definition Main.cpp:110
void OctPostInitialize()
Definition Main.cpp:90
void ResizeWindow(uint32_t width, uint32_t height)
Definition Engine.cpp:1847
POLYPHASE_API class SignalBus * GetSignalBus()
Definition SignalBus.cpp:7
bool IsPlaying()
Definition Engine.cpp:1875
void ResetEngineConfig()
Definition Engine.cpp:2335
void EnableConsole(bool enable)
Definition Engine.cpp:1841
bool IsPaused()
Definition Engine.cpp:2021
void OctPreUpdate()
Definition Main.cpp:95
void GarbageCollect()
Definition Engine.cpp:2041
POLYPHASE_API int32_t GetNumWorlds()
Definition Engine.cpp:1387
bool IsShuttingDown()
Definition Engine.cpp:1428
void LoadProject(const std::string &path, bool discoverAssets=true)
Definition Engine.cpp:1498
bool IsGameTickEnabled()
Definition Engine.cpp:1884
POLYPHASE_API struct EngineState * GetEngineState()
Definition Engine.cpp:1392
void Quit()
Definition Engine.cpp:1375
POLYPHASE_API bool IsHeadlessService()
Definition Engine.cpp:435
ScreenOrientation GetScreenOrientation()
Definition Engine.cpp:2061
POLYPHASE_API struct EngineConfig * GetMutableEngineConfig()
Definition Engine.cpp:1402
float GetTimeDilation()
Definition Engine.cpp:2036
void Shutdown()
Definition Engine.cpp:1298
POLYPHASE_API lua_State * GetLua()
Definition Engine.cpp:2341
POLYPHASE_API const struct EngineConfig * GetEngineConfig()
Definition Engine.cpp:1397
POLYPHASE_API std::string GetEngineContentDir(const char *subDir)
Definition Engine.cpp:594
void ReloadAllScripts(bool restartComponents=true)
Definition Engine.cpp:1893
void SetScreenOrientation(ScreenOrientation mode)
Definition Engine.cpp:2056
void OctPostUpdate()
Definition Main.cpp:100
bool IsPlayingInEditor()
Definition Engine.cpp:1866
void GatherGlobalProperties(std::vector< Property > &props)
Definition Engine.cpp:2047
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
ScreenOrientation
Definition SystemTypes.h:90
InitOptions OctPreInitialize()
Definition Main.cpp:20
Definition Clock.h:6
Definition SignalBus.h:45
Definition World.h:26
Definition EngineTypes.h:426
Definition EngineTypes.h:503
Definition Engine.h:31
void(* postInitialize)()
Definition Engine.h:33
void(* preUpdate)()
Definition Engine.h:34
void(* postShutdown)()
Definition Engine.h:37
void(* preShutdown)()
Definition Engine.h:36
void(* preInitialize)(EngineConfig &)
Definition Engine.h:32
void(* postUpdate)()
Definition Engine.h:35