Barely progress on tilesets
This commit is contained in:
83
src/dawn/display/Tileset.hpp
Normal file
83
src/dawn/display/Tileset.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Tile {
|
||||
public:
|
||||
glm::vec2 uv0;
|
||||
glm::vec2 uv1;
|
||||
};
|
||||
|
||||
struct Tileset {
|
||||
public:
|
||||
std::vector<struct Tile> tiles;
|
||||
};
|
||||
|
||||
struct TilesetGrid : public Tileset{
|
||||
public:
|
||||
int32_t rows;
|
||||
int32_t columns;
|
||||
|
||||
TilesetGrid(
|
||||
int32_t columns,
|
||||
int32_t rows,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
int32_t gapX,
|
||||
int32_t gapY,
|
||||
int32_t borderX,
|
||||
int32_t borderY
|
||||
) {
|
||||
assertTrue(columns >= 1);
|
||||
assertTrue(rows >= 1);
|
||||
assertTrue(width >= 1);
|
||||
assertTrue(height >= 1);
|
||||
assertTrue(gapX >= 0);
|
||||
assertTrue(gapY >= 0);
|
||||
assertTrue(borderX >= 0);
|
||||
assertTrue(borderY >= 0);
|
||||
assertTrue(width >= (columns + (gapX * columns) + borderX + borderX));
|
||||
assertTrue(height >= (rows + (gapY * rows) + borderY + borderY));
|
||||
|
||||
this->rows = rows;
|
||||
this->columns = columns;
|
||||
|
||||
// Calculate division sizes (pixels)
|
||||
float_t divX = (
|
||||
(float_t)width - ((float_t)borderX * 2.0f) -
|
||||
((float_t)gapX * ((float_t)columns - 1))
|
||||
) / columns;
|
||||
float_t divY = (
|
||||
(float_t)height - ((float_t)borderY * 2.0f) -
|
||||
((float_t)gapY * ((float_t)rows - 1))
|
||||
) / rows;
|
||||
|
||||
// Calculate the division sizes (units)
|
||||
float_t tdivX = divX / (float_t)width;
|
||||
float_t tdivY = divY / (float_t)height;
|
||||
|
||||
for(int32_t y = 0; y < rows; y++) {
|
||||
for(int32_t x = 0; x < columns; x++) {
|
||||
struct Tile tile;
|
||||
tile.uv0.x = (borderX + (divX * x) + (gapX * x)) / width;
|
||||
tile.uv1.x = tile.uv0.x + tdivX;
|
||||
|
||||
tile.uv0.y = (borderY + (divY * y) + (gapY * y)) / height;
|
||||
tile.uv1.y = tile.uv0.y + tdivY;
|
||||
this->tiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Tile getTile(int32_t row, int32_t column) {
|
||||
assertTrue(row > 0 && row < this->rows);
|
||||
assertTrue(column > 0 && column < this->columns);
|
||||
return this->tiles[row + (column * this->rows)];
|
||||
}
|
||||
};
|
||||
}
|
@ -28,7 +28,7 @@ namespace Dawn {
|
||||
bool_t finished = false;
|
||||
float_t time = 0;
|
||||
float_t duration = 0;
|
||||
easefunction_t *easing = &easeLinear;
|
||||
easefunction_t *easing = &easeOutQuad;
|
||||
std::vector<struct TimelineItem<T>> timelineItems;
|
||||
Event<> eventAnimationEnd;
|
||||
|
||||
|
@ -8,14 +8,4 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TrueTypeFont.cpp
|
||||
FontMeasure.cpp
|
||||
)
|
||||
|
||||
tool_truetype(truetype_ark
|
||||
ark-pixel.ttf
|
||||
truetype_ark
|
||||
96
|
||||
96
|
||||
10
|
||||
)
|
||||
|
||||
add_dependencies(${DAWN_TARGET_NAME} truetype_ark)
|
||||
)
|
@ -48,4 +48,15 @@ void QuadMesh::bufferQuadMesh(
|
||||
QuadMesh::bufferQuadMeshWithZ(
|
||||
mesh, xy0, uv0, xy1, uv1, 0, verticeStart, indiceStart
|
||||
);
|
||||
}
|
||||
|
||||
void QuadMesh::initQuadMesh(
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z
|
||||
) {
|
||||
assertNotNull(mesh);
|
||||
mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
||||
QuadMesh::bufferQuadMeshWithZ(mesh, xy0, uv0, xy1, uv1, z, 0, 0);
|
||||
}
|
@ -49,5 +49,12 @@ namespace Dawn {
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
);
|
||||
|
||||
static void initQuadMesh(
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z
|
||||
);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user