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.