Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Model.cpp
/* Copyright (C) 2016 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 30 Lines | |||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Constructor | // Constructor | ||||
CModel::CModel(CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation) | CModel::CModel(CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation) | ||||
: m_Flags(0), m_Anim(NULL), m_AnimTime(0), m_Simulation(simulation), | : m_Flags(0), m_Anim(nullptr), m_AnimTime(0), m_Simulation(simulation), | ||||
m_BoneMatrices(NULL), m_AmmoPropPoint(NULL), m_AmmoLoadedProp(0), | m_BoneMatrices(nullptr), m_AmmoPropPoint(nullptr), m_AmmoLoadedProp(0), | ||||
m_SkeletonAnimManager(skeletonAnimManager) | m_SkeletonAnimManager(skeletonAnimManager) | ||||
{ | { | ||||
} | } | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Destructor | // Destructor | ||||
CModel::~CModel() | CModel::~CModel() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | |||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// BuildAnimation: load raw animation frame animation from given file, and build a | // BuildAnimation: load raw animation frame animation from given file, and build a | ||||
// animation specific to this model | // animation specific to this model | ||||
CSkeletonAnim* CModel::BuildAnimation(const VfsPath& pathname, const CStr& name, const CStr& ID, int frequency, float speed, float actionpos, float actionpos2, float soundpos) | CSkeletonAnim* CModel::BuildAnimation(const VfsPath& pathname, const CStr& name, const CStr& ID, int frequency, float speed, float actionpos, float actionpos2, float soundpos) | ||||
{ | { | ||||
CSkeletonAnimDef* def = m_SkeletonAnimManager.GetAnimation(pathname); | CSkeletonAnimDef* def = m_SkeletonAnimManager.GetAnimation(pathname); | ||||
if (!def) | if (!def) | ||||
return NULL; | return nullptr; | ||||
CSkeletonAnim* anim = new CSkeletonAnim(); | CSkeletonAnim* anim = new CSkeletonAnim(); | ||||
anim->m_Name = name; | anim->m_Name = name; | ||||
anim->m_ID = ID; | anim->m_ID = ID; | ||||
anim->m_Frequency = frequency; | anim->m_Frequency = frequency; | ||||
anim->m_AnimDef = def; | anim->m_AnimDef = def; | ||||
anim->m_Speed = speed; | anim->m_Speed = speed; | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// SetAnimation: set the given animation as the current animation on this model; | // SetAnimation: set the given animation as the current animation on this model; | ||||
// return false on error, else true | // return false on error, else true | ||||
bool CModel::SetAnimation(CSkeletonAnim* anim, bool once) | bool CModel::SetAnimation(CSkeletonAnim* anim, bool once) | ||||
{ | { | ||||
m_Anim = NULL; // in case something fails | m_Anim = nullptr; // in case something fails | ||||
if (anim) | if (anim) | ||||
{ | { | ||||
m_Flags &= ~MODELFLAG_NOLOOPANIMATION; | m_Flags &= ~MODELFLAG_NOLOOPANIMATION; | ||||
if (once) | if (once) | ||||
m_Flags |= MODELFLAG_NOLOOPANIMATION; | m_Flags |= MODELFLAG_NOLOOPANIMATION; | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | void CModel::AddAmmoProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry) | ||||
// we only need to invalidate the selection box here if it is based on props and their visibilities | // we only need to invalidate the selection box here if it is based on props and their visibilities | ||||
if (!m_CustomSelectionShape) | if (!m_CustomSelectionShape) | ||||
m_SelectionBoxValid = false; | m_SelectionBoxValid = false; | ||||
} | } | ||||
void CModel::ShowAmmoProp() | void CModel::ShowAmmoProp() | ||||
{ | { | ||||
if (m_AmmoPropPoint == NULL) | if (m_AmmoPropPoint == nullptr) | ||||
return; | return; | ||||
// Show the ammo prop, hide all others on the same prop point | // Show the ammo prop, hide all others on the same prop point | ||||
for (size_t i = 0; i < m_Props.size(); ++i) | for (size_t i = 0; i < m_Props.size(); ++i) | ||||
if (m_Props[i].m_Point == m_AmmoPropPoint) | if (m_Props[i].m_Point == m_AmmoPropPoint) | ||||
m_Props[i].m_Hidden = (i != m_AmmoLoadedProp); | m_Props[i].m_Hidden = (i != m_AmmoLoadedProp); | ||||
// we only need to invalidate the selection box here if it is based on props and their visibilities | // we only need to invalidate the selection box here if it is based on props and their visibilities | ||||
if (!m_CustomSelectionShape) | if (!m_CustomSelectionShape) | ||||
m_SelectionBoxValid = false; | m_SelectionBoxValid = false; | ||||
} | } | ||||
void CModel::HideAmmoProp() | void CModel::HideAmmoProp() | ||||
{ | { | ||||
if (m_AmmoPropPoint == NULL) | if (m_AmmoPropPoint == nullptr) | ||||
return; | return; | ||||
// Hide the ammo prop, show all others on the same prop point | // Hide the ammo prop, show all others on the same prop point | ||||
for (size_t i = 0; i < m_Props.size(); ++i) | for (size_t i = 0; i < m_Props.size(); ++i) | ||||
if (m_Props[i].m_Point == m_AmmoPropPoint) | if (m_Props[i].m_Point == m_AmmoPropPoint) | ||||
m_Props[i].m_Hidden = (i == m_AmmoLoadedProp); | m_Props[i].m_Hidden = (i == m_AmmoLoadedProp); | ||||
// we only need to invalidate here if the selection box is based on props and their visibilities | // we only need to invalidate here if the selection box is based on props and their visibilities | ||||
Show All 12 Lines | for (size_t i = 0; i < m_Props.size(); ++i) | ||||
if (propModel) | if (propModel) | ||||
{ | { | ||||
CModelAbstract* model = propModel->FindFirstAmmoProp(); | CModelAbstract* model = propModel->FindFirstAmmoProp(); | ||||
if (model) | if (model) | ||||
return model; | return model; | ||||
} | } | ||||
} | } | ||||
return NULL; | return nullptr; | ||||
} | } | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Clone: return a clone of this model | // Clone: return a clone of this model | ||||
CModelAbstract* CModel::Clone() const | CModelAbstract* CModel::Clone() const | ||||
{ | { | ||||
CModel* clone = new CModel(m_SkeletonAnimManager, m_Simulation); | CModel* clone = new CModel(m_SkeletonAnimManager, m_Simulation); | ||||
clone->m_ObjectBounds = m_ObjectBounds; | clone->m_ObjectBounds = m_ObjectBounds; | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator