-
Notifications
You must be signed in to change notification settings - Fork 61
Game Objects
All game relevant objects are described by a Controller
-class inside the logic/
-folder.
There are controllers for characters, visuals, items and other objects found in the game, which can be hooked to a vob using functions found in the Vob
/VobTypes
-Namespace.
Controllers are currently split into two main types: Logic-Controllers and Visual-Controllers.
The Controller
-class has a couple of methods and members you will want to learn to use:
-
virtual void onUpdate(float deltaTime)
- Called on every tick, if the object is in range of the player.
-
void setEntityTransform(const Math::Matrix& transform)
andMath::Matrix& getEntityTransform()
- Accessors to the underlaying entities transform-matrix
-
World::WorldInstance& m_World
- Reference to the world this object resides in
-
Handle::EntityHandle m_Entity
- Handle of the entity owning this controller
A logic-controller reacts to events from other controllers and manages the state of the vob. For example, there is the MobController
(Mob being an intractable object in the world of PiranhaBytes), which can describe a chest, a bench or something else that can be interacted with.
To create a vob owning one of these, you can find Functions inside the VobTypes
-Namespace.
Currently there are:
Type | Function |
---|---|
Character | WLD_InsertNPC |
Mob | createMob |
Item | createItem |
Furthermore, to access the functionality of a specific type of entity, you can cast an entity to a vob-type, by using:
Type | Function |
---|---|
Character | asNpcVob |
Mob | asMobVob |
Item | asItemVob |
Note that the resulting objects only hold the current memory addresses of the object! These are not safe to store somewhere for later access, as the memory allocator could move the objects around after an other entity got removed. ALWAYS re-get these after you added or removed an entity!
If you were to create an item, you'd have to do the following:
// Create the vob
Handle::EntityHandle e = VobTypes::createItem(world, "ItFo_Bacon");
VobTypes::ItemInformation item = VobTypes::asItemVob(world, e);
// Do something with it
item.itemController->pickUp(someCharacterHandle);
A visual-controller of the right kind is automatically created for an existing vob, by calling the following code:
Vob::VobInformation vob = Vob::asVob(world, someEntity);
Vob::setVisual(vob, "rock.3ds");
Where "rock.3ds"
can be any other content-file known by the game. For 3ds-files, a StaticMeshVisual
-Controller is created, for ASC
-files, a ModelVisual
-Controller is created.
The visual-controllers job is, to create sub-entities, containing actual rendering-data, which are then attached to the main entity.