Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Unit.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 20 Lines | CUnit::CUnit(CObjectEntry* object, CObjectManager& objectManager, | ||||
const std::set<CStr>& actorSelections, uint32_t seed) | const std::set<CStr>& actorSelections, uint32_t seed) | ||||
: m_Object(object), m_Model(object->m_Model->Clone()), | : m_Object(object), m_Model(object->m_Model->Clone()), | ||||
m_ID(INVALID_ENTITY), m_ActorSelections(actorSelections), | m_ID(INVALID_ENTITY), m_ActorSelections(actorSelections), | ||||
m_ObjectManager(objectManager), m_Seed(seed) | m_ObjectManager(objectManager), m_Seed(seed) | ||||
{ | { | ||||
if (m_Model->ToCModel()) | if (m_Model->ToCModel()) | ||||
m_Animation = new CUnitAnimation(m_ID, m_Model->ToCModel(), m_Object); | m_Animation = new CUnitAnimation(m_ID, m_Model->ToCModel(), m_Object); | ||||
else | else | ||||
m_Animation = NULL; | m_Animation = nullptr; | ||||
} | } | ||||
CUnit::~CUnit() | CUnit::~CUnit() | ||||
{ | { | ||||
delete m_Animation; | delete m_Animation; | ||||
delete m_Model; | delete m_Model; | ||||
} | } | ||||
CUnit* CUnit::Create(const CStrW& actorName, uint32_t seed, const std::set<CStr>& selections, CObjectManager& objectManager) | CUnit* CUnit::Create(const CStrW& actorName, uint32_t seed, const std::set<CStr>& selections, CObjectManager& objectManager) | ||||
{ | { | ||||
CObjectBase* base = objectManager.FindObjectBase(actorName); | CObjectBase* base = objectManager.FindObjectBase(actorName); | ||||
if (! base) | if (! base) | ||||
return NULL; | return nullptr; | ||||
std::set<CStr> actorSelections = base->CalculateRandomVariation(seed, selections); | std::set<CStr> actorSelections = base->CalculateRandomVariation(seed, selections); | ||||
std::vector<std::set<CStr> > selectionsVec; | std::vector<std::set<CStr> > selectionsVec; | ||||
selectionsVec.push_back(actorSelections); | selectionsVec.push_back(actorSelections); | ||||
CObjectEntry* obj = objectManager.FindObjectVariation(base, selectionsVec); | CObjectEntry* obj = objectManager.FindObjectVariation(base, selectionsVec); | ||||
if (! obj) | if (! obj) | ||||
return NULL; | return nullptr; | ||||
return new CUnit(obj, objectManager, actorSelections, seed); | return new CUnit(obj, objectManager, actorSelections, seed); | ||||
} | } | ||||
void CUnit::UpdateModel(float frameTime) | void CUnit::UpdateModel(float frameTime) | ||||
{ | { | ||||
if (m_Animation) | if (m_Animation) | ||||
m_Animation->Update(frameTime*1000.0f); | m_Animation->Update(frameTime*1000.0f); | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator