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 ""
show_cursor
disable_game
ui_show
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 <string>
#include <fstream>
#include <sstream>
MPFW_ConsoleCommand(echo) {
for (int i = 0; i < cmd.size(); 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) {
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";
}
MPFW_ConsoleCommand(disable_game) {
ctx->gameDisabled = true;
}
MPFW_ConsoleCommand(enable_game) {
ctx->gameDisabled = false;
}
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)
{
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
@ -99,6 +136,12 @@ MPFW::Console::CommandHandler::CommandHandler(CommandHandlerResources* c)
// elemental commands work. less important commands will be
// 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 quakeEcho = { QUAKE, "echo" };
functionMap[mpfwEcho] = echo;
@ -125,6 +168,25 @@ MPFW::Console::CommandHandler::CommandHandler(CommandHandlerResources* c)
CommandID uiCreateWindow = { MPFW, "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

View File

@ -20,6 +20,8 @@ namespace MPFW {
Quake::Maps::MapFile* mapQuake;
OperationMode mode = MPFW;
UI::UIRenderer* ui;
std::map<std::string, std::string> cvars;
bool gameDisabled = false;
};

View File

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

View File

@ -135,46 +135,6 @@ int main() {
#endif
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");
@ -221,7 +181,7 @@ int main() {
while (!WindowShouldClose()) {
if (framebuffer < 5) {
if (framebuffer < 5 && !uiRenderer.showCursorOnLaunch) {
DisableCursor();
framebuffer++;
@ -230,7 +190,7 @@ int main() {
if (IsKeyPressed(KEY_APOSTROPHE)) {
consoleOn = !consoleOn;
}
if(!consoleOn){
if(!consoleOn && IsCursorHidden()){
Look();
Vector3 wishVel = { 0,0,0 };
wishSpeed = 320;
@ -271,9 +231,11 @@ int main() {
velocity *= {GetFrameTime(), 1, GetFrameTime()};
camera.position += velocity;
camera.target = camera.position + rotation;
}
if (IsKeyPressed(KEY_ESCAPE)) {
if (IsKeyPressed(KEY_ESCAPE) && !chr.gameDisabled) {
if (IsCursorHidden()) {
EnableCursor();
uiRenderer.rendererIsActive = true;
@ -284,14 +246,13 @@ int main() {
}
}
camera.position += velocity;
camera.target = camera.position + rotation;
BeginDrawing();
ClearBackground(BLACK);
DrawRectangleGradientV(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE, LIGHTGRAY);
if (chr.cvars["vid_2d_background"] == "true") DrawRectangleGradientV(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE, LIGHTGRAY);
if (chr.cvars["vid_3d_renderer"] == "true") {
BeginMode3D(camera);
DrawGrid(10000, 10);
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);
@ -325,6 +286,7 @@ int main() {
}
EndMode3D();
}
DrawFPS(0, 0);
if (consoleOn) {

View File

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

View File

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

View File

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