From 7fbbeed60e31bc6d1171070ce374ed97c2ce1aba Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Sun, 13 Aug 2023 18:51:40 +0200 Subject: [PATCH 1/6] Bump version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6902dcca..055904ec5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.4) # Project + versions #----------------------------------------------------------------------------------------------------------------------- -project(ViZDoom VERSION 1.2.0) +project(ViZDoom VERSION 1.2.1) set(ViZDoom_VERSION_STR ${ViZDoom_VERSION_MAJOR}.${ViZDoom_VERSION_MINOR}.${ViZDoom_VERSION_PATCH}) set(ViZDoom_VERSION_ID ${ViZDoom_VERSION_MAJOR}${ViZDoom_VERSION_MINOR}${ViZDoom_VERSION_PATCH}) From 64e64d134441c923b8cabc5443ae3728e5b5d61e Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Sun, 13 Aug 2023 20:18:37 +0200 Subject: [PATCH 2/6] Add arguments names to pybind11 module --- include/ViZDoomGame.h | 4 +- src/lib/ViZDoomGame.cpp | 14 +-- src/lib_python/ViZDoomGamePython.h | 18 --- src/lib_python/ViZDoomPythonModule.cpp | 151 +++++++++++++------------ 4 files changed, 83 insertions(+), 104 deletions(-) diff --git a/include/ViZDoomGame.h b/include/ViZDoomGame.h index d36f8f419..f1e1d343d 100644 --- a/include/ViZDoomGame.h +++ b/include/ViZDoomGame.h @@ -93,9 +93,9 @@ namespace vizdoom { /*------------------------------------------------------------------------------------------------------------*/ std::vector getAvailableGameVariables(); - void setAvailableGameVariables(std::vector gameVariables); + void setAvailableGameVariables(std::vector variables); - void addAvailableGameVariable(GameVariable var); + void addAvailableGameVariable(GameVariable variable); void clearAvailableGameVariables(); size_t getAvailableGameVariablesSize(); double getGameVariable(GameVariable variable); diff --git a/src/lib/ViZDoomGame.cpp b/src/lib/ViZDoomGame.cpp index 4e5beddec..8ff421e4f 100644 --- a/src/lib/ViZDoomGame.cpp +++ b/src/lib/ViZDoomGame.cpp @@ -398,16 +398,16 @@ namespace vizdoom { return this->availableGameVariables; } - void DoomGame::setAvailableGameVariables(std::vector gameVariables){ + void DoomGame::setAvailableGameVariables(std::vector variables){ this->clearAvailableGameVariables(); - for(auto i : gameVariables) this->addAvailableGameVariable(i); + for(auto i : variables) this->addAvailableGameVariable(i); } - void DoomGame::addAvailableGameVariable(GameVariable var) { + void DoomGame::addAvailableGameVariable(GameVariable variable) { if (!this->isRunning() && - std::find(this->availableGameVariables.begin(), this->availableGameVariables.end(), var) + std::find(this->availableGameVariables.begin(), this->availableGameVariables.end(), variable) == this->availableGameVariables.end()) { - this->availableGameVariables.push_back(var); + this->availableGameVariables.push_back(variable); } } @@ -667,7 +667,3 @@ namespace vizdoom { updateState(); } } - - - - diff --git a/src/lib_python/ViZDoomGamePython.h b/src/lib_python/ViZDoomGamePython.h index 0f1ea0aec..6156c750e 100644 --- a/src/lib_python/ViZDoomGamePython.h +++ b/src/lib_python/ViZDoomGamePython.h @@ -122,24 +122,6 @@ namespace vizdoom { void advanceAction(unsigned int tics = 1, bool updateState = true); void respawnPlayer(); - // Overloaded functions instead of default arguments for pybind11 - - void newEpisode_() { this->newEpisode(); }; - void newEpisode_str(std::string _str) { this->newEpisode(_str); }; - - double makeAction_list(pyb::object const &_list){ return this->makeAction(_list); } - double makeAction_list_int(pyb::object const &_list, unsigned int _int){ return this->makeAction(_list, _int); } - - void advanceAction_() { this->advanceAction(); } - void advanceAction_int(unsigned int _int) { this->advanceAction(_int); } - void advanceAction_int_bool(unsigned int _int, bool _bool) { this->advanceAction(_int, _bool); } - - void addAvailableButton_btn(Button _btn) { this->addAvailableButton(_btn); } - void addAvailableButton_btn_double(Button _btn, double _double) { this->addAvailableButton(_btn, _double); } - - void replayEpisode_str(std::string _str) { this->replayEpisode(_str); } - void replayEpisode_str_int(std::string _str, unsigned int _int) { this->replayEpisode(_str, _int); } - private: GameStatePython* pyState; diff --git a/src/lib_python/ViZDoomPythonModule.cpp b/src/lib_python/ViZDoomPythonModule.cpp index 326135c41..779b4b05d 100644 --- a/src/lib_python/ViZDoomPythonModule.cpp +++ b/src/lib_python/ViZDoomPythonModule.cpp @@ -66,6 +66,7 @@ PYBIND11_MODULE(vizdoom, vz){ /* Helpers */ /*----------------------------------------------------------------------------------------------------------------*/ + // These macros are used to make the code below shorter and less prone to typos #define CONST_2_PYT(c) vz.attr( #c ) = c /* vz.attr("CONST") = CONST */ @@ -79,9 +80,15 @@ PYBIND11_MODULE(vizdoom, vz){ #define FUNC_2_PYT(n, f) vz.def( n , f , docstrings::f ) /* vz.def("name", function, docstrings::function) */ + #define FUNC_2_PYT_WITH_ARGS(n, f, a...) vz.def( n , f , docstrings::f , a) + /* vz.def("name", function, docstrings::function, args) */ + #define CLASS_FUNC_2_PYT(n, cf) .def( n , &cf , docstrings::cf ) /* .def("name", &class::function, docstrings::class::function) */ + #define CLASS_FUNC_2_PYT_WITH_ARGS(n, cf, a...) .def( n , &cf , docstrings::cf, a ) + /* .def("name", &class::function, docstrings::class::function, args) */ + /* Consts */ /*----------------------------------------------------------------------------------------------------------------*/ @@ -613,40 +620,35 @@ PYBIND11_MODULE(vizdoom, vz){ pyb::class_(vz, "DoomGame") .def(pyb::init<>()) CLASS_FUNC_2_PYT("init", DoomGamePython::init) - CLASS_FUNC_2_PYT("load_config", DoomGamePython::loadConfig) + CLASS_FUNC_2_PYT_WITH_ARGS("load_config", DoomGamePython::loadConfig, pyb::arg("config")) CLASS_FUNC_2_PYT("close", DoomGamePython::close) CLASS_FUNC_2_PYT("is_running", DoomGamePython::isRunning) CLASS_FUNC_2_PYT("is_multiplayer_game", DoomGamePython::isMultiplayerGame) CLASS_FUNC_2_PYT("is_recording_episode", DoomGamePython::isRecordingEpisode) CLASS_FUNC_2_PYT("is_replaying_episode", DoomGamePython::isReplayingEpisode) - .def("new_episode", &DoomGamePython::newEpisode_, docstrings::DoomGamePython::newEpisode) - .def("new_episode", &DoomGamePython::newEpisode_str, docstrings::DoomGamePython::newEpisode) - .def("replay_episode", &DoomGamePython::replayEpisode_str, docstrings::DoomGamePython::replayEpisode) - .def("replay_episode", &DoomGamePython::replayEpisode_str_int, docstrings::DoomGamePython::replayEpisode) + CLASS_FUNC_2_PYT_WITH_ARGS("new_episode", DoomGamePython::newEpisode, pyb::arg("recording_file_path") = "") + CLASS_FUNC_2_PYT_WITH_ARGS("replay_episode", DoomGamePython::replayEpisode, pyb::arg("file_path"), pyb::arg("player") = 0) CLASS_FUNC_2_PYT("is_episode_finished", DoomGamePython::isEpisodeFinished) CLASS_FUNC_2_PYT("is_new_episode", DoomGamePython::isNewEpisode) CLASS_FUNC_2_PYT("is_player_dead", DoomGamePython::isPlayerDead) CLASS_FUNC_2_PYT("respawn_player", DoomGamePython::respawnPlayer) - CLASS_FUNC_2_PYT("set_action", DoomGamePython::setAction) - .def("make_action", &DoomGamePython::makeAction_list, docstrings::DoomGamePython::makeAction) - .def("make_action", &DoomGamePython::makeAction_list_int, docstrings::DoomGamePython::makeAction) - .def("advance_action", &DoomGamePython::advanceAction_, docstrings::DoomGamePython::advanceAction) - .def("advance_action", &DoomGamePython::advanceAction_int, docstrings::DoomGamePython::advanceAction) - .def("advance_action", &DoomGamePython::advanceAction_int_bool, docstrings::DoomGamePython::advanceAction) - CLASS_FUNC_2_PYT("save", DoomGamePython::save) - CLASS_FUNC_2_PYT("load", DoomGamePython::load) + CLASS_FUNC_2_PYT_WITH_ARGS("set_action", DoomGamePython::setAction, pyb::arg("action")) + CLASS_FUNC_2_PYT_WITH_ARGS("make_action", DoomGamePython::makeAction, pyb::arg("action"), pyb::arg("tics") = 1) + CLASS_FUNC_2_PYT_WITH_ARGS("advance_action", DoomGamePython::advanceAction, pyb::arg("tics") = 1, pyb::arg("update_state") = true) + CLASS_FUNC_2_PYT_WITH_ARGS("save", DoomGamePython::save, pyb::arg("file_path")) + CLASS_FUNC_2_PYT_WITH_ARGS("load", DoomGamePython::load, pyb::arg("file_path")) .def("get_state", &DoomGamePython::getState, pyb::return_value_policy::take_ownership, docstrings::DoomGamePython::getState) .def("get_server_state", &DoomGamePython::getServerState, pyb::return_value_policy::take_ownership, docstrings::DoomGamePython::getServerState) - CLASS_FUNC_2_PYT("get_game_variable", DoomGamePython::getGameVariable) - CLASS_FUNC_2_PYT("get_button", DoomGamePython::getButton) + CLASS_FUNC_2_PYT_WITH_ARGS("get_game_variable", DoomGamePython::getGameVariable, pyb::arg("variable")) + CLASS_FUNC_2_PYT_WITH_ARGS("get_button", DoomGamePython::getButton, pyb::arg("button")) CLASS_FUNC_2_PYT("get_living_reward", DoomGamePython::getLivingReward) - CLASS_FUNC_2_PYT("set_living_reward", DoomGamePython::setLivingReward) + CLASS_FUNC_2_PYT_WITH_ARGS("set_living_reward", DoomGamePython::setLivingReward, pyb::arg("living_reward")) CLASS_FUNC_2_PYT("get_death_penalty", DoomGamePython::getDeathPenalty) - CLASS_FUNC_2_PYT("set_death_penalty", DoomGamePython::setDeathPenalty) + CLASS_FUNC_2_PYT_WITH_ARGS("set_death_penalty", DoomGamePython::setDeathPenalty, pyb::arg("death_penalty")) CLASS_FUNC_2_PYT("get_last_reward", DoomGamePython::getLastReward) CLASS_FUNC_2_PYT("get_total_reward", DoomGamePython::getTotalReward) @@ -654,86 +656,85 @@ PYBIND11_MODULE(vizdoom, vz){ CLASS_FUNC_2_PYT("get_last_action", DoomGamePython::getLastAction) CLASS_FUNC_2_PYT("get_available_game_variables", DoomGamePython::getAvailableGameVariables) - CLASS_FUNC_2_PYT("set_available_game_variables", DoomGamePython::setAvailableGameVariables) - CLASS_FUNC_2_PYT("add_available_game_variable", DoomGamePython::addAvailableGameVariable) + CLASS_FUNC_2_PYT_WITH_ARGS("set_available_game_variables", DoomGamePython::setAvailableGameVariables, pyb::arg("variables")) + CLASS_FUNC_2_PYT_WITH_ARGS("add_available_game_variable", DoomGamePython::addAvailableGameVariable, pyb::arg("variable")) CLASS_FUNC_2_PYT("clear_available_game_variables", DoomGamePython::clearAvailableGameVariables) CLASS_FUNC_2_PYT("get_available_game_variables_size", DoomGamePython::getAvailableGameVariablesSize) CLASS_FUNC_2_PYT("get_available_buttons", DoomGamePython::getAvailableButtons) - CLASS_FUNC_2_PYT("set_available_buttons", DoomGamePython::setAvailableButtons) - .def("add_available_button", &DoomGamePython::addAvailableButton_btn, docstrings::DoomGamePython::addAvailableButton) - .def("add_available_button", &DoomGamePython::addAvailableButton_btn_double, docstrings::DoomGamePython::addAvailableButton) + CLASS_FUNC_2_PYT_WITH_ARGS("set_available_buttons", DoomGamePython::setAvailableButtons, pyb::arg("buttons")) + CLASS_FUNC_2_PYT_WITH_ARGS("add_available_button", DoomGamePython::addAvailableButton, pyb::arg("button"), pyb::arg("max_value") = -1) CLASS_FUNC_2_PYT("clear_available_buttons", DoomGamePython::clearAvailableButtons) CLASS_FUNC_2_PYT("get_available_buttons_size", DoomGamePython::getAvailableButtonsSize) - CLASS_FUNC_2_PYT("set_button_max_value", DoomGamePython::setButtonMaxValue) - CLASS_FUNC_2_PYT("get_button_max_value", DoomGamePython::getButtonMaxValue) + CLASS_FUNC_2_PYT_WITH_ARGS("set_button_max_value", DoomGamePython::setButtonMaxValue, pyb::arg("button"), pyb::arg("max_value")) + CLASS_FUNC_2_PYT_WITH_ARGS("get_button_max_value", DoomGamePython::getButtonMaxValue, pyb::arg("button")) - CLASS_FUNC_2_PYT("add_game_args", DoomGamePython::addGameArgs) + CLASS_FUNC_2_PYT_WITH_ARGS("add_game_args", DoomGamePython::addGameArgs, pyb::arg("args")) CLASS_FUNC_2_PYT("clear_game_args", DoomGamePython::clearGameArgs) - CLASS_FUNC_2_PYT("send_game_command", DoomGamePython::sendGameCommand) + CLASS_FUNC_2_PYT_WITH_ARGS("send_game_command", DoomGamePython::sendGameCommand, pyb::arg("cmd")) CLASS_FUNC_2_PYT("get_mode", DoomGamePython::getMode) - CLASS_FUNC_2_PYT("set_mode", DoomGamePython::setMode) + CLASS_FUNC_2_PYT_WITH_ARGS("set_mode", DoomGamePython::setMode, pyb::arg("mode")) CLASS_FUNC_2_PYT("get_ticrate", DoomGamePython::getTicrate) - CLASS_FUNC_2_PYT("set_ticrate", DoomGamePython::setTicrate) + CLASS_FUNC_2_PYT_WITH_ARGS("set_ticrate", DoomGamePython::setTicrate, pyb::arg("button")) - CLASS_FUNC_2_PYT("set_vizdoom_path", DoomGamePython::setViZDoomPath) - CLASS_FUNC_2_PYT("set_doom_game_path", DoomGamePython::setDoomGamePath) - CLASS_FUNC_2_PYT("set_doom_scenario_path", DoomGamePython::setDoomScenarioPath) - CLASS_FUNC_2_PYT("set_doom_map", DoomGamePython::setDoomMap) - CLASS_FUNC_2_PYT("set_doom_skill", DoomGamePython::setDoomSkill) - CLASS_FUNC_2_PYT("set_doom_config_path", DoomGamePython::setDoomConfigPath) + CLASS_FUNC_2_PYT_WITH_ARGS("set_vizdoom_path", DoomGamePython::setViZDoomPath, pyb::arg("button")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_doom_game_path", DoomGamePython::setDoomGamePath, pyb::arg("button")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_doom_scenario_path", DoomGamePython::setDoomScenarioPath, pyb::arg("button")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_doom_map", DoomGamePython::setDoomMap, pyb::arg("button")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_doom_skill", DoomGamePython::setDoomSkill, pyb::arg("button")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_doom_config_path", DoomGamePython::setDoomConfigPath, pyb::arg("button")) CLASS_FUNC_2_PYT("get_seed", DoomGamePython::getSeed) - CLASS_FUNC_2_PYT("set_seed", DoomGamePython::setSeed) + CLASS_FUNC_2_PYT_WITH_ARGS("set_seed", DoomGamePython::setSeed, pyb::arg("seed")) CLASS_FUNC_2_PYT("get_episode_start_time", DoomGamePython::getEpisodeStartTime) - CLASS_FUNC_2_PYT("set_episode_start_time", DoomGamePython::setEpisodeStartTime) + CLASS_FUNC_2_PYT_WITH_ARGS("set_episode_start_time", DoomGamePython::setEpisodeStartTime, pyb::arg("start_time")) CLASS_FUNC_2_PYT("get_episode_timeout", DoomGamePython::getEpisodeTimeout) - CLASS_FUNC_2_PYT("set_episode_timeout", DoomGamePython::setEpisodeTimeout) + CLASS_FUNC_2_PYT_WITH_ARGS("set_episode_timeout", DoomGamePython::setEpisodeTimeout, pyb::arg("timeout")) CLASS_FUNC_2_PYT("get_episode_time", DoomGamePython::getEpisodeTime) - CLASS_FUNC_2_PYT("set_console_enabled", DoomGamePython::setConsoleEnabled) - CLASS_FUNC_2_PYT("set_sound_enabled", DoomGamePython::setSoundEnabled) + CLASS_FUNC_2_PYT_WITH_ARGS("set_console_enabled", DoomGamePython::setConsoleEnabled, pyb::arg("console")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_sound_enabled", DoomGamePython::setSoundEnabled, pyb::arg("sound")) CLASS_FUNC_2_PYT("is_audio_buffer_enabled", DoomGamePython::isAudioBufferEnabled) - CLASS_FUNC_2_PYT("set_audio_buffer_enabled", DoomGamePython::setAudioBufferEnabled) + CLASS_FUNC_2_PYT_WITH_ARGS("set_audio_buffer_enabled", DoomGamePython::setAudioBufferEnabled, pyb::arg("audio_buffer")) CLASS_FUNC_2_PYT("get_audio_sampling_rate", DoomGamePython::getAudioSamplingRate) - CLASS_FUNC_2_PYT("set_audio_sampling_rate", DoomGamePython::setAudioSamplingRate) + CLASS_FUNC_2_PYT_WITH_ARGS("set_audio_sampling_rate", DoomGamePython::setAudioSamplingRate, pyb::arg("sampling_rate")) CLASS_FUNC_2_PYT("get_audio_buffer_size", DoomGamePython::getAudioBufferSize) - CLASS_FUNC_2_PYT("set_audio_buffer_size", DoomGamePython::setAudioBufferSize) + CLASS_FUNC_2_PYT_WITH_ARGS("set_audio_buffer_size", DoomGamePython::setAudioBufferSize, pyb::arg("buffer_size")) - CLASS_FUNC_2_PYT("set_screen_resolution", DoomGamePython::setScreenResolution) - CLASS_FUNC_2_PYT("set_screen_format", DoomGamePython::setScreenFormat) + CLASS_FUNC_2_PYT_WITH_ARGS("set_screen_resolution", DoomGamePython::setScreenResolution, pyb::arg("resolution")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_screen_format", DoomGamePython::setScreenFormat, pyb::arg("format")) CLASS_FUNC_2_PYT("is_depth_buffer_enabled", DoomGamePython::isDepthBufferEnabled) - CLASS_FUNC_2_PYT("set_depth_buffer_enabled", DoomGamePython::setDepthBufferEnabled) + CLASS_FUNC_2_PYT_WITH_ARGS("set_depth_buffer_enabled", DoomGamePython::setDepthBufferEnabled, pyb::arg("depth_buffer")) CLASS_FUNC_2_PYT("is_labels_buffer_enabled", DoomGamePython::isLabelsBufferEnabled) - CLASS_FUNC_2_PYT("set_labels_buffer_enabled", DoomGamePython::setLabelsBufferEnabled) + CLASS_FUNC_2_PYT_WITH_ARGS("set_labels_buffer_enabled", DoomGamePython::setLabelsBufferEnabled, pyb::arg("labels_buffer")) CLASS_FUNC_2_PYT("is_automap_buffer_enabled", DoomGamePython::isAutomapBufferEnabled) - CLASS_FUNC_2_PYT("set_automap_buffer_enabled", DoomGamePython::setAutomapBufferEnabled) - CLASS_FUNC_2_PYT("set_automap_mode", DoomGamePython::setAutomapMode) - CLASS_FUNC_2_PYT("set_automap_rotate", DoomGamePython::setAutomapRotate) - CLASS_FUNC_2_PYT("set_automap_render_textures", DoomGamePython::setAutomapRenderTextures) + CLASS_FUNC_2_PYT_WITH_ARGS("set_automap_buffer_enabled", DoomGamePython::setAutomapBufferEnabled, pyb::arg("automap_buffer")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_automap_mode", DoomGamePython::setAutomapMode, pyb::arg("mode")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_automap_rotate", DoomGamePython::setAutomapRotate, pyb::arg("rotate")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_automap_render_textures", DoomGamePython::setAutomapRenderTextures, pyb::arg("textures")) CLASS_FUNC_2_PYT("is_objects_info_enabled", DoomGamePython::isObjectsInfoEnabled) - CLASS_FUNC_2_PYT("set_objects_info_enabled", DoomGamePython::setObjectsInfoEnabled) + CLASS_FUNC_2_PYT_WITH_ARGS("set_objects_info_enabled", DoomGamePython::setObjectsInfoEnabled, pyb::arg("objects_info")) CLASS_FUNC_2_PYT("is_sectors_info_enabled", DoomGamePython::isSectorsInfoEnabled) - CLASS_FUNC_2_PYT("set_sectors_info_enabled", DoomGamePython::setSectorsInfoEnabled) - - CLASS_FUNC_2_PYT("set_render_hud", DoomGamePython::setRenderHud) - CLASS_FUNC_2_PYT("set_render_minimal_hud", DoomGamePython::setRenderMinimalHud) - CLASS_FUNC_2_PYT("set_render_weapon", DoomGamePython::setRenderWeapon) - CLASS_FUNC_2_PYT("set_render_crosshair", DoomGamePython::setRenderCrosshair) - CLASS_FUNC_2_PYT("set_render_decals", DoomGamePython::setRenderDecals) - CLASS_FUNC_2_PYT("set_render_particles", DoomGamePython::setRenderParticles) - CLASS_FUNC_2_PYT("set_render_effects_sprites", DoomGamePython::setRenderEffectsSprites) - CLASS_FUNC_2_PYT("set_render_messages", DoomGamePython::setRenderMessages) - CLASS_FUNC_2_PYT("set_render_corpses", DoomGamePython::setRenderCorpses) - CLASS_FUNC_2_PYT("set_render_screen_flashes", DoomGamePython::setRenderScreenFlashes) - CLASS_FUNC_2_PYT("set_render_all_frames", DoomGamePython::setRenderAllFrames) - CLASS_FUNC_2_PYT("set_window_visible", DoomGamePython::setWindowVisible) + CLASS_FUNC_2_PYT_WITH_ARGS("set_sectors_info_enabled", DoomGamePython::setSectorsInfoEnabled, pyb::arg("sectors_info")) + + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_hud", DoomGamePython::setRenderHud, pyb::arg("hud")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_minimal_hud", DoomGamePython::setRenderMinimalHud, pyb::arg("min_hud")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_weapon", DoomGamePython::setRenderWeapon, pyb::arg("weapon")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_crosshair", DoomGamePython::setRenderCrosshair, pyb::arg("crosshair")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_decals", DoomGamePython::setRenderDecals, pyb::arg("decals")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_particles", DoomGamePython::setRenderParticles, pyb::arg("particles")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_effects_sprites", DoomGamePython::setRenderEffectsSprites, pyb::arg("sprites")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_messages", DoomGamePython::setRenderMessages, pyb::arg("messages")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_corpses", DoomGamePython::setRenderCorpses, pyb::arg("bodies")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_screen_flashes", DoomGamePython::setRenderScreenFlashes, pyb::arg("flashes")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_render_all_frames", DoomGamePython::setRenderAllFrames, pyb::arg("all_frames")) + CLASS_FUNC_2_PYT_WITH_ARGS("set_window_visible", DoomGamePython::setWindowVisible, pyb::arg("visiblity")) CLASS_FUNC_2_PYT("get_screen_width", DoomGamePython::getScreenWidth) CLASS_FUNC_2_PYT("get_screen_height", DoomGamePython::getScreenHeight) CLASS_FUNC_2_PYT("get_screen_channels", DoomGamePython::getScreenChannels) @@ -745,15 +746,15 @@ PYBIND11_MODULE(vizdoom, vz){ /* Utilities */ /*----------------------------------------------------------------------------------------------------------------*/ - FUNC_2_PYT("doom_tics_to_ms", doomTicsToMs); - FUNC_2_PYT("ms_to_doom_tics", msToDoomTics); - FUNC_2_PYT("doom_tics_to_sec", doomTicsToSec); - FUNC_2_PYT("sec_to_doom_tics", secToDoomTics); - vz.def("doom_fixed_to_double", doomFixedToDouble_int, docstrings::doomFixedToDouble); - vz.def("doom_fixed_to_double", doomFixedToDouble_double, docstrings::doomFixedToDouble); - vz.def("doom_fixed_to_float", doomFixedToDouble_int, docstrings::doomFixedToDouble); - vz.def("doom_fixed_to_float", doomFixedToDouble_double, docstrings::doomFixedToDouble); - FUNC_2_PYT("is_binary_button", isBinaryButton); - FUNC_2_PYT("is_delta_button", isDeltaButton); + FUNC_2_PYT_WITH_ARGS("doom_tics_to_ms", doomTicsToMs, pyb::arg("doom_tics"), pyb::arg("fps") = 35); + FUNC_2_PYT_WITH_ARGS("ms_to_doom_tics", msToDoomTics, pyb::arg("doom_tics"), pyb::arg("fps") = 35); + FUNC_2_PYT_WITH_ARGS("doom_tics_to_sec", doomTicsToSec, pyb::arg("doom_tics"), pyb::arg("fps") = 35); + FUNC_2_PYT_WITH_ARGS("sec_to_doom_tics", secToDoomTics, pyb::arg("doom_tics"), pyb::arg("fps") = 35); + vz.def("doom_fixed_to_double", doomFixedToDouble_int); + vz.def("doom_fixed_to_double", doomFixedToDouble_double); + vz.def("doom_fixed_to_float", doomFixedToDouble_int); + vz.def("doom_fixed_to_float", doomFixedToDouble_double); + FUNC_2_PYT_WITH_ARGS("is_binary_button", isBinaryButton, pyb::arg("button")); + FUNC_2_PYT_WITH_ARGS("is_delta_button", isDeltaButton, pyb::arg("button")); } From cee3122f89263233e8604fc171ffd54624123fba Mon Sep 17 00:00:00 2001 From: Marek Wydmuch Date: Mon, 14 Aug 2023 00:07:26 +0200 Subject: [PATCH 3/6] Update the structure of the documentation, add docs for Python GameState-related types, enums, and exceptions --- docs/README.md | 6 + docs/{api_cpp => api}/configurationFiles.md | 3 +- docs/api/cpp.md | 19 ++ docs/{api_cpp => api/cpp}/doomGame.md | 2 +- docs/{api_cpp => api/cpp}/enums.md | 16 +- docs/{api_cpp => api/cpp}/exceptions.md | 5 +- docs/{api_cpp => api/cpp}/gameState.md | 24 +-- docs/{api_cpp => api/cpp}/utils.md | 6 +- docs/api/python.md | 14 ++ docs/{api_python => api/python}/doomGame.md | 9 +- docs/api/python/enums.md | 174 ++++++++++++++++++ docs/api/python/exceptions.md | 46 +++++ docs/api/python/gameState.md | 108 +++++++++++ docs/{api_python => api/python}/gymnasium.md | 0 docs/{api_python => api/python}/utils.md | 3 +- docs/api_python/enums.md | 3 - docs/api_python/gameState.md | 3 - docs/conf.py | 22 ++- docs/environments/creatingCustom.md | 62 ++++++- docs/index.md | 24 +-- .../{wrappers.md => apisAndWrappers.md} | 2 +- 21 files changed, 492 insertions(+), 59 deletions(-) rename docs/{api_cpp => api}/configurationFiles.md (98%) create mode 100644 docs/api/cpp.md rename docs/{api_cpp => api/cpp}/doomGame.md (99%) rename docs/{api_cpp => api/cpp}/enums.md (94%) rename docs/{api_cpp => api/cpp}/exceptions.md (89%) rename docs/{api_cpp => api/cpp}/gameState.md (93%) rename docs/{api_cpp => api/cpp}/utils.md (96%) create mode 100644 docs/api/python.md rename docs/{api_python => api/python}/doomGame.md (97%) create mode 100644 docs/api/python/enums.md create mode 100644 docs/api/python/exceptions.md create mode 100644 docs/api/python/gameState.md rename docs/{api_python => api/python}/gymnasium.md (100%) rename docs/{api_python => api/python}/utils.md (99%) delete mode 100644 docs/api_python/enums.md delete mode 100644 docs/api_python/gameState.md rename docs/introduction/{wrappers.md => apisAndWrappers.md} (98%) diff --git a/docs/README.md b/docs/README.md index 41c50068c..ce07781c0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,3 +3,9 @@ This directory contains the documentation for ViZDOOm. For more information about how to contribute to the documentation go to our [CONTRIBUTING.md](https://github.com/Farama-Foundation/Celshast/blob/main/CONTRIBUTING.md) + +If you edit the C++ documentation (inside `api_cpp`), you need to run to update other files: +``` +python scripts/create_python_docs_from_cpp_docs.py +python scripts/create_python_docstrings_from_cpp_docs.py +``` diff --git a/docs/api_cpp/configurationFiles.md b/docs/api/configurationFiles.md similarity index 98% rename from docs/api_cpp/configurationFiles.md rename to docs/api/configurationFiles.md index debf30139..78a77045a 100644 --- a/docs/api_cpp/configurationFiles.md +++ b/docs/api/configurationFiles.md @@ -1,5 +1,6 @@ # Configuration files +ViZDoom Instead of configuring the ViZDoom in code, you can load it from the configuration file(s). Each file is read sequentially, so multiple entries with the same key will overwrite previous entries. ## Format @@ -19,7 +20,7 @@ A violation of any of these rules will result in ignoring **only** the line with ### Appending values Each list assignment (**KEY = { VALUES }**)clears values specified for this key before (in other configuration files or in the code). That is why the **append operator(*KEY += { VALUES })** is available. This way you can more easily combine multiple configuration files and tinker in code. -### Supported configuration keys: +### Supported configuration keys: * `audioBufferEnabled/audio_buffer_enabled` * `audioBufferSize/audio_buffer_size` * `audioSamplingRate/audio_samping_rate` diff --git a/docs/api/cpp.md b/docs/api/cpp.md new file mode 100644 index 000000000..20586041c --- /dev/null +++ b/docs/api/cpp.md @@ -0,0 +1,19 @@ +# C++ API + +ViZDoom was created the end of 2015, before release of OpenAI Gym, becasue of that it uses some different terms for its API than Gym/Gymmnasium. This page is meant to clarify the terms used in ViZDoom. + +- enviroments and scenarios +- observations and states + + + +```{toctree} +:hidden: +:caption: C++ API + +cpp/doomGame +cpp/gameState +cpp/enums +cpp/exceptions +cpp/utils +``` \ No newline at end of file diff --git a/docs/api_cpp/doomGame.md b/docs/api/cpp/doomGame.md similarity index 99% rename from docs/api_cpp/doomGame.md rename to docs/api/cpp/doomGame.md index 21393e633..96cc0192c 100644 --- a/docs/api_cpp/doomGame.md +++ b/docs/api/cpp/doomGame.md @@ -1,6 +1,6 @@ # DoomGame -DoomGame is the main object of the ViZDoom library, representing a single instance of the Doom game and providing the interface for a single agent/player to interact with the game. The object allows sending actions to the game, getting the game state, etc. +DoomGame is the main object of the ViZDoom library, representing a single instance of the Doom game and providing the interface for a single agent/player to interact with the game. The object allows sending actions to the game, getting the game state, etc. The declarations of this class and its methods can be found in the `include/ViZDoomGame.h` header file. Here we document all the methods of the DoomGame class and their corresponding Python bindings implemented as pybind11 module. diff --git a/docs/api_cpp/enums.md b/docs/api/cpp/enums.md similarity index 94% rename from docs/api_cpp/enums.md rename to docs/api/cpp/enums.md index 8f094a410..725b4180f 100644 --- a/docs/api_cpp/enums.md +++ b/docs/api/cpp/enums.md @@ -1,5 +1,8 @@ # Enums +ViZDoom is using few types of enums as parameters for its functions. Below you can find the description of all of them. +The declarations of all the enums can be found in the `include/ViZDoomTypes.h` header file. + ## `Mode` Enum type that defines all supported modes. @@ -178,11 +181,11 @@ Other from 1 to 60 (global int 1-60) can be accessed as USER1 - USER60 GameVaria See also: - [ZDoom Wiki: ACS](http://zdoom.org/wiki/ACS), -- [`DoomGame: getAvailableGameVariables`](./doomGame.md#getAvailableGameVariables), -- [`DoomGame: setAvailableGameVariables`](./doomGame.md#setAvailableGameVariables), -- [`DoomGame: addAvailableGameVariable`](./doomGame.md#addAvailableGameVariable), -- [`DoomGame: getGameVariable`](./doomGame.md#getGameVariable), -- [`Utilities: doomFixedToDouble`](Utilities.md#doomFixedToDouble), +- [`DoomGame: getAvailableGameVariables`](./doomGame.md#getavailablegamevariables), +- [`DoomGame: setAvailableGameVariables`](./doomGame.md#setavailablegamevariables), +- [`DoomGame: addAvailableGameVariable`](./doomGame.md#addavailablegamevariable), +- [`DoomGame: getGameVariable`](./doomGame.md#getgamevariable), +- [`Utilities: doomFixedToDouble`](utils.md#doomfixedtodouble), - [examples/python/basic.py](https://github.com/Farama-Foundation/ViZDoom/tree/master/examples/python/basic.py), - [examples/python/shaping.py](https://github.com/Farama-Foundation/ViZDoom/tree/master/examples/python/shaping.py). @@ -271,3 +274,6 @@ Added in 1.1.9. - **SR_11025** - **SR_22050** - **SR_44100** + +See also: +- [`DoomGame: setAudioSamplingRate`](./doomGame.md#setaudiosamplingrate), diff --git a/docs/api_cpp/exceptions.md b/docs/api/cpp/exceptions.md similarity index 89% rename from docs/api_cpp/exceptions.md rename to docs/api/cpp/exceptions.md index 9d877416a..31d87cb5a 100644 --- a/docs/api_cpp/exceptions.md +++ b/docs/api/cpp/exceptions.md @@ -1,6 +1,9 @@ # Exceptions ViZDoom defines several exceptions that can be thrown by its API: +Most of the exceptions contain more information in "what()" message. +The declarations of all the enums can be found in the `include/ViZDoomExceptions.h` header file. + * `FileDoesNotExistException` - means that file specified as part of a configuration does not exist. @@ -13,5 +16,3 @@ ViZDoom defines several exceptions that can be thrown by its API: * `ViZDoomIsNotRunningException` - means that called method cannot be used when ViZDoom instance is not running. * `ViZDoomUnexpectedExitException` - means that ViZDoom's instance was closed/terminated/killed from the outside. - -Most of the exceptions contain more information in "what()" message. diff --git a/docs/api_cpp/gameState.md b/docs/api/cpp/gameState.md similarity index 93% rename from docs/api_cpp/gameState.md rename to docs/api/cpp/gameState.md index a584fa99c..22c583d1c 100644 --- a/docs/api_cpp/gameState.md +++ b/docs/api/cpp/gameState.md @@ -1,6 +1,7 @@ # GameState GameState is the main object returned by [`DoomGame: getState`](./doomGame.md#getstate) method. +The declarations of all the enums can be found in the `include/ViZDoomTypes.h` header file. ## `GameState` @@ -57,7 +58,10 @@ See also: - `double / float` **objectVelocityY / object_velocity_y** - `double / float` **objectVelocityZ / object_velocity_z** -**objectId / object_id** - unique object ID, if both Labels and Objects information is enabled, this will be the same as **id** in corresponding**Object**. + +Description of the object in the labels buffer. + +**objectId / object_id** - unique object ID, if both Labels and Objects information is enabled, this will be the same as **id** in corresponding **Object**. **objectName / object_name** - ingame object name, many different objects can have the same name (e.g. Medikit, Clip, Zombie). @@ -87,11 +91,12 @@ See also: - `double / float` **velocityY / velocity_y** - `double / float` **velocityZ / velocity_z** +Description of the object present in the game world. + **id** - unique object ID. **name** - ingame object name, many different objects can have the same name (e.g. Medikit, Clip, Zombie). -Right now `Object` is only available to C++ and Python. Added in 1.1.8. See also: @@ -109,13 +114,14 @@ See also: - `double / float` **y2** - `bool / bool` **isBlocking / is_blocking** +Description of the line that is part of a sector definition. + **x1**, **y1** - position of the line's first vertex. **x2**, **y2** - position of the line's second vertex. **isBlocking / is_blocking** - is true, if line is a wall that can't be passed. -Right now `Line` is only available to C++ and Python. Added in 1.1.8. See also: @@ -130,13 +136,14 @@ See also: - `double / float` **ceilingHeight / ceiling_height** - `std::vector