So collisions wasn't too much a hassle to resolve. My solution is by no means elegant or hyper-efficient and it will have it's bumps in the future to come, but I ran across some weird sections of code.
For collisions, the previous programmer copied the entire list of objects into a separate array of SceneObjects and then used a foreach() to loop through the scene objects and checked against each object.
The copy couldn't have incurred too much overhead, since each SceneObject in the list was a reference to the SceneObject in memory, but the double-checking is a strange way to go about doing your collision checking. The game is small, so that could be a justification for a redundant collision check, but when I started queuing my collisions it would double-trigger collisions and cause really terrible behavior in the game. It was a simple fix,
(a double-for loop
for(int i = 0; i < sceneObjects.Count -1 ; i++)
{
for(int j = i+1; j < sceneObjects.Count; j++)
{
//stuff goes here }
} )
so I guess it must have been a simple oversight, unless there's some tidbit of information I'm missing.
But I'm going to go ahead and say that was just bad collision code practice and leave it at that. Now the game is "data-driven" with the exception of win/lose screens, I believe. All input, creations and collisions are funneled first through the InputQueue, and are processed at the end of every loop.
My unhappy moment of the day was in the collision code I changed the scene objects to be somewhat based off of unique game IDs. Which is fine for the most part, until you have to loop through your entire list to find an object of a specific ID. (Actually, make that twice, to find the first colliding object, and then the second)
This was done because once I start having to send information between hosts/end machines I won't be able to send references, the two games will have to have some common denominators (ID numbers)
But even keeping those ID numbers synced is going to be a fun challenge in of itself.
This Saturday sucks.
No comments:
Post a Comment