12.07.2015 Views

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A.2 Simulation: <strong>Game</strong> Connec<strong>to</strong>r CodeListing A.2: simula<strong>to</strong>r.sml(* fake transport_open and transport_close for C++ bindings *)fun nothing () = ()val () = _export "transport_open" : (unit -> unit) -> unit; nothingval () = _export "transport_close" : (unit -> unit) -> unit; nothing(* call C++ node start code *)fun start (peer : string , gateway : string option) =letval startNode = _import "startNode" : string * string -> unit;val () = Log.log(Log.INFO , "starting node " ^ peer)instartNode (peer , Option.getOpt (gateway , ""))end(* create nodes *)val () = GlobalLog.print ("Creating nodes.\n")fun makeNode partner node =Simula<strong>to</strong>rNode.setCurrent (node , fn () => start (partner , NONE))val bootstrapNode = Vec<strong>to</strong>r.sub (nodes , 0)val bootstrapAddr = Word32.<strong>to</strong>String (valOf(MasterConnectionProperties.staticAddress(Simula<strong>to</strong>rNode.connection bootstrapNode )))val () = GlobalLog.print ("Preparing nodes.\n")val () = Vec<strong>to</strong>r.app (fn x => ignore (Simula<strong>to</strong>r.RawEvent.schedule(Time.zero , fn _ => makeNode bootstrapAddr x))) nodes(* s<strong>to</strong>p event *)fun s<strong>to</strong>pSim _ =( GlobalLog.print "S<strong>to</strong>pping Simula<strong>to</strong>r.\n"; OS.Process.exit OS.Process.success)val _ = Simula<strong>to</strong>r.RawEvent.schedule (Time.fromSeconds 300, s<strong>to</strong>pSim)(* run *)val () = GlobalLog.print "Running simula<strong>to</strong>r.\n"val () = Simula<strong>to</strong>r.run ()A Source Code Extracts 89

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!