2 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Lugaru is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
20 #include "Animation/Skeleton.h"
21 #include "Animation/Animation.h"
22 #include "Utils/Folders.h"
25 extern bool visibleloading;
27 std::vector<Animation> Animation::animations;
29 void Animation::loadAll()
31 #define DECLARE_ANIM(id, file, height, attack, ...) if (id < loadable_anim_end) animations.emplace_back(file, height, attack);
32 #include "Animation.def"
36 void AnimationFrame::loadBaseInfo(FILE* tfile)
38 // for each joint in the skeleton...
39 for (unsigned j = 0; j < joints.size(); j++) {
40 // read joint position
41 funpackf(tfile, "Bf Bf Bf", &joints[j].position.x, &joints[j].position.y, &joints[j].position.z);
43 for (unsigned j = 0; j < joints.size(); j++) {
45 funpackf(tfile, "Bf", &joints[j].twist);
47 for (unsigned j = 0; j < joints.size(); j++) {
48 // read onground (boolean)
50 funpackf(tfile, "Bb", &uch);
51 joints[j].onground = (uch != 0);
53 // read frame speed (?)
54 funpackf(tfile, "Bf", &speed);
57 void AnimationFrame::loadTwist2(FILE* tfile)
59 for (unsigned j = 0; j < joints.size(); j++) {
60 funpackf(tfile, "Bf", &joints[j].twist2);
64 void AnimationFrame::loadLabel(FILE* tfile)
66 funpackf(tfile, "Bf", &label);
69 void AnimationFrame::loadWeaponTarget(FILE* tfile)
71 funpackf(tfile, "Bf Bf Bf", &weapontarget.x, &weapontarget.y, &weapontarget.z);
74 Animation::Animation():
82 * load an animation from file
84 Animation::Animation(const std::string& filename, anim_height_type aheight, anim_attack_type aattack):
92 // Changing the filename into something the OS can understand
93 std::string filepath = Folders::getResourcePath("Animations/"+filename);
95 LOG(std::string("Loading animation...") + filepath);
101 Game::LoadingScreen();
103 // read file in binary mode
104 tfile = Folders::openMandatoryFile( filepath, "rb" );
106 // read numframes, joints to know how much memory to allocate
107 funpackf(tfile, "Bi Bi", &numframes, &numjoints);
109 // allocate memory for everything
111 frames.resize(numframes);
113 // read binary data as animation
116 for (i = 0; i < frames.size(); i++) {
117 frames[i].joints.resize(numjoints);
118 frames[i].loadBaseInfo(tfile);
120 // read twist2 for whole animation
121 for (i = 0; i < frames.size(); i++) {
122 frames[i].loadTwist2(tfile);
124 // read label for each frame
125 for (i = 0; i < frames.size(); i++) {
126 frames[i].loadLabel(tfile);
128 // read unused weapontargetnum
130 funpackf(tfile, "Bi", &weapontargetnum);
131 // read weapontarget positions for each frame
132 for (i = 0; i < frames.size(); i++) {
133 frames[i].loadWeaponTarget(tfile);
140 // find average position of certain joints on last frames
141 // and save in endoffset
142 // (not sure what exactly this accomplishes. the y < 1 test confuses me.)
143 for (j = 0; j < numjoints; j++) {
144 if (frames.back().joints[j].position.y < 1) {
145 endoffset += frames.back().joints[j].position;
148 endoffset /= numjoints;