From 3eccd38e989012ff35ee5376670aabc338c52008 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 12 Feb 2017 17:07:55 -0500 Subject: locked EM.each, arenas --- src/components.cpp | 26 +++++++++++++------------- src/engine.cpp | 2 +- src/world.cpp | 12 ++++-------- 3 files changed, 18 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/components.cpp b/src/components.cpp index dfce75c..3b38a53 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -22,8 +22,10 @@ static std::vector randomDialog (readFileA("assets/dialog_en-us")); void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) { + std::string arena; + (void)ev; - en.each([dt](entityx::Entity entity, Position &position, Direction &direction) { + en.each([&arena, dt](entityx::Entity entity, Position &position, Direction &direction) { position.x += direction.x * dt; position.y += direction.y * dt; @@ -49,15 +51,10 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e // TODO initialX and range? if (entity.has_component()) { auto ppos = game::engine.getSystem()->getPosition(); - if (ppos.x > position.x && ppos.x < position.x + entity.component()->width) { - ui::toggleWhiteFast(); - ui::waitForCover(); // TODO thread safe call to load world? - //game::engine.getSystem()->load(entity.component()->arena); - ui::toggleWhiteFast(); - entity.destroy(); - } else { + if (ppos.x > position.x && ppos.x < position.x + entity.component()->width) + arena = entity.component()->arena; + else direction.x = (ppos.x > position.x) ? .05 : -.05; - } } else if (entity.has_component()) { auto& countdown = entity.component()->countdown; @@ -70,6 +67,13 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e } } }); + + if (!arena.empty()) { + ui::toggleWhiteFast(); + ui::waitForCover(); + game::engine.getSystem()->load(arena); + ui::toggleWhiteFast(); + } } void PhysicsSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) @@ -106,7 +110,6 @@ void RenderSystem::render(void) if (!loadTexResult.isEmpty()) return; - game::entities.lock(); game::entities.each([](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) { // Verticies and shit float its = 0; @@ -180,7 +183,6 @@ void RenderSystem::render(void) ui::setFontZ(-5.0); ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name); }); - game::entities.unlock(); } void DialogSystem::configure(entityx::EventManager &ev) @@ -190,7 +192,6 @@ void DialogSystem::configure(entityx::EventManager &ev) void DialogSystem::receive(const MouseClickEvent &mce) { - game::entities.lock(); game::entities.each( [&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) { static std::atomic_bool dialogRun; @@ -308,7 +309,6 @@ void DialogSystem::receive(const MouseClickEvent &mce) } } }); - game::entities.unlock(); } void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) diff --git a/src/engine.cpp b/src/engine.cpp index ebf5953..ee35d06 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -59,7 +59,7 @@ void Engine::update(entityx::TimeDelta dt) namespace game { entityx::EventManager events; - LockableEntityManager entities (events); + entityx::EntityManager entities (events); //SpriteLoader sprite_l; Engine engine; diff --git a/src/world.cpp b/src/world.cpp index f46339b..09d277f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -137,7 +137,6 @@ bool WorldSystem::save(void) // signature? save << "831998 "; - game::entities.lock(); game::entities.each([&](entityx::Entity entity, Position& pos) { // save position save << "p " << pos.x << ' ' << pos.y << ' '; @@ -146,7 +145,6 @@ bool WorldSystem::save(void) if (entity.has_component()) save << "d " << entity.component()->index << ' '; }); - game::entities.unlock(); save.close(); return true; @@ -204,11 +202,14 @@ void WorldSystem::load(const std::string& file) UserAssert(wxml != nullptr, "XML Error: Cannot find a or tag in " + xmlPath); wxml = wxml->FirstChildElement(); world.indoor = true; + if (world.outdoor.empty()) { + world.outdoor = currentXMLFile; + world.outdoorCoords = vec2(0, 100); + } } world.toLeft = world.toRight = ""; currentXMLFile = file; - game::entities.lock(); game::entities.reset(); game::engine.getSystem()->create(); @@ -449,7 +450,6 @@ void WorldSystem::load(const std::string& file) } game::events.emit(); - game::entities.unlock(); } /* @@ -1115,7 +1115,6 @@ void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, void WorldSystem::detect(entityx::TimeDelta dt) { - game::entities.lock(); game::entities.each( [&](entityx::Entity e, Grounded &g, Position &loc, Solid &dim) { (void)e; @@ -1180,7 +1179,6 @@ void WorldSystem::detect(entityx::TimeDelta dt) loc.x = -(static_cast(world.startX)) - dim.width - game::HLINE; } }); - game::entities.unlock(); } void WorldSystem::goWorldRight(Position& p, Solid &d) @@ -1218,7 +1216,6 @@ void WorldSystem::goWorldPortal(Position& p) p.x = world.outdoorCoords.x; // ineffective, player is regen'd p.y = world.outdoorCoords.y; } else { - game::entities.lock(); game::entities.each( [&](entityx::Entity entity, Position& loc, Solid &dim, Portal &portal) { (void)entity; @@ -1229,7 +1226,6 @@ void WorldSystem::goWorldPortal(Position& p) return; } }); - game::entities.unlock(); } if (!file.empty()) { -- cgit v1.2.3