source: trunk/src/ticker.cpp @ 100

Last change on this file since 100 was 100, checked in by sam, 10 years ago

Slightly improve the documentation in a few files, add the missing
joystick class, and put a header in each source file.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdlib>
11#include <cstdio>
12#include <stdint.h>
13
14#include "ticker.h"
15#include "asset.h"
16
17/*
18 * Ticker implementation class
19 */
20
21static class TickerData
22{
23    friend class Ticker;
24
25public:
26    TickerData() :
27        list(0),
28        nassets(0)
29    {
30    }
31
32    ~TickerData()
33    {
34        if (nassets)
35            fprintf(stderr, "ERROR: still %i assets in ticker\n", nassets);
36    }
37
38private:
39    Asset *list;
40    int nassets;
41}
42tickerdata;
43
44static TickerData * const data = &tickerdata;
45
46/*
47 * Ticker public class
48 */
49
50void Ticker::Register(Asset *asset)
51{
52    asset->next = data->list;
53    data->list = asset;
54    data->nassets++;
55}
56
57void Ticker::TickGame(float delta_time)
58{
59    /* Garbage collect objects that can be destroyed */
60    for (Asset *asset = data->list, *prev = NULL;
61         asset;
62         prev = asset, asset = asset->next)
63        if (asset->destroy)
64        {
65            if (prev)
66                prev->next = asset->next;
67            else
68                data->list = asset->next;
69
70            data->nassets--;
71            delete asset;
72        }
73
74    /* Tick objects for the game loop */
75    for (Asset *asset = data->list; asset; asset = asset->next)
76        asset->TickGame(delta_time);
77}
78
79void Ticker::TickRender(float delta_time)
80{
81    /* Tick objects for the render loop */
82    for (Asset *asset = data->list; asset; asset = asset->next)
83        asset->TickRender(delta_time);
84}
85
Note: See TracBrowser for help on using the repository browser.