Skip to content

Objects

Roger Levy edited this page May 3, 2018 · 8 revisions

RAMEN distinguishes regular data structures from something we call "objects". It could be helpful to refer to them as RAMEN objects when needed to avoid confusion.

All objects' structures are a union of several datatypes, housed within slots of a predetermined size.

The following are all good uses for RAMEN objects:

  • Game objects (a.k.a. entities, actors, displayobjects ...)
  • Particles
  • GUI objects
  • Roundrobin tasks
  • Tree nodes
  • Sound channels

One advantage to using a union is that all objects are intrinsically polymorphic, making your traditional class hierarchy unnecessary. Just instantiate an object, set its properties appropriately and you're off. Objects can more freely transform into each other and performance is very good. The tradeoff is memory use, but 4GB is standard for computers and game consoles now. RAMEN objects are never going to be your memory bottleneck.

The regular word for declaring new object properties is simply field ( size -- <name> ). There is also a shorthand for cell field called var. These properties are "indirectly addressed". Instead of accessing properties of an object on the stack, they use a pointer called me. This setup is more convenient in a scripting situation and relieves you of a lot of stack juggling.

You can also declare "external properties", with xfield and xvar. These use T as the base address.

Should you need to access indirect properties and other me-dependent words in relation to T, there is -> ( obj -- <word> ).

You can change the value of me with as ( obj -- ). You can also save and restore it with { and }.

The next field offset is kept in a variable called used.

Common fields

Fields Type Description
en flag Marks the object as active. If off, the object should be considered "free".
ola adr Object List address. Internal.
x y fixed Object position vector
vx vy fixed Object velocity vector
hidden flag Marks object as hidden
drw beha code adr Define drawing code and game logic.

Static declaration and allocation

Dynamic declaration and allocation

Itteration

Defining behavior and graphics

Roles