aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/animationresource.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2010-08-06 13:13:25 +0000
committerEugene Sandulenko2010-10-12 22:35:55 +0000
commit47904bc7b2992189bb554833f00a79ff0fea9fb8 (patch)
tree1cec51758c6741b970bd064fafee77607b9f884f /engines/sword25/gfx/animationresource.cpp
parentca17def625154e5f758b797e4fc48c76b0566320 (diff)
downloadscummvm-rg350-47904bc7b2992189bb554833f00a79ff0fea9fb8.tar.gz
scummvm-rg350-47904bc7b2992189bb554833f00a79ff0fea9fb8.tar.bz2
scummvm-rg350-47904bc7b2992189bb554833f00a79ff0fea9fb8.zip
SWORD25: Mass-astyle.
svn-id: r53222
Diffstat (limited to 'engines/sword25/gfx/animationresource.cpp')
-rw-r--r--engines/sword25/gfx/animationresource.cpp170
1 files changed, 69 insertions, 101 deletions
diff --git a/engines/sword25/gfx/animationresource.cpp b/engines/sword25/gfx/animationresource.cpp
index 5de3d90ff2..a0a7f25057 100644
--- a/engines/sword25/gfx/animationresource.cpp
+++ b/engines/sword25/gfx/animationresource.cpp
@@ -23,7 +23,7 @@
*
*/
-/*
+/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
@@ -54,34 +54,31 @@ namespace Sword25 {
// Constants
// -----------------------------------------------------------------------------
-namespace
-{
- const int DEFAULT_FPS = 10;
- const int MIN_FPS = 1;
- const int MAX_FPS = 200;
+namespace {
+const int DEFAULT_FPS = 10;
+const int MIN_FPS = 1;
+const int MAX_FPS = 200;
}
// -----------------------------------------------------------------------------
// Construction / Destruction
// -----------------------------------------------------------------------------
-BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
+BS_AnimationResource::BS_AnimationResource(const Common::String &FileName) :
BS_Resource(FileName, BS_Resource::TYPE_ANIMATION),
- m_Valid(false)
-{
+ m_Valid(false) {
// Pointer auf den Package-Manager bekommen
- BS_PackageManager* PackagePtr = BS_Kernel::GetInstance()->GetPackage();
+ BS_PackageManager *PackagePtr = BS_Kernel::GetInstance()->GetPackage();
BS_ASSERT(PackagePtr);
// Animations-XML laden
TiXmlDocument Doc;
{
- // Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert und
+ // Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert und
// NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
unsigned int FileSize;
- char * LoadBuffer = (char *) PackagePtr->GetFile(GetFileName(), &FileSize);
- if (!LoadBuffer)
- {
+ char *LoadBuffer = (char *) PackagePtr->GetFile(GetFileName(), &FileSize);
+ if (!LoadBuffer) {
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
return;
}
@@ -94,27 +91,24 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
// Datei parsen
Doc.Parse(&WorkBuffer[0]);
free(WorkBuffer);
- if (Doc.Error())
- {
+ if (Doc.Error()) {
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
return;
}
}
// Wurzelknoten des Animations-Tags finden, prüfen und Attribute auslesen.
- TiXmlElement* pElement;
+ TiXmlElement *pElement;
{
- TiXmlNode* pNode = Doc.FirstChild("animation");
- if (!pNode || pNode->Type() != TiXmlNode::ELEMENT)
- {
+ TiXmlNode *pNode = Doc.FirstChild("animation");
+ if (!pNode || pNode->Type() != TiXmlNode::ELEMENT) {
BS_LOG_ERRORLN("No <animation> tag found in \"%s\".", GetFileName().c_str());
return;
}
pElement = pNode->ToElement();
// Animation-Tag parsen
- if (!ParseAnimationTag(*pElement, m_FPS, m_AnimationType))
- {
+ if (!ParseAnimationTag(*pElement, m_FPS, m_AnimationType)) {
BS_LOG_ERRORLN("An error occurred while parsing <animation> tag in \"%s\".", GetFileName().c_str());
return;
}
@@ -131,17 +125,15 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
}
// Nacheinander alle Frames-Informationen erstellen.
- TiXmlElement* pFrameElement = pElement->FirstChild("frame")->ToElement();
- while (pFrameElement)
- {
+ TiXmlElement *pFrameElement = pElement->FirstChild("frame")->ToElement();
+ while (pFrameElement) {
Frame CurFrame;
-
- if (!ParseFrameTag(*pFrameElement, CurFrame, *PackagePtr))
- {
+
+ if (!ParseFrameTag(*pFrameElement, CurFrame, *PackagePtr)) {
BS_LOG_ERRORLN("An error occurred in \"%s\" while parsing <frame> tag.", GetFileName().c_str());
return;
}
-
+
m_Frames.push_back(CurFrame);
pFrameElement = pFrameElement->NextSiblingElement("frame");
}
@@ -150,54 +142,46 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
PackagePtr->ChangeDirectory(OldDirectory);
// Sicherstellen, dass die Animation mindestens einen Frame besitzt
- if (m_Frames.empty())
- {
+ if (m_Frames.empty()) {
BS_LOG_ERRORLN("\"%s\" does not have any frames.", GetFileName().c_str());
return;
}
// Alle Frame-Dateien werden vorgecached
- if (!PrecacheAllFrames())
- {
+ if (!PrecacheAllFrames()) {
BS_LOG_ERRORLN("Could not precache all frames of \"%s\".", GetFileName().c_str());
return;
}
// Feststellen, ob die Animation skalierbar ist
- if (!ComputeFeatures())
- {
- BS_LOG_ERRORLN("Could not determine the features of \"%s\".", GetFileName().c_str());
- return;
- }
+ if (!ComputeFeatures()) {
+ BS_LOG_ERRORLN("Could not determine the features of \"%s\".", GetFileName().c_str());
+ return;
+ }
- m_Valid = true;
+ m_Valid = true;
}
// -----------------------------------------------------------------------------
// Dokument-Parsermethoden
// -----------------------------------------------------------------------------
-bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FPS, BS_Animation::ANIMATION_TYPES & AnimationType)
-{
+bool BS_AnimationResource::ParseAnimationTag(TiXmlElement &AnimationTag, int &FPS, BS_Animation::ANIMATION_TYPES &AnimationType) {
// FPS einlesen
- const char* FPSString;
- if (FPSString = AnimationTag.Attribute("fps"))
- {
+ const char *FPSString;
+ if (FPSString = AnimationTag.Attribute("fps")) {
int TempFPS;
- if (!BS_String::ToInt(Common::String(FPSString), TempFPS) || TempFPS < MIN_FPS || TempFPS > MAX_FPS)
- {
+ if (!BS_String::ToInt(Common::String(FPSString), TempFPS) || TempFPS < MIN_FPS || TempFPS > MAX_FPS) {
BS_LOG_WARNINGLN("Illegal fps value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"%d\"). "
- "The fps value has to be between %d and %d.",
- FPSString, GetFileName().c_str(), DEFAULT_FPS, MIN_FPS, MAX_FPS);
- }
- else
+ "The fps value has to be between %d and %d.",
+ FPSString, GetFileName().c_str(), DEFAULT_FPS, MIN_FPS, MAX_FPS);
+ } else
FPS = TempFPS;
}
// Loop-Typ einlesen
- const char* LoopTypeString;
- if (LoopTypeString = AnimationTag.Attribute("type"))
- {
+ const char *LoopTypeString;
+ if (LoopTypeString = AnimationTag.Attribute("type")) {
if (strcmp(LoopTypeString, "oneshot") == 0)
AnimationType = BS_Animation::AT_ONESHOT;
else if (strcmp(LoopTypeString, "loop") == 0)
@@ -206,7 +190,7 @@ bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FP
AnimationType = BS_Animation::AT_JOJO;
else
BS_LOG_WARNINGLN("Illegal type value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"loop\").",
- LoopTypeString, GetFileName().c_str());
+ LoopTypeString, GetFileName().c_str());
}
return true;
@@ -214,68 +198,59 @@ bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FP
// -----------------------------------------------------------------------------
-bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_, BS_PackageManager& PackageManager)
-{
- const char* FileString = FrameTag.Attribute("file");
- if (!FileString)
- {
+bool BS_AnimationResource::ParseFrameTag(TiXmlElement &FrameTag, Frame &Frame_, BS_PackageManager &PackageManager) {
+ const char *FileString = FrameTag.Attribute("file");
+ if (!FileString) {
BS_LOG_ERRORLN("<frame> tag without file attribute occurred in \"%s\".", GetFileName().c_str());
return false;
}
Frame_.FileName = PackageManager.GetAbsolutePath(FileString);
- if (Frame_.FileName == "")
- {
+ if (Frame_.FileName == "") {
BS_LOG_ERRORLN("Could not create absolute path for file specified in <frame> tag in \"%s\": \"%s\".", GetFileName().c_str(), FileString);
return false;
}
- const char* ActionString = FrameTag.Attribute("action");
+ const char *ActionString = FrameTag.Attribute("action");
if (ActionString)
Frame_.Action = ActionString;
- const char* HotspotxString = FrameTag.Attribute("hotspotx");
- const char* HotspotyString = FrameTag.Attribute("hotspoty");
+ const char *HotspotxString = FrameTag.Attribute("hotspotx");
+ const char *HotspotyString = FrameTag.Attribute("hotspoty");
if ((!HotspotxString && HotspotyString) ||
- (HotspotxString && !HotspotyString))
+ (HotspotxString && !HotspotyString))
BS_LOG_WARNINGLN("%s attribute occurred without %s attribute in <frame> tag in \"%s\". Assuming default (\"0\").",
- HotspotxString ? "hotspotx" : "hotspoty",
- !HotspotyString ? "hotspoty" : "hotspotx",
- GetFileName().c_str());
+ HotspotxString ? "hotspotx" : "hotspoty",
+ !HotspotyString ? "hotspoty" : "hotspotx",
+ GetFileName().c_str());
Frame_.HotspotX = 0;
if (HotspotxString && !BS_String::ToInt(Common::String(HotspotxString), Frame_.HotspotX))
BS_LOG_WARNINGLN("Illegal hotspotx value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
- HotspotxString,GetFileName().c_str(), Frame_.HotspotX);
+ HotspotxString, GetFileName().c_str(), Frame_.HotspotX);
Frame_.HotspotY = 0;
if (HotspotyString && !BS_String::ToInt(Common::String(HotspotyString), Frame_.HotspotY))
BS_LOG_WARNINGLN("Illegal hotspoty value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
- HotspotyString, GetFileName().c_str(), Frame_.HotspotY);
+ HotspotyString, GetFileName().c_str(), Frame_.HotspotY);
- const char* FlipVString = FrameTag.Attribute("flipv");
- if (FlipVString)
- {
- if (!BS_String::ToBool(Common::String(FlipVString), Frame_.FlipV))
- {
+ const char *FlipVString = FrameTag.Attribute("flipv");
+ if (FlipVString) {
+ if (!BS_String::ToBool(Common::String(FlipVString), Frame_.FlipV)) {
BS_LOG_WARNINGLN("Illegal flipv value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
- FlipVString, GetFileName().c_str());
+ FlipVString, GetFileName().c_str());
Frame_.FlipV = false;
}
- }
- else
+ } else
Frame_.FlipV = false;
- const char* FlipHString = FrameTag.Attribute("fliph");
- if (FlipHString)
- {
- if (!BS_String::ToBool(FlipHString, Frame_.FlipH))
- {
+ const char *FlipHString = FrameTag.Attribute("fliph");
+ if (FlipHString) {
+ if (!BS_String::ToBool(FlipHString, Frame_.FlipH)) {
BS_LOG_WARNINGLN("Illegal fliph value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
- FlipHString, GetFileName().c_str());
+ FlipHString, GetFileName().c_str());
Frame_.FlipH = false;
}
- }
- else
+ } else
Frame_.FlipH = false;
return true;
@@ -283,19 +258,15 @@ bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_,
// -----------------------------------------------------------------------------
-BS_AnimationResource::~BS_AnimationResource()
-{
+BS_AnimationResource::~BS_AnimationResource() {
}
// -----------------------------------------------------------------------------
-bool BS_AnimationResource::PrecacheAllFrames() const
-{
+bool BS_AnimationResource::PrecacheAllFrames() const {
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
- for (; Iter != m_Frames.end(); ++Iter)
- {
- if (!BS_Kernel::GetInstance()->GetResourceManager()->PrecacheResource((*Iter).FileName))
- {
+ for (; Iter != m_Frames.end(); ++Iter) {
+ if (!BS_Kernel::GetInstance()->GetResourceManager()->PrecacheResource((*Iter).FileName)) {
BS_LOG_ERRORLN("Could not precache \"%s\".", (*Iter).FileName.c_str());
return false;
}
@@ -306,8 +277,7 @@ bool BS_AnimationResource::PrecacheAllFrames() const
// -----------------------------------------------------------------------------
-bool BS_AnimationResource::ComputeFeatures()
-{
+bool BS_AnimationResource::ComputeFeatures() {
BS_ASSERT(m_Frames.size());
// Alle Features werden als vorhanden angenommen
@@ -317,11 +287,9 @@ bool BS_AnimationResource::ComputeFeatures()
// Alle Frame durchgehen und alle Features deaktivieren, die auch nur von einem Frame nicht unterstützt werden.
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
- for (; Iter != m_Frames.end(); ++Iter)
- {
- BS_BitmapResource* pBitmap;
- if (!(pBitmap = static_cast<BS_BitmapResource*> (BS_Kernel::GetInstance()->GetResourceManager()->RequestResource((*Iter).FileName))))
- {
+ for (; Iter != m_Frames.end(); ++Iter) {
+ BS_BitmapResource *pBitmap;
+ if (!(pBitmap = static_cast<BS_BitmapResource *>(BS_Kernel::GetInstance()->GetResourceManager()->RequestResource((*Iter).FileName)))) {
BS_LOG_ERRORLN("Could not request \"%s\".", (*Iter).FileName.c_str());
return false;
}