@@ -7,26 +7,27 @@ Important stuff | |||||
[ ] Map collisions? | [ ] Map collisions? | ||||
[ ] Add scripting support (lua?). | [ ] Add scripting support (lua?). | ||||
[ ] Open several maps at the same time. | [ ] Open several maps at the same time. | ||||
[ ] See whether we should use floats or at least subpixel coordinates for | |||||
on-screen objects, in order to handle velocity and other physics stuff | |||||
(with rounding when displaying, of course) | |||||
Performances | Performances | ||||
------------ | ------------ | ||||
[ ] Switch rendering to vertex/index buffer objects | [ ] Switch rendering to vertex/index buffer objects | ||||
Editor | Editor | ||||
------ | ------ | ||||
[ ] File requester for maps. | [ ] File requester for maps. | ||||
[ ] Scroller/panner for maps. | [ ] Scroller/panner for maps. | ||||
[ ] Allow to modify maps. | [ ] Allow to modify maps. | ||||
[ ] Do GTK stuff instead of waiting for the framerate | |||||
[x] Do GTK stuff instead of waiting for the framerate | |||||
[ ] "map viewer" object/asset, as opposed to more complex in-game manager | |||||
Specs | Specs | ||||
----- | ----- | ||||
[ ] Write a map file format. | [ ] Write a map file format. | ||||
[ ] Add special zones to the map. | [ ] Add special zones to the map. | ||||
Architecture | Architecture | ||||
------------ | ------------ | ||||
[ ] Tiler and Forge are almost the same, try to refactor them. | [ ] Tiler and Forge are almost the same, try to refactor them. | ||||
@@ -84,7 +84,7 @@ static gint draw(GtkWidget *widget, GdkEventExpose *event) | |||||
gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); | gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); | ||||
while (g_main_context_iteration(NULL, FALSE)) | while (g_main_context_iteration(NULL, FALSE)) | ||||
; | ; | ||||
Ticker::ClampFps(FPS); | |||||
Ticker::ClampFps(1.0f / FPS); | |||||
} | } | ||||
return TRUE; | return TRUE; | ||||
@@ -16,8 +16,6 @@ | |||||
#include "layer.h" | #include "layer.h" | ||||
#include "tiler.h" | #include "tiler.h" | ||||
#define MAX_TILERS 128 | |||||
/* | /* | ||||
* Map implementation class | * Map implementation class | ||||
*/ | */ | ||||
@@ -26,11 +24,16 @@ class MapData | |||||
{ | { | ||||
friend class Map; | friend class Map; | ||||
static int const MAX_TILERS = 128; | |||||
private: | private: | ||||
int tilers[MAX_TILERS]; | int tilers[MAX_TILERS]; | ||||
int ntilers; | int ntilers; | ||||
Layer **layers; | Layer **layers; | ||||
int nlayers; | int nlayers; | ||||
int width, height; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -43,11 +46,13 @@ Map::Map(char const *path) | |||||
data->ntilers = 0; | data->ntilers = 0; | ||||
data->layers = NULL; | data->layers = NULL; | ||||
data->nlayers = 0; | data->nlayers = 0; | ||||
data->width = 0; | |||||
data->height = 0; | |||||
char tmp[BUFSIZ]; | char tmp[BUFSIZ]; | ||||
int gids[MAX_TILERS]; | |||||
int gids[MapData::MAX_TILERS]; | |||||
uint32_t *tiles = NULL; | uint32_t *tiles = NULL; | ||||
int width = 0, height = 0, level = 0, orientation = 0, ntiles = 0; | |||||
int level = 0, orientation = 0, ntiles = 0; | |||||
FILE *fp = fopen(path, "r"); | FILE *fp = fopen(path, "r"); | ||||
@@ -68,7 +73,7 @@ Map::Map(char const *path) | |||||
/* We are in the process of reading layer data. Only stop | /* We are in the process of reading layer data. Only stop | ||||
* when we have read the expected number of tiles. */ | * when we have read the expected number of tiles. */ | ||||
char const *parser = tmp; | char const *parser = tmp; | ||||
while (ntiles < width * height) | |||||
while (ntiles < data->width * data->height) | |||||
{ | { | ||||
uint32_t code = 0; | uint32_t code = 0; | ||||
int id = atoi(parser); | int id = atoi(parser); | ||||
@@ -96,12 +101,13 @@ Map::Map(char const *path) | |||||
break; | break; | ||||
} | } | ||||
if (ntiles == width * height) | |||||
if (ntiles == data->width * data->height) | |||||
{ | { | ||||
data->layers[data->nlayers] = new Layer(width, height, level, tiles); | |||||
data->layers[data->nlayers] = new Layer(data->width, | |||||
data->height, level, tiles); | |||||
data->nlayers++; | data->nlayers++; | ||||
tiles = NULL; | tiles = NULL; | ||||
//fprintf(stderr, "new layer %ix%i\n", width, height); | |||||
//fprintf(stderr, "new layer %ix%i\n", data->width, data->height); | |||||
} | } | ||||
} | } | ||||
else if (sscanf(tmp, " <tileset firstgid=\"%i\"", &i) == 1) | else if (sscanf(tmp, " <tileset firstgid=\"%i\"", &i) == 1) | ||||
@@ -123,9 +129,9 @@ Map::Map(char const *path) | |||||
data->layers = (Layer **)realloc(data->layers, | data->layers = (Layer **)realloc(data->layers, | ||||
sizeof(Layer **) * (data->nlayers + 1)); | sizeof(Layer **) * (data->nlayers + 1)); | ||||
orientation = toupper(a) == 'V' ? 1 : 0; | orientation = toupper(a) == 'V' ? 1 : 0; | ||||
width = j; | |||||
height = k; | |||||
tiles = (uint32_t *)malloc(width * height * sizeof(uint32_t)); | |||||
data->width = j; | |||||
data->height = k; | |||||
tiles = (uint32_t *)malloc(j * k * sizeof(uint32_t)); | |||||
ntiles = 0; | ntiles = 0; | ||||
} | } | ||||
} | } | ||||
@@ -149,3 +155,13 @@ void Map::Render(Scene *scene, int x, int y, int z) | |||||
data->layers[i]->Render(scene, x, y, z); | data->layers[i]->Render(scene, x, y, z); | ||||
} | } | ||||
int Map::GetWidth() | |||||
{ | |||||
return data->width * 32; | |||||
} | |||||
int Map::GetHeight() | |||||
{ | |||||
return data->height * 32; | |||||
} | |||||
@@ -24,6 +24,8 @@ public: | |||||
~Map(); | ~Map(); | ||||
void Render(Scene *scene, int x, int y, int z); | void Render(Scene *scene, int x, int y, int z); | ||||
int GetWidth(); | |||||
int GetHeight(); | |||||
private: | private: | ||||
MapData *data; | MapData *data; | ||||
@@ -62,7 +62,7 @@ int main(int argc, char **argv) | |||||
Video::Clear(); | Video::Clear(); | ||||
Ticker::TickRender(); | Ticker::TickRender(); | ||||
SDL_GL_SwapBuffers(); | SDL_GL_SwapBuffers(); | ||||
Ticker::ClampFps(FPS); | |||||
Ticker::ClampFps(1.0f / FPS); | |||||
} | } | ||||
SDL_Quit(); | SDL_Quit(); | ||||
@@ -128,13 +128,14 @@ void Ticker::TickRender() | |||||
Profiler::Start(Profiler::STAT_TICK_BLIT); | Profiler::Start(Profiler::STAT_TICK_BLIT); | ||||
} | } | ||||
void Ticker::ClampFps(float fps) | |||||
void Ticker::ClampFps(float delta_time) | |||||
{ | { | ||||
Profiler::Stop(Profiler::STAT_TICK_BLIT); | Profiler::Stop(Profiler::STAT_TICK_BLIT); | ||||
float ideal_time = 1.0f / fps; | |||||
if (ideal_time > data->bias) | |||||
data->timer.WaitSeconds(ideal_time - data->bias); | |||||
data->bias -= ideal_time; | |||||
if (delta_time > data->bias + 0.2f) | |||||
delta_time = data->bias + 0.2f; // Don't go below 5 fps | |||||
if (delta_time > data->bias) | |||||
data->timer.WaitSeconds(delta_time - data->bias); | |||||
data->bias -= delta_time; | |||||
} | } | ||||
@@ -23,7 +23,7 @@ public: | |||||
static void TickGame(); | static void TickGame(); | ||||
static void TickRender(); | static void TickRender(); | ||||
static void ClampFps(float fps); | |||||
static void ClampFps(float delta_time); | |||||
}; | }; | ||||
#endif // __DH_TICKER_H__ | #endif // __DH_TICKER_H__ | ||||