关键词:系统性、模块化、可扩展性
模块 | 技术库/接口 |
---|---|
窗口/输入 | SDL2、GLFW、WinAPI |
渲染引擎 | OpenGL、Vulkan、DirectX |
音频系统 | OpenAL、FMOD |
网络通信 | ENet、asio、RakNet |
脚本系统 | Lua、AngelScript、Python |
UI 系统 | Dear ImGui、自研 |
物理引擎 | Box2D(2D)、Bullet(3D) |
数学库 | glm、Eigen |
ECS 架构 | entt、flecs、自研 |
构建系统 | CMake |
可选用完整的商业引擎(Unity/UE)或者部分自研、半封装框架(类似 mini-engine)
mathematica复制编辑[ Game Engine ]
├── Application
├── Renderer
├── Input
├── Audio
├── Physics
├── Entity Component System (ECS)
├── ResourceManager
├── UI
└── Scripting (Lua)
cpp复制编辑while (gameRunning) {
processInput(); // 处理输入
update(deltaTime); // 更新游戏状态
render(); // 渲染场景
swapBuffers(); // 显示帧
}
isActionPressed("Jump")
→ 解耦输入设备bash复制编辑GameProject/
├── CMakeLists.txt
├── engine/
│ ├── core/ # 日志、事件、时钟
│ ├── render/ # 渲染模块
│ ├── physics/ # 物理模块
│ ├── ecs/ # ECS架构
│ ├── resource/ # 资源加载器
│ └── scripting/ # Lua 绑定
├── game/
│ ├── main.cpp
│ └── scenes/ # 各个关卡、游戏状态
├── assets/
│ ├── textures/
│ ├── shaders/
│ └── models/
└── thirdparty/ # SDL, GLAD, glm, Bullet 等
工具类别 | 推荐工具 |
---|---|
IDE | Visual Studio, CLion |
编译系统 | CMake, Ninja |
调试工具 | gdb, RenderDoc, valgrind |
热更新 | Lua, DLL热加载 |
性能分析 | Tracy, Perfetto, Intel VTune |
单元测试 | GoogleTest, Catch2 |
版本控制 | Git + GitHub/GitLab |
plaintext复制编辑[需求分析] → [技术选型] → [架构设计]
↓
[核心模块开发] → [主循环搭建]
↓
[系统整合] → [资源导入]
↓
[游戏逻辑开发] → [AI/关卡/交互]
↓
[测试 + 性能优化]
↓
[部署 + 发布]
main.cpp
)cpp复制编辑#include
#include
#include
#include
#include "Shader.h"
#include "Cube.h"
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("OpenGL Game Demo", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(window);
gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress);
glEnable(GL_DEPTH_TEST);
Shader shader("shaders/vertex.glsl", "shaders/fragment.glsl");
Cube cube;
bool running = true;
SDL_Event event;
float angle = 0.0f;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT ||
(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) {
running = false;
}
}
glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader.use();
glm::mat4 model = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.5f, 1.0f, 0.0f));
glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, -5));
glm::mat4 proj = glm::perspective(glm::radians(45.0f), 800.f/600.f, 0.1f, 100.f);
shader.setMat4("model", model);
shader.setMat4("view", view);
shader.setMat4("projection", proj);
cube.draw();
SDL_GL_SwapWindow(window);
angle += 0.01f;
}
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
glsl复制编辑#version 330 core
layout(location = 0) in vec3 aPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main() {
gl_Position = projection * view * model * vec4(aPos, 1.0);
}
cpp复制编辑class Cube {
private:
GLuint VAO, VBO;
public:
Cube();
void draw();
};