Skip to content

Commit 5c55cbc

Browse files
committed
Готовлю новый релиз
1 parent c1d7418 commit 5c55cbc

13 files changed

+129
-478
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ git push origin v1.0.0
180180

181181
- **./system**: Настройка системы, OpenGL и пользовательского ввода:
182182
- `OpenGLInitializer.h`, `OpenGLInitializer.cpp` - Инициализация контекста OpenGL
183-
- `GLFunctions.h`, `GLFunctions.cpp` - Загрузка функций OpenGL
183+
- `GLFunctions.h`, `GLFunctions.cpp` - Загрузка функций OpenGL (урезанный GLAD)
184184
- `ShaderManager.h`, `ShaderManager.cpp` - Создание компиляция проверка шейдеров (GLSL) OpenGL
185185
- `SettingsManager.h`, `SettingsManager.cpp` - Сохранение и загрузка пользовательских настроек.
186186
- `InputHandler.h`, `InputHandler.cpp` - Обработчик пользовательского ввода (клавиатура мыш).

game/GPUAutomaton.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ void GPUAutomaton::Update() {
190190
glDispatchCompute((gridWidth + 31) / 32, (gridHeight + 31) / 32, 1);
191191
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
192192

193-
//bufferIndex = (bufferIndex + 1) % 2;
194-
195193
SwapBuffers();
196194
}
197195
// Êàê ýòî ðàáîòàåò

game/GameController.cpp

+16-30
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#include "GameController.h"
22

33
GameController::GameController(int width, int height, float cellSize)
4-
: grid(width, height), GameSimulation(grid), cellSize(cellSize),
5-
isRunning(false), showGrid(true), showUI(true),
4+
: grid(width, height),
5+
gpuAutomaton(grid.getWidth(), grid.getHeight()),
6+
cellSize(cellSize),
7+
isRunning(false), showGrid(true), showUI(true), isWorldToroidal(true),
68
currentPatternRotator(0), isSelectionActive(false),
79
rendererProvider(nullptr)
810
{
911
currentPattern = glider;
1012
std::srand(static_cast<unsigned int>(std::time(nullptr))); // Èíèöèàëèçàöèÿ ãåíåðàòîðà ñëó÷àéíûõ ÷èñåë
11-
13+
grid.SetGPUAutomaton(&gpuAutomaton);
1214
}
1315

1416
void GameController::randomizeGrid() {
@@ -77,6 +79,12 @@ void GameController::PlacePattern(int startX, int startY) {
7779
}
7880
}
7981

82+
void GameController::setWoldToroidal(bool wt)
83+
{
84+
isWorldToroidal = wt;
85+
gpuAutomaton.SetToroidal(isWorldToroidal);
86+
}
87+
8088
void GameController::randomizeGrid(float density) {
8189
if (isRunning) return;
8290
// Ãåíåðàòîð ñëó÷àéíûõ ÷èñåë
@@ -113,7 +121,7 @@ void GameController::update(float deltaTime) {
113121
if (isRunning) {
114122
//frameTimeAccumulator += deltaTime;
115123
//if (frameTimeAccumulator >= simulationSpeed) {
116-
GameSimulation.nextGeneration();
124+
gpuAutomaton.Update();
117125
// frameTimeAccumulator -= simulationSpeed;
118126
//}
119127
}
@@ -129,7 +137,7 @@ void GameController::stopSimulation() {
129137

130138
void GameController::stepSimulation() {
131139
if (isRunning) return;
132-
GameSimulation.nextGeneration();
140+
gpuAutomaton.Update();
133141
}
134142

135143
bool GameController::isSimulationRunning() const {
@@ -162,7 +170,7 @@ bool GameController::getCellState(int x, int y) const {
162170

163171
void GameController::SetCellInstanceProvider(IRendererProvider* provider) {
164172
rendererProvider = provider;
165-
GameSimulation.SetCellProvider(provider); // Ïåðåäàåì ïðîâàéäåðà â GameOfLife
173+
//GameSimulation.SetCellProvider(provider); // Ïåðåäàåì ïðîâàéäåðà â GameOfLife
166174
}
167175

168176
void GameController::setFieldSize(int newWidth, int newHeight) {
@@ -172,30 +180,8 @@ void GameController::setFieldSize(int newWidth, int newHeight) {
172180
}
173181
if (newWidth <= 0 || newHeight <= 0) return; // Ïðîâåðêà íà ïîëîæèòåëüíûé ðàçìåð
174182

175-
// Ñîçäàåì íîâóþ ñåòêó ñ íîâûìè ðàçìåðàìè
176-
Grid newGrid(newWidth, newHeight);
177-
178-
// Êîïèðóåì ñòàðûå äàííûå â íîâóþ ñåòêó, ãäå ýòî âîçìîæíî
179-
for (int y = 0; y < grid.getHeight(); ++y) {
180-
if (y >= newHeight) break; // Âûõîäèì èç öèêëà, åñëè ïðåâûøàåì íîâóþ âûñîòó
181-
for (int x = 0; x < grid.getWidth(); ++x) {
182-
if (x >= newWidth) break; // Âûõîäèì èç öèêëà, åñëè ïðåâûøàåì íîâóþ øèðèíó
183-
184-
bool currentState = grid.getCellState(x, y);
185-
newGrid.setCellState(x, y, currentState);
186-
if (currentState) {
187-
newGrid.setCellColor(x, y, 0.1f, 0.4f, 0.1f);
188-
}
189-
else {
190-
newGrid.setCellColor(x, y, 0.0f, 0.0f, 0.0f);
191-
}
192-
}
193-
}
194-
// Îáíîâëÿåì òåêóùóþ ñåòêó
195-
grid = std::move(newGrid);
196-
197-
// Îáíîâëÿåì ññûëêó íà ñåòêó â GameOfLife
198-
GameSimulation.updateGridReference(grid);
183+
grid.setSize(newWidth, newHeight);
184+
gpuAutomaton.SetNewGridSize(newWidth, newHeight);
199185
// Ïåðåä ïåðåñòðîéêîé áóôåðîâ, óâåäîìëÿåì ðåíäåð î íåîáõîäèìîñòè îáíîâëåíèé
200186
rendererProvider->RebuildGameField();
201187
}

game/GameController.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
#ifndef GAMECONTROLLER_H_
33
#define GAMECONTROLLER_H_
44

5-
#include "GameSimulation.h"
5+
//#include "GameSimulation.h"
6+
67
#include "Grid.h"
8+
#include "GPUAutomaton.h"
79
#include "GameStateManager.h"
810
#include "PatternManager.h"
11+
#include "../rendering/IRendererProvider.h"
912

1013
#include <random> // Äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
1114
#include <string>
@@ -21,11 +24,13 @@ using Pattern = std::vector<std::vector<bool>>;
2124
class GameController {
2225
private:
2326
Grid grid;
24-
GameSimulation GameSimulation;
27+
//GameSimulation GameSimulation;
28+
GPUAutomaton gpuAutomaton; // ÷ëåí êëàññà äëÿ âû÷èñëåíèé íà GPU
2529
float cellSize; // Ðàçìåð êàæäîé êëåòêè â ïèêñåëÿõ
2630
bool isRunning; // Ôëàã, ïîêàçûâàåò, çàïóùåíà ëè ñèìóëÿöèÿ
2731
bool showGrid;
2832
bool showUI;
33+
bool isWorldToroidal;
2934
float simulationSpeed = 0.01f; // Çíà÷åíèå 1.0f ìîæåò ñîîòâåòñòâîâàòü îäíîé ñåêóíäå ðåàëüíîãî âðåìåíè
3035
float frameTimeAccumulator = 0.0f;
3136

@@ -132,8 +137,8 @@ class GameController {
132137

133138
void PlacePattern(int startX, int startY);
134139

135-
void setWoldToroidal(bool wt) { GameSimulation.setWoldToroidal( wt); };
136-
bool getWoldToroidal() const { return GameSimulation.getWoldToroidal(); };
140+
void setWoldToroidal(bool wt);
141+
bool getWoldToroidal() const { return isWorldToroidal; };
137142

138143
void setSimulationSpeed(float speed);
139144

@@ -147,7 +152,7 @@ class GameController {
147152

148153
void SetCellInstanceProvider(IRendererProvider* provider);
149154

150-
GPUAutomaton& getGPUAutomaton() { return GameSimulation.getGPUAutomaton(); }
155+
GPUAutomaton& getGPUAutomaton() { return gpuAutomaton; }
151156

152157
// Íîâûé ìåòîä äëÿ çàãðóçêè ñïèñêà ïàòòåðíîâ
153158
void loadPatternList(const std::string& patternFolder = "patterns");

game/GameSimulation.cpp

-115
This file was deleted.

game/GameSimulation.h

-48
This file was deleted.

game/Grid.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ int Grid::getWidth() const {
3737

3838
int Grid::getHeight() const {
3939
return height;
40-
}
40+
}
41+
42+
void Grid::setSize(int w, int h)
43+
{
44+
width = w;
45+
height = h;
46+
}

game/Grid.h

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Grid {
1616
void setCellState(int x, int y, bool alive);
1717
bool getCellState(int x, int y) const;
1818
int getWidth() const;
19+
void setWidth(int w) { width = w; };
1920
int getHeight() const;
21+
void setHeight(int h) { height = h; };
22+
void setSize(int w, int h);
2023
};
2124
#endif // GRID_H_

life.vcxproj

-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
<ClCompile Include="external\imgui\imgui_tables.cpp" />
157157
<ClCompile Include="external\imgui\imgui_widgets.cpp" />
158158
<ClCompile Include="game\GameController.cpp" />
159-
<ClCompile Include="game\GameSimulation.cpp" />
160159
<ClCompile Include="game\GameStateManager.cpp" />
161160
<ClCompile Include="game\GPUAutomaton.cpp" />
162161
<ClCompile Include="game\Grid.cpp" />
@@ -185,7 +184,6 @@
185184
<ClInclude Include="external\imgui\imgui.h" />
186185
<ClInclude Include="external\imgui\imgui_internal.h" />
187186
<ClInclude Include="game\GameController.h" />
188-
<ClInclude Include="game\GameSimulation.h" />
189187
<ClInclude Include="game\GameStateManager.h" />
190188
<ClInclude Include="game\GPUAutomaton.h" />
191189
<ClInclude Include="game\Grid.h" />

life.vcxproj.filters

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<ClCompile Include="game\GameController.cpp">
55
<Filter>game</Filter>
66
</ClCompile>
7-
<ClCompile Include="game\GameSimulation.cpp">
8-
<Filter>game</Filter>
9-
</ClCompile>
107
<ClCompile Include="rendering\Camera.cpp">
118
<Filter>rendering</Filter>
129
</ClCompile>
@@ -91,12 +88,6 @@
9188
</ClCompile>
9289
</ItemGroup>
9390
<ItemGroup>
94-
<ClInclude Include="game\GameController.h">
95-
<Filter>game</Filter>
96-
</ClInclude>
97-
<ClInclude Include="game\GameSimulation.h">
98-
<Filter>game</Filter>
99-
</ClInclude>
10091
<ClInclude Include="rendering\Camera.h">
10192
<Filter>rendering</Filter>
10293
</ClInclude>
@@ -181,6 +172,9 @@
181172
<ClInclude Include="system\OpenGLDebug.h">
182173
<Filter>system</Filter>
183174
</ClInclude>
175+
<ClInclude Include="game\GameController.h">
176+
<Filter>game</Filter>
177+
</ClInclude>
184178
</ItemGroup>
185179
<ItemGroup>
186180
<Filter Include="game">

0 commit comments

Comments
 (0)