Hedra 是我在高中时从零开始编写的一款 3D 开放世界游戏。
Hedra is a 3D open world game I wrote from scratch while in highschool

原始链接: https://github.com/maxilevi/project-hedra/tree/pre-ai

Project Hedra 是一个开放世界、低多边形 RPG 和自定义游戏引擎,最初是高中 OpenGL 学习项目。它发展成一个跨平台(Linux/Windows)的 C# 引擎,约 10 万行代码,具有用 Marching Cubes 提取的程序生成体素世界、任务、Boss、物品、技能、职业、制作、钓鱼、交易、NPC、同伴、地图和多个维度。其渲染器使用现代 OpenGL 处理蒙皮/静态网格、动画、SSR、SSAO、泛光、FXAA/MSAA、阴影、LOD、粒子和天空盒,并提供 OpenAL 音频、Python Mod、本地化、UI、Steam、ECS、物理和资源压缩等系统。它强调 GC 友好的自定义分配器/数组,并包含大量测试。游戏本身是引擎上的 Mod,使用世界种子而非世界存档,且仅支持纯文本 .PLY/.DAE 模型。构建需要子模块、依赖脚本和编译 C# 解决方案。

Hacker News 用户讨论了 Hedra,一款 3D 开放世界游戏及引擎,其作者在高中时期为学习 OpenGL 而开始制作,并手工编写成约 10 万行代码,支持 Linux 和 Windows。评论者称赞其原创性、工艺、流畅性能、模组 API 和低多边形美学,同时就 AI 辅助编码与手动学习展开了辩论。一些人认为手动构建能培养宝贵的领域专业知识;其他人则质疑 LLM 能否有效重用先前的公开代码。少数人还将其与 Cube World 进行了比较。
相关文章

原文

Project Hedra is an ambitious open-world, low-poly RPG. Choose your class, explore endless procedurally generated worlds, unlock different skills and complete procedurally generated quests.

More screenshots at (Screenshots)

I started this project when I was in highschool (around 15 yo) in order to learn how OpenGL worked.

The scope creep quickly arrived and after a few years it turned into a fullfledged 3D game and game engine. The codebase has around 100k LOC and the game has first class support for Linux and Windows.

The million lines of code are not in vain. The game and engine are both full of features :)

  • Beatiful procedurally generated worlds
  • Quests and bosses
  • 100+ items with rarities system
  • Skills and skill tree system with N+ skills
  • 4 different classes with 2 specializations each ()
  • Procedurally placed structures generated dynamically
  • Fishing, crafting, etc
  • Trading and NPCs
  • Companions and pets
  • Beatiful soundtrack
  • Navigation, maps
  • Different dimensions
  • More stuff I don't recall :)
  • Fully fledged renderer using modern OpenGL
  • Skinned mesh rendering
  • Support for loading and playing generic animations
  • Collada (.dae) parser
  • Static mesh rendering
  • Screen space reflections
  • Screen space ambient occlusion
  • Bloom, FXAA & MSAA
  • Modding support
  • CI for automatically deploying to a Steam beta branch
  • Localization support
  • Sound support using OpenAL
  • Python scripting support
  • Module system for loading data oriented objects
  • Steam integration
  • Fully fledged UI & controls system (dropdowns, buttons, etc.) written from raw OpenGL
  • Dynamic shader system for reloading during runtime
  • Frustum culling, occlusion culling,
  • Mesh simplification for runtime level of detail (LOD)
  • Skybox support
  • Shadows
  • 3D trails renderering support
  • Particle system using object instancing in opengl
  • bulletphysics integration
  • Chunk system for infinite worlds support
  • .ply parsing support
  • Dynamic meshing support using MarchingCubes
  • Custom implementation of basic C# primitives and allocators (like Lists) for supporting stack allocated lists and minimizing the automatic runtime allocations (and thus the GC).
  • 1000+ plus test cases
  • Framework for mocking game components and doing integration testing on games
  • Image and asset compression for faster loading and smaller size
  • Entity component system
  • More stuff I don't recall :)
  • WorldRenderer.cs. Renders the entire world in just 3 (actually it depends on how partitioned is the data buffer, but it was designed to be in 3) draw calls (water, terrain, instanced) using glMultiDrawElements.

  • Block.cs. Core component of the world. Read more at https://maxilevi.com/blog/procedural-meshing-hedra

  • Fishing.py. Written in Python as a mod script using IronPython, directly interacts with the C# API.

  • NativeArray.cs Implementation of an array primitive using a custom allocator. The same project provides heap based allocators as well as stac based ones using stackalloc. The idea was to minimize the automatic heap allocations (and thus avoiding the GC) during the game frames.

  • The world is fully procedurally generated, there is no world save file. Only the player contents are saved and the world seed. The rest is created at runtime.
  • The world is voxel based but an isosurface extraction algorithm called Marching Cubes is applied to extract an implicit continous surface from the discrete voxels.
  • The name "Hedra" comes from tetrahedra which is the shape used in the original iso surface extraction algorithm I implemented Marching Tetrahedra
  • The game only supports loading .PLY and .DAE models, both which are in plaintext and the models have no textures. Therefore if you put this into perspective, this means I wrote a bunch of text that reads text and creates interactive images from this. I think this is pretty cool.

image image image image

TODO add more

The game is a mod to a base engine. The idea of architecturing this way was to force myself to maintain the mod API up to date, therefore encouraging access to make mods.

Basically the entire game. This includes AI logic, components, world generation, module systems, object placement and lots of other stuff.

The core parts of the engine, this defines all the abstractions to the world. It handles rendering, sound, different base systems as well as the general windowing, game loop and platform features. The split was not done at the start so some stuff might still be outside.

Core primitives used in the engine. This includes heap and stack allocators, custom implementations of lists and arrays as well as wrappers to pointers to native and some other useful primitives

Test suite that

Command line tool to compress the game assets into convenient binary files. Combines images, models, sound files, shaders into a single binary file with a structure designed for fast data retrieval.

Once upong a time Hedra used to support multiplayer. It worked by doing UDP Hole Punching and having clients communicate P2P, this server was in charge of that. You might also see some networking remnants in the Engine code.

The build process is pretty straightforward.

  1. Checkout all the submodules
  2. Run the build depedencies scripts
  3. Compile the C# solution

You can check the GitHub actions workflows for some examples on Linux and Windows.

联系我们 contact @ memedata.com