@@ -74,9 +74,7 @@ void Emitter::TickDraw(float deltams) | |||||
for (int i = 0; i < data->nparticles; i++) | for (int i = 0; i < data->nparticles; i++) | ||||
Scene::GetDefault()->AddTile(data->tileset, data->particles[i], | Scene::GetDefault()->AddTile(data->tileset, data->particles[i], | ||||
data->positions[i].x, | |||||
data->positions[i].y, | |||||
data->positions[i].z, 0); | |||||
data->positions[i], 0); | |||||
} | } | ||||
void Emitter::AddParticle(int id, vec3 pos, vec3 vel) | void Emitter::AddParticle(int id, vec3 pos, vec3 vel) | ||||
@@ -78,8 +78,7 @@ void Font::Print(vec3i pos, char const *str) | |||||
uint32_t ch = (uint8_t)*str++; | uint32_t ch = (uint8_t)*str++; | ||||
if (ch != ' ') | if (ch != ' ') | ||||
scene->AddTile(data->tileset, ch & 255, | |||||
pos.x, pos.y, pos.z, 0); | |||||
scene->AddTile(data->tileset, ch & 255, pos, 0); | |||||
pos.x += data->size.x; | pos.x += data->size.x; | ||||
} | } | ||||
@@ -54,8 +54,10 @@ void Layer::Render(int x, int y, int z) | |||||
for (int i = 0; i < width; i++) | for (int i = 0; i < width; i++) | ||||
if (data[j * width + i]) | if (data[j * width + i]) | ||||
scene->AddTile(data[j * width + i], | scene->AddTile(data[j * width + i], | ||||
x + i * 32, y + j * 32 - altitude, | |||||
altitude + z, orientation); | |||||
vec3i(x + i * 32, | |||||
y + j * 32 - altitude, | |||||
altitude + z), | |||||
orientation); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -95,7 +95,7 @@ Map::Map(char const *path) | |||||
if (n == data->ntilers - 1 | if (n == data->ntilers - 1 | ||||
|| id < gids[n + 1]) | || id < gids[n + 1]) | ||||
{ | { | ||||
Log::Error("tilesets no longer work this way"); | |||||
Log::Error("tilesets no longer work this way\n"); | |||||
//code = (data->tilesets[n] << 16) | (id - gids[n]); | //code = (data->tilesets[n] << 16) | (id - gids[n]); | ||||
break; | break; | ||||
} | } | ||||
@@ -30,7 +30,8 @@ struct Tile | |||||
{ | { | ||||
TileSet *tileset; | TileSet *tileset; | ||||
uint32_t prio; | uint32_t prio; | ||||
int id, x, y, z, o; | |||||
vec3i pos; | |||||
int id, o; | |||||
}; | }; | ||||
static Shader *stdshader = NULL; | static Shader *stdshader = NULL; | ||||
@@ -114,18 +115,16 @@ void Scene::Reset() | |||||
SceneData::scene = NULL; | SceneData::scene = NULL; | ||||
} | } | ||||
void Scene::AddTile(TileSet *tileset, int id, int x, int y, int z, int o) | |||||
void Scene::AddTile(TileSet *tileset, int id, vec3i pos, int o) | |||||
{ | { | ||||
if ((data->ntiles % 1024) == 0) | if ((data->ntiles % 1024) == 0) | ||||
data->tiles = (Tile *)realloc(data->tiles, | data->tiles = (Tile *)realloc(data->tiles, | ||||
(data->ntiles + 1024) * sizeof(Tile)); | (data->ntiles + 1024) * sizeof(Tile)); | ||||
/* FIXME: this sorting only works for a 45-degree camera */ | /* FIXME: this sorting only works for a 45-degree camera */ | ||||
data->tiles[data->ntiles].prio = -y - 2 * 32 * z + (o ? 0 : 32); | |||||
data->tiles[data->ntiles].prio = -pos.y - 2 * 32 * pos.z + (o ? 0 : 32); | |||||
data->tiles[data->ntiles].tileset = tileset; | data->tiles[data->ntiles].tileset = tileset; | ||||
data->tiles[data->ntiles].id = id; | data->tiles[data->ntiles].id = id; | ||||
data->tiles[data->ntiles].x = x; | |||||
data->tiles[data->ntiles].y = y; | |||||
data->tiles[data->ntiles].z = z; | |||||
data->tiles[data->ntiles].pos = pos; | |||||
data->tiles[data->ntiles].o = o; | data->tiles[data->ntiles].o = o; | ||||
data->ntiles++; | data->ntiles++; | ||||
} | } | ||||
@@ -285,8 +284,7 @@ void Scene::Render() // XXX: rename to Blit() | |||||
for (int j = i; j < n; j++) | for (int j = i; j < n; j++) | ||||
{ | { | ||||
data->tiles[i].tileset->BlitTile(data->tiles[j].id, | data->tiles[i].tileset->BlitTile(data->tiles[j].id, | ||||
data->tiles[j].x, data->tiles[j].y, | |||||
data->tiles[j].z, data->tiles[j].o, | |||||
data->tiles[j].pos, data->tiles[j].o, | |||||
vertex + 18 * (j - i), texture + 12 * (j - i)); | vertex + 18 * (j - i), texture + 12 * (j - i)); | ||||
} | } | ||||
@@ -34,7 +34,7 @@ public: | |||||
static Scene *GetDefault(); | static Scene *GetDefault(); | ||||
static void Reset(); | static void Reset(); | ||||
void AddTile(TileSet *tileset, int id, int x, int y, int z, int o); | |||||
void AddTile(TileSet *tileset, int id, vec3i pos, int o); | |||||
void Render(); | void Render(); | ||||
private: | private: | ||||
@@ -178,7 +178,7 @@ void TileSet::Bind() | |||||
} | } | ||||
} | } | ||||
void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o, | |||||
void TileSet::BlitTile(uint32_t id, vec3i pos, int o, | |||||
float *vertex, float *texture) | float *vertex, float *texture) | ||||
{ | { | ||||
float tx = data->tx * ((id & 0xffff) % data->count.i); | float tx = data->tx * ((id & 0xffff) % data->count.i); | ||||
@@ -193,21 +193,21 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o, | |||||
{ | { | ||||
float tmp[10]; | float tmp[10]; | ||||
*vertex++ = tmp[0] = x; | |||||
*vertex++ = tmp[1] = dilate * (y + dy); | |||||
*vertex++ = tmp[2] = dilate * (z + dz); | |||||
*vertex++ = tmp[0] = pos.x; | |||||
*vertex++ = tmp[1] = dilate * (pos.y + dy); | |||||
*vertex++ = tmp[2] = dilate * (pos.z + dz); | |||||
*texture++ = tmp[3] = tx; | *texture++ = tmp[3] = tx; | ||||
*texture++ = tmp[4] = ty; | *texture++ = tmp[4] = ty; | ||||
*vertex++ = x + dx; | |||||
*vertex++ = dilate * (y + dy); | |||||
*vertex++ = dilate * (z + dz); | |||||
*vertex++ = pos.x + dx; | |||||
*vertex++ = dilate * (pos.y + dy); | |||||
*vertex++ = dilate * (pos.z + dz); | |||||
*texture++ = tx + data->tx; | *texture++ = tx + data->tx; | ||||
*texture++ = ty; | *texture++ = ty; | ||||
*vertex++ = tmp[5] = x + dx; | |||||
*vertex++ = tmp[6] = dilate * y; | |||||
*vertex++ = tmp[7] = dilate * z; | |||||
*vertex++ = tmp[5] = pos.x + dx; | |||||
*vertex++ = tmp[6] = dilate * pos.y; | |||||
*vertex++ = tmp[7] = dilate * pos.z; | |||||
*texture++ = tmp[8] = tx + data->tx; | *texture++ = tmp[8] = tx + data->tx; | ||||
*texture++ = tmp[9] = ty + data->ty; | *texture++ = tmp[9] = ty + data->ty; | ||||
@@ -223,9 +223,9 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o, | |||||
*texture++ = tmp[8]; | *texture++ = tmp[8]; | ||||
*texture++ = tmp[9]; | *texture++ = tmp[9]; | ||||
*vertex++ = x; | |||||
*vertex++ = dilate * y; | |||||
*vertex++ = dilate * z; | |||||
*vertex++ = pos.x; | |||||
*vertex++ = dilate * pos.y; | |||||
*vertex++ = dilate * pos.z; | |||||
*texture++ = tx; | *texture++ = tx; | ||||
*texture++ = ty + data->ty; | *texture++ = ty + data->ty; | ||||
} | } | ||||
@@ -44,7 +44,7 @@ public: | |||||
vec2i GetCount() const; | vec2i GetCount() const; | ||||
vec2i GetSize(int tileid) const; | vec2i GetSize(int tileid) const; | ||||
void Bind(); | void Bind(); | ||||
void BlitTile(uint32_t id, int x, int y, int z, int o, | |||||
void BlitTile(uint32_t id, vec3i pos, int o, | |||||
float *vertex, float *texture); | float *vertex, float *texture); | ||||
private: | private: | ||||