@@ -1,5 +1,5 @@ | |||||
#include <malloc.h> | |||||
#include <cstdlib> | |||||
#include "asset.h" | #include "asset.h" | ||||
#include "ticker.h" | #include "ticker.h" | ||||
@@ -9,7 +9,7 @@ | |||||
*/ | */ | ||||
Asset::Asset() : | Asset::Asset() : | ||||
index(0), | |||||
next(0), | |||||
ref(0), | ref(0), | ||||
destroy(0) | destroy(0) | ||||
{ | { | ||||
@@ -23,7 +23,8 @@ public: | |||||
virtual int Unref(); | virtual int Unref(); | ||||
protected: | protected: | ||||
int index, ref, destroy; | |||||
Asset *next; | |||||
int ref, destroy; | |||||
}; | }; | ||||
#endif // __DH_ASSET_H__ | #endif // __DH_ASSET_H__ | ||||
@@ -1,17 +1,17 @@ | |||||
#include <SDL.h> | |||||
#include <stdio.h> | |||||
#include <math.h> | |||||
#include <cstdio> | |||||
#include <cmath> | |||||
#include "gtkvideo.h" | |||||
#include "ticker.h" | |||||
#include "game.h" | |||||
#include <SDL.h> | |||||
#include <math.h> | |||||
#include <gtk/gtk.h> | #include <gtk/gtk.h> | ||||
#include <gtkgl/gtkglarea.h> | #include <gtkgl/gtkglarea.h> | ||||
#include <GL/gl.h> | #include <GL/gl.h> | ||||
#include "gtkvideo.h" | |||||
#include "ticker.h" | |||||
#include "game.h" | |||||
volatile int quit = 0; | volatile int quit = 0; | ||||
static gint main_quit(GtkWidget *widget, GdkEventExpose *event) | static gint main_quit(GtkWidget *widget, GdkEventExpose *event) | ||||
@@ -1,4 +1,6 @@ | |||||
#include <cstdlib> | |||||
#include <gtk/gtk.h> | #include <gtk/gtk.h> | ||||
#include <gtkgl/gtkglarea.h> | #include <gtkgl/gtkglarea.h> | ||||
@@ -13,8 +15,6 @@ | |||||
# include <GL/gl.h> | # include <GL/gl.h> | ||||
#endif | #endif | ||||
#include <stdlib.h> | |||||
#include "gtkvideo.h" | #include "gtkvideo.h" | ||||
/* | /* | ||||
@@ -2,7 +2,6 @@ | |||||
#include <cstdio> | #include <cstdio> | ||||
#include <cstring> | #include <cstring> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <malloc.h> | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include "map.h" | #include "map.h" | ||||
@@ -1,9 +1,9 @@ | |||||
// Test stuff | // Test stuff | ||||
#include <SDL.h> | |||||
#include <cstdio> | |||||
#include <cmath> | |||||
#include <stdio.h> | |||||
#include <math.h> | |||||
#include <SDL.h> | |||||
#include "sdlvideo.h" | #include "sdlvideo.h" | ||||
#include "game.h" | #include "game.h" | ||||
@@ -3,8 +3,9 @@ | |||||
* The ticker | * The ticker | ||||
*/ | */ | ||||
#include <cstdlib> | |||||
#include <cstdio> | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdlib.h> | |||||
#include "ticker.h" | #include "ticker.h" | ||||
#include "asset.h" | #include "asset.h" | ||||
@@ -19,19 +20,19 @@ static class TickerData | |||||
public: | public: | ||||
TickerData() : | TickerData() : | ||||
assets(0), | |||||
list(0), | |||||
nassets(0) | nassets(0) | ||||
{ | { | ||||
/* Nothing to do */ | |||||
} | } | ||||
~TickerData() | ~TickerData() | ||||
{ | { | ||||
free(assets); | |||||
if (nassets) | |||||
fprintf(stderr, "ERROR: still %i assets in ticker\n", nassets); | |||||
} | } | ||||
private: | private: | ||||
Asset **assets; | |||||
Asset *list; | |||||
int nassets; | int nassets; | ||||
} | } | ||||
tickerdata; | tickerdata; | ||||
@@ -44,23 +45,37 @@ static TickerData * const data = &tickerdata; | |||||
void Ticker::Register(Asset *asset) | void Ticker::Register(Asset *asset) | ||||
{ | { | ||||
int tmp = data->nassets++; | |||||
data->assets = (Asset **)realloc(data->assets, | |||||
data->nassets * sizeof(Asset *)); | |||||
data->assets[tmp] = asset; | |||||
asset->index = tmp; | |||||
asset->next = data->list; | |||||
data->list = asset; | |||||
data->nassets++; | |||||
} | } | ||||
void Ticker::TickGame(float delta_time) | void Ticker::TickGame(float delta_time) | ||||
{ | { | ||||
for (int i = 0; i < data->nassets; i++) | |||||
data->assets[i]->TickGame(delta_time); | |||||
/* Garbage collect objects that can be destroyed */ | |||||
for (Asset *asset = data->list, *prev = NULL; | |||||
asset; | |||||
prev = asset, asset = asset->next) | |||||
if (asset->destroy) | |||||
{ | |||||
if (prev) | |||||
prev->next = asset->next; | |||||
else | |||||
data->list = asset->next; | |||||
data->nassets--; | |||||
delete asset; | |||||
} | |||||
/* Tick objects for the game loop */ | |||||
for (Asset *asset = data->list; asset; asset = asset->next) | |||||
asset->TickGame(delta_time); | |||||
} | } | ||||
void Ticker::TickRender(float delta_time) | void Ticker::TickRender(float delta_time) | ||||
{ | { | ||||
for (int i = 0; i < data->nassets; i++) | |||||
data->assets[i]->TickRender(delta_time); | |||||
/* Tick objects for the render loop */ | |||||
for (Asset *asset = data->list; asset; asset = asset->next) | |||||
asset->TickRender(delta_time); | |||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
#include <cstring> | #include <cstring> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <stdlib.h> | |||||
#include <cstdlib> | |||||
#include "tiler.h" | #include "tiler.h" | ||||
#include "tileset.h" | #include "tileset.h" | ||||
@@ -28,6 +28,8 @@ public: | |||||
~TilerData() | ~TilerData() | ||||
{ | { | ||||
if (ntilesets) | |||||
fprintf(stderr, "ERROR: still %i tilesets in tiler\n", ntilesets); | |||||
free(tilesets); | free(tilesets); | ||||
} | } | ||||
@@ -81,10 +83,7 @@ void Tiler::Deregister(int id) | |||||
--id; /* ID 0 is for the empty tileset */ | --id; /* ID 0 is for the empty tileset */ | ||||
if (data->tilesets[id]->Unref() == 0) | if (data->tilesets[id]->Unref() == 0) | ||||
{ | |||||
delete data->tilesets[id]; | |||||
data->tilesets[id] = NULL; | data->tilesets[id] = NULL; | ||||
} | |||||
} | } | ||||
void Tiler::Render(uint32_t code, int x, int y) | void Tiler::Render(uint32_t code, int x, int y) | ||||
@@ -1,4 +1,6 @@ | |||||
#include <cstdlib> | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
# define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
# include <windows.h> | # include <windows.h> | ||||
@@ -13,8 +15,6 @@ | |||||
#include <SDL.h> | #include <SDL.h> | ||||
#include <SDL_image.h> | #include <SDL_image.h> | ||||
#include <malloc.h> | |||||
#include "tileset.h" | #include "tileset.h" | ||||
/* | /* | ||||