Skip to content

Instantly share code, notes, and snippets.

@oeloeloel
Last active September 17, 2020 19:04
Show Gist options
  • Save oeloeloel/35515fd6fa9f9386d215871743c84138 to your computer and use it in GitHub Desktop.
Save oeloeloel/35515fd6fa9f9386d215871743c84138 to your computer and use it in GitHub Desktop.
[DragonRuby] Recycle Symbols for Render Targets (general idea)
$gtk.reset
def tick args
args.state.rt_symbols_recycle_bin = []
args.state.rt_symbol_counter = 0
if args.state.tick_count == 0
# get a couple of fresh symbols
symbol1 = get_rt_symbol(args)
puts symbol1
symbol2 = get_rt_symbol(args)
puts symbol2
# finished using first symbol, recycle it
recycle_rt_symbol(args, symbol1)
# next fetched symbol recycles first
symbol3 = get_rt_symbol(args)
puts symbol3
end
end
def get_rt_symbol(args)
if args.state.rt_symbols_recycle_bin.length == 0
sym = "rt_symbol_#{args.state.rt_symbol_counter}".to_sym
args.state.rt_symbol_counter += 1
sym
else
args.state.rt_symbols_recycle_bin.shift
end
end
def recycle_rt_symbol(args, abandoned_symbol)
args.state.rt_symbols_recycle_bin << abandoned_symbol
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment