annotate eosd @ 478:884ca91b0854

Fix synchro bug
author Thibaut Girka <thib@sitedethib.com>
date Wed, 28 Dec 2011 19:09:14 +0100
parents 44c5e7d4b615
children 1de67f332f00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 #!/usr/bin/env python
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
2 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
3 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
4 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
5 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
6 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
7 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
8 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
9 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
10 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
13 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
14 ##
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
16 import argparse
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17 import os
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
19 import pyximport
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
20 pyximport.install()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
21
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
22 from pytouhou.resource.loader import Loader
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23 from pytouhou.game.background import Background
205
ee6dfd14a785 Rename pytouhou.opengl to pytouhou.ui, makes much more sense that way.
Thibaut Girka <thib@sitedethib.com>
parents: 196
diff changeset
24 from pytouhou.ui.gamerunner import GameRunner
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 188
diff changeset
25 from pytouhou.games.eosd import EoSDGame
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
26 from pytouhou.game.player import PlayerState
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
27 from pytouhou.formats.t6rp import T6RP
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
30 def main(path, stage_num, rank, character, replay, data, port, remote):
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
31 players = [PlayerState(character=character)]
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
32
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
33 if replay:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
34 with open(replay, 'rb') as file:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
35 replay = T6RP.read(file)
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
36 rank = replay.rank
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
37 character = replay.character
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
38 if not replay.levels[stage_num-1]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
39 raise Exception
188
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
40 from pytouhou.utils.random import Random
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
41 prng = Random(replay.levels[stage_num-1].random_seed)
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
42 else:
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
43 prng = None
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
44
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
45 if port != 0:
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
46 from pytouhou.network import Network
476
44c5e7d4b615 Fix consistency
Thibaut Girka <thib@sitedethib.com>
parents: 475
diff changeset
47 from pytouhou.utils.random import Random
44c5e7d4b615 Fix consistency
Thibaut Girka <thib@sitedethib.com>
parents: 475
diff changeset
48
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
49 if remote:
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
50 remote_addr, remote_port = remote.split(':')
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
51 addr = remote_addr, int(remote_port)
476
44c5e7d4b615 Fix consistency
Thibaut Girka <thib@sitedethib.com>
parents: 475
diff changeset
52 players = [PlayerState(character=0), PlayerState(character=2)]
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
53 else:
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
54 addr = None
476
44c5e7d4b615 Fix consistency
Thibaut Girka <thib@sitedethib.com>
parents: 475
diff changeset
55 players = [PlayerState(character=2), PlayerState(character=0)]
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
56
476
44c5e7d4b615 Fix consistency
Thibaut Girka <thib@sitedethib.com>
parents: 475
diff changeset
57 prng = Random(0)
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
58 con = Network(port, addr)
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
59 else:
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
60 con = None
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
61
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
62 resource_loader = Loader()
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
63 resource_loader.scan_archives(os.path.join(path, name)
213
9bdf116bb2a5 Add a distutils setup and don’t hardcode DAT list.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 205
diff changeset
64 for name in data)
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
65 game = EoSDGame(resource_loader, players, stage_num, rank, 16,
188
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
66 prng=prng)
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
67
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
68 # Load stage data
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
69 stage = resource_loader.get_stage('stage%d.std' % stage_num)
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
70
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
71 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 94
diff changeset
72 background = Background(stage, background_anm_wrapper)
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
74 # Main loop
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
75 runner = GameRunner(resource_loader, game, background, replay=replay, con=con)
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
76 runner.start()
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
79 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80
213
9bdf116bb2a5 Add a distutils setup and don’t hardcode DAT list.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 205
diff changeset
81 parser.add_argument('data', metavar='DAT', default=('CM.DAT', 'ST.DAT'), nargs='*', help='Game’s .DAT data files')
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
82 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
83 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
84 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
85 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 186
diff changeset
86 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
87 parser.add_argument('--port', metavar='PORT', type=int, default=0, help='Port to use for netplay')
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
88 parser.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address')
186
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
89
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
90 args = parser.parse_args()
84da28ae7ee4 Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 162
diff changeset
91
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 224
diff changeset
92 main(args.path, args.stage, args.rank, args.character, args.replay, tuple(args.data), args.port, args.remote)