|
I'm attempting to create a BuiltIn Array wrapper in order to make a Circular Buffer, I basically want a class that acts just like an array... although when you Add it checks the maximum length and Shifts the first item if the length is exceeded. What would be the best approach to this?
(comments are locked)
|
|
It's a slow day, thought I'd write you one. You can use it from JS but I wrote it in C# as I wanted to create a generic version. Hence you should put this in a CS file and place it in a Plugins folder to access it from JS. To use in Javascript: If you choose to use insert, be aware that inserting at 0 will cause it to be immediately deleted if the list is at capacity. That's brilliant, haven't had a chance to test it but it's looks great. Might translate it into js for the benefit of others! Thanks for putting the time aside to answers!
Jun 15 '12 at 12:41 AM
Caiuse
This is not really a circular buffer ;) It's more like a mixture of a list and a queue :D Also two more points:
As a quick an dirty solution this works of course ;) Final note: Depending on the usage, Circular buffers usually have a read and write pointer. Especially to detect buffer-overruns. I guess the OP doesn't really want a circular buffer, since it's usually just a queue without random access. @caius-1: It would be great if you could go a bit more in detail for what purpose you need the buffer.
Jun 15 '12 at 01:35 AM
Bunny83
You are quite right of course :) It was a slow day, but not that slow... Actually as I hacked it out I typed override into MonoDevelop and it gave me Add and Insert - it wasn't until I'd actually posted it that I realised it had just happily dropped the override as they weren't virtual.
Jun 15 '12 at 01:37 AM
whydoidoit
(comments are locked)
|

this is probably more a general programming question than Unity specific.
if you used say StackOverflow you'd get heaps of idiots offering your general pseudocode within a few minutes - maybe that is better for you?
Okay will do, might post me answer from there :D Cheers