-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniverseComputerSimulation.cpp
More file actions
162 lines (109 loc) · 3.59 KB
/
Copy pathUniverseComputerSimulation.cpp
File metadata and controls
162 lines (109 loc) · 3.59 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef __UNIVERSECOMPUTERSIMULATION_CPP__
#define __UNIVERSECOMPUTERSIMULATION_CPP__
#include "UniverseComputerSimulation.hpp"
Point* simp_point_vector_create(__int64 init_sz) {
Point* ret = new Point[init_sz];
return ret;
}
Point* simp_point_vector_read(Point** v, __int64 vtop, __int64 vcap, __int64 loc) {
if (loc > vtop)
return 0;
return v[loc];
}
void simp_point_vector_append(Point*** v, __int64* vtop, __int64* vcap, Point* data) {
*vtop = *vtop + 1;
if (*vtop < *vcap)
(*v)[*vtop] = data;
else {
Point*** newv = new Point**[*vcap * 2];
for (__int64 i = 0; i < *vcap * 2; i++)
newv[i] = 0;
for (__int64 i = 0; i < *vcap; i++)
newv[i] = v[i];
*vcap = *vcap * 2;
delete[](*v);
*v = *newv;
(*v)[*vtop] = data;
}
}
Point* PointUniverseComputerSimulation_create_point(__int64 x, __int64 y, __int64 z, energy_state point_state) {
Point* point = new Point();
point->x = x;
point->y = y;
point->z = z;
point->point_state = point_state;
return point;
}
Atom_Star_Galaxy_Dark_Matter* atom_star_galaxy_dark_matter_point_universe_computer_simulation_create_point(__int64 x, __int64 y, __int64 z, __int64 mass) {
Atom_Star_Galaxy_Dark_Matter* point = new Atom_Star_Galaxy_Dark_Matter();
point->x = x;
point->y = y;
point->z = z;
point->mass = mass;
return point;
}
__int64* simp_vector_create(__int64 init_sz) {
__int64* ret = new __int64[init_sz];
return ret;
}
__int64 simp_vector_read(__int64* v, __int64 vtop, __int64 vcap, __int64 loc) {
if (loc > vtop)
return 0;
return v[loc];
}
void simp_vector_append(__int64** v, __int64* vtop, __int64* vcap, __int64 data) {
*vtop = *vtop + 1;
if (*vtop < *vcap)
(*v)[*vtop] = data;
else {
__int64* newv = new __int64[*vcap * 2];
for (__int64 i = 0; i < *vcap * 2; i++)
newv[i] = 0;
for (__int64 i = 0; i < *vcap; i++)
newv[i] = (*v)[i];
*vcap = *vcap * 2;
delete[](*v);
*v = newv;
(*v)[*vtop] = data;
}
}
int id_pool_retrieve(__int64* id_pool, __int64* id_pool_vtop, __int64* id_pool_vcap) {
if (*id_pool_vtop == -1) {
simp_vector_append(*id_pool, id_pool_vtop, id_pool_vcap, 0);
return 0;
}
__int64 id = id_pool[*id_pool_vtop + 1];
__int64 ix = -1;
for (__int64 i = 0; i <= *id_pool_vtop + 1; i++) {
if (id_pool[i] > id) {
ix = i;
break;
}
}
for (__int64 i = ix; i <= *id_pool_vtop; i++)
id_pool[i] = id_pool[i + 1];
return id;
}
void id_pool_submit(__int64* id_pool, __int64* id_pool_vtop, __int64* id_pool_vcap, __int64 id) {
__int64 ix = -1;
for (__int64 i = 0; i <= *id_pool_vtop + 1; i++) {
if (id_pool[i] > id) {
ix = i;
break;
}
}
simp_vector_append(&(id_pool), id_pool_vtop, id_pool_vcap, id_pool[*id_pool_vtop + 1]);
for (__int64 i = ix; i <= *id_pool_vtop; i++)
id_pool[i] = id_pool[i + 1];
id_pool[ix] = id;
}
ID_Pool* create_id_pool() {
ID_Pool* id_pool = new ID_Pool();
id_pool->simulation_entities = simp_vector_create(16);
id_pool->simulation_entities_vtop = -1;
id_pool->simulation_entities_vcap = 16;
id_pool_retrieve(id_pool->simulation_entities, &(id_pool->simulation_entities_vtop), &(id_pool->simulation_entities_vcap));
id_pool_retrieve(id_pool->simulation_entities, &(id_pool->simulation_entities_vtop), &(id_pool->simulation_entities_vcap));
return id_pool;
}
#endif