# Palomino - Lua Scripts

©2004,2009 Jim E. Brooks http://www.palomino3d.org

- Index
- Overview
- C++ and Lua Partitioning
- Execution Flow
- List of Lua Scripts

- lua module
- game module

## Overview

[2008/09]

See also lua module.

The simulator is implemented as a mixture of C++ and Lua code. The core of the simulator is written in C++. The high-level (missions, game logic, etc) is written in Lua. In client/server terms, C++ is the server, while Lua is the client.

Partitioning of C++ and Lua varies by area. Lua is fully responsible for mission setup and defining a scene. By contrast, game logic is a mixture of Lua and C++.

## C++ and Lua Partitioning

[2008/10]

Summary of functionality partitioned across C++ and Lua:
Only the C++ core is independent. All Lua code depends on the C++ core in one way or another.

C++:

- simulator core

Lua:

- scene construction
- keyboard handling
- missions
- updating HUD

Mixture of C++ and Lua:

- game logic

Of the Lua functionality, the most complex is the game logic.

## Execution Flow

[2008/09]

- C++ transfers execution to startup.lua.

- scene.lua builds the scene-graph
- mission.lua calls a specific mission_*.lua script
- The player's Craft is created and placed at a location
- If appropriate, aircraft carrier is populated
- Friendly aircraft are animated using Replay mechanism

- Every timer-tick, C++ calls tick.lua.

- polls keyboard (C++ KeyboardDevice)
- polls joystick button (C++ polls axises)
- updates HUD (C++ does tiny bit of HUD updating)
- updates sound (stall warning etc)
- initiates animation/cut-scenes (rescue helicopter, etc)
- processes commands from queue (enqueued by GUI)

## List of Lua Scripts

[2008/09]

- actors.lua

Defines the Player and Friends.

- cmd.lua

Dequeue and execute commands from the simulator's command queue.

- defs.lua

Definitions, constants.

- events.lua

Lua classes can define events to be broadcast to registered listeners.

- game.lua

Game class. C++ has a Game class too that implements much of the game logic.

- gfx.lua

Graphics-related classes (Vec3, RGBA etc) and functions.

- hud.lua

Lua is responsible for updating the "slow HUD" (low-frequency tick). For example, Lua is what causes "STALL" and "[PAUSED]" to be displayed. The C++ classes Hud and Game are involved in rendering the HUD.

- keyboard.lua

Lua responds to keyboard input (C++ responds to joystick input).

- lib.lua

General Lua functions.

- mission*.lua

Scripts for specific missions.

- replay.lua

Wraps underlying C++ Replay class.

- scene*.lua

Defines the scene graph. scene.lua has a function that populates the scene-graph by reading a Lua table from a specific scene_*.lua script.

- sim.lua

Bindings to many exported C++ classes. Some Lua classes extend the functionality of their underlying C++ class.

- startup.lua

The main script.

- tick.lua

Lua scripting is timer-driven.

- view.lua

Classes such as SuperView, ChaseView. View/window functions.

Last modified: Sat Nov 7 14:43:30 CST 2009