Browse Source

Change the way the Scene object works.

legacy
Sam Hocevar sam 14 years ago
parent
commit
4c278a0895
7 changed files with 32 additions and 9 deletions
  1. +2
    -1
      src/layer.cpp
  2. +1
    -3
      src/layer.h
  3. +2
    -2
      src/map.cpp
  4. +1
    -3
      src/map.h
  5. +18
    -0
      src/scene.cpp
  6. +3
    -0
      src/scene.h
  7. +5
    -0
      src/ticker.cpp

+ 2
- 1
src/layer.cpp View File

@@ -40,8 +40,9 @@ Layer::~Layer()
free(data); free(data);
} }


void Layer::Render(Scene *scene, int x, int y, int z)
void Layer::Render(int x, int y, int z)
{ {
Scene *scene = Scene::GetDefault();
for (int j = 0; j < height; j++) for (int j = 0; j < height; j++)
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
if (data[j * width + i]) if (data[j * width + i])


+ 1
- 3
src/layer.h View File

@@ -19,8 +19,6 @@


#include <stdint.h> #include <stdint.h>


#include "scene.h"

class Layer class Layer
{ {
public: public:
@@ -29,7 +27,7 @@ public:


int GetZ(); int GetZ();


void Render(Scene *scene, int x, int y, int z);
void Render(int x, int y, int z);


private: private:
int width, height, altitude, orientation; int width, height, altitude, orientation;


+ 2
- 2
src/map.cpp View File

@@ -160,10 +160,10 @@ Map::~Map()
delete data; delete data;
} }


void Map::Render(Scene *scene, int x, int y, int z)
void Map::Render(int x, int y, int z)
{ {
for (int i = 0; i < data->nlayers; i++) for (int i = 0; i < data->nlayers; i++)
data->layers[i]->Render(scene, x, y, z);
data->layers[i]->Render(x, y, z);
} }


int Map::GetWidth() int Map::GetWidth()


+ 1
- 3
src/map.h View File

@@ -18,8 +18,6 @@
#if !defined __DH_MAP_H__ #if !defined __DH_MAP_H__
#define __DH_MAP_H__ #define __DH_MAP_H__


#include "scene.h"

class MapData; class MapData;


class Map class Map
@@ -28,7 +26,7 @@ public:
Map(char const *path); Map(char const *path);
~Map(); ~Map();


void Render(Scene *scene, int x, int y, int z);
void Render(int x, int y, int z);
int GetWidth(); int GetWidth();
int GetHeight(); int GetHeight();




+ 18
- 0
src/scene.cpp View File

@@ -54,8 +54,12 @@ private:
Tile *tiles; Tile *tiles;
int ntiles; int ntiles;
float angle; float angle;

static Scene *scene;
}; };


Scene *SceneData::scene = NULL;

/* /*
* Public Scene class * Public Scene class
*/ */
@@ -73,6 +77,20 @@ Scene::~Scene()
delete data; delete data;
} }


Scene *Scene::GetDefault()
{
if (!SceneData::scene)
SceneData::scene = new Scene(0.0f);
return SceneData::scene;
}

void Scene::Reset()
{
if (SceneData::scene)
delete SceneData::scene;
SceneData::scene = NULL;
}

void Scene::AddTile(uint32_t code, int x, int y, int z, int o) void Scene::AddTile(uint32_t code, int x, int y, int z, int o)
{ {
if ((data->ntiles % 1024) == 0) if ((data->ntiles % 1024) == 0)


+ 3
- 0
src/scene.h View File

@@ -26,6 +26,9 @@ public:
Scene(float angle); Scene(float angle);
~Scene(); ~Scene();


static Scene *GetDefault();
static void Reset();

void AddTile(uint32_t code, int x, int y, int z, int o); void AddTile(uint32_t code, int x, int y, int z, int o);
void Render(); void Render();




+ 5
- 0
src/ticker.cpp View File

@@ -224,12 +224,15 @@ void Ticker::TickDraw()
{ {
Profiler::Start(Profiler::STAT_TICK_DRAW); Profiler::Start(Profiler::STAT_TICK_DRAW);


Scene::GetDefault();

/* Tick objects for the draw loop */ /* Tick objects for the draw loop */
for (int i = Entity::DRAWGROUP_BEGIN; i < Entity::DRAWGROUP_END; i++) for (int i = Entity::DRAWGROUP_BEGIN; i < Entity::DRAWGROUP_END; i++)
{ {
switch (i) switch (i)
{ {
case Entity::DRAWGROUP_HUD: case Entity::DRAWGROUP_HUD:
Scene::GetDefault()->Render();
Video::SetDepth(false); Video::SetDepth(false);
break; break;
default: default:
@@ -254,6 +257,8 @@ void Ticker::TickDraw()
} }
} }


Scene::Reset();

Profiler::Stop(Profiler::STAT_TICK_DRAW); Profiler::Stop(Profiler::STAT_TICK_DRAW);
Profiler::Start(Profiler::STAT_TICK_BLIT); Profiler::Start(Profiler::STAT_TICK_BLIT);
} }


Loading…
Cancel
Save