diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-12-10 18:33:40 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-12-10 18:33:40 -0500 |
commit | b6141f6cbf07f0fbfadc892488f2ba83b7cf1719 (patch) | |
tree | d48e05a6ab29409350637b67aa9777f09af9709a /src/components.cpp | |
parent | e472a62b750e57724a26d299bb682b4f39405d05 (diff) |
doc updates
Diffstat (limited to 'src/components.cpp')
-rw-r--r-- | src/components.cpp | 172 |
1 files changed, 86 insertions, 86 deletions
diff --git a/src/components.cpp b/src/components.cpp index 612e522..e85883e 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -10,6 +10,8 @@ #include <brice.hpp> #include <quest.hpp> +#include <atomic> + static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us")); void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) @@ -20,11 +22,9 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e position.y += direction.y * dt; if (entity.has_component<Animate>() && entity.has_component<Sprite>()) { - if (direction.x) { - entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->nextFrame(); - } else { - entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->firstFrame(); - } + auto animate = entity.component<Animate>(); + entity.component<Sprite>()->sprite = + (direction.x != 0) ? animate->nextFrame() : animate->firstFrame(); } if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) { direction.x = 0; @@ -98,9 +98,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, 1.0, 1.0, 1.0, 0.0}; - if (entity.has_component<Animate>()) - sprite.sprite = entity.component<Animate>()->nextFrame(); - for (auto &S : sprite.sprite) { float width = HLINES(S.first.size.x); float height = HLINES(S.first.size.y); @@ -159,97 +156,100 @@ void DialogSystem::receive(const MouseClickEvent &mce) { game::entities.each<Position, Solid, Dialog, Name>( [&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) { + static std::atomic_bool dialogRun; (void)e; (void)d; if (((mce.position.x > pos.x) & (mce.position.x < pos.x + dim.width)) && ((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) { - std::thread([&] { - std::string questAssignedText; - int newIndex; - - auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog"); - - if (e.has_component<Direction>()) - d.talking = true; - - if (d.index == 9999) { - ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]); - ui::waitForDialog(); - } else if (exml != nullptr) { - while (exml->StrAttribute("name") != name.name) - exml = exml->NextSiblingElement(); - - exml = exml->FirstChildElement("text"); - while (exml->IntAttribute("id") != d.index) - exml = exml->NextSiblingElement(); - - auto oxml = exml->FirstChildElement("set"); - if (oxml != nullptr) { - do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value")); - while ((oxml = oxml->NextSiblingElement())); - game::briceUpdate(); - } - - auto qxml = exml->FirstChildElement("quest"); - if (qxml != nullptr) { - const char *qname; - auto qsys = game::engine.getSystem<QuestSystem>(); - - do { - // assign quest - qname = qxml->Attribute("assign"); - if (qname != nullptr) { - questAssignedText = qname; - auto req = qxml->GetText(); - qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : ""); - } - - // check / finish quest - else { - qname = qxml->Attribute("check"); + if (!dialogRun.load()) { + std::thread([&] { + std::string questAssignedText; + int newIndex; + + auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog"); + dialogRun.store(true); + + if (e.has_component<Direction>()) + d.talking = true; + + if (d.index == 9999) { + ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]); + ui::waitForDialog(); + } else if (exml != nullptr) { + while (exml->StrAttribute("name") != name.name) + exml = exml->NextSiblingElement(); + + exml = exml->FirstChildElement("text"); + while (exml->IntAttribute("id") != d.index) + exml = exml->NextSiblingElement(); + + auto oxml = exml->FirstChildElement("set"); + if (oxml != nullptr) { + do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value")); + while ((oxml = oxml->NextSiblingElement())); + game::briceUpdate(); + } + + auto qxml = exml->FirstChildElement("quest"); + if (qxml != nullptr) { + const char *qname; + auto qsys = game::engine.getSystem<QuestSystem>(); + + do { + // assign quest + qname = qxml->Attribute("assign"); if (qname != nullptr) { - if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) { - d.index = 9999; - } else { - ui::dialogBox(name.name, "", false, "Finish my quest u nug"); - ui::waitForDialog(); - return; - } - // oldidx = d.index; - // d.index = qxml->UnsignedAttribute("fail"); - // goto COMMONAIFUNC; + questAssignedText = qname; + auto req = qxml->GetText(); + qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : ""); } - } - } while((qxml = qxml->NextSiblingElement())); - } - auto cxml = exml->FirstChildElement("content"); - const char *content; - if (cxml == nullptr) { - content = randomDialog[d.rindex % randomDialog.size()].c_str(); - } else { - content = cxml->GetText() - 1; - while (*++content && isspace(*content)); + // check / finish quest + else { + qname = qxml->Attribute("check"); + if (qname != nullptr) { + if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) { + d.index = 9999; + } else { + ui::dialogBox(name.name, "", false, "Finish my quest u nug"); + ui::waitForDialog(); + return; + } + // oldidx = d.index; + // d.index = qxml->UnsignedAttribute("fail"); + // goto COMMONAIFUNC; + } + } + } while((qxml = qxml->NextSiblingElement())); + } + + auto cxml = exml->FirstChildElement("content"); + const char *content; + if (cxml == nullptr) { + content = randomDialog[d.rindex % randomDialog.size()].c_str(); + } else { + content = cxml->GetText() - 1; + while (*++content && isspace(*content)); + } + + ui::dialogBox(name.name, "", false, content); + ui::waitForDialog(); + + if (!questAssignedText.empty()) + ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str()); + + if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR) + d.index = newIndex; } - ui::dialogBox(name.name, "", false, content); - ui::waitForDialog(); - - if (!questAssignedText.empty()) - ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str()); - - if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR) - d.index = newIndex; - } - - d.talking = false; - }).detach(); - + d.talking = false; + dialogRun.store(false); + }).detach(); } } - ); + }); } void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) |