Skip to content

Commit d7b32dc

Browse files
feat: encapsulate viewer application logic into ViewerApp and ViewerGraphics classes
1 parent 0fc1493 commit d7b32dc

9 files changed

Lines changed: 2507 additions & 2293 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ endif()
195195

196196
add_executable(ClimaxGameEngineToolkit MACOSX_BUNDLE
197197
src/main.cpp
198+
src/Viewer/ViewerApp.cpp
199+
src/Viewer/ViewerGraphics.cpp
198200
src/Viewer/ViewerDraw.cpp
199201
src/Viewer/ViewerAudio.cpp
200202
src/UI/UI.cpp

‎include/ClimaxEngine/Core/Types.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ struct GameObject {
252252
float lightAngle = 45.0f; // >180 means omnidirectional
253253
int lightType = 0;
254254

255+
// CFogConfig payload
256+
bool isFogConfig = false;
257+
float fogStart = 13.0f;
258+
float fogEnd = 25.0f;
259+
float fogDensity = 0.3f;
260+
glm::vec3 fogColor = glm::vec3(0.65f, 1.0f, 0.7f);
261+
255262
// Field of view in degrees, from CBaseCamera property 2 -- the property the
256263
// engine feeds to Camera::CBaseCamera::SetFOV. Shared by every camera class,
257264
// so constraint and cutscene cameras carry it too. -1 means not present.

‎include/ClimaxEngine/Render/ViewerState.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ struct ViewerState {
147147
// ice surfaces. Off by default -- both are approximations of engine state.
148148
bool frozenVariant = false;
149149
bool iceShading = true;
150+
151+
// Fog settings
152+
bool enableFog = false;
153+
bool useNativeFog = true;
154+
float fogColor[3] = {0.5f, 0.5f, 0.5f};
155+
float fogStart = 10.0f;
156+
float fogEnd = 50.0f;
157+
float fogDensity = 0.05f;
158+
int fogMode = 0; // 0=Linear, 1=Exp, 2=Exp2
150159
};
151160

152161
// ─────────────────────────────────────────────────────────────────────────────
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "ClimaxEngine/Viewer/ViewerGraphics.h"
2+
#pragma once
3+
4+
#include <string>
5+
6+
7+
#include <GL/glew.h>
8+
9+
namespace ClimaxEngine {
10+
namespace Viewer {
11+
12+
class ViewerApp {
13+
public:
14+
ViewerApp() = default;
15+
~ViewerApp() = default;
16+
17+
int Run(int argc, char* argv[]);
18+
19+
private:
20+
ViewerGraphics m_Graphics;
21+
};
22+
23+
24+
} // namespace Viewer
25+
} // namespace ClimaxEngine
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include "ClimaxEngine/Core/Types.h"
4+
#include <GL/glew.h>
5+
#include <glm/glm.hpp>
6+
#include <vector>
7+
8+
namespace ClimaxEngine {
9+
namespace Viewer {
10+
11+
class ViewerGraphics {
12+
public:
13+
ViewerGraphics() = default;
14+
~ViewerGraphics() = default;
15+
16+
bool Init();
17+
void RenderFrame(int fbW, int fbH, int winW, int winH, const glm::mat4& mvp, const glm::vec3& eye, const glm::vec3& viewDir, size_t totalMeshes);
18+
void Shutdown();
19+
20+
public:
21+
GLuint p = 0;
22+
GLuint uiP = 0;
23+
GLuint solidP = 0;
24+
GLuint skyProg = 0;
25+
GLuint collProg = 0;
26+
GLuint lineVao = 0, lineVbo = 0;
27+
GLuint markerVao = 0, markerVbo = 0;
28+
GLuint skyVao = 0;
29+
};
30+
31+
} // namespace Viewer
32+
} // namespace ClimaxEngine

‎src/Loader/Loader.cpp‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,45 @@ static void ParseGameObject(const std::vector<uint8_t> &data, size_t off,
730730
go.atOrigin = (glm::length(go.position) < 1e-4f);
731731
}
732732

733+
733734
// Second pass for CColorLight: the payload is spread over two components.
735+
if (go.className == "CFogConfig") {
736+
go.isFogConfig = true;
737+
int group = 0;
738+
long lastIdx = -1;
739+
size_t q = body + 4;
740+
while (q + 8 <= bodyEnd) {
741+
const uint32_t rs = ru32l(q);
742+
const uint32_t rid = ru32l(q + 4);
743+
if (rid == 0x0711) {
744+
size_t rq = q + 8;
745+
const size_t rqEnd = rq + rs;
746+
while (rq + 12 <= rqEnd) {
747+
const uint32_t propType = ru32l(rq);
748+
const uint32_t propSize = ru32l(rq + 4);
749+
const uint32_t propId = ru32l(rq + 8);
750+
if (propId <= lastIdx) group++;
751+
lastIdx = propId;
752+
const size_t payload = rq + 12;
753+
754+
if (propType == 2 && propSize == 4) { // Float
755+
uint32_t bits = ru32l(payload);
756+
float val;
757+
std::memcpy(&val, &bits, 4);
758+
if (propId == 2) go.fogStart = val;
759+
if (propId == 3) go.fogEnd = val;
760+
if (propId == 5) go.fogDensity = val;
761+
if (propId == 10) go.fogColor.r = val;
762+
if (propId == 11) go.fogColor.g = val;
763+
if (propId == 8) go.fogColor.b = val;
764+
}
765+
rq += 12 + propSize;
766+
}
767+
}
768+
q += 8 + rs;
769+
}
770+
}
771+
734772
if (go.className == "CColorLight") {
735773
go.isLight = true;
736774
// Property indices restart at 0 for each component of the object, so a

0 commit comments

Comments
 (0)