### Setup Rendering System with Meshes, Materials, and Textures (Go) Source: https://context7.com/kaijuengine/kaiju/llms.txt Demonstrates the setup of the rendering system in Go, including loading textures, creating vertices and meshes, setting up materials with instances, and registering entities for rendering. It utilizes the engine's caching mechanisms for textures and materials. ```go package main import ( "kaiju/engine" "kaiju/matrix" "kaiju/rendering" ) func setupRendering(host *engine.Host) error { // Load texture from asset database texture, err := host.TextureCache().Texture("texture-guid-123") if err != nil { return err } // Create vertices for a quad vertices := []rendering.Vertex{ {Position: matrix.Vec3{-1, -1, 0}, UV: matrix.Vec2{0, 0}, Normal: matrix.Vec3{0, 0, 1}}, {Position: matrix.Vec3{1, -1, 0}, UV: matrix.Vec2{1, 0}, Normal: matrix.Vec3{0, 0, 1}}, {Position: matrix.Vec3{1, 1, 0}, UV: matrix.Vec2{1, 1}, Normal: matrix.Vec3{0, 0, 1}}, {Position: matrix.Vec3{-1, 1, 0}, UV: matrix.Vec2{0, 1}, Normal: matrix.Vec3{0, 0, 1}}, } indices := []uint32{0, 1, 2, 0, 2, 3} // Create mesh mesh := rendering.NewMesh("quad-mesh", vertices, indices) host.MeshCache().Add("quad-mesh", mesh) // Load material material, err := host.MaterialCache().Material("material-guid-456") if err != nil { return err } // Create material instance with custom textures instanceMaterial := material.CreateInstance([]*rendering.Texture{texture}) // Create entity with mesh renderer entity := host.NewEntity() entity.Transform.SetPosition(0, 0, -10) // Add mesh rendering data to entity entity.SetData("mesh", mesh) entity.SetData("material", instanceMaterial) // Register render callback host.Updater.Add(func(deltaTime float64) { if entity.IsActive() && !entity.IsDestroyed() { // Drawing happens automatically through host.Drawings drawInstance := rendering.NewDrawInstance( mesh, instanceMaterial, entity.Transform.WorldMatrix(), ) host.Drawings.Add(drawInstance) } }) return nil } ``` -------------------------------- ### Build Soloud Library (Linux) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source.md Steps to compile the Soloud audio library on Linux using CMake and Unix Makefiles. This setup disables SDL2 and enables ALSA and C API backends for Linux audio. ```shell git clone https://github.com/jarikomppa/soloud.git cd soloud cd contrib mkdir build cd build cmake .. -G "Unix Makefiles" -DSOLOUD_BACKEND_SDL2=OFF -DSOLOUD_BACKEND_ALSA=ON -DSOLOUD_C_API=ON cmake --build . --config Release ``` -------------------------------- ### Initialize Kaiju Engine Host System in Go Source: https://context7.com/kaijuengine/kaiju/llms.txt Sets up the core Kaiju engine host, including logging, asset database, rendering, audio, and frame rate limiting. It initializes various caches for shaders, textures, meshes, and materials. This function is crucial for starting the engine's runtime environment. ```go package main import ( "kaiju/engine" "kaiju/engine/assets" "kaiju/engine/systems/logging" "kaiju/matrix" ) func initializeEngine() error { // Create logging stream logStream := logging.Initialize(nil) defer logStream.Close() // Create asset database assetDb, err := assets.NewFileDatabase("./database/content") if err != nil { return err } // Create host host := engine.NewHost("MyGame", logStream, assetDb) // Initialize with window dimensions and position if err := host.Initialize(1920, 1080, 100, 100, nil); err != nil { return err } // Initialize rendering subsystems if err := host.InitializeRenderer(); err != nil { return err } // Initialize audio if err := host.InitializeAudio(); err != nil { return err } // Set frame rate limit (60 FPS) host.SetFrameRateLimit(60) // Access various caches shaderCache := host.ShaderCache() textureCache := host.TextureCache() meshCache := host.MeshCache() materialCache := host.MaterialCache() return nil } ``` -------------------------------- ### Bootstrap Game Application in Go Source: https://context7.com/kaijuengine/kaiju/llms.txt Initializes a game or editor application using the Kaiju engine's bootstrap functionality. It requires a struct implementing the `bootstrap.Game` interface to define game logic, asset loading, and Lua integration points. The entry point uses `bootstrap.Main` to start the application. ```go package main import ( "kaiju/bootstrap" "kaiju/engine" "kaiju/engine/assets" "reflect" ) type MyGame struct{} func (g *MyGame) Launch(host *engine.Host) { // Initialize game systems, load assets, create entities entity := host.NewEntity() entity.Transform.SetPosition(0, 0, 0) // Register update callbacks host.Updater.Add(func(deltaTime float64) { // Game update logic here }) } func (g *MyGame) PluginRegistry() []reflect.Type { // Return types to expose to Lua scripting return []reflect.Type{} } func (g *MyGame) ContentDatabase() (assets.Database, error) { // Return the content database implementation return assets.NewFileDatabase("./database/content") } func main() { game := &MyGame{} bootstrap.Main(game, nil) // platformState is nil for desktop } ``` -------------------------------- ### Build Kaiju Editor (Windows) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source.md Commands to build the Kaiju editor executable in Windows. These commands are executed from the 'src' directory and allow for building in both debug and release modes. Ensure MinGW is installed and its bin folder is added to the system's PATH environment variable. ```shell go build -tags="debug,editor" -o ../kaiju.exe ./ ``` ```shell go build -ldflags="-s -w" -tags="editor" -o ../kaiju.exe ./ ``` -------------------------------- ### Bind Dummy Data for UI Preview using JSON Source: https://github.com/kaijuengine/kaiju/blob/master/docs/ui/preview.md This JSON structure demonstrates how to provide dummy data for UI preview. Create a JSON file with the same name as your HTML file but with a `.json` extension (e.g., `your-file.html.json`). This file should contain key-value pairs, where keys correspond to data you want to bind in your HTML. ```json { "EntityNames": ["Entity1", "Entity2", "Entity3"] } ``` -------------------------------- ### Go Template for Quick Access Folder Display Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/editor_embedded_content/editor_content/editor/ui/overlay/file_browser.go.html This Go template code snippet iterates through a list of folders (`QuickAccessFolders`) and renders them with an associated folder icon. It is designed to display a quick access menu within the Kaiju project's UI. Dependencies include the `QuickAccessFolders` data structure passed to the template. ```gohtml {{.Title}} Quick access {{range .QuickAccessFolders}}  {{.Name}} {{end}} < \> ^ @ New folder   Name 1 Select Cancel ``` -------------------------------- ### Set Up Event System with Go Source: https://context7.com/kaijuengine/kaiju/llms.txt Illustrates how to set up and manage events within the Kaiju Engine's event system. It covers entity lifecycle events (activate, deactivate, destroy), window events (resize), host close events, and custom event handling with adding, executing, and removing handlers. Dependencies include 'kaiju/engine' and 'kaiju/engine/systems/events'. ```go package main import ( "kaiju/engine" "kaiju/engine/systems/events" ) func setupEvents(host *engine.Host) { entity := host.NewEntity() // Entity lifecycle events entity.OnActivate.Add(func() { // Entity was activated }) entity.OnDeactivate.Add(func() { // Entity was deactivated }) entity.OnDestroy.Add(func() { // Entity is being destroyed // Cleanup resources here }) // Window events host.Window.OnResize.Add(func() { width := host.Window.Width() height := host.Window.Height() // Handle window resize _ = width _ = height }) // Host close event host.OnClose.Add(func() { // Application is closing // Save state, cleanup resources }) // Custom event system customEvent := events.Event{} customEvent.Add(func() { // Custom event handler }) // Execute event customEvent.Execute() // Remove event handler handlerId := customEvent.Add(func() {}) customEvent.Remove(handlerId) } ``` -------------------------------- ### Create UI Elements and Layouts Source: https://context7.com/kaijuengine/kaiju/llms.txt Demonstrates the creation and configuration of various UI elements such as buttons, labels, input fields, checkboxes, and panels. It shows how to initialize elements, set their positions and scales, apply colors, and attach event listeners for user interactions. This system relies on the engine's UI manager and rendering components. ```go package main import ( "kaiju/engine" "kaiju/engine/ui" "kaiju/matrix" "kaiju/rendering" ) func createUI(host *engine.Host, uiManager *ui.Manager) { // Load UI texture buttonTexture, _ := host.TextureCache().Texture("button-texture-guid") // Create button button := uiManager.Add().ToButton() button.Init(buttonTexture, "Click Me") button.layout.SetPosition(100, 100) button.layout.Scale(200, 50) button.SetColor(matrix.Color{R: 0.2, G: 0.5, B: 0.8, A: 1.0}) // Add click event button.Base().AddEvent(ui.EventTypeClick, func() { // Button clicked callback label := button.Label() label.SetText("Clicked!") }) // Create label label := uiManager.Add().ToLabel() label.Init("Score: 0") label.layout.SetPosition(50, 50) label.SetColor(matrix.ColorWhite()) label.SetFontSize(24) label.SetJustify(rendering.FontJustifyLeft) label.SetBaseline(rendering.FontBaselineTop) // Create input field input := uiManager.Add().ToInput() input.Init("Enter name...") input.layout.SetPosition(100, 200) input.layout.Scale(300, 40) // Get input value input.Base().AddEvent(ui.EventTypeChange, func() { text := input.Text() // Process input text _ = text }) // Create checkbox checkbox := uiManager.Add().ToCheckbox() checkbox.Init("Enable sound") checkbox.layout.SetPosition(100, 300) checkbox.Base().AddEvent(ui.EventTypeChange, func() { isChecked := checkbox.IsChecked() // Handle checkbox state _ = isChecked }) // Create panel container panel := uiManager.Add().ToPanel() panel.Init(nil, ui.ElementTypePanel) panel.layout.SetPosition(500, 100) panel.layout.Scale(400, 600) panel.SetColor(matrix.Color{R: 0.1, G: 0.1, B: 0.1, A: 0.9}) // Add children to panel childLabel := uiManager.Add().ToLabel() childLabel.Init("Inside Panel") panel.AddChild(childLabel.Base()) } ``` -------------------------------- ### Build Soloud Library (Windows) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source.md Instructions to build the Soloud audio library on Windows using CMake and MinGW Makefiles. This configuration disables SDL2 backend and enables WASAPI and C API, suitable for Windows audio output. ```shell git clone https://github.com/jarikomppa/soloud.git cd soloud cd contrib mkdir build cd build cmake .. -G "MinGW Makefiles" .. -DSOLOUD_BACKEND_SDL2=OFF -DSOLOUD_BACKEND_WASAPI=ON -DSOLOUD_C_API=ON cmake --build . --config Release ``` -------------------------------- ### Build Project Templates with Go Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source-custom.md This command generates project template files necessary for creating new projects within the Kaiju Engine. It requires the Go compiler and should be run from the 'src' directory. Ensure to re-run this command after pulling new content changes to update the project template. ```go go run ./generators/project_template/main.go ``` -------------------------------- ### Build Soloud Library (Android on Windows) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source.md Commands to build the Soloud library for Android on a Windows machine using CMake, MinGW, and the Android NDK. This configuration specifies ARM64 ABI, Android platform 21, static C++ STL, and enables OpenSL ES for audio, while disabling many other backends. It also enables support for WAV, OGG, and MP3 formats. ```shell git clone https://github.com/jarikomppa/soloud.git cd soloud cd contrib mkdir build cd build cmake .. -G "MinGW Makefiles" .. -DCMAKE_TOOLCHAIN_FILE=%NDK_HOME%/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-21 -DANDROID_STL=c++_static -DCMAKE_BUILD_TYPE=Release -DSOLLOUD_STATIC=1 -DSOLLOUD_BUILD_DEMOS=OFF -DSOLOUD_BACKEND_OPENSLES=ON -DSOLOUD_BACKEND_SDL2=OFF -DSOLOUD_C_API=ON -DSOLOUD_BACKEND_NULL=OFF -DSOLOUD_BACKEND_MINIAUDIO=OFF -DSOLOUD_BACKEND_WAVEOUT=OFF -DSOLOUD_BACKEND_XAUDIO2=OFF -DSOLOUD_BACKEND_WINMM=OFF -DSOLOUD_BACKEND_WASAPI=OFF -DSOLOUD_BACKEND_ALSA=OFF -DSOLOUD_BACKEND_COREAUDIO=OFF -DSOLOUD_BACKEND_OPENAL=OFF -DSOLOUD_WAV=ON -DSOLOUD_OGG=ON -DSOLOUD_MP3=ON -DSOLOUD_FLAC=OFF -DSOLOUD_OPUS=OFF -DSOLOUD_SPEECH=OFF -DSOLOUD_SFXR=OFF -DSOLOUD_AY=OFF -DSOLOUD_SID=OFF -DSOLOUD_VIC=OFF -DSOLOUD_TEDSID=OFF -DSOLOUD_MONOTONE=OFF -DSOLOUD_VIC=OFF -DSOLOUD_BASSBOOST=OFF -DSOLOUD_BIQUAD=OFF -DSOLOUD_DCREMOVAL=OFF -DSOLOUD_ECHO=OFF -DSOLOUD_FFT=OFF -DSOLOUD_FREEVERB=OFF -DSOLOUD_LOFI=OFF -DSOLOUD_WAVESHAPER=OFF cmake --build . --config Release ``` -------------------------------- ### Loading UI from HTML Asset in Go Source: https://github.com/kaijuengine/kaiju/blob/master/docs/ui/writing.md Demonstrates how to load and render a UI document from an HTML asset using the Kaiju Engine's Go API. It shows how to prepare binding data, call `DocumentFromHTMLAsset`, and handle the returned document and any potential errors. The function automatically loads the UI into the host. ```go data := struct{ EntityNames []string }{ []string{"Entity1", "Entity2", "Entity3"}, } doc, err := markup.DocumentFromHTMLAsset(host, "ui/tests/binding.html", data, nil) ``` -------------------------------- ### Activate Live UI Preview in Kaiju Engine Console Source: https://github.com/kaijuengine/kaiju/blob/master/docs/ui/preview.md This command activates the live preview for your UI. It requires the path to the HTML file you want to preview. The preview updates automatically when the HTML file is saved. ```shell preview path/to/file.html ``` -------------------------------- ### Build Kaiju Engine Executable with Go (Windows) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source-custom.md Builds the Kaiju Engine executable on Windows. This process requires the Kaiju Engine Go compiler and mingw to be set up and accessible via the system's PATH. It is executed by running a Go script. ```go go run build/build.go ``` -------------------------------- ### Build Kaiju Editor (Linux) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source.md Commands to build the Kaiju editor executable on Linux systems. The process involves navigating to the 'src' directory and using the 'go build' command. Options are provided for building in debug mode with the 'debug' tag or in release mode with linker flags for smaller executables. ```shell go build -tags="debug,editor" -o ../kaiju ./ ``` ```shell go build -ldflags="-s -w" -tags="editor" -o ../kaiju ./ ``` -------------------------------- ### Go Template for Rendering File List Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/editor_embedded_content/editor_content/editor/ui/workspace/shading_workspace.go.html A Go template that iterates over a collection of files and renders their names. It assumes a data structure with a 'Files' field, where each element has a 'Name' property. ```go-template {{range .Files}} {{.Name}} {{end}} ``` -------------------------------- ### Configure Dual Camera System and Input Handling Source: https://context7.com/kaijuengine/kaiju/llms.txt Initializes and configures both the primary 3D camera and the UI orthographic camera. It sets camera properties like position, look-at target, field of view, and near/far clipping planes. The system also handles window resize events to update camera viewports and implements basic first-person shooter style camera movement using keyboard input ('W' and 'D' keys) tied to the engine's update loop. ```go package main import ( "kaiju/engine" "kaiju/engine/cameras" "kaiju/matrix" ) func setupCameras(host *engine.Host) { // Access primary 3D camera primaryCamera := host.Cameras.Primary.Camera primaryCamera.SetPosition(matrix.Vec3{X: 0, Y: 5, Z: 10}) primaryCamera.LookAt(matrix.Vec3Zero()) primaryCamera.SetFOV(60.0) primaryCamera.SetNearFar(0.1, 1000.0) // Get camera matrices viewMatrix := primaryCamera.View() projectionMatrix := primaryCamera.Projection() _ = viewMatrix _ = projectionMatrix // Access UI camera (orthographic) uiCamera := host.Cameras.UI.Camera uiCamera.ViewportChanged(1920, 1080) // Handle window resize host.Window.OnResize.Add(func() { width := float32(host.Window.Width()) height := float32(host.Window.Height()) primaryCamera.ViewportChanged(width, height) uiCamera.ViewportChanged(width, height) }) // Camera movement (typical FPS-style) speed := float32(5.0) host.Updater.Add(func(deltaTime float64) { dt := float32(deltaTime) pos := primaryCamera.Position() forward := primaryCamera.Forward() right := primaryCamera.Right() // Move forward if host.Window.Input.IsKeyDown("W") { newPos := matrix.Vec3Add(pos, matrix.Vec3Scale(forward, speed*dt)) primaryCamera.SetPosition(newPos) } // Move right if host.Window.Input.IsKeyDown("D") { newPos := matrix.Vec3Add(pos, matrix.Vec3Scale(right, speed*dt)) primaryCamera.SetPosition(newPos) } }) } ``` -------------------------------- ### Initialize Physics World and Rigid Bodies with Bullet3 (Go) Source: https://context7.com/kaijuengine/kaiju/llms.txt Details the initialization of a 3D physics world using the Bullet3 library in Go. It covers setting up the collision configuration, dispatcher, broadphase, and solver, then creating a discrete dynamics world with gravity, a rigid body, and performing a raycast test. ```go package main import ( "kaiju/physics" "kaiju/matrix" ) func initializePhysics() *physics.World { // Create collision configuration collisionConfig := physics.NewDefaultCollisionConfiguration() // Create dispatcher dispatcher := physics.NewCollisionDispatcher(collisionConfig) // Create broadphase broadphase := physics.NewDbvtBroadphase() // Create solver solver := physics.NewSequentialImpulseConstraintSolver() // Create physics world world := physics.NewDiscreteDynamicsWorld( dispatcher, broadphase, solver, collisionConfig, ) // Set gravity world.SetGravity(matrix.Vec3{X: 0, Y: -9.81, Z: 0}) // Create collision shape (box) boxShape := physics.NewBoxShape(matrix.Vec3{X: 1, Y: 1, Z: 1}) // Create rigid body mass := float32(1.0) motionState := physics.NewDefaultMotionState( matrix.Vec3{X: 0, Y: 10, Z: 0}, matrix.QuaternionIdentity(), ) rigidBody := physics.NewRigidBody(mass, motionState, boxShape) world.AddRigidBody(rigidBody) // Step simulation (call each frame) deltaTime := float32(0.016) // 60 FPS world.StepSimulation(deltaTime) // Raycast test from := matrix.Vec3{X: 0, Y: 10, Z: 0} to := matrix.Vec3{X: 0, Y: -10, Z: 0} hit := world.Raycast(from, to) if hit.HasHit { hitPoint := hit.Point hitNormal := hit.Normal // Process hit result _ = hitPoint _ = hitNormal } return world } ``` -------------------------------- ### Load Assets with Go Source: https://context7.com/kaijuengine/kaiju/llms.txt Demonstrates loading various assets including textures, meshes, fonts, materials, and shaders using the Host's cache systems. It handles potential errors during the loading process and ensures assets are available for use. Dependencies include the 'kaiju/engine' and 'kaiju/rendering' packages. ```go package main import ( "kaiju/engine" "kaiju/rendering" ) func loadAssets(host *engine.Host) error { // Texture loading textureCache := host.TextureCache() texture, err := textureCache.Texture("texture-guid-abc123") if err != nil { return err } // Mesh loading (GLTF format) meshCache := host.MeshCache() mesh, err := meshCache.Mesh("mesh-guid-def456") if err != nil { return err } // Font loading fontCache := host.FontCache() font, err := fontCache.Font("font-guid-ghi789") if err != nil { return err } // Material loading materialCache := host.MaterialCache() material, err := materialCache.Material("material-guid-jkl012") if err != nil { return err } // Shader loading shaderCache := host.ShaderCache() shader, err := shaderCache.Shader("shader-guid-mno345") if err != nil { return err } // Use loaded assets _ = texture _ = mesh _ = font _ = material _ = shader return nil } ``` -------------------------------- ### Go Template for Dynamic Data Rendering Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/editor_embedded_content/editor_content/editor/ui/overlay/table_of_contents.go.html This Go template snippet iterates over a map named 'Entries' to dynamically render key-value pairs. It displays the key and the corresponding 'Id' for each entry. This is likely used to populate lists or tables with data from the application's backend. ```gohtml Key Id {{range $k, $v := .Entries}} {{$k}} {{$v.Id}} X {{end}} ``` -------------------------------- ### Generate MSDF Fonts using Go CLI Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/building_fonts.md This command initiates the process of generating MSDF font assets from TTF files. It requires the msdf-atlas-gen tool to be set up and the font's character set defined in charset.txt. The output includes .bin and .png files, which are then copied to the project's font directory. ```bash go run ./generators/msdf/main.go OpenSans ``` -------------------------------- ### Compile Kaiju for Android Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/build_from_source.md A Go command to initiate the Android build process for the Kaiju engine. This is typically run from the engine's root folder and utilizes a generator script located within the project structure. ```shell go run src/generators/engine_builds/engine_builds_android/main.go ``` -------------------------------- ### Implement Init Interface for Data Binding Structures Source: https://github.com/kaijuengine/kaiju/blob/master/docs/programming/data_binding.md Structures intended for data binding in the Kaiju engine must implement the `Init` interface. This interface requires a function that accepts an `engine.Entity` and an `engine.Host` pointer, enabling the engine to initialize the structure within its context. ```go func Init(e *engine.Entity, host *engine.Host) ``` -------------------------------- ### Display Confirmation Popup (Go) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/prompt_popup.md Displays a confirmation dialog with custom 'OK' and 'Cancel' buttons. It returns a boolean channel that resolves to `true` if the 'OK' button is clicked, and `false` otherwise. This function is useful for scenarios requiring user confirmation before proceeding with an action. ```go ok := <-alert.New("Save Changes", "You are changing stages, any unsaved changes will be lost. Are you sure you wish to continue?", "Yes", "No", host) // ok will be true if the "Yes" (ok) button was clicked ``` -------------------------------- ### Create POD Entity Data Structure (JavaScript) Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/editor_embedded_content/editor_content/editor/ui/overlay/create_entity_data.go.html This snippet demonstrates how to create a Plain Old Data (POD) entity data structure. It is intended to be bound to entities within the Kaiju engine. No specific dependencies are mentioned, and the output is a JavaScript object. ```javascript function createEntityData() { // Placeholder for POD entity data structure return {}; } ``` -------------------------------- ### Kaiju Engine Templating - Root Section and Save Action Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/editor_embedded_content/editor_content/editor/ui/workspace/shading_workspace_data_input.go.html Defines the main template for a Kaiju Engine object. It displays the object's Name and then uses the recursive 'section' template to render its structure. Includes a 'Save' action and a tooltip. ```gohtml {{.Name}} ========= {{template "section" .}} Save tooltip ``` -------------------------------- ### Display Input Popup (Go) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/engine_developers/prompt_popup.md Displays a popup with a text input field, a primary action button (e.g., 'Save'), and a cancel button. It returns a string channel. If the cancel button is clicked, the channel resolves to an empty string. Otherwise, it resolves to the text entered by the user. This is ideal for gathering user-provided information. ```go name := <-alert.NewInput("Stage Name", "Name of stage...", "", "Save", "Cancel", host) // The result will be "" if cancel was clicked, otherwise it's the input text ``` -------------------------------- ### Configure Concurrent Update Callbacks and Scheduling Source: https://context7.com/kaijuengine/kaiju/llms.txt Sets up various update callbacks that execute at different stages of the engine's frame loop, including main thread updates, late updates, and concurrent UI updates. It also demonstrates scheduling functions to run on the main thread, after a specific number of frames, or after a duration of time. Frame-related information like frame count and time is also accessible. ```go package main import ( "kaiju/engine" time "time" ) func setupUpdateCallbacks(host *engine.Host) { // Register main thread update host.Updater.Add(func(deltaTime float64) { // Called every frame on main thread // Safe for all engine operations }) // Register late update (after all updates) host.LateUpdater.Add(func(deltaTime float64) { // Called after all standard updates // Good for camera following, final transforms }) // Register UI update (concurrent) host.UIUpdater.Add(func(deltaTime float64) { // Called concurrently with other UI updates // Use for UI-specific logic }) // Run function on main thread host.RunOnMainThread(func() { // Executed on main thread in next frame entity := host.NewEntity() // Safe to manipulate engine state here _ = entity }) // Run after specific number of frames host.RunAfterFrames(60, func() { // Executed after 60 frames }) // Run after time duration host.RunAfterTime(5*time.Second, func() { // Executed after 5 seconds }) // Access frame information currentFrame := host.Frame() frameTime := host.FrameTime() _ = currentFrame _ = frameTime } ``` -------------------------------- ### Add Shared Library for the Project Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/project_templates/android/app/src/main/cpp/CMakeLists.txt Creates and names the main shared library for the project using the ${CMAKE_PROJECT_NAME} variable. It lists the C/C++ source files for the library and links it with other necessary libraries. ```cmake add_library(${CMAKE_PROJECT_NAME} SHARED # List C/C++ source files with relative paths to this CMakeLists.txt. native-lib.cpp) target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}) target_link_libraries(${CMAKE_PROJECT_NAME} # List libraries link to the target library kaiju_android app-glue android log) ``` -------------------------------- ### Manage Entities and Hierarchy in Go with Kaiju Engine Source: https://context7.com/kaijuengine/kaiju/llms.txt Demonstrates creating, managing, and manipulating entities within the Kaiju engine's entity-component system. It covers setting transform properties, establishing parent-child relationships, storing/retrieving custom data, handling lifecycle events, and destroying entities. ```go package main import ( "kaiju/engine" "kaiju/matrix" ) func createEntityHierarchy(host *engine.Host) { // Create root entity rootEntity := engine.NewEntity() rootEntity.SetName("RootObject") rootEntity.Transform.SetPosition(0, 0, 0) rootEntity.Transform.SetRotation(matrix.QuaternionIdentity()) rootEntity.Transform.SetScale(1, 1, 1) host.AddEntity(rootEntity) // Create child entity childEntity := engine.NewEntity() childEntity.SetName("ChildObject") childEntity.Transform.SetPosition(5, 0, 0) childEntity.SetParent(rootEntity) // Store custom data on entity childEntity.SetData("health", 100) childEntity.SetData("velocity", matrix.Vec3{X: 1, Y: 0, Z: 0}) // Retrieve data health := childEntity.Data("health").(int) velocity := childEntity.Data("velocity").(matrix.Vec3) // Entity lifecycle events childEntity.OnActivate.Add(func() { // Called when entity is activated }) childEntity.OnDeactivate.Add(func() { // Called when entity is deactivated }) childEntity.OnDestroy.Add(func() { // Called when entity is destroyed }) // Activate/deactivate entities childEntity.Deactivate() // Entity and children become inactive childEntity.Activate() // Entity and children become active // Destroy entity childEntity.Destroy() // Find entity by ID foundEntity := host.FindEntity("my-unique-id") } ``` -------------------------------- ### Kaiju Engine Templating - Any Type Definition Source: https://github.com/kaijuengine/kaiju/blob/master/src/editor/editor_embedded_content/editor_content/editor/ui/workspace/shading_workspace_data_input.go.html Defines a generic template for rendering any type not explicitly handled by other templates. It displays the DisplayName. ```gohtml {{define "any"}} {{.DisplayName}}: {{end}} ``` -------------------------------- ### Apply Struct Tag Decorators for Editor Interaction (Go) Source: https://github.com/kaijuengine/kaiju/blob/master/docs/programming/data_binding.md Struct tags in Go can be used to provide metadata to the Kaiju editor, influencing how fields are displayed and interacted with. Common decorators include `clamp` for value range constraints and `default` for initial values. ```go type SomeEntityDataModule struct { Speed float32 `clamp:"3,1,30"` MaxCount int `default:"15"` MaxHeight float32 `default:"3.14"` IsPrimary bool `default:"false"` } ``` -------------------------------- ### HTML Structure for Kaiju UI Source: https://github.com/kaijuengine/kaiju/blob/master/docs/ui/writing.md Defines the basic HTML structure for a UI element in Kaiju Engine, including linking a CSS stylesheet and using Go template syntax to dynamically display a list of entity names. This HTML file is typically placed within the 'content/ui' directory. ```html