diff --git a/gameenv/data/sys/cvardefs.cvars b/gameenv/data/sys/cvardefs.cvars index c89ff78..a6b022a 100644 --- a/gameenv/data/sys/cvardefs.cvars +++ b/gameenv/data/sys/cvardefs.cvars @@ -1,6 +1,7 @@ +math_3d_floor_collision_work false vid_2d_background false vid_3d_renderer true vid_3d_grid false vid_3d_cull_sky false vid_3d_cull_clips true -vid_3d_cull_triggers true \ No newline at end of file +vid_3d_cull_triggers true diff --git a/mpfw/MPFW_Backend_raylib.cpp b/mpfw/MPFW_Backend_raylib.cpp new file mode 100644 index 0000000..8de7088 --- /dev/null +++ b/mpfw/MPFW_Backend_raylib.cpp @@ -0,0 +1,41 @@ +#include "MPFW_Backend_raylib.h" +#include +#include +std::vector _fonts_RL; + +void BackEnd_Raylib::Create(MPFW::Backends::Video::ContextParameters param) +{ + InitWindow(param.width, param.height, param.name.c_str()); + SetTargetFPS(param.desiredFps); +} + +int BackEnd_Raylib::BE_LoadFont(std::string path) +{ + _fonts_RL.push_back(LoadFontEx(path.c_str(), 360, 0, 4000)); + return _fonts_RL.size() - 1; +} + +void BackEnd_Raylib::BE_DrawText(int fontId, std::string text, int x, int y, int fontSize) +{ + DrawTextEx(_fonts_RL[fontId], text.c_str(), { (float)x,(float)y }, fontSize, 0, WHITE); +} + +int BackEnd_Raylib::BE_LoadTexture(MPFW::Backends::Video::Agnostic::Picture pic) +{ + Image i; + i.data = malloc(pic.width * pic.height * 4); + i.width = pic.width; + i.height = pic.height; + std::memcpy(i.data, pic.data.data(), pic.data.size()*4); + i.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; + + Texture t = LoadTextureFromImage(i); + + free(i.data); + + return t.id; + + +} + + diff --git a/mpfw/MPFW_Backend_raylib.h b/mpfw/MPFW_Backend_raylib.h new file mode 100644 index 0000000..6ed7d1c --- /dev/null +++ b/mpfw/MPFW_Backend_raylib.h @@ -0,0 +1,22 @@ +#pragma once +#include "MPFW_BackendDefinition.h" + + +class BackEnd_Raylib : public MPFW::Backends::Video::BackEnd { +public: + void Create(MPFW::Backends::Video::ContextParameters param); + + int BE_LoadFont(std::string path); + void BE_DrawText(int fontId, std::string text, int x, int y, int fontSize); + + int BE_LoadTexture(MPFW::Backends::Video::Agnostic::Picture pic); + void BE_UnloadTexture(int picId); + void BE_DrawColorTriangle(MPFW::Backends::Video::Agnostic::Triangle tri, MPFW::Backends::Video::Agnostic::Color col); + void BE_DrawTexturedTriangle(MPFW::Backends::Video::Agnostic::TexturedTriangle tri); + + void BE_ImGui_Begin(); + void BE_ImGui_End(); + + void BE_StartFrame(); + void BE_EndFrame(); +}; \ No newline at end of file diff --git a/mpfw/MPFW_Quake.cpp b/mpfw/MPFW_Quake.cpp index 19fd264..01465bc 100644 --- a/mpfw/MPFW_Quake.cpp +++ b/mpfw/MPFW_Quake.cpp @@ -431,6 +431,17 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path) } + data.planes.clear(); + data.planes.resize(data.header.planes.size / sizeof(Plane)); + + std::memcpy( + data.planes.data(), + Utils::Strings::IterativeStringExcerpt(buffer, data.header.planes.offset, data.header.planes.size).data(), + data.header.planes.size + ); + + + ds = Debug::DONE; diff --git a/mpfw/MPFW_Quake.h b/mpfw/MPFW_Quake.h index 9422728..577b33d 100644 --- a/mpfw/MPFW_Quake.h +++ b/mpfw/MPFW_Quake.h @@ -112,6 +112,12 @@ namespace MPFW { }; + + struct Plane { + Vector3 normal; + float dist; + long type; + }; struct cMipHeader { long numtex; @@ -176,7 +182,7 @@ namespace MPFW { std::vector ledges; std::vector textures; - + std::vector planes; std::vector renderFaces; diff --git a/mpfw/main.cpp b/mpfw/main.cpp index 3c6a43c..a355bca 100644 --- a/mpfw/main.cpp +++ b/mpfw/main.cpp @@ -11,6 +11,8 @@ #include #include #include "MPFW_UI.h" +#include +#include // turn quake miptex into rl texture Texture2D RLMT_QUAKE(MPFW::Quake::Maps::rlMipTex rlmt) { @@ -47,7 +49,47 @@ void Look() { } +BoundingBox GenerateTriangleBoundingBox(Vector3 a, Vector3 b, Vector3 c) { + BoundingBox retval; + retval.min = { + a.x < b.x && a.x < c.x ? a.x : + b.x < a.x && b.x < c.x ? b.x : c.x, + a.y < b.y && a.y < c.y ? a.y : + b.y < a.y && b.y < c.y ? b.y : c.y, + + a.z < b.z && a.z < c.z ? a.z : + b.z < a.z && b.z < c.z ? b.z : c.z + }; + + + retval.max = { + a.x > b.x && a.x > c.x ? a.x : + b.x > a.x && b.x > c.x ? b.x : c.x, + + a.y > b.y && a.y > c.y ? a.y : + b.y > a.y && b.y > c.y ? b.y : c.y, + + a.z > b.z && a.z > c.z ? a.z : + b.z > a.z && b.z > c.z ? b.z : c.z + }; + + + return retval; +} + +BoundingBox GenerateBoundingBoxPolygon(std::vector poly) { + std::vector polyCopy = poly; + + std::sort(polyCopy.begin(), polyCopy.end(), [](Vector3 a, Vector3 b) { + return Vector3Distance({ 0,0,0 }, a) < Vector3Distance({ 0,0,0 }, b); + }); + + BoundingBox retval; + retval.min = polyCopy[0]; + retval.max = polyCopy[polyCopy.size() - 1]; + return retval; +} // because quake can't normalize vectors like a civilized piece of software @@ -66,7 +108,7 @@ qNVec qNormalize(Vector3 v) { Vector3 wishDir = { 0,0,0 }; double wishSpeed; - +float collisionFloor = 5; void Accelerate() { double addSpeed, accelSpeed, currentSpeed; @@ -106,6 +148,20 @@ void ___test___(T a, T b) { #endif + +bool consoleOn = false; +bool waitingForFrameToFinish = false; +bool physicsThreadShouldDie = false; +void PhysicsThread(MPFW::Console::CommandHandlerResources* chr) { + float ctime = GetTime(); + while(!physicsThreadShouldDie){ + + + } +} + + + int main() { @@ -141,7 +197,7 @@ int main() { SetConfigFlags(FLAG_WINDOW_RESIZABLE); InitWindow(1280, 720, TextFormat("mpfw")); - SetTargetFPS(60); + // SetTargetFPS(60); SetExitKey(0); DisableCursor(); @@ -160,6 +216,7 @@ int main() { cmdH.RunScript("data/cfg/startup.cfg"); uiRenderer.cmh = &cmdH; + // MPFW::UI::Window wndw("data/menus/test.wnd"); @@ -175,11 +232,13 @@ int main() { bool indivFaceMode = false; int indivFace = 0; - bool consoleOn = false; std::string cmdBuf = ""; int framebuffer = 0; + std::thread physics(PhysicsThread, &chr); + + while (!WindowShouldClose()) { - + if (framebuffer < 5 && !uiRenderer.showCursorOnLaunch) { @@ -190,7 +249,23 @@ int main() { if (IsKeyPressed(KEY_APOSTROPHE)) { consoleOn = !consoleOn; } - if(!consoleOn && IsCursorHidden()){ + + + if (IsKeyPressed(KEY_ESCAPE) && !chr.gameDisabled) { + if (IsCursorHidden()) { + EnableCursor(); + uiRenderer.rendererIsActive = true; + } + else { + DisableCursor(); + uiRenderer.rendererIsActive = false; + } + } + + BeginDrawing(); + ClearBackground(BLACK); + + if(IsCursorHidden() && !consoleOn){ Look(); Vector3 wishVel = { 0,0,0 }; wishSpeed = 320; @@ -212,11 +287,12 @@ int main() { wishVel = Vector3Multiply(Vector3Normalize(wishVel), { 320, 320, 320 }); wishDir = Vector3Normalize(wishVel); - if (camera.position.y <= 5) { - camera.position.y = 5; + + if (camera.position.y <= collisionFloor) { + camera.position.y = collisionFloor; velocity.y = 0; - if(IsKeyPressed(KEY_SPACE)){ - velocity.y += wishSpeed*0.5*GetFrameTime(); + if (IsKeyPressed(KEY_SPACE)) { + velocity.y += wishSpeed * 0.5 * GetFrameTime(); } Accelerate(); @@ -225,32 +301,22 @@ int main() { AirAccelerate(wishVel); velocity.y -= 10 * GetFrameTime(); } - if (IsKeyPressed(KEY_LEFT) && indivFace > 0) indivFace--; - if (IsKeyPressed(KEY_RIGHT) && indivFace < map.data.faces.size() - 1) indivFace++; - if (IsKeyPressed(KEY_F)) indivFaceMode = !indivFaceMode; velocity *= {GetFrameTime(), 1, GetFrameTime()}; camera.position += velocity; camera.target = camera.position + rotation; - } - if (IsKeyPressed(KEY_ESCAPE) && !chr.gameDisabled) { - if (IsCursorHidden()) { - EnableCursor(); - uiRenderer.rendererIsActive = true; - } - else { - DisableCursor(); - uiRenderer.rendererIsActive = false; - } + + } + + - BeginDrawing(); - ClearBackground(BLACK); if (chr.cvars["vid_2d_background"] == "true") DrawRectangleGradientV(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE, LIGHTGRAY); 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++) { @@ -321,6 +387,8 @@ int main() { uiRenderer.Render(); EndDrawing(); } + physicsThreadShouldDie = true; + physics.join(); CloseWindow(); } diff --git a/mpfw/mpfw.vcxproj b/mpfw/mpfw.vcxproj index 94b4147..fbdcbeb 100644 --- a/mpfw/mpfw.vcxproj +++ b/mpfw/mpfw.vcxproj @@ -1,4 +1,4 @@ - + @@ -145,6 +145,7 @@ + @@ -153,6 +154,8 @@ + + diff --git a/mpfw/mpfw.vcxproj.filters b/mpfw/mpfw.vcxproj.filters index 327449a..4e17a98 100644 --- a/mpfw/mpfw.vcxproj.filters +++ b/mpfw/mpfw.vcxproj.filters @@ -16,6 +16,9 @@ {4f8f0e99-b4e5-46ed-8593-5de637bd7032} + + {563323f5-04e3-405d-9047-db638c5bf1fd} + @@ -60,6 +63,9 @@ Source Files + + Backends + @@ -83,5 +89,11 @@ Header Files + + Header Files + + + Backends + \ No newline at end of file