X-Git-Url: http://git.localhorst.tv/?p=space.git;a=blobdiff_plain;f=src%2Fworld%2FUniverse.cpp;h=bc1aad8bde2f0dff8c94251c5cb7c7df56f9d65d;hp=daac4dbf8fa9099d22be8149de14ea3d79875fb6;hb=dd2641dd1b87a0ee3ae27f000ea9527ee05fddbd;hpb=9a1076ae9a803c51147645b1ddac873ee7d1e08e diff --git a/src/world/Universe.cpp b/src/world/Universe.cpp index daac4db..bc1aad8 100644 --- a/src/world/Universe.cpp +++ b/src/world/Universe.cpp @@ -9,7 +9,9 @@ namespace space { Universe::Universe(Vector size, Vector secSize, Vector areaSize) : size(size) , secSize(secSize) -, areaSize(areaSize) { +, areaSize(areaSize) +, bounds(size * secSize * areaSize) +, env(bounds.x * bounds.y) { } @@ -30,6 +32,25 @@ int Universe::AddResource(const Resource &r) { } +void Universe::DumpEnv(int res, Vector coords, float amount) { + if (coords.x < 0) coords.x = 0; + if (coords.x > bounds.x) coords.x = bounds.x - 1; + if (coords.y < 0) coords.y = 0; + if (coords.y > bounds.x) coords.y = bounds.y - 1; + + int index = coords.x * bounds.y + coords.y; + + Env &point = env[index]; + Env::iterator entry(point.find(res)); + + if (entry == point.end()) { + point.emplace(res, amount); + } else { + entry->second += amount; + } +} + + void Universe::Update(float delta) { for (Ship &s : ships) { s.Update(delta);