Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_config/loadConfig fix #565

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ src/vizdoom/zlib/CTestTestfile.cmake
**/freedm.wad
**_vizdoom.ini

# CLion & PyCharm
**/.idea

# MacOS
.DS_Store

# Visual Studio Code
.vscode

# CLion & PyCharm
**/.idea
2 changes: 2 additions & 0 deletions docs/api/cpp/doomGame.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ Overwriting does not involve resetting to default values. Thus only overlapping
The method returns true if the whole configuration file was correctly read and applied,
false if the file contained errors.

If the file relative path is given, it will be searched for in the following order: current directory, current directory + `/scenarios/`, ViZDoom's installation directory + `/scenarios/`.

See also:
- [ConfigFile](./configurationFiles.md)

Expand Down
9 changes: 4 additions & 5 deletions src/lib/ViZDoomConfigLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,13 @@ namespace vizdoom {
std::string sharedConfigPath = getThisSharedObjectPath() + "/scenarios/" + scenarioName;

// Check if scenario exists in library's scenerios directory
if (fileExists(filePath)) this->filePath = filePath;
else if (fileExists(workingConfigPath)) this->filePath = workingConfigPath;
else if (fileExists(sharedConfigPath)) this->filePath = sharedConfigPath;
if (fileExistsAndCanBeRead(filePath)) this->filePath = filePath;
else if (fileExistsAndCanBeRead(workingConfigPath)) this->filePath = workingConfigPath;
else if (fileExistsAndCanBeRead(sharedConfigPath)) this->filePath = sharedConfigPath;
else throw FileDoesNotExistException(filePath + " | " + workingConfigPath + " | " + sharedConfigPath);

bool success = true;
std::ifstream file(filePath);

std::ifstream file(this->filePath);

std::string line;
int lineNumber = 0;
Expand Down
11 changes: 11 additions & 0 deletions src/lib/ViZDoomPathHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ namespace vizdoom {
//return exist;
}

bool ifstreamGood(std::string filePath) {
std::ifstream file(filePath);
bool isGood = file.good();
file.close();
return isGood;
}

bool fileExistsAndCanBeRead(std::string filePath){
return fileExists(filePath) && ifstreamGood(filePath);
}

std::string relativePath(std::string relativePath, std::string basePath) {
bfs::path outPath(basePath);
outPath.remove_filename();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ViZDoomPathHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace vizdoom {

bool fileExists(std::string filePath);

bool fileExistsAndCanBeRead(std::string filePath);

std::string relativePath(std::string relativePath, std::string basePath = "");

std::string checkFile(std::string filePath, std::string expectedExt = "");
Expand Down
4 changes: 3 additions & 1 deletion src/lib_python/ViZDoomMethodsDocstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ Default value: 0)DOCSTRING";
In case of multiple invocations, older configurations will be overwritten by the recent ones.
Overwriting does not involve resetting to default values. Thus only overlapping parameters will be changed.
The method returns True if the whole configuration file was correctly read and applied,
False if the file contained errors.)DOCSTRING";
False if the file contained errors.

If the file relative path is given, it will be searched for in the following order: current directory, current directory + `/scenarios/`, ViZDoom's installation directory + `/scenarios/`.)DOCSTRING";

const char *getMode = R"DOCSTRING(Returns current mode (`PLAYER`, `SPECTATOR`, `ASYNC_PLAYER`, `ASYNC_SPECTATOR`).)DOCSTRING";

Expand Down
4 changes: 4 additions & 0 deletions src/lib_python/__init__.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ from .vizdoom import *

import os as _os

root_path = __path__[0]
exe_path_windows = _os.path.join(__path__[0], "vizdoom.exe")
exe_path_unix = _os.path.join(__path__[0], "vizdoom")
exe_path = exe_path_windows if _os.path.exists(exe_path_windows) else exe_path_unix
scenarios_path = _os.path.join(__path__[0], "scenarios")
wads = [wad for wad in sorted(_os.listdir(scenarios_path)) if wad.endswith(".wad")]
configs = [cfg for cfg in sorted(_os.listdir(scenarios_path)) if cfg.endswith(".cfg")]
2 changes: 1 addition & 1 deletion src/vizdoom/src/d_iwad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad,
if (pickwad < 0)
exit (0);

// zdoom.pk3 must always be the first file loaded and the IWAD second.
// vizdoom.pk3 must always be the first file loaded and the IWAD second.
wadfiles.Clear();
D_AddFile (wadfiles, zdoom_wad);

Expand Down
19 changes: 19 additions & 0 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

# Tests for ViZDoom enums and related methods.
# This test can be run as Python script or via PyTest

import os

import vizdoom as vzd


def test_load_config():
for file in os.listdir(vzd.scenarios_path):
if file.endswith(".cfg"):
vzd.DoomGame().load_config(os.path.join(vzd.scenarios_path, file))
vzd.DoomGame().load_config(file)


if __name__ == "__main__":
test_load_config()
Loading