Skip to content

Commit e190de2

Browse files
committed
Отрисовка клеток оптимизирована для производительности
1 parent 6272344 commit e190de2

15 files changed

+605
-224
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ git push origin v1.0.0
184184
- `Renderer.h`, `Renderer.cpp` - Логика рендеринга в OpenGL.
185185
- `UIRenderer.h`, `UIRenderer.cpp` - Отрисовка и работа с GUI окна и меню.
186186
- `SelectionRenderer.h`, `SelectionRenderer.cpp` - Отрисовка линий выделения поля мышкой.
187-
- `CellInstance.h` - Структура для хранения инстанса дивых и мертвых клеток для оптимальной отрисовки в OpenGL.
187+
- `GridRenderer.h`, `GridRenderer.cpp` - Отрисовка навигационной координатной сетки.
188+
- `TextureFieldRenderer.h`, `TextureFieldRenderer.cpp` - Отрисовка игрового поля на дальних расстояниях от самого поля, улучшает производительность не влияя на визуальное отображение.
189+
- `CellsViewportRenderer.h`, `CellsViewportRenderer.cpp` - Отрисовка игрового поля на ближних расстояниях от игрового поля, улучшает визуальное отображение.
188190
- `IRendererProvider.h` - Проводник обеспечивающий обмен данными между разными классами. Это простой интерфейс, паттерн провайдер.
189191

190192
- **./mathematics**: Математические утилиты:

README_EN.md

+117-87
Large diffs are not rendered by default.

life.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
<ClCompile Include="rendering\Camera.cpp" />
168168
<ClCompile Include="rendering\CameraController.cpp" />
169169
<ClCompile Include="rendering\CellsRenderer.cpp" />
170-
<ClCompile Include="rendering\ChunkedCellsRenderer.cpp" />
170+
<ClCompile Include="rendering\CellsViewportRenderer.cpp" />
171171
<ClCompile Include="rendering\CubeRenderer.cpp" />
172172
<ClCompile Include="rendering\GridRenderer.cpp" />
173173
<ClCompile Include="rendering\Renderer.cpp" />
@@ -200,7 +200,7 @@
200200
<ClInclude Include="rendering\Camera.h" />
201201
<ClInclude Include="rendering\CameraController.h" />
202202
<ClInclude Include="rendering\CellsRenderer.h" />
203-
<ClInclude Include="rendering\ChunkedCellsRenderer.h" />
203+
<ClInclude Include="rendering\CellsViewportRenderer.h" />
204204
<ClInclude Include="rendering\CubeRenderer.h" />
205205
<ClInclude Include="rendering\GridRenderer.h" />
206206
<ClInclude Include="rendering\IRendererProvider.h" />

life.vcxproj.filters

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<ClCompile Include="rendering\CubeRenderer.cpp">
102102
<Filter>rendering</Filter>
103103
</ClCompile>
104-
<ClCompile Include="rendering\ChunkedCellsRenderer.cpp">
104+
<ClCompile Include="rendering\CellsViewportRenderer.cpp">
105105
<Filter>rendering</Filter>
106106
</ClCompile>
107107
</ItemGroup>
@@ -205,7 +205,7 @@
205205
<ClInclude Include="rendering\CubeRenderer.h">
206206
<Filter>rendering</Filter>
207207
</ClInclude>
208-
<ClInclude Include="rendering\ChunkedCellsRenderer.h">
208+
<ClInclude Include="rendering\CellsViewportRenderer.h">
209209
<Filter>rendering</Filter>
210210
</ClInclude>
211211
</ItemGroup>

rendering/BaseRenderer.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ class BaseRenderer {
1717
virtual ~BaseRenderer();
1818

1919
void SetGameController(GameController* gameController);
20-
virtual void Initialize() = 0; // ×èñòî âèðòóàëüíûé ìåòîä äëÿ èíèöèàëèçàöèè
21-
virtual void Draw() = 0; // ×èñòî âèðòóàëüíûé ìåòîä äëÿ îòðèñîâêè
20+
virtual void Initialize() = 0; // Чисто виртуальный метод для инициализации
21+
virtual void Draw() = 0; // Чисто виртуальный метод для отрисовки
2222

2323
protected:
2424
const Camera& camera;
2525
ShaderManager& shaderManager;
2626
GameController* pGameController;
2727

28-
// Ìåòîäû äëÿ ðàáîòû ñ VAO/VBO
28+
// Методы для работы с VAO/VBO
2929
void CreateBuffers(GLuint& vao, GLuint& vbo, const float* vertices, size_t size, const std::vector<std::pair<GLint, GLint>>& attribs);
3030
void DeleteBuffers(GLuint& vao, GLuint& vbo);
3131

32-
// Ìåòîäû äëÿ ðàáîòû ñ øåéäåðàìè
32+
// Методы для работы с шейдерами
3333
GLuint LoadShaderProgram(const std::string& programName, const std::string& vertexSource, const std::string& fragmentSource);
3434
GLint GetUniformLocation(GLuint program, const std::string& name);
35-
void SetCommonUniforms(GLuint program); // Óñòàíîâêà projection è view
35+
void SetCommonUniforms(GLuint program); // Установка projection и view
3636

3737
private:
38-
std::unordered_map<std::string, GLint> uniformCache; // Êýø óíèôîðìîâ äëÿ êàæäîãî øåéäåðà
38+
std::unordered_map<std::string, GLint> uniformCache; // Кэш униформов для каждого шейдера
3939
};
4040

4141
#endif

rendering/Camera.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "Camera.h"
22

33
Camera::Camera(float fov, float aspectRatio, float nearPlane, float farPlane)
4-
: fov(fov), fPlane(farPlane),
4+
: fov(fov), aspectRatio(aspectRatio), fPlane(farPlane),
55
position{0.0f, 0.0f, 0.0f},
66
direction{0.0f, 0.0f, -1.0f},
77
up{0.0f, 1.0f, 0.0f} {
8-
SetProjection(fov, aspectRatio, nearPlane, farPlane);
8+
UpdateProjectionMatrix();
99
UpdateViewMatrix();
1010
}
1111

@@ -125,9 +125,7 @@ void Camera::UpdateViewMatrix() {
125125
viewMatrix[15] = 1.0f;
126126
}
127127

128-
129-
void Camera::SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane) {
130-
fPlane = farPlane;
128+
void Camera::UpdateProjectionMatrix() {
131129
float f = 1.0f / std::tan(fov * 0.5f * PI / 180.0f);
132130

133131
projectionMatrix[0] = f / aspectRatio;
@@ -142,15 +140,22 @@ void Camera::SetProjection(float fov, float aspectRatio, float nearPlane, float
142140

143141
projectionMatrix[8] = 0.0f;
144142
projectionMatrix[9] = 0.0f;
145-
projectionMatrix[10] = (fPlane + nearPlane) / (nearPlane - fPlane);
143+
projectionMatrix[10] = (fPlane + 0.1f) / (0.1f - fPlane);
146144
projectionMatrix[11] = -1.0f;
147145

148146
projectionMatrix[12] = 0.0f;
149147
projectionMatrix[13] = 0.0f;
150-
projectionMatrix[14] = (2.0f * fPlane * nearPlane) / (nearPlane - fPlane);
148+
projectionMatrix[14] = (2.0f * fPlane * 0.1f) / (0.1f - fPlane);
151149
projectionMatrix[15] = 0.0f;
152150
}
153151

152+
void Camera::SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane) {
153+
this->fov = fov;
154+
this->aspectRatio = aspectRatio;
155+
this->fPlane = farPlane;
156+
UpdateProjectionMatrix();
157+
}
158+
154159
void Camera::LookAt(float targetX, float targetY, float targetZ, float upX, float upY, float upZ) {
155160
// Вектор направления (forward)
156161
std::array<float, 3> forward = {
@@ -215,4 +220,4 @@ void Camera::NormalizeVector(std::array<float, 3>& vector) {
215220

216221
float Camera::GetDistance() const {
217222
return std::abs(position[2]);
218-
}
223+
}

rendering/Camera.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Camera {
2121
void Move(float dx, float dy, float dz); // Перемещение камеры
2222
void Rotate(float yaw, float pitch); // Вращение камеры (рыскание и тангаж)
2323

24-
void UpdateViewMatrix(); // Обновляем матрицу вида
24+
//void UpdateViewMatrix(); // Обновляем матрицу вида
2525
void SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane); // Устанавливаем проекцию
2626

2727
void LookAt(float targetX, float targetY, float targetZ,
@@ -37,6 +37,14 @@ class Camera {
3737
static constexpr float PI = 3.14159265358979323846f;
3838
static constexpr float MAX_PITCH = 89.0f * PI / 180.0f;
3939

40+
// Добавляем новые методы
41+
void SetAspectRatio(float ratio) {
42+
aspectRatio = ratio;
43+
UpdateProjectionMatrix();
44+
}
45+
46+
float GetAspectRatio() const { return aspectRatio; }
47+
4048
private:
4149
std::array<float, 3> position;
4250
std::array<float, 3> direction;
@@ -45,7 +53,12 @@ class Camera {
4553
float fPlane;
4654
std::array<float, 16> viewMatrix;
4755
std::array<float, 16> projectionMatrix;
56+
float aspectRatio;
4857

4958
void NormalizeVector(std::array<float, 3>& vector); // Изменено с float* на std::array
59+
60+
// Разделяем обновление матриц
61+
void UpdateProjectionMatrix();
62+
void UpdateViewMatrix();
5063
};
5164
#endif // CAMERA_H_

rendering/CellsRenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
CellsRenderer::CellsRenderer(const Camera& camera, ShaderManager& shaderManager)
5-
: BaseRenderer(camera, shaderManager), // Ïåðåäàåì ïàðàìåòðû â áàçîâûé êëàññ
5+
: BaseRenderer(camera, shaderManager), // Передаем параметры в базовый класс
66
cellsVAO(0), cellsVBO(0), cellInstanceVBO(0), cellShaderProgram(0), computeCellShaderProgram(0) {
77
LoadCellShaders();
88
}

rendering/CellsRenderer.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
#include "BaseRenderer.h"
55

6-
struct CellInstance {
7-
float x, y;
8-
};
6+
97

108
class CellsRenderer : public BaseRenderer {
119
public:
@@ -16,6 +14,9 @@ class CellsRenderer : public BaseRenderer {
1614
void Draw();
1715

1816
private:
17+
struct CellInstance {
18+
float x, y;
19+
};
1920
GLuint cellsVAO, cellsVBO, cellInstanceVBO;
2021
GLuint cellShaderProgram, computeCellShaderProgram;
2122
std::vector<CellInstance> cellInstances;

0 commit comments

Comments
 (0)