CEG:Operators: Difference between revisions

From Spring
Jump to navigationJump to search
No edit summary
No edit summary
Line 8: Line 8:


== The Buffer ==
== The Buffer ==
CEG provides you with a buffer in which you can store numbers using the yank (y) operator. This buffer can store 16 values, numbered 0 to 15.
CEG provides you with a buffer in which you can store numbers using the yank ('y') operator. This buffer can store 16 values, numbered 0 to 15.


== Operators ==
== Operators ==
Line 23: Line 23:
Suggested use: Keeping explosions from looking too "perfect", making explosions look different every time.
Suggested use: Keeping explosions from looking too "perfect", making explosions look different every time.


=== Damage (d) ===
=== Damage ('d') ===
Multiplies the operand by damage.
Multiplies the operand by damage.


=== Sawtooth (m) ===
=== Sawtooth ('m') ===
Calculates the floating-point remainder of the operand.
Calculates the floating-point remainder of the operand.


=== Discrete (k) ===
=== Discrete ('k') ===
Calculates the floor of the operand.
Calculates the floor of the operand.


=== Sine (s) ===
=== Sine ('s') ===
Calculates the sine of the operand.
Calculates the sine of the operand.


=== Yank (y) ===
=== Yank ('y') ===
Saves the running result into buffer[operand], and resets the running result to zero.
Saves the running result into buffer[operand], and resets the running result to zero.


=== Multiply (x) ===
=== Multiply ('x') ===
Multiplies the running result by buffer[operand].
Multiplies the running result by buffer[operand].


=== Add Buffer (a) ===
=== Add Buffer ('a') ===
Adds buffer[operand] to the running result.
Adds buffer[operand] to the running result.


=== Power (p) ===
=== Power ('p') ===
Raises the running result to the operandth power
Raises the running result to the operandth power


=== Power Buffer (q) ===
=== Power Buffer ('q') ===
Raises the running result to the buffer[operand]th power.
Raises the running result to the buffer[operand]th power.


=== Add ( ) ===
=== Add (default) ===
Adds the operand to the running result.
Adds the operand to the running result. This operator is used if no other operator is given.


== Example ==
== Example ==

Revision as of 00:39, 30 December 2008

Source: https://spring.clan-sy.com/svn/spring/trunk/rts/Sim/Projectiles/ExplosionGenerator.cpp

Introduction

You are not limited to using fixed numbers in CEGs for positions, speeds, and so forth. Instead, you can use operators to change the CEG based on a variety of things.

Syntax

Operators are read left to right. The operand is always to the right of the operator. Spaces are ignored, except to separate numbers. A number with no operator defaults to addition.

The Buffer

CEG provides you with a buffer in which you can store numbers using the yank ('y') operator. This buffer can store 16 values, numbered 0 to 15.

Operators

These are listed in the format "Operator Name (operator)".

Index (i)

Multiplies the operand by the current count index. This index starts at 0 and increments every time the spawn is run, until the spawn has run a number of times equal to its count.

Suggested use: Spawning things in a line.

Rand (r)

Multiplies the operand by a random float between 0 and 1.

Suggested use: Keeping explosions from looking too "perfect", making explosions look different every time.

Damage ('d')

Multiplies the operand by damage.

Sawtooth ('m')

Calculates the floating-point remainder of the operand.

Discrete ('k')

Calculates the floor of the operand.

Sine ('s')

Calculates the sine of the operand.

Yank ('y')

Saves the running result into buffer[operand], and resets the running result to zero.

Multiply ('x')

Multiplies the running result by buffer[operand].

Add Buffer ('a')

Adds buffer[operand] to the running result.

Power ('p')

Raises the running result to the operandth power

Power Buffer ('q')

Raises the running result to the buffer[operand]th power.

Add (default)

Adds the operand to the running result. This operator is used if no other operator is given.

Example

i0.03125y0 -0.2x0x0

This multiplies the index by 0.03125 and saves it to buffer[0]. It then multiplies -0.2 by buffer[0] twice. The result is then -0.2 (i * 0.03125)^2.