Module Interp_types

module Interp_types: sig .. end
Types used in Interp.


Types used in Interp.
type position = float * float 
Guess what. It's (x, y).
type 'a table = ('a Bulletml.Syntax.id * 'a) list 
Environment for indirect calls (actionRef, etc).
type 'a linear_map = {
   frame_start : int;
   frame_end : int;
   val_start : 'a;
   val_end : 'a;
}
Description of a phenomenon that grows in a linear (well, affine) manner:


type opcode = 
| OpRepeatE of Bulletml.Syntax.expr * Bulletml.Syntax.action (*Repeat times the same Syntax.action*)
| OpWaitE of Bulletml.Syntax.expr (*Wait frames (unevaluated form)*)
| OpWaitN of int (*Wait frames (evaluated form)*)
| OpFire of Bulletml.Syntax.fire (*Fork execution by creating a new Interp_types.obj*)
| OpSpdE of Bulletml.Syntax.speed * Bulletml.Syntax.expr (*Change speed (unevaluated form)*)
| OpSpdN of float linear_map (*Change speed (evaluated form)*)
| OpDirE of Bulletml.Syntax.direction * Bulletml.Syntax.expr (*Change direction (unevaluated form)*)
| OpDirN of float linear_map (*Change direction (evaluated form)*)
| OpAccelE of Bulletml.Syntax.expr * Bulletml.Syntax.expr * Bulletml.Syntax.expr (*Accelerate (unevaluated form)*)
| OpAccelN of (float * float) linear_map (*Accelerate (unevaluated form): h, v, term*)
| OpVanish (*Let the bullet disappear*)
| OpCall of string * Bulletml.Syntax.expr list (*Call an indirect action with parameters*)
Abstract operation, specific to a particular Interp_types.obj.

Some cases have an both an unevaluated form and an evaluated form. This is because it is necessary to delay the evaluation as late as possible, and having a convenient form for computations in progress.

For example, OpWaitX. Evaluating Wait (Param 1) will create a OpWaitE (Param 1) (as is in the opcode list). When it is time to handle the opcode, it will be replaced by OpWaitN 3 (if we are in a context where $1 = 3). At the next frame it will be OpWaitN 2, etc.

Some cases have a "term", it is the number of frames in which the evolution will be done in the corresponding Interp_types.linear_map.

type obj = {
   prog : opcode list; (*Behaviour*)
   speed : float; (*In pixels/frame*)
   dir : float; (*In degrees. Top is 0, clockwise. Strange, I know*)
   children : obj list; (*Interp_types.objs created by this one*)
   pos : position; (*Where to draw it*)
   prev_dir : float; (*Used for interpreting DirSeq e*)
   prev_speed : float; (*Used for interpreting SpdSeq e*)
   vanished : bool; (*If true, don't draw this bullet*)
}
A movable (and drawable) entity.
type env = {
   frame : int; (*Frame number. Usually starts at 1, but only deltas are significant*)
   ship_pos : position; (*Where patterns can aim*)
   screen_w : int; (*Screen width in pixels*)
   screen_h : int; (*Screen height in pixels*)
   actions : Bulletml.Syntax.action table; (*Definitions of Syntax.actions*)
   bullets : Bulletml.Syntax.bullet table; (*Definitions of Syntax.bullets*)
   fires : Bulletml.Syntax.fire table; (*Definitions of Syntax.fires*)
}
Stuff that does not change during a frame and can be referred to during computations.
type init_params = {
   p_ship : position; (*Where is the ship. The one that is aimed*)
   p_enemy : position; (*Where is the enemy. The one that shoots*)
   p_screen_w : int; (*Screen width in pixels*)
   p_screen_h : int; (*Screen height in pixels*)
}
Initial parameters used to build an interpreter (see Interp.prepare and Interp.main_loop).
type ('g, 'l, 'r) interpreter = {
   make_global_ctx : unit -> 'g; (*(once) create the global, persistent context*)
   make_local_ctx : 'g -> 'l; (*(each frame) create a local context*)
   clear : 'l -> unit; (*clear frame*)
   draw : 'l -> obj -> unit; (*draw the object and its descendants*)
   run_cont : 'l -> (unit -> 'r) -> 'r; (*run the next frame. When in doubt, fun _ k -> k () works*)
}
Interpreter functions, used for Interp.main_loop.

It is polymorphic and quite parametric, to allow for different kind of interpreters.