Nano v1.0.0
Simulating Natural Selection
simulator.h
Go to the documentation of this file.
1#pragma once
2
3#include "sceneManager.h"
4#include "simulation.h"
5#include "utils.h"
6#include <array>
7#include <raygui.h>
8#include <raylib.h>
9
11{
12class Simulator : public Scene
13{
14 private:
15 // Instance of scene manager class, used to change scenes
18
19 // 2D variables
20 Vector2 mousePos;
21 Vector2 planePos;
22
23 // Textures
28 Texture2D exit_Button;
30 Texture2D checkmark;
31 Texture2D dropDown_Arrow;
33
35 Texture2D entityGoingHome;
38
39 // Camera
40 Camera3D camera{0};
41 Camera3D entityCamera{0};
42
43 // Font
45
46 // Variables, used for initializing the simulation
49 size_t worldSize;
50 size_t entities;
51 size_t food;
52 // size_t currentCycle;
53
54 float offset;
57 // float entityRadius;
58 // float* radiusArray;
60
64
66 float timeScale;
71
73 {
74 SPEED,
75 ENERGY,
77
78 // Variable, stores the current scene state
79 enum class SimulatorState
80 {
81 Setup,
82 Simulation
84
85 // Getter variables
87 {
95
96 const std::array<std::string, 4> entityThoughts = {"SearchingFood", "GoingFood", "GoingHome", "Idle"};
97
98 // Methods, used to draw scenes
99 void drawSetup();
100 void drawSimulation();
101 void drawSummary();
102 void drawAdditionalMenu();
103 void drawTraitsSwitch();
104 void drawProgressBar();
105
106 // void drawEntity(const auto &entity, float radius);
107 void drawEntity(const ss::bll::simulation::Entity &entity);
108 void drawFood(const auto &food);
110
111 float animateProgress();
112 // float animateDying(float currentRadius);
113
114 // Getter methods
115 SummaryInfo getSummaryData();
116
117 // Method which checks the mouse/keyboard input
118 void checkInput();
119 void handleEntityClick();
120
121 // Method that resets the camera position, rotation, look
122 void resetCamera();
123
124 public:
125 Simulator(std::string sceneName, SceneManager &sceneManager);
126
127 virtual void Start();
128
129 virtual void Update();
130
131 virtual void onExit();
132
133 virtual void loadAssets();
134
135 virtual void deleteAssets();
136};
137} // namespace ss::pl::simulator
Definition: Scene.h:9
Definition: SceneManager.h:8
A class representing a single entity in the simulation.
Definition: simulation.h:45
A class representing the simulation.
Definition: simulation.h:157
Definition: simulator.h:13
ss::bll::simulation::Simulation * simulation
Definition: simulator.h:17
bool shouldShowTraits
Definition: simulator.h:70
virtual void Start()
Method which is called in the start of the Simulation page.
Definition: simulator.cpp:17
virtual void deleteAssets()
Method for deallocating the dynamically created assets.
Definition: simulator.cpp:585
void drawFood(const auto &food)
Method for drawing every food on the simulation field.
Definition: simulator.cpp:498
Texture2D entityShouldBreed
Definition: simulator.h:37
ss::bll::simulation::Entity * selectedEntity
Definition: simulator.h:62
size_t cyclesCount
Definition: simulator.h:48
float entityLookingDirRadian
Definition: simulator.h:55
float timeScale
Definition: simulator.h:66
float aminationProgress
Definition: simulator.h:56
Texture2D checkmark
Definition: simulator.h:30
virtual void loadAssets()
Method for loading all the needed assets in the Simulation page.
Definition: simulator.cpp:560
Vector2 planePos
Definition: simulator.h:21
float offset
Definition: simulator.h:54
void drawTraitsSwitch()
Function to draw the switch in the additionals menu.
Definition: simulator.cpp:395
bool followingEntity
Definition: simulator.h:63
const std::array< std::string, 4 > entityThoughts
Definition: simulator.h:96
size_t food
Definition: simulator.h:51
SceneManager & m_sceneManager
Definition: simulator.h:16
void drawAdditionalMenu()
Method for drawing controls menu at simulation runtime.
Definition: simulator.cpp:329
Vector2 mousePos
Definition: simulator.h:20
void handleEntityClick()
Method for handling the camera and collision for clickig on entity.
Definition: simulator.cpp:173
void drawEntityThoughts(const ss::bll::simulation::Entity *entity)
Function that draws the thoughts of a desired entity.
Definition: simulator.cpp:511
enum ss::pl::simulator::Simulator::SimulatorState currentState
void checkInput()
This method creates checks for the mouse input during the actual simulation.
Definition: simulator.cpp:80
Camera3D entityCamera
Definition: simulator.h:41
Texture2D backArrow_Texture
Definition: simulator.h:25
float animateProgress()
Method for animating the progress bar at the bottom of simuation.
Definition: simulator.cpp:426
int newFoodChange
Definition: simulator.h:68
Texture2D entitySearchingFood
Definition: simulator.h:34
Font fontInter
Definition: simulator.h:44
Camera3D camera
Definition: simulator.h:40
void resetCamera()
Method for reseting the camera to its initial position.
Definition: simulator.cpp:196
bool savedSimulationInfo
Definition: simulator.h:94
void drawEntity(const ss::bll::simulation::Entity &entity)
Method for drawing every entity at the simulation field.
Definition: simulator.cpp:442
Texture2D setupContainer_Texture
Definition: simulator.h:24
Texture2D exit_Button
Definition: simulator.h:28
Texture2D save_Data_Button
Definition: simulator.h:29
bool additionalMenuTriggered
Definition: simulator.h:65
Texture2D dropDown_Arrow_Selected
Definition: simulator.h:32
struct ss::pl::simulator::Simulator::SummaryInfo summaryInfo
void drawProgressBar()
Method for drawing the progress bar at the bottom of simuation.
Definition: simulator.cpp:376
size_t worldSize
Definition: simulator.h:49
bool catchSummaryInfo
Definition: simulator.h:93
bool shouldShowProgressBar
Definition: simulator.h:69
SLECTED_TRAITS_MONITOR
Definition: simulator.h:73
Texture2D entityGoingHome
Definition: simulator.h:35
size_t entities
Definition: simulator.h:50
void drawSimulation()
Method for drawing the actual simulation.
Definition: simulator.cpp:241
Texture2D summary_Container
Definition: simulator.h:27
SummaryInfo getSummaryData()
Method for getting the data for summary screen.
Definition: simulator.cpp:549
SimulatorState
Definition: simulator.h:80
enum ss::pl::simulator::Simulator::SLECTED_TRAITS_MONITOR selectedTraitsMonitor
Texture2D simulateButton_Texture
Definition: simulator.h:26
void drawSetup()
Method for drawing the setUp page before the actual simulation.
Definition: simulator.cpp:206
virtual void Update()
Method which is called every frame.
Definition: simulator.cpp:50
size_t selectedEntityId
Definition: simulator.h:61
Texture2D entityGoingTowardsFood
Definition: simulator.h:36
int foodChange
Definition: simulator.h:67
virtual void onExit()
Method which is called when we exit the program or the Simulation page.
Definition: simulator.cpp:70
float graphsContainerPos
Definition: simulator.h:47
bool simulating
Definition: simulator.h:59
Texture2D dropDown_Arrow
Definition: simulator.h:31
Simulator(std::string sceneName, SceneManager &sceneManager)
Constructor for the Simulation class.
Definition: simulator.cpp:7
void drawSummary()
Method for drawing summary screen at the end of the simulation.
Definition: simulator.cpp:308
Definition: simulator.h:11
float averageSpeed
Definition: simulator.h:90
size_t diedEntities
Definition: simulator.h:89
size_t activeEntites
Definition: simulator.h:88
float averageSense
Definition: simulator.h:91