Decorators, Addons, and Extensions #1283
JSideris
started this conversation in
Game Engine Tech Blog
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Overview
Extensions are the newest way to extend the functionality of a
GameObject
. The other supported ways are using decorators and augmentations (addons).Extensions differ from addons and decorators. Decorators permanently update the class hierarchy of a class. This is useful for adding functionality that will exist on both client and server for all instances of the class. For instance, the
@ownable
decorator contains everything it means to be owned and controlled by aController
. In general, a single decorator is designed to be generic as to be able to add functionality to different types ofGameObject
s. Decorators modify the definition of a class, and therefore apply to both client and server.Addons augment a specific instance of a class with new behavior. This is useful for adding functionality at runtime. For instance, a player could pick up a powerup that grants some ability (e.g. night vision). In general, addons are designed for specific inherited types of
GameObject
. Addons augment objects on the client and the server.An extension provides functionality that overlaps greatly with decorators, but rather than changing the definition of a class, it augments each instance of the class with new behavior. To that end, extensions combine some of the functionality of decorators and addons. The advantage over decorators is in modding, or in situations where the behavior of an object is different on the client from the server (for instance, drawing and sound effects). The advantage of using extensions over addons is in the fact that they are completely managed by the game engine. For instance, to add a draw method to an Alien class client-side, using addons it would be possible to intercept an
onAddGameObject
event, augment the new object, and manage the lifecycle of the drawing for each Alien. But with extensions, the extension for drawing an Alien is registered once in the client-side version of the code and the extension is automatically instantiated for each AlienGameObject
that is created. Cleanup is also automatic.Detailed Comparison
Beta Was this translation helpful? Give feedback.
All reactions