realtime map resizing

This commit is contained in:
Issac332 2026-07-11 23:16:34 +03:00
parent 3cb8091b11
commit f67cb9ce78
4 changed files with 23 additions and 7 deletions

View file

@ -40,7 +40,7 @@ class DynamicLight
def update
# dont render light if its disabled or not awaked
@light_sprite.visible = Settings[:light] && $light.awaked
if (!Settings[:light] && $light.awaked)
if !Settings[:light] || !$light.awaked
return
end

View file

@ -422,7 +422,7 @@ class Game_Map
tile_id = data[x, y, i]
if tile_id == nil
next #return 0
elsif @terrain_tags[tile_id] > 0
elsif @terrain_tags[tile_id] && @terrain_tags[tile_id] > 0
return @terrain_tags[tile_id]
end
end
@ -549,4 +549,9 @@ class Game_Map
end
@map.data[x, y, z]
end
def resize(x, y, z)
@map.data.resize(x, y, z)
@map.width = x
@map.height = y
end
end

View file

@ -62,9 +62,9 @@ void Table::resize(int x, int y, int z){
std::vector<int16_t> newData(x*y*z);
for (int k = 0; k < std::min(z, zs); ++k)
for (int j = 0; j < std::min(y, ys); ++j)
for (int i = 0; i < std::min(x, xs); ++i)
for (int k = 0; k < z; ++k)
for (int j = 0; j < y; ++j)
for (int i = 0; i < x; ++i)
newData[x*y*k + x*j + i] = at(i, j, k);
data.swap(newData);

View file

@ -52,11 +52,22 @@ public:
/* <internal */
inline int16_t &at(int x, int y = 0, int z = 0){
return data[xs*ys*z + xs*y + x];
int pos = xs*ys*z + xs*y + x;
if (pos >= 0 && pos < data.size()) {
return data[pos];
}
static int16_t dummy = 0;
dummy = 0;
return dummy;
}
inline const int16_t &at(int x, int y = 0, int z = 0) const{
return data[xs*ys*z + xs*y + x];
int pos = xs*ys*z + xs*y + x;
if (pos >= 0 && pos < data.size()) {
return data[pos];
}
static const int16_t fallback = 0;
return fallback;
}
sigc::signal<void> modified;