comparison 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
comparison
equal deleted inserted replaced
474:ca22df9e70bc 486:2f53be1b2f60
44 parser.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).') 44 parser.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).')
45 parser.add_argument('--no-music', action='store_false', help='Disable background music.') 45 parser.add_argument('--no-music', action='store_false', help='Disable background music.')
46 parser.add_argument('--hints', metavar='HINTS', default=None, help='Hints file, to display text while playing.') 46 parser.add_argument('--hints', metavar='HINTS', default=None, help='Hints file, to display text while playing.')
47 parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.') 47 parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.')
48 parser.add_argument('--game', metavar='GAME', choices=['EoSD'], default='EoSD', help='Select the game engine to use.') 48 parser.add_argument('--game', metavar='GAME', choices=['EoSD'], default='EoSD', help='Select the game engine to use.')
49 parser.add_argument('--port', metavar='PORT', type=int, default=0, help='Port to use for netplay')
50 parser.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address')
49 51
50 args = parser.parse_args() 52 args = parser.parse_args()
51 53
52 54
53 import sys 55 import sys
60 from pytouhou.game.player import PlayerState, GameOver 62 from pytouhou.game.player import PlayerState, GameOver
61 from pytouhou.formats.t6rp import T6RP, Level 63 from pytouhou.formats.t6rp import T6RP, Level
62 from pytouhou.utils.random import Random 64 from pytouhou.utils.random import Random
63 from pytouhou.vm.msgrunner import NextStage 65 from pytouhou.vm.msgrunner import NextStage
64 from pytouhou.formats.hint import Hint 66 from pytouhou.formats.hint import Hint
67 from pytouhou.network import Network
65 68
66 69
67 if args.game == 'EoSD': 70 if args.game == 'EoSD':
68 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game 71 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game
69 72
96 Game.cleanup(self) 99 Game.cleanup(self)
97 100
98 101
99 def main(window, path, data, stage_num, rank, character, replay, save_filename, 102 def main(window, path, data, stage_num, rank, character, replay, save_filename,
100 skip_replay, boss_rush, debug, enable_background, enable_particles, 103 skip_replay, boss_rush, debug, enable_background, enable_particles,
101 enable_music, hints, verbosity): 104 enable_music, hints, verbosity, port, remote):
102 105
103 resource_loader = Loader(path) 106 resource_loader = Loader(path)
104 107
105 try: 108 try:
106 resource_loader.scan_archives(data) 109 resource_loader.scan_archives(data)
134 if save_filename: 137 if save_filename:
135 save_replay = T6RP() 138 save_replay = T6RP()
136 save_replay.rank = rank 139 save_replay.rank = rank
137 save_replay.character = character 140 save_replay.character = character
138 141
142 if port != 0:
143 players = [PlayerState(character=0), PlayerState(character=2)]
144
145 if remote:
146 remote_addr, remote_port = remote.split(':')
147 addr = remote_addr, int(remote_port)
148 selected_player = 0
149 else:
150 addr = None
151 selected_player = 1
152
153 prng = Random(0)
154 con = Network(port, addr, selected_player)
155 else:
156 con = None
157
139 if hints: 158 if hints:
140 with open(hints, 'rb') as file: 159 with open(hints, 'rb') as file:
141 hints = Hint.read(file) 160 hints = Hint.read(file)
142 161
143 difficulty = 16 162 difficulty = 16
145 states = [PlayerState(character=character, power=default_power, continues=continues)] 164 states = [PlayerState(character=character, power=default_power, continues=continues)]
146 165
147 game_class = GameBossRush if boss_rush else Game 166 game_class = GameBossRush if boss_rush else Game
148 167
149 common = Common(resource_loader) 168 common = Common(resource_loader)
150 runner = GameRunner(window, resource_loader, skip=skip_replay) 169 runner = GameRunner(window, resource_loader, skip=skip_replay, con=con)
151 while True: 170 while True:
152 if replay: 171 if replay:
153 level = replay.levels[stage_num - 1] 172 level = replay.levels[stage_num - 1]
154 if not level: 173 if not level:
155 raise Exception 174 raise Exception
165 states[0].points = level.point_items 184 states[0].points = level.point_items
166 states[0].power = level.power 185 states[0].power = level.power
167 states[0].lives = level.lives 186 states[0].lives = level.lives
168 states[0].bombs = level.bombs 187 states[0].bombs = level.bombs
169 difficulty = level.difficulty 188 difficulty = level.difficulty
170 else: 189 elif port == 0:
171 prng = Random() 190 prng = Random()
172 191
173 if save_filename: 192 if save_filename:
174 if not replay: 193 if not replay:
175 save_replay.levels[stage_num - 1] = level = Level() 194 save_replay.levels[stage_num - 1] = level = Level()
229 fixed_pipeline=args.fixed_pipeline) 248 fixed_pipeline=args.fixed_pipeline)
230 249
231 main(window, args.path, tuple(args.data), args.stage, args.rank, 250 main(window, args.path, tuple(args.data), args.stage, args.rank,
232 args.character, args.replay, args.save_replay, args.skip_replay, 251 args.character, args.replay, args.save_replay, args.skip_replay,
233 args.boss_rush, args.debug, args.no_background, args.no_particles, 252 args.boss_rush, args.debug, args.no_background, args.no_particles,
234 args.no_music, args.hints, args.verbosity) 253 args.no_music, args.hints, args.verbosity, args.port, args.remote)
235 254
236 import gc 255 import gc
237 gc.collect() 256 gc.collect()