Skip to content

atl/script.hpp

Script classes: the C++ base classes for parts, tools, characters, worlds, games and terrain, split server/client classes, and the registration macros that expose them.

#define ATL_CLIENT_ONLY(_, name)

Rejects callbacks that belong to the other half.

#define ATL_CAT_(a, b)

Token pasting helpers.

#define ATL_CLASS(T)

Registers script class T under its own name, so Lua can ask for it with scriptClass("T"). Chain .method<&T::name>("name") to add custom methods.

#define ATL_SERVER_CLASS(Name, T)

Register T as the server / client half of split class Name (see ServerShapeClass). Each half may be in its own file. Chain .on<&T::handler>() and .method<>().

#define ATL_MOD(T)

Registers T as the mod-wide lifecycle object (see atl::Mod).

#define ATL_LIFECYCLE(name, params, args)

Exports the ATL_MOD lifecycle callbacks the loader calls.

What a tool's client_onEquippedUpdate returns: whether to block the primary / secondary input from reaching the game.

struct InputBlock
bool primary = false;
bool secondary = false;

Base of every script class. One C++ object exists per game script instance. Override the callbacks you need; only overridden callbacks exist on the game-side class. server_* callbacks run only on the server, client_* callbacks only on clients. Callbacks keep the game's names and must be public.

class ScriptClass
const Value &self() const;

The Lua script instance (self).

Returns const Value &

Network network() const;

self.network, for network calls between the server and client sides.

Returns Network

Value data() const;

self.data: the class's data from its JSON definition.

Returns Value

Storage storage() const;

[server] self.storage: data kept for the next time this object loads.

Returns Storage

template <class R = void, class... A> R callBase(StringView method, const A &...args) const;

Calls the Lua base class's version of method (see scriptClass's base argument). Does nothing and returns R() when the base has no such method.

Parameters

  • method (StringView)
  • args (const A &...)

Returns R

virtual void server_onCreate();

Called once when the object is created on the server / a client.

virtual void client_onCreate();

Called once when the object is created on the server / a client.

virtual void server_onDestroy();

Called when the object is destroyed on the server / a client.

virtual void client_onDestroy();

Called when the object is destroyed on the server / a client.

virtual void server_onRefresh();

Called after the script file is reloaded (dev mode).

virtual void client_onRefresh();

Called after the script file is reloaded (dev mode).

virtual void server_onFixedUpdate(double dt);

Called every physics tick (40 per second); dt is in seconds.

Parameters

  • dt (double)
virtual void client_onFixedUpdate(double dt);

Called every physics tick (40 per second); dt is in seconds.

Parameters

  • dt (double)
virtual void client_onUpdate(double dt);

[client] Called every frame.

Parameters

  • dt (double)
virtual void client_onClientDataUpdate(Value data, int channel);

[client] Called with data the server set with Network::setClientData.

Parameters

  • data (Value)
  • channel (int)
virtual void server_onReceiveUpdate();

[server] Called when the object receives a network update.

virtual void client_onLocalPlayerChangedWorld(World world);

[client] Called when the local player moves to another world.

Parameters

  • world (World)

A part or block script (scriptClass for a shape).

class ShapeClass : public ScriptClass
Shape shape() const;

The shape this script runs on.

Returns Shape

Interactable interactable() const;

The shape's interactable.

Returns Interactable

virtual void client_onInteract(Character character, bool pressed);

[client] Called when a player presses / releases the interact key on the part.

Parameters

  • character (Character)
  • pressed (bool)
virtual bool client_canInteract(Character character);

[client] Whether the part can be interacted with now; also the place to set the interaction text.

Parameters

  • character (Character)

Returns bool

virtual void client_onTinker(Character character, bool pressed);

[client] Called when a player presses / releases the tinker key on the part.

Parameters

  • character (Character)
  • pressed (bool)
virtual bool client_canTinker(Character character);

[client] Whether the part can be tinkered with now.

Parameters

  • character (Character)

Returns bool

virtual void client_onAction(int action, bool pressed);

[client] Called for movement and other input actions while a player is seated in the part.

Parameters

  • action (int)
  • pressed (bool)
virtual bool server_canErase();

Whether the part may be removed now.

Returns bool

virtual bool client_canErase();

Whether the part may be removed now.

Returns bool

virtual bool client_canCarry();

[client] Whether the part may be picked up.

Returns bool

virtual void server_onUnload();

[server] Called when the part unloads with its cell.

virtual void server_onSledgehammer();

[server] Called when the part is hit with a sledgehammer.

virtual void server_onProjectile(const ProjectileHit &hit);

Called when a projectile hits the part.

Parameters

  • hit (const ProjectileHit &)
virtual void client_onProjectile(const ProjectileHit &hit);

Called when a projectile hits the part.

Parameters

  • hit (const ProjectileHit &)
virtual void server_onMelee(const MeleeHit &hit);

Called when a melee attack hits the part.

Parameters

  • hit (const MeleeHit &)
virtual void client_onMelee(const MeleeHit &hit);

Called when a melee attack hits the part.

Parameters

  • hit (const MeleeHit &)
virtual void server_onExplosion(Vec3 center, int destructionLevel, int damage);

[server] Called when an explosion hits the part.

Parameters

  • center (Vec3)
  • destructionLevel (int)
  • damage (int)
virtual void server_onCollision(const CollisionHit &hit);

Called when the part collides with something.

Parameters

  • hit (const CollisionHit &)
virtual void client_onCollision(const CollisionHit &hit);

Called when the part collides with something.

Parameters

  • hit (const CollisionHit &)
virtual void client_onInteractThroughJoint(Character character, bool pressed, Joint joint);

[client] Called when interacting through a child joint (e.g. a bearing). pressed is always true.

Parameters

  • character (Character)
  • pressed (bool)
  • joint (Joint)
virtual bool client_canInteractThroughJoint(Character character, Joint joint);

[client] Whether interacting through a child joint is allowed.

Parameters

  • character (Character)
  • joint (Joint)

Returns bool

virtual int client_getAvailableParentConnectionCount(Connection flags);

[client] How many more parent / child connections of type flags are allowed (1+ allows one). Only called when the class's maxParentCount / maxChildCount field is 1 or more.

Parameters

  • flags (Connection)

Returns int

virtual int client_getAvailableChildConnectionCount(Connection flags);

[client] How many more parent / child connections of type flags are allowed (1+ allows one). Only called when the class's maxParentCount / maxChildCount field is 1 or more.

Parameters

  • flags (Connection)

Returns int

virtual void client_onChildJointRemoved(Joint joint);

[client] Called when a child joint is removed.

Parameters

  • joint (Joint)
virtual void server_onWorldChanged();

[server] Called when the part moves to another world.

A tool script.

class ToolClass : public ScriptClass
Tool tool() const;

The tool this script runs on.

Returns Tool

Player owner() const;

The player holding the tool.

Returns Player

bool isLocal() const;

True on the client of the player who owns the tool.

Returns bool

bool isEquipped() const;

True while the tool is equipped.

Returns bool

virtual void client_onEquip(bool animate);

[client] Called when the tool is equipped / unequipped.

Parameters

  • animate (bool)
virtual void client_onUnequip(bool animate);

[client] Called when the tool is equipped / unequipped.

Parameters

  • animate (bool)
virtual InputBlock client_onEquippedUpdate(int primaryState, int secondaryState);

[client] Called every frame while equipped with the primary and secondary input states. Return which inputs to block from the game.

Parameters

  • primaryState (int)
  • secondaryState (int)

Returns InputBlock

virtual bool client_onToggle();

[client] Called on the toggle / reload key; return true to consume the key.

Returns bool

virtual bool client_onReload();

[client] Called on the toggle / reload key; return true to consume the key.

Returns bool

virtual bool client_canEquip();

[client] Whether the tool can be equipped now.

Returns bool

A character script (scriptClass for a character type).

class CharacterClass : public ScriptClass
Character character() const;

The character this script runs on.

Returns Character

virtual void client_onGraphicsLoaded();

[client] Called when the character's graphics load / unload.

virtual void client_onGraphicsUnloaded();

[client] Called when the character's graphics load / unload.

virtual void client_onInteract(Character character, bool pressed);

[client] Called when a player interacts with the character.

Parameters

  • character (Character)
  • pressed (bool)
virtual bool client_canInteract(Character character);

[client] Whether the character can be interacted with now.

Parameters

  • character (Character)

Returns bool

virtual void client_onEvent(String event);

[client] Called for animation events.

Parameters

  • event (String)
virtual void client_onProjectile(const ProjectileHit &hit);

[client] Called when the character is hit by a projectile, a melee attack or a collision.

Parameters

  • hit (const ProjectileHit &)
virtual void client_onMelee(const MeleeHit &hit);

[client] Called when the character is hit by a projectile, a melee attack or a collision.

Parameters

  • hit (const MeleeHit &)
virtual void client_onCollision(const CollisionHit &hit);

[client] Called when the character is hit by a projectile, a melee attack or a collision.

Parameters

  • hit (const CollisionHit &)

A harvestable script (trees, rocks, crops...).

class HarvestableClass : public ScriptClass
Harvestable harvestable() const;

The harvestable this script runs on.

Returns Harvestable

virtual void server_onUnload();

[server] Called when the harvestable unloads with its cell.

virtual void client_onInteract(Character character, bool pressed);

[client] Called when a player interacts with the harvestable.

Parameters

  • character (Character)
  • pressed (bool)
virtual bool client_canInteract(Character character);

[client] Whether the harvestable can be interacted with now.

Parameters

  • character (Character)

Returns bool

virtual void client_onAction(int action, bool pressed);

[client] Called for input actions.

Parameters

  • action (int)
  • pressed (bool)
virtual bool server_canErase();

Whether the harvestable may be removed now.

Returns bool

virtual bool client_canErase();

Whether the harvestable may be removed now.

Returns bool

virtual void server_onRemoved(Player player);

[server] Called when a player removes the harvestable.

Parameters

  • player (Player)
virtual void server_onIgnite();

[server] Called when the harvestable catches fire.

virtual void server_onFloating();

[server] Called when the harvestable starts floating.

virtual void server_onProjectile(const ProjectileHit &hit);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const ProjectileHit &)
virtual void client_onProjectile(const ProjectileHit &hit);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const ProjectileHit &)
virtual void server_onMelee(const MeleeHit &hit);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const MeleeHit &)
virtual void client_onMelee(const MeleeHit &hit);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const MeleeHit &)
virtual void server_onExplosion(Vec3 center, int destructionLevel, int damage);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • center (Vec3)
  • destructionLevel (int)
  • damage (int)
virtual void server_onCollision(const CollisionHit &hit);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const CollisionHit &)
virtual void client_onCollision(const CollisionHit &hit);

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const CollisionHit &)

A unit script: the AI that controls a creature, server only.

class UnitClass : public ScriptClass
Unit unit() const;

The unit this script runs on.

Returns Unit

virtual void server_onUnitUpdate(double dt);

[server] Called every AI update.

Parameters

  • dt (double)
virtual void server_onProjectile(const ProjectileHit &hit);

[server] Called when the unit's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const ProjectileHit &)
virtual void server_onMelee(const MeleeHit &hit);

[server] Called when the unit's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const MeleeHit &)
virtual void server_onExplosion(Vec3 center, int destructionLevel, int damage);

[server] Called when the unit's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • center (Vec3)
  • destructionLevel (int)
  • damage (int)
virtual void server_onCollision(const CollisionHit &hit);

[server] Called when the unit's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const CollisionHit &)
virtual void server_onCollisionCrush();

[server] Called when the character is crushed.

virtual void server_onCharacterChangedColor(Color color);

[server] Called when the character's color changes.

Parameters

  • color (Color)

A player script (the game's player class).

class PlayerClass : public ScriptClass
Player player() const;

The player this script runs on.

Returns Player

virtual void client_onInteract(Character character, bool pressed);

[client] Called when the player interacts with a character.

Parameters

  • character (Character)
  • pressed (bool)
virtual void client_onCancel();

[client] Called on the cancel, skip dialog and reload keys.

virtual void client_onSkipDialog();

[client] Called on the cancel, skip dialog and reload keys.

virtual void client_onReload();

[client] Called on the cancel, skip dialog and reload keys.

virtual void server_onProjectile(const ProjectileHit &hit);

[server] Called when the player's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const ProjectileHit &)
virtual void server_onMelee(const MeleeHit &hit);

[server] Called when the player's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const MeleeHit &)
virtual void server_onExplosion(Vec3 center, int destructionLevel, int damage);

[server] Called when the player's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • center (Vec3)
  • destructionLevel (int)
  • damage (int)
virtual void server_onCollision(const CollisionHit &hit);

[server] Called when the player's character is hit by a projectile, melee attack, explosion or collision.

Parameters

  • hit (const CollisionHit &)
virtual void server_onCollisionCrush();

[server] Called when the player's character is crushed.

virtual void server_onShapeRemoved(Value items);

[server] Called with the items a removed shape gave the player.

Parameters

  • items (Value)
virtual void server_onInventoryChanges(Container inventory, Value changes);

[server] Called when the player's inventory changes.

Parameters

  • inventory (Container)
  • changes (Value)

A world script.

class WorldClass : public ScriptClass
World world() const;

The world this script runs on.

Returns World

virtual void server_onUnload();

[server] Called when the world unloads.

virtual void server_onTerrainCreated();

Called when the world's terrain is first created / loaded.

virtual void server_onTerrainLoaded();

Called when the world's terrain is first created / loaded.

virtual void client_onTerrainCreated();

Called when the world's terrain is first created / loaded.

virtual void client_onTerrainLoaded();

Called when the world's terrain is first created / loaded.

virtual void server_onCellCreated(int x, int y);

[server] Called when a cell is first created, loaded or unloaded.

Parameters

  • x (int)
  • y (int)
virtual void server_onCellLoaded(int x, int y);

[server] Called when a cell is first created, loaded or unloaded.

Parameters

  • x (int)
  • y (int)
virtual void server_onCellUnloaded(int x, int y);

[server] Called when a cell is first created, loaded or unloaded.

Parameters

  • x (int)
  • y (int)
virtual void client_onCellLoaded(int x, int y);

[client] Called when a cell is loaded / unloaded.

Parameters

  • x (int)
  • y (int)
virtual void client_onCellUnloaded(int x, int y);

[client] Called when a cell is loaded / unloaded.

Parameters

  • x (int)
  • y (int)
virtual void server_onInteractableCreated(Interactable i);

[server] Called when an interactable is created / destroyed in the world.

Parameters

  • i (Interactable)
virtual void server_onInteractableDestroyed(Interactable i);

[server] Called when an interactable is created / destroyed in the world.

Parameters

  • i (Interactable)
virtual void server_onProjectile(const WorldProjectileHit &hit);

Called when a projectile hits something in the world.

Parameters

  • hit (const WorldProjectileHit &)
virtual void client_onProjectile(const WorldProjectileHit &hit);

Called when a projectile hits something in the world.

Parameters

  • hit (const WorldProjectileHit &)
virtual void server_onProjectileFire(Vec3 position, Vec3 velocity, String projectile, Target shooter, Uuid uuid);

[server] Called when a projectile is fired in the world.

Parameters

  • position (Vec3)
  • velocity (Vec3)
  • projectile (String)
  • shooter (Target)
  • uuid (Uuid)
virtual void server_onMelee(const WorldMeleeHit &hit);

[server] Called when a melee attack hits something in the world.

Parameters

  • hit (const WorldMeleeHit &)
virtual void server_onExplosion(Vec3 center, int destructionLevel, int damage);

[server] Called when an explosion happens in the world.

Parameters

  • center (Vec3)
  • destructionLevel (int)
  • damage (int)
virtual void server_onCollision(const WorldCollision &hit);

Called on collisions in the world.

Parameters

  • hit (const WorldCollision &)
virtual void client_onCollision(const WorldCollision &hit);

Called on collisions in the world.

Parameters

  • hit (const WorldCollision &)
virtual void server_onVoxelDestruction(Value densityLoss, Value positions);

[server] Voxels removed / added by a player or creation: per-material density tables and positions.

Parameters

  • densityLoss (Value)
  • positions (Value)
virtual void server_onVoxelConstruction(Value densityGain, Value positions);

[server] Voxels removed / added by a player or creation: per-material density tables and positions.

Parameters

  • densityGain (Value)
  • positions (Value)
virtual void server_onMining(Vector<MineSpawn> spawns);

[server] Mining loot to spawn (see World::setMiningConfig).

Parameters

  • spawns (Vector<MineSpawn>)

A scriptable object script: a script with no body in the world.

class ScriptableObjectClass : public ScriptClass
ScriptableObject scriptableObject() const;

The scriptable object this script runs on.

Returns ScriptableObject

Value params() const;

The params it was created with.

Returns Value

virtual void server_onUnload();

[server] Called when the object unloads.

A scriptable object that exists on one client only (clientScriptableObjects::create).

class ClientScriptableObjectClass : public ScriptClass
ClientScriptableObject scriptableObject() const;

The scriptable object this script runs on.

Returns ClientScriptableObject

Value params() const;

The params it was created with.

Returns Value

A terrain generation script. The world class's terrainScript file runs one per generator thread, each in its own Lua state. Override what your terrain provides; the engine calls Init, then Load (or Create when Load returns false), then PrepareCell before each cell's Get* queries. The Lua side is sm.allthelanguages.terrainScript.

class TerrainScript : public ScriptClass
TerrainScript();

Constructing a TerrainScript makes it the current one.

static TerrainScript *&current();

The terrain script the loader forwards the engine's calls to.

Returns TerrainScript *&

virtual void Init(World world, int generatorIndex);

Called first, with the world and this generator thread's index.

Parameters

  • world (World)
  • generatorIndex (int)
virtual bool Load();

Loads saved terrain data. Return true if it was loaded; false makes the engine call Create.

Returns bool

virtual void Create(int xMin, int xMax, int yMin, int yMax, int seed, Value data);

Generates new terrain data for the given cell bounds and seed.

Parameters

  • xMin (int)
  • xMax (int)
  • yMin (int)
  • yMax (int)
  • seed (int)
  • data (Value)
virtual void PrepareCell(int cellX, int cellY, int loadFlags);

Called before a cell's queries. loadFlags bits: creations, surface, assets, nodes, harvestables, kinematics.

Parameters

  • cellX (int)
  • cellY (int)
  • loadFlags (int)
virtual String GetTilePath(Uuid tile);

The file path of a tile uuid.

Parameters

  • tile (Uuid)

Returns String

virtual double GetHeightAt(double x, double y, int lod);

Per-vertex queries in world coordinates: height, color and the 8 material weights. GetHeightAt and GetClutterIdxAt take a fast path that skips the handle table.

Parameters

  • x (double)
  • y (double)
  • lod (int)

Returns double

virtual TerrainColor GetColorAt(double x, double y, int lod);

Per-vertex queries in world coordinates: height, color and the 8 material weights. GetHeightAt and GetClutterIdxAt take a fast path that skips the handle table.

Parameters

  • x (double)
  • y (double)
  • lod (int)

Returns TerrainColor

virtual MaterialWeights GetMaterialAt(double x, double y, int lod);

Per-vertex queries in world coordinates: height, color and the 8 material weights. GetHeightAt and GetClutterIdxAt take a fast path that skips the handle table.

Parameters

  • x (double)
  • y (double)
  • lod (int)

Returns MaterialWeights

virtual int GetClutterIdxAt(double x, double y);

The clutter index at a point, or -1 for none.

Parameters

  • x (double)
  • y (double)

Returns int

virtual String GetEffectMaterialAt(double x, double y);

The effect material at a point (used for footstep and impact sounds).

Parameters

  • x (double)
  • y (double)

Returns String

virtual Value GetAssetsForCell(int cellX, int cellY, int lod);

Per-cell contents: arrays of the engine's terrain tables (sm::terrainTile returns them too).

Parameters

  • cellX (int)
  • cellY (int)
  • lod (int)

Returns Value

virtual Value GetNodesForCell(int cellX, int cellY);

Per-cell contents: arrays of the engine's terrain tables (sm::terrainTile returns them too).

Parameters

  • cellX (int)
  • cellY (int)

Returns Value

virtual Value GetCreationsForCell(int cellX, int cellY);

Per-cell contents: arrays of the engine's terrain tables (sm::terrainTile returns them too).

Parameters

  • cellX (int)
  • cellY (int)

Returns Value

virtual Value GetHarvestablesForCell(int cellX, int cellY, int lod);

Per-cell contents: arrays of the engine's terrain tables (sm::terrainTile returns them too).

Parameters

  • cellX (int)
  • cellY (int)
  • lod (int)

Returns Value

virtual Value GetKinematicsForCell(int cellX, int cellY, int lod);

Per-cell contents: arrays of the engine's terrain tables (sm::terrainTile returns them too).

Parameters

  • cellX (int)
  • cellY (int)
  • lod (int)

Returns Value

virtual Value GetDecalsForCell(int cellX, int cellY, int lod);

Per-cell contents: arrays of the engine's terrain tables (sm::terrainTile returns them too).

Parameters

  • cellX (int)
  • cellY (int)
  • lod (int)

Returns Value

virtual Vector<String> GetTagsForCell(int cellX, int cellY);

A cell's tags.

Parameters

  • cellX (int)
  • cellY (int)

Returns Vector<String>

virtual Value GetOceanCells();

Cells covered by ocean: {{cellX, cellY}, ...}.

Returns Value

virtual Value GetHLodCells();

High level-of-detail cells: {{x, y, z, effectName}, ...}.

Returns Value

virtual CullingZoneTree GetCullingZoneTree();

The culling zone tree for the whole terrain.

Returns CullingZoneTree

Culling portals and zones.

struct CullingZoneTree
Value portals, zones;

One parameter of a chat command: its type ("int", "string", ...), name, and whether it's optional.

struct ChatParam
const char *type;
const char *name;
bool optional = false;

The game script of a custom game (gameClass).

class GameClass : public ScriptClass
virtual void server_onPlayerJoined(Player player, bool isNewPlayer);

[server] Called when a player joins; isNewPlayer is true on their first visit.

Parameters

  • player (Player)
  • isNewPlayer (bool)
virtual void server_onPlayerLeft(Player player);

[server] Called when a player leaves.

Parameters

  • player (Player)
virtual void server_onReset();

[server] Called on the game's reset / restart.

virtual void server_onRestart();

[server] Called on the game's reset / restart.

virtual void server_onSaveLevel();

[server] Challenge mode: called when saving, testing and stopping a test of a level.

virtual void server_onTestLevel();

[server] Challenge mode: called when saving, testing and stopping a test of a level.

virtual void server_onStopTest();

[server] Challenge mode: called when saving, testing and stopping a test of a level.

virtual void server_onUnload();

[server] Called when the game unloads.

virtual void client_onLoadingScreenLifted();

[client] Called when the loading screen is lifted.

virtual void client_onLanguageChange(String language);

[client] Called when the game language changes.

Parameters

  • language (String)
virtual void client_onUnstuck();

[client] Called when the player uses /unstuck.

template <size_t N> void bindChatCommand(StringView command, const ChatParam (&params)[N], StringView help, atl::Function<void(Value args)> handler);

Binds a chat command to a lambda, e.g. bindChatCommand("/heal", {{"int", "amount", true}}, "Heals you", [](atl::Value args) { ... }). The handler receives the parsed parameters.

Parameters

  • command (StringView)
  • params (const ChatParam (&)[N])
  • help (StringView)
  • handler (atl::Function<void (Value)>)
void bindChatCommand(StringView command, StringView help, atl::Function<void(Value args)> handler);

Binds a chat command with no parameters.

Parameters

  • command (StringView)
  • help (StringView)
  • handler (atl::Function<void (Value)>)

The server half's network: sends to the client halves. Every method is server-only.

class ServerNetwork
explicit ServerNetwork(Network n);

Wraps self.network.

Parameters

  • n (Network)
template <class T = atl::Nil> void sendToClients(StringView method, const T &data = {}) const;

[server] Calls method(data) on every client half.

Parameters

  • method (StringView)
  • data (const T &)
template <class T = atl::Nil> void sendToClient(const Player &player, StringView method, const T &data = {}) const;

[server] Calls method(data) on one player's client half.

Parameters

  • player (const Player &)
  • method (StringView)
  • data (const T &)
template <class T> void setClientData(const T &data, int channel = 1) const;

[server] Syncs data to onClientDataUpdate on every client half, including players who join later.

Parameters

  • data (const T &)
  • channel (int)
template <class M> void send(const M &msg) const;

[server] Sends a typed message (a plain struct, see atl/wire.hpp) to every client half, where .on<&Client::handler>() receives it. Messages up to atl::wire::kMaxMessageBytes are split into packets as needed and reassembled on arrival.

Parameters

  • msg (const M &)
template <class M> void sendTo(const Player &player, const M &msg) const;

[server] Sends a typed message to one player's client half.

Parameters

  • player (const Player &)
  • msg (const M &)
template <class M> void sync(const M &state, int channel = 1) const;

[server] Like send, but kept: players who join later get the latest state too. One state per channel (1 or 2); a newer sync replaces the older one. A synced state must fit in one packet (atl::wire::kChunkBytes encoded); a bigger one is logged and not sent.

Parameters

  • state (const M &)
  • channel (int)

The client half's network: sends to the server half.

class ClientNetwork
explicit ClientNetwork(Network n);

Wraps self.network.

Parameters

  • n (Network)
template <class T = atl::Nil> void sendToServer(StringView method, const T &data = {}) const;

Calls method(data, sender) on the server half.

Parameters

  • method (StringView)
  • data (const T &)
template <class M> void send(const M &msg) const;

Sends a typed message to the server half's .on<>() handler (see ServerNetwork::send).

Parameters

  • msg (const M &)

Base of both halves of a split script class.

class ScriptSide
const Value &self() const;

The Lua script instance (self).

Returns const Value &

Value data() const;

self.data: the class's data from its JSON definition.

Returns Value

The server half of a split part. Callbacks drop the game's server_ prefix: onCreate is server_onCreate, and so on. See ShapeClass for what each callback does. Server only: every callback and method of this half runs on the server.

class ServerShapeClass : public ScriptSide
Shape shape() const;

The shape this script runs on.

Returns Shape

Interactable interactable() const;

The shape's interactable.

Returns Interactable

ServerNetwork network() const;

[server] The network, for sending to the client halves.

Returns ServerNetwork

Storage storage() const;

[server] Data kept for the next time this part loads.

Returns Storage

template <class T> void saveState(const T &state) const;

[server] Saves a plain struct to storage in the wire format (see atl/wire.hpp).

Parameters

  • state (const T &)
template <class T> atl::Optional<T> loadState() const;

[server] The struct saveState saved, or nothing. A save from a build with a different definition of T is ignored with a warning (fields are stored by position, so it can't be read safely) and the part starts fresh.

Returns atl::Optional<T>

virtual void onCreate();
virtual void onDestroy();
virtual void onRefresh();
virtual void onFixedUpdate(double dt);

Parameters

  • dt (double)
virtual void onReceiveUpdate();
virtual bool canErase();

Returns bool

virtual void onUnload();
virtual void onSledgehammer();
virtual void onProjectile(const ProjectileHit &hit);

Parameters

  • hit (const ProjectileHit &)
virtual void onMelee(const MeleeHit &hit);

Parameters

  • hit (const MeleeHit &)
virtual void onExplosion(Vec3 center, int destructionLevel, int damage);

Parameters

  • center (Vec3)
  • destructionLevel (int)
  • damage (int)
virtual void onCollision(const CollisionHit &hit);

Parameters

  • hit (const CollisionHit &)
virtual void onWorldChanged();

The client half of a split part. Callbacks drop the game's client_ prefix: onInteract is client_onInteract, and so on. See ShapeClass for what each callback does. Client only: every callback and method of this half runs on clients.

class ClientShapeClass : public ScriptSide
Shape shape() const;

The shape this script runs on.

Returns Shape

Interactable interactable() const;

The shape's interactable.

Returns Interactable

ClientNetwork network() const;

The network, for sending to the server half.

Returns ClientNetwork

virtual void onCreate();
virtual void onDestroy();
virtual void onRefresh();
virtual void onFixedUpdate(double dt);

Parameters

  • dt (double)
virtual void onUpdate(double dt);

Parameters

  • dt (double)
virtual void onClientDataUpdate(Value data, int channel);

Parameters

  • data (Value)
  • channel (int)
virtual void onLocalPlayerChangedWorld(World world);

Parameters

  • world (World)
virtual void onInteract(Character character, bool pressed);

Parameters

  • character (Character)
  • pressed (bool)
virtual bool canInteract(Character character);

Parameters

  • character (Character)

Returns bool

virtual void onTinker(Character character, bool pressed);

Parameters

  • character (Character)
  • pressed (bool)
virtual bool canTinker(Character character);

Parameters

  • character (Character)

Returns bool

virtual void onAction(int action, bool pressed);

Parameters

  • action (int)
  • pressed (bool)
virtual bool canErase();

Returns bool

virtual bool canCarry();

Returns bool

virtual void onProjectile(const ProjectileHit &hit);

Parameters

  • hit (const ProjectileHit &)
virtual void onMelee(const MeleeHit &hit);

Parameters

  • hit (const MeleeHit &)
virtual void onCollision(const CollisionHit &hit);

Parameters

  • hit (const CollisionHit &)
virtual void onInteractThroughJoint(Character character, bool pressed, Joint joint);

Called when interacting through a child joint (e.g. a bearing). pressed is always true.

Parameters

  • character (Character)
  • pressed (bool)
  • joint (Joint)
virtual bool canInteractThroughJoint(Character character, Joint joint);

Called when interacting through a child joint (e.g. a bearing). pressed is always true.

Parameters

  • character (Character)
  • joint (Joint)

Returns bool

virtual int getAvailableParentConnectionCount(Connection flags);

See ShapeClass::client_getAvailableParentConnectionCount.

Parameters

  • flags (Connection)

Returns int

virtual int getAvailableChildConnectionCount(Connection flags);

See ShapeClass::client_getAvailableParentConnectionCount.

Parameters

  • flags (Connection)

Returns int

virtual void onChildJointRemoved(Joint joint);

See ShapeClass::client_getAvailableParentConnectionCount.

Parameters

  • joint (Joint)

Lets the loader give script objects their Lua self.

struct ScriptAccess
static void setSelf(ScriptClass *s, Value self);

Parameters

  • s (ScriptClass *)
  • self (Value)
static void setSelf(ScriptSide *s, Value self);

Parameters

  • s (ScriptSide *)
  • self (Value)
template <class T> ClassDef<T> &defineClass(const char *name);

Registers T as script class name; used by ATL_CLASS.

Parameters

  • name (const char *)

Returns ClassDef<T> &

template <class T, detail::Side S> SideDef<T, S> &defineSide(const char *className, const char *typeName);

Registers T as a half of className; used by ATL_SERVER_CLASS / ATL_CLIENT_CLASS.

Parameters

  • className (const char *)
  • typeName (const char *)

Returns SideDef<T, S> &

Mod-wide lifecycle, independent of any part: derive from it and use ATL_MOD(MyMod). The loader's runtime tool (or a custom game's script) calls these once per tick.

class Mod
virtual void server_onCreate();

[server] Called once when the mod starts.

virtual void server_onFixedUpdate(double dt);

[server] Called every physics tick (40 per second); dt is in seconds.

Parameters

  • dt (double)
virtual void server_onDestroy();

[server] Called when the mod shuts down.

virtual void client_onCreate();

[client] Called once when the mod starts.

virtual void client_onFixedUpdate(double dt);

[client] Called every physics tick.

Parameters

  • dt (double)
virtual void client_onUpdate(double dt);

[client] Called every frame.

Parameters

  • dt (double)
virtual void client_onDestroy();

[client] Called when the mod shuts down.

The registration of a script class, returned by ATL_CLASS.

template <class T> class ClassDef
explicit ClassDef(const char *name);

Registers T under name with every engine callback it overrides.

Parameters

  • name (const char *)
template <auto M> ClassDef &method(const char *name);

Adds a custom method callable from Lua or the network (e.g. a sendToServer target), with its parameters converted from Lua by type: .method<&Lamp::sv_toggle>("sv_toggle").

Parameters

  • name (const char *)

Returns ClassDef<T> &

The registration of one half of a split class, returned by ATL_SERVER_CLASS / ATL_CLIENT_CLASS.

template <class T, detail::Side S> class SideDef
SideDef(const char *className, const char *typeName);

Registers T as the server or client half of className, with every callback it overrides.

Parameters

  • className (const char *)
  • typeName (const char *)
template <auto M> SideDef &method(const char *name);

Adds a network target or other custom method of this half. It only runs on this half's side: a call that arrives on the other side is logged and dropped.

Parameters

  • name (const char *)

Returns SideDef<T, S> &

template <auto H> SideDef &on();

Adds a typed-message handler: void handler(const Message &), where Message is a plain struct (server halves may take a second Player sender). The other half sends it with network().send(Message{...}), or sync().

Returns SideDef<T, S> &