Skip to content

Commit

Permalink
Convert ICollidable into interface, introduce CollidableBase class.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Nov 10, 2015
1 parent ac3b38d commit eaad5fb
Show file tree
Hide file tree
Showing 30 changed files with 107 additions and 97 deletions.
22 changes: 11 additions & 11 deletions src/xrCDB/xr_area_raypick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ BOOL CObjectSpace::_RayTest ( const Fvector &start, const Fvector &dir, float ra
ISpatial* spatial = r_spatial[o_it];
CObject* collidable = spatial->dcast_CObject ();
if (collidable && (collidable!=ignore_object)) {
ECollisionFormType tp = collidable->collidable.model->Type();
if ((tgt&(rqtObject|rqtObstacle))&&(tp==cftObject)&&collidable->collidable.model->_RayQuery(Q,r_temp)) return TRUE;
if ((tgt&rqtShape)&&(tp==cftShape)&&collidable->collidable.model->_RayQuery(Q,r_temp)) return TRUE;
ECollisionFormType tp = collidable->GetCForm()->Type();
if ((tgt&(rqtObject|rqtObstacle))&&(tp==cftObject)&&collidable->GetCForm()->_RayQuery(Q,r_temp)) return TRUE;
if ((tgt&rqtShape)&&(tp==cftShape)&&collidable->GetCForm()->_RayQuery(Q,r_temp)) return TRUE;
}
}
}
Expand Down Expand Up @@ -128,11 +128,11 @@ BOOL CObjectSpace::_RayPick ( const Fvector &start, const Fvector &dir, float ra
CObject* collidable = spatial->dcast_CObject();
if (0==collidable) continue;
if (collidable==ignore_object) continue;
ECollisionFormType tp = collidable->collidable.model->Type();
ECollisionFormType tp = collidable->GetCForm()->Type();
if (((tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((tgt&rqtShape)&&(tp==cftShape))){
u32 C = color_xrgb (64,64,64);
Q.range = R.range;
if (collidable->collidable.model->_RayQuery(Q,r_temp)){
if (collidable->GetCForm()->_RayQuery(Q,r_temp)){
C = color_xrgb(128,128,196);
R.set_if_less (r_temp.r_begin());
}
Expand Down Expand Up @@ -191,8 +191,8 @@ BOOL CObjectSpace::_RayQuery2 (collide::rq_results& r_dest, const collide::ray_d
CObject* collidable = r_spatial[o_it]->dcast_CObject();
if (0==collidable) continue;
if (collidable==ignore_object) continue;
ICollisionForm* cform = collidable->collidable.model;
ECollisionFormType tp = collidable->collidable.model->Type();
ICollisionForm* cform = collidable->GetCForm();
ECollisionFormType tp = cform->Type();
if (((R.tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((R.tgt&rqtShape)&&(tp==cftShape))){
if (tb&&!tb(R,collidable,user_data))continue;
cform->_RayQuery(R,r_temp);
Expand Down Expand Up @@ -258,8 +258,8 @@ BOOL CObjectSpace::_RayQuery3 (collide::rq_results& r_dest, const collide::ray_d
CObject* collidable = r_spatial[o_it]->dcast_CObject();
if (0==collidable) continue;
if (collidable==ignore_object) continue;
ICollisionForm* cform = collidable->collidable.model;
ECollisionFormType tp = collidable->collidable.model->Type();
ICollisionForm* cform = collidable->GetCForm();
ECollisionFormType tp = cform->Type();
if (((R.tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((R.tgt&rqtShape)&&(tp==cftShape))){
if (tb&&!tb(d_rd,collidable,user_data))continue;
u32 r_cnt = r_temp.r_count();
Expand Down Expand Up @@ -345,8 +345,8 @@ BOOL CObjectSpace::_RayQuery (collide::rq_results& r_dest, const collide::ray_de
CObject* collidable = r_spatial[o_it]->dcast_CObject();
if (0==collidable) continue;
if (collidable==ignore_object) continue;
ICollisionForm* cform = collidable->collidable.model;
ECollisionFormType tp = collidable->collidable.model->Type();
ICollisionForm* cform = collidable->GetCForm();
ECollisionFormType tp = cform->Type();
if (((R.tgt&(rqtObject|rqtObstacle))&&(tp==cftObject))||((R.tgt&rqtShape)&&(tp==cftShape))){
if (tb&&!tb(d_rd,collidable,user_data))continue;
cform->_RayQuery(d_rd,r_temp);
Expand Down
4 changes: 2 additions & 2 deletions src/xrEngine/Feel_Vision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void Vision::o_trace(Fvector& P, float dt, float vis_threshold)
xr_vector<feel_visible_Item>::iterator I = feel_visible.begin(), E = feel_visible.end();
for (; I != E; I++)
{
if (0 == I->O->CFORM()) { I->fuzzy = -1; continue; }
if (0 == I->O->GetCForm()) { I->fuzzy = -1; continue; }

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

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

collision_found = true;
Expand Down
10 changes: 5 additions & 5 deletions src/xrEngine/ICollidable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include "xrCDB/ispatial.h"
#include "icollidable.h"
#include "xr_collide_form.h"

ICollidable::ICollidable()
// XXX: rename this file to CollidableBase.cpp
CollidableBase::CollidableBase()
{
collidable.model = NULL;
CForm = nullptr;
ISpatial* self = dynamic_cast<ISpatial*> (this);
if (self) self->spatial.type |= STYPE_COLLIDEABLE;
};
ICollidable::~ICollidable()
CollidableBase::~CollidableBase()
{
xr_delete(collidable.model);
xr_delete(CForm);
};
25 changes: 18 additions & 7 deletions src/xrEngine/ICollidable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

class ENGINE_API ICollisionForm;

class ENGINE_API ICollidable
class ICollidable
{
public:
struct
{
ICollisionForm* model;
} collidable;
virtual ~ICollidable() = 0;
virtual void SetCForm(ICollisionForm *cform) = 0;
virtual ICollisionForm *GetCForm() const = 0;
};

inline ICollidable::~ICollidable() {}

class ENGINE_API CollidableBase : public ICollidable
{
public:
ICollidable();
virtual ~ICollidable();
CollidableBase();
virtual ~CollidableBase();

virtual void SetCForm(ICollisionForm *cform) override { CForm = cform; }
virtual ICollisionForm *GetCForm() const override { return CForm; }

protected:
ICollisionForm *CForm;
};
4 changes: 2 additions & 2 deletions src/xrEngine/xr_collide_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ BOOL CCF_Shape::Contact(CObject* O)
O->Center(S.P);
S.R = O->Radius();
}
else if (O->CFORM())
else if (O->GetCForm())
{
S = O->CFORM()->getSphere();
S = O->GetCForm()->getSphere();
O->XFORM().transform_tiny(S.P);
}
else return FALSE;
Expand Down
12 changes: 6 additions & 6 deletions src/xrEngine/xr_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void CObject::setEnabled(BOOL _enabled)
if (_enabled)
{
Props.bEnabled = 1;
if (collidable.model) spatial.type |= STYPE_COLLIDEABLE;
if (CForm) spatial.type |= STYPE_COLLIDEABLE;
}
else
{
Expand Down Expand Up @@ -212,12 +212,12 @@ BOOL CObject::net_Spawn(CSE_Abstract* data)
if (0 == Visual() && pSettings->line_exist(cNameSect(), "visual"))
cNameVisual_set(pSettings->r_string(cNameSect(), "visual"));

if (0 == collidable.model)
if (0 == CForm)
{
if (pSettings->line_exist(cNameSect(), "cform"))
{
VERIFY3(*NameVisual, "Model isn't assigned for object, but cform requisted", *cName());
collidable.model = xr_new<CCF_Skeleton>(this);
CForm = xr_new<CCF_Skeleton>(this);
}
}

Expand All @@ -239,7 +239,7 @@ BOOL CObject::net_Spawn(CSE_Abstract* data)
void CObject::net_Destroy()
{
VERIFY(getDestroy());
xr_delete(collidable.model);
xr_delete(CForm);
if (register_schedule())
shedule_unregister();

Expand Down Expand Up @@ -323,7 +323,7 @@ void CObject::UpdateCL()

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

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

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

// Build OBB + Ellipse and X-form point
Fvector c, r;
Expand Down
4 changes: 2 additions & 2 deletions src/xrEngine/xr_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CSE_Abstract;
//-----------------------------------------------------------------------------------------------------------
// CObject
//-----------------------------------------------------------------------------------------------------------

class IPhysicsShell;
xr_pure_interface IObjectPhysicsCollision;
#pragma pack(push,4)
Expand All @@ -30,7 +31,7 @@ class ENGINE_API CObject :
public ISpatial,
public ISheduled,
public IRenderable,
public ICollidable
public CollidableBase
{
public:
struct SavedPosition
Expand Down Expand Up @@ -130,7 +131,6 @@ class ENGINE_API CObject :

// Accessors and converters
ICF IRenderVisual* Visual() const { return renderable.visual; }
ICF ICollisionForm* CFORM() const { return collidable.model; }
virtual CObject* dcast_CObject() { return this; }
virtual IRenderable* dcast_Renderable() { return this; }
virtual void OnChangeVisual() { }
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/Actor_Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ void CActor::OnRender_Network()
Level().debug_renderer().draw_obb(BoneMatrix, BoneOBB.m_halfsize, color_rgba(0, 255, 0, 255));
};
*/
CCF_Skeleton* Skeleton = smart_cast<CCF_Skeleton*>(collidable.model);
CCF_Skeleton* Skeleton = smart_cast<CCF_Skeleton*>(CForm);
if (Skeleton){
Skeleton->_dbg_refresh();

Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/BreakableObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ BOOL CBreakableObject::net_Spawn(CSE_Abstract* DC)
CSE_ALifeObjectBreakable *obj = smart_cast<CSE_ALifeObjectBreakable*>(e);
R_ASSERT (obj);
inherited::net_Spawn (DC);
VERIFY(!collidable.model);
collidable.model = xr_new<CCF_Skeleton>(this);
VERIFY(!CForm);
CForm = xr_new<CCF_Skeleton>(this);
// set bone id
R_ASSERT (Visual()&&smart_cast<IKinematics*>(Visual()));
// IKinematics* K = smart_cast<IKinematics*>(Visual());
Expand Down Expand Up @@ -198,7 +198,7 @@ void CBreakableObject::net_Destroy()

m_pPhysicsShell=NULL;
inherited::net_Destroy();
xr_delete(collidable.model);
xr_delete(CForm);
Init();
//Visual()->vis.box.set(m_saved_box);
GlobalEnv.Render->model_Delete(renderable.visual,TRUE);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/Car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ bool CCar::Use(const Fvector& pos,const Fvector& dir,const Fvector& foot_pos)
RQR.r_clear ();
collide::ray_defs Q(pos, dir, 3.f, CDB::OPT_CULL,collide::rqtObject); // CDB::OPT_ONLYFIRST CDB::OPT_ONLYNEAREST
VERIFY(!fis_zero(Q.dir.square_magnitude()));
if (g_pGameLevel->ObjectSpace.RayQuery(RQR,collidable.model,Q))
if (g_pGameLevel->ObjectSpace.RayQuery(RQR,CForm,Q))
{
collide::rq_results& R = RQR;
int y=R.r_count();
Expand Down
12 changes: 6 additions & 6 deletions src/xrGame/CustomZone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void CCustomZone::shedule_Update(u32 dt)

if (IsEnabled())
{
const Fsphere& s = CFORM()->getSphere();
const Fsphere& s = GetCForm()->getSphere();
Fvector P;
XFORM().transform_tiny (P,s.P);

Expand Down Expand Up @@ -633,7 +633,7 @@ bool CCustomZone::feel_touch_contact(CObject* O)
if (!object || !object->IsVisibleForZones())
return (FALSE);

if (!((CCF_Shape*)CFORM())->Contact(O))
if (!((CCF_Shape*)GetCForm())->Contact(O))
return (FALSE);

return (object->feel_touch_on_contact(this));
Expand Down Expand Up @@ -828,7 +828,7 @@ void CCustomZone::PlayEntranceParticles(CGameObject* pObject)
void CCustomZone::PlayBoltEntranceParticles()
{

CCF_Shape* Sh = (CCF_Shape*)CFORM();
CCF_Shape* Sh = (CCF_Shape*)GetCForm();
const Fmatrix& XF = XFORM();
Fmatrix PXF;
xr_vector<CCF_Shape::shape_def>& Shapes = Sh->Shapes();
Expand Down Expand Up @@ -1410,11 +1410,11 @@ BOOL CCustomZone::AlwaysTheCrow()

void CCustomZone::CalcDistanceTo(const Fvector& P, float& dist, float& radius)
{
R_ASSERT (CFORM()->Type()==cftShape);
CCF_Shape* Sh = (CCF_Shape*)CFORM();
R_ASSERT (GetCForm()->Type()==cftShape);
CCF_Shape* Sh = (CCF_Shape*)GetCForm();

dist = P.distance_to(Position());
float sr = CFORM()->getSphere().R;
float sr = GetCForm()->getSphere().R;
//quick test
if(Sh->Shapes().size()==1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ void CGameObject::spatial_move ()
#ifdef DEBUG
void CGameObject::dbg_DrawSkeleton ()
{
CCF_Skeleton* Skeleton = smart_cast<CCF_Skeleton*>(collidable.model);
CCF_Skeleton* Skeleton = smart_cast<CCF_Skeleton*>(CForm);
if (!Skeleton) return;
Skeleton->_dbg_refresh();

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/HairsZone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void CHairsZone::Affect(SZoneObjectInfo* O)
if(O->zone_ignore) return;

Fvector P;
XFORM().transform_tiny(P,CFORM()->getSphere().P);
XFORM().transform_tiny(P, GetCForm()->getSphere().P);

Fvector hit_dir;
hit_dir.set(::Random.randF(-.5f,.5f),
Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/HangingLamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ BOOL CHangingLamp::net_Spawn(CSE_Abstract* DC)
// set bone id
// CInifile* pUserData = K->LL_UserData();
// R_ASSERT3 (pUserData,"Empty HangingLamp user data!",lamp->get_visual());
xr_delete(collidable.model);
xr_delete(CForm);
if (Visual()){
IKinematics* K = smart_cast<IKinematics*>(Visual());
R_ASSERT (Visual()&&smart_cast<IKinematics*>(Visual()));
light_bone = K->LL_BoneID (*lamp->light_main_bone); VERIFY(light_bone!=BI_NONE);
ambient_bone = K->LL_BoneID (*lamp->light_ambient_bone);VERIFY(ambient_bone!=BI_NONE);
collidable.model = xr_new<CCF_Skeleton> (this);
CForm = xr_new<CCF_Skeleton> (this);
}
fBrightness = lamp->brightness;
clr.set (lamp->color); clr.a = 1.f;
Expand Down Expand Up @@ -154,7 +154,7 @@ BOOL CHangingLamp::net_Spawn(CSE_Abstract* DC)
}

setVisible ((BOOL)!!Visual());
setEnabled ((BOOL)!!collidable.model);
setEnabled ((BOOL)!!CForm);

return (TRUE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/Level_bullet_manager_firetrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ BOOL CBulletManager::test_callback(const collide::ray_defs& rd, CObject* object,
if (object){
CEntity* entity = smart_cast<CEntity*>(object);
if (entity&&entity->g_Alive()&&(entity->ID()!=bullet->parent_id)){
ICollisionForm* cform = entity->collidable.model;
ICollisionForm* cform = entity->GetCForm();
if ((NULL!=cform) && (cftObject==cform->Type())){
CActor* actor = smart_cast<CActor*>(entity);
CAI_Stalker* stalker= smart_cast<CAI_Stalker*>(entity);
Expand Down Expand Up @@ -357,7 +357,7 @@ bool CBulletManager::ObjectHit( SBullet_Hit* hit_res, SBullet* bullet, const Fve
if ( R.O )
{
//âåðíóòü íîðìàëü ïî êîòîðîé èãðàòü ïàðòèêëû
CCF_Skeleton* skeleton = smart_cast<CCF_Skeleton*>(R.O->CFORM());
CCF_Skeleton* skeleton = smart_cast<CCF_Skeleton*>(R.O->GetCForm());
if ( skeleton )
{
Fvector e_center;
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/MosquitoBald.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CMosquitoBald::Affect(SZoneObjectInfo* O)
if(O->zone_ignore) return;

Fvector P;
XFORM().transform_tiny(P,CFORM()->getSphere().P);
XFORM().transform_tiny(P, GetCForm()->getSphere().P);

Fvector hit_dir;
hit_dir.set( ::Random.randF(-.5f,.5f),
Expand Down Expand Up @@ -97,7 +97,7 @@ void CMosquitoBald::UpdateSecondaryHit()

if((&(*it))->zone_ignore) return;
Fvector P;
XFORM().transform_tiny(P,CFORM()->getSphere().P);
XFORM().transform_tiny(P, GetCForm()->getSphere().P);

Fvector hit_dir;
hit_dir.set( ::Random.randF(-.5f,.5f),
Expand Down
Loading

0 comments on commit eaad5fb

Please sign in to comment.