1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-01-14 19:25:48 +00:00

Merge pull request #76 from Quuxplusone/steam

Make hyper_function work on GCC 4.6 so we don't need USE_STDFUNCTION anymore
This commit is contained in:
Zeno Rogue 2019-04-05 03:18:40 +02:00 committed by GitHub
commit 016aa76f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 43 deletions

View File

@ -3,6 +3,20 @@ services:
- docker - docker
matrix: matrix:
include: include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.6
- g++-4.6
env: >-
TRAVIS_OS_NAME=linux
TRAVIS_BUILD_SYSTEM=Makefile
HYPERROGUE_CXX=g++-4.6
HYPERROGUE_USE_GLEW=1
HYPERROGUE_USE_PNG=1
- os: linux - os: linux
compiler: gcc compiler: gcc
env: >- env: >-
@ -126,7 +140,7 @@ script:
./configure CXXFLAGS="-Wall -Werror" ./configure CXXFLAGS="-Wall -Werror"
make make
elif [[ "$TRAVIS_BUILD_SYSTEM" == "Makefile" ]]; then elif [[ "$TRAVIS_BUILD_SYSTEM" == "Makefile" ]]; then
make -f Makefile.simple make -f Makefile.simple CXX="${HYPERROGUE_CXX-g++}"
elif [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then elif [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then
docker run --rm -v $(pwd):/src trzeci/emscripten make -f Makefile.simple emscripten docker run --rm -v $(pwd):/src trzeci/emscripten make -f Makefile.simple emscripten
else else

View File

@ -32,10 +32,14 @@ else
TOOLCHAIN_VERSION_S := $(shell $(CXX) --version) TOOLCHAIN_VERSION_S := $(shell $(CXX) --version)
ifneq (,$(findstring clang,$(TOOLCHAIN_VERSION_S))) ifneq (,$(findstring clang,$(TOOLCHAIN_VERSION_S)))
TOOLCHAIN := clang TOOLCHAIN := clang
else
ifneq (,$(findstring 4.6.,$(TOOLCHAIN_VERSION_S)))
TOOLCHAIN := gcc46
else else
TOOLCHAIN := gcc TOOLCHAIN := gcc
endif endif
endif endif
endif
## We have now finished inspecting the environment via $(shell). ## We have now finished inspecting the environment via $(shell).
@ -91,6 +95,12 @@ ifeq (${TOOLCHAIN},gcc)
CXXFLAGS_EARLY += -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-unused-parameter CXXFLAGS_EARLY += -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-unused-parameter
endif endif
ifeq (${TOOLCHAIN},gcc46)
CXXFLAGS_EARLY += -std=c++0x
CXXFLAGS_EARLY += -W -Wall -Wextra -Werror
CXXFLAGS_EARLY += -Wno-missing-field-initializers -Wno-unused-parameter
endif
ifeq (${TOOLCHAIN},mingw) ifeq (${TOOLCHAIN},mingw)
CXXFLAGS_EARLY += -std=c++11 -march=native CXXFLAGS_EARLY += -std=c++11 -march=native
CXXFLAGS_EARLY += -W -Wall -Wextra -Werror CXXFLAGS_EARLY += -W -Wall -Wextra -Werror

View File

@ -356,7 +356,7 @@ void virtualRebaseSimple(heptagon*& base, transmatrix& at) {
heptagon *newbase = NULL; heptagon *newbase = NULL;
transmatrix bestV; transmatrix bestV {};
for(int d=0; d<S7; d++) { for(int d=0; d<S7; d++) {
heptspin hs(h, d, false); heptspin hs(h, d, false);
@ -592,4 +592,3 @@ hyperpoint get_warp_corner(cell *c, int cid) {
} }
} }

View File

@ -1,67 +1,54 @@
#pragma once #pragma once
#if USE_STDFUNCTION
#include <functional>
namespace hr {
using std::function;
} // namespace hr
#else
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
namespace hr { namespace hr {
template<class Sig> template<class Sig>
class hyper_function; class function;
template<class Sig>
using function = hyper_function<Sig>;
template<class R, class... Args> template<class R, class... Args>
struct hyper_function_state_base { struct function_state_base {
virtual R call(Args...) const = 0; virtual R call(Args...) const = 0;
virtual hyper_function_state_base *clone() const = 0; virtual function_state_base *clone() const = 0;
virtual ~hyper_function_state_base() = default; virtual ~function_state_base() {}
}; };
template<class T, class R, class... Args> template<class T, class R, class... Args>
struct hyper_function_state : hyper_function_state_base<R, Args...> { struct function_state : function_state_base<R, Args...> {
using Self = hyper_function_state<T, R, Args...>;
T t_; T t_;
explicit hyper_function_state(T t) : t_(std::move(t)) {} explicit function_state(T t) : t_(std::move(t)) {}
R call(Args... args) const override { R call(Args... args) const /*override*/ {
return const_cast<T&>(t_)(static_cast<Args&&>(args)...); return const_cast<T&>(t_)(static_cast<Args&&>(args)...);
} }
hyper_function_state_base<R, Args...> *clone() const override { function_state_base<R, Args...> *clone() const /*override*/ {
return new Self(*this); return new function_state(*this);
} }
}; };
template<class R, class... Args> template<class R, class... Args>
class hyper_function<R(Args...)> class function<R(Args...)>
{ {
hyper_function_state_base<R, Args...> *ptr_ = nullptr; function_state_base<R, Args...> *ptr_;
public: public:
hyper_function() = default; function() : ptr_(nullptr) {}
template<class Callable, class = decltype(R(std::declval<typename std::decay<Callable>::type>()(std::declval<Args>()...)))> template<class Callable, class = decltype(R(std::declval<typename std::decay<Callable>::type>()(std::declval<Args>()...)))>
hyper_function(Callable&& t) : function(Callable&& t) :
ptr_(new hyper_function_state<typename std::decay<Callable>::type, R, Args...>(static_cast<Callable&&>(t))) ptr_(new function_state<typename std::decay<Callable>::type, R, Args...>(static_cast<Callable&&>(t)))
{} {}
~hyper_function() { ~function() {
delete ptr_; delete ptr_;
} }
hyper_function(hyper_function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {} function(function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {}
hyper_function(const hyper_function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {} function(const function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {}
hyper_function(hyper_function&& rhs) noexcept : ptr_(rhs.ptr_) { rhs.ptr_ = nullptr; } function(function&& rhs) noexcept : ptr_(rhs.ptr_) { rhs.ptr_ = nullptr; }
hyper_function(const hyper_function&& rhs) = delete; function(const function&& rhs) = delete;
void operator=(hyper_function rhs) noexcept { void operator=(function rhs) noexcept {
std::swap(ptr_, rhs.ptr_); std::swap(ptr_, rhs.ptr_);
} }
@ -75,5 +62,3 @@ public:
}; };
} // namespace hr } // namespace hr
#endif

View File

@ -72,10 +72,6 @@
#define NOLICENSE ISSTEAM #define NOLICENSE ISSTEAM
#endif #endif
#ifndef USE_STDFUNCTION
#define USE_STDFUNCTION ISSTEAM
#endif
#ifndef CAP_SHADER #ifndef CAP_SHADER
#define CAP_SHADER CAP_GL #define CAP_SHADER CAP_GL
#endif #endif