-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile_Generator.cpp
59 lines (52 loc) · 1.36 KB
/
Tile_Generator.cpp
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
/***
* @file Tile_Generator.cpp
* Tile factory
*/
// Copyright 2019 by Julio Albornoz <[email protected]>
// The License.txt file describes the conditions under which this
// software may be distributed.
#include "Generators.h"
Tile_Generator::Tile_Generator(Config* config){
scale = config->scale;
shape = config->shape;
generic = form();
}
Tile* Tile_Generator::form(){
/***
* Initializes a Tile object, if the shape requested is not known it
* will raise an error.
*/
if (shape.compare("SQUARE") == 0){
return new Square_Tile(scale);
}
else if (shape.compare("HEXAGON") == 0){
return new Hexagon_Tile(scale);
}
else{
throw std::invalid_argument("Unknown tile shape");
}
}
void Tile_Generator::reset(std::vector<glm::vec3>* colors){
/***
* Deletes previous Tile instances, creates a new set based on
* the colors given.
*
* @param colors: New colorset
*
* @return New Tileset OpenGL ID list
*/
glDeleteLists(1, colors->size());
construct(colors);
}
void Tile_Generator::construct(std::vector<glm::vec3>* colors){
/***
* For each color given, the generator will instance a Tile by
* calling the OpenGL commands used on its construction + its color
*
* @return Tileset OpenGL ID list
*/
unsigned int size = colors->size();
for (unsigned int i = 0; i < size; i++){
generic->compile(&(*colors)[i]);
}
}