diff --git a/TODO b/TODO index f534c8df..090e4500 100644 --- a/TODO +++ b/TODO @@ -7,26 +7,27 @@ Important stuff [ ] Map collisions? [ ] Add scripting support (lua?). [ ] 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 ------------ [ ] Switch rendering to vertex/index buffer objects - Editor ------ [ ] File requester for maps. [ ] Scroller/panner for 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 ----- [ ] Write a map file format. [ ] Add special zones to the map. - Architecture ------------ [ ] Tiler and Forge are almost the same, try to refactor them. diff --git a/src/gtk/editor.cpp b/src/gtk/editor.cpp index ab3f3cb8..c6b5a974 100644 --- a/src/gtk/editor.cpp +++ b/src/gtk/editor.cpp @@ -84,7 +84,7 @@ static gint draw(GtkWidget *widget, GdkEventExpose *event) gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); while (g_main_context_iteration(NULL, FALSE)) ; - Ticker::ClampFps(FPS); + Ticker::ClampFps(1.0f / FPS); } return TRUE; diff --git a/src/map.cpp b/src/map.cpp index 719d161f..e5d9f08b 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -16,8 +16,6 @@ #include "layer.h" #include "tiler.h" -#define MAX_TILERS 128 - /* * Map implementation class */ @@ -26,11 +24,16 @@ class MapData { friend class Map; + static int const MAX_TILERS = 128; + private: int tilers[MAX_TILERS]; int ntilers; + Layer **layers; int nlayers; + + int width, height; }; /* @@ -43,11 +46,13 @@ Map::Map(char const *path) data->ntilers = 0; data->layers = NULL; data->nlayers = 0; + data->width = 0; + data->height = 0; char tmp[BUFSIZ]; - int gids[MAX_TILERS]; + int gids[MapData::MAX_TILERS]; 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"); @@ -68,7 +73,7 @@ Map::Map(char const *path) /* We are in the process of reading layer data. Only stop * when we have read the expected number of tiles. */ char const *parser = tmp; - while (ntiles < width * height) + while (ntiles < data->width * data->height) { uint32_t code = 0; int id = atoi(parser); @@ -96,12 +101,13 @@ Map::Map(char const *path) 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++; 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, " layers = (Layer **)realloc(data->layers, sizeof(Layer **) * (data->nlayers + 1)); 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; } } @@ -149,3 +155,13 @@ void Map::Render(Scene *scene, int x, int y, int z) data->layers[i]->Render(scene, x, y, z); } +int Map::GetWidth() +{ + return data->width * 32; +} + +int Map::GetHeight() +{ + return data->height * 32; +} + diff --git a/src/map.h b/src/map.h index f0a47b51..4a074d48 100644 --- a/src/map.h +++ b/src/map.h @@ -24,6 +24,8 @@ public: ~Map(); void Render(Scene *scene, int x, int y, int z); + int GetWidth(); + int GetHeight(); private: MapData *data; diff --git a/src/test-map.cpp b/src/test-map.cpp index 9f45f27a..7e28d065 100644 --- a/src/test-map.cpp +++ b/src/test-map.cpp @@ -62,7 +62,7 @@ int main(int argc, char **argv) Video::Clear(); Ticker::TickRender(); SDL_GL_SwapBuffers(); - Ticker::ClampFps(FPS); + Ticker::ClampFps(1.0f / FPS); } SDL_Quit(); diff --git a/src/ticker.cpp b/src/ticker.cpp index 80186f5d..7e354714 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -128,13 +128,14 @@ void Ticker::TickRender() Profiler::Start(Profiler::STAT_TICK_BLIT); } -void Ticker::ClampFps(float fps) +void Ticker::ClampFps(float delta_time) { 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; } diff --git a/src/ticker.h b/src/ticker.h index d40c6390..0f33b6a7 100644 --- a/src/ticker.h +++ b/src/ticker.h @@ -23,7 +23,7 @@ public: static void TickGame(); static void TickRender(); - static void ClampFps(float fps); + static void ClampFps(float delta_time); }; #endif // __DH_TICKER_H__