Nano v1.0.0
Simulating Natural Selection
graph.h
Go to the documentation of this file.
1#pragma once
2#include "sceneManager.h"
3#include "simulation_data.h"
4#include <raygui.h>
5#include <raylib.h>
6#include <string>
7#include <vector>
8
9namespace ss::pl::graph
10{
11class Graph : public Scene
12{
13 private:
14 // Textures
16 Texture2D graph_Container;
17 Texture2D cycle_Next;
18 Texture2D cycle_Prev;
19 Texture2D slider_Box;
20 Texture2D auto_Button;
21 Texture2D data_Container;
22
23 // Vector2 variables
24 Vector2 mousePos;
25 Vector2 graphLine;
26 Vector2 graphText;
27
28 // Custom font
30
31 // Variables, regarding each cycle and it's data
33 unsigned int totalAlive;
39
40 std::string populationChange;
41
42 std::vector<ss::types::Cycle> cycleInfo;
43
44 // Pairs, used to pair cycle data
45 std::pair<float, float> getHighestSenseAndSpeed(const std::vector<ss::types::Cycle> &cycle);
46
47 std::pair<float, float> maxSenseAndSpeed;
48
49 // Methods for drawing textures
50 void drawGraph();
51 void drawMenu();
52
53 // Methods, checking mouse collisions
54 void checkCollision();
55
56 // Mathods, automating cycle
57 void automateCycle();
58
59 enum class AutoState
60 {
61 AutoOn,
62 AutoOff
64
65 const std::array<std::string, 2> autoPaths = {"Auto_Button_Checked", "Auto_Button_Unchecked"};
66
67 // Mathods, drawing and calculating graph info
68 std::vector<ss::types::Trait> traitData;
69 const std::array<Color, 2> graphColors{{{246, 245, 250, 255}, {108, 108, 108, 255}}};
70
71 void getTraitData(size_t cycle);
72 void drawTrait();
73 Vector2 calculateTraitPosition(float sence, float speed);
74
75 public:
76 Graph(std::string sceneName, SceneManager &sceneManager);
77
78 // Inline static variable, used to save opened graph file
79 inline static std::string fileName;
80
81 // Derived methods from class Scene
82 virtual void Start();
83
84 virtual void Update();
85
86 virtual void onExit();
87
88 virtual void loadAssets();
89
90 virtual void deleteAssets();
91
93
94 // Methods, used to calculate cycle data
95 static float getHighestSense(const std::vector<ss::types::Cycle> &cycle);
96
97 static float getHighestSpeed(const std::vector<ss::types::Cycle> &cycle);
98
99 static inline float getGrowthPercentage(int lastedBef, int lastedCur);
100
101 static inline float getDecreasedPercentage(int lastedBef, int lastedCur);
102};
103} // namespace ss::pl::graph
Definition: Scene.h:9
Definition: SceneManager.h:8
Definition: graph.h:12
virtual void Start()
Method which is called in the start of the Graph page.
Definition: graph.cpp:15
float currentSpeed
Definition: graph.h:35
float currentSense
Definition: graph.h:34
static float getGrowthPercentage(int lastedBef, int lastedCur)
Method for getting the Growth percentage.
Definition: graph.cpp:127
Texture2D slider_Box
Definition: graph.h:19
Texture2D data_Container
Definition: graph.h:21
std::pair< float, float > maxSenseAndSpeed
Definition: graph.h:47
static float getHighestSense(const std::vector< ss::types::Cycle > &cycle)
Getter highest sense function.
Definition: graph.cpp:63
enum ss::pl::graph::Graph::AutoState currentAutoState
void checkCollision()
Method for checking the collision on click.
Definition: graph.cpp:298
std::vector< ss::types::Trait > traitData
Definition: graph.h:68
Graph(std::string sceneName, SceneManager &sceneManager)
Constructor for the Graph class.
Definition: graph.cpp:9
virtual void Update()
Method which is called every frame.
Definition: graph.cpp:32
AutoState
Definition: graph.h:60
Texture2D auto_Button
Definition: graph.h:20
void automateCycle()
Method for automating the cycle change.
Definition: graph.cpp:397
void drawGraph()
Method for drawing the Graph body.
Definition: graph.cpp:178
virtual void onExit()
Method which is called when we exit the program or the Graph page.
Definition: graph.cpp:52
const std::array< Color, 2 > graphColors
Definition: graph.h:69
Texture2D cycle_Next
Definition: graph.h:17
void getTraitData(size_t cycle)
Method for loading trait data.
Definition: graph.cpp:147
bool autoCycle
Definition: graph.h:36
virtual void deleteAssets()
Method for deallocating the dynamically created assets.
Definition: graph.cpp:284
int cycleSpeed
Definition: graph.h:37
Vector2 graphLine
Definition: graph.h:25
static float getDecreasedPercentage(int lastedBef, int lastedCur)
Method for getting the Decreased percentage.
Definition: graph.cpp:138
Texture2D graph_Container
Definition: graph.h:16
const std::array< std::string, 2 > autoPaths
Definition: graph.h:65
SceneManager & m_sceneManager
Definition: graph.h:92
unsigned int totalAlive
Definition: graph.h:33
static std::string fileName
Definition: graph.h:79
void drawMenu()
Method for drawing the menu in the graph page.
Definition: graph.cpp:232
Font fontInter
Definition: graph.h:29
std::vector< ss::types::Cycle > cycleInfo
Definition: graph.h:42
float fElapsedTime
Definition: graph.h:38
virtual void loadAssets()
Method for loading all the needed assets in the graph page.
Definition: graph.cpp:252
size_t currentCycle
Definition: graph.h:32
static float getHighestSpeed(const std::vector< ss::types::Cycle > &cycle)
Getter highest speed function.
Definition: graph.cpp:89
Texture2D cycle_Prev
Definition: graph.h:18
Vector2 calculateTraitPosition(float sence, float speed)
Method for calculating trait data position.
Definition: graph.cpp:170
void drawTrait()
Method for drawing trait data into the graph.
Definition: graph.cpp:155
Vector2 mousePos
Definition: graph.h:24
Vector2 graphText
Definition: graph.h:26
Texture2D backArrow_Texture
Definition: graph.h:15
std::pair< float, float > getHighestSenseAndSpeed(const std::vector< ss::types::Cycle > &cycle)
Function returning the highest sense and speed.
Definition: graph.cpp:116
std::string populationChange
Definition: graph.h:40
Definition: graph.h:10