Skip to content

libriscv/godot-sandbox

Repository files navigation

Godot Sandbox Build

Website | Code Examples | Discord | Web Demo


Safe, low-latency and fast sandbox for the Godot game engine.

GodotCon 2024 Presentation


Godot Sandbox allows Godot creators to implement safe modding support, such that they can pass around programs built by other players, knowing that restricted programs cannot harm other players. All Godot platforms are supported.

Installation

  • Automatic (Recommended): Download the plugin from the official Godot Asset Store using the AssetLib tab in Godot by searching for Godot Sandbox.

  • Manual: Download the latest github release and move only the addons folder into your project addons folder.

What can I do?

  • Modding API
    • You can implement a modding API for your game. This API can then be used by other players to extend your game, in a safe manner.
    • Put restrictions on resources, classes and objects to say what is accessible inside the sandbox.
  • Build once, run everywhere
    • You can publish your game for all mobile and console platforms, without paying a performance penalty. It's not going to be laggy on some platforms, which is a risk with solutions that are only fast when JIT is available.
  • High-performance
    • You can use this extension as a way to write higher performance code than GDScript permits, without having to resort to writing and maintaining a GDExtension for all platforms.
    • Enable binary translation to increase performance drastically. Also works on all platforms, but has to be embedded in the project or loaded as a DLL.
    • Yields 2.5-10x performance boost by default, 5-50x with binary translation
  • Publish and then make updates without re-publishing
    • You can distribute programs from a server to clients as part of the login sequence. You can use this to live-distribute changes like bugfixes or even new features to the game without having to re-publish the game itself. I do this in my game.

Usage

  • Write C++ or Rust in the Godot editor. An accompanying ELF resource is created. This resource can be loaded into any Sandbox instance on every platform without recompiling.

  • Create a new Sandbox and assign the ELF resource to it

    • Lifetime as any other node
    • Auto-completion from other GDScripts using @export
  • Or, directly assign an ELF script resource to a node

    • Shared sandbox among all instances with that script
    • Maximum scalability
    • Call functions and attach signals like GDScript

Examples

#include "api.hpp"
static int coins = 0;

PUBLIC Variant reset_game() {
	coins = 0;
	return Nil;
}

static void add_coin(const Node& player) {
	coins ++;
	Label coinlabel = player.get_node<Label>("../Texts/CoinLabel");
	coinlabel.set_text("You have collected "
		+ std::to_string(coins) + ((coins == 1) ? " coin" : " coins"));
}

PUBLIC Variant _on_body_entered(CharacterBody2D body) {
	if (body.get_name() != "Player")
		return Nil;

	get_node().queue_free(); // Remove the current coin!
	add_coin(body);
	return Nil;
}

Script of a simple Coin pickup, with a counter that updates a label in the outer tree. This script can be attached to the Coin in the editor just like GDScript.

You may also have a look at our demo repository for the Godot Sandbox. It's a tiny platformer that uses C++ and Rust.

Contributing

Requirements:

If you want to contribute to this repo, here are steps on how to build locally:

scons

Linting:

./scripts/clang-tidy.sh

Icons

The script icon is built from the Godot icons. It's using the same font as the Godot Logo, which is Lilita One. The icons are then imported into Godot once in order to check the box Scale With Editor in the import panel.

Module

If you want to build this as a module, simply download the sandbox.zip from releases, unzip it, and copy it to the modules folder in godot, build it:

scons module_sandbox_enabled=True disable_exceptions=False target=editor

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Alf-André Walla
Alf-André Walla

💻
K. S. Ernest (iFire) Lee
K. S. Ernest (iFire) Lee

💻 🔬 ⚠️
Dragos Daian
Dragos Daian

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Other Projects

The Jenova Framework has a built-in C++ compiler, and supports writing C++ in the Godot editor with hot-reloading support.