From 9af2c28ac7767151654328ef96635b1479a5d984 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 20 Dec 2023 14:17:03 +0100 Subject: [PATCH] Fixed TileMap. --- game_scene.cpp | 28 +++++++++++++++------------- game_scene.h | 10 +--------- sfw/application/tile_map.cpp | 26 +++++++++++++------------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/game_scene.cpp b/game_scene.cpp index 791d40e..ded7bbe 100644 --- a/game_scene.cpp +++ b/game_scene.cpp @@ -105,7 +105,7 @@ void GameScene::render() { camera->bind(); - //tile_map->render(); + //sprite->render(); //material->bind(); //color_material->bind(); @@ -118,6 +118,7 @@ void GameScene::render() { camera_2d->bind(); sprite->render(); + tile_map->render(); } GameScene::GameScene() { @@ -153,11 +154,11 @@ GameScene::GameScene() { //sprite->region_width = 1.0 / 16.0; //sprite->region_height = 1.0 / 16.0; sprite->update_mesh(); - /* + tile_map = new TileMap(); tile_map->material = material; - tile_map->atlas_size_x = 16; - tile_map->atlas_size_y = 16; + tile_map->atlas_size_x = 2; + tile_map->atlas_size_y = 2; tile_map->allocate_data(); @@ -172,7 +173,10 @@ GameScene::GameScene() { } tile_map->build_mesh(); - */ + + tile_map->transform.scale(Vector2(32, 32)); + tile_map->transform.set_origin(Vector2(500, 500)); + camera = new PerspectiveCamera(); //camera->width = 2; @@ -243,17 +247,15 @@ GameScene::GameScene() { } GameScene::~GameScene() { - /* - delete tile_map; - */ - memdelete(camera); - //memdelete(texture); - //memdelete(material); + memdelete(tile_map); - //memdelete(sprite); + memdelete(camera); + memdelete(texture); + + memdelete(sprite); memdelete(camera); memdelete(mesh); - //memdelete(material); + memdelete(material); memdelete(color_material); } diff --git a/game_scene.h b/game_scene.h index 3170e0d..ae32fcb 100644 --- a/game_scene.h +++ b/game_scene.h @@ -3,15 +3,7 @@ #include "scene.h" -/* - - - -#include "texture.h" -#include "texture_material.h" #include "tile_map.h" -*/ - #include "mesh_instance.h" #include "camera.h" #include "camera_2d.h" @@ -42,7 +34,7 @@ public: TextureMaterial2D *material; Camera2D *camera_2d; - //TileMap *tile_map; + TileMap *tile_map; Sprite *sprite; Camera *camera; diff --git a/sfw/application/tile_map.cpp b/sfw/application/tile_map.cpp index 05b0646..9ae2d40 100644 --- a/sfw/application/tile_map.cpp +++ b/sfw/application/tile_map.cpp @@ -1,6 +1,6 @@ #include "tile_map.h" -#include "camera.h" +#include "camera_2d.h" void TileMap::build_mesh() { if (!mesh) { @@ -98,26 +98,25 @@ void TileMap::set_data(const int x, const int y, const uint8_t value) { } void TileMap::render() { - if (!mesh) + if (!mesh) return; - Transform mat_orig = Camera::current_camera->model_view_matrix; - - //Camera::current_camera->model_view_matrix = glm::translate(Camera::current_camera->model_view_matrix, glm::vec3(position.x, position.y, 0)); + Transform2D mat_orig = Camera2D::current_camera->model_view_matrix; - //Camera::current_camera->model_view_matrix = glm::rotate(Camera::current_camera->model_view_matrix, rotation, glm::vec3(0, 0, 1)); + Camera2D::current_camera->model_view_matrix *= transform; - //Camera::current_camera->model_view_matrix = glm::scale(Camera::current_camera->model_view_matrix, glm::vec3(scale.x, scale.y, 0)); - - if (material) + if (material) { material->bind(); + } mesh->render(); - Camera::current_camera->model_view_matrix = mat_orig; + Camera2D::current_camera->model_view_matrix = mat_orig; } -TileMap::TileMap() : Object2D() { +TileMap::TileMap() : + Object2D() { + data = nullptr; size_x = 16; size_y = 16; @@ -129,6 +128,7 @@ TileMap::TileMap() : Object2D() { material = nullptr; } TileMap::~TileMap() { - if (data) - delete[] data; + if (data) { + delete[] data; + } }