Monday, February 13, 2012

Housekeeping

Hey Readers,

Bit of a boring week this past week. Lots of internal work went on but not much for new screenshots.

I started the week off by moving a lot of the code for controlling the editor camera into an EditorCameraController class. It had all been sitting in my GameRenderTask class which should have only been responsible for setting up some of the game rendering things like setting up views and other game related things but since it was one of the first things I got up and running a lot of game specific code got placed in there. That got me to thinking about a proper separation of game and editor code which led me to create a MainGameState class. I migrated all the code for player creation out of the GameRenderTask and into the MainGameState.

The next day I did was to move the SceneCollector which collects all the renderable objects out of the EditorGameState and into the GameRenderTask as it made a lot more sense to be in there. The scene collector essentially visits all the renderable sprockets as a container which allows the sprockets to fill the container with any renderable data for the scene. This container can then be batch processed for things like occlusion and frustum culling and then passed to the views. I also fixed up a little bug that was crashing my debug drawing if it was disabled, just a stupid little thing where a buffer count wasn't being reset. I then got to thinking that it would be a good idea to have a way to properly switch between my editor and my game. Up to this point they had essentially been the same thing. I decided I needed to think about this one and wait before I implemented anything. Before attempting that I needed to get my coin collection scheme working. I decided that instead of the coin delegator which I had originally started to implement that I would create a coin collector component. This idea seemed to fit better with my component based architecture.

Wednesday I managed to get the coin collector finished up. I ran into some stupidness with the compiler where it wouldn't compile some templated code unless I separated it into a couple lines. It had me bonking my head on the bus window for half my trip trying to figure out why it wouldn't compile since the code looked fine. The rest of the trip was spent cleaning up the creation codepath for my player sprocket. It was still using the old creation method which was leading to some updating issues with some of the components. I also made a small change to the rendering code and disabled the rendering of bounding boxes if an object was spawned. It was getting annoying seeing all the bounding boxes when I was trying to place down coins.

Thursday, I decided that placing coins was a pain in the ass, the reason, trying to get the coins lined up properly. I decided it was time for some settings in my editor. I repurposed the Protoform property window to work for settings as well. So the first setting to implement was snap. I already had code for snapping in the editor but it was hooked up to a constant value. So it was a pretty quick change to get snap working and it made placing the coins a lot easier. I still need to get save and load working for the settings window though. I also fixed a little bug where the UINode editor wasn't working anymore. It was just because I had changed the default behaviour of my windows to be hidden on creation, so I just needed to add a call to make the UI nodes visible. On the way home that day I implemented object deletion within the editor. Kinda crazy that I had gone this long without any kind of object deletion. I mean I had a pipeline for deleting objects, its just that there was nothing hooked up to the keyboard for deleting a selected object. So that didn't take too long to hookup just some keyboard command setup.

Friday, this was the big day for finally separating game from editor. I created a base game state which would be popped on to a thing I call the GameStateController, it's essentially a stack of game states which allows me to push and pop game states, originally conceived for things like pausing the game and being in the front end, but also works quite well for game logic. So from the base game state you can currently select 1, editor, or 2 game. Nothing fancy yet, need to get some menus or something instead of a blank screen that responds to key presses. This got me realizing that a ton of the code for loading levels and frustum culling and all that good stuff has been set up in the editor game state so I spent the rest of the day pulling things out of there and putting them into their own independent common systems so that they could be shared between the two state.

Sunday, February 5, 2012

Collectibles and Menus

Hey Readers,

Another week of programming on the bus gone by. I haven't really figured out how I'm going to format this blog but I think for now I'll just kind of run through the things I did each day. The first thing I tackled was an easy one, just resetting the player's velocity when teleporting them back to the beginning of the level. Before putting that in if the player was moving too fast like if he'd fallen off the edge and I needed to reset him back to the beginning he'd be going so fast he'd fly right through the floor.

The next thing to tackle were my menubars, and let me tell you I had a hell of a time with getting those menubars working again. The menubars were one of the first pieces of my UI that I got working and the code had evolved quite a bit over the course of getting everything working. Needless to say there was some weirdness with how the coordinates were set up and I just could not wrap my head around what I needed to offset to get the mouse coordinates into the right space. The right thing to do would have been to just rewrite them to better match how things were currently working in the more updated UI elements but instead I just hammered on it for 2 days until it started working haha. Definitely sucks losing 2 mornings and 2 evenings to a menu. It's nice having them working now though, I've hooked up all the various windows that I had floating around so I can toggle them visible and invisible. Previously all I could do was click the close button in the corner of the window and it would be gone until the next session.


Shot of the main menu
I also found what I thought was a bug in my debug text rendering. It seemed like the prints constantly flickered, turned out all the prints were in some of my physics code and because I didn't use a fixed time step for my physics sometimes it would skip an update. The side effect of fixing this was that my physics runs way smoother now. Next up were adding some collectibles to the game. I reused some of the components of my trigger volume to set up a coin which disappears when the player moves through it. I still need to figure out how the system will work for adding the collectibles value to the players score. I still need to finish this up by putting in some code for receiving the collected message and rewarding the player appropriately. My current gameplan for the coins is to do something similar to the first Mario Kart where the more coins a player has the higher his top speed is.

Here's a shot of the editor in voxel sprite edit mode.
Here's a shot of the first collectable, a coin.
I also set up some code for better modifying the players control based on three parameters: Top Speed, Acceleration, Spin Handling. This code had to be hooked up to the physics so it could properly limit the different physics properties based on those three values.


There was also a few little tweaks I made. I adjusted the gameplay camera a little bit, moved it up a little bit and removed the horizontal offset I had in place. I also tweaked the color on the tweakable menu so I could see it a little better. I also added a tool to the main menu for duplicating the level 4 times to generate the 4 lanes that the player will race in. I also found a major bonehead error in my bulk frustum check that was resulting in some serious performance issues. I was doing a frustum test on all of the objects in my scene, however the function that performs the frustum check takes an array of aabb's and I was stupidly calling that function once for every object, which squared the number of frustum checks I was doing!!!! So dumb, it doubled my performance getting rid of that stupid loop. Oh yeah I also put in my first pass at the character for the game! He still needs a name though, and trying to figure out the final style for him, whether I extrude certain blocks or make him totally 3d voxelated.
Shot of the tweakable menu
Shot from the current game camera