-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
90 lines (73 loc) · 2.69 KB
/
main.cpp
File metadata and controls
90 lines (73 loc) · 2.69 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
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <iostream>
#include "inc/ParticleStores/BaseParticleStore.h"
#include "inc/ParticleStores/EdgePositionedParticleStore.h"
#include "inc/ParticleStores/RandomPositionedParticleStore.h"
#include "inc/Particle.h"
#include "inc/Engine.h"
#include <thread>
#include <chrono>
#include "inc/config.h"
#include "inc/ParticleStores/ParticleStoreFactory.h"
#include "src/Windows/GridWindow.cpp"
#include "src/RenderMachines/BaseRenderMachine.cpp"
#include "src/RenderMachines/TwoDimensionalRenderMachine.cpp"
// Use standard library components globally
using namespace std;
void countDown(int time_before_start)
{
// Simple countdown before simulation starts
cout << "Iteration will start in " << endl;
for (int i = 0; i < time_before_start / 1000; i++)
{
cout << time_before_start / 1000 - i << endl;
this_thread::sleep_for(chrono::milliseconds(1000));
}
}
int main(int argc, char **argv)
{
// Initialization of randomness for particle positions
srand(time(0));
// Set up the simulation space metadata
SpaceMetadata *space_data = new SpaceMetadata();
space_data->setMetaData(GRID_WIDTH, GRID_HEIGHT, 2);
// Initialize particle store and engine
BaseParticleStore *particle_store = ParticleStoreFactory::initialize(PARTICLE_STORE_TYPE, space_data);
particle_store->initialize(DENSITY, CENTER_DENSITY);
// Setup engine
Engine *engine = new Engine(particle_store, space_data);
BaseWindow *window_instance = new GridWindow();
// Set up the window and particles
GLFWwindow *window = window_instance->initialize(800, 800, "2D Particle aggregation Simulation");
Particle **particles = particle_store->getParticles();
// Setup rendermachine and visualization
BaseRenderMachine *render_machine = new TwoDimensionalRenderMachine();
render_machine->render(window, particles);
// Countdown before starting the simulation
countDown(COUNTDOWN_FOR_SIMULATION_MS);
// Main simulation loop
size_t n_iteration = 1;
while (!glfwWindowShouldClose(window) && !particle_store->reachedTerminalState())
{
engine->update();
cout << "Engine updated at iteration " << n_iteration << endl;
render_machine->render(window, particles);
glfwPollEvents();
this_thread::sleep_for(chrono::milliseconds(SIMULATION_TIME_MS));
n_iteration++;
}
cout << "Simulation ended" << endl;
// Cleanup and close the window
while (!glfwWindowShouldClose(window))
{
}
// Cleanup
delete particle_store;
delete engine;
delete render_machine;
delete space_data;
delete window_instance;
glfwTerminate();
return 0;
}