Various changes

This commit is contained in:
2023-01-29 15:13:24 -08:00
parent 329383da30
commit 3b458aaf96
40 changed files with 410 additions and 447 deletions

View File

@ -8,6 +8,7 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
RenderPipeline.cpp
Transform.cpp
Tileset.cpp
)
# Subdirs

View File

@ -0,0 +1,78 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Tileset.hpp"
using namespace Dawn;
struct Tile Tileset::getTile(int32_t tile) {
assertTrue(tile >= 0);
assertTrue(tile < this->tiles.size());
return this->tiles[tile];
}
TilesetGrid::TilesetGrid() {
}
TilesetGrid::TilesetGrid(
int32_t columns,
int32_t rows,
int32_t w,
int32_t h,
int32_t gapX,
int32_t gapY,
int32_t borderX,
int32_t borderY
) {
assertTrue(columns >= 1);
assertTrue(rows >= 1);
assertTrue(w >= 1);
assertTrue(h >= 1);
assertTrue(gapX >= 0);
assertTrue(gapY >= 0);
assertTrue(borderX >= 0);
assertTrue(borderY >= 0);
assertTrue(w >= (columns + (gapX * columns) + borderX + borderX));
assertTrue(h >= (rows + (gapY * rows) + borderY + borderY));
this->rows = rows;
this->columns = columns;
// Calculate division sizes (pixels)
this->divX = (w - (borderX * 2) - (gapX * (columns - 1))) / columns;
this->divY = (h - (borderY * 2) - (gapY * (rows - 1))) / rows;
// Calculate the division sizes (units)
float_t tdivX = (float_t)this->divX / (float_t)w;
float_t tdivY = (float_t)this->divY / (float_t)h;
for(int32_t y = 0; y < rows; y++) {
for(int32_t x = 0; x < columns; x++) {
struct Tile tile;
tile.uv0.x = (borderX + ((float_t)this->divX * x) + (gapX * x)) / w;
tile.uv1.x = tile.uv0.x + tdivX;
tile.uv0.y = (borderY + ((float_t)this->divY * y) + (gapY * y)) / h;
tile.uv1.y = tile.uv0.y + tdivY;
this->tiles.push_back(tile);
}
}
}
float_t TilesetGrid::getTileWidth() {
return this->divX;
}
float_t TilesetGrid::getTileHeight() {
return this->divY;
}
struct Tile TilesetGrid::getTileFromGrid(int32_t column, int32_t row) {
assertTrue(row > 0 && row < this->rows);
assertTrue(column > 0 && column < this->columns);
return this->getTile(row + (column * this->rows));
}

View File

@ -5,23 +5,25 @@
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
struct Tile {
public:
glm::vec2 uv0;
glm::vec2 uv1;
glm::vec2 uv0;
glm::vec2 uv1;
};
struct Tileset {
public:
std::vector<struct Tile> tiles;
struct Tile getTile(int32_t tile) {
assertTrue(tile >= 0);
assertTrue(tile < this->tiles.size());
return this->tiles[tile];
}
/**
* Returns the tile at the given tile index.
*
* @param tile Tile index to get.
* @return Tile at that index.
*/
struct Tile getTile(int32_t tile);
};
struct TilesetGrid : public Tileset{
@ -31,10 +33,23 @@ namespace Dawn {
int32_t divX;
int32_t divY;
TilesetGrid() {
}
/**
* Constructs a new Tileset Grid.
*/
TilesetGrid();
/**
* Constructs a new Tileset Grid.
*
* @param columns How many columns in the grid of tiles.
* @param rows How many rows in the grid of tiles.
* @param w Width of the grid.
* @param h Height of te grid.
* @param gapX Gap / Gutter between tiles.
* @param gapY Gap / Gutter between tiles.
* @param borderX Border at the edge of the grid before the first tiles.
* @param borderY Border at the edge of the grid before the first tiles.
*/
TilesetGrid(
int32_t columns,
int32_t rows,
@ -44,46 +59,29 @@ namespace Dawn {
int32_t gapY,
int32_t borderX,
int32_t borderY
) {
assertTrue(columns >= 1);
assertTrue(rows >= 1);
assertTrue(w >= 1);
assertTrue(h >= 1);
assertTrue(gapX >= 0);
assertTrue(gapY >= 0);
assertTrue(borderX >= 0);
assertTrue(borderY >= 0);
assertTrue(w >= (columns + (gapX * columns) + borderX + borderX));
assertTrue(h >= (rows + (gapY * rows) + borderY + borderY));
);
this->rows = rows;
this->columns = columns;
/**
* Returns the width of an individual tile.
*
* @return The tile width.
*/
float_t getTileWidth();
// Calculate division sizes (pixels)
this->divX = (w - (borderX * 2) - (gapX * (columns - 1))) / columns;
this->divY = (h - (borderY * 2) - (gapY * (rows - 1))) / rows;
/**
* Returns the height of an individual tile.
*
* @return The tile height.
*/
float_t getTileHeight();
// Calculate the division sizes (units)
float_t tdivX = (float_t)this->divX / (float_t)w;
float_t tdivY = (float_t)this->divY / (float_t)h;
for(int32_t y = 0; y < rows; y++) {
for(int32_t x = 0; x < columns; x++) {
struct Tile tile;
tile.uv0.x = (borderX + ((float_t)this->divX * x) + (gapX * x)) / w;
tile.uv1.x = tile.uv0.x + tdivX;
tile.uv0.y = (borderY + ((float_t)this->divY * y) + (gapY * y)) / h;
tile.uv1.y = tile.uv0.y + tdivY;
this->tiles.push_back(tile);
}
}
}
struct Tile getTileFromGrid(int32_t row, int32_t column) {
assertTrue(row > 0 && row < this->rows);
assertTrue(column > 0 && column < this->columns);
return this->getTile(row + (column * this->rows));
}
/**
* Returns the tile at a given grid position.
*
* @param column Column (0 indexed) to get the tile of.
* @param row Row (0 indexed) to get the tile of.
* @return Tile at this grid position.
*/
struct Tile getTileFromGrid(int32_t column, int32_t row);
};
}

View File

@ -8,6 +8,12 @@
#include "assert/assert.hpp"
namespace Dawn {
/**
* Append a list on to another list.
*
* @param list Pointer to list that is being appended to.
* @param append Pointer to list that will be appended.
*/
template<typename T>
void vectorAppend(std::vector<T> *list, std::vector<T> *append) {
assertNotNull(list);
@ -20,6 +26,12 @@ namespace Dawn {
}
}
/**
* Append a list on to another list.
*
* @param list Pointer to list that is being appended to.
* @param append List that will be appended.
*/
template<typename T>
void vectorAppend(std::vector<T> *list, std::vector<T> append) {
assertNotNull(list);

View File

@ -25,11 +25,9 @@ void SimpleVNScene::stage() {
// Camera
this->camera = Camera::create(this);
this->camera->transform->lookAtPixelPerfect(
glm::vec3(0, 0, 0),
glm::vec3(0, 0, 0),
this->camera->getRenderTarget()->getHeight(),
camera->fov
this->camera->transform->lookAt(
glm::vec3(0, 0, 3),
glm::vec3(0, 0, 0)
);
this->background = SimpleVisualNovelBackground::create(this);