Browse Source

tiler: ensure AddTile() and BlitTile() accept vec3i arguments.

legacy
Sam Hocevar sam 13 years ago
parent
commit
dc13c1f742
8 changed files with 28 additions and 31 deletions
  1. +1
    -3
      src/emitter.cpp
  2. +1
    -2
      src/font.cpp
  3. +4
    -2
      src/layer.cpp
  4. +1
    -1
      src/map.cpp
  5. +6
    -8
      src/scene.cpp
  6. +1
    -1
      src/scene.h
  7. +13
    -13
      src/tileset.cpp
  8. +1
    -1
      src/tileset.h

+ 1
- 3
src/emitter.cpp View File

@@ -74,9 +74,7 @@ void Emitter::TickDraw(float deltams)

for (int i = 0; i < data->nparticles; 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)


+ 1
- 2
src/font.cpp View File

@@ -78,8 +78,7 @@ void Font::Print(vec3i pos, char const *str)
uint32_t ch = (uint8_t)*str++;

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


+ 4
- 2
src/layer.cpp View File

@@ -54,8 +54,10 @@ void Layer::Render(int x, int y, int z)
for (int i = 0; i < width; i++)
if (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
}



+ 1
- 1
src/map.cpp View File

@@ -95,7 +95,7 @@ Map::Map(char const *path)
if (n == data->ntilers - 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]);
break;
}


+ 6
- 8
src/scene.cpp View File

@@ -30,7 +30,8 @@ struct Tile
{
TileSet *tileset;
uint32_t prio;
int id, x, y, z, o;
vec3i pos;
int id, o;
};

static Shader *stdshader = NULL;
@@ -114,18 +115,16 @@ void Scene::Reset()
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)
data->tiles = (Tile *)realloc(data->tiles,
(data->ntiles + 1024) * sizeof(Tile));
/* 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].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->ntiles++;
}
@@ -285,8 +284,7 @@ void Scene::Render() // XXX: rename to Blit()
for (int j = i; j < n; j++)
{
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));
}



+ 1
- 1
src/scene.h View File

@@ -34,7 +34,7 @@ public:
static Scene *GetDefault();
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();

private:


+ 13
- 13
src/tileset.cpp View File

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

*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[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++ = 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[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[9];

*vertex++ = x;
*vertex++ = dilate * y;
*vertex++ = dilate * z;
*vertex++ = pos.x;
*vertex++ = dilate * pos.y;
*vertex++ = dilate * pos.z;
*texture++ = tx;
*texture++ = ty + data->ty;
}


+ 1
- 1
src/tileset.h View File

@@ -44,7 +44,7 @@ public:
vec2i GetCount() const;
vec2i GetSize(int tileid) const;
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);

private:


Loading…
Cancel
Save