Blade Edge

Computer software | Video production | My life in general

Blade Edge main header

Render Madness

October 28th, 2004 · No Comments · Software

Transposed from Gaiiden’s Scroll

man, I finally got some time to just sit and code for like 8 hours straight. Thursdays, I’ve found, are my best coding days. Mondays I do the GDNet newsletter, Tuesdays I’m out with the guys, Wednesdays I generally get in some good coding too, but yesterday I had to ride with my buddy out to PA to sell his bike. Thursdays though… Thursdays I usually don’t do anything except code. Wunderful!

So yea, I finally finished my huge render code overhaul for Katana. *phew*. It was quite an ordeal. I probably ripped out a couple hundred lines of code, edited and stuck back in only half that, which is good. My scene render function is now half the size it was originally. I don’t think I ever fully explained how I was rendering before. Here’s the breakdown:

I came up with the idea of using intermediate surfaces, called viewports, to cut down on render times. I also have scenes, with subscenes. A scene is a collection of subscenes, and a subscene is a collection of objects. This lets me, say, define a “Game Menu” scene, with subscenes “Main Menu”, “Options”, “Credits”, etc. Now, in order to render a subscene, it has to be assigned a viewport. A subscene can have more than one viewport. The objects that belong to that subscene are rendered onto the viewports, which in turn are rendered onto the screen. This gives me a lot of rendering flexibility, For instance, I can make a split screen game simply by creating two viewports into the main game subscene, and have one viewport’s world coordinates offset to show the location of the second player. Additionally, objects can be rendered to the screen using world, viewport, or screen coordinates. So if I have a map, in order to scroll the map, I’d have all the objects in the map viewport set to world coordinates, and then update the viewport’s world coordinates, which will make it seem like the world is scrolling. Stuff like that. Viewports also keep track of whether they are “dirty” or not, i.e. if they’ve been moved on the screen or an object on them has changed. In this case the viewport is re-rendered, otherwise, it’s just blitted straight to the main surface. It’s kinda like a cheap dirty rectangle trick – the only downside is that even tho you may be blitting a single surface rather than 25 individual objects, you still have to clear the screen for each frame.

Anyways, in order to store all these subscenes and objects and viewports and the layers for rendering order, I was using a bunch of maps and lists up the whazooo. To get an object layer, I’d first have to find the subscene from a map, then the object from that subscene from another map, and then the layer object from a third map… good gravy right? All that iterator grabbing had to have been playing havoc on my render times.

So now I’ve encapsulated the process better. I used to store all this in the scene manager class, but after I realized that objects are really contained within viewports, the viewport object class handles it’s own scene objects, while the scene manager handles the viewports. So to render a scene, the scene manager calls the viewports, which call their objects, which update and render themselves. Wheee.

So yea, it was a pretty big overhaul. I seriously wasn’t expecting to get all the errors out and have a clean compile at the end of the night, but I managed to indeed do that 30 minutes ago. I was forced to comment out my std::list sort() functors due to some error I can’t even begin to fathom at 4am and after hours of straight coding. So screw that until tomorrow, heh. Plus it’s the sort functor for the object and viewport layers, so I don’t even need it to test the new render code. I can live without layers for a bit.

Okay, so testing the new render code tomorrow, see if I gain any frames. Here’s hopin. I also got to use Evolution some more, since I had to check out all the files I had to modify. Good stuff. I even had another team member connect successfully to the Evolution server on my machine – after I told stupid Windows Firewall to not block the port I’m using .

Now…. it’s high time for bed, since I gotta be up to drive my family to the airport.


No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment