Thursday, March 28, 2013

[Morgan] Persistent client-server

The client and server now automatically reconnect when disconnected.  I can turn off my iPod and then turn it back on later and they correctly sync.  Here's a screenshot of the server...the Cornell Box is one of the default G3D scenes just to give the renderer something to do,
and doesn't have anything to do with the game.  The interesting parts are the list of clients shown at the upper left and the dynamically-generated QR code on the right.

I use G3D::GUniqueID to assign a unique identifier to every resource in the system, which right now means cards and clients. This allows the server and client to refer to objects without having to deal with synchronizing namespaces.

I introduced a Graphic class that holds both a Texture (i.e., of a card) and the bytes of the message to send to a client to tell it about that Graphic. The server can use this to quickly send images to the clients.  The clients maintain an explicit image cache to avoid allowing the browser to manage it (since browser caches can be very small on mobile), but this has a serious disadvantage because Javascript doesn't have weak pointer class.  Every card is stored as a separate HTML5 image object, so there could be a lot of these in memory at once.

I also refactored the code because the number of global variables that I was accumulating in C++ was horrifying (a side effect of using a C-based webserver).  The full code base is about 500 SLOC, measured by counting semi-colons in the project.

TODO:

  1. Have the server send the client a list of the cards it has
  2. Have the server display the contents of the current encounter as cards
  3. Put "use" button on the active card
  4. Make an action on the client have some effect on the server

No comments:

Post a Comment