Tiled sprite improvements!
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
<asset type="texture" name="texture_eth" />
|
<asset type="texture" name="texture_eth" />
|
||||||
|
|
||||||
<MeshRenderer />
|
<MeshRenderer />
|
||||||
<QuadMeshHost xy0="0, 0" xy1="7.41, 7.90" uv0="0, 0" uv1="1, 0.07142857142" />
|
<QuadMeshHost />
|
||||||
<SimpleBillboardedMaterial texture="texture_eth" />
|
<SimpleBillboardedMaterial texture="texture_eth" />
|
||||||
<!-- <TiledSprite tile="1" ref="tiledSprite" /> -->
|
<TiledSprite tile="0" ref="tiledSprite" sizeType="TILED_SPRITE_SIZE_TYPE_WIDTH_RATIO" />
|
||||||
</prefab>
|
</prefab>
|
BIN
assets/games/liminal/textures/eth.png
Normal file
BIN
assets/games/liminal/textures/eth.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 MiB |
BIN
assets/games/liminal/textures/eth2.png
Normal file
BIN
assets/games/liminal/textures/eth2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 317 KiB |
@ -63,11 +63,11 @@ TilesetGrid::TilesetGrid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t TilesetGrid::getTileWidth() {
|
float_t TilesetGrid::getTileWidth(int32_t tile) {
|
||||||
return this->divX;
|
return this->divX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t TilesetGrid::getTileHeight() {
|
float_t TilesetGrid::getTileHeight(int32_t tile) {
|
||||||
return this->divY;
|
return this->divY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,22 @@ namespace Dawn {
|
|||||||
* @return Tile at that index.
|
* @return Tile at that index.
|
||||||
*/
|
*/
|
||||||
struct Tile getTile(int32_t tile);
|
struct Tile getTile(int32_t tile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the width of an individual tile.
|
||||||
|
*
|
||||||
|
* @param tile The tile to get the width of.
|
||||||
|
* @return The tile width.
|
||||||
|
*/
|
||||||
|
virtual float_t getTileWidth(int32_t tile) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the height of an individual tile.
|
||||||
|
*
|
||||||
|
* @param tile The tile to get the height of.
|
||||||
|
* @return The tile height.
|
||||||
|
*/
|
||||||
|
virtual float_t getTileHeight(int32_t tile) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TilesetGrid : public Tileset{
|
struct TilesetGrid : public Tileset{
|
||||||
@ -61,19 +77,8 @@ namespace Dawn {
|
|||||||
int32_t borderY
|
int32_t borderY
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
float_t getTileWidth(int32_t tile) override;
|
||||||
* Returns the width of an individual tile.
|
float_t getTileHeight(int32_t tile) override;
|
||||||
*
|
|
||||||
* @return The tile width.
|
|
||||||
*/
|
|
||||||
float_t getTileWidth();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the height of an individual tile.
|
|
||||||
*
|
|
||||||
* @return The tile height.
|
|
||||||
*/
|
|
||||||
float_t getTileHeight();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tile at a given grid position.
|
* Returns the tile at a given grid position.
|
||||||
|
@ -45,7 +45,7 @@ void BitmapFont::buffer(
|
|||||||
size_t wordStart = 0;
|
size_t wordStart = 0;
|
||||||
glm::vec2 xy0(0, 0);
|
glm::vec2 xy0(0, 0);
|
||||||
glm::vec2 tileSize =
|
glm::vec2 tileSize =
|
||||||
glm::vec2(tileset->getTileWidth(), tileset->getTileHeight()) *
|
glm::vec2(tileset->getTileWidth(0), tileset->getTileHeight(0)) *
|
||||||
(fontSize / this->getDefaultFontSize())
|
(fontSize / this->getDefaultFontSize())
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -142,9 +142,9 @@ void BitmapFont::draw(Mesh *mesh, int32_t start, int32_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float_t BitmapFont::getLineHeight(float_t fontSize) {
|
float_t BitmapFont::getLineHeight(float_t fontSize) {
|
||||||
return tileset->getTileHeight();
|
return tileset->getTileHeight(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t BitmapFont::getDefaultFontSize() {
|
float_t BitmapFont::getDefaultFontSize() {
|
||||||
return tileset->getTileHeight();
|
return tileset->getTileHeight(0);
|
||||||
}
|
}
|
@ -10,6 +10,7 @@
|
|||||||
#include "scene/debug/SceneDebugLine.hpp"
|
#include "scene/debug/SceneDebugLine.hpp"
|
||||||
#include "physics/ScenePhysicsManager.hpp"
|
#include "physics/ScenePhysicsManager.hpp"
|
||||||
#include "state/StateEvent.hpp"
|
#include "state/StateEvent.hpp"
|
||||||
|
#include "state/StateOwner.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class DawnGame;
|
class DawnGame;
|
||||||
@ -25,7 +26,7 @@ namespace Dawn {
|
|||||||
template<class T>
|
template<class T>
|
||||||
std::vector<T*> _sceneForwardGetComponents(SceneItem *item);
|
std::vector<T*> _sceneForwardGetComponents(SceneItem *item);
|
||||||
|
|
||||||
class Scene {
|
class Scene : public StateOwner {
|
||||||
private:
|
private:
|
||||||
sceneitemid_t nextId;
|
sceneitemid_t nextId;
|
||||||
std::map<sceneitemid_t, SceneItem*> items;
|
std::map<sceneitemid_t, SceneItem*> items;
|
||||||
|
@ -12,7 +12,10 @@ TiledSprite::TiledSprite(SceneItem *item) :
|
|||||||
SceneItemComponent(item),
|
SceneItemComponent(item),
|
||||||
tile(-1),
|
tile(-1),
|
||||||
tileset(nullptr),
|
tileset(nullptr),
|
||||||
meshHost(nullptr)
|
meshHost(nullptr),
|
||||||
|
flip(TILED_SPRITE_FLIP_Y),
|
||||||
|
sizeType(TILED_SPRITE_SIZE_TYPE_SCALE),
|
||||||
|
size(1.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -33,11 +36,60 @@ void TiledSprite::onStart() {
|
|||||||
useEffect([&]{
|
useEffect([&]{
|
||||||
if(this->meshHost == nullptr || this->tileset == nullptr) return;
|
if(this->meshHost == nullptr || this->tileset == nullptr) return;
|
||||||
auto tile = this->tileset->getTile(this->tile);
|
auto tile = this->tileset->getTile(this->tile);
|
||||||
this->meshHost->uv0 = tile.uv0;
|
this->meshHost->uv0 = glm::vec2(
|
||||||
this->meshHost->uv1 = tile.uv1;
|
(((flag_t)this->flip) & TILED_SPRITE_FLIP_X) == 0 ? tile.uv0.x : tile.uv1.x,
|
||||||
|
(((flag_t)this->flip) & TILED_SPRITE_FLIP_Y) == 0 ? tile.uv0.y : tile.uv1.y
|
||||||
|
);
|
||||||
|
this->meshHost->uv1 = glm::vec2(
|
||||||
|
(((flag_t)this->flip) & TILED_SPRITE_FLIP_X) == 0 ? tile.uv1.x : tile.uv0.x,
|
||||||
|
(((flag_t)this->flip) & TILED_SPRITE_FLIP_Y) == 0 ? tile.uv1.y : tile.uv0.y
|
||||||
|
);
|
||||||
}, {
|
}, {
|
||||||
&this->tile,
|
&this->tile,
|
||||||
&this->meshHost,
|
&this->meshHost,
|
||||||
&this->tileset
|
&this->tileset,
|
||||||
|
&this->flip
|
||||||
|
})();
|
||||||
|
|
||||||
|
useEffect([&]{
|
||||||
|
if(this->meshHost == nullptr || this->tileset == nullptr) return;
|
||||||
|
auto tile = this->tileset->getTile(this->tile);
|
||||||
|
|
||||||
|
glm::vec2 size;
|
||||||
|
|
||||||
|
switch(this->sizeType) {
|
||||||
|
case TILED_SPRITE_SIZE_TYPE_SCALE: {
|
||||||
|
size = glm::vec2(
|
||||||
|
this->tileset->getTileWidth(this->tile),
|
||||||
|
this->tileset->getTileHeight(this->tile)
|
||||||
|
) * (float_t)this->size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TILED_SPRITE_SIZE_TYPE_WIDTH_RATIO: {
|
||||||
|
float_t rw = this->tileset->getTileHeight(this->tile) / this->tileset->getTileWidth(this->tile);
|
||||||
|
size.x = (float_t)this->size;
|
||||||
|
size.y = size.x * rw;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TILED_SPRITE_SIZE_TYPE_HEIGHT_RATIO: {
|
||||||
|
float_t rh = this->tileset->getTileWidth(this->tile) / this->tileset->getTileHeight(this->tile);
|
||||||
|
size.y = (float_t)this->size;
|
||||||
|
size.x = size.y * rh;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->meshHost->xy0 = -size;
|
||||||
|
this->meshHost->xy1 = size;
|
||||||
|
}, {
|
||||||
|
&this->tile,
|
||||||
|
&this->meshHost,
|
||||||
|
&this->tileset,
|
||||||
|
&this->size
|
||||||
})();
|
})();
|
||||||
}
|
}
|
@ -7,7 +7,16 @@
|
|||||||
#include "display/Tileset.hpp"
|
#include "display/Tileset.hpp"
|
||||||
#include "scene/components/display/mesh/QuadMeshHost.hpp"
|
#include "scene/components/display/mesh/QuadMeshHost.hpp"
|
||||||
|
|
||||||
|
#define TILED_SPRITE_FLIP_Y FLAG_DEFINE(1)
|
||||||
|
#define TILED_SPRITE_FLIP_X FLAG_DEFINE(2)
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
|
enum TiledSpriteSizeType {
|
||||||
|
TILED_SPRITE_SIZE_TYPE_SCALE,
|
||||||
|
TILED_SPRITE_SIZE_TYPE_WIDTH_RATIO,
|
||||||
|
TILED_SPRITE_SIZE_TYPE_HEIGHT_RATIO
|
||||||
|
};
|
||||||
|
|
||||||
class TiledSprite : public SceneItemComponent {
|
class TiledSprite : public SceneItemComponent {
|
||||||
public:
|
public:
|
||||||
// @optional
|
// @optional
|
||||||
@ -16,6 +25,12 @@ namespace Dawn {
|
|||||||
StateProperty<QuadMeshHost*> meshHost;
|
StateProperty<QuadMeshHost*> meshHost;
|
||||||
// @optional
|
// @optional
|
||||||
StateProperty<int32_t> tile;
|
StateProperty<int32_t> tile;
|
||||||
|
// @optional
|
||||||
|
StateProperty<flag_t> flip;
|
||||||
|
// @optional
|
||||||
|
StateProperty<enum TiledSpriteSizeType> sizeType;
|
||||||
|
// @optional
|
||||||
|
StateProperty<float_t> size;
|
||||||
|
|
||||||
TiledSprite(SceneItem *item);
|
TiledSprite(SceneItem *item);
|
||||||
std::vector<SceneItemComponent*> getDependencies();
|
std::vector<SceneItemComponent*> getDependencies();
|
||||||
|
@ -42,8 +42,6 @@ namespace Dawn {
|
|||||||
protected:
|
protected:
|
||||||
float_t width = 1;
|
float_t width = 1;
|
||||||
float_t height = 1;
|
float_t height = 1;
|
||||||
|
|
||||||
StateEvent<> eventAlignmentUpdated;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply returns this UI Components' dimensional parent, used for the
|
* Simply returns this UI Components' dimensional parent, used for the
|
||||||
@ -60,6 +58,7 @@ namespace Dawn {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
StateProperty<bool_t> alignmentNeedsUpdating;
|
StateProperty<bool_t> alignmentNeedsUpdating;
|
||||||
|
StateEvent<> eventAlignmentUpdated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used to calculate alignment values.
|
* Method used to calculate alignment values.
|
||||||
|
@ -21,51 +21,51 @@ namespace Dawn {
|
|||||||
TextureRenderTarget *renderTarget;
|
TextureRenderTarget *renderTarget;
|
||||||
Texture text;
|
Texture text;
|
||||||
TilesetGrid grid;
|
TilesetGrid grid;
|
||||||
|
CameraTexture *camTexture;
|
||||||
|
UIImage *image;
|
||||||
|
|
||||||
int32_t test = 0;
|
int32_t test = 0;
|
||||||
|
|
||||||
void stage() override {
|
void stage() override {
|
||||||
// canvas = UICanvas::create(this);
|
canvas = UICanvas::create(this);
|
||||||
|
|
||||||
camera = Camera::create(this);
|
camera = Camera::create(this);
|
||||||
glm::vec3 off = glm::vec3(0, 0, 0);
|
glm::vec3 off = glm::vec3(0, 0, 0);
|
||||||
camera->transform->lookAt(glm::vec3(10, 10, 10) + off, glm::vec3(0, 0, 0) + off);
|
camera->transform->lookAt(glm::vec3(10, 10, 10) + off, glm::vec3(0, 0, 0) + off);
|
||||||
|
|
||||||
// auto textbox = VNTextbox::create(this);
|
auto textbox = VNTextbox::create(this);
|
||||||
// textbox->transform.setParent(canvas->transform);
|
textbox->transform.setParent(canvas->transform);
|
||||||
|
|
||||||
// camNew = Camera::create(this);
|
camNew = Camera::create(this);
|
||||||
// auto camTexture = camNew->item->addComponent<CameraTexture>();
|
camTexture = camNew->item->addComponent<CameraTexture>();
|
||||||
// camNew->fov = 0.436332f;
|
camNew->fov = 0.436332f;
|
||||||
// camNew->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
|
camNew->transform->lookAt(glm::vec3(0, 0, 5), glm::vec3(0, 0, 0));
|
||||||
// camTexture->renderTarget.setSize(1024, 1024);
|
camTexture->renderTarget.setSize(1, 1);
|
||||||
|
|
||||||
// auto uiTest = this->createSceneItem();
|
auto uiTest = this->createSceneItem();
|
||||||
// uiTest->transform.setParent(canvas->transform);
|
uiTest->transform.setParent(canvas->transform);
|
||||||
// auto image = uiTest->addComponent<UIImage>();
|
image = uiTest->addComponent<UIImage>();
|
||||||
// image->texture = camTexture->renderTarget.getTexture();
|
image->texture = camTexture->renderTarget.getTexture();
|
||||||
// image->alignment = glm::vec4(0, 0, 50, 0);
|
image->alignment = glm::vec4(0, 0, 50, 0);
|
||||||
// image->alignX = UI_COMPONENT_ALIGN_START;
|
image->alignX = UI_COMPONENT_ALIGN_START;
|
||||||
// image->alignUnitRight = UI_COMPONENT_ALIGN_UNIT_PERCENT;
|
image->alignUnitRight = UI_COMPONENT_ALIGN_UNIT_PERCENT;
|
||||||
// image->alignY = UI_COMPONENT_ALIGN_STRETCH;
|
image->alignY = UI_COMPONENT_ALIGN_STRETCH;
|
||||||
|
|
||||||
this->grid = TilesetGrid(
|
this->grid = TilesetGrid(
|
||||||
1, 26,
|
1, 13,
|
||||||
741, 20540,
|
741, 10270,
|
||||||
0, 0,
|
0, 0,
|
||||||
0, 0
|
0, 0
|
||||||
);
|
);
|
||||||
auto eth = EthPrefab::create(this);
|
auto eth = EthPrefab::create(this);
|
||||||
// eth->tiledSprite->tileset = &grid;
|
eth->tiledSprite->tileset = &grid;
|
||||||
|
|
||||||
// struct Color colors[] = {
|
useEvent([&]{
|
||||||
// COLOR_BLUE, COLOR_MAGENTA, COLOR_WHITE,
|
assertNotNull(camTexture);
|
||||||
// COLOR_MAGENTA, COLOR_CORNFLOWER_BLUE, COLOR_MAGENTA,
|
assertNotNull(image);
|
||||||
// COLOR_BLACK, COLOR_MAGENTA, COLOR_BLUE
|
std::cout << "Size Update" << std::endl;
|
||||||
// };
|
camTexture->renderTarget.setSize(image->getWidth(), image->getHeight());
|
||||||
// text.setSize(3, 3);
|
}, image->eventAlignmentUpdated);
|
||||||
// text.buffer(colors);
|
|
||||||
// textbox->border->texture = &text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Asset*> getRequiredAssets() override {
|
std::vector<Asset*> getRequiredAssets() override {
|
||||||
|
@ -18,8 +18,8 @@ Texture * TextureRenderTarget::getTexture() {
|
|||||||
void TextureRenderTarget::setSize(float_t width, float_t height) {
|
void TextureRenderTarget::setSize(float_t width, float_t height) {
|
||||||
assertTrue(width > 0);
|
assertTrue(width > 0);
|
||||||
assertTrue(height > 0);
|
assertTrue(height > 0);
|
||||||
assertTrue(width != this->getWidth());
|
|
||||||
assertTrue(height != this->getHeight());
|
if(width == this->getWidth() && height == this->getHeight()) return;
|
||||||
|
|
||||||
// Delete old buffers.
|
// Delete old buffers.
|
||||||
if(this->rboId != -1) glDeleteRenderbuffers(1, &this->rboId);
|
if(this->rboId != -1) glDeleteRenderbuffers(1, &this->rboId);
|
||||||
|
@ -62,6 +62,8 @@ int32_t PrefabComponentParser::onParse(
|
|||||||
parser = intParser;
|
parser = intParser;
|
||||||
} else if(type == "bool_t") {
|
} else if(type == "bool_t") {
|
||||||
parser = boolParser;
|
parser = boolParser;
|
||||||
|
} else if(type == "flag_t") {
|
||||||
|
parser = rawParser;
|
||||||
} else if(type.starts_with("enum")) {
|
} else if(type.starts_with("enum")) {
|
||||||
parser = rawParser;
|
parser = rawParser;
|
||||||
} else if(type.find("*") == (type.size() - 1)) {
|
} else if(type.find("*") == (type.size() - 1)) {
|
||||||
|
Reference in New Issue
Block a user