@@ -188,17 +188,16 @@ void NodeBox::deSerialize(std::istream &is)
188
188
189
189
void TileDef::serialize (std::ostream &os, u16 protocol_version) const
190
190
{
191
- if (protocol_version >= 26 )
191
+ if (protocol_version >= 29 )
192
+ writeU8 (os, 3 );
193
+ else if (protocol_version >= 26 )
192
194
writeU8 (os, 2 );
193
195
else if (protocol_version >= 17 )
194
196
writeU8 (os, 1 );
195
197
else
196
198
writeU8 (os, 0 );
197
199
os<<serializeString (name);
198
- writeU8 (os, animation.type );
199
- writeU16 (os, animation.aspect_w );
200
- writeU16 (os, animation.aspect_h );
201
- writeF1000 (os, animation.length );
200
+ animation.serialize (os, protocol_version);
202
201
if (protocol_version >= 17 )
203
202
writeU8 (os, backface_culling);
204
203
if (protocol_version >= 26 ) {
@@ -211,10 +210,7 @@ void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, con
211
210
{
212
211
int version = readU8 (is);
213
212
name = deSerializeString (is);
214
- animation.type = (TileAnimationType)readU8 (is);
215
- animation.aspect_w = readU16 (is);
216
- animation.aspect_h = readU16 (is);
217
- animation.length = readF1000 (is);
213
+ animation.deSerialize (is, version >= 3 ? 29 : 26 );
218
214
if (version >= 1 )
219
215
backface_culling = readU8 (is);
220
216
if (version >= 2 ) {
@@ -533,28 +529,24 @@ void ContentFeatures::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile,
533
529
if (backface_culling)
534
530
tile->material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
535
531
if (tiledef->animation .type == TAT_VERTICAL_FRAMES)
536
- tile->material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES ;
532
+ tile->material_flags |= MATERIAL_FLAG_ANIMATION ;
537
533
if (tiledef->tileable_horizontal )
538
534
tile->material_flags |= MATERIAL_FLAG_TILEABLE_HORIZONTAL;
539
535
if (tiledef->tileable_vertical )
540
536
tile->material_flags |= MATERIAL_FLAG_TILEABLE_VERTICAL;
541
537
542
538
// Animation parameters
543
539
int frame_count = 1 ;
544
- if (tile->material_flags & MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES) {
545
- // Get texture size to determine frame count by aspect ratio
546
- v2u32 size = tile->texture ->getOriginalSize ();
547
- int frame_height = (float )size.X /
548
- (float )tiledef->animation .aspect_w *
549
- (float )tiledef->animation .aspect_h ;
550
- frame_count = size.Y / frame_height;
551
- int frame_length_ms = 1000.0 * tiledef->animation .length / frame_count;
540
+ if (tile->material_flags & MATERIAL_FLAG_ANIMATION) {
541
+ int frame_length_ms;
542
+ tiledef->animation .determineParams (tile->texture ->getOriginalSize (),
543
+ &frame_count, &frame_length_ms);
552
544
tile->animation_frame_count = frame_count;
553
545
tile->animation_frame_length_ms = frame_length_ms;
554
546
}
555
547
556
548
if (frame_count == 1 ) {
557
- tile->material_flags &= ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES ;
549
+ tile->material_flags &= ~MATERIAL_FLAG_ANIMATION ;
558
550
} else {
559
551
std::ostringstream os (std::ios::binary);
560
552
tile->frames .resize (frame_count);
@@ -564,8 +556,9 @@ void ContentFeatures::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile,
564
556
FrameSpec frame;
565
557
566
558
os.str (" " );
567
- os << tiledef->name << " ^[verticalframe:"
568
- << frame_count << " :" << i;
559
+ os << tiledef->name ;
560
+ tiledef->animation .getTextureModifer (os,
561
+ tile->texture ->getOriginalSize (), i);
569
562
570
563
frame.texture = tsrc->getTextureForMesh (os.str (), &frame.texture_id );
571
564
if (tile->normal_texture )
0 commit comments