mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +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:
		
							
								
								
									
										16
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								.travis.yml
									
									
									
									
									
								
							| @@ -3,6 +3,20 @@ services: | ||||
|   - docker | ||||
| matrix: | ||||
|   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 | ||||
|     compiler: gcc | ||||
|     env: >- | ||||
| @@ -126,7 +140,7 @@ script: | ||||
|     ./configure CXXFLAGS="-Wall -Werror" | ||||
|     make | ||||
|   elif [[ "$TRAVIS_BUILD_SYSTEM" == "Makefile" ]]; then | ||||
|     make -f Makefile.simple | ||||
|     make -f Makefile.simple CXX="${HYPERROGUE_CXX-g++}" | ||||
|   elif [[ "$TRAVIS_BUILD_SYSTEM" == "emscripten" ]]; then | ||||
|     docker run --rm -v $(pwd):/src trzeci/emscripten make -f Makefile.simple emscripten | ||||
|   else | ||||
|   | ||||
| @@ -33,7 +33,11 @@ else | ||||
|   ifneq (,$(findstring clang,$(TOOLCHAIN_VERSION_S))) | ||||
|     TOOLCHAIN := clang | ||||
|   else | ||||
|     TOOLCHAIN := gcc | ||||
|     ifneq (,$(findstring 4.6.,$(TOOLCHAIN_VERSION_S))) | ||||
|       TOOLCHAIN := gcc46 | ||||
|     else | ||||
|       TOOLCHAIN := gcc | ||||
|     endif | ||||
|   endif | ||||
| endif | ||||
|  | ||||
| @@ -91,6 +95,12 @@ ifeq (${TOOLCHAIN},gcc) | ||||
|   CXXFLAGS_EARLY += -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-unused-parameter | ||||
| 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) | ||||
|   CXXFLAGS_EARLY += -std=c++11 -march=native | ||||
|   CXXFLAGS_EARLY += -W -Wall -Wextra -Werror | ||||
|   | ||||
| @@ -356,7 +356,7 @@ void virtualRebaseSimple(heptagon*& base, transmatrix& at) { | ||||
|      | ||||
|     heptagon *newbase = NULL; | ||||
|      | ||||
|     transmatrix bestV; | ||||
|     transmatrix bestV {}; | ||||
|      | ||||
|     for(int d=0; d<S7; d++) { | ||||
|       heptspin hs(h, d, false); | ||||
| @@ -592,4 +592,3 @@ hyperpoint get_warp_corner(cell *c, int cid) { | ||||
|   } | ||||
|    | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -1,67 +1,54 @@ | ||||
| #pragma once | ||||
|  | ||||
| #if USE_STDFUNCTION | ||||
|  | ||||
| #include <functional> | ||||
| namespace hr { | ||||
|     using std::function; | ||||
| } // namespace hr | ||||
|  | ||||
| #else | ||||
|  | ||||
| #include <type_traits> | ||||
| #include <utility> | ||||
|  | ||||
| namespace hr { | ||||
|  | ||||
| template<class Sig> | ||||
| class hyper_function; | ||||
|  | ||||
| template<class Sig> | ||||
| using function = hyper_function<Sig>; | ||||
| class function; | ||||
|  | ||||
| template<class R, class... Args> | ||||
| struct hyper_function_state_base { | ||||
| struct function_state_base { | ||||
|     virtual R call(Args...) const = 0; | ||||
|     virtual hyper_function_state_base *clone() const = 0; | ||||
|     virtual ~hyper_function_state_base() = default; | ||||
|     virtual function_state_base *clone() const = 0; | ||||
|     virtual ~function_state_base() {} | ||||
| }; | ||||
|  | ||||
| template<class T, class R, class... Args> | ||||
| struct hyper_function_state : hyper_function_state_base<R, Args...> { | ||||
|     using Self = hyper_function_state<T, R, Args...>; | ||||
| struct function_state : function_state_base<R, Args...> { | ||||
|     T t_; | ||||
|     explicit hyper_function_state(T t) : t_(std::move(t)) {} | ||||
|     R call(Args... args) const override { | ||||
|     explicit function_state(T t) : t_(std::move(t)) {} | ||||
|     R call(Args... args) const /*override*/ { | ||||
|         return const_cast<T&>(t_)(static_cast<Args&&>(args)...); | ||||
|     } | ||||
|     hyper_function_state_base<R, Args...> *clone() const override { | ||||
|         return new Self(*this); | ||||
|     function_state_base<R, Args...> *clone() const /*override*/ { | ||||
|         return new function_state(*this); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| 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: | ||||
|     hyper_function() = default; | ||||
|     function() : ptr_(nullptr) {} | ||||
|  | ||||
|     template<class Callable, class = decltype(R(std::declval<typename std::decay<Callable>::type>()(std::declval<Args>()...)))> | ||||
|     hyper_function(Callable&& t) : | ||||
|         ptr_(new hyper_function_state<typename std::decay<Callable>::type, R, Args...>(static_cast<Callable&&>(t))) | ||||
|     function(Callable&& t) : | ||||
|         ptr_(new function_state<typename std::decay<Callable>::type, R, Args...>(static_cast<Callable&&>(t))) | ||||
|     {} | ||||
|  | ||||
|     ~hyper_function() { | ||||
|     ~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; | ||||
|     function(function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {} | ||||
|     function(const function& rhs) : ptr_(rhs.ptr_ ? rhs.ptr_->clone() : nullptr) {} | ||||
|     function(function&& rhs) noexcept : ptr_(rhs.ptr_) { rhs.ptr_ = nullptr; } | ||||
|     function(const function&& rhs) = delete; | ||||
|  | ||||
|     void operator=(hyper_function rhs) noexcept { | ||||
|     void operator=(function rhs) noexcept { | ||||
|         std::swap(ptr_, rhs.ptr_); | ||||
|     } | ||||
|  | ||||
| @@ -75,5 +62,3 @@ public: | ||||
| }; | ||||
|  | ||||
| } // namespace hr | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -72,10 +72,6 @@ | ||||
| #define NOLICENSE ISSTEAM | ||||
| #endif | ||||
|  | ||||
| #ifndef USE_STDFUNCTION | ||||
| #define USE_STDFUNCTION ISSTEAM | ||||
| #endif | ||||
|  | ||||
| #ifndef CAP_SHADER | ||||
| #define CAP_SHADER CAP_GL | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue