pomdog icon indicating copy to clipboard operation
pomdog copied to clipboard

Redesign Engine and APIs for C++17

Open mogemimi opened this issue 7 years ago • 4 comments

Hello, mates! I have the following plans for Pomdog in 2018:

Plans

  • To migrate C++14 -> C++17, I will remove support for such old compilers and IDEs:
    • Visual Studio < 2017
    • Xcode < 9.2
    • LLVM Clang < 5.0
  • Migrating a new build system from GYP
  • Removing all tools written by Python 2.x from our toolchains
  • Using Catch2 as a test framework
  • Update the version of clang-format and .clang-format
  • Upgrading third-party libraries, docker containers and CI settings.

New API Style

  • Use C++17, not C++14
  • Replacing Pomdog::Optional<T>, Pomdog::Any and Pomdog::PathHelper with the C++17 standard libraries.
  • Do not use Exceptions in favor of the std::tuple, std::tie and std::optional for error handling.
  • More documentations and examples.

Done/TODOs

  • [x] Ubuntu docker container for CI
    • Clang: 3.8 -> 6.0
    • Ubuntu: 17.04 -> 18.04 LTS
  • [x] Wercker CI
    • Clang: 3.8 -> 6.0
    • C++14 -> C++17
  • [x] Travis CI settings
  • [x] Fix some build errors with Clang 5.0 on a new Ubuntu
  • [x] Updating third-party libraries
  • [ ] CMake support
    • [x] Building static libraries and executables using CMake
    • [ ] Building *.framework using CMake
    • [ ] Building shared library using CMake (https://github.com/mogemimi/pomdog/issues/20)
    • [x] Remove GYP artifacts completely (https://github.com/mogemimi/pomdog/pull/22)
  • [x] Rewrite tools from Python 2.7 to Golang (https://github.com/mogemimi/pomdog/pull/23)
  • [x] Use std::optional instead of Optional<T> class
  • [x] Testing between Debug and Release configuration on CI
    • https://github.com/mogemimi/pomdog/commit/a96b2886122770f6c4f741667069e13f43ef0ed7
    • https://github.com/mogemimi/pomdog/commit/6478995ac79e6389ff3dd94f1f5a86a116ab01b5
    • https://github.com/mogemimi/pomdog/commit/6a248e024f5f6372085f2756df328d2dc317143b
  • [x] Vendoring Catch2 header and rewriting test cases
  • [ ] New file system
    • Make resource file path flexible (https://github.com/mogemimi/pomdog/issues/19)
  • [ ] New error handling API without exceptions
    • Add Result<T, E> class
    • Add IOError class
  • [ ] Add test game
    • [x] Add more examples and test cases (https://github.com/mogemimi/pomdog/pull/30)
    • [ ] Remove the obsolete test/TestApp directory
    • [x] Remove examples/TestGame (https://github.com/mogemimi/pomdog/pull/30)
  • [ ] Pixel perfect rendering
    • Redesign Sprite, Scene and Camera
    • Add support for Retina or 4K display on Mac
  • [ ] Updating documentation
    • https://github.com/mogemimi/pomdog/commit/e2cdd68731d73861ba5741ea0f62c52f85eb5ce0
    • https://github.com/mogemimi/pomdog/commit/1053fa5d99e15165fc3a6db0037349913010e135
    • [ ] Inregrating all contents of GitHub wiki to docs directory (https://github.com/mogemimi/pomdog/commit/63479154a23eabff7dfa35147f835ad404d6abac)
    • Add documentation about Application (https://github.com/mogemimi/pomdog/pull/26)
      • https://github.com/mogemimi/pomdog/commit/dfe96c3faaae044681e509f3b97f4be3a6aef4e7
      • https://github.com/mogemimi/pomdog/commit/f32d260c690b8fc326ef17be163c5eec791279c3

mogemimi avatar Jan 25 '18 22:01 mogemimi

I noticed that Pomdog::FileSystem has system-depend implementation, and since there is std::filesystem, this part can also be refactored in favor of c++17 std:

  • Pomdog::FS::CreateDirectory -> std::fs::create_directory
  • Pomdog::FS::CreateDirectories -> std::fs::create_directories
  • Pomdog::FS::Exist -> std::fs::exists
  • Pomdog::FS::IsDirectory -> std::fs::is_directory
  • Pomdog::FS::GetTempDirectoryPath -> std::fs::temp_directory_path
  • Pomdog::FS::GetCurrentWorkingDirectory -> std::fs::current_path

(note: FS is reduced form of FileSystem and fs is reduced form of filesystem)

Although, I'm not sure about other methods in there (GetLocalAppDataDirectoryPath, GetAppDataDirectoryPath and GetResourceDirectoryPath). Since I am using Linux, I am not aware of AppData directories in either Mac or Windows, so I can't guess there.

barsoosayque avatar Jul 20 '18 12:07 barsoosayque

Hello @barsoosayque,

this part can also be refactored in favor of c++17 std

I agree with you. These APIs will be replaced with <file_system> and will be deprecated. 👍 Currently, Mac (Xcode 9) does not support <file_system> and <experimental/file_system> yet, so I'll upgrade the build requirements of Pomdog for the C++17 libraries when Xcode 10 stable will be released.

GetResourceDirectoryPath() represents a asset directory which includes the Content directory. When you build the application, the Content directory is copied into it from your source directory. It is usually the same as where the executable file is located.

GetLocalAppDataDirectoryPath() and GetAppDataDirectoryPath() are equal to /home/<Username>/.<application-name>/, like ~/.thunderbird or ~/.minecraft on Linux, but these are not been implemented yet, please see FileSystemLinux.cpp#L70-L80.

In addition, these are platform-specific APIs which is causing confusion, so I'd like to change them as follows:

// current version
std::string GetLocalAppDataDirectoryPath();
std::string GetAppDataDirectoryPath();

// next version (TBD)
std::optional<std::string> Win32::GetLocalAppDataDirectoryPath();
std::optional<std::string> Win32::GetAppDataDirectoryPath();
std::optional<std::string> Mac::GetApplicationSupportDirectoryPath();
std::optional<std::string> Linux::GetHomeDirectoryPath();
std::string GetContentDirectoryPath();
std::string GetPersistentDataDirectoryPath();

mogemimi avatar Jul 22 '18 12:07 mogemimi

... are equal to /home/<Username>/.<application-name>/, like ~/.thunderbird or ~/.minecraft on Linux.

It is now desirable to store game data (or any other program specific data, but not the configs) in $HOME/.local/share/<application-name>/ according to the XDG Specification.

Regarding next filesystem API, I guess it will be more convenient to return std::filesystem::path and then do path.c_str() or path.string().

barsoosayque avatar Jul 22 '18 13:07 barsoosayque

... $HOME/.local/share// according to the XDG Specification.

Thank you for the link. That seems like the right path! I'll read the spec and try it.

it will be more convenient to return std::filesystem::path

I totally agree with this direction. 👍

mogemimi avatar Jul 22 '18 15:07 mogemimi