From dbb26902ed54ce308fdcec4697616e152f2894fd Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 16 Sep 2019 12:46:44 -0400 Subject: success with font loading --- src/engine.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index 66739ff..37f6e68 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -27,6 +27,7 @@ #include "script.hpp" #include "render.hpp" #include "physics.hpp" +#include "text.hpp" #include "components/EventListener.hpp" #include "components/Script.hpp" @@ -47,10 +48,18 @@ int Engine::init(void) systems.add(); systems.add(entities); systems.add(); + systems.add(); systems.configure(); // Load game script and entity data - systems.system()->init(); + auto* script = systems.system().get(); + script->addToGameNamespace("loadFont", + [this](std::string name, std::string file, int size) { + systems.system().get()->loadFont(name, file, size); + }); + script->init(); + + if (GameState::load("save.json", entities)) { std::cout << "Loaded from save.json. Delete the file if you don't want " "it." << std::endl; -- cgit v1.2.3 From 145d74e433216f8c17475685c553321ca4cbedf3 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 17 Sep 2019 15:36:26 -0400 Subject: text rendering in-place; but something's missing --- Scripts/init.lua | 3 ++- src/engine.cpp | 5 +++++ src/render.hpp | 1 + src/text.cpp | 23 ++++++++++++++++++++--- src/text.hpp | 1 + 5 files changed, 29 insertions(+), 4 deletions(-) (limited to 'src/engine.cpp') diff --git a/Scripts/init.lua b/Scripts/init.lua index 65513ec..da9ba14 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -1,4 +1,4 @@ -game.loadFont("freepixel16", "Assets/FreePixel.ttf", 16) +game.loadFont("default", "Assets/FreePixel.ttf", 16) bird = { Player = 0, @@ -9,6 +9,7 @@ bird = { end, MoveLeftReleased = function(self) self.Velocity.x = self.Velocity.x + 100 + game.puts("default", self.Position.x, self.Position.y, "Hey.") end, MoveRightPressed = function(self) self.Velocity.x = self.Velocity.x + 100 diff --git a/src/engine.cpp b/src/engine.cpp index 70b0b45..703b45e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -58,6 +58,10 @@ int Engine::init(void) [this](std::string name, std::string file, int size) { systems.system().get()->loadFont(name, file, size); }); + script->addToGameNamespace("puts", + [this](std::string name, float x, float y, std::string text) { + systems.system().get()->put(name, x, y, text); + }); script->init(); @@ -138,6 +142,7 @@ void Engine::renderLoop(void) { entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */ while (shouldRun()) { + systems.update(dt); systems.update(dt); } } diff --git a/src/render.hpp b/src/render.hpp index d74aca4..3f632f1 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -67,6 +67,7 @@ private: // Map of VBOs and their render data std::map renders; + public: RenderSystem() : window(nullptr, SDL_DestroyWindow) {} diff --git a/src/text.cpp b/src/text.cpp index 186907f..1381eb2 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -1,5 +1,7 @@ #include "text.hpp" +#include "events/render.hpp" + #include void TextSystem::configure([[maybe_unused]] entityx::EntityManager& entities, @@ -8,16 +10,30 @@ void TextSystem::configure([[maybe_unused]] entityx::EntityManager& entities, if (FT_Init_FreeType(&freetype) != 0) { // TODO handle error } + + shouldUpdateVBOs = false; } /** * Draws the text for all entities. */ void TextSystem::update([[maybe_unused]] entityx::EntityManager& entites, - [[maybe_unused]] entityx::EventManager& events, + entityx::EventManager& events, [[maybe_unused]] entityx::TimeDelta dt) { - // TODO render each Text component's text + if (shouldUpdateVBOs) { + shouldUpdateVBOs = false; + updateVBOs(); + + for (auto& data : fontData) { + auto& d = data.second; + if (d.text.size() == 0) + continue; + + // TODO make normal + events.emit(d.vbo, d.tex, 0, d.buffer.size()); + } + } } void TextSystem::loadFont(const std::string& name, @@ -105,7 +121,8 @@ void TextSystem::put(const std::string& font, if (fontData.find(font) == fontData.end()) return; - fontData[font].text.emplace_back(text, x, y); + fontData[font].text.emplace_back(text, x, y, -9.0f); + shouldUpdateVBOs = true; } void TextSystem::updateVBOs(void) diff --git a/src/text.hpp b/src/text.hpp index 8efe3ae..c3479ca 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -91,6 +91,7 @@ private: FT_Library freetype; std::map fonts; std::map fontData; + bool shouldUpdateVBOs; void updateVBOs(void); }; -- cgit v1.2.3 From 1703f84121f18277c2a9bd671e204730c131c102 Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Wed, 25 Sep 2019 12:57:18 -0400 Subject: Changed up time-step to see if it fixes desktop stuttering movement issues --- src/engine.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index 703b45e..a000979 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -84,8 +84,15 @@ void Engine::logicLoop(void) the logic loop is run during our first loop. */ + auto start = mc::now(); while (shouldRun()) { - auto start = mc::now(); + auto end = start; + start = mc::now(); + auto diff = start-end; + auto micros = cr::duration_cast(diff); + auto msc = micros.count(); + dt = static_cast(msc) / 1000.0; + elapsed += dt; systems.update(dt); //systems.update(dt); @@ -107,35 +114,27 @@ void Engine::logicLoop(void) } std::this_thread::yield(); - - auto end = mc::now(); - auto diff = end - start; - auto micros = cr::duration_cast(diff); - auto msc = micros.count(); - dt = static_cast(msc) / 1000.0; - elapsed += dt; } } void Engine::physicsLoop(void) { entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */ - + auto start = mc::now(); while (shouldRun()) { - auto start = mc::now(); + auto end = start; + start = mc::now(); + + auto diff = start - end; + auto micros = cr::duration_cast(diff); + auto msc = micros.count(); + dt = static_cast(msc) / 1000.0; // Update the entities physics/position systems.update(dt); std::this_thread::yield(); - - auto end = mc::now(); - auto diff = end - start; - auto micros = cr::duration_cast(diff); - auto msc = micros.count(); - dt = static_cast(msc) / 1000.0; } - std::cout << std::endl; } void Engine::renderLoop(void) -- cgit v1.2.3