Added AsloEngine 0.9.0 to Repository

This commit is contained in:
Aslan2142 2019-08-29 18:42:28 +02:00
parent d017dd84b3
commit 881e6c70f2
60 changed files with 2648 additions and 0 deletions

209
asloengine/helpers.cpp Executable file
View file

@ -0,0 +1,209 @@
#include "headers/helpers.hpp"
namespace asloengine
{
unsigned long long log_count = 0;
void log(const std::string& prefix, const bool condition)
{
#ifdef DEBUG
std::string new_message = condition ? "true" : "false";
log(prefix, new_message);
#endif
}
void log(const std::string& prefix, const int number)
{
#ifdef DEBUG
std::string new_message = std::to_string(number);
log(prefix, new_message);
#endif
}
void log(const std::string& prefix, const double number)
{
#ifdef DEBUG
std::string new_message = std::to_string(number);
log(prefix, new_message);
#endif
}
void log(const std::string& prefix, const char* message)
{
#ifdef DEBUG
std::string new_message = std::string(message);
log(prefix, new_message);
#endif
}
void log(const std::string& prefix, const std::string& message)
{
#ifdef DEBUG
std::string logged_message = std::to_string(log_count++) + " - " + prefix + message;
// Log into Console
std::cout << logged_message << std::endl;
// Log into File
if (log_count == 1) { remove("log.txt"); }
std::ofstream o_file("log.txt", std::ios_base::app);
o_file << logged_message << std::endl;
o_file.close();
#endif
}
sf::Vector2f operator+(sf::Vector2f _vec, float add)
{
return sf::Vector2f(_vec.x + add, _vec.y + add);
}
sf::Vector2f operator-(sf::Vector2f _vec, float subtract)
{
return sf::Vector2f(_vec.x - subtract, _vec.y - subtract);
}
sf::Vector2f operator*(sf::Vector2f _vec, float multiplier)
{
return sf::Vector2f(_vec.x * multiplier, _vec.y * multiplier);
}
sf::Vector2f operator/(sf::Vector2f _vec, float divider)
{
return sf::Vector2f(_vec.x / divider, _vec.y / divider);
}
sf::Vector2f operator+(sf::Vector2f _vec_1, sf::Vector2f _vec_2)
{
return sf::Vector2f(_vec_1.x + _vec_2.x, _vec_1.y + _vec_2.y);
}
sf::Vector2f operator-(sf::Vector2f _vec_1, sf::Vector2f _vec_2)
{
return sf::Vector2f(_vec_1.x - _vec_2.x, _vec_1.y - _vec_2.y);
}
sf::Vector2f operator*(sf::Vector2f _vec_1, sf::Vector2f _vec_2)
{
return sf::Vector2f(_vec_1.x * _vec_2.x, _vec_1.y * _vec_2.y);
}
sf::Vector2f operator/(sf::Vector2f _vec_1, sf::Vector2f _vec_2)
{
return sf::Vector2f(_vec_1.x / _vec_2.x, _vec_1.y / _vec_2.y);
}
sf::Vector2f operator+(sf::Vector2f _vec, sf::FloatRect _rect)
{
return sf::Vector2f(_vec.x + _rect.width, _vec.y + _rect.height);
}
sf::Vector2f operator-(sf::Vector2f _vec, sf::FloatRect _rect)
{
return sf::Vector2f(_vec.x - _rect.width, _vec.y - _rect.height);
}
sf::Vector2f operator*(sf::Vector2f _vec, sf::FloatRect _rect)
{
return sf::Vector2f(_vec.x * _rect.width, _vec.y * _rect.height);
}
sf::Vector2f operator/(sf::Vector2f _vec, sf::FloatRect _rect)
{
return sf::Vector2f(_vec.x / _rect.width, _vec.y / _rect.height);
}
float clamp(float value, float min, float max)
{
if (value < min)
{
value = min;
}
if (value > max)
{
value = max;
}
return value;
}
sf::Vector2i to_vector2i(sf::Vector2u _vec)
{
return sf::Vector2i(_vec.x, _vec.y);
}
sf::Vector2i to_vector2i(sf::Vector2f _vec)
{
return sf::Vector2i(_vec.x, _vec.y);
}
sf::Vector2u to_vector2u(sf::Vector2i _vec)
{
return sf::Vector2u(_vec.x, _vec.y);
}
sf::Vector2u to_vector2u(sf::Vector2f _vec)
{
return sf::Vector2u(_vec.x, _vec.y);
}
sf::Vector2f to_vector2f(sf::Vector2i _vec)
{
return sf::Vector2f(_vec.x, _vec.y);
}
sf::Vector2f to_vector2f(sf::Vector2u _vec)
{
return sf::Vector2f(_vec.x, _vec.y);
}
}