]> git.localhorst.tv Git - space.git/blob - src/world/Universe.cpp
grid view
[space.git] / src / world / Universe.cpp
1 #include "Universe.h"
2
3 #include "Sector.h"
4
5 #include <cstring>
6 #include <memory>
7
8
9 namespace space {
10
11 Universe::Universe(int w, int h, int sec_w, int sec_h, int numres)
12 : w(w)
13 , h(h)
14 , numres(numres)
15 , total(w * h)
16 , sec_begin(reinterpret_cast<Sector *>(new char[total * sizeof(Sector)]))
17 , sec_end(sec_begin + total) {
18         for (Sector *i = sec_begin; i < sec_end; ++i) {
19                 new (i) Sector(sec_w, sec_h, numres);
20         }
21 }
22
23 Universe::~Universe() {
24         delete[] reinterpret_cast<char *>(sec_begin);
25 }
26
27 }