Browse Source

Minor updates here and there. Not worth mentioning.

legacy
Sam Hocevar sam 14 years ago
parent
commit
6ddfa26129
7 changed files with 43 additions and 23 deletions
  1. +5
    -4
      TODO
  2. +1
    -1
      src/gtk/editor.cpp
  3. +27
    -11
      src/map.cpp
  4. +2
    -0
      src/map.h
  5. +1
    -1
      src/test-map.cpp
  6. +6
    -5
      src/ticker.cpp
  7. +1
    -1
      src/ticker.h

+ 5
- 4
TODO View File

@@ -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.


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

@@ -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;


+ 27
- 11
src/map.cpp View File

@@ -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, " <tileset firstgid=\"%i\"", &i) == 1)
@@ -123,9 +129,9 @@ Map::Map(char const *path)
data->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;
}


+ 2
- 0
src/map.h View File

@@ -24,6 +24,8 @@ public:
~Map();

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

private:
MapData *data;


+ 1
- 1
src/test-map.cpp View File

@@ -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();


+ 6
- 5
src/ticker.cpp View File

@@ -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;
}


+ 1
- 1
src/ticker.h View File

@@ -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__


Loading…
Cancel
Save