tile2d
Loading...
Searching...
No Matches
base.hpp
Go to the documentation of this file.
1#pragma once
2
137#include <vector>
138#include <iterator>
139#include <cassert>
140#include <array>
141#include <set>
142#include <bitset>
143#include <stack>
144
145#define GLM_ENABLE_EXPERIMENTAL
146#include <glm/glm.hpp>
147#include <glm/gtx/rotate_vector.hpp>
148#include <glm/gtc/type_ptr.hpp>
149#include <glm/gtx/norm.hpp>
150#include <glm/gtx/vector_angle.hpp>
151
152#include <boost/unordered/unordered_flat_map.hpp>
153#include <boost/unordered/unordered_flat_set.hpp>
154
155// Multithreading
156#include <boost/pool/object_pool.hpp>
157#include <boost/asio/io_service.hpp>
158#include <boost/bind/bind.hpp>
159#include <boost/thread/thread.hpp>
160#include <boost/thread/locks.hpp>
161
162#define T2D_NAMESPACE_BEGIN namespace t2d {
163#define T2D_NAMESPACE_END }
164
165T2D_NAMESPACE_BEGIN
166
167using Float = float;
168using vec2 = glm::vec<2, Float, glm::packed_lowp>;
169
170namespace debug {
171
172}
173
174namespace impl {
175 template<typename T>
176 T constexpr sqrtNewtonRaphson(T x, T curr, T prev)
177 {
178 return curr == prev
179 ? curr
180 : sqrtNewtonRaphson<T>(x, (T)0.5 * (curr + x / curr), curr);
181 }
182}
183
189template<typename T>
190T constexpr sqrt(T x)
191{
192 return x >= 0 && x < std::numeric_limits<T>::infinity()
193 ? impl::sqrtNewtonRaphson<T>(x, x, 0)
194 : std::numeric_limits<T>::quiet_NaN();
195}
196
197static constexpr Float tileWidth = 10.0f;
198static constexpr Float tileHeight = 10.0f;
199static constexpr vec2 tileSize = vec2(tileWidth, tileHeight);
200static constexpr Float tileRadi = sqrt<Float>(tileWidth * tileWidth + tileHeight * tileHeight) * 0.5f;
201
202static constexpr size_t chunkSideLength = 4;
203static constexpr size_t chunkWidth = chunkSideLength;
204static constexpr size_t chunkHeight = chunkSideLength;
205static constexpr Float tcW = (Float)tileWidth * (Float)chunkWidth;
206static constexpr Float tcH = (Float)tileHeight * (Float)chunkHeight;
207
208template<typename K, typename T>
209using FlatMap = boost::unordered_flat_map<K, T>;
210
211template<typename K>
212using FlatSet = boost::unordered_flat_set<K>;
213
214template<typename T>
215bool isNaN(const T& v) {
216 return std::isnan(v);
217}
218
219template<>
220bool isNaN<vec2>(const vec2& v) {
221 return std::isnan(v.x) || std::isnan(v.y);
222}
223
224T2D_NAMESPACE_END
T constexpr sqrt(T x)
Returns the sqaure root of some constant x.
Definition base.hpp:190