diff eosd @ 486:2f53be1b2f60

Merge netplay branch.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 27 Sep 2013 19:01:47 +0200
parents 58b47e788c59 1de67f332f00
children 711c75115675
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -46,6 +46,8 @@ parser.add_argument('--no-music', action
 parser.add_argument('--hints', metavar='HINTS', default=None, help='Hints file, to display text while playing.')
 parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.')
 parser.add_argument('--game', metavar='GAME', choices=['EoSD'], default='EoSD', help='Select the game engine to use.')
+parser.add_argument('--port', metavar='PORT', type=int, default=0, help='Port to use for netplay')
+parser.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address')
 
 args = parser.parse_args()
 
@@ -62,6 +64,7 @@ from pytouhou.formats.t6rp import T6RP, 
 from pytouhou.utils.random import Random
 from pytouhou.vm.msgrunner import NextStage
 from pytouhou.formats.hint import Hint
+from pytouhou.network import Network
 
 
 if args.game == 'EoSD':
@@ -98,7 +101,7 @@ class GameBossRush(Game):
 
 def main(window, path, data, stage_num, rank, character, replay, save_filename,
          skip_replay, boss_rush, debug, enable_background, enable_particles,
-         enable_music, hints, verbosity):
+         enable_music, hints, verbosity, port, remote):
 
     resource_loader = Loader(path)
 
@@ -136,6 +139,22 @@ def main(window, path, data, stage_num, 
         save_replay.rank = rank
         save_replay.character = character
 
+    if port != 0:
+        players = [PlayerState(character=0), PlayerState(character=2)]
+
+        if remote:
+            remote_addr, remote_port = remote.split(':')
+            addr = remote_addr, int(remote_port)
+            selected_player = 0
+        else:
+            addr = None
+            selected_player = 1
+
+        prng = Random(0)
+        con = Network(port, addr, selected_player)
+    else:
+        con = None
+
     if hints:
         with open(hints, 'rb') as file:
             hints = Hint.read(file)
@@ -147,7 +166,7 @@ def main(window, path, data, stage_num, 
     game_class = GameBossRush if boss_rush else Game
 
     common = Common(resource_loader)
-    runner = GameRunner(window, resource_loader, skip=skip_replay)
+    runner = GameRunner(window, resource_loader, skip=skip_replay, con=con)
     while True:
         if replay:
             level = replay.levels[stage_num - 1]
@@ -167,7 +186,7 @@ def main(window, path, data, stage_num, 
             states[0].lives = level.lives
             states[0].bombs = level.bombs
             difficulty = level.difficulty
-        else:
+        elif port == 0:
             prng = Random()
 
         if save_filename:
@@ -231,7 +250,7 @@ with SDL():
     main(window, args.path, tuple(args.data), args.stage, args.rank,
          args.character, args.replay, args.save_replay, args.skip_replay,
          args.boss_rush, args.debug, args.no_background, args.no_particles,
-         args.no_music, args.hints, args.verbosity)
+         args.no_music, args.hints, args.verbosity, args.port, args.remote)
 
     import gc
     gc.collect()