Skip to content

Commit

Permalink
Fixes to car_racing.py (rendering in mode=human and main method) (ope…
Browse files Browse the repository at this point in the history
…nai#1339)

* record_video=False by default

* remove print(isopen)

* change isopen flag handling to a more compatible way
  • Loading branch information
pzhokhov authored Feb 27, 2019
1 parent 53e4b2c commit 09e09f7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions gym/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,15 @@ def render(self, mode='human'):
self.human_render = True
win.clear()
t = self.transform
gl.glViewport(0, 0, WINDOW_W, WINDOW_H)
gl.glViewport(0, 0, 2 * WINDOW_W, 2 * WINDOW_H)
t.enable()
self.render_road()
for geom in self.viewer.onetime_geoms:
geom.render()
t.disable()
self.render_indicators(WINDOW_W, WINDOW_H)
win.flip()
return self.viewer.isopen

self.viewer.onetime_geoms = []
return arr
Expand Down Expand Up @@ -472,12 +473,14 @@ def key_release(k, mod):
if k==key.DOWN: a[2] = 0
env = CarRacing()
env.render()
record_video = False
if record_video:
env.monitor.start('/tmp/video-test', force=True)
env.viewer.window.on_key_press = key_press
env.viewer.window.on_key_release = key_release
while True:
record_video = False
if record_video:
from gym.wrappers.monitor import Monitor
env = Monitor(env, '/tmp/video-test', force=True)
isopen = True
while isopen:
env.reset()
total_reward = 0.0
steps = 0
Expand All @@ -492,7 +495,6 @@ def key_release(k, mod):
#plt.imshow(s)
#plt.savefig("test.jpeg")
steps += 1
if not record_video: # Faster, but you can as well call env.render() every time to play full window.
env.render()
if done or restart: break
isopen = env.render()
if done or restart or isopen == False: break
env.close()

0 comments on commit 09e09f7

Please sign in to comment.