From 212545c67cc5ef6ac02725a3743a84b539e84e80 Mon Sep 17 00:00:00 2001 From: Joeyrp Date: Tue, 18 Jan 2022 14:00:39 -0500 Subject: [PATCH] Non-filled box drawing method added to graphics system World system design started --- src/core/state.cpp | 2 +- src/game/world/world.h | 57 +++++++++++++++++++ src/graphics/opengl/glGraphics.cpp | 44 +++++++++++--- src/internal_data/dataManager.cpp | 1 + src/internal_libs/utils/types.cpp | 5 ++ src/internal_libs/utils/types.h | 14 +++++ .../tester/scenes/simpleRenderScene.cpp | 8 ++- .../tester/scenes/simpleRenderScene.h | 1 + 8 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 src/game/world/world.h diff --git a/src/core/state.cpp b/src/core/state.cpp index 407ad06..0b22bf3 100644 --- a/src/core/state.cpp +++ b/src/core/state.cpp @@ -92,7 +92,7 @@ namespace lunarium else { Logger::Log(LogCategory::CORE, LogLevel::WARNING, - "Can not find Run Mode in state file: %s, defaulting to MODE_TEST", filename); + "Can not find Run Mode in state file: %s, defaulting to MODE_TEST", filename.c_str()); state.Mode = RunMode::MODE_TEST; } diff --git a/src/game/world/world.h b/src/game/world/world.h new file mode 100644 index 0000000..4fe4692 --- /dev/null +++ b/src/game/world/world.h @@ -0,0 +1,57 @@ +/****************************************************************************** +* File - world.h +* Author - Joey Pollack +* Date - 2022/01/12 (y/m/d) +* Mod Date - 2022/01/12 (y/m/d) +* Description - Manages a game "world". A world is made up of regions which +* are subdivisions of the world. Each region contains: a set +* of images for the maps layers, a list of objects that spawn +* in this region and static collision data. +******************************************************************************/ + +#ifndef WORLD_H_ +#define WORLD_H_ + +#include +#include +#include + +namespace lunarium +{ + class Graphics; + class Camera; + class GameObject; + class Script; + class Image; + + class World + { + public: + struct Region + { + Script* mRegionScript; + Point2Di mCoords; + std::vector mObjects; + std::vector mLayers; + }; + + public: // INTERFACE + + void OnLoad(); + void OnUnload(); + void Update(float dt); + void Render(Graphics* pGraphics); + void RenderToTexture(Graphics* pGraphics, Image* pTexture); + + private: + Camera* mpCamera; + std::vector mWorldObjects; + std::vector mWorldScripts; // Maybe just want 1 script? + Sizei mRegionSize; + std::map mRegions; + + + }; +} + +#endif // WORLD_H_ \ No newline at end of file diff --git a/src/graphics/opengl/glGraphics.cpp b/src/graphics/opengl/glGraphics.cpp index db2b10a..47ea5b5 100644 --- a/src/graphics/opengl/glGraphics.cpp +++ b/src/graphics/opengl/glGraphics.cpp @@ -328,16 +328,46 @@ namespace lunarium glm::vec2 botRight(dimensions.right(), dimensions.bottom()); // left side top to bottom - DrawLine(glm::vec2(topLeft.x, topLeft.y), glm::vec2(topLeft.x, botRight.y), color, thickness); + // DrawLine(glm::vec2(topLeft.x, topLeft.y), glm::vec2(topLeft.x, botRight.y), color, thickness, angle); + + // // bottom left to right + // DrawLine(glm::vec2(topLeft.x, botRight.y), glm::vec2(botRight.x, botRight.y), color, thickness, angle); + + // // right side bottom to top + // DrawLine(glm::vec2(botRight.x, botRight.y), glm::vec2(botRight.x, topLeft.y), color, thickness, angle); + + // // top right to left + // DrawLine(glm::vec2(botRight.x, topLeft.y), glm::vec2(topLeft.x, topLeft.y), color, thickness, angle); + + mShapeShader.MakeActive(); + mShapeShader.SetUniformMatrix("projection", 1, glm::value_ptr(mProjection)); + glm::mat4 model = glm::mat4(1.0f); + model = glm::translate(model, glm::vec3(dimensions.CenterPoint().x, dimensions.CenterPoint().y, 0.0f)); + model = glm::scale(model, glm::vec3(dimensions.HalfWidth * 2, dimensions.HalfHeight * 2, 1.0f)); + model = glm::rotate(model, angle, glm::vec3(0.0f, 0.0f, 1.0f)); + mShapeShader.SetUniformMatrix("model", 1, glm::value_ptr(model)); + mShapeShader.SetUniformf("shapeColor", { color.Red, color.Green, color.Blue, color.Alpha }); + glBindVertexArray(mRectVAO); + + GLfloat lineVerts[4][4] = { + { -0.5f, -0.5f, }, + { 0.5f, -0.5f }, + + { 0.5f, 0.5f, }, + { -0.5f, 0.5f, }, + }; + + glBindBuffer(GL_ARRAY_BUFFER, mRectVBO); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(lineVerts), lineVerts); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glLineWidth(thickness); + glDrawArrays(GL_LINE_LOOP, 0, 4); + + glBindVertexArray(0); - // bottom left to right - DrawLine(glm::vec2(topLeft.x, botRight.y), glm::vec2(botRight.x, botRight.y), color, thickness); - // right side bottom to top - DrawLine(glm::vec2(botRight.x, botRight.y), glm::vec2(botRight.x, topLeft.y), color, thickness); - // top right to left - DrawLine(glm::vec2(botRight.x, topLeft.y), glm::vec2(topLeft.x, topLeft.y), color, thickness); } void OglGraphics::DrawImage(Image& image, glm::vec2 position, Color color, float angle) diff --git a/src/internal_data/dataManager.cpp b/src/internal_data/dataManager.cpp index 89721b6..35d4af5 100644 --- a/src/internal_data/dataManager.cpp +++ b/src/internal_data/dataManager.cpp @@ -68,6 +68,7 @@ namespace lunarium Core::Graphics().RegisterImage(*mUpArrowIcon); mUpArrowIcon->FreeRawData(); ////////////////////////////////////////// + } void DataManager::Shutdown() diff --git a/src/internal_libs/utils/types.cpp b/src/internal_libs/utils/types.cpp index 62dfea2..b6e9282 100644 --- a/src/internal_libs/utils/types.cpp +++ b/src/internal_libs/utils/types.cpp @@ -77,6 +77,11 @@ namespace lunarium return true; } + glm::vec2 Rectangle::CenterPoint() const + { + return glm::vec2(X, Y); + } + bool Rectangle::Intersects(const Rectangle& other, glm::vec2& centers) const { glm::vec2 myCenter = glm::vec2(X, Y); diff --git a/src/internal_libs/utils/types.h b/src/internal_libs/utils/types.h index 9367c0f..b1a6c71 100644 --- a/src/internal_libs/utils/types.h +++ b/src/internal_libs/utils/types.h @@ -15,6 +15,20 @@ namespace lunarium { + //////////////////////////////////////////////////////////// + // POINT + //////////////////////////////////////////////////////////// + template + struct Point2D + { + T X; + T Y; + }; + + typedef Point2D Point2Di; + typedef Point2D Point2Du; + typedef Point2D Point2Df; + /////////////////////////////////////////////////////// // SIZE ////////////////////////////////////////////////////// diff --git a/src/run_modes/tester/scenes/simpleRenderScene.cpp b/src/run_modes/tester/scenes/simpleRenderScene.cpp index 7c86770..414e6a3 100644 --- a/src/run_modes/tester/scenes/simpleRenderScene.cpp +++ b/src/run_modes/tester/scenes/simpleRenderScene.cpp @@ -26,11 +26,13 @@ namespace lunarium Logger::Log(mLogCat, LogLevel::INFO, "Running Simple Render Test Scene"); mTextBoxWidth = 500; + // Currently the full default window size mImageSize.Width = 1280; mImageSize.Height = 720; angle = 0.0f; + box_angle = 0.0f; } void SimpleRenderScene::OnTick(double delta) @@ -94,13 +96,17 @@ namespace lunarium Color(0.0f, 1.0f, 1.0f, 1.0f), 0.5f, g.DefaultFont()); mpRenderedImage = Core::GetInstance().EndRenderToTexture(); + + box_angle += 0.01f; } void SimpleRenderScene::OnRender(IGraphics* g) { g->DrawImage(*mpRenderedImage, Rectangle::MakeFromTopLeft(0.0f, 0.0f, (float)mpRenderedImage->GetWidth(), (float)mpRenderedImage->GetHeight()), - Rectangle::MakeFromTopLeft(0.0f, 0.0f, (float)mImageSize.Width, (float)mImageSize.Height), Color(1.0f, 1.0f, 1.0f, 1.0f), angle); + Rectangle::MakeFromTopLeft(0.0f, 0.0f, (float)mImageSize.Width, (float)mImageSize.Height), Color(1.0f, 1.0f, 1.0f, 1.0f), angle); g->DrawBox(Rectangle::MakeFromTopLeft(0.0f, 0.0f, (float)mImageSize.Width, (float)mImageSize.Height), Color(0.0f, 0.0f, 0.0f, 1.0f), 1.0f, angle); + + g->DrawBox(Rectangle(400, 400, 128.0f, 128.0f), Color(0.0f, 1.0f, 0.0f, 1.0f), 2.0f, box_angle); } } \ No newline at end of file diff --git a/src/run_modes/tester/scenes/simpleRenderScene.h b/src/run_modes/tester/scenes/simpleRenderScene.h index 355e960..0dd707e 100644 --- a/src/run_modes/tester/scenes/simpleRenderScene.h +++ b/src/run_modes/tester/scenes/simpleRenderScene.h @@ -29,6 +29,7 @@ namespace lunarium Sizei mImageSize; Image* mpRenderedImage; float angle; + float box_angle; }; }