Quantcast Class instances and object pool issues - WoWInterface
Thread Tools Display Modes
04-04-19, 07:19 PM   #1
ArsenalLagspike
A Murloc Raider
Join Date: Mar 2019
Posts: 8
Question 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.
  Reply With Quote
04-05-19, 05:08 PM   #2
ArsenalLagspike
A Murloc Raider
Join Date: Mar 2019
Posts: 8
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.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Class instances and object pool issues

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off