Skip to content

Commit 250b8ff

Browse files
committed
trivial changes, angles units are now stored in TURNS similar to Qor
1 parent d708170 commit 250b8ff

File tree

7 files changed

+107
-53
lines changed

7 files changed

+107
-53
lines changed

kit/async/mx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class Multiplexer:
507507

508508
struct CacheLinePadding
509509
{
510-
volatile int8_t pad[CACHE_LINE_SIZE];
510+
volatile int8_t pad[CACHE_LINE_SIZE * 2];
511511
};
512512

513513
const unsigned m_Concurrency;

kit/freq/freq.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
#include <iostream>
55
#include <boost/signals2.hpp>
6+
#include "../kit_compat.h"
67
#include "../math/common.h"
78
#include "../kit.h"
89
#include "../log/log.h"
910

11+
#ifndef K_GET_TICKS
12+
#include <SDL2/SDL.h>
13+
#define K_GET_TICKS SDL_GetTicks
14+
#endif
15+
1016
class Freq
1117
{
1218
public:
@@ -402,10 +408,10 @@ class Freq
402408
{}
403409

404410
unsigned long get_ticks() const {
405-
return SDL_GetTicks();
411+
return K_GET_TICKS();
406412
}
407413
float get_seconds() const {
408-
return SDL_GetTicks() * 0.001f;
414+
return K_GET_TICKS() * 0.001f;
409415
}
410416

411417
// TODO: not yet implemented

kit/kit_compat.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _KIT_COMPAT_H
2+
3+
#ifdef _MSC_VER
4+
#ifndef __WIN32__
5+
#define __WIN32__
6+
#endif
7+
#endif
8+
9+
#ifdef __WIN32__
10+
#define WIN32_LEAN_AND_MEAN
11+
#define NOMINMAX
12+
#include <windows.h>
13+
#endif
14+
15+
#endif

kit/math/angle.h

+53-36
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,47 @@
44
#include "common.h"
55
#include <glm/gtx/vector_angle.hpp>
66

7+
#ifndef K_ANGLE_UNIT
8+
#define K_ANGLE_UNIT TURNS
9+
#endif
10+
711
class Angle
812
{
913

10-
float m_fDeg;
14+
float m_fTurns;
1115

1216
public:
1317

1418
enum Type{
19+
TURNS = 0,
1520
DEGREES,
1621
RADIANS
17-
//TURNS
1822
};
1923

20-
Angle(float a = 0.0f, Type t = DEGREES)
24+
Angle(float a = 0.0f, Type t = K_ANGLE_UNIT)
2125
{
22-
m_fDeg = t==DEGREES ? a : RAD2DEGf(a);
26+
switch(t){
27+
case DEGREES:
28+
m_fTurns = a;
29+
break;
30+
case RADIANS:
31+
m_fTurns = RAD2DEGf(a);
32+
break;
33+
case TURNS:
34+
m_fTurns = RAD2DEGf(a*K_TAU);
35+
break;
36+
default:
37+
assert(false);
38+
}
2339
wrap();
2440
}
2541

2642
//Angle(const glm::vec2& v) {
27-
// m_fDeg = glm::angle(Axis::X, glm::normalize(v));
43+
// m_fTurns = glm::angle(Axis::X, glm::normalize(v));
2844
//}
2945

3046
glm::vec2 vector() const {
31-
return glm::vec2(cos(), sin());
47+
return glm::vec2(Angle::cos(), Angle::sin());
3248
}
3349

3450
//static Angle between(const Angle& a, const Angle& b) {
@@ -39,108 +55,109 @@ class Angle
3955
return Angle(deg, DEGREES);
4056
}
4157
static Angle radians(float rad) {
42-
return Angle(rad, RADIANS);
58+
return Angle(RAD2DEGf(rad), RADIANS);
4359
}
4460
static Angle turns(float t) {
4561
return Angle(t * 360.0f, DEGREES);
4662
}
4763

4864
void wrap()
4965
{
50-
while(m_fDeg >= 180.0f)
51-
m_fDeg -= 360.0f;
52-
while(m_fDeg < -180.0f)
53-
m_fDeg += 360.0f;
66+
while(m_fTurns >= 0.5f)
67+
m_fTurns -= 1.0f;
68+
while(m_fTurns < -0.5f)
69+
m_fTurns += 1.0f;
5470
}
5571

5672
glm::vec2 vector(float mag = 1.0f) {
57-
float rad = DEG2RADf(m_fDeg);
73+
float rad = m_fTurns*K_TAU;
5874
return glm::vec2(
5975
mag * std::cos(rad),
6076
mag * std::sin(rad)
6177
);
6278
}
6379

6480
float cos() const {
65-
return std::cos(DEG2RADf(m_fDeg));
81+
return std::cos(DEG2RADf(m_fTurns));
6682
}
6783
float sin() const {
68-
return std::sin(DEG2RADf(m_fDeg));
84+
return std::sin(DEG2RADf(m_fTurns));
6985
}
7086

71-
Angle flip() {
72-
return *this+Angle::degrees(180.0f);
87+
Angle flip() const {
88+
return *this+Angle::turns(0.5f);
7389
}
7490

75-
float degrees() const { return m_fDeg; }
76-
float radians() const { return DEG2RADf(m_fDeg); }
91+
float degrees() const { return m_fTurns*360.0f; }
92+
float radians() const { return m_fTurns*K_TAU; }
93+
float turns() const { return DEG2RADf(m_fTurns*K_TAU); }
7794
//void degrees(float deg) {
78-
// m_fDeg = deg;
95+
// m_fTurns = deg;
7996
// wrap();
8097
//}
8198
//void radians(float rad) {
82-
// m_fDeg = RAD2DEGf(rad);
99+
// m_fTurns = RAD2DEGf(rad);
83100
// wrap();
84101
//}
85102

86103
Angle operator +(const Angle& a) const{
87-
return Angle(m_fDeg + a.degrees());
104+
return Angle(m_fTurns + a.turns());
88105
}
89106
const Angle& operator +=(const Angle& a) {
90107
return (*this = *this+a);
91108
}
92109
Angle operator -(const Angle& a) const{
93-
return Angle(m_fDeg - a.degrees());
110+
return Angle(m_fTurns - a.turns());
94111
}
95112
Angle operator -() const {
96-
return Angle(-m_fDeg);
113+
return Angle(-m_fTurns);
97114
}
98115
Angle operator *(float f) const{
99-
return Angle(m_fDeg * f);
116+
return Angle(m_fTurns * f);
100117
}
101118
const Angle& operator*=(float f) {
102119
return (*this = *this*f);
103120
}
104121
bool operator==(const Angle& a) const {
105-
return floatcmp(m_fDeg, a.degrees());
122+
return floatcmp(m_fTurns, a.turns());
106123
}
107124

108125
bool operator==(float f) const {
109-
return floatcmp(m_fDeg, Angle::degrees(f).degrees());
126+
return floatcmp(m_fTurns, Angle::turns(f).turns());
110127
}
111128
bool operator!=(float f) const {
112-
return !floatcmp(m_fDeg, Angle::degrees(f).degrees());
129+
return !floatcmp(m_fTurns, Angle::turns(f).turns());
113130
}
114131
const Angle& operator=(float f) {
115-
m_fDeg = f;
132+
m_fTurns = f;
116133
wrap();
117134
return *this;
118135
}
119136

120137
bool operator>(float f) const {
121-
return degrees() > f;
138+
return turns() > f;
122139
}
123140
bool operator>=(float f) const {
124-
return degrees() >= f;
141+
return turns() >= f;
125142
}
126143
bool operator<(float f) const {
127-
return degrees() < f;
144+
return turns() < f;
128145
}
129146
bool operator<=(float f) const {
130-
return degrees() <= f;
147+
return turns() <= f;
131148
}
132149

133150
bool operator>(const Angle& a) const {
134-
return degrees() > a.degrees();
151+
return turns() > a.turns();
135152
}
136153
bool operator>=(const Angle& a) const {
137-
return degrees() >= a.degrees();
154+
return turns() >= a.turns();
138155
}
139156
bool operator<(const Angle& a) const {
140-
return degrees() < a.degrees();
157+
return turns() < a.turns();
141158
}
142159
bool operator<=(const Angle& a) const {
143-
return degrees() <= a.degrees();
160+
return turns() <= a.turns();
144161
}
145162
};
146163

kit/math/common.h

+16
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,32 @@
88
#include <glm/gtx/transform.hpp>
99
#include <glm/gtx/transform2.hpp>
1010

11+
#ifndef K_EPSILON
1112
#define K_EPSILON 0.00001
13+
#endif
1214

15+
#ifndef K_PI
1316
#define K_PI 3.1415926535897932385
17+
#endif
18+
19+
#ifndef K_TAU
1420
#define K_TAU 6.2831853071795864770
21+
#endif
1522

1623
#define DEG2RAD(X) ((X)*K_TAU/360.0)
1724
#define RAD2DEG(X) ((X)*360.0/K_TAU)
1825
#define DEG2RADf(X) ((X)*((float)K_TAU)/360.0f)
1926
#define RAD2DEGf(X) ((X)*360.0f/((float)K_TAU))
2027

28+
#define RAD2TRNf(X) ((X)/(float)K_TAU)
29+
#define TRN2RADf(X) ((X)*(float)K_TAU)
30+
#define DEG2TRNf(X) ((X)/360.0f)
31+
#define TRN2DEGf(X) ((X)*360.0f)
32+
33+
inline float sinT(float theta){ return sin(theta*K_TAU);}
34+
inline float cosT(float theta){ return cos(theta*K_TAU);}
35+
inline float tanT(float theta){ return tan(theta*K_TAU);}
36+
2137
inline float sin_deg(float theta){
2238
return (sinf(theta*((float)K_TAU/360.0f)));
2339
}

kit/net/net.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
#ifndef NET_H_QTJHVVWD
22
#define NET_H_QTJHVVWD
33

4-
#ifdef _MSC_VER
5-
#ifndef __WIN32__
6-
#define __WIN32__
7-
#endif
8-
#endif
4+
#include "../kit_compat.h"
95

106
#ifdef __WIN32__
11-
#define WIN32_LEAN_AND_MEAN
12-
#define NOMINMAX
13-
#include <windows.h>
147
#include <winsock2.h>
158
typedef int socklen_t;
169
#else

toys/premake4.lua

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ solution("kit")
33

44
targetdir("bin")
55

6+
defines {
7+
"GLM_FORCE_CTOR_INIT",
8+
"GLM_ENABLE_EXPERIMENTAL",
9+
"GLM_FORCE_RADIANS",
10+
"NOMINMAX"
11+
}
12+
613
configuration "debug"
714
defines { "DEBUG" }
815
flags { "Symbols" }
@@ -25,8 +32,8 @@ solution("kit")
2532
}
2633
files {
2734
"src/echo.cpp",
28-
"../include/**.cpp",
29-
"../include/**.inl"
35+
"../kit/**.cpp",
36+
"../kit/**.inl"
3037
}
3138

3239
defines { "BACKWARD_HAS_BFD=1" }
@@ -67,8 +74,8 @@ solution("kit")
6774
}
6875
files {
6976
"src/stability.cpp",
70-
"../include/**.cpp",
71-
"../include/**.inl"
77+
"../kit/**.cpp",
78+
"../kit/**.inl"
7279
}
7380

7481
defines { "BACKWARD_HAS_BFD=1" }
@@ -109,8 +116,8 @@ solution("kit")
109116
}
110117
files {
111118
"src/chat.cpp",
112-
"../include/**.cpp",
113-
"../include/**.inl"
119+
"../kit/**.cpp",
120+
"../kit/**.inl"
114121
}
115122

116123
defines { "BACKWARD_HAS_BFD=1" }

0 commit comments

Comments
 (0)