refactor: format code
This commit is contained in:
@@ -49,7 +49,7 @@ DataBuffer Compress(const DataBuffer& buffer) {
|
||||
return packet;
|
||||
}
|
||||
|
||||
DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength){
|
||||
DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength) {
|
||||
std::uint64_t uncompressedLength;
|
||||
|
||||
buffer >> uncompressedLength;
|
||||
|
||||
@@ -2,70 +2,70 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace td{
|
||||
namespace utils{
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
/* Sine functions */
|
||||
|
||||
float easeInSine(float x){
|
||||
float easeInSine(float x) {
|
||||
return 1.0f - std::cos((x * PI) / 2.0f);
|
||||
}
|
||||
|
||||
float easeOutSine(float x){
|
||||
float easeOutSine(float x) {
|
||||
return std::sin((x * PI) / 2.0f);
|
||||
}
|
||||
|
||||
float easeInOutSine(float x){
|
||||
float easeInOutSine(float x) {
|
||||
return -(std::cos(PI * x) - 1.0f) / 2.0f;
|
||||
}
|
||||
|
||||
/* Cubic functions */
|
||||
|
||||
float easeInCubic(float x){
|
||||
float easeInCubic(float x) {
|
||||
return x * easeInQuad(x);
|
||||
}
|
||||
|
||||
float easeOutCubic(float x){
|
||||
float easeOutCubic(float x) {
|
||||
return 1 - std::pow(1 - x, 3);
|
||||
}
|
||||
|
||||
float easeInOutCubic(float x){
|
||||
float easeInOutCubic(float x) {
|
||||
return x < 0.5 ? 4 * easeInCubic(x) : 1 - std::pow(-2 * x + 2, 3) / 2.0f;
|
||||
}
|
||||
|
||||
/* Quint functions */
|
||||
|
||||
float easeInQuint(float x){
|
||||
float easeInQuint(float x) {
|
||||
return x * easeInQuart(x);
|
||||
}
|
||||
|
||||
float easeOutQuint(float x){
|
||||
float easeOutQuint(float x) {
|
||||
return 1 - std::pow(1 - x, 5);
|
||||
}
|
||||
|
||||
float easeInOutQuint(float x){
|
||||
float easeInOutQuint(float x) {
|
||||
return x < 0.5 ? 16 * easeInQuint(x) : 1 - std::pow(-2 * x + 2, 5) / 2.0f;
|
||||
}
|
||||
|
||||
/* Circ functions */
|
||||
|
||||
float easeInCirc(float x){
|
||||
float easeInCirc(float x) {
|
||||
return 1 - std::sqrt(1 - std::pow(x, 2));
|
||||
}
|
||||
|
||||
float easeOutCirc(float x){
|
||||
float easeOutCirc(float x) {
|
||||
return std::sqrt(1 - std::pow(x - 1, 2));
|
||||
}
|
||||
|
||||
float easeInOutCirc(float x){
|
||||
float easeInOutCirc(float x) {
|
||||
return x < 0.5
|
||||
? (1 - std::sqrt(1 - std::pow(2 * x, 2))) / 2.0f
|
||||
: (std::sqrt(1 - std::pow(-2 * x + 2, 2)) + 1) / 2.0f;
|
||||
? (1 - std::sqrt(1 - std::pow(2 * x, 2))) / 2.0f
|
||||
: (std::sqrt(1 - std::pow(-2 * x + 2, 2)) + 1) / 2.0f;
|
||||
}
|
||||
|
||||
/* Elastic functions */
|
||||
|
||||
float easeInElastic(float x){
|
||||
float easeInElastic(float x) {
|
||||
const float c4 = (2 * PI) / 3.0f;
|
||||
|
||||
return x == 0
|
||||
@@ -75,7 +75,7 @@ float easeInElastic(float x){
|
||||
: -std::pow(2, 10 * x - 10) * std::sin((x * 10 - 10.75) * c4);
|
||||
}
|
||||
|
||||
float easeOutElastic(float x){
|
||||
float easeOutElastic(float x) {
|
||||
const float c4 = (2 * PI) / 3.0f;
|
||||
|
||||
return x == 0
|
||||
@@ -85,7 +85,7 @@ float easeOutElastic(float x){
|
||||
: std::pow(2, -10 * x) * std::sin((x * 10 - 0.75) * c4) + 1;
|
||||
}
|
||||
|
||||
float easeInOutElastic(float x){
|
||||
float easeInOutElastic(float x) {
|
||||
const float c5 = (2 * PI) / 4.5;
|
||||
|
||||
return x == 0
|
||||
@@ -99,43 +99,43 @@ float easeInOutElastic(float x){
|
||||
|
||||
/* Quad functions */
|
||||
|
||||
float easeInQuad(float x){
|
||||
float easeInQuad(float x) {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
float easeOutQuad(float x){
|
||||
float easeOutQuad(float x) {
|
||||
return 1 - (1 - x) * (1 - x);
|
||||
}
|
||||
|
||||
float easeInOutQuad(float x){
|
||||
float easeInOutQuad(float x) {
|
||||
return x < 0.5 ? 2 * x * x : 1 - std::pow(-2 * x + 2, 2) / 2.0f;
|
||||
}
|
||||
|
||||
/* Quart functions */
|
||||
|
||||
float easeInQuart(float x){
|
||||
float easeInQuart(float x) {
|
||||
return x * easeInCubic(x);
|
||||
}
|
||||
|
||||
float easeOutQuart(float x){
|
||||
float easeOutQuart(float x) {
|
||||
return 1 - std::pow(1 - x, 4);
|
||||
}
|
||||
|
||||
float easeInOutQuart(float x){
|
||||
float easeInOutQuart(float x) {
|
||||
return x < 0.5 ? 8 * easeInQuart(x) : 1 - std::pow(-2 * x + 2, 4) / 2.0f;
|
||||
}
|
||||
|
||||
/* Expo functions */
|
||||
|
||||
float easeInExpo(float x){
|
||||
float easeInExpo(float x) {
|
||||
return x == 0 ? 0 : std::pow(2, 10 * x - 10);
|
||||
}
|
||||
|
||||
float easeOutExpo(float x){
|
||||
float easeOutExpo(float x) {
|
||||
return x == 1 ? 1 : 1 - std::pow(2, -10 * x);
|
||||
}
|
||||
|
||||
float easeInOutExpo(float x){
|
||||
float easeInOutExpo(float x) {
|
||||
return x == 0
|
||||
? 0
|
||||
: x == 1
|
||||
@@ -146,21 +146,21 @@ float easeInOutExpo(float x){
|
||||
|
||||
/* Back functions */
|
||||
|
||||
float easeInBack(float x){
|
||||
float easeInBack(float x) {
|
||||
const float c1 = 1.70158;
|
||||
const float c3 = c1 + 1;
|
||||
|
||||
return c3 * easeInCubic(x) - c1 * easeInQuad(x);
|
||||
}
|
||||
|
||||
float easeOutBack(float x){
|
||||
float easeOutBack(float x) {
|
||||
const float c1 = 1.70158;
|
||||
const float c3 = c1 + 1;
|
||||
|
||||
return 1 + c3 * std::pow(x - 1, 3) + c1 * std::pow(x - 1, 2);
|
||||
}
|
||||
|
||||
float easeInOutBack(float x){
|
||||
float easeInOutBack(float x) {
|
||||
const float c1 = 1.70158;
|
||||
const float c2 = c1 * 1.525;
|
||||
|
||||
@@ -171,18 +171,18 @@ float easeInOutBack(float x){
|
||||
|
||||
/* Bounce functions */
|
||||
|
||||
float easeInBounce(float x){
|
||||
float easeInBounce(float x) {
|
||||
return 1 - easeOutBounce(1 - x);
|
||||
}
|
||||
|
||||
float easeOutBounce(float x){
|
||||
float easeOutBounce(float x) {
|
||||
const float n1 = 7.5625;
|
||||
const float d1 = 2.75;
|
||||
|
||||
if (x < 1 / d1) {
|
||||
return n1 * easeInQuad(x);
|
||||
} else if (x < 2 / d1) {
|
||||
x-= 1.5;
|
||||
x -= 1.5;
|
||||
return n1 * (x / d1) * x + 0.75;
|
||||
} else if (x < 2.5 / d1) {
|
||||
x -= 2.25;
|
||||
@@ -193,11 +193,11 @@ float easeOutBounce(float x){
|
||||
}
|
||||
}
|
||||
|
||||
float easeInOutBounce(float x){
|
||||
float easeInOutBounce(float x) {
|
||||
return x < 0.5
|
||||
? (1 - easeOutBounce(1 - 2 * x)) / 2.0f
|
||||
: (1 + easeOutBounce(2 * x - 1)) / 2.0f;
|
||||
}
|
||||
|
||||
|
||||
} // namespace utils
|
||||
} // namespace td
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
void initRandomizer(){
|
||||
void initRandomizer() {
|
||||
srand(time(0));
|
||||
}
|
||||
|
||||
std::uint64_t getRandomNumber(std::uint64_t max){
|
||||
std::uint64_t getRandomNumber(std::uint64_t max) {
|
||||
return rand() % max;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,32 +4,32 @@
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
void Timer::update(){
|
||||
void Timer::update() {
|
||||
m_InternalTime += getTime() - m_LastTime;
|
||||
if(m_InternalTime >= m_Interval){
|
||||
if(m_Function != nullptr)
|
||||
if (m_InternalTime >= m_Interval) {
|
||||
if (m_Function != nullptr)
|
||||
m_Function();
|
||||
m_InternalTime %= m_Interval;
|
||||
}
|
||||
m_LastTime = getTime();
|
||||
}
|
||||
|
||||
void Timer::update(std::uint64_t delta){
|
||||
void Timer::update(std::uint64_t delta) {
|
||||
m_InternalTime += delta;
|
||||
if(m_InternalTime >= m_Interval){
|
||||
if(m_Function != nullptr)
|
||||
if (m_InternalTime >= m_Interval) {
|
||||
if (m_Function != nullptr)
|
||||
m_Function();
|
||||
m_InternalTime %= m_Interval;
|
||||
}
|
||||
m_LastTime = getTime();
|
||||
}
|
||||
|
||||
void Timer::reset(){
|
||||
void Timer::reset() {
|
||||
m_InternalTime = 0;
|
||||
m_LastTime = getTime();
|
||||
}
|
||||
|
||||
std::uint64_t getTime(){
|
||||
std::uint64_t getTime() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock().now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user