123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|729|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Question of the Day -> QOTD - Bothering to Sort Things

Mon, 20 Nov 2006, 15:14
Jayenkai
Today's Q
Whenever you have a load of objects in a game, do you ever bother to organise them?
What kind of occasions is sorted objects better than unsorted, and do you ever bother to use a complex sorting algorhythm, or just settle for a plain sort? (check through, if x>y then t=x:x=y:y=t, kinda thing)

Why's this here?
I posted QOTD's over at CodersWorkshop, whenever the site looked like it was drifting away from the coding.
Currently we all seem to be discussing consoles, so I thought I'd get us all thinking code-stuff again!

Future QOTDs
If you can think of a great QOTD, PM it, or email it to me.. (so's we don't end up with topics full of everyone answering each other's QOTDs!)

-=-=-
''Load, Next List!''
Mon, 20 Nov 2006, 15:41
Scherererer
It really depends. Firstly, the main thing that would change is the type of data structure that i would be using for the objects. And secondly, what kind of a game it is. It would really depend on whether it was more efficient on average to have everything sorted or to search for them in an unsorted mess.

-=-=-
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus
Mon, 20 Nov 2006, 21:40
Scherererer
And also, extending what Agent Smith said, not only would you insert them at the correct order at load time, but you would also want to insert all new items in their respective positions in the order of things.

-=-=-
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus
Tue, 21 Nov 2006, 03:55
Jayenkai
Biggest thing I've had to organise is the Word List for Stringy Things, but even then that was only for the purpose of quickly spotting and removing duplicate words. Otherwise the game tends to run through the whole word list each time anyway.

-=-=-
''Load, Next List!''
Tue, 21 Nov 2006, 14:42
magicman
every once in a while i will organize code, in major projects mainly. but normaly i dont, especialy in ww's. boo organization!

-=-=-
Stuff... Yeah...
Wed, 22 Nov 2006, 15:00
HoboBen
The only thing that I think I've sorted in a game was a list of debug messages, that scrolled down the screen.

Basically, I had a function:

AddDebugMessage(text$,detail=0)

It would scroll through an array, and shift each value in it down one. The newer message would then occupy the first array value, and the last one would be chopped off.

Then, to draw the debug text to screen, I would just loop through it.

I could have just added the debug messages to the end, and loop through the array backwards, but it seemed tidier this way.

The same concept could be applied to HUD text-updates, such as adding mission objectives, or a chat engine.

But, that's all I've ever sorted, reasoning that all my game objects would be looped through anyway, and things like the physics engine would work on them no matter what order they were in.

-=-=-
blog | work | code | more code
Wed, 22 Nov 2006, 15:38
hyruleknight
i try to always organize my code, so i don't have to overhual often.

but it becomes messing and i have to rewrite it

-=-=-
i like green haired girls...
Wed, 22 Nov 2006, 19:29
JL235
I've never really had to sort any of the data structures in my code. It's either entered in order (like in an array) or doesn't need ordering. The only time I can remember doing anything like that was recently in one of my assignments where I had to make a spellchecker. When you add a word I had to iterate through so it was entered lexicographically to keep the order of the dictionary.
Thu, 23 Nov 2006, 06:14
mike_g
I only know how to do a bubble sort

For sorting Types I give them a handle and swap that according to whatever field I want to sort em by. Still thats probably not the best way to sort Types.
Thu, 23 Nov 2006, 08:07
Scherererer
We had a test on sorting algorithms last week actually... Insertion sort, merge sort, selection sort, and bubble sort.

-=-=-
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus