소스 검색

core: allow each blitted tile to be stretched differently.

legacy
Sam Hocevar sam 12 년 전
부모
커밋
f35f4284b0
11개의 변경된 파일47개의 추가작업 그리고 47개의 파일을 삭제
  1. +2
    -2
      src/emitter.cpp
  2. +5
    -5
      src/font.cpp
  3. +2
    -2
      src/font.h
  4. +2
    -2
      src/map.cpp
  5. +5
    -2
      src/scene.cpp
  6. +2
    -2
      src/scene.h
  7. +3
    -2
      src/sprite.cpp
  8. +3
    -4
      src/tiler.cpp
  9. +2
    -3
      src/tiler.h
  10. +18
    -20
      src/tileset.cpp
  11. +3
    -3
      src/tileset.h

+ 2
- 2
src/emitter.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -76,7 +76,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], 0);
data->positions[i], 0, vec2(1.0f));
}

void Emitter::AddParticle(int id, vec3 pos, vec3 vel)


+ 5
- 5
src/font.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -46,7 +46,7 @@ Font::Font(char const *path)
data->name = (char *)malloc(7 + strlen(path) + 1);
sprintf(data->name, "<font> %s", path);

data->tileset = Tiler::Register(path, ivec2(0), ivec2(16), vec2(1.0f));
data->tileset = Tiler::Register(path, ivec2(0), ivec2(16));
data->size = data->tileset->GetSize(0);

m_drawgroup = DRAWGROUP_BEFORE;
@@ -69,7 +69,7 @@ char const *Font::GetName()
return data->name;
}

void Font::Print(vec3 pos, char const *str)
void Font::Print(vec3 pos, char const *str, vec2 scale)
{
Scene *scene = Scene::GetDefault();

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

if (ch != ' ')
scene->AddTile(data->tileset, ch & 255, pos, 0);
scene->AddTile(data->tileset, ch & 255, pos, 0, scale);

pos.x += data->size.x;
pos.x += data->size.x * scale.x;
}
}



+ 2
- 2
src/font.h 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -36,7 +36,7 @@ protected:

public:
/* New methods */
void Print(vec3 pos, char const *str);
void Print(vec3 pos, char const *str, vec2 scale = vec2(1.0f));
ivec2 GetSize() const;

private:


+ 2
- 2
src/map.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -136,7 +136,7 @@ Map::Map(char const *path)
{
/* This is a tileset image file. Associate it with firstgid. */
data->tilesets[data->ntilers] = Tiler::Register(str, ivec2(32),
ivec2(0), vec2(1.0f, sqrtf(2)));
ivec2(0));
data->ntilers++;
//Log::Debug("new tiler %s\n", str);
}


+ 5
- 2
src/scene.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -31,6 +31,7 @@ struct Tile
TileSet *tileset;
uint32_t prio;
vec3 pos;
vec2 scale;
int id, o;
};

@@ -141,7 +142,7 @@ void Scene::Reset()
SceneData::scene = NULL;
}

void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o)
void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale)
{
#if !defined _XBOX /* No WPOS on Xbox */
if ((data->ntiles % 1024) == 0)
@@ -153,6 +154,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o)
data->tiles[data->ntiles].id = id;
data->tiles[data->ntiles].pos = pos;
data->tiles[data->ntiles].o = o;
data->tiles[data->ntiles].scale = scale;
data->ntiles++;
#endif
}
@@ -407,6 +409,7 @@ void Scene::Render() // XXX: rename to Blit()
{
data->tiles[i].tileset->BlitTile(data->tiles[j].id,
data->tiles[j].pos, data->tiles[j].o,
data->tiles[j].scale,
vertex + 18 * (j - i), texture + 12 * (j - i));
}



+ 2
- 2
src/scene.h 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -34,7 +34,7 @@ public:
static Scene *GetDefault();
static void Reset();

void AddTile(TileSet *tileset, int id, vec3 pos, int o);
void AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale);
void Render();

private:


+ 3
- 2
src/sprite.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -50,7 +50,8 @@ void Sprite::TickDraw(float deltams)
{
Entity::TickDraw(deltams);

Scene::GetDefault()->AddTile(data->tileset, data->id, position, 0);
Scene::GetDefault()->AddTile(data->tileset, data->id, position,
0, vec2(1.0f));
}

Sprite::~Sprite()


+ 3
- 4
src/tiler.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -40,15 +40,14 @@ static TilerData * const data = &tilerdata;
* Public Tiler class
*/

TileSet *Tiler::Register(char const *path, ivec2 size, ivec2 count,
vec2 scale)
TileSet *Tiler::Register(char const *path, ivec2 size, ivec2 count)
{
int id = data->tilesets.MakeSlot(path);
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);

if (!tileset)
{
tileset = new TileSet(path, size, count, scale);
tileset = new TileSet(path, size, count);
data->tilesets.SetEntity(id, tileset);
}



+ 2
- 3
src/tiler.h 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -27,8 +27,7 @@ namespace lol
class Tiler
{
public:
static TileSet *Register(char const *path, ivec2 size, ivec2 count,
vec2 scale);
static TileSet *Register(char const *path, ivec2 size, ivec2 count);
static void Deregister(TileSet *);
};



+ 18
- 20
src/tileset.cpp 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -61,7 +61,7 @@ private:
* Public TileSet class
*/

TileSet::TileSet(char const *path, ivec2 size, ivec2 count, vec2 scale)
TileSet::TileSet(char const *path, ivec2 size, ivec2 count)
: data(new TileSetData())
{
data->name = (char *)malloc(10 + strlen(path) + 1);
@@ -98,7 +98,6 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count, vec2 scale)
data->tx = (float)data->size.x / PotUp(data->isize.x);
data->ty = (float)data->size.y / PotUp(data->isize.y);

data->scale = scale;
data->ntiles = data->count.x * data->count.y;

m_drawgroup = DRAWGROUP_BEFORE;
@@ -219,16 +218,15 @@ void TileSet::Bind()
#endif
}

void TileSet::BlitTile(uint32_t id, vec3 pos, int o,
void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale,
float *vertex, float *texture)
{
float tx = data->tx * ((id & 0xffff) % data->count.x);
float ty = data->ty * ((id & 0xffff) / data->count.x);
vec2 scale = data->scale;

int dx = data->size.x;
int dy = o ? 0 : data->size.y;
int dz = o ? data->size.y : 0;
int dx = data->size.x * scale.x;
int dy = o ? 0 : data->size.y * scale.y;
int dz = o ? data->size.y * scale.y : 0;

#if defined _XBOX
# define STR0(x) #x
@@ -241,21 +239,21 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o,
{
float tmp[10];

*vertex++ = tmp[0] = scale.x * pos.x;
*vertex++ = tmp[1] = scale.y * (pos.y + dy);
*vertex++ = tmp[2] = scale.y * (pos.z + dz);
*vertex++ = tmp[0] = pos.x;
*vertex++ = tmp[1] = pos.y + dy;
*vertex++ = tmp[2] = pos.z + dz;
*texture++ = tmp[3] = tx;
*texture++ = tmp[4] = ty;

*vertex++ = scale.x * (pos.x + dx);
*vertex++ = scale.y * (pos.y + dy);
*vertex++ = scale.y * (pos.z + dz);
*vertex++ = pos.x + dx;
*vertex++ = pos.y + dy;
*vertex++ = pos.z + dz;
*texture++ = tx + data->tx;
*texture++ = ty;

*vertex++ = tmp[5] = scale.x * (pos.x + dx);
*vertex++ = tmp[6] = scale.y * pos.y;
*vertex++ = tmp[7] = scale.y * pos.z;
*vertex++ = tmp[5] = pos.x + dx;
*vertex++ = tmp[6] = pos.y;
*vertex++ = tmp[7] = pos.z;
*texture++ = tmp[8] = tx + data->tx;
*texture++ = tmp[9] = ty + data->ty;

@@ -271,9 +269,9 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o,
*texture++ = tmp[8];
*texture++ = tmp[9];

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


+ 3
- 3
src/tileset.h 파일 보기

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2012 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
@@ -31,7 +31,7 @@ class TileSetData;
class TileSet : public Entity
{
public:
TileSet(char const *path, ivec2 size, ivec2 count, vec2 scale);
TileSet(char const *path, ivec2 size, ivec2 count);
virtual ~TileSet();

protected:
@@ -44,7 +44,7 @@ public:
ivec2 GetCount() const;
ivec2 GetSize(int tileid) const;
void Bind();
void BlitTile(uint32_t id, vec3 pos, int o,
void BlitTile(uint32_t id, vec3 pos, int o, vec2 scale,
float *vertex, float *texture);

private:


불러오는 중...
취소
저장