-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.txt
203 lines (194 loc) · 27.9 KB
/
out.txt
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Setting MiniSoldier art from Soldier.
Setting MegaSoldier art from Soldier.
# game objects: 279
Hit Player with 179.0 health left
Hit Player with 158.0 health left
Wrote profile results to main.py.lprof
Timer unit: 1e-07 s
Total time: 4.29818 s
File: .\main.py
Function: update at line 67
Line # Hits Time Per Hit % Time Line Contents
==============================================================
67 # @profile
68 def update(self, seconds, events):
69 """ update each part of the game's engine
70 """
71 # update debug box
72 114 2046.0 17.9 0.0 if debug_mode:
73 114 327190.0 2870.1 0.8 self.debugger.update()
74
75 # update holder
76 114 21174.0 185.7 0.0 self.holder.update()
77 # update game with keyboard events
78 114 57174.0 501.5 0.1 actions = self.holder.playerClass.update(events)
79
80 # process actions
81 114 5157.0 45.2 0.0 self.process_actions(actions)
82
83 # update physics with time passage
84 114 42538231.0 373142.4 99.0 self.holder.physicsClass.update(seconds, self.holder.gameObjects, self.holder.worldClass, 'staticObjects')
85
86 # update screen
87 114 15901.0 139.5 0.0 self.holder.playerClass.screenClass.update(self.holder.playerClass.gameObject.x, self.holder.playerClass.gameObject.y)
88
89 # add to data stream
90 114 8779.0 77.0 0.0 DATA["player_xy"] = self.holder.playerClass.position
91 114 6195.0 54.3 0.0 DATA["game_time"] = pygame.time.get_ticks() / 1000.0
Total time: 8.56738 s
File: .\main.py
Function: main at line 119
Line # Hits Time Per Hit % Time Line Contents
==============================================================
119 # @profile
120 def main():
121 # init the clock
122 1 2002.0 2002.0 0.0 clock = pygame.time.Clock()
123 1 18.0 18.0 0.0 FPS = 30
124 1 9.0 9.0 0.0 seconds = 0.0
125 1 7.0 7.0 0.0 milli = 0.0
126
127 # init pygame
128
129 # os.environ['SDL_VIDEO_WINDOW_POS'] = '800,50'
130 1 553.0 553.0 0.0 os.environ['SDL_VIDEO_CENTERED'] = '1'
131 1 4480023.0 4480023.0 5.2 pygame.init()
132 #logo=pygame.image.load("logo filename")
133 #pygame.display.set_icon(logo)
134 1 633.0 633.0 0.0 pygame.display.set_caption('Ephiro') #Eponymous Hero -> EpHero -> Ephiro
135 1 4070480.0 4070480.0 4.8 screen=pygame.display.set_mode([int(i) for i in scrsize])
136 1 51.0 51.0 0.0 World.screen = screen
137
138 # instantiate starting classes
139 1 1364455.0 1364455.0 1.6 master = MasterClass(screen)
140
141 # ----------------------------------------------------------------------
142 # main loop:
143 115 4503.0 39.2 0.0 while not Done:
144 114 514634.0 4514.3 0.6 screen.fill((0,0,0)) #black background
145
146 #update game world
147 114 153704.0 1348.3 0.2 seconds = clock.tick(FPS) / 1000.0
148 114 43156718.0 378567.7 50.4 master.update(seconds, pygame.event.get())
149
150 #write screen
151 114 31323709.0 274769.4 36.6 master.writeScreen()
152
153 #display screen
154 114 602319.0 5283.5 0.7 pygame.display.flip()
Total time: 2.81008 s
File: .\physics.py
Function: get_active_game_objects at line 21
Line # Hits Time Per Hit % Time Line Contents
==============================================================
21 # @profile
22 def get_active_game_objects(self, gameObjects):
23 # collect all rects
24 114 14953.0 131.2 0.1 go_list = list(gameObjects.values())
25
26 # calc all pygame rects
27 114 18226505.0 159881.6 64.9 [go.calc_pygame_rect() for go in go_list]
28
29 # use a quadtree
30 114 9587554.0 84101.4 34.1 tree = utils.QuadTree(go_list, depth=6)
31
32 # get rect for the active screen
33 114 114545.0 1004.8 0.4 screen = self.playerClass.screenClass.get_footprint_rect().convert_to_pygame_rect()
34
35 114 147205.0 1291.3 0.5 hits = tree.hit(screen)
36 114 8738.0 76.6 0.0 active_gos = {go.id: go for go in hits}
37 114 1277.0 11.2 0.0 return active_gos
Total time: 4.20055 s
File: .\physics.py
Function: update at line 50
Line # Hits Time Per Hit % Time Line Contents
==============================================================
50 # @profile
51 def update(self, timeElapsed, all_game_objects, worldClass, mapType):
52 """
53 Step 1: everybody moves
54 Step 2: resolve all collisions
55 Step 3: static-object collision prevention
56 """
57 114 2145.0 18.8 0.0 dt = timeElapsed
58
59 114 1565.0 13.7 0.0 vel_dict = {}
60
61 # get only game objects that are on screen
62 114 28146978.0 246903.3 67.0 gameObjects = self.get_active_game_objects(all_game_objects)
63 114 2095.0 18.4 0.0 if not gameObjects:
64 1 7.0 7.0 0.0 return
65
66 # first, update each game-objects location
67 813 12049.0 14.8 0.0 for key in gameObjects:
68 700 9765.0 13.9 0.0 gameObject = gameObjects[key]
69
70
71
72 #gameObject.update(timeElapsed)
73 700 6395270.0 9136.1 15.2 action, cbs = gameObject.AI.get_action()
74 700 41711.0 59.6 0.1 vel_dict[gameObject.id] = np.zeros(2) #action['dv']
75 700 42777.0 61.1 0.1 dx, dy = action['dv']
76
77 # add on pre-existing momentum, deteriorated by friction
78 700 92160.0 131.7 0.2 dv = 5. * gameObject.velocity # simplified this equation: ( gameObject.momentum / gameObject.mass) * gameObject.unit_velocity
79
80 700 20163.0 28.8 0.0 dx += dv[0]
81 700 13575.0 19.4 0.0 dy += dv[1]
82
83 700 14529.0 20.8 0.0 gameObject.dx = dx; gameObject.dy = dy
84
85 700 17127.0 24.5 0.0 gameObject.x += dt * dx
86 700 13641.0 19.5 0.0 gameObject.y += dt * dy
87
88 # call cbs
89 714 12424.0 17.4 0.0 for cb in cbs:
90 14 283.0 20.2 0.0 if cb in gameObject.callbacks:
91 14 62062.0 4433.0 0.1 gameObject.callbacks[cb](go=gameObject)
92
93 # second, resolve all collisions with gameObjects
94 113 1368779.0 12113.1 3.3 vel_residual = self.collision_resolution(vel_dict, timeElapsed, gameObjects)
95
96 # third, add residual delta
97 813 15355.0 18.9 0.0 for key in gameObjects:
98 700 10958.0 15.7 0.0 gameObject = gameObjects[key]
99
100 700 31780.0 45.4 0.1 dx, dy = vel_residual[gameObject.id]
101
102 700 19054.0 27.2 0.0 gameObject.x += dt * dx
103 700 14603.0 20.9 0.0 gameObject.y += dt * dy
104
105 # must be last: check collision against static objects
106 700 1329461.0 1899.2 3.2 indices = gameObject.get_overlap_tiles()
107 10146 504547.0 49.7 1.2 for i, j in indices:
108 9446 3511153.0 371.7 8.4 if worldClass.can_tile_collide(mapType, [i, j]):
109 181 44017.0 243.2 0.1 rect = worldClass.maps[mapType].get_rect(i, j)
110
111 181 3546.0 19.6 0.0 dx = gameObject.dx
112 181 2846.0 15.7 0.0 dy = gameObject.dy
113
114 # pdb.set_trace()
115
116 181 61022.0 337.1 0.1 if gameObject.intersect(rect):
117 # pdb.set_trace()
118 # see which direction is less distance to move
119
120 # got pushed
121 9 729.0 81.0 0.0 xf1 = rect.left - gameObject.width
122 9 331.0 36.8 0.0 xf2 = rect.right
123 9 324.0 36.0 0.0 yf1 = rect.top - gameObject.height
124 9 275.0 30.6 0.0 yf2 = rect.bottom
125 9 747.0 83.0 0.0 dist1 = np.abs(gameObject.x - xf1)
126 9 413.0 45.9 0.0 dist2 = np.abs(gameObject.x - xf2)
127 9 379.0 42.1 0.0 dist3 = np.abs(gameObject.y - yf1)
128 9 444.0 49.3 0.0 dist4 = np.abs(gameObject.y - yf2)
129 9 3421.0 380.1 0.0 argmin = np.argmin([dist1, dist2, dist3, dist4])
130 9 394.0 43.8 0.0 if argmin == 0: gameObject.x = xf1
131 9 203.0 22.6 0.0 if argmin == 1: gameObject.x = xf2
132 9 234.0 26.0 0.0 if argmin == 2: gameObject.y = yf1
133 9 185.0 20.6 0.0 if argmin == 3: gameObject.y = yf2
134
135 # real update
136 700 180007.0 257.2 0.4 gameObject.update(timeElapsed)