• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.0] How do I remove a tile?

Acedayz

Member
Joined
Jan 24, 2015
Messages
38
Reaction score
19
I'm currently creating thousands of [Edit: 1,073,741,824] tiles using Game.createTile(position[, isDynamic = false]).
And these tiles will eventually no longer be needed, so I need a way to remove them to save memory.

Here is the function to create tiles:
Code:
int32_t LuaScriptInterface::luaGameCreateTile(lua_State* L)
{
    // Game.createTile(x, y, z[, isDynamic = false])
    // Game.createTile(position[, isDynamic = false])
    Position position;
    bool isDynamic;
    if (isTable(L, 1)) {
        position = getPosition(L, 1);
        isDynamic = getBoolean(L, 2, false);
    } else {
        position.x = getNumber<uint16_t>(L, 1);
        position.y = getNumber<uint16_t>(L, 2);
        position.z = getNumber<uint16_t>(L, 3);
        isDynamic = getBoolean(L, 4, false);
    }

    Tile* tile = g_game.getTile(position);
    if (!tile) {
        if (isDynamic) {
            tile = new DynamicTile(position.x, position.y, position.z);
        } else {
            tile = new StaticTile(position.x, position.y, position.z);
        }
        g_game.setTile(tile);
    }

    pushUserdata(L, tile);
    setMetatable(L, -1, "Tile");
    return 1;
}

However, there's no function that can remove tiles.
How would I go about doing this?
 
Last edited:
I don't know if you mean only c++ or also lua, you should explain better.
In lua i use this:
Code:
local position = {x, y, z}
local tile = position:getTile()
tile:remove(-1)
 
Considering the way it is currently implemented there is no safe way to remove a tile completely. There is no guarantee that the tile you want to remove is not referenced by other internal server objects. Oh and BTW. I think you're trying to optimize prematurely. A DynamicTile occupies only 88 bytes on x64. Even if you create 10000 tiles and leave them, it's going to increase your memory usage only by around 800 KiB.
 
Considering the way it is currently implemented there is no safe way to remove a tile completely. There is no guarantee that the tile you want to remove is not referenced by other internal server objects. Oh and BTW. I think you're trying to optimize prematurely. A DynamicTile occupies only 88 bytes on x64. Even if you create 10000 tiles and leave them, it's going to increase your memory usage only by around 800 KiB.
That's what I was afraid of.
You're right, if I was talking about a few thousand tiles as I said (which is not actually true) it wouldn't matter.

However, the max possible amount of tiles that could be created on my server would be 1,073,741,824 which would increase my memory usage by 94.5gb.
That's A LOT.

So, there's actually no possibility to remove tiles without a huge amount of work then?
 
What is creating 1,073,741,824 tiles? first time i see problem like that. Do you want remove your map or what the..?
As i said you didnt explain anything and trying to get help, it's wrong.

Show us script that creates tiles and tell what is that for so someone can help you.
 
What is creating 1,073,741,824 tiles? first time i see problem like that. Do you want remove your map or what the..?
As i said you didnt explain anything and trying to get help, it's wrong.

Show us script that creates tiles and tell what is that for so someone can help you.
There's no need to show any scripts, or explain what I'm trying to do (except to completely remove a tile).

Anyways, what I'm doing is creating random generated maps. Pretty much like Minecraft.
So when a player walks around, 9 chunks (16x16 tiles each) are created automatically around the player.

Chunks that the player cannot see are then removed (all items in each chunk) and saved to disk, so I can load them later.
What I need to do is to remove the tiles as well so I won't run out of memory, and there's currently no way to do that.

I've limited the map size to 32768x32768, which is enough for what I'm doing.
Currently I'm only creating tiles at floor 7, but later on I'll also create small parts on other floors as well.
 
@Acedayz

While it is possible to do, I don't recommend it because it would be extremely hard to do it right. The map and tile code is in a dire need of a rewrite because it's really messy. If you want, you can start a discussion in the TFS issue tracker (a map code rewrite is sort of hanging in the roadmap, but unlikely to happen for TFS 1.2) if you have suggestions about it or if you want to provide a bounty.
 
@Acedayz

While it is possible to do, I don't recommend it because it would be extremely hard to do it right. The map and tile code is in a dire need of a rewrite because it's really messy. If you want, you can start a discussion in the TFS issue tracker (a map code rewrite is sort of hanging in the roadmap, but unlikely to happen for TFS 1.2) if you have suggestions about it or if you want to provide a bounty.
Alright, guess I'll have to find another way to accomplish this.
Thanks for the help though!
 
Back
Top