-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.c
62 lines (58 loc) · 1.75 KB
/
generator.c
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
#include <stdlib.h>
#include "generator.h"
#include "sphere_generator.h"
#include "random_generator.h"
#include "mesh_generator.h"
#include "voxelgrid.h"
Generator *generator_create(GeneratorType type,const char *args)
{
Generator *generator = malloc(sizeof(Generator));
generator->type = type;
switch(generator->type){
case GENERATOR_SPHERE:
generator->generator_instance = sphere_generator_create(args);
break;
case GENERATOR_RANDOM:
generator->generator_instance = random_generator_create(args);
break;
case GENERATOR_MESH:
generator->generator_instance = mesh_generator_create(args);
break;
}
// if there was an error creating the generator instance
if(generator->generator_instance == NULL)
{
free(generator);
return NULL;
}
return generator;
}
VoxelGrid *generator_generate(Generator* generator)
{
switch(generator->type){
case GENERATOR_SPHERE:
sphere_generator_generate(generator->generator_instance);
break;
case GENERATOR_RANDOM:
random_generator_generate(generator->generator_instance);
break;
case GENERATOR_MESH:
mesh_generator_generate(generator->generator_instance);
break;
}
}
void generator_free(Generator* generator)
{
switch(generator->type){
case GENERATOR_SPHERE:
sphere_generator_free(generator->generator_instance);
break;
case GENERATOR_RANDOM:
random_generator_free(generator->generator_instance);
break;
case GENERATOR_MESH:
mesh_generator_free(generator->generator_instance);
break;
}
free(generator);
}