Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ObjectEntry.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 25 Lines | |||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include <sstream> | #include <sstream> | ||||
CObjectEntry::CObjectEntry(CObjectBase* base, CSimulation2& simulation) : | CObjectEntry::CObjectEntry(CObjectBase* base, CSimulation2& simulation) : | ||||
m_Base(base), m_Color(1.0f, 1.0f, 1.0f, 1.0f), m_Model(NULL), m_Outdated(false), m_Simulation(simulation) | m_Base(base), m_Color(1.0f, 1.0f, 1.0f, 1.0f), m_Model(nullptr), m_Outdated(false), m_Simulation(simulation) | ||||
{ | { | ||||
} | } | ||||
CObjectEntry::~CObjectEntry() | CObjectEntry::~CObjectEntry() | ||||
{ | { | ||||
for (const std::pair<CStr, CSkeletonAnim*>& anim : m_Animations) | for (const std::pair<CStr, CSkeletonAnim*>& anim : m_Animations) | ||||
delete anim.second; | delete anim.second; | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr> >& selections, | ||||
} | } | ||||
// ensure there's always an idle animation | // ensure there's always an idle animation | ||||
if (m_Animations.find("idle") == m_Animations.end()) | if (m_Animations.find("idle") == m_Animations.end()) | ||||
{ | { | ||||
CSkeletonAnim* anim = new CSkeletonAnim(); | CSkeletonAnim* anim = new CSkeletonAnim(); | ||||
anim->m_Name = "idle"; | anim->m_Name = "idle"; | ||||
anim->m_ID = ""; | anim->m_ID = ""; | ||||
anim->m_AnimDef = NULL; | anim->m_AnimDef = nullptr; | ||||
anim->m_Frequency = 0; | anim->m_Frequency = 0; | ||||
anim->m_Speed = 0.f; | anim->m_Speed = 0.f; | ||||
anim->m_ActionPos = 0.f; | anim->m_ActionPos = 0.f; | ||||
anim->m_ActionPos2 = 0.f; | anim->m_ActionPos2 = 0.f; | ||||
anim->m_SoundPos = 0.f; | anim->m_SoundPos = 0.f; | ||||
m_Animations.insert(std::make_pair("idle", anim)); | m_Animations.insert(std::make_pair("idle", anim)); | ||||
// Ignore errors, since they're probably saying this is a non-animated model | // Ignore errors, since they're probably saying this is a non-animated model | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | CSkeletonAnim* CObjectEntry::GetRandomAnimation(const CStr& animationName, const CStr& ID) const | ||||
int r = rand(0, totalFreq); | int r = rand(0, totalFreq); | ||||
for (CSkeletonAnim* anim : anims) | for (CSkeletonAnim* anim : anims) | ||||
{ | { | ||||
r -= anim->m_Frequency; | r -= anim->m_Frequency; | ||||
if (r < 0) | if (r < 0) | ||||
return anim; | return anim; | ||||
} | } | ||||
return NULL; | return nullptr; | ||||
} | } | ||||
std::vector<CSkeletonAnim*> CObjectEntry::GetAnimations(const CStr& animationName, const CStr& ID) const | std::vector<CSkeletonAnim*> CObjectEntry::GetAnimations(const CStr& animationName, const CStr& ID) const | ||||
{ | { | ||||
std::vector<CSkeletonAnim*> anims; | std::vector<CSkeletonAnim*> anims; | ||||
SkeletonAnimMap::const_iterator lower = m_Animations.lower_bound(animationName); | SkeletonAnimMap::const_iterator lower = m_Animations.lower_bound(animationName); | ||||
SkeletonAnimMap::const_iterator upper = m_Animations.upper_bound(animationName); | SkeletonAnimMap::const_iterator upper = m_Animations.upper_bound(animationName); | ||||
Show All 18 Lines |
Wildfire Games · Phabricator