X-Git-Url: http://git.localhorst.tv/?p=space.git;a=blobdiff_plain;f=src%2Fworld%2FUniverse.cpp;fp=src%2Fworld%2FUniverse.cpp;h=ec71fd1acc665a83e42ff80023b3195e0b78f8af;hp=ec307a52eb3fc952e34f2125be6d3250730363d7;hb=3f4f8a92f64df08119a40da4d196b3e92ecdc637;hpb=96ab5904b059e00e78b26a6527790c8dc951e324 diff --git a/src/world/Universe.cpp b/src/world/Universe.cpp index ec307a5..ec71fd1 100644 --- a/src/world/Universe.cpp +++ b/src/world/Universe.cpp @@ -8,15 +8,16 @@ namespace space { -Universe::Universe(int w, int h, int sec_w, int sec_h, int numres) -: w(w) -, h(h) +Universe::Universe(Vector size, Vector secSize, Vector areaSize, int numres) +: size(size) +, secSize(secSize) +, areaSize(areaSize) , numres(numres) -, total(w * h) +, total(size.x * size.y) , sec_begin(reinterpret_cast(new char[total * sizeof(Sector)])) , sec_end(sec_begin + total) { for (Sector *i = sec_begin; i < sec_end; ++i) { - new (i) Sector(sec_w, sec_h, numres); + new (i) Sector(secSize, numres); } } @@ -24,4 +25,33 @@ Universe::~Universe() { delete[] reinterpret_cast(sec_begin); } + +Entity *Universe::AddEntity(const Entity &e) { + entities.emplace_back(e); + return &entities.back(); +} + + +void Universe::Update(float delta) { + for (Entity &e : entities) { + e.Update(delta); + while (e.pos.x > areaSize.x) { + e.pos.x -= areaSize.x; + ++e.area.x; + } + while (e.pos.x < 0) { + e.pos.x += areaSize.x; + --e.area.x; + } + while (e.pos.y > areaSize.y) { + e.pos.y -= areaSize.y; + ++e.area.y; + } + while (e.pos.y < 0) { + e.pos.y += areaSize.y; + --e.area.y; + } + } +} + }