BEEP-8 Helper Lib 1.0.0
Loading...
Searching...
No Matches
cobj.h
Go to the documentation of this file.
1
35#pragma once
36#include <b8/type.h>
37#include <b8/assert.h>
38#include <b8/ppu.h>
39#include <b8/misc.h>
40#include <handle.h>
41#include <vector>
42
43typedef unsigned long HObj;
44class CObj{
45 friend void CObjHolder_Step( b8PpuCmd* cmd_ );
46
47 // id
48 private: u32 _id_cobj;
53 public: u32 GetId() const {
54 return _id_cobj;
55 }
56
57 // step
58 private: u32 _cnt_step_called = 0;
59 private: virtual void vOnStep() = 0;
60 private: void Step();
61
62 // touch
63 private: virtual void vOnTouch(){}
64 private: void Touch();
65
66 // draw
67 private: virtual void vOnDraw( b8PpuCmd* cmd_ ){
68 UNUSED(cmd_);
69 }
70 private: void Draw( b8PpuCmd* cmd_ );
71
72 // handle
73 private: HObj _hObj = HANDLE_NULL;
78 public: HObj GetHandle() const {
79 return _hObj;
80 }
81
86 public: void SetHandle( HObj hObj_ ){
87 _hObj = hObj_;
88 }
89
90 // priority
91 private: u32 _priority = 0;
96 public: void SetPriority( u32 priority_ ){
97 _priority = priority_;
98 }
103 public: u32 GetPriority() const {
104 return _priority;
105 }
106
107 // kill
108 private: bool _req_kill = false;
112 public: void ReqKill(){
113 _req_kill = true;
114 }
119 public: bool IsReqKill() const {
120 return _req_kill;
121 }
122
123 // type of
124 private: u32 _type_id = 0x00000000;
129 protected: void SetTypeId( u32 type_id_ ){
130 _type_id = type_id_;
131 }
136 public: u32 GetTypeId(){
137 return _type_id;
138 }
144 public: bool IsTypeOf( u32 type_id_ ){
145 return _type_id == type_id_ ? true : false;
146 }
147
148 public:
149 CObj();
150 virtual ~CObj();
151};
152
153extern void CObjHolder_Reset();
154extern HObj CObjHolder_Entry( CObj* obj , u32 priority );
155extern void CObjHolder_Remove( HObj hObj );
156extern void CObjHolder_Enum( std::vector< HObj >& dest_ , u32 prio_ , u32 type_id_ );
157extern void CObjHolder_Step( b8PpuCmd* cmd_ );
158extern void CObjHolder_Pause( s32 cnt_pause_ );
159extern CObj* cobj( HObj hObj );
160template <class T>
161class Handle {
162 HObj _h = HANDLE_NULL;
163 T* _p = nullptr;
164
165 void _DynamicCast(){
166 _p = dynamic_cast< T* >( cobj( _h ) );
167 _ASSERT( _p , "failed dynamic_cast" );
168 }
169
170public:
175 inline T* operator -> (){
176 if( nullptr == _p ){
177 _ASSERT( 0 , "failed dynamic_cast" );
178 }
179 return _p;
180 }
181
188 _h = h_;
189 _DynamicCast();
190 return *this;
191 }
192
199 _h = x_._h;
200 _DynamicCast();
201 return *this;
202 }
203
208 Handle( HObj hObj_ )
209 {
210 _h = hObj_;
211 _DynamicCast();
212 }
213
214 Handle(){}
215};
Definition cobj.h:44
bool IsTypeOf(u32 type_id_)
Check if the object is of a specific type.
Definition cobj.h:144
u32 GetPriority() const
Get the priority of the object.
Definition cobj.h:103
HObj GetHandle() const
Get the handle of the object.
Definition cobj.h:78
void SetTypeId(u32 type_id_)
Set the type ID of the object.
Definition cobj.h:129
void ReqKill()
Request to kill the object.
Definition cobj.h:112
u32 GetId() const
Get the ID of the object.
Definition cobj.h:53
bool IsReqKill() const
Check if the object is requested to be killed.
Definition cobj.h:119
u32 GetTypeId()
Get the type ID of the object.
Definition cobj.h:136
void SetHandle(HObj hObj_)
Set the handle of the object.
Definition cobj.h:86
void SetPriority(u32 priority_)
Set the priority of the object.
Definition cobj.h:96
Definition cobj.h:161
Handle< T > operator=(HObj h_)
Assignment operator for handle.
Definition cobj.h:187
Handle(HObj hObj_)
Constructor with handle parameter.
Definition cobj.h:208
T * operator->()
Arrow operator to access the underlying object.
Definition cobj.h:175
Module for managing pointers using handles.