Monday, May 30, 2011

The Ships are Coming! The Ships, the Ships!

I'm very happy to report that I made huge progress today and now have both ships moving correctly for the guest and host. Both are displaying correctly on each player's screen. To be honest, I had avoided working on this for several days because I was getting a little overwhelmed with my own thoughts about how to continue. I had been doing really well with getting the lobby set up and networking the initial data for the ships and asteroids but I had not idea where to send over data that was updated every frame. Just thinking about order made my head spin. I spent those days working on my Independent Study and Engine. 

Then today, I decided to get back to this. My husband urged me to tackle what I was afraid of. Initially, I was really confused about how to tie each actual player with their respective ship physically. Putting in matching indices wasn't enough as that only made it so that both the guest and host controlled the same ship. The guest was also getting a read error on the rotation vector for the host's ship when I tried to read the incoming packet. I tinkered with this for about an hour and a half and then went for a walk on the beach to let it absorb and think about it. 

While out, I realized that I had the wrong call order on the ship move update, regardless of indices. Excited, I went to change this as soon as I came home. Then I noticed something else: I had forgotten to write the rotation vector in the event. Of course I was getting errors trying to read it! I was trying to read something that wasn't there. I quickly put this in and things began to look a lot better. With my two changes, I was now able to see the movement of ship 1 as controlled by the host on both machines, but the guest could also control the same ship. After debugging a little, I realized that I needed to only process certain ships movement from the controller based on the playerType (ie host or guest). I wrote respective conditionals for each and sent and read packets on both ends. 

The events for updating the ship movement are created and added to the player's respective data queue in a function that I wrote in the EvolvedScreen class. This function is called after the currentScreen.update() call in SpacewarGame.update(). The game ran fine on both machines with my new code but ship 2 still wasn't moving with input from either player. I was perplexed at first but after looking into the ship's update code again, I saw that I was passing PlayerIndex.Two to the guest's controller for ship2 when in actuality, both player's controllers needed to be tied to PlayerIndex.One. Changing this yielded wonderful results and here we are now. 

Overall, today I got ship updates and timer changes networked which is great. Tomorrow, I will finish off ship data (hyperspace button if we even need to have that implemented-- need to check first, whatever else there is) and get to work on bullets. I do feel that the more I work on this, the more I understand it. That seems like an obvious statement but sometimes with programming, I get so overwhelmed that I get more confused the longer I look at it. I think that my more optimistic attitude is really helping me to go with the flow and see the code more clearly though. Let's continue this state.

Wednesday, May 25, 2011

Networking is Working, but Boy is it Work

This is probably one of the most convoluted assignments I have ever had to do by far yet. I don't know if it's just that my brain functions on a completely different wavelength but I find the logic in this so difficult to trace and tie together. It's funny too, because when I look at the simple Peer to Peer Sample that is in the XNA folder on Perforce, I totally follow the flow and understand what's happening. It's when I get into the monster of a game with all of the state changes and parallel queues that I begin to lose my mind. I think it takes practice and a focus of a special kind to really hone in on the idea of parallelism that becomes so critical when you network. After several days of despair, I think that I am starting to really get in the zone.


After focusing all my energies on my Independent Study for the past week and weekend, I started the week off with a plan to switch gears and devote time to networking. I had spent several solid days programming the Event queue architecture into the game at the beginning of the assignment but had not made any attempts at networking any part of it until this week. Phil kept mentioning how it was best to start the networking portion because there would be a lot of re-working of the queue (data-driven portion) stuff to be compatible with the networking. I took his advice on Monday. 


Starting at 8am that morning and going on all day with intermittent studying, I was wracking my brain and slowly going crazy. I could feel my sanity seeping out of my ears and emanating from my head in waves, sadly shaped in mini-goodbyes. I did not fare much better on Tuesday because despite all of my efforts and long hours at the computer, I still had nothing networked. Instead, I was re-writing and pulling down old revisions of code like a madwoman, unsure of what universe I was in. Nothing made sense. I understood the concepts of networking and I understood the sample code, but somehow, I could not bring it into my game and make it function.


Finally today happened. The entire morning and afternoon was spent in a similar state to the previous two days. I was getting so desperate that I thought of giving up on numerous occasions but what kept me going was the fact that like it or not, this had to be done and it was not going to get any easier. I just had to keep trying and debugging, the job very much resembling the untangling of a very fine chain that has managed to loop itself around into tens of tiny knots. 


I was beginning to see patterns at around 3pm, but I wasn't sure if this was a symptom of mental distress or actual progress at this point. Then, my husband came home from work and I drew him a picture of my architecture, asking him if it made sense. He said that it did, and suggested that I now try sending a piece of data over the network, a flag of hello. This was my biggest goal all along and something that I had failed to make work in the past few days. This was the start of it all, real networking. We ate some delicious Chinese food-- my first non-pee or eat-an-apple break in like forever. It was only 30 min. but it was like taking a tropical vacation in the scope of everything else I've been doing for the past week. That recharged me enough to go back to my code. Slowly, the patterns began to emerge again and I started to see what functionality I needed to add in order to network my hello. About 45 minutes later, a yell broke out from the 13th floor. It was me, screaming my pants off and jumping up and down so hard that the cat almost peed himself because I'd gotten "Helo" sent from the guest to the host. It had begun.


Now, I'd love to leave it at that dramatic line but even better: I've done more work since The Beginning and now have more goodness. Thanks to Phil's help on the forums, I've edited my Event class to have the reader and writer inside of it, whereas before I was at a disconnect when it came to events. I left it at the point where the host checks if a connection has been initiated and then sends the guest Events from it's queue. Currently, the guest doesn't get a chance to read it because it gets smacked in the forehead with a null exception since I haven't gone through all of the code and changed it to be per PlayerType, ie Host or Guest. That is on tomorrow morning's agenda but right now, I am absolutely zosted and there's a fat brown cat that needs squishing waiting for me in the sleep box. 

Monday, May 23, 2011

Lobbies and Finals

Exhausted... I think that is the state that I will be in for the next several months. I spent all day reviewing for the Networking final tomorrow. I know that it is open book but I don't want to take any chances. I went over everything to make sure that I understood it, printed all of the notes and re-read them, drew diagrams for things that I wanted to clarify, and printed my assignments. Once the evening came around, I decided to shift away from my latest obsession with my independent study and continue the networking theme of the day so I pulled up Spacewar. 


In my newly imposed schedule (which consists literally of only working on all of my coding projects, eating in short bursts, sleeping some, and using the bathroom), I didn't have too much time to devote to programming today. However, I removed the Ship Selection and Upgrade screens from the game and began to work on the lobby. I had originally planned on making my game networked with a true Client Server model but I don't know that that will happen now. For one, the assignment PDF for the Lobby says that we need to create a lobby using P2P. This also appears to be the simpler way to do it, especially given that there is relevant sample code. With very little time and very much to do, I am going to work with whatever gives me good functionality faster. 


Tomorrow will begin early and is reserved for creating the Lobby, continuing to work on the networking layer of the game, and taking the final. Then the final will be out of the way and I will have one less thing to worry about;-)

Wednesday, May 18, 2011

Space War Pew Pew

Space War is kind of convoluted. It's not the worst code I've seen by far, and it's got pretty good comments, but there is so much mixed in. At times, I feel like I am spending more time figuring out how the game code works than focusing on the networking aspect. Anywho, enough complaining though. Yesterday, I decided to clean up the code before going any further with my queue and networking. I deleted the retro version of the game, the sun and gravity. Now, I need to delete the upgrades and ship selection screens, as well as smoothing out the edges between the changes I make. Cutting things out wasn't bad, but I realize more and more that I need to rewrite more and more code. This is definitely a big project and I'm very glad that we still have several weeks and I've already been. I'm totally baby stepping it now. I don't have anything huge to declare at this point, but I'm happy to report that everything is on track and going well. 

Wednesday, May 11, 2011

Continuation of Queuing it up

I worked a lot on converting the game to a queued format today. Looking back on last night's code, I noticed that I had been passing some unnecessary data so I ended up cutting that out and cleaning it up. I then added another event for creating the player ships and began to work on an event for when an asteroid collides with a ship. I might have mentioned this before but the most challenging thing in this assignment is not the coding-- instead, it is getting through the convoluted aspects of the design and knowing what and when to abstract. Any who, I don't have much time to blog about what I did now because I am working on my independent study project. Ever since I got to working on this, I have become a little obsessed with the assignment since I have a tendency to really immerse myself in a code project. Now, I need to shift gears and work on other things, especially since I have the luxury and challenge of no hard deadlines. Off to code away the night then!

Monday, May 9, 2011

An Epiphany

There has been a lot of debugging going on today. I am exhausted, both physically and mentally but very excited about my newfound understanding of this project. I thought I got it before, then I really didn't get it, then I realized I really, really didn't get it, panic and frustration set in, followed by lots of debugging and discussing of general concepts-- then came understanding. I have sketches galore littering my desk and a successful shift-over of the asteroids to my Game Queue. I'm excited, happy, and ready to go! Tomorrow morning that is...now it is time to rest a little, even though I know my dreams will be full of floating points and abstract methods. Details to ensue when I have more strength to type and think.

Friday, May 6, 2011

Belated Update on PA3, my Happiest Assignment

I can't believe that I forgot to post about my successful completion of PA3, the networked packets, because it was my most happiness inducing completion yet! I had never networked anything before and to see this work made me squeal! It's funny because it's nowhere near as difficult as a lot of other things I've worked on, and yet it was so new and ominous when I started, and such a relief and feeling of pride when I finished. I even tried it out on two machines to really see it in action! I know that this sounds really cheesy, especially to all of the overqualified networking gurus in this class, but I don't care! That is why I am here, to learn to network-- not show off what I already know.

On to the Big Ships!

Logging on, I realized how log it's been since I've last written in this blog. I have three blogs to keep for my classes so I keep on bouncing back and forth between all of them, but it's easy to forget which one is updated and which isn't. After being out of commission last week due to being sick, I jumped back on the train but really focused my efforts on my Independent Study. I missed the deadline for PA4 Data Driven and kind of left it on the back burner, knowing that I would get to it when I had to progress on my final project. I normally don't miss deadlines, in fact this is the first in a very long time, but with everything crashing down on my head after falling behind a little, I needed to prioritize and pick my battles. Fortunately though, PA4 is now complete. 


To be honest, it was significantly easier than I expected. At first, I was really confused by the instructions in the PDF. The first issue that I had was in terms of doWork(). Initially, I thought that Keenan wanted us to implement a generic type function, like a template, to take in any data type. However, I did not see how I could call the necessary methods for that data if I didn't know what types I could be dealing with. After speaking to a classmate, I realized that we were meant to know the type we were using, the caveat was just that it had to be user defined. This cleared things up and really made things easier. 


As for Interleaved, the confusion arose when I compared the instructions to the function calls made in Tests.cs which didn't quite match up. I really did not understand why and how there were two separate queues that were then congealed into one. After reading forums though, I learned that it was not necessary to implement it exactly that way-- so long as the data was processed in the same way. Perhaps Keenan knows something about C# queues that I don't and has a better reasoning for using them the way he did but the way I implemented it is much easier for me to understand. 


I went back to the way I had done it last year for my Capstone game, creating a single Object queue since all of the objects go back to the Object base type. I then looped through the queue, dequeuing object by object, checking its type, casting it to that type, and calling the necessary methods on it.  


Now, I can start working on the final project. This is going to be a busy weekend with my hours spread out between the final project for this class, my Independent Study, and the animation converter for Engine. Time for another day (or lots of days) of hard work!

Friday, April 8, 2011

Packed and Serialized!

I just completed Assignment 2- Serialization and am very happy. It feels great to finish something so early and not have to worry about it hanging over your head. My goal this quarter is to really stay on top of my work, and this is a step in the right direction.


Overall, this assignment took me just under three hours to complete. At first, I wasn't quite sure about serialization in practice, because I didn't understand if we had to manually create "headers" and block the data off in the buffer, or if that was the larger picture used to describe it. In the first examples, with Dog and Cat, serialization was very straightforward and simple. Even though my tests for those passed, I thought that I was misunderstanding something because it seemed so easy, so I debugged and stepped through it, making sure that everything made sense. Then, I began working on Bird, and this is where things got ugly. A little.


I had to go back and look at the slides to make sure that we were indeed supposed to section off the data. Once I understood that we were allowed to, and in fact supposed to do that, I used placement new to create a temporary pointer to the buffer, and then incremented this pointer as I memcpy'd everything I needed in a step by step way. In Bird, the thing that gave me the most trouble was the char * because I knew how to serialize it, but when it came to deserializing it, I could not get a hold of its length. Then, I remembered the "header" suggestion, and in serializing, placed the strlen of the char * into the buffer at the very beginning. At that point, I could easily pull it out in my deserialize the same way and use it. After I had coded all of this, the test was still failing on the strncmp. I debugged and saw the string in my data field had extra junk on its end, so I went back and memset it to 0x00 in my constructors. This solved the problem and the test passed. I also added print statements to my constructors and destructors to print out the pointers, in order to check that everything was working correctly. 


Finally, in Fish, I realized that I could serialize the apple and orange structs as wholes, rather than going inside of them and individually blocking out all of their data. The serialize worked off the bat, but the deserialize caused a crash. It turned out that I had forgotten to actually initialize my apple and orange, was trying to write to them when they were null. Similarly to the previous situation in Bird, I went back to the constructor and initialized them which solved the problem. 


I like this class because it's teaching me something I've never even broached in other classes. I've done data alignment before but networking is literally a new world for me-- like a programming expansion pack. I'm really excited about learning more and applying to making an actual networked game, but I'm also glad to be done with this assignment. I'd say that having 4 teeth drilled and then completing this assignment makes for a good day's work. Tomorrow: Independent Study and Engine 2.

Sunday, April 3, 2011

Just Gave It a Go

I just finished playing Space War with myself. I tried to control both ships simultaneously, which did not work out very well strategically but demonstrated to me that everything works successfully! The initial controls are strange though. I had to press 'f' to get the control screen to pop up, and a 'g' to start the game. I could not figure out how to select "Retro" or "Modern" on my machine via keyboard, and based on what I played, it looks like it defaults to "Retro". When I start working on this, I'll use XBOX controllers to make my life easier, but beyond that, it looks great!


I finished the programming assignment shortly after writing my post, but as I just mapped the depot into a new workspace for this class, I submitted it tonight. Looks like everything is done, and I am ready to continue with learning about networking games! Sounds like fun, can't wait! In the meantime, I am off to work on my Engine 2 + Independent Study -- converting an FBX to binary and integrating this into my code to read in the model data and use the model. Wish me luck because I sure will need it!

Wednesday, March 30, 2011

My First Multipass Ride

My first post of the new quarter for a new class. There isn't much to write about yet but I'm sure that it won't take long for that to change. Once again, this quarter I have all Keenan classes. While stuck on a problem in my code for Independent Study, I thought that I would get started early here. I still haven't received an invite to the Wiki but in the meantime, I'll do the mini-program for Assignment 1. 


Cheers to a new quarter and best of luck to everyone!