source: trunk/src/ticker.cpp @ 94

Last change on this file since 94 was 94, checked in by sam, 11 years ago

Implement a clean class for various assets that can be ticked both in
the game context and in the render context, and a ticker class that
takes care of the ticking.

  • Property svn:keywords set to Id
File size: 1019 bytes
Line 
1
2/*
3 * The ticker
4 */
5
6#include <stdint.h>
7#include <stdlib.h>
8
9#include "ticker.h"
10#include "asset.h"
11
12/*
13 * Ticker implementation class
14 */
15
16static class TickerData
17{
18    friend class Ticker;
19
20public:
21    TickerData() :
22        assets(0),
23        nassets(0)
24    {
25        /* Nothing to do */
26    }
27
28    ~TickerData()
29    {
30        free(assets);
31    }
32
33private:
34    Asset **assets;
35    int nassets;
36}
37tickerdata;
38
39static TickerData * const data = &tickerdata;
40
41/*
42 * Ticker public class
43 */
44
45void Ticker::Register(Asset *asset)
46{
47    int tmp = data->nassets++;
48    data->assets = (Asset **)realloc(data->assets,
49                                     data->nassets * sizeof(Asset *));
50    data->assets[tmp] = asset;
51
52    asset->index = tmp;
53}
54
55void Ticker::TickGame(float delta_time)
56{
57    for (int i = 0; i < data->nassets; i++)
58        data->assets[i]->TickGame(delta_time);
59}
60
61void Ticker::TickRender(float delta_time)
62{
63    for (int i = 0; i < data->nassets; i++)
64        data->assets[i]->TickRender(delta_time);
65}
66
Note: See TracBrowser for help on using the repository browser.