Skip to content

Commit eaad5fb

Browse files
author
nitrocaster
committed
Convert ICollidable into interface, introduce CollidableBase class.
1 parent ac3b38d commit eaad5fb

30 files changed

+107
-97
lines changed

src/xrCDB/xr_area_raypick.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ BOOL CObjectSpace::_RayTest ( const Fvector &start, const Fvector &dir, float ra
4848
ISpatial* spatial = r_spatial[o_it];
4949
CObject* collidable = spatial->dcast_CObject ();
5050
if (collidable && (collidable!=ignore_object)) {
51-
ECollisionFormType tp = collidable->collidable.model->Type();
52-
if ((tgt&(rqtObject|rqtObstacle))&&(tp==cftObject)&&collidable->collidable.model->_RayQuery(Q,r_temp)) return TRUE;
53-
if ((tgt&rqtShape)&&(tp==cftShape)&&collidable->collidable.model->_RayQuery(Q,r_temp)) return TRUE;
51+
ECollisionFormType tp = collidable->GetCForm()->Type();
52+
if ((tgt&(rqtObject|rqtObstacle))&&(tp==cftObject)&&collidable->GetCForm()->_RayQuery(Q,r_temp)) return TRUE;
53+
if ((tgt&rqtShape)&&(tp==cftShape)&&collidable->GetCForm()->_RayQuery(Q,r_temp)) return TRUE;
5454
}
5555
}
5656
}
@@ -128,11 +128,11 @@ BOOL CObjectSpace::_RayPick ( const Fvector &start, const Fvector &dir, float ra
128128
CObject* collidable = spatial->dcast_CObject();
129129
if (0==collidable) continue;
130130
if (collidable==ignore_object) continue;
131-
ECollisionFormType tp = collidable->collidable.model->Type();
131+
ECollisionFormType tp = collidable->GetCForm()->Type();
132132
if (((tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((tgt&rqtShape)&&(tp==cftShape))){
133133
u32 C = color_xrgb (64,64,64);
134134
Q.range = R.range;
135-
if (collidable->collidable.model->_RayQuery(Q,r_temp)){
135+
if (collidable->GetCForm()->_RayQuery(Q,r_temp)){
136136
C = color_xrgb(128,128,196);
137137
R.set_if_less (r_temp.r_begin());
138138
}
@@ -191,8 +191,8 @@ BOOL CObjectSpace::_RayQuery2 (collide::rq_results& r_dest, const collide::ray_d
191191
CObject* collidable = r_spatial[o_it]->dcast_CObject();
192192
if (0==collidable) continue;
193193
if (collidable==ignore_object) continue;
194-
ICollisionForm* cform = collidable->collidable.model;
195-
ECollisionFormType tp = collidable->collidable.model->Type();
194+
ICollisionForm* cform = collidable->GetCForm();
195+
ECollisionFormType tp = cform->Type();
196196
if (((R.tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((R.tgt&rqtShape)&&(tp==cftShape))){
197197
if (tb&&!tb(R,collidable,user_data))continue;
198198
cform->_RayQuery(R,r_temp);
@@ -258,8 +258,8 @@ BOOL CObjectSpace::_RayQuery3 (collide::rq_results& r_dest, const collide::ray_d
258258
CObject* collidable = r_spatial[o_it]->dcast_CObject();
259259
if (0==collidable) continue;
260260
if (collidable==ignore_object) continue;
261-
ICollisionForm* cform = collidable->collidable.model;
262-
ECollisionFormType tp = collidable->collidable.model->Type();
261+
ICollisionForm* cform = collidable->GetCForm();
262+
ECollisionFormType tp = cform->Type();
263263
if (((R.tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((R.tgt&rqtShape)&&(tp==cftShape))){
264264
if (tb&&!tb(d_rd,collidable,user_data))continue;
265265
u32 r_cnt = r_temp.r_count();
@@ -345,8 +345,8 @@ BOOL CObjectSpace::_RayQuery (collide::rq_results& r_dest, const collide::ray_de
345345
CObject* collidable = r_spatial[o_it]->dcast_CObject();
346346
if (0==collidable) continue;
347347
if (collidable==ignore_object) continue;
348-
ICollisionForm* cform = collidable->collidable.model;
349-
ECollisionFormType tp = collidable->collidable.model->Type();
348+
ICollisionForm* cform = collidable->GetCForm();
349+
ECollisionFormType tp = cform->Type();
350350
if (((R.tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((R.tgt&rqtShape)&&(tp==cftShape))){
351351
if (tb&&!tb(d_rd,collidable,user_data))continue;
352352
cform->_RayQuery(d_rd,r_temp);

src/xrEngine/Feel_Vision.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void Vision::o_trace(Fvector& P, float dt, float vis_threshold)
161161
xr_vector<feel_visible_Item>::iterator I = feel_visible.begin(), E = feel_visible.end();
162162
for (; I != E; I++)
163163
{
164-
if (0 == I->O->CFORM()) { I->fuzzy = -1; continue; }
164+
if (0 == I->O->GetCForm()) { I->fuzzy = -1; continue; }
165165

166166
// verify relation
167167
// if (positive(I->fuzzy) && I->O->Position().similar(I->cp_LR_dst,lr_granularity) && P.similar(I->cp_LR_src,lr_granularity))
@@ -240,7 +240,7 @@ void Vision::o_trace(Fvector& P, float dt, float vis_threshold)
240240

241241
CObject const* object = (*i)->dcast_CObject();
242242
RQR.r_clear();
243-
if (object && object->collidable.model && !object->collidable.model->_RayQuery(RD, RQR))
243+
if (object && object->GetCForm() && !object->GetCForm()->_RayQuery(RD, RQR))
244244
continue;
245245

246246
collision_found = true;

src/xrEngine/ICollidable.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#include "xrCDB/ispatial.h"
33
#include "icollidable.h"
44
#include "xr_collide_form.h"
5-
6-
ICollidable::ICollidable()
5+
// XXX: rename this file to CollidableBase.cpp
6+
CollidableBase::CollidableBase()
77
{
8-
collidable.model = NULL;
8+
CForm = nullptr;
99
ISpatial* self = dynamic_cast<ISpatial*> (this);
1010
if (self) self->spatial.type |= STYPE_COLLIDEABLE;
1111
};
12-
ICollidable::~ICollidable()
12+
CollidableBase::~CollidableBase()
1313
{
14-
xr_delete(collidable.model);
14+
xr_delete(CForm);
1515
};

src/xrEngine/ICollidable.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
class ENGINE_API ICollisionForm;
44

5-
class ENGINE_API ICollidable
5+
class ICollidable
66
{
77
public:
8-
struct
9-
{
10-
ICollisionForm* model;
11-
} collidable;
8+
virtual ~ICollidable() = 0;
9+
virtual void SetCForm(ICollisionForm *cform) = 0;
10+
virtual ICollisionForm *GetCForm() const = 0;
11+
};
12+
13+
inline ICollidable::~ICollidable() {}
14+
15+
class ENGINE_API CollidableBase : public ICollidable
16+
{
1217
public:
13-
ICollidable();
14-
virtual ~ICollidable();
18+
CollidableBase();
19+
virtual ~CollidableBase();
20+
21+
virtual void SetCForm(ICollisionForm *cform) override { CForm = cform; }
22+
virtual ICollisionForm *GetCForm() const override { return CForm; }
23+
24+
protected:
25+
ICollisionForm *CForm;
1526
};

src/xrEngine/xr_collide_form.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ BOOL CCF_Shape::Contact(CObject* O)
487487
O->Center(S.P);
488488
S.R = O->Radius();
489489
}
490-
else if (O->CFORM())
490+
else if (O->GetCForm())
491491
{
492-
S = O->CFORM()->getSphere();
492+
S = O->GetCForm()->getSphere();
493493
O->XFORM().transform_tiny(S.P);
494494
}
495495
else return FALSE;

src/xrEngine/xr_object.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void CObject::setEnabled(BOOL _enabled)
122122
if (_enabled)
123123
{
124124
Props.bEnabled = 1;
125-
if (collidable.model) spatial.type |= STYPE_COLLIDEABLE;
125+
if (CForm) spatial.type |= STYPE_COLLIDEABLE;
126126
}
127127
else
128128
{
@@ -212,12 +212,12 @@ BOOL CObject::net_Spawn(CSE_Abstract* data)
212212
if (0 == Visual() && pSettings->line_exist(cNameSect(), "visual"))
213213
cNameVisual_set(pSettings->r_string(cNameSect(), "visual"));
214214

215-
if (0 == collidable.model)
215+
if (0 == CForm)
216216
{
217217
if (pSettings->line_exist(cNameSect(), "cform"))
218218
{
219219
VERIFY3(*NameVisual, "Model isn't assigned for object, but cform requisted", *cName());
220-
collidable.model = xr_new<CCF_Skeleton>(this);
220+
CForm = xr_new<CCF_Skeleton>(this);
221221
}
222222
}
223223

@@ -239,7 +239,7 @@ BOOL CObject::net_Spawn(CSE_Abstract* data)
239239
void CObject::net_Destroy()
240240
{
241241
VERIFY(getDestroy());
242-
xr_delete(collidable.model);
242+
xr_delete(CForm);
243243
if (register_schedule())
244244
shedule_unregister();
245245

@@ -323,7 +323,7 @@ void CObject::UpdateCL()
323323

324324
if (Parent && spatial.node_ptr) Debug.fatal(DEBUG_INFO, "Object %s has parent but is still registered inside spatial DB", *cName());
325325

326-
if ((0 == collidable.model) && (spatial.type&STYPE_COLLIDEABLE)) Debug.fatal(DEBUG_INFO, "Object %s registered as 'collidable' but has no collidable model", *cName());
326+
if ((0 == CForm) && (spatial.type&STYPE_COLLIDEABLE)) Debug.fatal(DEBUG_INFO, "Object %s registered as 'collidable' but has no collidable model", *cName());
327327
#endif
328328

329329
spatial_update(base_spu_epsP * 5, base_spu_epsR * 5);
@@ -462,7 +462,7 @@ Fvector CObject::get_last_local_point_on_mesh(Fvector const& local_point, u16 co
462462
// Fetch data
463463
Fmatrix mE;
464464
const Fmatrix& M = XFORM();
465-
const Fbox& B = CFORM()->getBBox();
465+
const Fbox& B = CForm->getBBox();
466466

467467
// Build OBB + Ellipse and X-form point
468468
Fvector c, r;

src/xrEngine/xr_object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CSE_Abstract;
2222
//-----------------------------------------------------------------------------------------------------------
2323
// CObject
2424
//-----------------------------------------------------------------------------------------------------------
25+
2526
class IPhysicsShell;
2627
xr_pure_interface IObjectPhysicsCollision;
2728
#pragma pack(push,4)
@@ -30,7 +31,7 @@ class ENGINE_API CObject :
3031
public ISpatial,
3132
public ISheduled,
3233
public IRenderable,
33-
public ICollidable
34+
public CollidableBase
3435
{
3536
public:
3637
struct SavedPosition
@@ -130,7 +131,6 @@ class ENGINE_API CObject :
130131

131132
// Accessors and converters
132133
ICF IRenderVisual* Visual() const { return renderable.visual; }
133-
ICF ICollisionForm* CFORM() const { return collidable.model; }
134134
virtual CObject* dcast_CObject() { return this; }
135135
virtual IRenderable* dcast_Renderable() { return this; }
136136
virtual void OnChangeVisual() { }

src/xrGame/Actor_Network.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ void CActor::OnRender_Network()
14771477
Level().debug_renderer().draw_obb(BoneMatrix, BoneOBB.m_halfsize, color_rgba(0, 255, 0, 255));
14781478
};
14791479
*/
1480-
CCF_Skeleton* Skeleton = smart_cast<CCF_Skeleton*>(collidable.model);
1480+
CCF_Skeleton* Skeleton = smart_cast<CCF_Skeleton*>(CForm);
14811481
if (Skeleton){
14821482
Skeleton->_dbg_refresh();
14831483

src/xrGame/BreakableObject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ BOOL CBreakableObject::net_Spawn(CSE_Abstract* DC)
4343
CSE_ALifeObjectBreakable *obj = smart_cast<CSE_ALifeObjectBreakable*>(e);
4444
R_ASSERT (obj);
4545
inherited::net_Spawn (DC);
46-
VERIFY(!collidable.model);
47-
collidable.model = xr_new<CCF_Skeleton>(this);
46+
VERIFY(!CForm);
47+
CForm = xr_new<CCF_Skeleton>(this);
4848
// set bone id
4949
R_ASSERT (Visual()&&smart_cast<IKinematics*>(Visual()));
5050
// IKinematics* K = smart_cast<IKinematics*>(Visual());
@@ -198,7 +198,7 @@ void CBreakableObject::net_Destroy()
198198

199199
m_pPhysicsShell=NULL;
200200
inherited::net_Destroy();
201-
xr_delete(collidable.model);
201+
xr_delete(CForm);
202202
Init();
203203
//Visual()->vis.box.set(m_saved_box);
204204
GlobalEnv.Render->model_Delete(renderable.visual,TRUE);

src/xrGame/Car.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ bool CCar::Use(const Fvector& pos,const Fvector& dir,const Fvector& foot_pos)
14631463
RQR.r_clear ();
14641464
collide::ray_defs Q(pos, dir, 3.f, CDB::OPT_CULL,collide::rqtObject); // CDB::OPT_ONLYFIRST CDB::OPT_ONLYNEAREST
14651465
VERIFY(!fis_zero(Q.dir.square_magnitude()));
1466-
if (g_pGameLevel->ObjectSpace.RayQuery(RQR,collidable.model,Q))
1466+
if (g_pGameLevel->ObjectSpace.RayQuery(RQR,CForm,Q))
14671467
{
14681468
collide::rq_results& R = RQR;
14691469
int y=R.r_count();

0 commit comments

Comments
 (0)