BareEngine: Writing a Game Engine from Scratch in C++

6 min read cpp game-engine mmorpg metin2 bareengine editor gamedev

It all started 10 years ago. Metin2 private servers, Knight Online emulators, game server communities... An 11-year-old kid was trying to figure out how a game works. He was sniffing packets, writing server emulators, learning C++.

That kid was me.

And now, at 21, I'm making that kid's dream real: BareEngine, my own game engine.

Why your own game engine?

There are ready-made engines: Unity, Unreal, Godot. Why write yet another one from scratch?

Because they don't do what I want.

Here's what I want: open an editor, drop in a few models, write a few scripts, and have the game server get generated automatically too. The editor and the server should be parts of the same toolchain. To do that in Unity you need third-party libraries like Mirror, FishNet or Netcode for GameObjects. I want it native.

Also, games like Metin2 and Knight Online have a "feel" of their own. Camera angle, character control, combat system, UI: all of it has a specific style. That style is hard to capture in modern engines, because they're optimized for FPS games or open-world RPGs.

I want an engine optimized for Metin2-style MMORPGs. So I'm writing it myself.

Architecture

BareEngine is made of three main components:

┌──────────────────────────────────────────┐
│              BareEditor (GUI)             │
│  ┌─────────┐ ┌──────────┐ ┌──────────┐   │
│  │ World   │ │ Asset    │ │ Script   │   │
│  │ Editor  │ │ Browser  │ │ Editor   │   │
│  └─────────┘ └──────────┘ └──────────┘   │
├──────────────────────────────────────────┤
│             BareEngine (Core)            │
│  ┌─────────┐ ┌──────────┐ ┌──────────┐   │
│  │Renderer │ │ Physics  │ │ Audio    │   │
│  │(OpenGL) │ │(Bullet)  │ │(OpenAL)  │   │
│  └─────────┘ └──────────┘ └──────────┘   │
├──────────────────────────────────────────┤
│            BareServer (Server)            │
│  ┌─────────┐ ┌──────────┐ ┌──────────┐   │
│  │Network  │ │ Game     │ │ DB       │   │
│  │(ENet)   │ │ Logic    │ │(SQLite)  │   │
│  └─────────┘ └──────────┘ └──────────┘   │
└──────────────────────────────────────────┘

BareEditor: An ImGui-based desktop editor. World editor (terrain, object placement), asset browser (models, textures, sounds), script editor (Lua integration). The editor itself is editor-first, meaning the editor is the product and the game output is a by-product.

BareEngine (Core): Renderer (OpenGL), physics engine (Bullet Physics), audio (OpenAL). All in C++, all native.

BareServer: The server players connect to. ENet (reliable UDP), game logic (C++), database (SQLite). The server reads the world file exported from the editor.

The editor-first philosophy

Most game engines are "engine-first." You write the engine first, then bolt on the editor. I'm doing the opposite.

In BareEngine the editor isn't an interface to the engine, the editor is the product itself. A game maker opens the editor, builds their world, hits "Build," and out comes a game. Just like RPG Maker. But unlike RPG Maker:

  • Multiplayer is native (for MMORPGs)
  • Performance-focused (C++, OpenGL)
  • Scriptable (Lua)
  • Open source

Target audience: the private server communities of games like Metin2, Knight Online and Silkroad. For years these communities have been wrestling with emulators and reverse-engineered server files. I want to give them a tool that says "make your own game."

Technical decisions

Why ImGui?

For the editor I'm using ImGui (Dear ImGui). Not Qt, not wxWidgets, ImGui.

The reason: ImGui is immediate mode. You redraw the GUI from scratch every frame. That's great for game engine editors because:

  • Render state and GUI state live in the same place
  • Debugging is easy (everything is computed right then)
  • It's fast (no unnecessary state)
  • It's portable (runs on OpenGL, Vulkan and DirectX)

The downside: it doesn't look "pretty." The default ImGui theme is... let's call it functional. But I don't care. An editor doesn't have to look pretty, it has to work.

Why Bullet Physics?

Not PhysX, not Havok, Bullet. The reason: it's open source and it's enough for MMORPGs. MMORPG physics isn't FPS physics. No ragdolls, no destructible environments. Just collision detection, simple rigid bodies, character control. Bullet does all of that and then some.

Why ENet?

MMORPG servers need a UDP-based protocol, not TCP. Movement input, combat events: all of it needs low latency. TCP's head-of-line blocking is deadly here.

ENet is a lightweight library built on reliable UDP. Ordered packet delivery, fragmentation, throttling: it's all there. And most importantly: it's simple. Just one .c file. No dependencies.

Why Lua?

Writing game logic in C++... possible, but not practical. Recompile on every change. Write it in Lua and you get:

  • Hot-reload (update scripts without shutting down the server)
  • Accessible to modders
  • Safer than C++ (even if a script crashes, the server doesn't go down)

For Lua bindings I'm using Sol3. It builds the bridge between C++ and Lua in a few lines.

Challenges

1. Editor-state synchronization. When you drag an object in the editor, that change has to reach the renderer, the physics engine and the network layer. When you undo/redo, all of it has to roll back. The command pattern solves this, but the implementation gets detailed.

2. Multiplayer synchronization. When a player moves, that movement has to reach the other players. But if you send every movement, your bandwidth explodes. You need client-side prediction + server reconciliation. That's a solved problem for FPS games, but the scale is different in MMORPGs: hundreds of players, thousands of entities.

3. Metin2 format compatibility. Metin2's file formats (.gr2 models, .dds textures, .msm animations) aren't documented. They need reverse-engineering. This is the part that eats most of my time.

4. Cross-platform. I develop on Windows but it'll run on Linux servers. OpenGL, ENet, Bullet: all cross-platform. But the build system (CMake), dependency management (vcpkg) and CI/CD all need platform-specific configuration.

Where it stands now

The project is at a very early stage. What works right now:

  • OpenGL renderer (basic meshes, textures)
  • ImGui editor UI (world outliner, property editor)
  • ENet networking (connections, messaging)
  • Basic Lua scripting (onPlayerJoin, onChatMessage)

What doesn't work yet (next milestone):

  • Asset import pipeline (.fbx, .gltf)
  • Physics (collision detection)
  • Animation system
  • Database persistence (saving characters)
  • Metin2 format parsers

Why does this project matter?

BareEngine isn't a commercial product. It's a passion project. Like a letter to my 11-year-old self.

That kid was sniffing packets to understand how games work. Now I'm building something that can tell him "here's how it works." Open source. So everyone can see it and learn from it.

Also, game development is growing in Turkey. But most studios use Unity/Unreal. Few people understand "how an engine works" at a low level. BareEngine is one way to spread that knowledge through open source.

Try it

git clone https://github.com/Tuntii/BareEngine
cd BareEngine
# Build (CMake + vcpkg):
cmake -B build -S . --toolchain ...
cmake --build build --config Release
# Run editor:
./build/Release/BareEditor.exe

It's not at the "you can make a game with it" stage yet. But it's on the way. Every commit brings me one step closer to my 11-year-old self.


This isn't the last post in the series. Next up: alexander-storage (self-hosted S3), IntentScript (LLM task runner) and more. Stay tuned.

← Blog