Skip to content

Commit 212fe5d

Browse files
committed
Предрелизная подготовка завершена
1 parent 51f4e5f commit 212fe5d

File tree

5 files changed

+82
-33
lines changed

5 files changed

+82
-33
lines changed

game/GPUAutomaton.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ GPUAutomaton::GPUAutomaton(int width, int height)
99
}
1010

1111
GPUAutomaton::~GPUAutomaton() {
12-
GL_CHECK(glDeleteBuffers(2, cellsBuffer));
13-
GL_CHECK(glDeleteBuffers(1, &colorsBuffer));
12+
if (cellsBuffer[0] && cellsBuffer[1]) {
13+
GL_CHECK(glDeleteBuffers(2, cellsBuffer));
14+
}
15+
if (colorsBuffer) {
16+
GL_CHECK(glDeleteBuffers(1, &colorsBuffer));
17+
}
1418
}
1519

1620
void GPUAutomaton::CreateComputeShader() {

game/GameController.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ void GameController::placePattern(int startX, int startY, const Pattern& pattern
2525
int patternHeight = static_cast<int>(pattern.size());
2626
int patternWidth = static_cast<int>(pattern[0].size());
2727

28+
if (startX < 0 || startY < 0 ||
29+
startX + patternWidth > grid.getWidth() ||
30+
startY + patternHeight > grid.getHeight()) {
31+
return; // Паттерн не помещается
32+
}
33+
2834
// Проверяем, помещается ли фигура в пределах сетки
2935
if (startX + patternWidth <= grid.getWidth() && startY + patternHeight <= grid.getHeight()) {
3036
for (auto y = patternHeight - 1; y >= 0; --y) { // Итерируемся снизу вверх
@@ -73,19 +79,17 @@ void GameController::clearGrid() {
7379
}
7480

7581
void GameController::update(float deltaTime) {
82+
static auto lastUpdate = std::chrono::steady_clock::now();
7683
if (isRunning) {
77-
if (simulationSpeed != 0) {
78-
// Вычисляем прошедшее время с последнего обновления
79-
DWORD elapsedTime = deltaTime - frameTimeAccumulator;
80-
if (elapsedTime >= simulationSpeed) {
81-
gpuAutomaton.Update();
82-
// Увеличиваем аккумулятор на simulationSpeed, а не сбрасываем на deltaTime
83-
frameTimeAccumulator += simulationSpeed;
84-
PerformanceStats::getInstance().recordSimulation();
85-
}
84+
auto now = std::chrono::steady_clock::now();
85+
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastUpdate).count();
86+
87+
if (simulationSpeed != 0 && elapsed >= simulationSpeed) {
88+
gpuAutomaton.Update();
89+
lastUpdate = now;
90+
PerformanceStats::getInstance().recordSimulation();
8691
}
87-
else {
88-
// Без задержки — каждый кадр
92+
else if (simulationSpeed == 0) {
8993
gpuAutomaton.Update();
9094
PerformanceStats::getInstance().recordSimulation();
9195
}

rendering/CellsViewportRenderer.cpp

+27-6
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,41 @@ void CellsViewportRenderer::LoadShaders() {
203203
cellShaderProgram = LoadShaderProgram("viewportCellShader", vertexShaderSource, fragmentShaderSource);
204204
}
205205

206+
//void CellsViewportRenderer::UpdateVisibleCells() {
207+
// int minX, minY, maxX, maxY;
208+
// GetVisibleGridBounds(minX, minY, maxX, maxY);
209+
//
210+
// float cellSize = pGameController->getCellSize();
211+
// int gridWidth = pGameController->getGridWidth();
212+
// visibleCellInstances.clear();
213+
//
214+
// // Сохраняем информацию о каждой клетке
215+
// for (int y = minY; y <= maxY; ++y) {
216+
// for (int x = minX; x <= maxX; ++x) {
217+
// float worldX = x * cellSize;
218+
// float worldY = y * cellSize;
219+
// visibleCellInstances.push_back({worldX, worldY});
220+
// }
221+
// }
222+
//}
223+
206224
void CellsViewportRenderer::UpdateVisibleCells() {
207225
int minX, minY, maxX, maxY;
208226
GetVisibleGridBounds(minX, minY, maxX, maxY);
209-
210227
float cellSize = pGameController->getCellSize();
211-
int gridWidth = pGameController->getGridWidth();
212228
visibleCellInstances.clear();
213229

214-
// Сохраняем информацию о каждой клетке
230+
std::vector<int> gridState;
231+
pGameController->getGPUAutomaton().GetGridState(gridState);
232+
215233
for (int y = minY; y <= maxY; ++y) {
216234
for (int x = minX; x <= maxX; ++x) {
217-
float worldX = x * cellSize;
218-
float worldY = y * cellSize;
219-
visibleCellInstances.push_back({worldX, worldY});
235+
int index = y * pGameController->getGridWidth() + x;
236+
if (gridState[index] > 0) { // Только живые клетки
237+
float worldX = x * cellSize;
238+
float worldY = y * cellSize;
239+
visibleCellInstances.push_back({ worldX, worldY });
240+
}
220241
}
221242
}
222243
}

windowing/MainWindow.cpp

+32-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#include "MainWindow.h"
22

3+
4+
//// Динамическая загрузка RtlGetVersion
5+
typedef LONG(NTAPI* RtlGetVersionFunc)(RTL_OSVERSIONINFOW*);
6+
7+
bool GetOSVersion(RTL_OSVERSIONINFOW& osvi) {
8+
HMODULE hMod = GetModuleHandleW(L"ntdll.dll");
9+
if (!hMod) return false;
10+
11+
RtlGetVersionFunc RtlGetVersion = (RtlGetVersionFunc)GetProcAddress(hMod, "RtlGetVersion");
12+
if (!RtlGetVersion) return false;
13+
14+
osvi.dwOSVersionInfoSize = sizeof(osvi);
15+
return RtlGetVersion(&osvi) == 0; // Успех, если возвращается STATUS_SUCCESS (0)
16+
}
17+
18+
319
MainWindow::MainWindow(HINSTANCE hInstance, int width, int height, int xPos, int yPos) :
420
hInstance(hInstance), hWnd(NULL), pController(nullptr),
521
windowWidth(width), windowHeight(height),
@@ -10,21 +26,23 @@ MainWindow::MainWindow(HINSTANCE hInstance, int width, int height, int xPos, int
1026
HWND MainWindow::Create() {
1127

1228
// Проверка версии Windows
13-
OSVERSIONINFOEX osvi;
14-
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
15-
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
16-
GetVersionEx((LPOSVERSIONINFO)&osvi);
17-
18-
// Windows 8.1 = Major 6, Minor 3
19-
if (osvi.dwMajorVersion < 6 || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion < 3)) {
20-
int result = MessageBox(NULL,
21-
L"Извините, но ваша версия Windows ниже 8.1. Это слишком мало для меня!\nХотите посетить сайт разработчика для поддержки?",
22-
L"Ошибка версии Windows",
23-
MB_YESNO | MB_ICONERROR);
24-
if (result == IDYES) {
25-
ShellExecute(NULL, L"open", L"https://yourwebsite.com", NULL, NULL, SW_SHOWNORMAL);
29+
RTL_OSVERSIONINFOW osvi = { 0 };
30+
if (GetOSVersion(osvi)) {
31+
// Пример проверки: требуется Windows 7 или новее (Major Version >= 6, Minor Version >= 1)
32+
if (osvi.dwMajorVersion < 8 || (osvi.dwMajorVersion == 1 && osvi.dwMinorVersion < 0)) {
33+
int result = MessageBox(NULL,
34+
L"Извините, но ваша версия Windows ниже 8.1. Это слишком мало для меня!\nХотите посетить сайт разработчика для поддержки?",
35+
L"Ошибка версии Windows",
36+
MB_YESNO | MB_ICONERROR);
37+
if (result == IDYES) {
38+
ShellExecute(NULL, L"open", L"https://support.microsoft.com/ru-ru/windows", NULL, NULL, SW_SHOWNORMAL);
39+
}
40+
exit(1); // Завершаем создание окна
2641
}
27-
exit(1); // Завершаем создание окна
42+
43+
}
44+
else {
45+
MessageBox(nullptr, L"Я не смог определить версию windows, но попробую запустится, надеюсь получится.", L"Error", MB_OK | MB_ICONERROR);
2846
}
2947

3048
WNDCLASSEX wc = { 0 };

windowing/MainWindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#define MAINWINDOW_H_
44

55
#include <Windows.h>
6+
#include <ntverp.h>
7+
68
#include "../res/resource.h"
79
#include "WindowController.h"
810

0 commit comments

Comments
 (0)