Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Entry #83 is it?

Sign in to follow this  


  • Random Observation of the day!!
    If ########### is going to bitch like that someone should remind him that he is living in one of about 100,000,000,000 galaxies in the universe, and our galaxy is about 500,000,000,000,000,000,000 times bigger than he is

    (I've run out of material)

Yeah, so, uh... nothing really new. I've been reading Josuttis, ~100 pages/day, and he makes my current engine layout look like shit. I could have made my life a hell of a lot easier with some creative template classes, and *gulp* ...STL.

Anyway, if I do reincarnate it (it would be the 3rd time) I'd make my own linked list structure that supports random access to speed up inquiries AND allow rapid sorting of elements. Which is necessary when the elements must be sorted to render properly, and their positions change.

My plan to achieve this would only be plausible for lists of class objects, because, well, I'll explain:

// note - this is only psudocode
template <class T>
class VecList {

// this is a list of all the elements themselves
// where the actual data is stored.
std::list tehList;

// this is a vector of pointers to the nodes. It
// is sorted based on the order that the elements
// were added. The internal structure of a list
// provides the pointers to the nodes stay constant,
// thus, we can store pointers at the loss of only
// 1 byte/element.
std::vector tehVector;

// the function by which the list is sorted. If I
// were to make this for a collection of units in
// an RTS, I'd be sorting by Y-Value, so that they
// would draw in the right order w/o a z-buffer.
bool (compFunction*)(T&, T&);


// add an element into the list, sorted
typename T* addElement(T&);

// add an element With Out Sort
typename T* addElementWOC(T&);

// sort the list, overloaded to sort with a different
// comparison predicate.
void sort();
void sort(bool(newCompFunction*)(T&,T&));

// and a special sort that only evaluates the position
// of a single element. Useful if you're only moving one
// but have to do it every pass (ie, moving a unit)
void sort(int index);
// although, if you're moving lots of units, it'd probably
// be better to just call sort() once per pass.

// and some accessors

// get it based on a criterion
typename T* getElement(bool(getFunction)(T&, void*), void*);

// get it based on the index, which is basically what number
// the element was when added. It _should_ be stored
// internally to the element, but technically, could
// just get the pointer at that index in the vector.
typename T* getElement(int idnex);

// and then we'd have all the other crap, so that we
// could use some of STL's generic functions on our new
// container.

// don't forget operators

// unary index operator - returns the pointer stored
// at the specified index in the vector. Gives us
// random access control.
typename T& operator[](index);

//and other crap
typename T& operator=(T&, T&);
bool operator==(T&, T&);

// and finally, constructors/destructors. Do stuff here.
VecList() {...};
~VecList() {...};

And that should give you a container that would autosort like a set, but have non-const values, be sortable after values change, like a list, and have fast random access, like a vector. Or maybe I'm just full of hot air, because Josuttis has brainwashed me with all this template STL-nonsense. Oh well. Screw it all.

Man, I'm starting to sound more like some tech journal from hell. I'll have to think up something better to post ta morrow.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!