@@ -53,7 +53,7 @@ void DebugSprite::TickRender(float delta_time) | |||||
Asset::TickRender(delta_time); | Asset::TickRender(delta_time); | ||||
data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 32, 1); | data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 32, 1); | ||||
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 232, 0, 1); | |||||
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 200, 0, 1); | |||||
} | } | ||||
DebugSprite::~DebugSprite() | DebugSprite::~DebugSprite() | ||||
@@ -7,7 +7,19 @@ | |||||
# include "config.h" | # include "config.h" | ||||
#endif | #endif | ||||
#include <stdlib.h> | |||||
#include <cstdlib> | |||||
#include <cmath> | |||||
#ifdef WIN32 | |||||
# define WIN32_LEAN_AND_MEAN | |||||
# include <windows.h> | |||||
#endif | |||||
#if defined __APPLE__ && defined __MACH__ | |||||
# include <OpenGL/gl.h> | |||||
#else | |||||
# define GL_GLEXT_PROTOTYPES | |||||
# include <GL/gl.h> | |||||
#endif | |||||
#include "scene.h" | #include "scene.h" | ||||
#include "tiler.h" | #include "tiler.h" | ||||
@@ -15,7 +27,7 @@ | |||||
struct Tile | struct Tile | ||||
{ | { | ||||
uint32_t prio, code; | uint32_t prio, code; | ||||
int x, y; | |||||
int x, y, z, o; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -64,6 +76,8 @@ void Scene::AddTile(uint32_t code, int x, int y, int z, int o) | |||||
data->tiles[data->ntiles].code = code; | data->tiles[data->ntiles].code = code; | ||||
data->tiles[data->ntiles].x = x; | data->tiles[data->ntiles].x = x; | ||||
data->tiles[data->ntiles].y = y; | data->tiles[data->ntiles].y = y; | ||||
data->tiles[data->ntiles].z = z; | |||||
data->tiles[data->ntiles].o = o; | |||||
data->ntiles++; | data->ntiles++; | ||||
} | } | ||||
@@ -71,8 +85,22 @@ void Scene::Render() // XXX: rename to Blit() | |||||
{ | { | ||||
qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare); | qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare); | ||||
// XXX: debug stuff | |||||
glPushMatrix(); | |||||
static float f = 0.0f; | |||||
f += 0.05f; | |||||
glTranslatef(320.0f, 240.0f, 0.0f); | |||||
glRotatef(45.0f, 1.0f, 0.0f, 0.0f); | |||||
glRotatef(30.0f * sinf(f), 0.0f, 0.0f, 1.0f); | |||||
//glRotatef(30.0f, 0.0f, 0.0f, 1.0f); | |||||
glTranslatef(-320.0f, -240.0f, 0.0f); | |||||
for (int i = 0; i < data->ntiles; i++) | for (int i = 0; i < data->ntiles; i++) | ||||
Tiler::Render(data->tiles[i].code, data->tiles[i].x, data->tiles[i].y); | |||||
Tiler::BlitTile(data->tiles[i].code, data->tiles[i].x, | |||||
data->tiles[i].y, data->tiles[i].z, data->tiles[i].o); | |||||
glPopMatrix(); | |||||
// XXX: end of debug stuff | |||||
free(data->tiles); | free(data->tiles); | ||||
data->tiles = 0; | data->tiles = 0; | ||||
@@ -50,7 +50,7 @@ void SdlInput::TickGame(float delta_time) | |||||
/* Handle mouse input */ | /* Handle mouse input */ | ||||
int mx, my; | int mx, my; | ||||
SDL_GetMouseState(&mx, &my); | SDL_GetMouseState(&mx, &my); | ||||
data->game->SetMouse(mx * (640 - 32) / 640, my * (480 - 32) / 480); | |||||
data->game->SetMouse(mx * (640 - 32) / 320 - 320, my * (480 - 32) / 240 - 240); | |||||
/* Handle keyboard and WM input */ | /* Handle keyboard and WM input */ | ||||
SDL_Event event; | SDL_Event event; | ||||
@@ -94,10 +94,10 @@ void Tiler::Deregister(int id) | |||||
data->tilesets[id] = NULL; | data->tilesets[id] = NULL; | ||||
} | } | ||||
void Tiler::Render(uint32_t code, int x, int y) | |||||
void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o) | |||||
{ | { | ||||
int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */ | int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */ | ||||
data->tilesets[id]->BlitTile(code & 0xffff, x, y); | |||||
data->tilesets[id]->BlitTile(code & 0xffff, x, y, z, o); | |||||
} | } | ||||
@@ -20,7 +20,7 @@ public: | |||||
static int Register(char const *path); | static int Register(char const *path); | ||||
static void Deregister(int id); | static void Deregister(int id); | ||||
static void Render(uint32_t code, int x, int y); | |||||
static void BlitTile(uint32_t code, int x, int y, int z, int o); | |||||
}; | }; | ||||
#endif // __DH_TILER_H__ | #endif // __DH_TILER_H__ | ||||
@@ -8,6 +8,7 @@ | |||||
#endif | #endif | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <cmath> | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
# define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
@@ -108,23 +109,26 @@ char const *TileSet::GetName() | |||||
return data->name; | return data->name; | ||||
} | } | ||||
void TileSet::BlitTile(uint32_t id, int x, int y) | |||||
void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o) | |||||
{ | { | ||||
float tx = .0625f * (id & 0xf); | float tx = .0625f * (id & 0xf); | ||||
float ty = .0625f * ((id >> 4) & 0xf); | float ty = .0625f * ((id >> 4) & 0xf); | ||||
float sqrt2 = sqrtf(2.0f); | |||||
int off = o ? 32 : 0; | |||||
if (!data->img) | if (!data->img) | ||||
{ | { | ||||
glBindTexture(GL_TEXTURE_2D, data->texture); | glBindTexture(GL_TEXTURE_2D, data->texture); | ||||
glBegin(GL_QUADS); | glBegin(GL_QUADS); | ||||
glTexCoord2f(tx, ty); | glTexCoord2f(tx, ty); | ||||
glVertex2f(x, y); | |||||
glVertex3f(x, sqrt2 * (y + off), sqrt2 * (z + off)); | |||||
glTexCoord2f(tx + .0625f, ty); | glTexCoord2f(tx + .0625f, ty); | ||||
glVertex2f(x + 32, y); | |||||
glVertex3f(x + 32, sqrt2 * (y + off), sqrt2 * (z + off)); | |||||
glTexCoord2f(tx + .0625f, ty + .0625f); | glTexCoord2f(tx + .0625f, ty + .0625f); | ||||
glVertex2f(x + 32, y + 32); | |||||
glVertex3f(x + 32, sqrt2 * (y + 32), sqrt2 * z); | |||||
glTexCoord2f(tx, ty + .0625f); | glTexCoord2f(tx, ty + .0625f); | ||||
glVertex2f(x, y + 32); | |||||
glVertex3f(x, sqrt2 * (y + 32), sqrt2 * z); | |||||
glEnd(); | glEnd(); | ||||
} | } | ||||
} | } | ||||
@@ -35,7 +35,7 @@ public: | |||||
/* New methods */ | /* New methods */ | ||||
char const *GetName(); | char const *GetName(); | ||||
void BlitTile(uint32_t id, int x, int y); | |||||
void BlitTile(uint32_t id, int x, int y, int z, int o); | |||||
private: | private: | ||||
TileSetData *data; | TileSetData *data; | ||||