source: trunk/src/scene.cpp @ 145

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

Remove some debug stuff.

  • Property svn:keywords set to Id
File size: 2.2 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 <cmath>
12
13#ifdef WIN32
14#   define WIN32_LEAN_AND_MEAN
15#   include <windows.h>
16#endif
17#if defined __APPLE__ && defined __MACH__
18#   include <OpenGL/gl.h>
19#else
20#   define GL_GLEXT_PROTOTYPES
21#   include <GL/gl.h>
22#endif
23
24#include "scene.h"
25#include "tiler.h"
26
27struct Tile
28{
29    uint32_t prio, code;
30    int x, y, z, o;
31};
32
33/*
34 * Scene implementation class
35 */
36
37class SceneData
38{
39    friend class Scene;
40
41private:
42    static int Compare(void const *p1, void const *p2)
43    {
44        Tile const *t1 = (Tile const *)p1;
45        Tile const *t2 = (Tile const *)p2;
46
47        return t2->prio - t1->prio;
48    }
49
50    Tile *tiles;
51    int ntiles;
52};
53
54/*
55 * Public Scene class
56 */
57
58Scene::Scene()
59{
60    data = new SceneData();
61    data->tiles = 0;
62    data->ntiles = 0;
63}
64
65Scene::~Scene()
66{
67    delete data;
68}
69
70void Scene::AddTile(uint32_t code, int x, int y, int z, int o)
71{
72    if ((data->ntiles % 1024) == 0)
73        data->tiles = (Tile *)realloc(data->tiles,
74                                      (data->ntiles + 1024) * sizeof(Tile));
75    data->tiles[data->ntiles].prio = -y - 2 * 32 * z + (o ? 0 : 32);
76    data->tiles[data->ntiles].code = code;
77    data->tiles[data->ntiles].x = x;
78    data->tiles[data->ntiles].y = y;
79    data->tiles[data->ntiles].z = z;
80    data->tiles[data->ntiles].o = o;
81    data->ntiles++;
82}
83
84void Scene::Render() // XXX: rename to Blit()
85{
86    qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);
87
88    // XXX: debug stuff
89    glPushMatrix();
90    static float f = 0.0f;
91    f += 0.05f;
92    glTranslatef(320.0f, 240.0f, 0.0f);
93    glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
94    //glRotatef(5.0f + 3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
95    //glRotatef(20.0f * cosf(f), 0.0f, 0.0f, 1.0f);
96    //glRotatef(30.0f, 0.0f, 0.0f, 1.0f);
97    glTranslatef(-320.0f, -240.0f, 0.0f);
98
99    for (int i = 0; i < data->ntiles; i++)
100        Tiler::BlitTile(data->tiles[i].code, data->tiles[i].x,
101                        data->tiles[i].y, data->tiles[i].z, data->tiles[i].o);
102
103    glPopMatrix();
104    // XXX: end of debug stuff
105
106    free(data->tiles);
107    data->tiles = 0;
108    data->ntiles = 0;
109}
110
Note: See TracBrowser for help on using the repository browser.