source: trunk/src/scene.cpp @ 79

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

Rendering starts to work again. There is no Z-sorting yet.

  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1
2#include <stdlib.h>
3
4#include "scene.h"
5#include "tiler.h"
6
7struct Tile
8{
9    uint32_t prio, code;
10    int x, y;
11};
12
13/*
14 * Scene implementation class
15 */
16
17class SceneData
18{
19    friend class Scene;
20
21private:
22    static int Compare(void const *p1, void const *p2)
23    {
24        Tile const *t1 = (Tile const *)p1;
25        Tile const *t2 = (Tile const *)p2;
26
27        return t1->prio - t2->prio;
28    }
29
30    Tile *tiles;
31    int ntiles;
32};
33
34/*
35 * Public Scene class
36 */
37
38Scene::Scene()
39{
40    data = new SceneData();
41    data->tiles = 0;
42    data->ntiles = 0;
43}
44
45Scene::~Scene()
46{
47    delete data;
48}
49
50void Scene::AddTile(uint32_t code, int x, int y, int z)
51{
52    if ((data->ntiles % 1024) == 0)
53        data->tiles = (Tile *)realloc(data->tiles,
54                                      (data->ntiles + 1024) * sizeof(Tile));
55    data->tiles[data->ntiles].prio = 0;
56    data->tiles[data->ntiles].code = code;
57    data->tiles[data->ntiles].x = x;
58    data->tiles[data->ntiles].y = y;
59    data->ntiles++;
60}
61
62void Scene::Render() // XXX: rename to Blit()
63{
64    qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);
65
66    for (int i = 0; i < data->ntiles; i++)
67        Tiler::Render(data->tiles[i].code, data->tiles[i].x, data->tiles[i].y);
68
69    free(data->tiles);
70    data->tiles = 0;
71    data->ntiles = 0;
72}
73
Note: See TracBrowser for help on using the repository browser.