default rule functions - mt-sane/lsystem GitHub Wiki

LSystem supplies as set of basic build functions that perform actions that are commonly needed. These functions are kept in the LSystem.Rule.B namespace (table).

Diag

Logs diagnostic infos using minetest.log.

Parameters

info

The l-system's build information for the rule.

The parameter has the following fields:

key

The key character that is assigned zu this rule.

global

The sytems global state.

state

The sytems local state.

pos

This Field is optional.
The default functions use this field manage the current position.

dir

This Field is optional.
The default functions use this field manage the current direction.

...

Other paramters passed to the rule

Globals

Fields used in the global state.

diag

If nil the function does nothing. All other values will be passed as first parameter to minetest.log.

diagLevels

nil or a table of log levels per rule key. If nil all rules are logged with level 1.

Log levels:

Value 0 - Nothing

No log output is generated.

Value 1 - Action

Logs the rule's key and the parameters that it's build function is called with. Default rules use LSystem.Rule.B.Diag for action log.

Value 2 - Info

Additionally log what the rule does. Default rules log when they change info fileds in the state. If they contain a random component the result will be logged too.

Value 3 - Verbose

Additionally log whatever else is deemed necessary. Default rules do not log anything verbose.

diagLevels.default

If nil the default log level is 1. Other values set the log level for all rules that don not have an explicit log level.

Locals

Fields used in the local state.

Not used.

Examples

No log

local sys = LSystem.New("A")

Log only the current axiom

local sys = LSystem.New("A", { diag = "action", diagLevels = { default = 0, } } )

Fine grained logging control

This will logg the current axiom. Infos for rule 'A' and basic action for rule 'B' all other rules don't get logged.

local sys = LSystem.New(
	"A", 
	{	diag = "action", 
		diagLevels = {	default = 0, A=2, B=1, }, 
	}
)

This will logg the current axiom. Verbose for rule 'A', info for rule 'B', rule 'C' does not produce diagnostis. All other rules get logged on basic action level.

local sys = LSystem.New(
	"A", 
	{	diag = "action", 
		diagLevels = {	A=3, B=2, C=0, }, 
	}
)

Move

Moves the current position into the current direction.

Parameters

info

The l-system's build information for the rule.
See Diag for details.

Globals

Fields used in the global state.

Not used.

Locals

Fields used in the local state.

pos

The current position.

The function simply adds dir to pos.

dir

The current direction.

Used to increment pos.

Examples

With k being the rule key, and pos at the center {x=0,y=0,z=0}

Current dir axiom resulting pos
west k {x=-1,y=0,z=0}
west kkk {x=-3,y=0,z=0}
noth k {x=0,y=0,z=1}
up kk {x=0,y=2,z=0}

Select

todo doc

Parameters

info

The l-system's build information for the rule.
See Diag for details.

Globals

Fields used in the global state. todo

Locals

Fields used in the local state. todo

Examples

todo

SetDir

Sets the current direction to a cardinal.

SetDir sets the dir field in the local state.

Parameters

info

The l-system's build information for the rule.
See Diag for details.

cardinal

This parameter selects the cardinal.
If nil this function does nothing.

key meaning vector
n north vector.new( 0, 0, 1)
s south vector.new( 0, 0,-1)
e east vector.new( 1, 0, 0)
w west vector.new(-1, 0, 0)
u up vector.new( 0, 1, 0)
d down vector.new( 0,-1, 0)
c center vector.new( 0, 0, 0)

Globals

Fields used in the global state.

Not used.

Locals

Fields used in the local state.

dir

The current position.
Will be set to the cardinal supplied in the parameter.

Examples

With k being the rule key.

axiom dir meaning
(w)k {x=-1,y=0,z=0} West
(n)k {x=0,y=0,z=1} North
(s)k {x=0,y=0,z=-1} South
(u)k {x=0,y=1,z=0} Up

Turn

Changes the current direction by 90°.

Turn changes the dir field in the local state.

Parameters

The parameter selects the turning direction.
Think of the turning direction as the movement keys in computer games.

w = pitch down, s = pitch up
a = yaw left, d = yaw right
q = roll left, e = roll right

Globals

Fields used in the global state. todo

Locals

Fields used in the local state. todo

Examples

With rule key = 'k'
current dir = north. ( info.state.dir = Lib.Cardinal.C.n ).

axiom resulting dir
(a)k west - Lib.Cardinal.C.w - (-1, 0, 0)
(d)k down - Lib.Cardinal.C.d - (0, -1, 0)
(d)k(e)k west - Lib.Cardinal.C.w - (-1, 0, 0)
⚠️ **GitHub.com Fallback** ⚠️