VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
EngineCommands.cpp
1#include "components/EngineCommands.hpp"
2#include "Engine.hpp"
3#include "components/DebugConsole.hpp"
4#include "components/HardwareInfo.hpp"
6#include <string>
7#include <sstream>
8
9namespace vex {
10
13 static bool parseBool(const std::string& arg) {
14 return arg == "1" || arg == "true" || arg == "on";
15 }
16
18 static glm::vec3 parseVec3(const std::vector<std::string>& args, size_t startIndex) {
19 if (args.size() < startIndex + 3) return glm::vec3(0.0f);
20 return glm::vec3(std::stof(args[startIndex]), std::stof(args[startIndex+1]), std::stof(args[startIndex+2]));
21 }
22
23 void RegisterEngineCommands(Engine* engine) {
24 auto& console = DebugConsole::Get();
25
26 // sys commands
27 console.RegisterCommand("sys_info", [](auto args) {
28 vex::log(LogLevel::INFO, "--- SYSTEM ---");
29 vex::log(LogLevel::INFO, " CPU: %s", HardwareInfo::GetCPUName().c_str());
30 vex::log(LogLevel::INFO, " RAM: %s", HardwareInfo::GetSystemMemory().c_str());
31 vex::log(LogLevel::INFO, " AVX2 Support: %s", HardwareInfo::HasAVX2() ? "YES" : "NO");
32
33 vex::log(LogLevel::INFO, "--- GPU ---");
34 vex::log(LogLevel::INFO, " Device: %s", HardwareInfo::GetGPUName().c_str());
35 vex::log(LogLevel::INFO, " Driver: %s", HardwareInfo::GetDriverVersion().c_str());
36
37 vex::log(LogLevel::INFO, "--- VULKAN API ---");
38 vex::log(LogLevel::INFO, " Device Version: %s", HardwareInfo::GetVulkanDeviceVersion().c_str());
39 vex::log(LogLevel::INFO, " Requested Version: %s", HardwareInfo::GetVulkanRequestedVersion().c_str());
40
42 vex::log(LogLevel::INFO, "--- ENGINE FEATURES ---");
43 vex::log(LogLevel::INFO, " Multi-Draw Indirect: %s", feats.multiDraw ? "ENABLED" : "DISABLED");
44 vex::log(LogLevel::INFO, " Indirect Draw: %s", feats.indirectDraw ? "ENABLED" : "DISABLED");
45 vex::log(LogLevel::INFO, " Bindless Textures: %s", feats.bindlessTextures ? "ENABLED" : "DISABLED");
46 vex::log(LogLevel::INFO, " Shader Draw Params: %s", feats.shaderDrawParameters ? "ENABLED" : "DISABLED");
47
48 vex::log(LogLevel::INFO, " Build Hash: %s", Engine::GetBuildHash());
49 });
50
51 console.RegisterCommand("sys_fps_max", [engine](auto args) {
52 if (args.empty()) {
53 vex::log(LogLevel::INFO, "Current FPS Limit: %d", engine->getFrameLimit());
54 } else {
55 int limit = std::stoi(args[0]);
56 engine->setFrameLimit(limit);
57 vex::log(LogLevel::INFO, "FPS Limit set to %d", limit);
58 }
59 });
60
61 console.RegisterCommand("sys_vsync", [engine](auto args) {
62 if (args.empty()) {
63 vex::log(LogLevel::INFO, "VSync is %s", engine->getVSync() ? "ON" : "OFF");
64 } else {
65 bool enable = parseBool(args[0]);
66 engine->setVSync(enable);
67 vex::log(LogLevel::INFO, "VSync set to %s", enable ? "ON" : "OFF");
68 }
69 });
70
71 console.RegisterCommand("quit", [engine](auto args) {
72 engine->quit();
73 });
74
75 // scene commands
76 console.RegisterCommand("scene_load", [engine](auto args) {
77 if (args.empty()) {
78 vex::log(LogLevel::ERROR, "Usage: scene_load <filename.json>");
79 return;
80 }
81 std::string path = args[0];
82 engine->getSceneManager()->loadScene(path, *engine);
83 vex::log(LogLevel::INFO, "Loading scene: %s", path.c_str());
84 });
85
86 console.RegisterCommand("scene_list", [engine](auto args) {
87 auto scenes = engine->getSceneManager()->GetAllSceneNames();
88 vex::log(LogLevel::INFO, "--- Loaded Scenes ---");
89 for (const auto& name : scenes) {
90 vex::log(LogLevel::INFO, " > %s", name.c_str());
91 }
92 });
93
94 console.RegisterCommand("scene_reload", [engine](auto args) {
95 engine->prepareScenesForHotReload();
96 std::string last = engine->getSceneManager()->getLastSceneName();
97 if (!last.empty()) {
98 engine->getSceneManager()->loadScene(last, *engine);
99 vex::log(LogLevel::INFO, "Reloaded scene: %s", last.c_str());
100 }
101 });
102
103 // render commands
104 auto modifyEnv = [engine](std::function<void(environment&)> modFunc) {
105 environment env = engine->getEnvironmentSettings();
106 modFunc(env);
107 engine->setEnvironmentSettings(env);
108 };
109
110 console.RegisterCommand("r_ps1_jitter", [modifyEnv](auto args) {
111 if (args.empty()) return;
112 bool val = parseBool(args[0]);
113 modifyEnv([val](environment& e) {
114 e.passiveVertexJitter = val;
115 e.vertexSnapping = val;
116 });
117 vex::log(LogLevel::INFO, "PS1 Jitter/Snapping: %s", val ? "ON" : "OFF");
118 });
119
120 console.RegisterCommand("r_ps1_warp", [modifyEnv](auto args) {
121 if (args.empty()) return;
122 bool val = parseBool(args[0]);
123 modifyEnv([val](environment& e) { e.affineWarping = val; });
124 vex::log(LogLevel::INFO, "Affine Warping: %s", val ? "ON" : "OFF");
125 });
126
127 console.RegisterCommand("r_dither", [modifyEnv](auto args) {
128 if (args.empty()) return;
129 bool val = parseBool(args[0]);
130 modifyEnv([val](environment& e) { e.screenDither = val; });
131 vex::log(LogLevel::INFO, "Screen Dither: %s", val ? "ON" : "OFF");
132 });
133
134 console.RegisterCommand("r_crt", [modifyEnv](auto args) {
135 if (args.empty()) return;
136 bool val = parseBool(args[0]);
137 modifyEnv([val](environment& e) { e.ntfsArtifacts = val; });
138 vex::log(LogLevel::INFO, "CRT Artifacts: %s", val ? "ON" : "OFF");
139 });
140
141 console.RegisterCommand("r_resolution_mode", [engine](auto args) {
142 if (args.empty()) return;
143 int mode = std::stoi(args[0]);
144 engine->setResolutionMode(static_cast<ResolutionMode>(mode));
145 vex::log(LogLevel::INFO, "Resolution Mode set to: %d", mode);
146 });
147
148 console.RegisterCommand("r_ambient", [modifyEnv](auto args) {
149 if (args.size() < 4) {
150 vex::log(LogLevel::ERROR, "Usage: r_ambient <r> <g> <b> <strength>");
151 return;
152 }
153 glm::vec3 color = parseVec3(args, 0);
154 float strength = std::stof(args[3]);
155 modifyEnv([color, strength](environment& e) {
156 e.ambientLight = color;
157 e.ambientLightStrength = strength;
158 });
159 vex::log(LogLevel::INFO, "Ambient light updated");
160 });
161
162 // physics commands
163 console.RegisterCommand("phys_debug", [engine](auto args) {
164 if (args.empty()) return;
165 bool val = parseBool(args[0]);
166 engine->setRenderPhysicsDebug(val);
167 vex::log(LogLevel::INFO, "Physics Debug Draw: %s", val ? "ON" : "OFF");
168 });
169
170 console.RegisterCommand("phys_gravity", [engine](auto args) {
171 if (args.size() < 3) {
172 vex::log(LogLevel::ERROR, "Usage: phys_gravity <x> <y> <z>");
173 return;
174 }
175 glm::vec3 grav = parseVec3(args, 0);
176 if (auto* phys = engine->getPhysicsSystem()) {
177 phys->SetGravityVector(grav);
178 vex::log(LogLevel::INFO, "Gravity set to [%.2f, %.2f, %.2f]", grav.x, grav.y, grav.z);
179 }
180 });
181
182 console.RegisterCommand("phys_steps", [engine](auto args) {
183 if (args.empty()) return;
184 int steps = std::stoi(args[0]);
185 if (auto* phys = engine->getPhysicsSystem()) {
186 phys->setCollisionSteps(steps);
187 vex::log(LogLevel::INFO, "Physics steps set to %d", steps);
188 }
189 });
190 }
191}
Contains main Engine class.
This file defines SceneManager class.
Class for interaction with engine systems.
Definition Engine.hpp:47
static const char * GetBuildHash()
returns engine hash generated during build process.
Definition Engine.cpp:98
static std::string GetVulkanDeviceVersion()
Retrieves the Vulkan version supported by the device.
static std::string GetCPUName()
Retrieves the name of the CPU.
static bool HasAVX2()
Checks if the CPU supports the AVX2 instruction set.
static std::string GetVulkanRequestedVersion()
Retrieves the Vulkan version requested by the engine.
static VulkanFeatures GetVulkanFeatures()
Retrieves the active Vulkan features.
static std::string GetGPUName()
Retrieves the name of the GPU.
static std::string GetDriverVersion()
Retrieves the GPU driver version.
static std::string GetSystemMemory()
Retrieves the total amount of system memory.
ResolutionMode
Enumeration representing different resolution modes.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
Holds the status of various Vulkan features.
This struct is used to hold all environment settings. eg. shading details or lighting setup.