Skip to content

Custom Behavior System #9

@Ratsch0k

Description

@Ratsch0k

In the current state, plugins must manually hook into Future Cop's behavior and actor system to implement custom behaviors.
Therefore, only one plugin is currently able to implement custom behaviors.

A new API should enable various plugins to define their own custom behaviors.
If possible, the API should safe, meaning, plugins should not be able to write or read memory outside of the memory allocated for the behavior.

API Suggestion

API name: behavior

register(behavior: Behavior)

Register a new behavior implemented as a class.

Behavior

A behavior class implement the behavior.
It has several methods that are called depending on specific game event.
For example, each frame, the onUpdate as well as the onRender methods will be called.

Behavior.getSize(): number

Get the size in bytes the behavior requires in memory as an integer.
While this method can return an arbitrary number (up to a maximum value),
Future Cop only differentiate between three behavior sizes:

  • TODO
    Therefore, a behavior always has access to one of these values.
    In case the method returns another value, it is rounded up to the next highest value.
    If the method returns a larger number than allowed, the cal to register() will fail.

Behavior.onInit(behaviorMemory, resources): BehaviorImpl

Called when a new actor with this behavior is initialized.
The first arguments is the memory region allocated for the behavior.
The behavior is allowed to read and write any address within this memory region.
The second argument contains references to the behavior data as stored in the mission file.

Note: This method serves as a constructor.

Behavior.onUpdate(self, gameSpeed)

Called for each instance of this behavior in a frame.

Behavior.onRender(self)

Called for each instance of this behavior in a frame.
This method is intended to be used for rendering.

Behavior.defaultHandler(self, arg1: number, arg2: number, arg3: number, arg4: number): number

Used as a callback function in case the behavior does not implement a specific method.

Etc.

There are several other types of actor event the behavior should be able to handle.
However, not all are fully uncovered and for the case of this suggestion, are not necessary to define.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions