X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FUniverse.cpp;h=9f9efe627839eb4be29d33ed2751dc225fe0250a;hb=11306935dbf7213d583222ce239985e1b3f180bf;hp=ec307a52eb3fc952e34f2125be6d3250730363d7;hpb=96ab5904b059e00e78b26a6527790c8dc951e324;p=space.git diff --git a/src/world/Universe.cpp b/src/world/Universe.cpp index ec307a5..9f9efe6 100644 --- a/src/world/Universe.cpp +++ b/src/world/Universe.cpp @@ -1,27 +1,49 @@ #include "Universe.h" -#include "Sector.h" - #include #include namespace space { -Universe::Universe(int w, int h, int sec_w, int sec_h, int numres) -: w(w) -, h(h) -, numres(numres) -, total(w * h) -, 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); - } +Universe::Universe(Vector size, Vector secSize, Vector areaSize) +: size(size) +, secSize(secSize) +, areaSize(areaSize) { + } 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; + } + } } }