#include "Universe.h"
-#include "Sector.h"
-
#include <cstring>
#include <memory>
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<Sector *>(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<int> size, Vector<int> secSize, Vector<int> areaSize)
+: size(size)
+, secSize(secSize)
+, areaSize(areaSize)
+, bounds(size * secSize * areaSize)
+, env(bounds.x * bounds.y) {
+
}
Universe::~Universe() {
- delete[] reinterpret_cast<char *>(sec_begin);
+
+}
+
+
+Ship *Universe::AddShip(const Ship &s) {
+ ships.emplace_back(s);
+ return &ships.back();
+}
+
+int Universe::AddResource(const Resource &r) {
+ resources.emplace_back(r);
+ resources.back().id = resources.size();
+ return resources.size();
+}
+
+
+void Universe::DumpEnv(int res, Vector<int> 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);
+ }
}
}