Browse Source

tileset: rename AddTile() to define_tile().

This is to avoid confusion with Scene::AddTile().
undefined
Sam Hocevar 9 years ago
parent
commit
3eb7db5e4d
3 changed files with 30 additions and 26 deletions
  1. +2
    -2
      doc/tutorial/06_sprite.cpp
  2. +18
    -16
      src/tileset.cpp
  3. +10
    -8
      src/tileset.h

+ 2
- 2
doc/tutorial/06_sprite.cpp View File

@@ -4,7 +4,7 @@
// Copyright © 2011—2015 Sam Hocevar <sam@hocevar.net>
// © 2012 Daniel Stephens (artwork)
//
// This program is free software. It comes without any warranty, to
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
@@ -33,7 +33,7 @@ public:

m_tileset = Tiler::Register("06_sprite.png");
for (int i = 0; i < FRAME_COUNT; ++i)
m_tileset->AddTile(ibox2(i * 24, 376, 24 + i * 24, 24 + 376));
m_tileset->define_tile(ibox2(i * 24, 376, 24 + i * 24, 24 + 376));

for (int i = 0; i < SPRITE_COUNT; ++i)
{


+ 18
- 16
src/tileset.cpp View File

@@ -1,11 +1,13 @@
//
// Lol Engine
// Lol Engine
//
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#include <lol/engine-internal.h>
@@ -55,7 +57,7 @@ TileSet::TileSet(char const *path)
array<ivec2, ivec2> tiles;
if (m_data->m_image->RetrieveTiles(tiles))
for (int i = 0; i < tiles.count(); i++)
AddTile(ibox2(tiles[0].m1, tiles[0].m1 + tiles[0].m2));
define_tile(ibox2(tiles[0].m1, tiles[0].m1 + tiles[0].m2));
}

TileSet::TileSet(char const *path, Image* image)
@@ -66,7 +68,7 @@ TileSet::TileSet(char const *path, Image* image)
array<ivec2, ivec2> tiles;
if (m_data->m_image->RetrieveTiles(tiles))
for (int i = 0; i < tiles.count(); i++)
AddTile(ibox2(tiles[0].m1, tiles[0].m1 + tiles[0].m2));
define_tile(ibox2(tiles[0].m1, tiles[0].m1 + tiles[0].m2));
}

TileSet::TileSet(char const *path, ivec2 size, ivec2 count)
@@ -87,8 +89,8 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count)
for (int j = 0; j < count.y; ++j)
for (int i = 0; i < count.x; ++i)
{
AddTile(ibox2(size * ivec2(i, j),
size * ivec2(i + 1, j + 1)));
define_tile(ibox2(size * ivec2(i, j),
size * ivec2(i + 1, j + 1)));
}
}

@@ -110,8 +112,8 @@ TileSet::TileSet(char const *path, Image* image, ivec2 size, ivec2 count)
for (int j = 0; j < count.y; ++j)
for (int i = 0; i < count.x; ++i)
{
AddTile(ibox2(size * ivec2(i, j),
size * ivec2(i + 1, j + 1)));
define_tile(ibox2(size * ivec2(i, j),
size * ivec2(i + 1, j + 1)));
}
}

@@ -134,7 +136,7 @@ char const *TileSet::GetName()
}

//New methods -----------------------------------------------------------------
int TileSet::AddTile(ibox2 rect)
int TileSet::define_tile(ibox2 rect)
{
m_tileset_data->m_tiles.push(rect,
box2((vec2)rect.aa / (vec2)m_data->m_texture_size,
@@ -142,15 +144,15 @@ int TileSet::AddTile(ibox2 rect)
return m_tileset_data->m_tiles.count() - 1;
}

void TileSet::AddTile(ivec2 count)
void TileSet::define_tile(ivec2 count)
{
ivec2 size = m_data->m_image_size / count;

for (int j = 0; j < count.y; ++j)
for (int i = 0; i < count.x; ++i)
{
AddTile(ibox2(size * ivec2(i, j),
size * ivec2(i + 1, j + 1)));
define_tile(ibox2(size * ivec2(i, j),
size * ivec2(i + 1, j + 1)));
}
}



+ 10
- 8
src/tileset.h View File

@@ -1,11 +1,13 @@
//
// Lol Engine
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#pragma once
@@ -56,8 +58,8 @@ public:
virtual char const *GetName();

/* New methods */
int AddTile(ibox2 rect);
void AddTile(ivec2 count);
int define_tile(ibox2 rect);
void define_tile(ivec2 count);
int GetTileCount() const;
ivec2 GetTileSize(int tileid) const;



Loading…
Cancel
Save