CVar system and systems to disable both gameplay and UI

This commit is contained in:
Safariminer 2025-08-01 15:37:31 -04:00
parent b33ddd47ca
commit 9c7a3219d9
13 changed files with 121 additions and 120 deletions

View File

@ -0,0 +1,3 @@
vid_3d_renderer true
vid_3d_grid false
vid_2d_background false

View File

@ -2,4 +2,6 @@ echo "GMTK 2025"
echo "Made with MPFW" echo "Made with MPFW"
echo "" echo ""
show_cursor show_cursor
disable_game
ui_show
ui_create_window "data/menus/mainmenu.wnd" ui_create_window "data/menus/mainmenu.wnd"

View File

@ -0,0 +1,3 @@
vid_3d_renderer true
vid_3d_grid false
vid_2d_background false

8
gmtk2025/imgui.ini Normal file
View File

@ -0,0 +1,8 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
[Window][GMTK 2025]
Pos=57,64
Size=262,178

View File

@ -1,16 +0,0 @@
#include "MPFW_CVars.h"
#include <string>
std::variant<std::string, int> MPFW::CVar::get() {
try {
int retval = std::stoi(value);
return retval;
}
catch(...){
return value;
}
}

View File

@ -1,17 +0,0 @@
#pragma once
#include <iostream>
#include <map>
#include <variant>
namespace MPFW {
class CVar {
public:
std::string value;
std::variant<std::string, int> get();
};
using CVarMap = std::map<std::string, CVar>;
}

View File

@ -1,9 +1,12 @@
#include <raylib.h>
#include "MPFW_Console.h" #include "MPFW_Console.h"
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
MPFW_ConsoleCommand(echo) { MPFW_ConsoleCommand(echo) {
for (int i = 0; i < cmd.size(); i++) { for (int i = 0; i < cmd.size(); i++) {
*logStr += std::format("{} ", cmd[i]); *logStr += std::format("{} ", cmd[i]);
@ -31,9 +34,15 @@ MPFW_ConsoleCommand(ui_create_window) {
} }
} }
MPFW_ConsoleCommand(ui_show) {
ctx->ui->rendererIsActive = true;
}
MPFW_ConsoleCommand(ui_hide) {
ctx->ui->rendererIsActive = false;
}
MPFW_ConsoleCommand(ui_delete_window) { MPFW_ConsoleCommand(ui_delete_window) {
if (cmd.size() != 1) { if (cmd.size() != 1) {
} }
} }
@ -79,18 +88,46 @@ MPFW_ConsoleCommand(map_mpfw) {
*logStr += "Mode MPFW has no \"map\" command because it has no available map format.\n\nUse one of these modes instead:\n - 'mode 1' : QUAKE\n\n"; *logStr += "Mode MPFW has no \"map\" command because it has no available map format.\n\nUse one of these modes instead:\n - 'mode 1' : QUAKE\n\n";
} }
MPFW_ConsoleCommand(disable_game) {
ctx->gameDisabled = true;
}
MPFW_ConsoleCommand(enable_game) {
ctx->gameDisabled = false;
}
MPFW_ConsoleCommand(set) { MPFW_ConsoleCommand(set) {
if (cmd.size() == 2) {
ctx->cvars[cmd[0]] = cmd[1];
}
} }
MPFW_ConsoleCommand(show_cursor) {
ctx->ui->showCursorOnLaunch = true;
EnableCursor();
}
MPFW_ConsoleCommand(hide_cursor) {
ctx->ui->showCursorOnLaunch = false;
DisableCursor();
}
MPFW::Console::CommandHandler::CommandHandler(CommandHandlerResources* c) MPFW::Console::CommandHandler::CommandHandler(CommandHandlerResources* c)
{ {
chr = c; chr = c;
chr->cvars.clear();
std::ifstream cvarFile("data/sys/cvardefs.cvars");
std::string cvarLine;
while (std::getline(cvarFile, cvarLine)) {
std::vector<std::string> line = parseCommand(cvarLine);
chr->cvars[line[0]] = line[1];
}
#pragma region #pragma region
@ -99,6 +136,12 @@ MPFW::Console::CommandHandler::CommandHandler(CommandHandlerResources* c)
// elemental commands work. less important commands will be // elemental commands work. less important commands will be
// defined with a definition instantiator or some random shit // defined with a definition instantiator or some random shit
CommandID mpfwSet = { MPFW, "set" };
CommandID quakeSet = { QUAKE, "set" };
functionMap[mpfwSet] = set;
functionMap[quakeSet] = set;
CommandID mpfwEcho = { MPFW, "echo" }; CommandID mpfwEcho = { MPFW, "echo" };
CommandID quakeEcho = { QUAKE, "echo" }; CommandID quakeEcho = { QUAKE, "echo" };
functionMap[mpfwEcho] = echo; functionMap[mpfwEcho] = echo;
@ -125,6 +168,25 @@ MPFW::Console::CommandHandler::CommandHandler(CommandHandlerResources* c)
CommandID uiCreateWindow = { MPFW, "ui_create_window" }; CommandID uiCreateWindow = { MPFW, "ui_create_window" };
functionMap[uiCreateWindow] = ui_create_window; functionMap[uiCreateWindow] = ui_create_window;
CommandID uiShow = { MPFW, "ui_show" };
functionMap[uiShow] = ui_show;
CommandID uiHide = { MPFW, "ui_hide" };
functionMap[uiHide] = ui_hide;
CommandID mpfwShowCursor = { MPFW, "show_cursor" };
functionMap[mpfwShowCursor] = show_cursor;
CommandID mpfwHideCursor = { MPFW, "hide_cursor" };
functionMap[mpfwHideCursor] = hide_cursor;
CommandID mpfwEnableGame = { MPFW, "enable_game" };
functionMap[mpfwEnableGame] = enable_game;
CommandID mpfwDisableGame = { MPFW, "disable_game" };
functionMap[mpfwDisableGame] = disable_game;
#pragma endregion System Commands #pragma endregion System Commands

View File

@ -20,6 +20,8 @@ namespace MPFW {
Quake::Maps::MapFile* mapQuake; Quake::Maps::MapFile* mapQuake;
OperationMode mode = MPFW; OperationMode mode = MPFW;
UI::UIRenderer* ui; UI::UIRenderer* ui;
std::map<std::string, std::string> cvars;
bool gameDisabled = false;
}; };
@ -63,7 +65,7 @@ namespace MPFW{
CommandHandlerResources* chr; CommandHandlerResources* chr;
std::unordered_map<CommandID, std::function<void(std::vector<std::string>,CommandHandlerResources*, std::string*)>> functionMap; std::unordered_map<CommandID, std::function<void(std::vector<std::string>,CommandHandlerResources*, std::string*)>> functionMap;
public: public:
[[deprecated("Never initialize an empty command handler")]] [[deprecated("Never initialize an empty command handler")]]
CommandHandler() { throw; } CommandHandler() { throw; }

View File

@ -40,7 +40,7 @@ namespace MPFW {
class UIRenderer { class UIRenderer {
bool cursorState = false; // false = off, true = on bool cursorState = false; // false = off, true = on
public: public:
bool showCursorOnLaunch = false;
UIRenderer(); UIRenderer();
bool rendererIsActive = false; bool rendererIsActive = false;
MPFW::Console::CommandHandler* cmh; MPFW::Console::CommandHandler* cmh;

View File

@ -135,47 +135,7 @@ int main() {
#endif #endif
MPFW::Quake::Maps::MapFile map; MPFW::Quake::Maps::MapFile map;
// std::thread t(__DebugCounter_Quake, &map);
// t.detach();
std::vector<Color> colors;
for (int i = 0; i < 3000000; i++) {
colors.push_back({ (unsigned char)GetRandomValue(0, 255), (unsigned char)GetRandomValue(0, 255), (unsigned char)GetRandomValue(0, 255), 255 });
}
std::print("MAP DATA:\n---------\n\n");
std::print("Version: {}\n", map.data.header.version);
std::print("\n---\nDIRENTS\n-------\n");
std::print("Entities: {}\n", map.data.header.entities);
std::print("Planes: {}\n", map.data.header.planes);
std::print("Wall Textures (miptex): {}\n", map.data.header.miptex);
std::print("Map Vertices: {}\n", map.data.header.vertices);
std::print("Leaves Visibility Lists: {}\n", map.data.header.visilist);
std::print("BSP Nodes: {}\n", map.data.header.nodes);
std::print("Texture Info for Faces: {}\n", map.data.header.texinfo);
std::print("Faces of each surface: {}\n", map.data.header.faces);
std::print("Wall Lightmaps: {}\n", map.data.header.lightmaps);
std::print("Clip Nodes: {}\n", map.data.header.clipnodes);
std::print("BSP Leaves: {}\n", map.data.header.leaves);
std::print("List of Faces: {}\n", map.data.header.lface);
std::print("Edges of Faces: {}\n", map.data.header.edges);
std::print("List of Edges: {}\n", map.data.header.ledges);
std::print("Models: {}\n", map.data.header.models);
std::print("---\n\n");
std::print("Vertex count: {} (on {} in header)\n", map.data.vertices.size(), map.data.header.vertices.size / sizeof(Vector3));
std::print("Edge count: {} (on {} in header)\n", map.data.edges.size(), map.data.header.edges.size / 4);
std::print("Model count: {} (on {} in header)\n", map.data.models.size(), map.data.header.models.size / sizeof(MPFW::Quake::Maps::qModel));
for (int i = 0; i < map.data.models.size(); i++) {
if (map.data.models[i].node_id3 != 0) {
std::print("node 3 on {} isn't 0 ({})\n", i, map.data.models[i].node_id3);
}
}
map.pal = new MPFW::Quake::Maps::Palette("data/palette.lmp"); map.pal = new MPFW::Quake::Maps::Palette("data/palette.lmp");
SetConfigFlags(FLAG_WINDOW_RESIZABLE); SetConfigFlags(FLAG_WINDOW_RESIZABLE);
@ -221,7 +181,7 @@ int main() {
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
if (framebuffer < 5) { if (framebuffer < 5 && !uiRenderer.showCursorOnLaunch) {
DisableCursor(); DisableCursor();
framebuffer++; framebuffer++;
@ -230,7 +190,7 @@ int main() {
if (IsKeyPressed(KEY_APOSTROPHE)) { if (IsKeyPressed(KEY_APOSTROPHE)) {
consoleOn = !consoleOn; consoleOn = !consoleOn;
} }
if(!consoleOn){ if(!consoleOn && IsCursorHidden()){
Look(); Look();
Vector3 wishVel = { 0,0,0 }; Vector3 wishVel = { 0,0,0 };
wishSpeed = 320; wishSpeed = 320;
@ -271,9 +231,11 @@ int main() {
velocity *= {GetFrameTime(), 1, GetFrameTime()}; velocity *= {GetFrameTime(), 1, GetFrameTime()};
camera.position += velocity;
camera.target = camera.position + rotation;
} }
if (IsKeyPressed(KEY_ESCAPE)) { if (IsKeyPressed(KEY_ESCAPE) && !chr.gameDisabled) {
if (IsCursorHidden()) { if (IsCursorHidden()) {
EnableCursor(); EnableCursor();
uiRenderer.rendererIsActive = true; uiRenderer.rendererIsActive = true;
@ -284,47 +246,47 @@ int main() {
} }
} }
camera.position += velocity;
camera.target = camera.position + rotation;
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawRectangleGradientV(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE, LIGHTGRAY); if (chr.cvars["vid_2d_background"] == "true") DrawRectangleGradientV(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE, LIGHTGRAY);
BeginMode3D(camera); if (chr.cvars["vid_3d_renderer"] == "true") {
DrawGrid(10000, 10); BeginMode3D(camera);
if(chr.cvars["vid_3d_grid"] == "true") DrawGrid(10000, 10);
for (int i = 0; i < map.data.renderFaces.size(); i++) {
rlColor4ub(255, 255, 255, 255); for (int i = 0; i < map.data.renderFaces.size(); i++) {
rlSetTexture(map.data.renderFaces[i].glTextureId); rlColor4ub(255, 255, 255, 255);
rlSetTexture(map.data.renderFaces[i].glTextureId);
for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) { for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) {
rlBegin(RL_QUADS); // for texturing reasons because rlgl rlBegin(RL_QUADS); // for texturing reasons because rlgl
Vector3 a = map.data.renderFaces[i].vertices[0], Vector3 a = map.data.renderFaces[i].vertices[0],
b = map.data.renderFaces[i].vertices[j], b = map.data.renderFaces[i].vertices[j],
c = map.data.renderFaces[i].vertices[j - 1]; c = map.data.renderFaces[i].vertices[j - 1];
Vector2 at = map.data.renderFaces[i].texCoords[0], Vector2 at = map.data.renderFaces[i].texCoords[0],
bt = map.data.renderFaces[i].texCoords[j], bt = map.data.renderFaces[i].texCoords[j],
ct = map.data.renderFaces[i].texCoords[j - 1]; ct = map.data.renderFaces[i].texCoords[j - 1];
rlTexCoord2f(at.x, at.y); rlTexCoord2f(at.x, at.y);
rlVertex3f(a.x, a.y, a.z); rlVertex3f(a.x, a.y, a.z);
rlTexCoord2f(bt.x, bt.y); rlTexCoord2f(bt.x, bt.y);
rlVertex3f(b.x, b.y, b.z); rlVertex3f(b.x, b.y, b.z);
rlTexCoord2f(ct.x, ct.y); rlTexCoord2f(ct.x, ct.y);
rlVertex3f(c.x, c.y, c.z); rlVertex3f(c.x, c.y, c.z);
rlVertex3f(c.x, c.y, c.z); rlVertex3f(c.x, c.y, c.z);
rlEnd();
}
rlEnd();
} }
EndMode3D();
} }
EndMode3D();
DrawFPS(0, 0); DrawFPS(0, 0);
if (consoleOn) { if (consoleOn) {

View File

@ -146,7 +146,6 @@
<ClCompile Include="..\deps\include\rlImGui.cpp" /> <ClCompile Include="..\deps\include\rlImGui.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="MPFW_Console.cpp" /> <ClCompile Include="MPFW_Console.cpp" />
<ClCompile Include="MPFW_CVars.cpp" />
<ClCompile Include="MPFW_HL.cpp" /> <ClCompile Include="MPFW_HL.cpp" />
<ClCompile Include="MPFW_Net.cpp" /> <ClCompile Include="MPFW_Net.cpp" />
<ClCompile Include="MPFW_Quake.cpp" /> <ClCompile Include="MPFW_Quake.cpp" />
@ -155,7 +154,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="MPFW_Console.h" /> <ClInclude Include="MPFW_Console.h" />
<ClInclude Include="MPFW_CVars.h" />
<ClInclude Include="MPFW_HL.h" /> <ClInclude Include="MPFW_HL.h" />
<ClInclude Include="MPFW_MPFWMF.h" /> <ClInclude Include="MPFW_MPFWMF.h" />
<ClInclude Include="MPFW_Net.h" /> <ClInclude Include="MPFW_Net.h" />

View File

@ -33,9 +33,6 @@
<ClCompile Include="MPFW_Console.cpp"> <ClCompile Include="MPFW_Console.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MPFW_CVars.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\deps\include\pugixml.cpp"> <ClCompile Include="..\deps\include\pugixml.cpp">
<Filter>ext.</Filter> <Filter>ext.</Filter>
</ClCompile> </ClCompile>
@ -80,9 +77,6 @@
<ClInclude Include="MPFW_Console.h"> <ClInclude Include="MPFW_Console.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="MPFW_CVars.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MPFW_UI.h"> <ClInclude Include="MPFW_UI.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)/gmtk2025</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>$(SolutionDir)/gameenv</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)/gmtk2025</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>$(SolutionDir)/gameenv</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
</Project> </Project>