@@ -15,6 +15,7 @@ | |||||
#include <cstdio> | #include <cstdio> | ||||
#include <cstring> | #include <cstring> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <cmath> | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include "core.h" | #include "core.h" | ||||
@@ -126,7 +127,8 @@ Map::Map(char const *path) | |||||
else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1) | else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1) | ||||
{ | { | ||||
/* This is a tileset image file. Associate it with firstgid. */ | /* This is a tileset image file. Associate it with firstgid. */ | ||||
data->tilers[data->ntilers] = Tiler::Register(str, 32, 32); | |||||
data->tilers[data->ntilers] = Tiler::Register(str, 32, 32, | |||||
sqrtf(2)); | |||||
data->ntilers++; | data->ntilers++; | ||||
//fprintf(stderr, "new tiler %s\n", str); | //fprintf(stderr, "new tiler %s\n", str); | ||||
} | } | ||||
@@ -53,17 +53,19 @@ private: | |||||
Tile *tiles; | Tile *tiles; | ||||
int ntiles; | int ntiles; | ||||
float angle; | |||||
}; | }; | ||||
/* | /* | ||||
* Public Scene class | * Public Scene class | ||||
*/ | */ | ||||
Scene::Scene() | |||||
Scene::Scene(float angle) | |||||
{ | { | ||||
data = new SceneData(); | data = new SceneData(); | ||||
data->tiles = 0; | data->tiles = 0; | ||||
data->ntiles = 0; | data->ntiles = 0; | ||||
data->angle = angle; | |||||
} | } | ||||
Scene::~Scene() | Scene::~Scene() | ||||
@@ -104,7 +106,7 @@ void Scene::Render() // XXX: rename to Blit() | |||||
static float f = 0.0f; | static float f = 0.0f; | ||||
f += 0.05f; | f += 0.05f; | ||||
glTranslatef(320.0f, 240.0f, 0.0f); | glTranslatef(320.0f, 240.0f, 0.0f); | ||||
glRotatef(-45.0f, 1.0f, 0.0f, 0.0f); | |||||
glRotatef(-data->angle, 1.0f, 0.0f, 0.0f); | |||||
#if 0 | #if 0 | ||||
glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f); | glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f); | ||||
glRotatef(8.0f * cosf(f), 0.0f, 0.0f, 1.0f); | glRotatef(8.0f * cosf(f), 0.0f, 0.0f, 1.0f); | ||||
@@ -23,7 +23,7 @@ class SceneData; | |||||
class Scene | class Scene | ||||
{ | { | ||||
public: | public: | ||||
Scene(); | |||||
Scene(float angle); | |||||
~Scene(); | ~Scene(); | ||||
void AddTile(uint32_t code, int x, int y, int z, int o); | void AddTile(uint32_t code, int x, int y, int z, int o); | ||||
@@ -33,13 +33,13 @@ static TilerData * const data = &tilerdata; | |||||
* Public Tiler class | * Public Tiler class | ||||
*/ | */ | ||||
int Tiler::Register(char const *path, int w, int h) | |||||
int Tiler::Register(char const *path, int w, int h, float dilate) | |||||
{ | { | ||||
int id = data->tilesets.MakeSlot(path); | int id = data->tilesets.MakeSlot(path); | ||||
if (!data->tilesets.GetEntity(id)) | if (!data->tilesets.GetEntity(id)) | ||||
{ | { | ||||
TileSet *tileset = new TileSet(path, w, h); | |||||
TileSet *tileset = new TileSet(path, w, h, dilate); | |||||
data->tilesets.SetEntity(id, tileset); | data->tilesets.SetEntity(id, tileset); | ||||
} | } | ||||
@@ -22,7 +22,7 @@ | |||||
class Tiler | class Tiler | ||||
{ | { | ||||
public: | public: | ||||
static int Register(char const *path, int w, int h); | |||||
static int Register(char const *path, int w, int h, float dilate); | |||||
static void Deregister(int id); | static void Deregister(int id); | ||||
static void BlitTile(uint32_t code, int x, int y, int z, int o); | static void BlitTile(uint32_t code, int x, int y, int z, int o); | ||||
@@ -43,7 +43,7 @@ private: | |||||
char *name; | char *name; | ||||
int *tiles; | int *tiles; | ||||
int w, h, nw, nh, ntiles; | int w, h, nw, nh, ntiles; | ||||
float tx, ty; | |||||
float dilate, tx, ty; | |||||
SDL_Surface *img; | SDL_Surface *img; | ||||
GLuint texture; | GLuint texture; | ||||
@@ -53,7 +53,7 @@ private: | |||||
* Public TileSet class | * Public TileSet class | ||||
*/ | */ | ||||
TileSet::TileSet(char const *path, int w, int h) | |||||
TileSet::TileSet(char const *path, int w, int h, float dilate) | |||||
{ | { | ||||
data = new TileSetData(); | data = new TileSetData(); | ||||
data->name = strdup(path); | data->name = strdup(path); | ||||
@@ -78,6 +78,7 @@ TileSet::TileSet(char const *path, int w, int h) | |||||
data->w = w; | data->w = w; | ||||
data->h = h; | data->h = h; | ||||
data->dilate = dilate; | |||||
/* FIXME: check for non-zero here */ | /* FIXME: check for non-zero here */ | ||||
data->nw = data->img->w / w; | data->nw = data->img->w / w; | ||||
data->nh = data->img->h / h; | data->nh = data->img->h / h; | ||||
@@ -134,8 +135,8 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o) | |||||
{ | { | ||||
float tx = data->tx * ((id & 0xffff) % data->nw); | float tx = data->tx * ((id & 0xffff) % data->nw); | ||||
float ty = data->ty * ((id & 0xffff) / data->nw); | float ty = data->ty * ((id & 0xffff) / data->nw); | ||||
float dilate = data->dilate; | |||||
float sqrt2 = sqrtf(2.0f); | |||||
int off = o ? data->h : 0; | int off = o ? data->h : 0; | ||||
int dx = data->w; | int dx = data->w; | ||||
int dy = data->h * 38 / 32; /* Magic... fix this one day */ | int dy = data->h * 38 / 32; /* Magic... fix this one day */ | ||||
@@ -146,13 +147,13 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o) | |||||
glBindTexture(GL_TEXTURE_2D, data->texture); | glBindTexture(GL_TEXTURE_2D, data->texture); | ||||
glBegin(GL_QUADS); | glBegin(GL_QUADS); | ||||
glTexCoord2f(tx, ty); | glTexCoord2f(tx, ty); | ||||
glVertex3f(x, sqrt2 * (y - dy - off), sqrt2 * (z + off)); | |||||
glVertex3f(x, dilate * (y - dy - off), dilate * (z + off)); | |||||
glTexCoord2f(tx + data->tx, ty); | glTexCoord2f(tx + data->tx, ty); | ||||
glVertex3f(x + dx, sqrt2 * (y - dy - off), sqrt2 * (z + off)); | |||||
glVertex3f(x + dx, dilate * (y - dy - off), dilate * (z + off)); | |||||
glTexCoord2f(tx + data->tx, ty + data->ty); | glTexCoord2f(tx + data->tx, ty + data->ty); | ||||
glVertex3f(x + dx, sqrt2 * (y - dy2), sqrt2 * z); | |||||
glVertex3f(x + dx, dilate * (y - dy2), dilate * z); | |||||
glTexCoord2f(tx, ty + data->ty); | glTexCoord2f(tx, ty + data->ty); | ||||
glVertex3f(x, sqrt2 * (y - dy2), sqrt2 * z); | |||||
glVertex3f(x, dilate * (y - dy2), dilate * z); | |||||
glEnd(); | glEnd(); | ||||
} | } | ||||
} | } | ||||
@@ -28,7 +28,7 @@ class TileSetData; | |||||
class TileSet : public Entity | class TileSet : public Entity | ||||
{ | { | ||||
public: | public: | ||||
TileSet(char const *path, int w, int h); | |||||
TileSet(char const *path, int w, int h, float dilate); | |||||
virtual ~TileSet(); | virtual ~TileSet(); | ||||
protected: | protected: | ||||