### Manage Draw Layers in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Provides examples of controlling the rendering order and states using different draw layers, including 2D UI, default 3D, and particle layers. It utilizes functions from 'renderer/drawLayer.h' and demonstrates layer configuration options. ```cpp #include "renderer/drawLayer.h" // Switch to 2D rendering mode for UI P64::DrawLayer::use2D(); // Draw UI elements here... rdpq_text_printf(nullptr, fontId, 10, 10, "Score: %d", score); // Return to default 3D rendering P64::DrawLayer::useDefault(); // Use specific 3D layer (for transparency sorting, etc.) P64::DrawLayer::use3D(1); // Use particle layer P64::DrawLayer::usePtx(0); // Layer configuration (typically done in editor) P64::DrawLayer::Conf layerConf; layerConf.flags = P64::DrawLayer::Conf::FLAG_Z_WRITE | P64::DrawLayer::Conf::FLAG_Z_COMPARE; layerConf.fogMode = P64::DrawLayer::Conf::FogMode::CLEAR_COLOR; layerConf.fogMin = 100.0f; layerConf.fogMax = 1000.0f; ``` -------------------------------- ### Object and Component System in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Interact with the object and component system in Pyrite64. This C++ code demonstrates how to get components, access object transforms, enable/disable objects, remove objects, iterate through children, get the parent object, and perform coordinate space conversions. ```cpp #include "scene/object.h" #include "scene/components/collBody.h" #include "scene/components/animModel.h" void update(P64::Object& obj, Data* data, float deltaTime) { // Get components attached to object auto* coll = obj.getComponent(); auto* anim = obj.getComponent(); // Access object transform fm_vec3_t position = obj.pos; fm_quat_t rotation = obj.rot; fm_vec3_t scale = obj.scale; // Enable/disable object obj.setEnabled(true); bool isEnabled = obj.isEnabled(); // Remove object from scene (deferred to end of frame) obj.remove(); // Iterate over child objects obj.iterChildren([](P64::Object* child) { child->setEnabled(false); }); // Get parent object P64::Object* parent = obj.getParent(); // Coordinate space conversions fm_vec3_t worldPos = {100.0f, 0.0f, 50.0f}; fm_vec3_t localPos = obj.intoLocalSpace(worldPos); fm_vec3_t backToWorld = obj.outOfLocalSpace(localPos); } ``` -------------------------------- ### Scene Manager API in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Manage game scenes using the Scene Manager API. Scenes are loaded at the end of the current frame to ensure smooth transitions. Provides functions to load scenes, get the current scene, and retrieve scene information. ```cpp #include "scene/sceneManager.h" // Load a new scene by ID (happens at end of frame) P64::SceneManager::load(2); // Get reference to current scene P64::Scene &scene = P64::SceneManager::getCurrent(); // Get scene ID and object count uint16_t sceneId = scene.getId(); uint32_t objectCount = scene.getObjectCount(); ``` -------------------------------- ### CMake Project Setup and C++ Standard Configuration Source: https://github.com/hailtododongo/pyrite64/blob/main/CMakeLists.txt Configures the CMake build system for the pyrite64 project. It sets the minimum required CMake version to 3.28, defines the project name as 'pyrite64' with version 0.2.0, and enforces the C++23 standard. It also enables the export of compile commands for better IDE integration and prevents in-source builds. ```cmake cmake_minimum_required(VERSION 3.28) project(pyrite64 VERSION 0.2.0) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "In-source builds are disabled.\n" "Run: cmake --preset ") endif() ``` -------------------------------- ### Configure Scene Lighting in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Illustrates how to configure scene lighting, including resetting lights, adding ambient, directional, and point lights, and applying temporary overrides. This functionality requires the 'scene/lighting.h' header and interacts with the P64::SceneManager. ```cpp #include "scene/lighting.h" P64::Scene& scene = P64::SceneManager::getCurrent(); P64::Lighting& lighting = scene.getLighting(); // Reset all lights lighting.reset(); // Add ambient light lighting.addAmbientLight({0x40, 0x40, 0x50, 0xFF}); // Add directional light (color, direction) fm_vec3_t sunDir = {0.5f, -1.0f, 0.3f}; fm_vec3_norm(&sunDir, &sunDir); lighting.addDirLight({0xFF, 0xF0, 0xE0, 0xFF}, sunDir); // Add point light (color, position, strength) fm_vec3_t lightPos = {100.0f, 50.0f, 0.0f}; lighting.addPointLight({0xFF, 0x80, 0x00, 0xFF}, lightPos, 200.0f); // Get light count (max 6) uint32_t count = lighting.getLightCount(); // Apply lighting changes lighting.apply(); // Temporary lighting override P64::Lighting& tempLighting = scene.startLightingOverride(true); tempLighting.addPointLight({0xFF, 0x00, 0x00, 0xFF}, {0,0,0}, 100.0f); // ... render with override ... scene.endLightingOverride(); ``` -------------------------------- ### CLI Build Command for Pyrite64 Source: https://context7.com/hailtododongo/pyrite64/llms.txt Build Pyrite64 projects from the command line. This is useful for CI/CD pipelines and automated build tasks. It does not require a GPU to run. ```bash # Show all available CLI options ./pyrite64 --help # Build a project from command line ./pyrite64 --cli --cmd build /path/to/project.p64proj # Open project in visual editor (default behavior) ./pyrite64 /path/to/project.p64proj ``` -------------------------------- ### Spawn Prefab Objects Dynamically with Pyrite64 Scene API Source: https://context7.com/hailtododongo/pyrite64/llms.txt This code snippet demonstrates how to spawn prefab objects dynamically at runtime using the Pyrite64 Scene API. It covers spawning prefabs at a specific position (deferred to the next frame), spawning with a full transform including scale and rotation, removing objects from the scene, and retrieving objects by their ID. ```cpp #include "scene/scene.h" P64::Scene& scene = P64::SceneManager::getCurrent(); // Spawn prefab at position (deferred to next frame) fm_vec3_t spawnPos = {100.0f, 0.0f, 50.0f}; uint16_t newObjectId = scene.addObject("MyPrefab.pf"_asset, spawnPos); // Spawn with full transform fm_vec3_t scale = {2.0f, 2.0f, 2.0f}; fm_quat_t rotation = {0.0f, 0.0f, 0.0f, 1.0f}; uint16_t id = scene.addObject( "Enemy.pf"_asset, spawnPos, scale, rotation ); // Remove object from scene P64::Object* objToRemove = scene.getObjectById(objectId); if (objToRemove) { scene.removeObject(*objToRemove); // Or use shorthand: objToRemove->remove(); } // Get object by ID P64::Object* obj = scene.getObjectById(targetId); ``` -------------------------------- ### Access HDR/Bloom and Big Texture Render Pipelines (C++) Source: https://context7.com/hailtododongo/pyrite64/llms.txt Demonstrates how to obtain pointers to specialized render pipelines (HDR/Bloom and Big Texture) from the current scene in Pyrite64. It also shows how to check the active pipeline type based on scene configuration. Requires including scene and pipeline headers. ```cpp #include "scene/scene.h" #include "renderer/pipelineHDRBloom.h" #include "renderer/pipelineBigTex.h" P64::Scene& scene = P64::SceneManager::getCurrent(); // Get HDR+Bloom pipeline (returns nullptr if not active) auto* hdrPipeline = scene.getRenderPipeline(); if (hdrPipeline) { // Access HDR-specific features } // Get Big Texture pipeline (256x256 textures) auto* bigTexPipeline = scene.getRenderPipeline(); if (bigTexPipeline) { // Access big texture features } // Get default pipeline auto* defaultPipeline = scene.getRenderPipeline(); // Check scene configuration for pipeline type P64::SceneConf& conf = scene.getConf(); if (conf.pipeline == P64::SceneConf::Pipeline::HDR_BLOOM) { // HDR rendering is active } ``` -------------------------------- ### Send and Handle Events in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Demonstrates how to send custom and built-in events between objects in the Pyrite64 scene and how to handle these events within a script. It requires the 'scene/event.h' header and uses the P64::SceneManager to access the current scene. ```cpp #include "scene/event.h" P64::Scene& scene = P64::SceneManager::getCurrent(); // Send event to target object uint16_t targetId = 5; uint16_t senderId = obj.id; uint16_t eventType = 1; // Custom event type uint32_t eventValue = 100; scene.sendEvent(targetId, senderId, eventType, eventValue); // Built-in event types scene.sendEvent(targetId, senderId, P64::EVENT_TYPE_ENABLE, 0); scene.sendEvent(targetId, senderId, P64::EVENT_TYPE_DISABLE, 0); // Handle events in script void onEvent(Object& obj, Data* data, const ObjectEvent& event) { switch (event.type) { case P64::EVENT_TYPE_ENABLE: data->isActive = true; break; case P64::EVENT_TYPE_DISABLE: data->isActive = false; break; case 1: // Custom event debugf("Received value: %ld from %d\n", event.value, event.senderId); break; } } ``` -------------------------------- ### Prefab Spawning Source: https://context7.com/hailtododongo/pyrite64/llms.txt Dynamically spawns prefab objects into the scene at runtime, allowing for custom positioning, scaling, and rotation. ```APIDOC ## Prefab Spawning ### Description Spawn prefab objects dynamically at runtime with custom transforms. ### Methods - `addObject(AssetRef prefabAsset, fm_vec3_t position)`: Spawns a prefab at the specified position (deferred to the next frame). - `addObject(AssetRef prefabAsset, fm_vec3_t position, fm_vec3_t scale, fm_quat_t rotation)`: Spawns a prefab with a full transform. - `getObjectById(uint16_t objectId)`: Retrieves an object from the scene by its ID. - `removeObject(Object& object)`: Removes an object from the scene. ### Example ```cpp #include "scene/scene.h" P64::Scene& scene = P64::SceneManager::getCurrent(); // Spawn prefab at position (deferred to next frame) fm_vec3_t spawnPos = {100.0f, 0.0f, 50.0f}; uint16_t newObjectId = scene.addObject("MyPrefab.pf"_asset, spawnPos); // Spawn with full transform fm_vec3_t scale = {2.0f, 2.0f, 2.0f}; fm_quat_t rotation = {0.0f, 0.0f, 0.0f, 1.0f}; uint16_t id = scene.addObject( "Enemy.pf"_asset, spawnPos, scale, rotation ); // Remove object from scene P64::Object* objToRemove = scene.getObjectById(objectId); if (objToRemove) { scene.removeObject(*objToRemove); // Or use shorthand: objToRemove->remove(); } // Get object by ID P64::Object* obj = scene.getObjectById(targetId); ``` ``` -------------------------------- ### Debug Drawing Utilities in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Shows how to initialize, draw various debug shapes (AABB, lines, spheres), print debug text, and render debug graphics using the 'debug/debugDraw.h' library. It includes initialization, drawing calls, rendering, and cleanup. ```cpp #include "debug/debugDraw.h" // Initialize debug drawing Debug::init(); // Draw debug shapes fm_vec3_t boxCenter = {0.0f, 50.0f, 0.0f}; fm_vec3_t boxHalfExtent = {25.0f, 50.0f, 25.0f}; Debug::drawAABB(boxCenter, boxHalfExtent, {0xFF, 0x00, 0x00, 0xFF}); fm_vec3_t lineStart = {0.0f, 0.0f, 0.0f}; fm_vec3_t lineEnd = {100.0f, 100.0f, 0.0f}; Debug::drawLine(lineStart, lineEnd, {0x00, 0xFF, 0x00, 0xFF}); Debug::drawSphere({50.0f, 25.0f, 50.0f}, 20.0f, {0x00, 0x00, 0xFF, 0xFF}); // Debug text output Debug::printStart(); Debug::printf(10, 20, "Position: %.2f, %.2f, %.2f", pos.x, pos.y, pos.z); Debug::print(10, 30, "Static text"); // Render debug graphics Debug::draw(framebuffer); // Cleanup Debug::destroy(); ``` -------------------------------- ### Math Utilities in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Details various optimized math functions for N64 development, including clamping, random number generation, easing functions, linear interpolation, vector operations, and memory alignment. These functions are available through the 'lib/math.h' header. ```cpp #include "lib/math.h" // Clamping float clamped = P64::Math::clamp(value, 0.0f, 1.0f); fm_vec3_t clampedVec = P64::Math::clamp(vec, -1.0f, 1.0f); // Random numbers float random01 = P64::Math::rand01(); // 0.0 to 1.0 fm_vec3_t randomDir3D = P64::Math::randDir3D(); fm_vec3_t randomDir2D = P64::Math::randDir2D(); // XZ plane only // Easing functions float eased = P64::Math::easeOutCubic(t); float easedInOut = P64::Math::easeInOutCubic(t); float easedSin = P64::Math::easeOutSin(t); // Linear interpolation float interpolated = P64::Math::lerp(a, b, t); // Vector operations fm_vec3_t minVec = P64::Math::min(vecA, vecB); fm_vec3_t maxVec = P64::Math::max(vecA, vecB); fm_vec3_t absVec = P64::Math::abs(vec); fm_vec3_t crossProduct = P64::Math::cross(vecA, vecB); // Memory alignment uint32_t aligned = P64::Math::alignUp(value, 8); // Round up to 8-byte boundary uint32_t alignedDown = P64::Math::alignDown(value, 8); ``` -------------------------------- ### Control Camera Positioning and Projection with Pyrite64 Camera API Source: https://context7.com/hailtododongo/pyrite64/llms.txt This code demonstrates the Pyrite64 Camera API for controlling camera positioning and projection. It covers retrieving the active camera, setting its view using look-at or position/rotation, accessing camera properties like position and view direction, projecting world coordinates to screen space, and setting the camera's viewport. ```cpp #include "scene/camera.h" // Get active camera from scene P64::Camera& cam = P64::SceneManager::getCurrent().getActiveCamera(); // Set camera using look-at (position, target, up vector) fm_vec3_t camPos = {0.0f, 100.0f, -200.0f}; fm_vec3_t target = {0.0f, 50.0f, 0.0f}; cam.setLookAt(camPos, target, {0.0f, 1.0f, 0.0f}); // Set camera using position and rotation quaternion fm_quat_t rotation; fm_vec3_t euler = {0.0f, -1.57f, 0.3f}; fm_quat_from_euler(&rotation, euler.v); cam.setPosRot(camPos, rotation); // Get camera properties const fm_vec3_t& position = cam.getPos(); const fm_vec3_t& lookTarget = cam.getTarget(); fm_vec3_t viewDir = cam.getViewDir(); // Project world position to screen coordinates fm_vec3_t screenPos = cam.getScreenPos(worldPosition); // Set screen viewport area cam.setScreenArea(0, 0, 320, 240); ``` -------------------------------- ### Manage Game Assets with Pyrite64 AssetManager Source: https://context7.com/hailtododongo/pyrite64/llms.txt This section details the Pyrite64 AssetManager API for loading and managing game assets. It includes initialization, retrieving assets by index, using asset references for automatic loading and unloading, freeing all assets, and referencing assets via string literals with the `_asset` suffix. ```cpp #include "assets/assetManager.h" // Initialize asset manager P64::AssetManager::init(); // Get asset by index void* asset = P64::AssetManager::getByIndex(assetIdx); // Use asset references for auto-loading P64::AssetRef spriteRef; sprite_t* sprite = spriteRef.get(); // Auto-loads if needed // Free all loaded assets P64::AssetManager::freeAll(); // Reference assets using string literals with _asset suffix uint32_t coinAsset = "sfx/CoinGet.wav64"_asset; uint32_t prefabAsset = "ParticlesCoin.pf"_asset; ``` -------------------------------- ### Play and Control 2D Audio with Pyrite64 AudioManager Source: https://context7.com/hailtododongo/pyrite64/llms.txt This snippet demonstrates how to play and control 2D audio using the Pyrite64 AudioManager. It covers setting master volume, playing sounds with asset references, modifying volume and speed in real-time, checking playback status, stopping individual sounds or all sounds, and adding pitch variation. ```cpp #include "audio/audioManager.h" // Set global master volume (0.0 to 1.0) P64::AudioManager::setMasterVolume(0.8f); // Play audio using asset reference (returns handle) auto sfx = P64::AudioManager::play2D("sfx/CoinGet.wav64"_asset); // Modify audio after starting playback sfx.setVolume(0.5f); sfx.setSpeed(1.2f); // Check if audio finished playing if (sfx.isDone()) { // Audio completed } // Stop specific audio sfx.stop(); // Stop all playing audio P64::AudioManager::stopAll(); // Play with randomized pitch for variety auto footstep = P64::AudioManager::play2D("sfx/Step.wav64"_asset); footstep.setSpeed(1.0f - (P64::Math::rand01() * 0.2f)); footstep.setVolume(0.3f); ``` -------------------------------- ### Configure N64 Engine Build with CMake Source: https://github.com/hailtododongo/pyrite64/blob/main/n64/CMakeLists.txt This CMake script sets up the build environment for the n64_engine executable. It specifies the C and C++ compilers and standards, includes directories for external and internal libraries, and lists all source and header files required for compilation. Dependencies include the tiny3d and libdragon libraries, as well as various engine modules. ```cmake cmake_minimum_required(VERSION 3.30) project(n64_engine) set(CMAKE_C_COMPILER gcc) set(CMAKE_CXX_COMPILER g++) set(CMAKE_C_STANDARD 23) set(CMAKE_CXX_STANDARD 23) include_directories(../vendored/tiny3d/src) include_directories(../vendored/libdragon/include) include_directories(engine/include) add_executable(n64_engine engine/include/lib/fifo.h engine/include/lib/logger.h engine/include/lib/memory.h engine/include/scene/scene.h engine/include/vi/swapChain.h engine/src/lib/memory.cpp engine/src/scene/scene.cpp engine/src/vi/swapChain.cpp engine/src/main.cpp engine/src/scene/camera.cpp engine/src/scene/sceneManager.cpp engine/src/audio/audioManager.cpp engine/src/scene/sceneLoader.cpp engine/include/scene/object.h engine/include/scene/components/code.h engine/include/scene/componentTable.h engine/include/assets/assetManager.h engine/src/assets/assetManager.cpp engine/include/assets/assetTypes.h engine/src/scene/object.cpp engine/include/scene/components/light.h engine/src/scene/lighting.cpp engine/include/scene/components/camera.h engine/include/lib/math.h engine/src/debug/debugDraw.cpp engine/include/lib/ringBuffer.h engine/src/vi/vi.cpp engine/include/script/userScript.h engine/include/script/globalScript.h engine/include/scene/event.h engine/src/scene/components/collMesh.cpp engine/src/libdragon/rspq.h engine/include/renderer/drawLayer.h engine/src/renderer/drawLayer.cpp engine/src/renderer/pipelineDefault.cpp engine/src/renderer/pipelineHDRBloom.cpp engine/include/renderer/pipeline.h engine/include/renderer/pipelineHDRBloom.h engine/src/libdragon/utils.h engine/src/libdragon/utils.cpp engine/include/lib/mips.h engine/src/renderer/pipelineBigTex.cpp engine/src/scene/components/model.cpp engine/src/renderer/bigtex/bigtex.h engine/src/renderer/bigtex/bigtex.cpp engine/src/renderer/bigtex/textures.cpp engine/src/renderer/bigtex/uvTexture.cpp engine/src/renderer/bigtex/memory.cpp engine/src/renderer/bigtex/fbCpuDraw.cpp engine/src/renderer/bigtex/rspBigTex.cpp engine/include/scene/components/audio2d.h engine/src/scene/components/audio2d.cpp engine/src/scene/components/collBody.cpp engine/include/collision/flags.h engine/src/renderer/hdr/rspHDR.cpp engine/include/renderer/particles/ptxSprites.h engine/src/renderer/particles/ptxSystem.cpp engine/src/renderer/particles/ptxSprites.cpp engine/src/collision/resolver.cpp engine/src/collision/mesh.cpp engine/src/collision/meshLoader.cpp engine/src/lib/math.cpp engine/src/debug/overlay.cpp engine/include/collision/attach.h engine/src/collision/attach.cpp engine/src/scene/componentTable.cpp engine/src/collision/scene.cpp engine/src/scene/components/culling.cpp engine/include/renderer/material.h engine/src/collision/shapes.cpp engine/src/scene/components/constraint.cpp engine/src/scene/components/camera.cpp engine/src/scene/components/nodeGraph.cpp engine/include/script/nodeGraph.h engine/src/script/nodeGraph.cpp engine/src/renderer/material.cpp engine/src/scene/components/animModel.cpp examples/empty/engine/include/scene/components/camera.h ) ``` -------------------------------- ### Camera API Source: https://context7.com/hailtododongo/pyrite64/llms.txt Provides control over the camera's position, orientation, and projection settings, supporting both look-at and position/rotation modes for scene viewing. ```APIDOC ## Camera API ### Description Control camera positioning with look-at or position/rotation modes. Cameras support perspective projection with configurable FOV and clipping planes. ### Methods - `getActiveCamera()`: Gets the active camera from the current scene. - `setLookAt(fm_vec3_t position, fm_vec3_t target, fm_vec3_t up)`: Sets the camera's position and orientation using a look-at target. - `setPosRot(fm_vec3_t position, fm_quat_t rotation)`: Sets the camera's position and rotation directly. - `getPos()`: Returns the camera's current position. - `getTarget()`: Returns the camera's look-at target (if in look-at mode). - `getViewDir()`: Returns the camera's forward view direction vector. - `getScreenPos(fm_vec3_t worldPosition)`: Projects a world-space position to screen coordinates. - `setScreenArea(int x, int y, int width, int height)`: Defines the screen viewport area for the camera. ### Example ```cpp #include "scene/camera.h" // Get active camera from scene P64::Camera& cam = P64::SceneManager::getCurrent().getActiveCamera(); // Set camera using look-at (position, target, up vector) fm_vec3_t camPos = {0.0f, 100.0f, -200.0f}; fm_vec3_t target = {0.0f, 50.0f, 0.0f}; cam.setLookAt(camPos, target, {0.0f, 1.0f, 0.0f}); // Set camera using position and rotation quaternion fm_quat_t rotation; fm_vec3_t euler = {0.0f, -1.57f, 0.3f}; fm_quat_from_euler(&rotation, euler.v); cam.setPosRot(camPos, rotation); // Get camera properties const fm_vec3_t& position = cam.getPos(); const fm_vec3_t& lookTarget = cam.getTarget(); fm_vec3_t viewDir = cam.getViewDir(); // Project world position to screen coordinates fm_vec3_t screenPos = cam.getScreenPos(worldPosition); // Set screen viewport area cam.setScreenArea(0, 0, 320, 240); ``` ``` -------------------------------- ### Audio Manager API Source: https://context7.com/hailtododongo/pyrite64/llms.txt Controls 2D audio playback, allowing for volume and speed adjustments, as well as real-time modification of audio handles after playback begins. ```APIDOC ## Audio Manager API ### Description Play and control 2D audio with volume and speed adjustments. Audio handles allow real-time modification after playback starts. ### Methods - `setMasterVolume(float volume)`: Sets the global master volume (0.0 to 1.0). - `play2D(AssetRef audioAsset)`: Plays a 2D audio clip and returns a handle. - `stopAll()`: Stops all currently playing audio. ### Audio Handle Methods - `setVolume(float volume)`: Sets the volume for a specific audio playback. - `setSpeed(float speed)`: Sets the playback speed for a specific audio playback. - `isDone()`: Checks if the audio playback has finished. - `stop()`: Stops a specific audio playback. ### Example ```cpp #include "audio/audioManager.h" // Set global master volume (0.0 to 1.0) P64::AudioManager::setMasterVolume(0.8f); // Play audio using asset reference (returns handle) auto sfx = P64::AudioManager::play2D("sfx/CoinGet.wav64"_asset); // Modify audio after starting playback sfx.setVolume(0.5f); sfx.setSpeed(1.2f); // Check if audio finished playing if (sfx.isDone()) { // Audio completed } // Stop specific audio sfx.stop(); // Stop all playing audio P64::AudioManager::stopAll(); // Play with randomized pitch for variety auto footstep = P64::AudioManager::play2D("sfx/Step.wav64"_asset); footstep.setSpeed(1.0f - (P64::Math::rand01() * 0.2f)); footstep.setVolume(0.3f); ``` ``` -------------------------------- ### Custom Script Definition in C++ Source: https://context7.com/hailtododongo/pyrite64/llms.txt Define custom game scripts using the P64_DATA macro for persistent data and standard callback functions in C++. This includes initialization, update, drawing, event handling, and collision handling. ```cpp #include "script/userScript.h" namespace P64::Script::MyCustomScript { // Define persistent data for this script P64_DATA( float timer; fm_vec3_t velocity; bool isActive; ); // Called on object creation and destruction void initDelete(Object& obj, Data* data, bool isDelete) { if (isDelete) { // Cleanup code here return; } // Initialize data data->timer = 0.0f; data->velocity = {0.0f, 0.0f, 0.0f}; data->isActive = true; } // Called every frame void update(Object& obj, Data* data, float deltaTime) { data->timer += deltaTime; obj.pos += data->velocity * deltaTime; } // Called during render phase void draw(Object& obj, Data* data, float deltaTime) { P64::DrawLayer::use2D(); // Draw UI elements P64::DrawLayer::useDefault(); } // Handle custom events void onEvent(Object& obj, Data* data, const ObjectEvent& event) { if (event.type == 1) { debugf("Received event from object %d\n", event.senderId); } } // Handle collision events void onCollision(Object& obj, Data* data, const Coll::CollEvent& event) { if (event.otherBCS) { // Handle collision with another collider } if (event.otherMesh) { // Handle collision with mesh } } } ``` -------------------------------- ### Asset Manager API Source: https://context7.com/hailtododongo/pyrite64/llms.txt Manages game assets, including loading, unloading, and automatic memory cleanup. Utilizes asset references for lazy-loading and efficient resource management. ```APIDOC ## Asset Manager API ### Description Load and manage game assets with automatic memory cleanup and lazy-loading through asset references. ### Methods - `init()`: Initializes the asset manager. - `getByIndex(uint32_t assetIndex)`: Retrieves an asset by its index. - `freeAll()`: Frees all loaded assets from memory. ### Asset References Asset references (`AssetRef`) provide a mechanism for automatic loading and unloading of assets. When `get()` is called on an `AssetRef`, the asset is loaded if it hasn't been already. ### Referencing Assets Assets can be referenced using string literals with the `_asset` suffix, which returns a `uint32_t` asset ID. ### Example ```cpp #include "assets/assetManager.h" // Initialize asset manager P64::AssetManager::init(); // Get asset by index void* asset = P64::AssetManager::getByIndex(assetIdx); // Use asset references for auto-loading P64::AssetRef spriteRef; sprite_t* sprite = spriteRef.get(); // Auto-loads if needed // Free all loaded assets P64::AssetManager::freeAll(); // Reference assets using string literals with _asset suffix uint32_t coinAsset = "sfx/CoinGet.wav64"_asset; uint32_t prefabAsset = "ParticlesCoin.pf"_asset; ``` ``` -------------------------------- ### Define Pyrite64 Executable Target (CMake) Source: https://github.com/hailtododongo/pyrite64/blob/main/CMakeLists.txt This CMake snippet defines the main executable target for the Pyrite64 project. It lists all the source files and header files required to compile the game, including core logic, vendored libraries, and custom editor/renderer components. Dependencies include SHA256, tiny3d, ImGui, ImGuizmo, ImNodeFlow, and tiny-regex-c. ```cmake add_executable(pyrite64 src/main.cpp # SHA256 vendored/SHA256/src/SHA256.cpp vendored/SHA256/include/SHA256.h # tiny3d gltf converter vendored/tiny3d/tools/gltf_importer/src/parser.cpp vendored/tiny3d/tools/gltf_importer/src/writer.cpp vendored/tiny3d/tools/gltf_importer/src/parser/materialParser.cpp vendored/tiny3d/tools/gltf_importer/src/parser/boneParser.cpp vendored/tiny3d/tools/gltf_importer/src/parser/nodeParser.cpp vendored/tiny3d/tools/gltf_importer/src/optimizer/meshOptimizer.cpp vendored/tiny3d/tools/gltf_importer/src/optimizer/meshBVH.cpp vendored/tiny3d/tools/gltf_importer/src/parser/animParser.cpp vendored/tiny3d/tools/gltf_importer/src/converter/meshConverter.cpp vendored/tiny3d/tools/gltf_importer/src/converter/animConverter.cpp vendored/tiny3d/tools/gltf_importer/src/lib/lodepng.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/allocator.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/indexcodec.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/indexgenerator.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/simplifier.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/stripifier.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/spatialorder.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/vcacheanalyzer.cpp vendored/tiny3d/tools/gltf_importer/src/lib/meshopt/vcacheoptimizer.cpp vendored/tiny3d/tools/gltf_importer/src/lib/tristrip/connectivity_graph.cpp vendored/tiny3d/tools/gltf_importer/src/lib/tristrip/policy.cpp vendored/tiny3d/tools/gltf_importer/src/lib/tristrip/tri_stripper.cpp # imgui vendored/imgui/backends/imgui_impl_sdl3.cpp vendored/imgui/backends/imgui_impl_sdl3.h vendored/imgui/backends/imgui_impl_sdlgpu3.cpp vendored/imgui/backends/imgui_impl_sdlgpu3.h vendored/imgui/imgui.h vendored/imgui/imgui.cpp vendored/imgui/imgui_draw.cpp vendored/imgui/imgui_tables.cpp vendored/imgui/imgui_widgets.cpp vendored/imgui/misc/cpp/imgui_stdlib.cpp vendored/imgui/misc/cpp/imgui_stdlib.h # ImGuizmo vendored/ImGuizmo/ImGuizmo.cpp # Imgui node editor vendored/ImNodeFlow/src/ImNodeFlow.cpp # Regex vendored/tiny-regex-c/re.c # editor src/editor/pages/editorScene.h src/editor/pages/editorScene.cpp src/renderer/shader.h src/renderer/shader.cpp src/renderer/vertBuffer.h src/renderer/vertBuffer.cpp src/renderer/vertex.h src/context.h src/project/project.h src/editor/pages/editorMain.cpp src/renderer/texture.cpp src/renderer/texture.h src/project/project.cpp src/editor/actions.h src/editor/actions.cpp src/editor/undoRedo.h src/editor/undoRedo.cpp src/utils/json.h src/editor/imgui/theme.h src/editor/imgui/theme.cpp src/editor/imgui/helper.h src/utils/filePicker.h src/utils/filePicker.cpp src/editor/pages/parts/viewport3D.h src/editor/pages/parts/viewport3D.cpp src/renderer/scene.h src/renderer/scene.cpp src/renderer/framebuffer.h src/renderer/framebuffer.cpp src/editor/pages/parts/assetsBrowser.h src/editor/pages/parts/assetsBrowser.cpp src/project/assetManager.h src/project/assetManager.cpp src/utils/hash.h src/editor/pages/parts/assetInspector.cpp src/editor/pages/parts/assetInspector.h src/utils/textureFormats.h src/project/scene/sceneManager.h src/project/scene/sceneManager.cpp src/project/scene/scene.h src/project/scene/scene.cpp src/editor/pages/parts/sceneInspector.cpp src/build/projectBuilder.h src/build/projectBuilder.cpp src/utils/fs.h src/utils/string.h src/utils/proc.h src/utils/proc.cpp src/build/sceneBuilder.cpp src/utils/binaryFile.h src/build/sceneContext.h src/build/stringTable.h src/utils/logger.h src/utils/logger.cpp src/editor/pages/parts/logWindow.cpp src/editor/pages/parts/logWindow.h src/editor/pages/parts/projectSettings.h src/editor/pages/parts/projectSettings.cpp src/editor/pages/parts/sceneGraph.h src/editor/pages/parts/sceneGraph.cpp src/project/scene/object.h src/project/scene/object.cpp src/editor/pages/parts/objectInspector.cpp src/utils/jsonBuilder.h src/project/component/components.h src/project/component/components.cpp src/project/component/types/compCode.cpp src/cli.cpp src/cli.h ) ``` -------------------------------- ### Collision System API Source: https://context7.com/hailtododongo/pyrite64/llms.txt Enables interaction with the physics system, allowing for raycasts to detect collisions and registration of collision bodies for physics simulation. ```APIDOC ## Collision System API ### Description Perform raycasts and register collision bodies for physics simulation. ### Methods - `getCollision()`: Retrieves the collision scene from the current scene. - `raycast(fm_vec3_t origin, fm_vec3_t direction)`: Performs a raycast and returns collision results. ### Collision Body Properties - `center`: The center position of the collision body. - `velocity`: The velocity of the collision body. - `hitTriTypes`: Bitmask indicating the types of triangles hit (e.g., FLOOR). - `isTrigger()`: Returns true if the body is a trigger. - `getRadius()`: Returns the radius of a spherical collision body. ### Example ```cpp #include "collision/scene.h" #include "collision/shapes.h" // Get collision scene from current scene P64::Coll::Scene& coll = P64::SceneManager::getCurrent().getCollision(); // Perform raycast fm_vec3_t rayOrigin = obj.pos; fm_vec3_t rayDir = {0.0f, -1.0f, 0.0f}; // Down P64::Coll::RaycastRes result = coll.raycast(rayOrigin, rayDir); if (result.hasResult()) { fm_vec3_t hitPoint = result.hitPos; fm_vec3_t hitNormal = result.normal; // Snap object to floor obj.pos.y = hitPoint.y + 20.0f; } // Access collision body from object component auto* collBody = obj.getComponent(); P64::Coll::BCS& bcs = collBody->bcs; // Modify collision sphere properties bcs.center = obj.pos; bcs.velocity = {10.0f, 0.0f, 5.0f}; // Check collision flags bool onFloor = bcs.hitTriTypes & P64::Coll::TriType::FLOOR; bool isTrigger = bcs.isTrigger(); float radius = bcs.getRadius(); ``` ``` -------------------------------- ### Perform Raycasts and Manage Collision Bodies with Pyrite64 Collision System Source: https://context7.com/hailtododongo/pyrite64/llms.txt This snippet illustrates the Pyrite64 Collision System API for performing raycasts and managing collision bodies. It shows how to access the collision scene, execute raycasts to detect intersections, retrieve hit information, and manipulate collision body properties such as center, velocity, and check collision flags. ```cpp #include "collision/scene.h" #include "collision/shapes.h" // Get collision scene from current scene P64::Coll::Scene& coll = P64::SceneManager::getCurrent().getCollision(); // Perform raycast fm_vec3_t rayOrigin = obj.pos; fm_vec3_t rayDir = {0.0f, -1.0f, 0.0f}; // Down P64::Coll::RaycastRes result = coll.raycast(rayOrigin, rayDir); if (result.hasResult()) { fm_vec3_t hitPoint = result.hitPos; fm_vec3_t hitNormal = result.normal; // Snap object to floor obj.pos.y = hitPoint.y + 20.0f; } // Access collision body from object component auto* collBody = obj.getComponent(); P64::Coll::BCS& bcs = collBody->bcs; // Modify collision sphere properties bcs.center = obj.pos; bcs.velocity = {10.0f, 0.0f, 5.0f}; // Check collision flags bool onFloor = bcs.hitTriTypes & P64::Coll::TriType::FLOOR; bool isTrigger = bcs.isTrigger(); float radius = bcs.getRadius(); ``` -------------------------------- ### CMake Subdirectory Inclusion for SDL and Dependencies Source: https://github.com/hailtododongo/pyrite64/blob/main/CMakeLists.txt Includes subdirectories for external libraries within the project. It adds 'vendored/SDL', 'vendored/SDL_image', and 'vendored/glm' to the build. Specific image formats for SDL_image are enabled, while others are explicitly disabled. ```cmake add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL) set(SDLIMAGE_BMP ON) set(SDLIMAGE_GIF ON) set(SDLIMAGE_JPG ON) set(SDLIMAGE_PNG ON) set(SDLIMAGE_SVG ON) # Not needed, some of those also break windows builds due to missing ASM compilers set(SDLIMAGE_AVIF OFF) set(SDLIMAGE_JXL OFF) set(SDLIMAGE_LBM OFF) set(SDLIMAGE_PCX OFF) set(SDLIMAGE_PNM OFF) set(SDLIMAGE_QOI OFF) set(SDLIMAGE_TGA OFF) set(SDLIMAGE_TIF OFF) set(SDLIMAGE_WEBP OFF) set(SDLIMAGE_XCF OFF) set(SDLIMAGE_XPM OFF) set(SDLIMAGE_XV OFF) add_subdirectory(vendored/SDL_image EXCLUDE_FROM_ALL) add_subdirectory(vendored/glm EXCLUDE_FROM_ALL) ``` -------------------------------- ### CMake Build Flags and Library Settings Source: https://github.com/hailtododongo/pyrite64/blob/main/CMakeLists.txt Customizes compiler flags for release and debug builds and configures library build types. Release builds include '-Wall' and '-O2' for warnings and optimization, while debug builds disable Link-Time Optimization (LTO). It also sets default options for building shared libraries. ```cmake set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -O2") # debug, disable LTO set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-lto") set(SDL_SHARED_DEFAULT OFF) set(BUILD_SHARED_LIBS off) ``` -------------------------------- ### Configure CMake Build for Pyrite64 Engine Source: https://github.com/hailtododongo/pyrite64/blob/main/n64/examples/jam25/CMakeLists.txt This CMake script configures the build environment for the Pyrite64 engine. It sets the minimum required CMake version, project name, C and C++ compiler versions, C and C++ standard versions, includes directories for vendored libraries and engine components, and defines the main executable target 'gj25' with a comprehensive list of source files. ```cmake cmake_minimum_required(VERSION 3.30) project(gj25) set(CMAKE_C_COMPILER gcc) set(CMAKE_CXX_COMPILER g++) set(CMAKE_C_STANDARD 23) set(CMAKE_CXX_STANDARD 23) include_directories(~/Documents/projects/pyrite64/vendored/tiny3d/src) include_directories(~/Documents/projects/pyrite64/vendored/libdragon/include) include_directories(~/Documents/projects/pyrite64/n64/engine/include) add_executable(gj25 src/user/ObjBot.cpp src/user/globalSetup.cpp src/user/systems/marker.h src/user/systems/marker.cpp src/user/systems/context.h src/user/TitleScreen.cpp src/user/TitleCard.cpp src/user/SkyBox.cpp src/user/systems/screenFade.h src/user/systems/screenFade.cpp src/user/globals.h src/user/LoadingZone.cpp src/user/MiniMap.cpp src/user/TestRot.cpp src/user/Player.cpp src/user/systems/dropShadows.cpp src/user/systems/dropShadows.h src/user/systems/sprites.h src/user/systems/sprites.cpp src/user/Coin.cpp src/user/HUD.cpp src/user/systems/fonts.h src/user/systems/fonts.cpp src/p64/assetTable.h src/user/Particles.cpp src/user/ObjVoid.cpp src/user/systems/dialog.h src/user/systems/dialog.cpp src/user/systems/dialogMessages.h src/user/Seesaw.cpp src/p64/CA20630FE536B54B.cpp src/p64/scriptTable.cpp src/user/Credits.cpp src/user/DebugCam.cpp src/user/BootChecks.cpp src/user/BootLogos.cpp src/user/ObjHead.cpp src/user/Goal.cpp ) ``` -------------------------------- ### CMake Preprocessor Definitions for IMGUI Source: https://github.com/hailtododongo/pyrite64/blob/main/CMakeLists.txt Adds preprocessor definitions for the IMGUI library. This specific definition 'IMGUI_USE_WCHAR32' is set, which likely influences how IMGUI handles wide character strings. ```cmake add_compile_definitions(IMGUI_USE_WCHAR32) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.