From aa6b68d328acef8b89a80ab222b40b0c9cf471ee Mon Sep 17 00:00:00 2001 From: Marqt Date: Tue, 15 Nov 2016 01:10:45 +0100 Subject: [PATCH] Corrected setRenderCorpses link in docs, removed sleep method from lua Former-commit-id: f560baf41065ec4373de594416c107780ecc651a --- doc/DoomGame.md | 12 +-- doc/Utilities.md | 10 -- examples/python/test_basic.py | 155 ------------------------------- examples/python/test_buffers.py | 109 ---------------------- src/lib_lua/ViZDoomLuaModule.cpp | 13 +-- 5 files changed, 10 insertions(+), 289 deletions(-) delete mode 100755 examples/python/test_basic.py delete mode 100755 examples/python/test_buffers.py diff --git a/doc/DoomGame.md b/doc/DoomGame.md index b0b9e7248..336409a63 100644 --- a/doc/DoomGame.md +++ b/doc/DoomGame.md @@ -1236,13 +1236,13 @@ Config key: `renderMessages/render_messages` --- -### `setRenderCorpses` +### `setRenderCorpses` -| C++ | `void setRenderCorpsess(bool corpses)` | -| :-- | :-- | -| Lua | `void setRenderCorpses(boolean corpses)` | -| Java | `void setRenderCorpsess(boolean corpses)` | -| Python | `void set_render_corpsess(bool corpses)` | +| C++ | `void setRenderCorpses(bool corpses)` | +| :-- | :-- | +| Lua | `void setRenderCorpses(boolean corpses)` | +| Java | `void setRenderCorpses(boolean corpses)` | +| Python | `void set_render_corpsess(bool corpses)` | Added in 1.1 diff --git a/doc/Utilities.md b/doc/Utilities.md index 478bbf50a..0aa64219c 100644 --- a/doc/Utilities.md +++ b/doc/Utilities.md @@ -9,7 +9,6 @@ In Java utilities functions are static methods in DoomGame class. * [doomFixedToDouble](#doomFixedToDouble) * [isBinaryButton](#isBinaryButton) * [isDeltaButton](#isDeltaButton) -* [sleep](#sleep) --- @@ -112,12 +111,3 @@ Returns true if button is binary button. Returns true if button is delta button. - ---- -### `sleep` - -| Lua | `void sleep(number sleepTime)` | -| :-- | :-- | - -Pause thread for specified number of milliseconds (without busy waiting). -Added because of the absence in stock Lua. diff --git a/examples/python/test_basic.py b/examples/python/test_basic.py deleted file mode 100755 index c4712dcad..000000000 --- a/examples/python/test_basic.py +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env python - -##################################################################### -# This script presents how to use the most basic features of the environment. -# It configures the engine, and makes the agent perform random actions. -# It also gets current state and reward earned with the action. -# number of episodes are played. -# Random combination of buttons is chosen for every action. -# Game variables from state and last reward are printed. -# -# To see the scenario description go to "../../scenarios/README.md" -##################################################################### - -from __future__ import print_function - -from vizdoom import * - -from random import choice -from time import sleep - -# Create DoomGame instance. It will run the game and communicate with you. -game = DoomGame() - -# Now it's time for configuration! -# load_config could be used to load configuration instead of doing it here with code. -# If load_config is used in-code configuration will work. Note that the most recent changes will add to previous ones. -# game.load_config("../../examples/config/basic.cfg") - -# Sets path to ViZDoom engine executive which will be spawned as a separate process. Default is "./vizdoom". -game.set_vizdoom_path("../../bin/vizdoom") - -# Sets path to iwad resource file which contains the actual doom game. Default is "./doom2.wad". -game.set_doom_game_path("../../scenarios/freedoom2.wad") -# game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences. - -# Sets path to additional resources wad file which is basically your scenario wad. -# If not specified default maps will be used and it's pretty much useless... unless you want to play good old Doom. -game.set_doom_scenario_path("../../scenarios/basic.wad") - -# Sets map to start (scenario .wad files can contain many maps). -game.set_doom_map("map01") - -# Sets resolution. Default is 320X240 -game.set_screen_resolution(ScreenResolution.RES_640X480) - -# Sets the screen buffer format. Not used here but now you can change it. Defalut is CRCGCB. -game.set_screen_format(ScreenFormat.RGB24) - -# Enables depth buffer. -game.set_depth_buffer_enabled(True) - -# Enables labeling of in game objects labeling. -game.set_labels_buffer_enabled(True) - -# Enables buffer with top down map of the current episode/level. -game.set_automap_buffer_enabled(True) - -# Sets other rendering options -game.set_render_hud(False) -game.set_render_minimal_hud(False) # If hud is enabled -game.set_render_crosshair(False) -game.set_render_weapon(True) -game.set_render_decals(False) -game.set_render_particles(False) -game.set_render_effects_sprites(False) - -# Adds buttons that will be allowed. -game.add_available_button(Button.MOVE_LEFT) -game.add_available_button(Button.MOVE_RIGHT) -game.add_available_button(Button.ATTACK) - -# Adds game variables that will be included in state. -game.add_available_game_variable(GameVariable.AMMO2) - -# Causes episodes to finish after 200 tics (actions) -game.set_episode_timeout(10) - -# Makes the window appear (turned on by default) -game.set_window_visible(True) - -# Turns on the sound. (turned off by default) -game.set_sound_enabled(True) - -# Sets the livin reward (for each move) to -1 -game.set_living_reward(-1) - -# Sets ViZDoom mode (PLAYER, ASYNC_PLAYER, SPECTATOR, ASYNC_SPECTATOR, PLAYER mode is default) -game.set_mode(Mode.PLAYER) - -# Initialize the game. Further configuration won't take any effect from now on. -#game.set_console_enabled(True) - - -# Define some actions. Each list entry corresponds to declared buttons: -# MOVE_LEFT, MOVE_RIGHT, ATTACK -# 5 more combinations are naturally possible but only 3 are included for transparency when watching. -actions = [[True, False, False], [False, True, False], [False, False, True]] - -# Run this many episodes -episodes = 1 - -# Sets time that will pause the engine after each action (in seconds) -# Without this everything would go too fast for you to keep track of what's happening. -sleep_time = 1 / DEFAULT_TICRATE # = 0.028 - -for i in range(episodes): - print("Episode #" + str(i + 1)) - game.init() - # Starts a new episode. It is not needed right after init() but it doesn't cost much. At least the loop is nicer. - game.new_episode() - - while not game.is_episode_finished(): - - # Gets the state - state = game.get_state() - - # Which consists of: - n = state.number - vars = state.game_variables - screen_buf = state.screen_buffer - depth_buf = state.depth_buffer - labels_buf = state.labels_buffer - automap_buf = state.automap_buffer - labels = state.labels - - # Makes a random action and get remember reward. - r = game.make_action(choice(actions)) - - # Makes a "prolonged" action and skip frames: - # skiprate = 4 - # r = game.make_action(choice(actions), skiprate) - - # The same could be achieved with: - # game.set_action(choice(actions)) - # game.advance_action(skiprate) - # r = game.get_last_reward() - - # Prints state's game variables and reward. - print("State #" + str(n)) - print("Game variables:", vars) - print("Reward:", r) - print("=====================") - - if sleep_time > 0: - sleep(sleep_time) - - # Check how the episode went. - print("Episode finished.") - print("Total reward:", game.get_total_reward()) - print("************************") - - game.close() - -# It will be done automatically anyway but sometimes you need to do it in the middle of the program... - diff --git a/examples/python/test_buffers.py b/examples/python/test_buffers.py deleted file mode 100755 index a29bf1b9a..000000000 --- a/examples/python/test_buffers.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python - -##################################################################### -# This script presents different buffers and formats. -# OpenCV is used here to display images, install it or remove any -# references to cv2 -# Configuration is loaded from "../../examples/config/basic.cfg" file. -# number of episodes are played. -# Random combination of buttons is chosen for every action. -# -# To see the scenario description go to "../../scenarios/README.md" -##################################################################### - -from __future__ import print_function - -from random import choice -from vizdoom import * - -import cv2 - -game = DoomGame() - -# Use other config file if you wish. -game.load_config("../../examples/config/deadly_corridor.cfg") - -# game.set_console_enabled(True) -# game.set_window_visible(False) - -# Just umcomment desired format for screen buffer (and map buffer). -# The last uncommented will be applied. -# Formats with C (CRCGCB and CBCGCR) were ommited cause they are not cv2 friendly. -# Default format is ScreenFormat.CRCGCB. - -game.set_screen_format(ScreenFormat.RGB24) -# game.set_screen_format(ScreenFormat.ARGB32) -# game.set_screen_format(ScreenFormat.GRAY8) - -# game.set_screen_format(ScreenFormat.BGR24) -# game.set_screen_format(ScreenFormat.RGBA32) -# game.set_screen_format(ScreenFormat.BGRA32) -# game.set_screen_format(ScreenFormat.ABGR32) - -# Raw Doom buffer with palette's values. This one makes no sense in particular -# game.set_screen_format(ScreenFormat.DOOM_256_COLORS) - -# Sets resolution for all buffers. -game.set_screen_resolution(ScreenResolution.RES_640X480) - -# Enables depth buffer. -game.set_depth_buffer_enabled(True) - -# Enables labeling of in game objects labeling. -game.set_labels_buffer_enabled(True) - -# Enables buffer with top down map of he current episode/level . -game.set_automap_buffer_enabled(True) -game.set_automap_mode(AutomapMode.OBJECTS) -game.set_automap_rotate(False) -game.set_automap_render_textures(False) - -game.set_render_hud(True) -game.set_render_minimal_hud(False) - -game.set_mode(Mode.SPECTATOR) -game.init() - -actions = [[True, False, False], [False, True, False], [False, False, True]] - -episodes = 10 -sleep_time = 0.028 - -for i in range(episodes): - print("Episode #" + str(i + 1)) - - # Not needed for the first episode but the loop is nicer. - game.new_episode() - while not game.is_episode_finished(): - # Gets the state and possibly to something with it - state = game.get_state() - labels = state.labels - - # Display all the buffers here! - - # Just screen buffer, given in selected format. This buffer is always available. - screen = state.screen_buffer - cv2.imshow('ViZDoom Screen Buffer', screen) - - # Depth buffer, always in 8-bit gray channel format. - # This is most fun. It looks best if you inverse colors. - depth = state.depth_buffer - if depth is not None: - cv2.imshow('ViZDoom Depth Buffer', depth) - - cv2.waitKey(int(sleep_time*1000)) - - r = game.make_action(choice(actions)) - - state = game.get_state() - screen2 = state.screen_buffer - suma = (screen == screen2).sum() - print(suma, suma == 640*480*3) - - print("State #" + str(state.number)) - print("=====================") - - print("Episode finished!") - print("************************") - -cv2.destroyAllWindows() \ No newline at end of file diff --git a/src/lib_lua/ViZDoomLuaModule.cpp b/src/lib_lua/ViZDoomLuaModule.cpp index 36d632999..d63d221da 100644 --- a/src/lib_lua/ViZDoomLuaModule.cpp +++ b/src/lib_lua/ViZDoomLuaModule.cpp @@ -71,10 +71,6 @@ EXCEPTION_TRANSLATE_TO_LUA(ViZDoomUnexpectedExitException) double (*doomFixedToDouble_int)(int) = &doomFixedToDouble; double (*doomFixedToDouble_double)(double) = &doomFixedToDouble; -void sleepLua(unsigned int time){ - std::this_thread::sleep_for(std::chrono::milliseconds(time)); -} - /* Module definition */ /*--------------------------------------------------------------------------------------------------------------------*/ @@ -462,15 +458,14 @@ extern "C" int luaopen_vizdoom(lua_State *luaState){ /* Utilities */ /*------------------------------------------------------------------------------------------------------------*/ - def("sleep", sleepLua), FUNC_2_LUA(doomTicsToMs), FUNC_2_LUA(msToDoomTics), FUNC_2_LUA(doomTicsToSec), FUNC_2_LUA(secToDoomTics), - def("doomFixedToDouble", doomFixedToDouble_int), - // def("doomFixedToDouble", doomFixedToDouble_double), - def("doomFixedToNumber", doomFixedToDouble_int), - // def("doomFixedToNumber", doomFixedToDouble_double), + //def("doomFixedToDouble", doomFixedToDouble_int), + def("doomFixedToDouble", doomFixedToDouble_double), + //def("doomFixedToNumber", doomFixedToDouble_int), + def("doomFixedToNumber", doomFixedToDouble_double), FUNC_2_LUA(isBinaryButton), FUNC_2_LUA(isDeltaButton)