- // Remove all stuff
- if(f->special_aps[j]){
- delete f->special_aps[j];
- f->special_aps[j] = NULL;
- }
- if(f->special_materials[j]){
- delete f->special_materials[j];
- f->special_materials[j] = NULL;
+ // Texture
+ f->special_tiles[j].texture =
+ tsrc->getTexture(f->tiledef_special[j].name);
+ // Alpha
+ f->special_tiles[j].alpha = f->alpha;
+ if(f->alpha == 255)
+ f->special_tiles[j].material_type = MATERIAL_ALPHA_SIMPLE;
+ else
+ f->special_tiles[j].material_type = MATERIAL_ALPHA_VERTEX;
+ // Material flags
+ f->special_tiles[j].material_flags = 0;
+ if(f->tiledef_special[j].backface_culling)
+ f->special_tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
+ if(f->tiledef_special[j].animation.type == TAT_VERTICAL_FRAMES)
+ f->special_tiles[j].material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
+ // Animation parameters
+ if(f->special_tiles[j].material_flags &
+ MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
+ {
+ // Get raw texture size to determine frame count by
+ // aspect ratio
+ video::ITexture *t = tsrc->getTextureRaw(f->tiledef_special[j].name);
+ v2u32 size = t->getOriginalSize();
+ int frame_height = (float)size.X /
+ (float)f->tiledef_special[j].animation.aspect_w *
+ (float)f->tiledef_special[j].animation.aspect_h;
+ int frame_count = size.Y / frame_height;
+ int frame_length_ms = 1000.0 *
+ f->tiledef_special[j].animation.length / frame_count;
+ f->special_tiles[j].animation_frame_count = frame_count;
+ f->special_tiles[j].animation_frame_length_ms = frame_length_ms;
+
+ // If there are no frames for an animation, switch
+ // animation off (so that having specified an animation
+ // for something but not using it in the texture pack
+ // gives no overhead)
+ if(frame_count == 1){
+ f->special_tiles[j].material_flags &=
+ ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
+ }