-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWorld.cpp
More file actions
76 lines (72 loc) · 1.83 KB
/
World.cpp
File metadata and controls
76 lines (72 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// World.cpp
// World definition
// Samuel Cagle
// Juston Li
// Xu Junjie, Kevin
// University of Oregon
// 2014-04-30
#include <cilk/cilk.h>
#include <iostream>
using std::cout;
using std::endl;
#include "World.h"
namespace gws {
const static int min = 0;
const static int max = 255;
World::World(SDL_Window* window, int width, int height) :
width(width),
height(height),
waterSystem(*this),
nutrientSystem(*this),
survivalSystem(*this),
movementSystem(*this),
renderSystem(*this, window) {}
World::~World() {}
size_t World::addRandomPlant() {
// Create a random plant-type entity
size_t ID = nextEntityID++;
positions.emplace_back(true);
survivors.emplace_back(false);
nutrients.emplace_back(true);
waters.emplace_back(false);
return ID;
}
size_t World::addRandomAnimal() {
// Create a random lake entity
size_t ID = nextEntityID++;
positions.emplace_back(true);
survivors.emplace_back(true);
nutrients.emplace_back(true);
waters.emplace_back(false);
return ID;
}
size_t World::addRandomLake() {
// Create a random lake entity
size_t ID = nextEntityID++;
positions.emplace_back(true);
survivors.emplace_back(false);
nutrients.emplace_back(false);
waters.emplace_back(true);
return ID;
}
void World::reserve(size_t size) {
positions.reserve(size);
survivors.reserve(size);
nutrients.reserve(size);
waters.reserve(size);
}
void World::runSystems() {
// Probably don't want this - we have to order the systems to update
// in a certain order since they have dependencies - generally render at
// the end of every other system
if (nextEntityID == 0) {
cout << "World is empty" << endl;
}
waterSystem.update();
nutrientSystem.update();
movementSystem.update();
survivalSystem.update();
// Rendering is done after everything else
renderSystem.update();
}
} /* gws */