Skip to content

Commit e98667d

Browse files
committed
Релиз новой версии 1.4.1
1 parent 554e052 commit e98667d

6 files changed

+44
-10
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
- **C**: Очистка поля, убить все клетки.
7676
- **G**: Спрятать или показать сетку.
7777
- **U**: Спрятать или показать пользовательский интерфейс GUI.
78+
- **I**: Скопировать выделенную область как паттерн для вставки.
7879
- **Y**: Сменить тип мира (сетка с ограниченными краями или с тороидальными краями).
7980
- **ЛКМ**: Изменение состояния клетки под курсором.
8081
- **ЛКМ + SHIFT и перетаскивание**: Выделить поле, после чего клавишами **INSERT** вставить в выделеное место живые клетки, на **DELETE** удалить живые клетки, **ESCAPE** снять выделение.

game/GameController.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool GameController::getCellState(int x, int y) const {
137137
return grid.getCellState(x, y);
138138
}
139139

140-
void GameController::SetCellInstanceProvider(IRendererProvider* provider) {
140+
void GameController::SetRendererProvider(IRendererProvider* provider) {
141141
rendererProvider = provider;
142142
}
143143

@@ -285,7 +285,6 @@ void GameController::setCurrentPatternFromFile(const std::string& filename, int
285285
PatternManager patternManager;
286286
try {
287287
currentPattern = patternManager.LoadPatternFromCells(filename);
288-
//patternManager.LoadAndPlacePattern(*this, filename, startX, startY);
289288
}
290289
catch (const std::exception& e) {
291290
std::cerr << "Ошибка при выборе паттерна: " << e.what() << std::endl;
@@ -350,4 +349,36 @@ void GameController::ReviveSelectedCells() {
350349
grid.setCellColor(x, y, 0.1f, 0.4f, 0.1f); // Устанавливаем цвет для живой клетки
351350
}
352351
isSelectionActive = false;
352+
}
353+
354+
void GameController::SaveSelectedCellsAsPattern() {
355+
if (!isSelectionActive) return;
356+
357+
// Определяем границы выделения
358+
int minX = static_cast<int>(selectedCells[0].X()), maxX = minX, minY = static_cast<int>(selectedCells[0].Y()), maxY = minY;
359+
for (size_t i = 1; i < selectedCells.size(); ++i) {
360+
int x = static_cast<int>(selectedCells[i].X());
361+
int y = static_cast<int>(selectedCells[i].Y());
362+
363+
// Обновляем минимальные значения
364+
if (x < minX) minX = x;
365+
if (y < minY) minY = y;
366+
367+
// Обновляем максимальные значения
368+
if (x > maxX) maxX = x;
369+
if (y > maxY) maxY = y;
370+
}
371+
372+
// Создаем паттерн
373+
Pattern newPattern(maxY - minY + 1, std::vector<bool>(maxX - minX + 1, false));
374+
// Заполняем паттерн, учитывая правильную ориентацию
375+
for (int y = minY; y <= maxY; ++y) {
376+
for (int x = minX; x <= maxX; ++x) {
377+
// Инвертируем оси Y и X
378+
newPattern[maxY - y][maxX - x] = grid.getCellState(x, y);
379+
}
380+
}
381+
// Сохраняем паттерн
382+
currentPattern = newPattern;
383+
isSelectionActive = false;
353384
}

game/GameController.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class GameController {
150150

151151
Pattern rotateOrFlip(const Pattern& pattern, Rotation rotation);
152152

153-
void SetCellInstanceProvider(IRendererProvider* provider);
153+
void SetRendererProvider(IRendererProvider* provider);
154154

155155
GPUAutomaton& getGPUAutomaton() { return gpuAutomaton; }
156156

@@ -175,5 +175,7 @@ class GameController {
175175
void ReviveSelectedCells();
176176
const std::vector<Vector3d>& GetSelectedCells() const { return selectedCells; }
177177

178+
void SaveSelectedCellsAsPattern();
179+
178180
};
179181
#endif // GAMECONTROLLER_H_

game/GameStateManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool GameStateManager::saveGameState(const Grid& grid, const std::string& filena
2525

2626
// Добавляем комментарии
2727
file << "!Name: Saved world to Pattern\n";
28-
file << "!Description: Just an example\n";
28+
file << "!Description: Just an https://github.com/AsuRaHan/GameOfLife3D\n";
2929

3030
// Сохранение паттерна
3131
for (int y = 0; y < grid.getHeight(); ++y) {

main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int wWinMain(
228228

229229
Renderer renderer(width, height);
230230
renderer.SetGameController(&gameController);
231-
gameController.SetCellInstanceProvider(&renderer);
231+
gameController.SetRendererProvider(&renderer);
232232

233233
// Передаем один и тот же экземпляр gameController в WindowController
234234
WindowController controller(&renderer, &gameController);

windowing/WindowController.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ void WindowController::HandleEvent(UINT message, WPARAM wParam, LPARAM lParam) {
177177
case 'U':
178178
pGameController->setShowUI(!pGameController->getShowUI());
179179
break;
180-
//case 'O':
181-
// if (!pGameController->isSimulationRunning()) {
182-
// pGameController->setGpuSimulated(!pGameController->getGpuSimulated()); // переключить метод симуляции с GPU на CPU
183-
// }
184-
// break;
180+
case 'I':
181+
if (!pGameController->isSimulationRunning()) {
182+
pGameController->SaveSelectedCellsAsPattern();
183+
}
184+
break;
185185
}
186186
break;
187187
default:

0 commit comments

Comments
 (0)