Skip to content

wuxianggujun/Tina

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Tina - 2D Sandbox Game Engine

English | ็ฎ€ไฝ“ไธญๆ–‡

Language Standard License

A 2D sandbox game engine developed with modern C++17, featuring bgfx rendering backend, terrain editing, fluid simulation, ECS architecture, and more.

Tina

๐ŸŽฎ Screenshots

Main Menu

Main Menu

World Selection

World Selection

Game Scene

Game Scene

โœจ Core Features

๐ŸŽจ Rendering System

  • Cross-platform rendering with bgfx - Supports DX11/OpenGL/Metal/Vulkan backends
  • Multi-view rendering architecture - Layered rendering (solid, alpha, UI layers)
  • 2D tile map rendering - Efficient batch rendering
  • Particle system - Supports explosions, debris, and other visual effects
  • Day-night cycle - Dynamic lighting and sky color changes

๐ŸŽฎ Gameplay

  • Terrain editing - Real-time digging, filling, and blasting
  • Fluid simulation - Advanced water flow simulation system (CA algorithm)
  • Physics system - AABB collision detection, gravity simulation
  • Character control - Platformer mechanics, multi-character switching
  • Procedural generation - Random terrain generation (Perlin noise)

๐Ÿ—๏ธ Engine Architecture

  • ECS architecture - Entity-Component-System based on EnTT
  • Scene management - Scene stack support (push/pop/replace)
  • Event system - Dual-layer event bus (OS layer + gameplay layer)
  • Resource management - Async resource loading, smart pointer management
  • UI system - Custom UI framework with layout, events, and animations

๐Ÿ–ผ๏ธ UI System Implementation

Implemented UI Components

  • UINode - Base UI node class (transform, hierarchy, visibility)
  • UIButton - Button component (hover, click, disabled states)
  • UIPanel - Panel container (background, border, rounded corners)
  • UIToolbar - Toolbar (multi-slot, icons, selection state)
  • UIDialog - Dialog system (centering, overlay)
  • UICharacterPanel - Character info panel (health bar, name, control button)
  • TextRenderer - Text renderer (TrueType fonts, alignment, colors)

UI Features

  • Auto layout management - Responsive window resizing
  • Event handling - Mouse hover, click, scroll wheel
  • RAII rendering scope - Automatic render state management
  • Color themes - Predefined color constants
  • DPI scaling - High-resolution display support

๐ŸŽฌ Scene System

Implemented Scenes

  1. MenuScene - Main menu scene

    • Start game, settings, exit buttons
    • Background rendering, title display
  2. WorldSelectScene - World selection scene

    • World list (3 preset worlds)
    • Create new world dialog
    • Seed input, world name editing
  3. GameScene - Main game scene

    • Terrain rendering (solid/water)
    • Character system (player + 3 NPCs)
    • Toolbar (8 tool slots)
    • Character info panel
    • Day-night cycle
  4. PauseScene - Pause menu

    • Continue, settings, return to main menu
    • Semi-transparent overlay
  5. SettingsScene - Settings scene

    • Sound/music volume adjustment
    • Fullscreen toggle
    • Day-night time adjustment

๐ŸŽต Audio System

  • SDL_mixer based - Supports MP3/WAV/OGG
  • Audio management - Fade in/out, volume control
  • Group management - Independent control for sound effects and music
  • Async loading - Lazy resource loading

๐ŸŽฏ Input System

  • InputSystem - Unified input management
  • Keyboard input - Keyboard state queries, key events
  • Mouse input - Coordinate conversion, button states, scroll wheel
  • Window events - Window resize, maximize, close

๐Ÿ“ฆ Project Structure

Tina/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/           # Core systems (logging, time, memory)
โ”‚   โ”œโ”€โ”€ engine/         # Engine core (application, scenes, events, input)
โ”‚   โ”œโ”€โ”€ renderer/       # Rendering system (shaders, textures, tile rendering)
โ”‚   โ”œโ”€โ”€ ui/             # UI system (components, renderers, layout)
โ”‚   โ”œโ”€โ”€ ecs/            # ECS system (components, systems)
โ”‚   โ””โ”€โ”€ game/           # Game logic (scenes, maps, characters)
โ”œโ”€โ”€ resources/          # Resource files (shaders, textures, audio, fonts)
โ”œโ”€โ”€ image/              # Game screenshots
โ””โ”€โ”€ docs/               # Documentation

๐ŸŽฎ Controls

Main Menu

  • Click "Start Game" to enter world selection
  • Click "Settings" to adjust volume and display options
  • Click "Exit" to close the game

Game Scene

  • A/D or โ†/โ†’ - Move character
  • W/Space - Jump
  • Left Click - Use current tool (dig/place/blast)
  • Right Click - View character info and switch control
  • Scroll Wheel/Number Keys - Switch tools
  • ESC - Pause menu

Tools

  • Tool 0 - Water placer (place water at click position)
  • Tool 1 - Excavator (circular area digging)
  • Tool 2 - Exploder (large area destruction + particle effects)

๐Ÿ“‹ Quick Start

Clone Repository

git clone https://github.com/wuxianggujun/Tina.git
cd Tina
git submodule update --init --recursive

Windows Build

Prerequisites:

  • CMake 3.20+
  • Visual Studio 2019/2022
  • Windows SDK

Build Steps:

mkdir build && cd build
cmake ..
cmake --build . --config Release

Ubuntu Build

Install Dependencies:

sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
sudo apt install ninja-build
sudo snap install cmake --classic
sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake
sudo ln -s /snap/cmake/current/bin/ccmake /usr/bin/ccmake
sudo ln -s /snap/cmake/current/bin/cpack /usr/bin/cpack
# Install graphics library dependencies
sudo apt install libgl1-mesa-dev libglfw3-dev
sudo apt install libwayland-dev libwayland-egl-backend-dev libxkbcommon-dev xorg-dev 
sudo apt install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
sudo apt install pkg-config

Build Steps:

mkdir build && cd build
cmake ..
make -j$(nproc)
./Tina

๐Ÿ”ง Tech Stack

Core Dependencies

Library Version Purpose
bgfx latest Cross-platform rendering (supports DX11/OpenGL/Vulkan)
SDL2 2.0+ Window management, input handling
SDL_mixer 2.0+ Audio playback (MP3/WAV/OGG)
EnTT 3.x Entity Component System (ECS)
spdlog 1.x High-performance logging library
stb latest Image loading, TrueType fonts
GLM 0.9.9+ Math library (vectors, matrices)

Development Tools

๐Ÿ“š Learning Resources

This project was developed with reference to the following excellent open source projects:

Game Engines

Sandbox/Platformer Games

Architecture Design

bgfx Related

  • efkbgfx - Effekseer particle system + bgfx
  • ant - Lua game engine (using bgfx)

Utility Libraries

๐ŸŽฏ Event System Details

The engine adopts a dual-layer event bus architecture, separating OS events and gameplay events:

Layer 1: OS Event Bus (OSEventBus)

Handles operating system level events:

  • Keyboard events - Key press/release
  • Mouse events - Movement, clicks, scroll wheel
  • Window events - Resize, maximize, close

Usage Example:

// Subscribe to keyboard press events
auto connection = app()->osEvents().onKeyPressed.connect(this, &MyScene::onKeyPressed);

void MyScene::onKeyPressed(const KeyEvent& e) {
    if (e.key == KeyCode::Escape) {
        // Open pause menu
    }
}

Layer 2: Typed Event Bus (TypedEventBus)

Based on entt::dispatcher, for gameplay events:

  • Type safe - Compile-time checking
  • No engine modification needed - Highly extensible
  • RAII auto-management - Automatic unsubscribe

Usage Example:

// 1. Define event types
namespace Events {
    struct PlayerJumped { float height; };
    struct SetDayNight { float normalized; };
}

// 2. Subscribe to events (using SubscriptionManager for automatic lifecycle management)
TINA_SUBSCRIBE_EVENT(m_subscriptions, Events::PlayerJumped, MyScene::onPlayerJumped);

// 3. Trigger events
Events::PlayerJumped event{2.5f};
app()->events().trigger(event);

// 4. Handle events
void MyScene::onPlayerJumped(const Events::PlayerJumped& e) {
    TINA_INFO("Player jumped height: {}", e.height);
}

Advantages:

  • โœ… Decouples module communication
  • โœ… Supports async event handling
  • โœ… Automatic subscription lifecycle management
  • โœ… Type safe, compile-time checking

See docs/event_system.md for details

๐Ÿ“ Project Status

Current Version: 1.0.0
Development Status: ๐Ÿ”’ Archived (No longer maintained)

This project has achieved its intended goals as a learning project, implementing:

  • โœ… Complete 2D sandbox game framework
  • โœ… Modern C++17 architecture practices
  • โœ… Cross-platform rendering system
  • โœ… ECS architecture implementation
  • โœ… Fluid simulation algorithms
  • โœ… Complete UI system

The project code is available for learning and reference. If you want to continue developing based on this project, feel free to Fork it!

๐Ÿ› Known Issues

  • Performance optimization - Frame rate may drop on large maps
  • Fluid simulation - May become unstable in extreme cases
  • UI scaling - Some UI elements may display incorrectly on high-DPI displays
  • Audio - Occasional audio stuttering

๐ŸŽ“ Key Learning Points

If you want to learn from this project, it is recommended to focus on the following modules:

  1. Scene Management System (src/engine/SceneManager.cpp)

    • Scene stack implementation
    • Lifecycle management
    • View configuration
  2. ECS Architecture (src/ecs/)

    • Component definitions
    • System implementation
    • Entity management
  3. Event System (src/engine/EventSystem.cpp)

    • Dual-layer event bus
    • RAII subscription management
    • Strongly-typed events
  4. UI Framework (src/ui/)

    • Custom UI components
    • Layout system
    • Event handling
  5. Fluid Simulation (src/game/TileMap.cpp)

    • Cellular automata algorithm
    • Water pressure calculation
    • Optimization techniques

๐Ÿค Acknowledgments

Thanks to the following organizations and projects:

  • JetBrains - For providing free licenses for open source projects

  • All Contributors - Thanks to all developers who provided feedback and suggestions

  • Open Source Community - Thanks to all the excellent open source projects referenced

๐Ÿ“„ License

This project is licensed under the MIT License.

MIT License

Copyright (c) 2024 wuxianggujun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

โญ If this project helps you, welcome to give it a Star!

๐Ÿ“ง Contact: GitHub Issues

About

This is a simple game engine that creates a window using GLFW and renders with bgfx.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages