~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/animated_tile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: animated_tile.cpp 15299 2009-01-31 20:16:06Z smatz $ */
 
2
 
 
3
/** @file animated_tile.cpp Everything related to animated tiles. */
 
4
 
 
5
#include "stdafx.h"
 
6
#include "core/alloc_func.hpp"
 
7
#include "functions.h"
 
8
 
 
9
/** The table/list with animated tiles. */
 
10
TileIndex *_animated_tile_list = NULL;
 
11
/** The number of animated tiles in the current state. */
 
12
uint _animated_tile_count = 0;
 
13
/** The number of slots for animated tiles allocated currently. */
 
14
uint _animated_tile_allocated = 0;
 
15
 
 
16
/**
 
17
 * Removes the given tile from the animated tile table.
 
18
 * @param tile the tile to remove
 
19
 */
 
20
void DeleteAnimatedTile(TileIndex tile)
 
21
{
 
22
        for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
 
23
                if (tile == *ti) {
 
24
                        /* Remove the hole
 
25
                         * The order of the remaining elements must stay the same, otherwise the animation loop
 
26
                         * may miss a tile; that's why we must use memmove instead of just moving the last element.
 
27
                         */
 
28
                        memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
 
29
                        _animated_tile_count--;
 
30
                        MarkTileDirtyByTile(tile);
 
31
                        return;
 
32
                }
 
33
        }
 
34
}
 
35
 
 
36
/**
 
37
 * Add the given tile to the animated tile table (if it does not exist
 
38
 * on that table yet). Also increases the size of the table if necessary.
 
39
 * @param tile the tile to make animated
 
40
 */
 
41
void AddAnimatedTile(TileIndex tile)
 
42
{
 
43
        MarkTileDirtyByTile(tile);
 
44
 
 
45
        for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
 
46
                if (tile == *ti) return;
 
47
        }
 
48
 
 
49
        /* Table not large enough, so make it larger */
 
50
        if (_animated_tile_count == _animated_tile_allocated) {
 
51
                _animated_tile_allocated *= 2;
 
52
                _animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
 
53
        }
 
54
 
 
55
        _animated_tile_list[_animated_tile_count] = tile;
 
56
        _animated_tile_count++;
 
57
}
 
58
 
 
59
/**
 
60
 * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
 
61
 */
 
62
void AnimateAnimatedTiles()
 
63
{
 
64
        const TileIndex *ti = _animated_tile_list;
 
65
        while (ti < _animated_tile_list + _animated_tile_count) {
 
66
                const TileIndex curr = *ti;
 
67
                AnimateTile(curr);
 
68
                /* During the AnimateTile call, DeleteAnimatedTile could have been called,
 
69
                 * deleting an element we've already processed and pushing the rest one
 
70
                 * slot to the left. We can detect this by checking whether the index
 
71
                 * in the current slot has changed - if it has, an element has been deleted,
 
72
                 * and we should process the current slot again instead of going forward.
 
73
                 * NOTE: this will still break if more than one animated tile is being
 
74
                 *       deleted during the same AnimateTile call, but no code seems to
 
75
                 *       be doing this anyway.
 
76
                 */
 
77
                if (*ti == curr) ++ti;
 
78
        }
 
79
}
 
80
 
 
81
/**
 
82
 * Initialize all animated tile variables to some known begin point
 
83
 */
 
84
void InitializeAnimatedTiles()
 
85
{
 
86
        _animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
 
87
        _animated_tile_count = 0;
 
88
        _animated_tile_allocated = 256;
 
89
}