mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 15:44:35 +00:00
added make_pooled, refactor pooling out of vector classes for easy reuse
This commit is contained in:
parent
3cc177a0c0
commit
6ef19cfde0
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
add pooling functionality to a class
|
add pooling functionality to a class
|
||||||
|
|
||||||
adds a handful of class and instance methods
|
adds a handful of class and instance methods to do with pooling
|
||||||
]]
|
]]
|
||||||
|
|
||||||
return function(class, limit)
|
return function(class, limit)
|
||||||
@ -29,9 +29,11 @@ return function(class, limit)
|
|||||||
--(re-initialised with new, or freshly constructed if the pool was empty)
|
--(re-initialised with new, or freshly constructed if the pool was empty)
|
||||||
function class:pooled(...)
|
function class:pooled(...)
|
||||||
if #_pool == 0 then
|
if #_pool == 0 then
|
||||||
return c(...)
|
return class(...)
|
||||||
end
|
end
|
||||||
return c.drain_pool():new(...)
|
local instance = class:drain_pool()
|
||||||
|
instance:new(...)
|
||||||
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
--release a vector to the pool
|
--release a vector to the pool
|
||||||
|
@ -92,6 +92,7 @@ These modules are probably only useful to some folks in some circumstances, or a
|
|||||||
- [`colour`](./colour.lua) - Colour conversion routines. Alias `color`.
|
- [`colour`](./colour.lua) - Colour conversion routines. Alias `color`.
|
||||||
- [`manual_gc`](./manual_gc.lua) - Get GC out of your update/draw calls. Useful when trying to get accurate profiling information; moves "randomness" of GC. Requires you to think a bit about your garbage budgets though.
|
- [`manual_gc`](./manual_gc.lua) - Get GC out of your update/draw calls. Useful when trying to get accurate profiling information; moves "randomness" of GC. Requires you to think a bit about your garbage budgets though.
|
||||||
- [`unique_mapping`](./unique_mapping.lua) - Generate a unique mapping from arbitrary lua values to numeric keys - essentially making up a consistent ordering for unordered data. Niche, but can be used to optimise draw batches for example, as you can't sort on textures without it.
|
- [`unique_mapping`](./unique_mapping.lua) - Generate a unique mapping from arbitrary lua values to numeric keys - essentially making up a consistent ordering for unordered data. Niche, but can be used to optimise draw batches for example, as you can't sort on textures without it.
|
||||||
|
- [`make_pooled`](./make_pooled.lua) - add pooling/recycling capability to a class
|
||||||
|
|
||||||
Any aliases are provided at both the `batteries` module level, and globally when exported.
|
Any aliases are provided at both the `batteries` module level, and globally when exported.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user