/
main.py
177 lines (139 loc) · 4.91 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
usageText = """
Usage:
%(prog)s [opts]
Options:
-s Run a server
-c Run a client
-t Don't run threaded network
-p [server:][port]
game server and/or port number to contact
-l output.log
optional log filename
If no options are specified, the default is to run a solo client-server."""
import getopt
import os
import sys
from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "notify-level-ITF debug")
#loadPrcFileData("", "extended-exceptions 1")
import universals
from universals import log
from panda3d.core import LPoint3d
def usage(code, msg=''):
print >> sys.stderr, usageText % {'prog': os.path.split(sys.argv[0])[1]}
print >> sys.stderr, msg
sys.exit(code)
try:
opts, args = getopt.getopt(sys.argv[1:], 'sacr:tp:l:h')
except getopt.error, msg:
usage(1, msg)
logFilename = None
threadedNet = False
for opt, arg in opts:
if opt == '-s':
universals.runServer = True
print "Server Flag"
elif opt == '-c':
universals.runClient = True
print "Client Flag"
elif opt == '-t':
threadedNet = True
elif opt == '-p':
if ':' in arg:
universals.ServerHost, arg = arg.split(':', 1)
if arg:
universals.ServerPort = int(arg)
elif opt == '-l':
logFilename = Filename.fromOsSpecific(arg)
elif opt == '-h':
usage(0)
else:
print 'illegal option: ' + opt
sys.exit(1)
if logFilename:
# Set up Panda's notify output to write to the indicated file.
mstream = MultiplexStream()
mstream.addFile(logFilename)
mstream.addStandardOutput()
Notify.ptr().setOstreamPtr(mstream, False)
# Also make Python output go to the same place.
sw = StreamWriter(mstream, False)
sys.stdout = sw
sys.stderr = sw
# Since we're writing to a log file, turn on timestamping.
loadPrcFileData('', 'notify-timestamp 1')
if not universals.runClient:
# Don't open a graphics window on the server. (Open a window only
# if we're running a normal client, not one of the server
# processes.)
loadPrcFileData('', 'window-type none\naudio-library-name null')
#pass
else:
loadPrcFileData('', 'frame-rate-meter-scale 0.035')
loadPrcFileData('', 'frame-rate-meter-side-margin 0.1')
loadPrcFileData('', 'show-frame-rate-meter 1')
loadPrcFileData('', 'window-title ' + "ITF")
loadPrcFileData('', "sync-video 0")
loadPrcFileData('', 'task-timer-verbose 1')
loadPrcFileData('', 'pstats-tasks 1')
loadPrcFileData('', 'want-pstats 1')
# After initial setup we can now start sandbox
log.debug("Loading sandbox")
import sandbox
sandbox.base.setSleep(0.001)
sandbox.base.disableMouse()
import physics
import shipSystem
import shipComponents
import solarSystem
if universals.runClient:
import clientNet
import graphicsComponents
import guiSystem
import renderSystem
log.info("Setting up client network")
clinet = clientNet.NetworkSystem()
clinet.serverAddress = '127.0.0.1'
sandbox.addSystem(clinet)
log.info("Setting up gui system")
sandbox.addSystem(guiSystem.GUISystem())
log.info("Setting up render system")
sandbox.addSystem(renderSystem.RenderSystem(graphicsComponents.RenderComponent))
sandbox.base.render.setShaderAuto()
if universals.runServer:
import serverNet
log.info("Setting up server network")
servnet = serverNet.NetworkSystem()
servnet.port = 1999
sandbox.addSystem(servnet)
log.info("Setting up Solar System Body Simulator")
sandbox.addSystem(solarSystem.SolarSystemSystem(solarSystem.CelestialComponent))
log.info("Setting up dynamic physics")
sandbox.addSystem(physics.PhysicsSystem(shipComponents.BulletPhysicsComponent))
log.info("Setting up ship interface system")
shipSystem = shipSystem.ShipSystem(shipComponents.PlayerComponent)
sandbox.addSystem(shipSystem)
shipSystem.loadShipClasses()
def planetPositionDebug(task):
log.debug("===== Day: " + str(universals.day) + " =====")
for bod in sandbox.getSystem(solarSystem.SolarSystemSystem).bodies:
log.debug(bod.getName() + ": " + str(bod.getPos()))
return task.again
def loginDebug(task):
#sandbox.getSystem(clientNet.NetworkSystem).sendLogin(universals.username, "Hash Password")
sandbox.send('login', [('127.0.0.1', 1999)])
#return task.again
return task.done
def spawnDebug(task):
shipSystem.spawnShip("The Hype", "Hyperion", universals.spawn, True)
spawnPoint = LPoint3d(universals.spawn)
spawnPoint.addX(3)
shipSystem.spawnShip("Boo boo", "Hyperion", spawnPoint)
#sandbox.base.taskMgr.doMethodLater(10, planetPositionDebug, "Position Debug")
if universals.runClient:
sandbox.base.taskMgr.doMethodLater(1, loginDebug, "Login Debug")
if universals.runServer:
sandbox.base.taskMgr.doMethodLater(1, spawnDebug, "Spawn Debug")
log.info("Setup complete.")
sandbox.run()
##TODO: FIX BULLET PHYSICS AND SOLAR SYSTE RENDER TO PROPERLY USE ROOT SOLAR SYSTEM NODE