diff --git a/tile_map.cpp b/tile_map.cpp index baecf93..4616566 100644 --- a/tile_map.cpp +++ b/tile_map.cpp @@ -549,8 +549,10 @@ void RTileMap::update_dirty_quadrants() { Ref normal_map = tile_set->tile_get_normal_map(c.id); Color modulate = tile_set->tile_get_modulate(c.id); Color self_modulate = get_self_modulate(); - modulate = Color(modulate.r * self_modulate.r, modulate.g * self_modulate.g, - modulate.b * self_modulate.b, modulate.a * self_modulate.a); + float col = (static_cast(c.rao) / 255.0) * 0.3; + + modulate = Color(modulate.r * self_modulate.r - col, modulate.g * self_modulate.g - col, + modulate.b * self_modulate.b - col, modulate.a * self_modulate.a); if (r == Rect2()) { tex->draw_rect(canvas_item, rect, false, modulate, c.transpose, normal_map); } else { @@ -897,7 +899,7 @@ void RTileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip } else { ERR_FAIL_COND(!Q); // quadrant should exist... - if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (uint16_t)p_autotile_coord.x && E->get().autotile_coord_y == (uint16_t)p_autotile_coord.y) { + if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (int16_t)p_autotile_coord.x && E->get().autotile_coord_y == (int16_t)p_autotile_coord.y) { return; //nothing changed } } @@ -908,8 +910,9 @@ void RTileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip c.flip_h = p_flip_x; c.flip_v = p_flip_y; c.transpose = p_transpose; - c.autotile_coord_x = (uint16_t)p_autotile_coord.x; - c.autotile_coord_y = (uint16_t)p_autotile_coord.y; + c.autotile_coord_x = (int16_t)p_autotile_coord.x; + c.autotile_coord_y = (int16_t)p_autotile_coord.y; + c.rao = static_cast(static_cast(CLAMP(noise->get_noise_2d(p_x, p_y), 0, 1) * 256.0) % 256); _make_quadrant_dirty(Q); used_size_cache_dirty = true; @@ -1267,6 +1270,7 @@ PoolVector RTileMap::_get_tile_data() const { encode_uint32(val, &ptr[4]); encode_uint16(E->get().autotile_coord_x, &ptr[8]); encode_uint16(E->get().autotile_coord_y, &ptr[10]); + idx += 3; } @@ -1895,6 +1899,10 @@ void RTileMap::_changed_callback(Object *p_changed, const char *p_prop) { } RTileMap::RTileMap() { + noise.instance(); + //noise->set_seed(Math::rand()); + noise->set_noise_type(FastNoise::TYPE_PERLIN); + rect_cache_dirty = true; used_size_cache_dirty = true; pending_update = false; diff --git a/tile_map.h b/tile_map.h index 8e5bb8e..a9ee8c4 100644 --- a/tile_map.h +++ b/tile_map.h @@ -37,6 +37,8 @@ #include "scene/2d/node_2d.h" #include "tile_set.h" +#include "../fastnoise/noise.h" + class CollisionObject2D; class RTileMap : public Node2D { @@ -80,6 +82,7 @@ private: bool use_kinematic; Navigation2D *navigation; bool show_collision = false; + Ref noise; union PosKey { struct { @@ -110,18 +113,24 @@ private: } }; - union Cell { - struct { - int32_t id : 24; - bool flip_h : 1; - bool flip_v : 1; - bool transpose : 1; - int16_t autotile_coord_x : 16; - int16_t autotile_coord_y : 16; - }; + struct Cell { + int32_t id; + bool flip_h; + bool flip_v; + bool transpose; + int16_t autotile_coord_x; + int16_t autotile_coord_y; + uint8_t rao; - uint64_t _u64t; - Cell() { _u64t = 0; } + Cell() { + id = 0; + flip_h = false; + flip_v = false; + transpose = false; + autotile_coord_x = 0; + autotile_coord_y = 0; + rao = 0; + } }; Map tile_map;