My Week #9
It generally looked like this:
Where do I start?
The majority of the work, and the pain causing the above image, involved making a data structure with O(log(n)) time when adding or deleting blocks from it. Took me 4 days to fix the problem.
To elaborate: I was creating a data structure for the pieces of the ship. The structure should've been really cheap in the memory, and could have fast lookup, delete, and insert times. The general idea was a 3D Spacial Tree, which held 3D "chunks" of blocks, with the models inside the chunks. Now...That didn't work...At. All.
So, after taking some time off and relaxing this crispy fried, slightly burnt (read 'burnt to ashes') brain of mine, I came up with a simpler, faster, easier to implement, and not to mention more memory efficient, way of doing things. A 3D "Map".
The 3D Chunks of blocks are basically the same as the previous idea above, but with a 3D map of the chunks, where you could access any chunk by specifying its location in space. If the function returned NULL, then the chunk located there, isn't there. If the function returned something that isn't NULL, and assuming there wasn't a weird bug (Tests have proved it doesn't! ☺), it was returning the actual chunk and it's data. The algorithm is pretty simple, but there needs to be a lot of checks.
So, what else was done this week?
Well, I found out that past me decided NOT to implement a few vital functions in my RenderList class (ie, removing models from it). So that cued in some writing, and rewriting of the RenderList.
My implementation of the RenderList was a list of textures holding a list of models, but all in one list. What that means is that, let's say we have 3 textures (Tex1, Tex2, Tex3). We also have a handful of models (M1, M2, ...). I had an array that basically looked like this:
(Tex1 starts here)M1, M2, M3, (Tex2) M4, M5, (Tex3) M6, M7,M8;
Now, lets say we wanted to add M9 to the list, and it has Tex2; that would mean finding the end of Tex2 (which was already recorded down), moving the array elements from that end to the end of the array, up by one. Then inserting M9 at the end of Tex2.
Fine and dandy, but what happens if we have 4000+ models, with 4 textures? While the texture count may be low, but if we inserted a model with texture 1 in the list, the entire list, minus the first texture, would have to move. I didn't quite like that. It was messy, and to be honest, not worth the small benefit I'd be saving by keeping everything in one array, if there was any benefit. So I now have it where each texture has it's own little list of models.
Anyhow, deleting from the previous implementation was causing more segfaults!
Lesson Learned: Simpler == Better
So, a bit late, as typically I'd have my work for this week finished by friday, with a few days to mess around, I finished this on saturday:
Yes, I know...Cubes again....Hey, it was the easiest thing to load and work with!
I also did a little fake lighting by "forcing" a ray of light. Now, my next goal to get is to get multiple pieces in and using the scroll wheel to change them up. That should be relatively easy, so once that is done, implement some basic saving/loading functionality.
It's a nice feeling finally working on the game editor, instead of the engine☺. I continued working on some miscellaneous things on Sunday, namely proper lighting, and I must say, I'm pretty impressed with the results. But that's a surprise for next week! So make sure you come back to see what I've done!
Not much else to say, I hope you enjoyed reading this, people on twitter are going to get a new little view now, and everyone else, if you're not following me on twitter, why not? You'll get the news when it's actually new and not a few days old!
But anyhow, enough of my ranting, I'll be back next week. Until then, have a good time!