|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Jaylib is a Java Native Interface (JNI) binding library for Raylib 5.5, providing Java developers with access to the popular C game development library. The project uses JavaCPP to automatically generate JNI bindings from the native Raylib headers. |
| 8 | + |
| 9 | +## Build System and Commands |
| 10 | + |
| 11 | +### Primary Build Commands |
| 12 | +- `./build-java.sh` - Main Java compilation and JAR creation (requires `RAYLIB_VERSION` environment variable) |
| 13 | +- `./build-linux.sh` - Linux platform-specific build |
| 14 | +- `./build-windows.sh` - Windows platform build (requires Visual Studio environment) |
| 15 | +- `./build-native.sh` - Native library compilation |
| 16 | + |
| 17 | +### Testing |
| 18 | +- `./run-test.sh` - Run the basic functionality test (requires `RAYLIB_PLATFORM` environment variable) |
| 19 | +- `./run-test-jar.sh` - Run tests using the compiled JAR |
| 20 | + |
| 21 | +### Documentation |
| 22 | +- `./build-docs.sh` - Generate Javadoc documentation |
| 23 | + |
| 24 | +### Environment Variables Required |
| 25 | +- `RAYLIB_VERSION` - Version string for builds (e.g., "5.5.0-0") |
| 26 | +- `RAYLIB_PLATFORM` - Platform identifier (e.g., "linux-x86_64", "windows-x86_64", "macosx-x86_64") |
| 27 | + |
| 28 | +## Architecture and Key Components |
| 29 | + |
| 30 | +### Core Structure |
| 31 | +- **JavaCPP Integration**: Uses `javacpp.jar` and JavaCPP annotations in `RaylibConfig.java` to automatically generate JNI bindings |
| 32 | +- **Multi-stage Build Process**: |
| 33 | + 1. Generate Java bindings from C headers using JavaCPP |
| 34 | + 2. Compile native code with platform-specific linkers |
| 35 | + 3. Package everything into distributable JARs |
| 36 | + |
| 37 | +### Key Source Files |
| 38 | +- `src/com/raylib/RaylibConfig.java` - JavaCPP configuration defining platform-specific linking and header includes |
| 39 | +- `src/com/raylib/Raylib.java` - Auto-generated main binding class (created during build) |
| 40 | +- `src/com/raylib/Colors.java` - Predefined color constants (RAYWHITE, BLACK, etc.) |
| 41 | +- `src/com/raylib/Helpers.java` - Alternative constructor methods for structs |
| 42 | +- `src/com/raylib/Test.java` - Basic functionality test and demo |
| 43 | + |
| 44 | +### Native Headers |
| 45 | +The project includes Raylib C header files: |
| 46 | +- `raylib.h` - Core Raylib API |
| 47 | +- `rlgl.h` - OpenGL abstraction layer |
| 48 | +- `raymath.h` - Math utility functions |
| 49 | +- `physac.h` - Physics simulation |
| 50 | +- `raygui.h` - Immediate mode GUI |
| 51 | + |
| 52 | +### Platform Support |
| 53 | +Configured for cross-platform builds supporting: |
| 54 | +- Windows x86_64 |
| 55 | +- macOS x86_64 and ARM64 |
| 56 | +- Linux x86_64 and ARM64 |
| 57 | + |
| 58 | +## JavaCPP Binding Specifics |
| 59 | + |
| 60 | +### Field Access Pattern |
| 61 | +- Getters: `vector.x()` returns the x field value |
| 62 | +- Setters: `vector.x(3)` sets the x field to 3 |
| 63 | +- Position field renamed to `_position` due to JavaCPP's internal position field |
| 64 | + |
| 65 | +### Struct Initialization |
| 66 | +JavaCPP uses fluent constructor syntax: |
| 67 | +```java |
| 68 | +var vec = new Vector3().x(1).y(2).z(3); |
| 69 | +``` |
| 70 | +Alternative constructors available in `Helpers.java`: |
| 71 | +```java |
| 72 | +var vec = Helpers.createVector3(1, 2, 3); |
| 73 | +``` |
| 74 | + |
| 75 | +### Array Access |
| 76 | +C arrays are not Java arrays - use position() method: |
| 77 | +```java |
| 78 | +model.materials().position(1).maps().position(2) // Second map of first material |
| 79 | +``` |
| 80 | + |
| 81 | +## Build Dependencies |
| 82 | +- Java 8+ (JDK required for compilation) |
| 83 | +- Platform-specific C++ compiler (GCC on Linux, Visual Studio on Windows, Xcode on macOS) |
| 84 | +- JavaCPP tool (included as `javacpp.jar`) |
| 85 | +- Raylib native library (included as git submodule) |
| 86 | + |
| 87 | +## macOS Specific Requirements |
| 88 | +When running Java applications on macOS, use the `-XstartOnFirstThread` JVM option: |
| 89 | +```bash |
| 90 | +java -XstartOnFirstThread -cp jaylib.jar:. MyGame |
| 91 | +``` |
0 commit comments