Cleanups.

This commit is contained in:
Relintai 2024-01-05 00:48:07 +01:00
parent 847de487e0
commit 6c7a1e239f
13 changed files with 58 additions and 48 deletions

View File

@ -219,7 +219,7 @@ GameScene::GameScene() {
sprite->update_mesh();
tile_map = new TileMap();
tile_map->material = material.ptr();
tile_map->material = material;
tile_map->atlas_size_x = 2;
tile_map->atlas_size_y = 2;

View File

@ -2,10 +2,6 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <cstring>
#include <functional>
#include <iostream>
#include <vector>
class String;

View File

@ -8,6 +8,8 @@
#include "core/error_macros.h"
#include "core/memory.h"
#include <cstring>
#define COMPACT_CHUNK(m_entry, m_to_pos) \
do { \
void *_dst = &((unsigned char *)pool)[m_to_pos]; \

View File

@ -10,7 +10,6 @@
#include "object/resource.h"
#include "core/ustring.h"
#include "font_material.h"
class Image;

View File

@ -8,7 +8,6 @@
#include "core/vector2i.h"
#include "object/object.h"
//#include "core/os/main_loop.h"
#include "core/rb_map.h"
#include "core/rb_set.h"
#include "core/thread_safe.h"

View File

@ -2,7 +2,7 @@
#define MESH_H
#include "core/vector.h"
#include <inttypes.h>
#include "core/int_types.h"
#include "core/color.h"
#include "object/resource.h"

View File

@ -9,7 +9,9 @@
#include "core/transform_2d.h"
#include "core/vector2.h"
class Camera2D : Object2D {
class Camera2D : public Object2D {
SFW_OBJECT(Camera2D, Object2D);
public:
Transform2D get_model_view_matrix();
void set_model_view_matrix(const Transform2D &p_value);

View File

@ -3,11 +3,15 @@
#include "render_core/3rd_glad.h"
#include "render_objects/object_3d.h"
#include "core/projection.h"
#include "core/transform.h"
#include "core/vector3.h"
class Camera3D {
class Camera3D : public Object3D {
SFW_OBJECT(Camera3D, Object3D);
public:
Transform get_camera_transform();
void set_camera_transform(const Transform &p_value);

View File

@ -1,9 +1,13 @@
#ifndef OBJECT_2D_H
#define OBJECT_2D_H
#include "object/object.h"
#include "core/transform_2d.h"
class Object2D {
class Object2D : public Object {
SFW_OBJECT(Object2D, Object);
public:
Object2D();
virtual ~Object2D();

View File

@ -1,15 +1,18 @@
#ifndef OBJECT_3D_H
#define OBJECT_3D_H
#include "object/object.h"
#include "core/transform.h"
class Object3D {
public:
Object3D();
virtual ~Object3D();
class Object3D : public Object {
SFW_OBJECT(Object3D, Object);
Transform transform;
public:
Object3D();
virtual ~Object3D();
Transform transform;
};
#endif // OBJECT_3D_h

View File

@ -14,6 +14,8 @@ class FontMaterial;
class Mesh;
class Text2D : public Object2D {
SFW_OBJECT(Text2D, Object2D);
public:
Color get_text_color() const;
void set_text_color(const Color &p_color);

View File

@ -3,8 +3,8 @@
#include "render_objects/camera_2d.h"
void TileMap::build_mesh() {
if (!mesh) {
mesh = new Mesh(2);
if (!mesh.is_valid()) {
mesh = Ref<Mesh>(memnew(Mesh(2)));
} else {
mesh->clear();
}
@ -24,8 +24,9 @@ void TileMap::build_mesh() {
for (int y = 0; y < size_y; ++y) {
uint8_t d = data[x_offset + y];
if (d == 0)
if (d == 0) {
continue;
}
float px;
float py;
@ -52,16 +53,17 @@ void TileMap::build_mesh() {
}
void TileMap::allocate_data() {
if (size_x <= 0 || size_y <= 0)
if (size_x <= 0 || size_y <= 0) {
return;
}
if (data) {
delete[] data;
memdelete_arr(data);
}
int size = size_x * size_y;
data = new uint8_t[size];
data = memnew_arr(uint8_t, size);
for (int i = 0; i < size; ++i) {
data[i] = 0;
@ -98,7 +100,7 @@ void TileMap::set_data(const int x, const int y, const uint8_t value) {
}
void TileMap::render() {
if (!mesh) {
if (!mesh.is_valid()) {
return;
}
@ -106,7 +108,7 @@ void TileMap::render() {
Camera2D::current_camera->set_model_view_matrix(mat_orig * transform);
if (material) {
if (material.is_valid()) {
material->bind();
}
@ -115,20 +117,16 @@ void TileMap::render() {
Camera2D::current_camera->set_model_view_matrix(mat_orig);
}
TileMap::TileMap() :
Object2D() {
data = nullptr;
TileMap::TileMap() {
data = NULL;
size_x = 16;
size_y = 16;
atlas_size_x = 1;
atlas_size_y = 1;
mesh = nullptr;
material = nullptr;
}
TileMap::~TileMap() {
if (data) {
delete[] data;
memdelete_arr(data);
}
}

View File

@ -8,29 +8,30 @@
#include "render_core/material.h"
class TileMap : public Object2D {
public:
SFW_OBJECT(TileMap, Object2D);
void build_mesh();
void allocate_data();
void add_rect(const int x, const int y, const float uv_x, const float uv_y, const float uv_size_x, const float uv_size_y);
public:
void build_mesh();
void allocate_data();
void add_rect(const int x, const int y, const float uv_x, const float uv_y, const float uv_size_x, const float uv_size_y);
uint8_t get_data(const int x, const int y) const;
void set_data(const int x, const int y, const uint8_t value);
uint8_t get_data(const int x, const int y) const;
void set_data(const int x, const int y, const uint8_t value);
void render();
void render();
TileMap();
~TileMap();
TileMap();
~TileMap();
uint8_t *data;
int size_x;
int size_y;
uint8_t *data;
int size_x;
int size_y;
int atlas_size_x;
int atlas_size_y;
int atlas_size_x;
int atlas_size_y;
Mesh *mesh;
Material *material;
Ref<Mesh> mesh;
Ref<Material> material;
};
#endif