Browse Source

Make the Game class an asset like the others.

legacy
Sam Hocevar sam 14 years ago
parent
commit
47bf73f680
7 changed files with 37 additions and 16 deletions
  1. +5
    -0
      src/asset.cpp
  2. +3
    -3
      src/asset.h
  3. +16
    -4
      src/game.cpp
  4. +11
    -2
      src/game.h
  5. +1
    -4
      src/gtk/editor.cpp
  6. +0
    -2
      src/test-map.cpp
  7. +1
    -1
      src/tileset.h

+ 5
- 0
src/asset.cpp View File

@@ -8,6 +8,7 @@
#endif

#include <cstdlib>
#include <cstdio>

#include "asset.h"
#include "ticker.h"
@@ -26,6 +27,10 @@ Asset::Asset() :

Asset::~Asset()
{
#if !defined FINAL_RELEASE
if (!destroy)
fprintf(stderr, "ERROR: asset destructor called directly\n");
#endif
}

Asset::Group Asset::GetGroup()


+ 3
- 3
src/asset.h View File

@@ -22,9 +22,6 @@ class Asset
friend class TickerData;

public:
Asset();
virtual ~Asset();

virtual void Ref();
virtual int Unref();

@@ -38,6 +35,9 @@ protected:
}
Group;

Asset();
virtual ~Asset();

virtual Group GetGroup();

virtual void TickGame(float delta_time);


+ 16
- 4
src/game.cpp View File

@@ -52,14 +52,20 @@ Game::~Game()
delete data;
}

void Game::SetMouse(int x, int y)
Asset::Group Game::GetGroup()
{
data->mousex = x;
data->mousey = y;
return Asset::GetGroup();
}

void Game::Render()
void Game::TickGame(float delta_time)
{
Asset::TickGame(delta_time);
}

void Game::TickRender(float delta_time)
{
Asset::TickRender(delta_time);

Scene *scene = new Scene();

data->map->Render(scene, data->mousex, data->mousey, 0);
@@ -72,6 +78,12 @@ void Game::Render()
data->font->Print(10, 10, buf);
}

void Game::SetMouse(int x, int y)
{
data->mousex = x;
data->mousey = y;
}

void Game::Quit()
{
data->done = 1;


+ 11
- 2
src/game.h View File

@@ -11,16 +11,25 @@
#if !defined __DH_GAME_H__
#define __DH_GAME_H__

#include "asset.h"

class GameData;

class Game
class Game : public Asset
{
public:
Game(char const *mapname);
~Game();

protected:
/* Inherited from Asset */
virtual Group GetGroup();
virtual void TickGame(float delta_time);
virtual void TickRender(float delta_time);

public:
/* New methods */
void SetMouse(int x, int y);
void Render();
void Quit();
int Finished();



+ 1
- 4
src/gtk/editor.cpp View File

@@ -35,7 +35,7 @@ int main(int argc, char **argv)
/* Create new top level window. */
window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Simple");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_container_set_border_width(GTK_CONTAINER(window), 5);

/* Quit form main if got delete event */
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
@@ -77,12 +77,9 @@ int main(int argc, char **argv)

video->PreRender();
Ticker::TickRender(33.33333f);

game->Render();
video->PostRender(33.33333f);
}

delete game;
delete video;

return 0;


+ 0
- 2
src/test-map.cpp View File

@@ -31,11 +31,9 @@ int main(int argc, char **argv)

video->PreRender();
Ticker::TickRender(33.33333f);
game->Render();
video->PostRender(33.33333f);
}

delete game;
delete video;

return EXIT_SUCCESS;


+ 1
- 1
src/tileset.h View File

@@ -32,7 +32,7 @@ protected:
virtual void TickRender(float delta_time);

public:
/* New implementations */
/* New methods */
char const *GetName();

void BlitTile(uint32_t id, int x, int y);


Loading…
Cancel
Save