This document provides essential context for AI models interacting with this project. Adhering to these guidelines will ensure consistency and maintain code quality.
- Primary Goal: This repository contains raylib examples ported to the Nim programming language, using the naylib wrapper. It serves as both a collection of educational examples and a showcase of naylib's capabilities for 2D/3D game and multimedia application development.
- Business Domain: Game development, multimedia applications, educational tools for programming graphics.
- Languages: Nim (version 2.0.0 or higher), C (via naylib/raylib)
- Frameworks & Runtimes: Raylib (C library for game development via naylib), GLFW (for window management), OpenGL (for graphics rendering)
- Key Libraries/Dependencies: naylib (Nim wrapper for raylib)
- Platforms: Windows, Linux, macOS, WebAssembly (via Emscripten) - inherited from naylib
- Package Manager: Nimble
- Overall Architecture: Example repository demonstrating various raylib features through Nim implementations. Uses naylib as the core binding layer to access raylib functionality with Nim idioms.
- Directory Structure Philosophy:
/core: Basic window and system examples/audio: Audio-related examples/shapes: 2D shape rendering examples/textures: Texture manipulation and rendering examples/text: Text rendering and font examples/models: 3D model rendering examples/shaders: Shader programming examples/games: Complete game implementations/others: Miscellaneous examples/personal: Unique examples created specifically for this repository/deps: External dependencies managed by Atlas/media: Media assets and screenshots
- Module Organization: Each example is a self-contained Nim file that imports raylib and any required standard library modules. Examples follow a consistent structure with initialization, main game loop, and de-initialization sections.
- Formatting: Follows Nim's standard style conventions with 2-space indentation.
- Naming Conventions:
- Variables, procedures: camelCase (
screenWidth,initWindow,drawRectangle) - Types: PascalCase (
Rectangle,Vector2) - Constants: PascalCase (
MaxFrameSpeed,MinFrameSpeed) - Files: snake_case for Nim files (
basic_window.nim,sprite_button.nim)
- Variables, procedures: camelCase (
- API Design:
- Uses naylib's Nim-idiomatic wrappers around raylib C functions
- Employs proc overloading instead of C-style suffixed function names
- Uses destructors for automatic resource management where applicable
- Maps C enums to Nim enums with shortened names
- Abstracts raw pointers with
openArray[T]andcstringwithstring - Provides syntactic sugar for begin-end pairs (templates like
drawing,mode3D)
- Common Patterns & Idioms:
- Metaprogramming: Uses templates like
drawing()andmode3D()for scoped operations - Memory Management: Relies on Nim's destructors
- Type Safety: Uses distinct types where appropriate (e.g.,
SpotIdx) - Concurrency: Limited use, primarily single-threaded game loops
- Metaprogramming: Uses templates like
- Error Handling:
- Uses Nim's exception system
- Uses
assertfor precondition checking
- Main Entrypoint: Each example file is a standalone entrypoint (e.g.,
core/basic_window.nim) - Configuration:
nim.cfg- Compiler configuration with dependency pathsconfig.nims- Build configuration with definesraylib_examples.nimble- Package definition and tasks
- CI/CD Pipeline:
.github/workflows/ci.ymlfor continuous integration
- Local Development Environment:
To set up the project locally, you need Nim installed.
- Install Nim
wget https://codeberg.org/janAkali/grabnim/raw/branch/master/misc/install.sh sh install.sh grabnim
- Setting up the project
- Clone the repository
- Run
nimble testto verify setup
- Install Nim
- Task Configuration:
- Nimble Tasks: Run
nimble tasksto list all available tasks in the .nimble file - Custom .nims Tasks: Build configuration in
config.nims
- Nimble Tasks: Run
- Testing: Run tests via
nimble test. The test task compiles all examples to verify they build correctly. - CI/CD Process: GitHub Actions workflow that tests on Ubuntu for native builds. Also includes Dependabot for GitHub Actions updates.
- Contribution Guidelines:
- Follow the existing code style and naming conventions
- Ensure examples are self-contained and well-commented
- Submit pull requests against the
mainbranch
- Security:
- Be mindful of security when handling file I/O and external resources
- Do not hardcode secrets or keys
- Dependencies:
- When adding new dependencies, use Nimble for management
- Core raylib functionality should go through naylib
- Commit Messages: Follow conventional commit messages with clear, descriptive summaries of changes