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. 

No comments:

Post a Comment