|
|
@@ -51,6 +51,28 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
|
|
cs_draw.compile();
|
|
|
particles_buffer.bind_base(cs_draw.get_program(), "particles_buffer", 1);
|
|
|
map_buffer.bind_base(cs_draw.get_program(), "map_buffer", 2);
|
|
|
+ }else if (key == GLFW_KEY_C){
|
|
|
+ float distance = std::min(config.map_width, config.map_height) / 5;
|
|
|
+ std::vector<Particle> particles(config.population);
|
|
|
+ for(auto &particle : particles){
|
|
|
+ float angle = random_float(0, 360) * deg_to_rad;
|
|
|
+ particle.dir_x = cosf(angle);
|
|
|
+ particle.dir_y = sinf(angle);
|
|
|
+
|
|
|
+ particle.pos_x = config.map_width / 2 + particle.dir_x * distance;
|
|
|
+ particle.pos_y = config.map_height / 2 + particle.dir_y * distance;
|
|
|
+ }
|
|
|
+ particles_buffer.set(particles.data(), particles.size(), sizeof(particles[0]));
|
|
|
+
|
|
|
+ std::vector<Cell> map(config.map_width * config.map_height);
|
|
|
+ for(auto &cell : map){
|
|
|
+ cell = {
|
|
|
+ .pheromone = 0,
|
|
|
+ .result = 0,
|
|
|
+ .population = 0,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ map_buffer.set(map.data(), map.size(), sizeof(map[0]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -64,7 +86,7 @@ int main(int argc, char *argv[]){
|
|
|
Canvas canvas;
|
|
|
|
|
|
int map_width = 1500;
|
|
|
- int map_height = 1200;
|
|
|
+ int map_height = 800;
|
|
|
size_t population = 5000000;
|
|
|
if(argc > 2){
|
|
|
map_width = strtol(argv[1], nullptr, 0);
|
|
|
@@ -96,12 +118,9 @@ int main(int argc, char *argv[]){
|
|
|
config = new_conf;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
float average_population = (float)config.population / (float)(config.map_width * config.map_height);
|
|
|
float average_pheromone = (float)config.increase * average_population;
|
|
|
|
|
|
- printf("Avg pop %08f - Avg phe %08f\n", average_population, average_pheromone);
|
|
|
-
|
|
|
app = Application(config.map_width, config.map_height);
|
|
|
app.init();
|
|
|
app.create_window();
|
|
|
@@ -128,7 +147,7 @@ int main(int argc, char *argv[]){
|
|
|
particle.pos_x = random_float(0.0f, config.map_width);
|
|
|
particle.pos_y = random_float(0.0f, config.map_height);
|
|
|
|
|
|
- float angle = random_float(0, 360) * deg_to_rad;
|
|
|
+ float angle = random_float(0, 360 * deg_to_rad);
|
|
|
particle.dir_x = cosf(angle);
|
|
|
particle.dir_y = sinf(angle);
|
|
|
}
|
|
|
@@ -170,15 +189,11 @@ int main(int argc, char *argv[]){
|
|
|
app.register_callback(key_callback);
|
|
|
|
|
|
/* Main loop */
|
|
|
- float pervious_time;
|
|
|
- float current_time = app.time();
|
|
|
- int key_previous_status;
|
|
|
- int key_current_status = GLFW_RELEASE;
|
|
|
+ float pervious_time = app.time();
|
|
|
while(app.running()){
|
|
|
- pervious_time = current_time;
|
|
|
- current_time = app.time();
|
|
|
-
|
|
|
- float dt = current_time - pervious_time;
|
|
|
+ float tick = app.time();
|
|
|
+ float dt = tick - pervious_time;
|
|
|
+ pervious_time = tick;
|
|
|
|
|
|
/* Update uniforms */
|
|
|
particle_uniform(config, cs_particles_update);
|
|
|
@@ -208,22 +223,20 @@ int main(int argc, char *argv[]){
|
|
|
canvas.unbind();
|
|
|
|
|
|
/* Reset map */
|
|
|
- cs_map_reset.execute(config.map_width * config.map_height, 256);
|
|
|
+ cs_map_reset.execute(config.map_width, config.map_height, 16, 16);
|
|
|
ComputeShader::wait();
|
|
|
|
|
|
/* Display, move on */
|
|
|
app.update();
|
|
|
-
|
|
|
- key_previous_status = key_current_status;
|
|
|
- key_current_status = app.key_status(GLFW_KEY_R);
|
|
|
- if(key_current_status != key_previous_status
|
|
|
- && key_current_status == GLFW_RELEASE){
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
particles_buffer.release();
|
|
|
map_buffer.release();
|
|
|
canvas.release();
|
|
|
+ cs_draw.release();
|
|
|
+ cs_map_reset.release();
|
|
|
+ cs_map_update.release();
|
|
|
+ cs_particles_update.release();
|
|
|
app.terminate();
|
|
|
|
|
|
return 0;
|