An explanation

Posted by Astryl on July 28, 2012, 3:47 a.m.

First things first, the last <n>(?) blogs I wrote were written under the

strain of increased fatigue. Figured that out when I nearly blacked out

yesterday. I've been sleeping a lot now, in order to catch up (1-2 hours of

sleep per 24 hours doesn't cut it).

Completely broke my sleeping pattern, trying to get as much done as I could

before I have to start work. :3

Secondly, let's get to what this blog is about: Decisions.

Rob asked a good question in my one blog earlier; one which I failed to

answer coherently. So here we go. Let me try this now that I've had at least ten hours of solid sleep.

Why std::vector instead of std::list?

No reason, they're interchangeable for the most part. I should have

used std::list from the start, but I'm in the bad habit of automatically

using vector.

Linear traversal of a list is definitely faster, whereas vector is better

suited to random access. Of course, in Exile, the only thing I'm really

using Containers for would be the Asset manager.

Before the game can start, all resources are loaded into their respective

vectors, usually with a corresponding nametable.

The Assets class provides the GetImage("name") and GetImageByID(9) static

member functions. These use the nametable and the corresponding index in

the resource table to return a pointer to the image, or throws an exception

if that image was not loaded.

If I was to rework the system, I would have created a pair-list class, with

a basic hash table. And I probably would've done it from scratch.

Of course, I wasn't expecting to get this far with Exile, nor the framework

underlying it; so my all encompassing excuse for the use of vectors where

lists would do better is this: Prototype evolution.

Why my object vectors are insert-sorted

This only takes effect in the 2D mode of the framework, and was only in use

for Exile. It's useless in 3D.

The best way to describe this is as a cheap depth sort.

Of course, a faster method would be to create my own doubly-linked list

class, and use recursion to add new objects.

Then call a recursive function to draw all elements from the tail of the

list.

Things I'm doing now

I created a rather extensive framework thanks to this competition, and I'm

definitely going to be shelving it for further use.

Already it's proven itself useful beyond a doubt, as I started creating

Arbiter with it. And then I moved on to Exile, using the exact same

framework.

There are a lot of optimizations and general rewrites that need to be

performed on the framework, granted. I have marked several locations within

the code that need optimization, mathematical attention, and re-design; but

the 'engine' and the games I created with it work for now.

I'm planning on releasing the cleaned and optimized code to Exile within

the next month or so. I still need to go back and resolve the problems I

'brute-forced' because of the time constraints.

Well, back to whatever it is I was going to do today. Read a book perhaps.

Comments

Astryl 12 years, 3 months ago

Quote:
Fair enough, but marking all the entries for deletion with a vector and compressing it in one go will still be faster.
Now that's an interesting idea. Might try that, since I'm going to be rewriting portions of the game next weekend…