@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // 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++) | 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], 0); | |||||
data->positions[i], 0, vec2(1.0f)); | |||||
} | } | ||||
void Emitter::AddParticle(int id, vec3 pos, vec3 vel) | void Emitter::AddParticle(int id, vec3 pos, vec3 vel) | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // 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); | data->name = (char *)malloc(7 + strlen(path) + 1); | ||||
sprintf(data->name, "<font> %s", path); | 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); | data->size = data->tileset->GetSize(0); | ||||
m_drawgroup = DRAWGROUP_BEFORE; | m_drawgroup = DRAWGROUP_BEFORE; | ||||
@@ -69,7 +69,7 @@ char const *Font::GetName() | |||||
return data->name; | 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(); | Scene *scene = Scene::GetDefault(); | ||||
@@ -78,9 +78,9 @@ void Font::Print(vec3 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, 0); | |||||
scene->AddTile(data->tileset, ch & 255, pos, 0, scale); | |||||
pos.x += data->size.x; | |||||
pos.x += data->size.x * scale.x; | |||||
} | } | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -36,7 +36,7 @@ protected: | |||||
public: | public: | ||||
/* New methods */ | /* New methods */ | ||||
void Print(vec3 pos, char const *str); | |||||
void Print(vec3 pos, char const *str, vec2 scale = vec2(1.0f)); | |||||
ivec2 GetSize() const; | ivec2 GetSize() const; | ||||
private: | private: | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // 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. */ | /* This is a tileset image file. Associate it with firstgid. */ | ||||
data->tilesets[data->ntilers] = Tiler::Register(str, ivec2(32), | data->tilesets[data->ntilers] = Tiler::Register(str, ivec2(32), | ||||
ivec2(0), vec2(1.0f, sqrtf(2))); | |||||
ivec2(0)); | |||||
data->ntilers++; | data->ntilers++; | ||||
//Log::Debug("new tiler %s\n", str); | //Log::Debug("new tiler %s\n", str); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -31,6 +31,7 @@ struct Tile | |||||
TileSet *tileset; | TileSet *tileset; | ||||
uint32_t prio; | uint32_t prio; | ||||
vec3 pos; | vec3 pos; | ||||
vec2 scale; | |||||
int id, o; | int id, o; | ||||
}; | }; | ||||
@@ -141,7 +142,7 @@ void Scene::Reset() | |||||
SceneData::scene = NULL; | 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 !defined _XBOX /* No WPOS on Xbox */ | ||||
if ((data->ntiles % 1024) == 0) | 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].id = id; | ||||
data->tiles[data->ntiles].pos = pos; | data->tiles[data->ntiles].pos = pos; | ||||
data->tiles[data->ntiles].o = o; | data->tiles[data->ntiles].o = o; | ||||
data->tiles[data->ntiles].scale = scale; | |||||
data->ntiles++; | data->ntiles++; | ||||
#endif | #endif | ||||
} | } | ||||
@@ -407,6 +409,7 @@ void Scene::Render() // XXX: rename to Blit() | |||||
{ | { | ||||
data->tiles[i].tileset->BlitTile(data->tiles[j].id, | data->tiles[i].tileset->BlitTile(data->tiles[j].id, | ||||
data->tiles[j].pos, data->tiles[j].o, | data->tiles[j].pos, data->tiles[j].o, | ||||
data->tiles[j].scale, | |||||
vertex + 18 * (j - i), texture + 12 * (j - i)); | vertex + 18 * (j - i), texture + 12 * (j - i)); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -34,7 +34,7 @@ public: | |||||
static Scene *GetDefault(); | static Scene *GetDefault(); | ||||
static void Reset(); | 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(); | void Render(); | ||||
private: | private: | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -50,7 +50,8 @@ void Sprite::TickDraw(float deltams) | |||||
{ | { | ||||
Entity::TickDraw(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() | Sprite::~Sprite() | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -40,15 +40,14 @@ static TilerData * const data = &tilerdata; | |||||
* Public Tiler class | * 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); | int id = data->tilesets.MakeSlot(path); | ||||
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); | TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); | ||||
if (!tileset) | if (!tileset) | ||||
{ | { | ||||
tileset = new TileSet(path, size, count, scale); | |||||
tileset = new TileSet(path, size, count); | |||||
data->tilesets.SetEntity(id, tileset); | data->tilesets.SetEntity(id, tileset); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -27,8 +27,7 @@ namespace lol | |||||
class Tiler | class Tiler | ||||
{ | { | ||||
public: | 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 *); | static void Deregister(TileSet *); | ||||
}; | }; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -61,7 +61,7 @@ private: | |||||
* Public TileSet class | * 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(new TileSetData()) | ||||
{ | { | ||||
data->name = (char *)malloc(10 + strlen(path) + 1); | 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->tx = (float)data->size.x / PotUp(data->isize.x); | ||||
data->ty = (float)data->size.y / PotUp(data->isize.y); | data->ty = (float)data->size.y / PotUp(data->isize.y); | ||||
data->scale = scale; | |||||
data->ntiles = data->count.x * data->count.y; | data->ntiles = data->count.x * data->count.y; | ||||
m_drawgroup = DRAWGROUP_BEFORE; | m_drawgroup = DRAWGROUP_BEFORE; | ||||
@@ -219,16 +218,15 @@ void TileSet::Bind() | |||||
#endif | #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 *vertex, float *texture) | ||||
{ | { | ||||
float tx = data->tx * ((id & 0xffff) % data->count.x); | float tx = data->tx * ((id & 0xffff) % data->count.x); | ||||
float ty = data->ty * ((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 | #if defined _XBOX | ||||
# define STR0(x) #x | # define STR0(x) #x | ||||
@@ -241,21 +239,21 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, | |||||
{ | { | ||||
float tmp[10]; | 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[3] = tx; | ||||
*texture++ = tmp[4] = ty; | *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++ = tx + data->tx; | ||||
*texture++ = ty; | *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[8] = tx + data->tx; | ||||
*texture++ = tmp[9] = ty + data->ty; | *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[8]; | ||||
*texture++ = tmp[9]; | *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++ = tx; | ||||
*texture++ = ty + data->ty; | *texture++ = ty + data->ty; | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // 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 | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -31,7 +31,7 @@ class TileSetData; | |||||
class TileSet : public Entity | class TileSet : public Entity | ||||
{ | { | ||||
public: | public: | ||||
TileSet(char const *path, ivec2 size, ivec2 count, vec2 scale); | |||||
TileSet(char const *path, ivec2 size, ivec2 count); | |||||
virtual ~TileSet(); | virtual ~TileSet(); | ||||
protected: | protected: | ||||
@@ -44,7 +44,7 @@ public: | |||||
ivec2 GetCount() const; | ivec2 GetCount() const; | ||||
ivec2 GetSize(int tileid) const; | ivec2 GetSize(int tileid) const; | ||||
void Bind(); | 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); | float *vertex, float *texture); | ||||
private: | private: | ||||