diff --git a/gameenv/data/sys/cvardefs.cvars b/gameenv/data/sys/cvardefs.cvars index cce33e4..c89ff78 100644 --- a/gameenv/data/sys/cvardefs.cvars +++ b/gameenv/data/sys/cvardefs.cvars @@ -1,3 +1,6 @@ +vid_2d_background false vid_3d_renderer true vid_3d_grid false -vid_2d_background false \ No newline at end of file +vid_3d_cull_sky false +vid_3d_cull_clips true +vid_3d_cull_triggers true \ No newline at end of file diff --git a/mpfw/MPFW_BackendDefinition.h b/mpfw/MPFW_BackendDefinition.h new file mode 100644 index 0000000..6d35381 --- /dev/null +++ b/mpfw/MPFW_BackendDefinition.h @@ -0,0 +1,61 @@ +#pragma once +#include +#include + +namespace MPFW { + namespace Backends { + namespace Video { + namespace Agnostic { + struct Color { + unsigned char r, g, b, a; + }; + struct Picture { + std::vector data; + int width, height; + }; + struct Vertex2D { + float x, y; + }; + struct Vertex3D { + float x, y, z; + }; + struct Vertex4D { + float x, y, z, w; + }; + struct Triangle { + Vertex3D a, b, c; + }; + struct TexturedTriangle { + Triangle tri; + int textureId; + }; + } + + + + struct ContextParameters { + std::string name; + int width, height, desiredFps; + }; + + + // note: backend inputs should ALWAYS be in quake coords + // note 2: backends should ideally implement all functions. + class BackEnd { + public: + virtual void Create(ContextParameters param) = 0; + + virtual int BE_LoadFont(std::string path) = 0; + virtual void BE_DrawText(int fontId, std::string text, int x, int y, int fontSize) = 0; + + virtual int BE_LoadTexture(Agnostic::Picture pic) = 0; + virtual void BE_UnloadTexture(int picId) = 0; + virtual void BE_DrawColorTriangle(Agnostic::Triangle tri, Agnostic::Color col) = 0; + virtual void BE_DrawTexturedTriangle(Agnostic::TexturedTriangle tri) = 0; + + virtual void BE_ImGui_Begin() = 0; + virtual void BE_ImGui_End() = 0; + }; + } + } +} \ No newline at end of file diff --git a/mpfw/MPFW_Quake.cpp b/mpfw/MPFW_Quake.cpp index 357890b..19fd264 100644 --- a/mpfw/MPFW_Quake.cpp +++ b/mpfw/MPFW_Quake.cpp @@ -355,6 +355,7 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path) Texture2D temp = LoadTextureFromImage(img); rlMipTex mt; + mt.name = std::string((const char*)t.name); mt.glTextureID = temp.id; mt.height = temp.height; mt.width = temp.width; @@ -416,6 +417,14 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path) )); } + cface.baselight = data.faces[i].baselight; + if ( + Utils::Strings::IterativeStringExcerpt(data.textures[data.texInfo[data.faces[i].texinfoId].textureId].name, 0, 3) == "sky" + ) { + cface.skyFace = true; + } + if (data.textures[data.texInfo[data.faces[i].texinfoId].textureId].name == "clip") cface.clipFace = true; + if (data.textures[data.texInfo[data.faces[i].texinfoId].textureId].name == "trigger") cface.triggerFace = true; data.renderFaces.push_back(cface); diff --git a/mpfw/MPFW_Quake.h b/mpfw/MPFW_Quake.h index 9bba5b6..9422728 100644 --- a/mpfw/MPFW_Quake.h +++ b/mpfw/MPFW_Quake.h @@ -104,6 +104,12 @@ namespace MPFW { std::vector vertices; std::vector texCoords; int glTextureId, glTextureWidth, glTextureHeight; + bool skyFace = false; + bool triggerFace = false; + bool clipFace = false; + + unsigned char baselight; + }; @@ -115,13 +121,13 @@ namespace MPFW { using MipHeader = std::vector; struct cMiptex{ - char name[16]; + unsigned char name[16]; unsigned long width, height, offset1, offset2, offset4, offset8; }; struct rlMipTex { - char name[16]; + std::string name; unsigned long width, height; unsigned long glTextureID; int type; @@ -188,11 +194,14 @@ namespace MPFW { int edgesCDBG = 0; int texInfoCDBG = 0; int facesCDBG = 0; - + MapFile(){} + + [[warning("Prefer using an empty map file linked to a command handler for map loading with CFGs.")]] MapFile(std::string path) { LoadBSPMap(path); } + void LoadBSPMap(std::string path); ~MapFile(){} }; diff --git a/mpfw/main.cpp b/mpfw/main.cpp index 00ad747..3c6a43c 100644 --- a/mpfw/main.cpp +++ b/mpfw/main.cpp @@ -253,34 +253,39 @@ int main() { if (chr.cvars["vid_3d_renderer"] == "true") { 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); - rlSetTexture(map.data.renderFaces[i].glTextureId); + if ( + !(chr.cvars["vid_3d_cull_sky"] == "true" && map.data.renderFaces[i].skyFace) && + !(chr.cvars["vid_3d_cull_clips"] == "true" && map.data.renderFaces[i].clipFace) && + !(chr.cvars["vid_3d_cull_triggers"] == "true" && map.data.renderFaces[i].triggerFace) + ){ + rlColor4ub(255, 255, 255, 255); + rlSetTexture(map.data.renderFaces[i].glTextureId); + + + for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) { + rlBegin(RL_QUADS); // for texturing reasons because rlgl + Vector3 a = map.data.renderFaces[i].vertices[0], + b = map.data.renderFaces[i].vertices[j], + c = map.data.renderFaces[i].vertices[j - 1]; - - for (int j = 1; j < map.data.renderFaces[i].vertices.size(); j++) { - rlBegin(RL_QUADS); // for texturing reasons because rlgl - Vector3 a = map.data.renderFaces[i].vertices[0], - b = map.data.renderFaces[i].vertices[j], - c = map.data.renderFaces[i].vertices[j - 1]; - - Vector2 at = map.data.renderFaces[i].texCoords[0], - bt = map.data.renderFaces[i].texCoords[j], - ct = map.data.renderFaces[i].texCoords[j - 1]; + Vector2 at = map.data.renderFaces[i].texCoords[0], + bt = map.data.renderFaces[i].texCoords[j], + ct = map.data.renderFaces[i].texCoords[j - 1]; - rlTexCoord2f(at.x, at.y); - rlVertex3f(a.x, a.y, a.z); - rlTexCoord2f(bt.x, bt.y); - rlVertex3f(b.x, b.y, b.z); - rlTexCoord2f(ct.x, ct.y); - rlVertex3f(c.x, c.y, c.z); - rlVertex3f(c.x, c.y, c.z); + rlTexCoord2f(at.x, at.y); + rlVertex3f(a.x, a.y, a.z); + rlTexCoord2f(bt.x, bt.y); + rlVertex3f(b.x, b.y, b.z); + rlTexCoord2f(ct.x, ct.y); + rlVertex3f(c.x, c.y, c.z); + rlVertex3f(c.x, c.y, c.z); - rlEnd(); + rlEnd(); + } }