diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index c1cdfb185a..65402af387 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -416,12 +416,12 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c) continue; int status = losMgr->GetUnitStatus(units[i], g_Game->GetLocalPlayer()); - CModel* model = units[i]->GetModel(); + CModel& model = units[i]->GetModel(); - model->ValidatePosition(); + model.ValidatePosition(); if (status != UNIT_HIDDEN && - (!m->Culling || frustum.IsBoxVisible(CVector3D(0,0,0), model->GetBounds()))) + (!m->Culling || frustum.IsBoxVisible(CVector3D(0,0,0), model.GetBounds()))) { if(units[i] != g_BuildingPlacer.m_actor) { @@ -434,11 +434,11 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c) { color = CColor(0.7f, 0.7f, 0.7f, 1.0f); } - model->SetShadingColor(color); + model.SetShadingColor(color); } PROFILE( "submit models" ); - c->SubmitRecursive(model); + c->SubmitRecursive(&model); } } @@ -493,13 +493,14 @@ void CGameView::CameraLock(float x, float y, float z, bool smooth) } -static void MarkUpdateColorRecursive(CModel* model) +static void MarkUpdateColorRecursive(CModel& model) { - model->SetDirty(RENDERDATA_UPDATE_COLOR); + model.SetDirty(RENDERDATA_UPDATE_COLOR); - const std::vector& props = model->GetProps(); + const std::vector& props = model.GetProps(); for(size_t i = 0; i < props.size(); ++i) { - MarkUpdateColorRecursive(props[i].m_Model); + debug_assert(props[i].m_Model); + MarkUpdateColorRecursive(*props[i].m_Model); } } diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index ddde2504dd..159ef01098 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -1112,7 +1112,7 @@ int CXMLReader::ReadNonEntities(XMBElement parent, double end_time) CMatrix3D m; m.SetYRotation(Orientation + (float)M_PI); m.Translate(Position); - unit->GetModel()->SetTransform(m); + unit->GetModel().SetTransform(m); // TODO: save object IDs in the map file, and load them again, // so that triggers have a persistent identifier for objects diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 796ecc5717..28e8d5672b 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -379,7 +379,7 @@ void CMapWriter::WriteXML(const VfsPath& filename, XML_Setting("Actor", (*unit)->GetObject().m_Base->m_Name); { - CVector3D position = (*unit)->GetModel()->GetTransform().GetTranslation(); + CVector3D position = (*unit)->GetModel().GetTransform().GetTranslation(); XML_Element("Position"); XML_Attribute("x", position.X); @@ -388,7 +388,7 @@ void CMapWriter::WriteXML(const VfsPath& filename, } { - CVector3D orient = (*unit)->GetModel()->GetTransform().GetIn(); + CVector3D orient = (*unit)->GetModel().GetTransform().GetIn(); float angle = atan2(-orient.X, -orient.Z); XML_Element("Orientation"); diff --git a/source/graphics/Unit.h b/source/graphics/Unit.h index bcf5a87394..65b58f03c5 100644 --- a/source/graphics/Unit.h +++ b/source/graphics/Unit.h @@ -59,8 +59,8 @@ public: // get unit's template object const CObjectEntry& GetObject() const { return *m_Object; } - // get unit's model data; never NULL - CModel* GetModel() const { return m_Model; } + // get unit's model data + CModel& GetModel() const { return *m_Model; } // get actor's entity; can be NULL CEntity* GetEntity() const { return m_Entity; } @@ -107,9 +107,9 @@ public: void SetActorSelections(const std::set& selections); private: - // object from which unit was created + // object from which unit was created; never NULL CObjectEntry* m_Object; - // object model representation + // object model representation; never NULL CModel* m_Model; // the entity that this actor represents, if any CEntity* m_Entity; diff --git a/source/graphics/UnitAnimation.cpp b/source/graphics/UnitAnimation.cpp index 0e0fedaace..66776239d3 100644 --- a/source/graphics/UnitAnimation.cpp +++ b/source/graphics/UnitAnimation.cpp @@ -65,32 +65,32 @@ void CUnitAnimation::SetAnimationState(const CStr& name, bool once, float speed, void CUnitAnimation::SetAnimationSync(float actionTime, float repeatTime) { - CModel* model = m_Unit.GetModel(); + CModel& model = m_Unit.GetModel(); - if (!model || !model->m_Anim || !model->m_Anim->m_AnimDef) + if (!model.m_Anim || !model.m_Anim->m_AnimDef) return; - float duration = model->m_Anim->m_AnimDef->GetDuration(); + float duration = model.m_Anim->m_AnimDef->GetDuration(); // Set the speed so it loops once in repeatTime float speed = duration / repeatTime; // Need to offset so that start+actionTime*speed = ActionPos - float start = model->m_Anim->m_ActionPos - actionTime*speed; + float start = model.m_Anim->m_ActionPos - actionTime*speed; // Wrap it so that it's within the animation start = fmodf(start, duration); if (start < 0) start += duration; // Make the animation run at the computed timings - model->m_AnimTime = start; + model.m_AnimTime = start; m_Speed = m_OriginalSpeed = speed; m_Desync = 0.f; } void CUnitAnimation::Update(float time) { - CModel* model = m_Unit.GetModel(); + CModel& model = m_Unit.GetModel(); // Convert from real time to scaled animation time float advance = time*m_Speed; @@ -98,10 +98,10 @@ void CUnitAnimation::Update(float time) // Check if the current animation will trigger the action events bool action = false; bool action2 = false; - m_Unit.GetModel()->CheckActionTriggers(advance, action, action2); + model.CheckActionTriggers(advance, action, action2); // Choose a new random animation if we're going to loop - if (m_Looping && model->NeedsNewAnim(time)) + if (m_Looping && model.NeedsNewAnim(time)) { // Re-desynchronise the animation, to keep the irregular drifting between separate units m_Speed = DesyncSpeed(m_OriginalSpeed, m_Desync); @@ -115,7 +115,7 @@ void CUnitAnimation::Update(float time) // Check if the start of the new animation will trigger the action events // (This is additive with the previous CheckActionTriggers) - m_Unit.GetModel()->CheckActionTriggers(advance, action, action2); + model.CheckActionTriggers(advance, action, action2); } // TODO: props should get a new random animation once they loop, independent @@ -143,5 +143,5 @@ void CUnitAnimation::Update(float time) // TODO: some animations (e.g. wood chopping) have two action points that should trigger sounds, // so we ought to support that somehow - model->Update(advance); + model.Update(advance); } diff --git a/source/graphics/UnitManager.cpp b/source/graphics/UnitManager.cpp index 917f62a81f..1ca581f7ef 100644 --- a/source/graphics/UnitManager.cpp +++ b/source/graphics/UnitManager.cpp @@ -112,12 +112,12 @@ CUnit* CUnitManager::PickUnit(const CVector3D& origin, const CVector3D& dir, boo if( ent && !ent->m_visible ) continue; - if (unit->GetModel()->GetBounds().RayIntersect(origin, dir, tmin, tmax) + if (unit->GetModel().GetBounds().RayIntersect(origin, dir, tmin, tmax) && losMgr->GetUnitStatus(unit, g_Game->GetLocalPlayer()) != UNIT_HIDDEN) { // Point of closest approach CVector3D obj; - unit->GetModel()->GetBounds().GetCentre(obj); + unit->GetModel().GetBounds().GetCentre(obj); CVector3D delta = obj - origin; float distance = delta.Dot(dir); CVector3D closest = origin + dir * distance; diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index a33e572d45..097cd20d28 100644 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -1200,7 +1200,7 @@ InReaction InteractInputHandler( const SDL_Event_* ev ) if ( g_Selection.m_selected.empty() ) break; - std::vector& Props = g_Selection.m_selected.front()->m_actor->GetModel()->GetProps(); + std::vector& Props = g_Selection.m_selected.front()->m_actor->GetModel().GetProps(); for (size_t x=0; xGetFrustum(); if( e->m_actor ) - return( frustum.IsBoxVisible( CVector3D(), e->m_actor->GetModel()->GetBounds() ) ); + return( frustum.IsBoxVisible( CVector3D(), e->m_actor->GetModel().GetBounds() ) ); else // If there's no actor, just treat the entity as a point return( frustum.IsBoxVisible( e->m_graphics_position, CBound() ) ); @@ -1519,7 +1519,7 @@ void CBuildingPlacer::Update( float timeStep ) CMatrix3D m; m.SetYRotation(m_angle + (float)M_PI); m.Translate(pos); - m_actor->GetModel()->SetTransform( m ); + m_actor->GetModel().SetTransform( m ); m_bounds->SetPosition(pos.X, pos.Z); if( m_bounds->m_type == CBoundingObject::BOUND_OABB ) @@ -1543,7 +1543,7 @@ void CBuildingPlacer::Update( float timeStep ) float add = ( sin(4*(float)M_PI*m_totalTime) + 1.0f ) * 0.08f; col = CColor( 1.4f+add, 0.4f+add, 0.4f+add, 1.0f ); } - m_actor->GetModel()->SetShadingColor( col ); + m_actor->GetModel().SetShadingColor( col ); } /** diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index ab604aca66..e7459e062e 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -372,7 +372,7 @@ void CEntity::UpdateActorTransforms() mXZ.Translate(m_graphics_position); if( m_actor ) - m_actor->GetModel()->SetTransform( mXZ ); + m_actor->GetModel().SetTransform( mXZ ); } void CEntity::SnapToGround() @@ -627,7 +627,7 @@ void CEntity::UpdateOrders( int timestep ) PROFILE( "animation updates" ); if( m_extant ) { - if( ( m_lastState != -1 ) || !m_actor->GetModel()->GetAnimation() ) + if( ( m_lastState != -1 ) || !m_actor->GetModel().GetAnimation() ) { m_actor->SetAnimationState( "idle", false, 1.f, 0.f, false, L"" ); } diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 74a7f3137a..8eb95a74b5 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -96,7 +96,7 @@ float CEntity::ChooseMovementSpeed( float distance ) m_actor->SetAnimationState( anim_name, false, speed, 0.f, false, L"" ); // Animation desync - m_actor->GetModel()->Update( rand( 0, 1000 ) / 1000.0f ); + m_actor->GetModel().Update( rand( 0, 1000 ) / 1000.0f ); } } diff --git a/source/simulation/LOSManager.cpp b/source/simulation/LOSManager.cpp index e5003682f5..99369374b4 100644 --- a/source/simulation/LOSManager.cpp +++ b/source/simulation/LOSManager.cpp @@ -238,7 +238,7 @@ EUnitLOSStatus CLOSManager::GetUnitStatus(CUnit* unit, CPlayer* player) if (entity) centre = entity->m_position; else - centre = unit->GetModel()->GetTransform().GetTranslation(); + centre = unit->GetModel().GetTransform().GetTranslation(); ELOSStatus status = GetStatus(centre.X, centre.Z, player); diff --git a/source/simulation2/components/CCmpProjectileManager.cpp b/source/simulation2/components/CCmpProjectileManager.cpp index e8fc053404..0ca7bc2b19 100644 --- a/source/simulation2/components/CCmpProjectileManager.cpp +++ b/source/simulation2/components/CCmpProjectileManager.cpp @@ -249,7 +249,7 @@ void CCmpProjectileManager::AdvanceProjectile(const CSimContext& context, Projec transform.Translate(projectile.pos); // Move the model - projectile.unit->GetModel()->SetTransform(transform); + projectile.unit->GetModel().SetTransform(transform); } void CCmpProjectileManager::Interpolate(const CSimContext& context, float frameTime, float frameOffset) @@ -279,15 +279,15 @@ void CCmpProjectileManager::RenderSubmit(const CSimContext& UNUSED(context), Sce { for (size_t i = 0; i < m_Projectiles.size(); ++i) { - CModel* model = m_Projectiles[i].unit->GetModel(); + CModel& model = m_Projectiles[i].unit->GetModel(); - model->ValidatePosition(); + model.ValidatePosition(); - if (culling && !frustum.IsBoxVisible(CVector3D(0, 0, 0), model->GetBounds())) + if (culling && !frustum.IsBoxVisible(CVector3D(0, 0, 0), model.GetBounds())) continue; // TODO: do something about LOS (copy from CCmpVisualActor) - collector.SubmitRecursive(model); + collector.SubmitRecursive(&model); } } diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp index 25224616da..5f49e876b9 100644 --- a/source/simulation2/components/CCmpVisualActor.cpp +++ b/source/simulation2/components/CCmpVisualActor.cpp @@ -166,14 +166,14 @@ public: { if (!m_Unit) return CBound(); - return m_Unit->GetModel()->GetBounds(); + return m_Unit->GetModel().GetBounds(); } virtual CVector3D GetPosition() { if (!m_Unit) return CVector3D(0, 0, 0); - return m_Unit->GetModel()->GetTransform().GetTranslation(); + return m_Unit->GetModel().GetTransform().GetTranslation(); } virtual std::wstring GetActor() @@ -221,7 +221,7 @@ public: if (!m_Unit) return; - m_Unit->GetModel()->SetShadingColor(CColor(r.ToFloat(), g.ToFloat(), b.ToFloat(), a.ToFloat())); + m_Unit->GetModel().SetShadingColor(CColor(r.ToFloat(), g.ToFloat(), b.ToFloat(), a.ToFloat())); } private: @@ -248,7 +248,7 @@ void CCmpVisualActor::Interpolate(const CSimContext& context, float frameTime, f CMatrix3D transform(cmpPosition->GetInterpolatedTransform(frameOffset)); - m_Unit->GetModel()->SetTransform(transform); + m_Unit->GetModel().SetTransform(transform); m_Unit->UpdateModel(frameTime); } @@ -259,14 +259,14 @@ void CCmpVisualActor::RenderSubmit(const CSimContext& UNUSED(context), SceneColl // TODO: need to think about things like LOS here - CModel* model = m_Unit->GetModel(); + CModel& model = m_Unit->GetModel(); - model->ValidatePosition(); + model.ValidatePosition(); - if (culling && !frustum.IsBoxVisible(CVector3D(0, 0, 0), model->GetBounds())) + if (culling && !frustum.IsBoxVisible(CVector3D(0, 0, 0), model.GetBounds())) return; // TODO: model->SetShadingColor(CColor(1.0f, 1.0f, 1.0f, 1.0f) if visible, CColor(0.7f, 0.7f, 0.7f, 1.0f) if hidden in FOW) - collector.SubmitRecursive(model); + collector.SubmitRecursive(&model); } diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 47ae41b0e4..01cf7b0c81 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -159,7 +159,7 @@ void AtlasRenderSelection() } else { - const CBound& bound = unit->GetModel()->GetBounds(); + const CBound& bound = unit->GetModel().GetBounds(); // Expand bounds by 10% around the centre CVector3D centre; bound.GetCentre(centre); @@ -529,7 +529,7 @@ MESSAGEHANDLER(ObjectPreview) m._21 = 0.0f; m._22 = 1.0f; m._23 = 0.0f; m._24 = pos.Y; m._31 = s; m._32 = 0.0f; m._33 = -c; m._34 = pos.Z; m._41 = 0.0f; m._42 = 0.0f; m._43 = 0.0f; m._44 = 1.0f; - previewUnit->GetModel()->SetTransform(m); + previewUnit->GetModel().SetTransform(m); // Update the unit's player colour: previewUnit->SetPlayerID(msg->settings->player); @@ -656,7 +656,7 @@ BEGIN_COMMAND(CreateObject) m._21 = 0.0f; m._22 = 1.0f; m._23 = 0.0f; m._24 = m_Pos.Y; m._31 = s; m._32 = 0.0f; m._33 = -c; m._34 = m_Pos.Z; m._41 = 0.0f; m._42 = 0.0f; m._43 = 0.0f; m._44 = 1.0f; - unit->GetModel()->SetTransform(m); + unit->GetModel().SetTransform(m); unit->SetPlayerID(m_Player); } @@ -724,7 +724,7 @@ QUERYHANDLER(PickObject) // working out the screen coordinates to move the object to. // (TODO: http://trac.wildfiregames.com/ticket/99) - CVector3D centre = target->GetModel()->GetTransform().GetTranslation(); + CVector3D centre = target->GetModel().GetTransform().GetTranslation(); centre.Y = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(centre.X, centre.Z); if (IsFloating(target)) @@ -775,7 +775,7 @@ BEGIN_COMMAND(MoveObject) } else { - CMatrix3D m = unit->GetModel()->GetTransform(); + CMatrix3D m = unit->GetModel().GetTransform(); m_PosOld = m.GetTranslation(); } } @@ -808,9 +808,9 @@ BEGIN_COMMAND(MoveObject) } else { - CMatrix3D m = unit->GetModel()->GetTransform(); + CMatrix3D m = unit->GetModel().GetTransform(); m.Translate(pos - m.GetTranslation()); - unit->GetModel()->SetTransform(m); + unit->GetModel().SetTransform(m); } } } @@ -884,9 +884,9 @@ BEGIN_COMMAND(RotateObject) } else { - m_TransformOld = unit->GetModel()->GetTransform(); + m_TransformOld = unit->GetModel().GetTransform(); - CVector3D pos = unit->GetModel()->GetTransform().GetTranslation(); + CVector3D pos = unit->GetModel().GetTransform().GetTranslation(); float s, c; if (msg->usetarget) @@ -935,7 +935,7 @@ BEGIN_COMMAND(RotateObject) } else { - unit->GetModel()->SetTransform(transform); + unit->GetModel().SetTransform(transform); } } } diff --git a/source/tools/atlas/GameInterface/SimState.cpp b/source/tools/atlas/GameInterface/SimState.cpp index 345c991fdc..e130e9cf0f 100644 --- a/source/tools/atlas/GameInterface/SimState.cpp +++ b/source/tools/atlas/GameInterface/SimState.cpp @@ -72,8 +72,8 @@ SimState::Nonentity SimState::Nonentity::Freeze(CUnit* unit) n.actorName = unit->GetObject().m_Base->m_Name; n.unitID = unit->GetID(); n.selections = unit->GetActorSelections(); - n.position = unit->GetModel()->GetTransform().GetTranslation(); - CVector3D orient = unit->GetModel()->GetTransform().GetIn(); + n.position = unit->GetModel().GetTransform().GetTranslation(); + CVector3D orient = unit->GetModel().GetTransform().GetIn(); n.angle = atan2(-orient.X, -orient.Z); return n; } @@ -87,7 +87,7 @@ CUnit* SimState::Nonentity::Thaw() CMatrix3D m; m.SetYRotation(angle + (float)M_PI); m.Translate(position); - unit->GetModel()->SetTransform(m); + unit->GetModel().SetTransform(m); unit->SetID(unitID); return unit;