Skip to content

Add dynamic object limit#1142

Draft
Sunketchupm wants to merge 3 commits intocoop-deluxe:devfrom
Sunketchupm:objects
Draft

Add dynamic object limit#1142
Sunketchupm wants to merge 3 commits intocoop-deluxe:devfrom
Sunketchupm:objects

Conversation

@Sunketchupm
Copy link
Contributor

@Sunketchupm Sunketchupm commented Mar 13, 2026

This was something I have been wanting to do for a while and finally managed to. Thanks to Isaac and FrozenAlex for their help.

The object limit doesn't become truly infinite though. Aside from the obvious limiting factor of computer power, there appears to be other forms of the object limit. Sync objects have their own limit determined by SYNC_ID_BLOCK_SIZE (which I don't think I should increase), and the game seems to give up on processing object graphics at a little below 5000 objects (but they are still definitely processed since in testing. I was able to interact with the invisible coins, which were my main test object). The game isn't very stable past that point, so the object limit still exists, but has been increased to 4096 (which isn't very much).

There's no doubt some form of memory leak here since this is my first time using the heap. This, combined with the issues mentioned last paragraph, and uncertainty of how well this will work across the network, is why this is currently a draft. Any help would be appreciated.

Testing mod:

hook_event(HOOK_MARIO_UPDATE, function (m)
    if m.playerIndex ~= 0 then return end

    if m.controller.buttonDown & L_TRIG ~= 0 then
        for i = 1, 100, 1 do
            spawn_sync_object(id_bhvYellowCoin, E_MODEL_YELLOW_COIN, m.pos.x, m.pos.y + 500, m.pos.z, nil)
        end
    end
end)

hook_event(HOOK_UPDATE, function ()
    djui_chat_message_create(tostring(obj_get_count()))
end)

@PeachyPeachSM64
Copy link
Contributor

That's a good attempt to make an unlimited object pool but...
I don't really see the point of splitting the existing object pool into smaller pools of fixed size.
It would make sense if there was for example a pool for each object type, but the pool itself having a fixed size defeats the point. I think it's just added complexity for no real benefit (and I'm not mentioning that weird crash you seem to have if the pool has more 256 elements).
If you want an infinitely growing pool of objects, you should probably take a look at Growing Arrays instead. They are used for the surface system and do the job pretty well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants