Ignore:
Timestamp:
Jul 8, 2010, 2:00:13 AM (11 years ago)
Author:
sam
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scene.cpp

    r75 r79  
     1
     2#include <stdlib.h>
    13
    24#include "scene.h"
     5#include "tiler.h"
     6
     7struct Tile
     8{
     9    uint32_t prio, code;
     10    int x, y;
     11};
    312
    413/*
     
    1120
    1221private:
    13     int dummy;
     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;
    1432};
    1533
     
    2139{
    2240    data = new SceneData();
     41    data->tiles = 0;
     42    data->ntiles = 0;
    2343}
    2444
     
    2848}
    2949
     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 TracChangeset for help on using the changeset viewer.