Blocks

repository·main·Indexed 43 days ago

https://github.com/jsoulier/blocks

A tiny Minecraft clone written in C and HLSL using the SDL3 GPU API. It features procedural world generation, asynchronous chunk loading, and cross-platform support for Desktop and Android.

Tokens
934
Snippets
3
Records
8
Agent score
5%

What's inside Blocks

  1. Build Blocks on Windows

    main

    To build Blocks on Windows, use CMake to generate build files and then compile using the Release configuration. Ensure you have Git, CMake, and a compatible C++ compiler installed.

    git clone https://github.com/jsoulier/blocks --recurse-submodules
    cd blocks
    mkdir build
    cd build
    cmake ..
    cmake --build . --parallel 8 --config Release
    cd bin
    ./blocks.exe
  2. Build Blocks on Linux

    main

    To build Blocks on Linux, use CMake with the CMAKE_BUILD_TYPE set to Release. Ensure you have Git, CMake, and necessary build tools installed.

    git clone https://github.com/jsoulier/blocks --recurse-submodules
    cd blocks
    mkdir build
    cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    cmake --build . --parallel 8
    cd bin
    ./blocks
  3. SDL3 Callback Lifecycle for Blocks

    main

    The Blocks application uses the SDL3 callback-based entry point pattern. Instead of a traditional main function, you implement specific lifecycle callbacks that the SDL runtime invokes.

    Key callbacks include:

    • SDL_AppInit: Initializes the SDL subsystem, creates the window and GPU device, loads textures/atlases, and initializes game modules (World, Player, Sky, etc.).
    • SDL_AppIterate: The main loop. Handles delta time calculation, updates game logic (World, Player, Sky, Input), triggers periodic saves, and executes the rendering pipeline.
    • SDL_AppEvent: Processes incoming SDL events, delegating them to the Input module.
    • SDL_AppQuit: Handles cleanup of all allocated resources, including GPU textures, pipelines, buffers, and game state saves.
    // The application relies on these SDL3 callbacks being implemented:
    SDL_AppResult SDLCALL SDL_AppInit(void** appstate, int argc, char** argv);
    SDL_AppResult SDLCALL SDL_AppIterate(void* appstate);
    SDL_AppResult SDLCALL SDL_AppEvent(void* appstate, SDL_Event* event);
    void SDLCALL SDL_AppQuit(void* appstate, SDL_AppResult result);
  4. Keyboard and Mouse Controls

    main

    Use the following controls for keyboard and mouse input:

    • Movement: WASDEQ to move, Space to jump, LControl to sprint
    • Camera/View: F5 to toggle fly, F11 to toggle fullscreen, Escape to unfocus
    • Interaction:
      • Left Click: Break a block
      • Middle Click: Select a block
      • Right Click: Place a block
      • Scroll: Change blocks
    • World: T to reset the time of day
  5. Gamepad Controls

    main

    Use the following controls for gamepad input:

    • Movement: Left Stick to move, L3 to sprint
    • Camera/View: Right Stick to look, Triangle to toggle fly
    • Interaction:
      • R2: Break a block
      • R3: Select a block
      • L2: Place a block
      • L1/R1: Change blocks
    • Action:
      • X: Jump or fly up
      • Circle: Fly down
      • Square: Reset the time of day