diff --git a/Makefile.simple b/Makefile.simple index 64627d6d1..9fb19fca0 100644 --- a/Makefile.simple +++ b/Makefile.simple @@ -54,7 +54,7 @@ ifeq (${OS},linux) endif ifeq (${OS},mingw) - CXXFLAGS_EARLY += -DWINDOWS -mwindows -D_A_VOLID=8 + CXXFLAGS_EARLY += -DWINDOWS -mwindows -D_A_VOLID=8 -I/msys2/mingw64/include EXE_EXTENSION := .exe LDFLAGS_GL := -lopengl32 LDFLAGS_GLEW := -lglew32 diff --git a/README.md b/README.md index bd4478363..71bc050ab 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ TravisCI badge TravisCI badge TravisCI badge +
+AppVeyor badge

diff --git a/appveyor.bat b/appveyor.bat new file mode 100644 index 000000000..d8ad71e9c --- /dev/null +++ b/appveyor.bat @@ -0,0 +1,97 @@ +cd %APPVEYOR_BUILD_FOLDER% +setlocal + +if "%TRAVIS_OS_NAME%" == "mingw" ( + set "PATH=C:\%MSYS2_DIR%\%MSYSTEM%\bin;C:\%MSYS2_DIR%\usr\bin;%PATH%" +) else if "%TRAVIS_OS_NAME%" == "windows" ( + call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG% +) + +if "%TRAVIS_STAGE%" == "before_build" ( + + REM Install SDL. + if "%TRAVIS_OS_NAME%" == "mingw" ( + pacman --noconfirm --noprogressbar -Syu + pacman --noconfirm --noprogressbar -Sy base-devel + pacman --noconfirm --noprogressbar -Sy mingw-w64-x86_64-SDL mingw-w64-x86_64-SDL_gfx mingw-w64-x86_64-SDL_mixer mingw-w64-x86_64-SDL_ttf + ) else if "%TRAVIS_OS_NAME%" == "windows" ( + cd %TEMP% + powershell Invoke-WebRequest -OutFile SDL.zip -Uri https://www.libsdl.org/release/SDL-devel-1.2.15-VC.zip + unzip SDL.zip + mkdir %APPVEYOR_BUILD_FOLDER%\include\SDL + move SDL-1.2.15\include\*.h %APPVEYOR_BUILD_FOLDER%\include\SDL\ + move SDL-1.2.15\lib\x64\*.* %APPVEYOR_BUILD_FOLDER%\dll\ + + powershell Invoke-WebRequest -OutFile SDL_mixer.zip -Uri https://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-devel-1.2.12-VC.zip + unzip SDL_mixer.zip + mkdir %APPVEYOR_BUILD_FOLDER%\include\SDL + move SDL_mixer-1.2.12\include\*.h %APPVEYOR_BUILD_FOLDER%\include\SDL\ + move SDL_mixer-1.2.12\lib\x64\*.* %APPVEYOR_BUILD_FOLDER%\dll\ + + powershell Invoke-WebRequest -OutFile SDL_ttf.zip -Uri https://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-devel-2.0.11-VC.zip + unzip SDL_ttf.zip + mkdir %APPVEYOR_BUILD_FOLDER%\include\SDL + move SDL_ttf-2.0.11\include\*.h %APPVEYOR_BUILD_FOLDER%\include\SDL\ + move SDL_ttf-2.0.11\lib\x64\*.* %APPVEYOR_BUILD_FOLDER%\dll\ + cd %APPVEYOR_BUILD_FOLDER% + ) else ( + exit 'Unsupported OS' + ) + + REM Install GLEW if asked for + if "%HYPERROGUE_USE_GLEW%" == "1" ( + if "%TRAVIS_OS_NAME%" == "mingw" ( + pacman --noconfirm --noprogressbar -Sy mingw-w64-x86_64-glew + ) else if "%TRAVIS_OS_NAME%" == "windows" ( + cd %TEMP% + powershell Invoke-WebRequest -OutFile GLEW.zip -Uri https://github.com/nigels-com/glew/releases/download/glew-2.1.0/glew-2.1.0-win32.zip + unzip GLEW.zip + mkdir %APPVEYOR_BUILD_FOLDER%\include\GL + move glew-2.1.0\include\GL\* %APPVEYOR_BUILD_FOLDER%\include\GL\ + move glew-2.1.0\lib\Release\x64\* %APPVEYOR_BUILD_FOLDER%\dll\ + move glew-2.1.0\bin\Release\x64\* %APPVEYOR_BUILD_FOLDER%\dll\ + cd %APPVEYOR_BUILD_FOLDER% + ) else ( + exit 'Unsupported OS' + ) + ) + + REM Install autotools if asked for + if "%TRAVIS_BUILD_SYSTEM%" == "autotools" ( + if "%TRAVIS_OS_NAME%" == "mingw" ( + pacman --noconfirm --noprogressbar -Sy automake autoconf + ) else ( + exit 'Unsupported OS' + ) + ) + +) else if "%TRAVIS_STAGE%" == "build_script" ( + + REM Build hyperrogue. + if "%TRAVIS_BUILD_SYSTEM%" == "autotools" ( + bash -c "autoreconf -vi" + bash -c "./configure CXXFLAGS='-Wall -Werror'" + bash -c "make" + ) else if "%TRAVIS_BUILD_SYSTEM%" == "Makefile" ( + make -f Makefile.simple + ) else if "%TRAVIS_BUILD_SYSTEM%" == "msvc" ( + cl -std:c++latest -W2 -WX -EHsc langen.cpp + .\langen.exe > language-data.cpp + cl -std:c++latest -W2 -WX -wd4068 -wd4244 -EHsc -bigobj -I include -D_USE_MATH_DEFINES=1 ^ + -DWINDOWS=1 -DCAP_SDLGFX=0 -DCAP_PNG=0 -DCAP_SAVE=0 -DCAP_ROGUEVIZ=1 hyper.cpp ^ + opengl32.lib dll\glew32.lib dll\SDL.lib dll\SDL_mixer.lib dll\SDL_ttf.lib /Fe: hyperrogue.exe + ) else ( + exit 'Unsupported build system' + ) + +) else if "%TRAVIS_STAGE%" == "test_script" ( + + set "PATH=%APPVEYOR_BUILD_FOLDER%\dll;%PATH%" + .\hyperrogue.exe --help + + REM Test "make dist". ("make distcheck" is expected to fail.) + if "%TRAVIS_BUILD_SYSTEM%" == "autotools" bash -c "make dist" + + REM Test "sudo make install". + if "%TRAVIS_BUILD_SYSTEM%" == "autotools" bash -c "make install" +) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..b61d3affd --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,35 @@ +environment: + matrix: + - TRAVIS_OS_NAME: windows + TRAVIS_COMPILER_NAME: msvc + TRAVIS_BUILD_SYSTEM: msvc + HYPERROGUE_USE_GLEW: 1 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat + MSVC_SETUP_ARG: x64 + - TRAVIS_OS_NAME: mingw + TRAVIS_COMPILER_NAME: gcc + TRAVIS_BUILD_SYSTEM: autotools + HYPERROGUE_USE_GLEW: 1 + MSYS2_ARCH: x86_64 + MSYS2_DIR: msys64 + MSYSTEM: MINGW64 + - TRAVIS_OS_NAME: mingw + TRAVIS_COMPILER_NAME: gcc + TRAVIS_BUILD_SYSTEM: Makefile + HYPERROGUE_USE_GLEW: 1 + MSYS2_ARCH: x86_64 + MSYS2_DIR: msys64 + MSYSTEM: MINGW64 + +before_build: +- set TRAVIS_STAGE=before_build +- call appveyor.bat + +build_script: +- set TRAVIS_STAGE=build_script +- call appveyor.bat + +test_script: +- set TRAVIS_STAGE=test_script +- call appveyor.bat diff --git a/dialogs.cpp b/dialogs.cpp index f838e97a3..ecfde143e 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -473,7 +473,7 @@ namespace dialog { color_t *colorPointer; - bool handleKeyColor(int sym, int uni) { + void handleKeyColor(int sym, int uni) { unsigned& color = *colorPointer; int shift = colorAlpha ? 0 : 8; @@ -514,7 +514,6 @@ namespace dialog { else if(doexiton(sym, uni)) { popScreen(); } - return false; } bool colorAlpha; diff --git a/graph.cpp b/graph.cpp index 08c37c540..32d1ef2bf 100644 --- a/graph.cpp +++ b/graph.cpp @@ -1840,9 +1840,9 @@ int taildist(cell *c) { } int last_wormsegment = -1; -vector > > wormsegments; +vector > > wormsegments; -void add_segment(int d, const std::function& s) { +void add_segment(int d, const function& s) { if(isize(wormsegments) <= d) wormsegments.resize(d+1); last_wormsegment = max(last_wormsegment, d); wormsegments[d].push_back(s); @@ -5727,7 +5727,7 @@ void drawscreen() { mouseovers = " "; cmode = 0; - keyhandler = [] (int sym, int uni) { return false; }; + keyhandler = [] (int sym, int uni) {}; #if CAP_SDL joyhandler = [] (SDL_Event& ev) { return false; }; #endif diff --git a/hyper.h b/hyper.h index 9828ff867..8bfeb2587 100644 --- a/hyper.h +++ b/hyper.h @@ -7,6 +7,7 @@ #define VERNUM_HEX 0xA504 #include +#include "hyper_function.h" namespace hr { @@ -15,6 +16,8 @@ void ignore(T&&) { // placate GCC's overzealous -Wunused-result } +template using function = hyper_function; + // functions and types used from the standard library using std::vector; using std::map; @@ -24,7 +27,6 @@ using std::sort; using std::multimap; using std::set; using std::string; -using std::function; using std::pair; using std::tuple; using std::shared_ptr; @@ -4216,6 +4218,9 @@ void virtualRebaseSimple(heptagon*& base, transmatrix& at); extern bool game_active, playerfound; +extern bool twopoint_do_flips; +extern int twopoint_sphere_flips; + string bygen(reaction_t h); #if CAP_URL diff --git a/hyper_function.h b/hyper_function.h new file mode 100644 index 000000000..a07f8c0b7 --- /dev/null +++ b/hyper_function.h @@ -0,0 +1,69 @@ +#pragma once + +#include + +template +class hyper_function; + +template +struct hyper_function_state_base { + virtual R call(Args...) const = 0; + virtual hyper_function_state_base *clone() const = 0; + virtual ~hyper_function_state_base() = default; +}; + +template +struct hyper_function_state : hyper_function_state_base { + using Self = hyper_function_state; + T t_; + explicit hyper_function_state(T t) : t_(std::move(t)) {} + R call(Args... args) const override { + return const_cast(t_)(static_cast(args)...); + } + hyper_function_state_base *clone() const override { + return new Self(*this); + } +}; + +template +class hyper_function +{ + hyper_function_state_base *ptr_ = nullptr; +public: + hyper_function() = default; + + template::type>()(std::declval()...)))> + hyper_function(Callable&& t) : + ptr_(new hyper_function_state::type, R, Args...>(static_cast(t))) + {} + + ~hyper_function() { + delete ptr_; + } + + hyper_function(hyper_function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {} + hyper_function(const hyper_function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {} + hyper_function(hyper_function&& rhs) noexcept : ptr_(rhs.ptr_) { rhs.ptr_ = nullptr; } + hyper_function(const hyper_function&& rhs) = delete; + + void operator=(const hyper_function& rhs) { + if (&rhs != this) { + delete ptr_; + ptr_ = (rhs.ptr_ ? rhs.ptr_->clone() : nullptr); + } + } + void operator=(hyper_function&& rhs) noexcept { + if (&rhs != this) { + delete ptr_; + ptr_ = rhs.ptr_; rhs.ptr_ = nullptr; + } + } + + R operator()(Args... args) const { + return ptr_->call(static_cast(args)...); + } + + explicit operator bool() const noexcept { + return ptr_ != nullptr; + } +}; diff --git a/polygons.cpp b/polygons.cpp index 753a5f274..06cb2b9f9 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -267,7 +267,7 @@ void addpoint(const hyperpoint& H) { } else { poly_flags |= POLY_NOTINFRONT; - tofix.push_back(make_pair(glcoords.size(), H)); + tofix.emplace_back(isize(glcoords), H); add1(H); return; } @@ -867,8 +867,6 @@ void dqi_poly::draw() { if(sphere && pmodel == mdTwoPoint && !in_twopoint) { #define MAX_PHASE 4 vector phases[MAX_PHASE]; - extern int twopoint_sphere_flips; - extern bool twopoint_do_flips; int pha; if(twopoint_do_flips) { for(int i=0; i