WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Class instances and object pool issues (https://www.wowinterface.com/forums/showthread.php?t=57096)

ArsenalLagspike 04-04-19 07:19 PM

Class instances and object pool issues
 
Ok, so I am instantiating object pools to help me manage state for the mod. Here is a basic run-down of how I am doing it:

Code:

HF_ObjectPool = {
    class = nil;
    available = {};
    inUse = {};
};
HF_ObjectPool.__index = HF_ObjectPool;

-- Instantiates a new pool for a specific class.
-- This class will be used to generate new instances of objects from.
function HF_ObjectPool.new(_class)
    local self = setmetatable({}, HF_ObjectPool);
    self.class = _class;
    return self;
end;

So whenever I need a new pool of objects, I would say:

Code:

HF_GroupPool = HF_ObjectPool.new(HF_Group);
HF_Group being a class object similar to how I am instantiating the object pool class.

The issue I am having in theory is this:

This works fine. Unique keys, the new things get placed in the inUse table on each with helpers I didn't include. Yay.
Code:

PoolA['thing1'] = HF_Thing.new('thing1');
PoolB['thing2'] = HF_Thing.new('thing2');

This blows up. The inUse table in B for some reason recognized the key meant to only be in table A, and then invokes the re-use strategy I have in place.
Code:

PoolA['thing1'] = HF_Thing.new('thing1');
PoolB['thing1'] = HF_Thing.new('thing1');

I am also assigning all function for each "class" like:
function Class.someFunction()

Would it make a difference to make local classes then assign them to props when I "new" an "instance"? Would making them local do anything? I'm new to Lua so I'm not sure why table refs are bleeding between tables.

ArsenalLagspike 04-05-19 05:08 PM

Actually might have figured it out. Seems like I tricked myself into thinking I was making real instances when really its all part of a larger table. So I cannot use generic "classes" or else they will clobber each-other. I need to make an object pool specific to each type of object.

Bummer too, it had some fancy engineering in it.


All times are GMT -6. The time now is 05:54 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI