Logo
latest

Quickstart

  • Table of Contents
  • What is RAMSES
  • Obtaining the source code
  • Build instructions
  • License

Building

  • Cloning
  • Build requirements
  • Build options
  • Project version
  • Building on Windows
  • Building on Linux natively

Core API

  • Ramses Core overview
  • Advanced concepts
  • List of all examples

Logic API

  • Overview
  • Logic node creation
  • Object lifecycle
  • Creating links between nodes
  • Linking logic nodes to Ramses scene objects
  • Dynamic sorting of content
  • Animations
  • Error handling
  • Iterating over object collections
  • Security and memory safety
  • Performance
  • List of all logic examples
    • Minimal logic example
    • Example with primitive properties
    • Example with structured properties
    • Example with indexed (vector, array) properties
    • Handling compilation errors
    • Handling runtime errors
    • Example with Ramses
    • Save/load from file example
    • Links example
    • Animation example
    • Dynamic animation (animateTo) example
    • Modules example
    • Globals example
    • Interfaces example
    • Anchor points example
    • Render order example
    • SkinBinding example
    • MeshNodeBinding example
    • RenderBufferBinding example

Lua Syntax

  • Quick start
  • Basics of Lua
  • Declaring an interface() and a run() function
  • Global variables and the init() function
  • Custom functions
  • Environments and isolation
  • Indexing inside Lua
  • Errors in scripts
  • Using Lua modules
  • Additional Lua syntax specifics

Viewer

  • ramses-viewer
  • Lua configuration API

Performance and Profiling

  • Performance and Profiling
  • Inspecting the contents of your scene and optimizing it
  • Looking at the Ramses periodic performance logs
  • Using specialized tools

Class Index

  • Class Index

ChangeLog

  • Ramses Changelog

Developers

  • Understand RAMSES Logic architecture and design
  • Developer guidelines
  • Contributing
  • Pull requests
  • Commit guidelines
  • Review
  • Code style
  • Continuous integration
  • Branching
ramses
  • Overview
  • Links example
  • Edit on GitHub

Links example

/**
 * This example demonstrates how to link properties of different scripts to
 * create a network of logic nodes executed in a specific order
 */

int main()
{
    ramses::RamsesFramework framework{ ramses::RamsesFrameworkConfig{ ramses::EFeatureLevel_Latest } };
    ramses::RamsesClient* client = framework.createClient("client");
    ramses::Scene* scene = client->createScene(ramses::sceneId_t{ 123u });
    ramses::LogicEngine& logicEngine{ *scene->createLogicEngine() };

    // Create a simple script which increments an integer and prints the result
    const std::string_view scriptSrc = R"(
        function interface(IN,OUT)
            IN.script_name = Type:String()

            IN.number = Type:Int32()
            OUT.incremented_number = Type:Int32()
        end

        function run(IN,OUT)
            -- add 1 to the input and assign to the output
            OUT.incremented_number = IN.number + 1

            -- Print the name of the script currently being executed and the result
            print("Executing: " .. IN.script_name .. ". Result is: " .. OUT.incremented_number)
        end
    )";

    // Enable the Lua base library so the print() function will be available in the script
    ramses::LuaConfig config;
    config.addStandardModuleDependency(ramses::EStandardModule::Base);

    // Create two scripts using the Lua source code from above
    ramses::LuaScript* script1 = logicEngine.createLuaScript(scriptSrc, config);
    ramses::LuaScript* script2 = logicEngine.createLuaScript(scriptSrc, config);

    // Assign the scripts their names so that we can see their execution order
    script1->getInputs()->getChild("script_name")->set<std::string>("script 1");
    script2->getInputs()->getChild("script_name")->set<std::string>("script 2");

    // Scripts will be executed at arbitrary order (they are not linked yet!)
    logicEngine.update();

    // Both scripts will produce 1 as a result (add 1 to 0 -> results to 1)
    assert(1 == *script1->getOutputs()->getChild("incremented_number")->get<int32_t>());
    assert(1 == *script2->getOutputs()->getChild("incremented_number")->get<int32_t>());

    // Create a link between the output property (of script1) and the input property (of script2)
    logicEngine.link(
        *script1->getOutputs()->getChild("incremented_number"),     // Get data from this property...
        *script2->getInputs()->getChild("number"));                 // ... and provide it to this property

    // Let's initialize script1's input with a new number
    script1->getInputs()->getChild("number")->set<int32_t>(42);

    // Above link will cause script1 to be executed first now, its output's data
    // provided to the input of script2, then script2 will be executed
    logicEngine.update();

    // New results are different, based on the new input value of script1 and the link between the scripts
    assert(43 == *script1->getOutputs()->getChild("incremented_number")->get<int32_t>());
    assert(44 == *script2->getOutputs()->getChild("incremented_number")->get<int32_t>());
Previous Next

© Copyright 2020, BMW AG. Revision 068163a6.

Built with Sphinx using a theme provided by Read the Docs.