3 Copyright (C) 2016 sfan5 <sfan5@live.de>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "tileanimation.h"
20 #include "util/serialize.h"
22 void TileAnimationParams::serialize(std::ostream &os, u16 protocol_version) const
24 if(protocol_version < 29 /* TODO bump */) {
25 if (type == TAT_VERTICAL_FRAMES) {
27 writeU16(os, vertical_frames.aspect_w);
28 writeU16(os, vertical_frames.aspect_h);
29 writeF1000(os, vertical_frames.length);
31 writeU8(os, TAT_NONE);
40 if (type == TAT_VERTICAL_FRAMES) {
41 writeU16(os, vertical_frames.aspect_w);
42 writeU16(os, vertical_frames.aspect_h);
43 writeF1000(os, vertical_frames.length);
47 void TileAnimationParams::deSerialize(std::istream &is, u16 protocol_version)
49 type = (TileAnimationType) readU8(is);
50 if(protocol_version < 29 /* TODO bump */) {
51 vertical_frames.aspect_w = readU16(is);
52 vertical_frames.aspect_h = readU16(is);
53 vertical_frames.length = readF1000(is);
57 if(type == TAT_VERTICAL_FRAMES) {
58 vertical_frames.aspect_w = readU16(is);
59 vertical_frames.aspect_h = readU16(is);
60 vertical_frames.length = readF1000(is);
64 void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count, int *frame_length_ms) const
66 if (type == TAT_NONE) {
68 *frame_length_ms = 1000;
71 int frame_height = (float)texture_size.X /
72 (float)vertical_frames.aspect_w *
73 (float)vertical_frames.aspect_h;
75 *frame_count = texture_size.Y / frame_height;
77 *frame_length_ms = 1000.0 * vertical_frames.length / (texture_size.Y / frame_height);
80 void TileAnimationParams::getTextureModifer(std::ostream &os, v2u32 texture_size, int frame) const
85 determineParams(texture_size, &frame_count, NULL);
86 os << "^[verticalframe:" << frame_count << ":" << frame;