Class Object

Game Object: This the main struct used in scenes to represent all sorts of entities.

class Object

Game Object: This the main struct used in scenes to represent all sorts of entities.

Objects can have multiple components attached to them, which provide functionality for running game logic and drawing things.

The exact makeup is set up in the editor, and loaded during a scene load. Dynamic creation at runtime is only possible through prefabs.

Public Functions

~Object()
inline void setFlag(uint16_t flag, bool enabled)
inline CompRef *getCompRefs() const

Returns pointer to the component reference table.

This is beyond the Object struct, but still in valid allocated memory.

Returns:

pointer

inline char *getCompData() const

Returns pointer to the component data buffer.

This is beyond the Object struct, but still in valid allocated memory.

Returns:

pointer

template<typename T>
inline T *getComponent() const

Returns the first component that matches the given type.

The type given must be component in the ‘P64::Comp’ namespace. If no component of the given type is found, nullptr is returned.

Template Parameters:

T – component type

Returns:

pointer to component or nullptr

template<typename T>
inline T *getComponent(uint32_t idx) const
inline bool isSelfEnabled() const

Check if the object itself is enabled (not considering parent/group state).

Returns:

true if enabled

inline bool isEnabled() const

Check if the object is enabled, considering parent/group state.

Returns:

true enabled

void setEnabled(bool isEnabled)

Changes the state of the object to be enabled or disabled.

Prefer this over changing flags directly, as components may need to be notified.

Parameters:

isEnabled – true to enable, false to disable

inline bool isSelfVisible() const

Check if the object itself is visible (not considering parent/group state).

Returns:

true if visible

inline bool isVisible() const

Check if the object is visible, considering parent/group state.

Returns:

true if visible

void setVisible(bool isVisible)

Changes the state of the object to be visible or hidden.

Prefer this over changing flags directly, so that children properly inherit visibility from parents.

Parameters:

isVisible – true to show, false to hide

inline bool hasChildren() const
void remove(bool keepChildren = false)

Removes the given object from the scene.

This is a shortcut for SceneManager::getCurrent().removeObject(obj); Note: deletion is deferred until the end of the frame.

Parameters:

keepChildren – if true, children will recursivly be removed, else children will remain with undefined/invalid group

template<typename F, typename SCENE = Scene>
inline void iterChildren(F &&f)

Iterates over all direct children of the object.

If you need nested iteration, call this function recursively.

Example:

obj.iterChildren(obj.id, [](Object* child) {
  child->setEnabled(true);
});

Note: This function is intentionally a template with a callback. Doing so generates the same ASM as a direct loops with an if+continue, whereas iterators or std::view performs worse. Template params are deduced automatically.

Parameters:
  • parentId – object id of the parent

  • f – callback function, takes Object* as argument

template<typename SCENE = Scene>
inline Object *getParent()

Returns the parent object of this object, or nullptr if none.

Returns:

pointer to parent object or nullptr

fm_vec3_t intoLocalSpace(const fm_vec3_t &p) const

Takes a world space position and converts it into the local space of this object.

Note that world-scace here assumes the object itself is sitting in it. If you somehow have transforms before it, you need to apply those yourself.

Parameters:

p – point in world space

Returns:

point in local space

fm_vec3_t outOfLocalSpace(const fm_vec3_t &p) const

Converts a point from local space of this object into world space.

This will effectively apply pos/rot/scale of a point in local space.

Parameters:

p – point in local space

Returns:

point in world space

Public Members

uint16_t id = {}
uint16_t group = {}
uint16_t flags = {}
uint16_t compCount = {0}
fm_quat_t rot = {}
fm_vec3_t pos = {}
fm_vec3_t scale = {}

Public Static Functions

static inline Scene &getScene()
struct CompRef

Public Members

uint8_t type = {}
uint8_t flags = {}
uint16_t offset = {}