A small namespace rework
This commit is contained in:
parent
b30de44a05
commit
77db031342
|
@ -960,7 +960,7 @@ RECURSIVE = NO
|
|||
# Note that relative paths are relative to the directory from which doxygen is
|
||||
# run.
|
||||
|
||||
EXCLUDE =
|
||||
EXCLUDE = ./include/doctest.h
|
||||
|
||||
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
|
||||
# directories that are symbolic links (a Unix file system feature) are excluded
|
||||
|
@ -1253,7 +1253,7 @@ HTML_STYLESHEET =
|
|||
# list). For an example see the documentation.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_EXTRA_STYLESHEET =
|
||||
HTML_EXTRA_STYLESHEET = doxygen-awesome-css/doxygen-awesome.css
|
||||
|
||||
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
||||
# other source files which should be copied to the HTML output directory. Note
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
struct Audio
|
||||
{
|
||||
static bool Init(int flags);
|
||||
static bool Init(int flags); ///< Initializes the SDL_mixer library
|
||||
|
||||
/// Used for short sound effects
|
||||
class SoundFile
|
||||
{
|
||||
public:
|
||||
|
@ -25,6 +26,7 @@ namespace Birb2D
|
|||
std::string filePath;
|
||||
};
|
||||
|
||||
/// Used for longer audio pieces like music. Shouldn't be used for sound effects
|
||||
class MusicFile
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -5,43 +5,44 @@
|
|||
#include <SDL2/SDL_ttf.h>
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
///
|
||||
/// TextComponent contains details needed to generate a sprite for the Entity in case the Entity is used to display text.
|
||||
///
|
||||
struct TextComponent
|
||||
{
|
||||
TextComponent();
|
||||
TextComponent(std::string p_text, TTF_Font* font, SDL_Color* p_color);
|
||||
std::string text;
|
||||
TTF_Font* font;
|
||||
SDL_Color* color;
|
||||
SDL_Color* color; ///< Surface color of the text
|
||||
};
|
||||
|
||||
/// Entities are objects that contain all of the information required to render stuff
|
||||
|
||||
/// Entities can be anything really. For example, it could be text or a picture. This could be extended to animations in the future
|
||||
struct Entity
|
||||
{
|
||||
Entity(); /*!< Creates empty Entity object */
|
||||
Entity(std::string p_name, Rect p_rect, SDL_Texture* p_texture); /*!< Creates an Entity with a SDL_Texture to render with custom scale */
|
||||
Entity(std::string p_name, Vector2int pos, TextComponent p_textComponent); /*!< Creates a Text Entity using a TextComponent */
|
||||
Entity(std::string p_name, Vector2int pos, SDL_Texture* p_texture); /*!< Creates an Entity with a SDL_Texture to render without specifying a scale */
|
||||
Entity(); ///< Creates empty Entity object
|
||||
Entity(std::string p_name, Rect p_rect, SDL_Texture* p_texture); ///< Creates an Entity with a SDL_Texture to render with custom scale
|
||||
Entity(std::string p_name, Vector2int pos, TextComponent p_textComponent); ///< Creates a Text Entity using a TextComponent
|
||||
Entity(std::string p_name, Vector2int pos, SDL_Texture* p_texture); ///< Creates an Entity with a SDL_Texture to render without specifying a scale
|
||||
|
||||
/* Make it possible to update the TextComponent */
|
||||
void SetText(std::string newText);
|
||||
void SetFont(TTF_Font* font);
|
||||
void SetColor(SDL_Color* color);
|
||||
void SetText(std::string newText); ///< Change the text in TextComponent and reload the sprite
|
||||
void SetFont(TTF_Font* font); ///< Change the font in TextComponent and reload the sprite
|
||||
void SetColor(SDL_Color* color); ///< Change the color in TextComponent and reload the sprite
|
||||
|
||||
std::string name;
|
||||
SDL_Texture* sprite;
|
||||
std::string name; ///< Name of the entity. Used for debugging
|
||||
SDL_Texture* sprite; ///< Sprite to be rendered
|
||||
|
||||
float angle;
|
||||
Rect rect;
|
||||
Vector2f localScale;
|
||||
float angle; ///< Sets the rotation of the entity when rendering it
|
||||
Rect rect; ///< Sets the position and the dimensions of the entity
|
||||
Vector2f localScale; ///< Scale modifier for the Entity rendering
|
||||
|
||||
TextComponent textComponent; /*!< Having a TextComponent in an Entity enables the rendering of Text */
|
||||
void LoadSprite();
|
||||
void ReloadSprite();
|
||||
void SetBaseEntityValues();
|
||||
TextComponent textComponent; ///< Having a TextComponent in an Entity enables the rendering of Text
|
||||
void LoadSprite(); ///< Create a sprite for the Entity using details found in the textComponent variable
|
||||
void ReloadSprite(); ///< Destroy the old sprite and create a new one. Useful for refreshing text after editing the textComponent variable
|
||||
void SetBaseEntityValues(); ///< Used to set some default value when they aren't provided during Entity initialization
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,15 @@
|
|||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
namespace Debug
|
||||
namespace Birb
|
||||
{
|
||||
enum Type
|
||||
namespace Debug
|
||||
{
|
||||
log, warning, error
|
||||
};
|
||||
void Log(std::string text, Type type = Type::log);
|
||||
static std::vector<std::string> lines;
|
||||
enum Type
|
||||
{
|
||||
log, warning, error
|
||||
};
|
||||
void Log(std::string text, Type type = Type::log);
|
||||
static std::vector<std::string> lines;
|
||||
}
|
||||
}
|
||||
|
|
179
include/Math.hpp
179
include/Math.hpp
|
@ -2,107 +2,110 @@
|
|||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
struct Vector2f
|
||||
namespace Birb
|
||||
{
|
||||
Vector2f()
|
||||
:x(0.0f), y(0.0f)
|
||||
{}
|
||||
|
||||
Vector2f(float p_x, float p_y)
|
||||
:x(p_x), y(p_y)
|
||||
{}
|
||||
|
||||
Vector2f getValue()
|
||||
struct Vector2f
|
||||
{
|
||||
return Vector2f(x, y);
|
||||
}
|
||||
Vector2f()
|
||||
:x(0.0f), y(0.0f)
|
||||
{}
|
||||
|
||||
std::string print()
|
||||
Vector2f(float p_x, float p_y)
|
||||
:x(p_x), y(p_y)
|
||||
{}
|
||||
|
||||
Vector2f getValue()
|
||||
{
|
||||
return Vector2f(x, y);
|
||||
}
|
||||
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
|
||||
}
|
||||
|
||||
float x, y;
|
||||
};
|
||||
|
||||
struct Vector2int
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
|
||||
}
|
||||
Vector2int()
|
||||
:x(0), y(0)
|
||||
{}
|
||||
|
||||
float x, y;
|
||||
};
|
||||
Vector2int(int p_x, int p_y)
|
||||
:x(p_x), y(p_y)
|
||||
{}
|
||||
|
||||
struct Vector2int
|
||||
{
|
||||
Vector2int()
|
||||
:x(0), y(0)
|
||||
{}
|
||||
Vector2int(float p_x, float p_y)
|
||||
{
|
||||
x = std::round(p_x);
|
||||
y = std::round(p_y);
|
||||
}
|
||||
|
||||
Vector2int(int p_x, int p_y)
|
||||
:x(p_x), y(p_y)
|
||||
{}
|
||||
Vector2int getValue()
|
||||
{
|
||||
return Vector2int(x, y);
|
||||
}
|
||||
|
||||
Vector2int(float p_x, float p_y)
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
|
||||
}
|
||||
|
||||
int x, y;
|
||||
};
|
||||
|
||||
struct Vector3f
|
||||
{
|
||||
x = std::round(p_x);
|
||||
y = std::round(p_y);
|
||||
}
|
||||
Vector3f()
|
||||
:x(0.0f), y(0.0f), z(0.0f)
|
||||
{}
|
||||
|
||||
Vector2int getValue()
|
||||
Vector3f(float p_x, float p_y, float p_z)
|
||||
:x(p_x), y(p_y), z(p_z)
|
||||
{}
|
||||
|
||||
Vector3f getValue()
|
||||
{
|
||||
return Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + ")";
|
||||
}
|
||||
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
struct Vector3int
|
||||
{
|
||||
return Vector2int(x, y);
|
||||
}
|
||||
Vector3int()
|
||||
:x(0), y(0), z(0)
|
||||
{}
|
||||
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
|
||||
}
|
||||
Vector3int(int p_x, int p_y, int p_z)
|
||||
:x(p_x), y(p_y), z(p_z)
|
||||
{}
|
||||
|
||||
int x, y;
|
||||
};
|
||||
Vector3int(float p_x, float p_y, float p_z)
|
||||
{
|
||||
x = std::round(p_x);
|
||||
y = std::round(p_y);
|
||||
z = std::round(p_z);
|
||||
}
|
||||
|
||||
struct Vector3f
|
||||
{
|
||||
Vector3f()
|
||||
:x(0.0f), y(0.0f), z(0.0f)
|
||||
{}
|
||||
Vector3int getValue()
|
||||
{
|
||||
return Vector3int(x, y, z);
|
||||
}
|
||||
|
||||
Vector3f(float p_x, float p_y, float p_z)
|
||||
:x(p_x), y(p_y), z(p_z)
|
||||
{}
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + ")";
|
||||
}
|
||||
|
||||
Vector3f getValue()
|
||||
{
|
||||
return Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + ")";
|
||||
}
|
||||
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
struct Vector3int
|
||||
{
|
||||
Vector3int()
|
||||
:x(0), y(0), z(0)
|
||||
{}
|
||||
|
||||
Vector3int(int p_x, int p_y, int p_z)
|
||||
:x(p_x), y(p_y), z(p_z)
|
||||
{}
|
||||
|
||||
Vector3int(float p_x, float p_y, float p_z)
|
||||
{
|
||||
x = std::round(p_x);
|
||||
y = std::round(p_y);
|
||||
z = std::round(p_z);
|
||||
}
|
||||
|
||||
Vector3int getValue()
|
||||
{
|
||||
return Vector3int(x, y, z);
|
||||
}
|
||||
|
||||
std::string print()
|
||||
{
|
||||
return "(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + ")";
|
||||
}
|
||||
|
||||
int x, y, z;
|
||||
};
|
||||
int x, y, z;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "Utils.hpp"
|
||||
#include "Entity.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
struct Window
|
||||
{
|
||||
|
@ -45,6 +45,7 @@ namespace Birb2D
|
|||
/* ---------------------- */
|
||||
};
|
||||
|
||||
/// Methods for loading different resources like fonts and textures
|
||||
struct Resources
|
||||
{
|
||||
static SDL_Texture* LoadTexture(std::string p_filePath);
|
||||
|
@ -52,6 +53,7 @@ namespace Birb2D
|
|||
static TTF_Font* LoadFont(std::string p_filePath, int p_fontSize);
|
||||
};
|
||||
|
||||
/// Methods for rendering things
|
||||
struct Render
|
||||
{
|
||||
static void DrawEntity(Entity& entity);
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
/// Class for timing things. Accurate down to milliseconds
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
|
@ -15,12 +16,12 @@ namespace Birb2D
|
|||
double ElapsedMinutes();
|
||||
double ElapsedHours();
|
||||
|
||||
double CalcSeconds(double mills);
|
||||
double CalcMinutes(double mills);
|
||||
double CalcHours(double mills);
|
||||
double CalcSeconds(double mills); ///< Converts milliseconds into seconds
|
||||
double CalcMinutes(double mills); ///< Converts milliseconds into minutes
|
||||
double CalcHours(double mills); ///< Converts milliseconds into hours
|
||||
|
||||
std::string DigitalFormat();
|
||||
std::string SplitDigitalFormat(double previousmills);
|
||||
std::string DigitalFormat(); ///< Prints the current elapsed time in digital format (00:00:00:000)
|
||||
std::string SplitDigitalFormat(double previousmills /**< [in] elapsed milliseconds of the previous split */); ///< Used for calculating digital time for a split during timing
|
||||
bool running = false;
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
/// Limit the runtime speed and handle delta time
|
||||
struct TimeStep
|
||||
{
|
||||
/* Functions */
|
||||
void Init();
|
||||
void Start();
|
||||
bool Running();
|
||||
void Step();
|
||||
void End();
|
||||
float getTimestepAlpha();
|
||||
void Init(); ///< Reset the currentTime variable
|
||||
void Start(); ///< Start a new step. Call this in the beginning of the gameloop
|
||||
bool Running(); ///< Check if the accumulator is empty yet. While this is true, handle input events etc.
|
||||
void Step(); ///< Deplete the accumulator. Speed determined by the value of timeStep
|
||||
void End(); ///< End the timeStep and delay the rendering to stay within the refreshrate
|
||||
float getTimestepAlpha(); ///< Method to get deltatime
|
||||
|
||||
/* Variables */
|
||||
const float timeStep = 0.01f;
|
||||
|
|
|
@ -8,62 +8,66 @@
|
|||
#include <math.h>
|
||||
|
||||
|
||||
struct Rect
|
||||
namespace Birb
|
||||
{
|
||||
Rect();
|
||||
Rect(float p_x, float p_y, float p_w, float p_h);
|
||||
|
||||
void print()
|
||||
struct Rect
|
||||
{
|
||||
std::cout << x << ", " << y << ", " << w << ", " << h << std::endl;
|
||||
}
|
||||
Rect();
|
||||
Rect(float p_x, float p_y, float p_w, float p_h);
|
||||
|
||||
Rect getInt();
|
||||
void print()
|
||||
{
|
||||
std::cout << x << ", " << y << ", " << w << ", " << h << std::endl;
|
||||
}
|
||||
|
||||
SDL_Rect getSDLRect();
|
||||
Rect getInt();
|
||||
|
||||
float x, y, w, h;
|
||||
};
|
||||
SDL_Rect getSDLRect();
|
||||
|
||||
namespace utils
|
||||
{
|
||||
inline float hireTimeInSeconds()
|
||||
{
|
||||
float t = SDL_GetTicks();
|
||||
t *= 0.001f;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
inline int randomInt(int min, int max)
|
||||
{
|
||||
srand(time(0));
|
||||
float value = rand() % (max + 1 - min) + min;
|
||||
return value;
|
||||
}
|
||||
|
||||
inline float randomFloat(float min, float max)
|
||||
{
|
||||
srand(time(0));
|
||||
float random = ((float) rand()) / (float) RAND_MAX;
|
||||
float range = max - min;
|
||||
return (random * range) + min;
|
||||
}
|
||||
|
||||
static void GetTextureDimensions(SDL_Texture* texture, int& x, int& y)
|
||||
{
|
||||
SDL_QueryTexture(texture, NULL, NULL, &x, &y);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Birb2D
|
||||
{
|
||||
struct Texture
|
||||
{
|
||||
Texture();
|
||||
Texture(SDL_Texture* p_sdlTexture, Vector2int p_dimensions);
|
||||
SDL_Texture* sdlTexture;
|
||||
Vector2int dimensions;
|
||||
float x, y, w, h;
|
||||
};
|
||||
|
||||
namespace utils
|
||||
{
|
||||
inline float hireTimeInSeconds()
|
||||
{
|
||||
float t = SDL_GetTicks();
|
||||
t *= 0.001f;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
inline int randomInt(int min, int max)
|
||||
{
|
||||
srand(time(0));
|
||||
float value = rand() % (max + 1 - min) + min;
|
||||
return value;
|
||||
}
|
||||
|
||||
inline float randomFloat(float min, float max)
|
||||
{
|
||||
srand(time(0));
|
||||
float random = ((float) rand()) / (float) RAND_MAX;
|
||||
float range = max - min;
|
||||
return (random * range) + min;
|
||||
}
|
||||
|
||||
static void GetTextureDimensions(SDL_Texture* texture, int& x, int& y)
|
||||
{
|
||||
SDL_QueryTexture(texture, NULL, NULL, &x, &y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//namespace Birb2D
|
||||
//{
|
||||
// /// Deprecated way of handling textures. Kept for now, but please don't use this
|
||||
// struct Texture
|
||||
// {
|
||||
// Texture();
|
||||
// Texture(SDL_Texture* p_sdlTexture, Vector2int p_dimensions);
|
||||
// SDL_Texture* sdlTexture;
|
||||
// Vector2int dimensions;
|
||||
// };
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -3,33 +3,36 @@
|
|||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace Global
|
||||
namespace Birb
|
||||
{
|
||||
namespace IsInit
|
||||
namespace Global
|
||||
{
|
||||
static bool SDL = false;
|
||||
static bool SDL_ttf = false;
|
||||
static bool SDL_image = false;
|
||||
namespace IsInit
|
||||
{
|
||||
static bool SDL = false;
|
||||
static bool SDL_ttf = false;
|
||||
static bool SDL_image = false;
|
||||
}
|
||||
|
||||
namespace RenderVars
|
||||
{
|
||||
static int RefreshRate = 60;
|
||||
static SDL_Window* MainWindow;
|
||||
static SDL_Renderer* Renderer;
|
||||
}
|
||||
}
|
||||
|
||||
namespace RenderVars
|
||||
namespace Colors
|
||||
{
|
||||
static int RefreshRate = 60;
|
||||
static SDL_Window* MainWindow;
|
||||
static SDL_Renderer* Renderer;
|
||||
static SDL_Color White = { 255, 255, 255, 255 };
|
||||
static SDL_Color Black = { 0, 0, 0, 255 };
|
||||
static SDL_Color Red = { 255, 0, 0, 255 };
|
||||
static SDL_Color Green = { 0, 255, 0, 255 };
|
||||
static SDL_Color Blue = { 0, 0, 255, 255 };
|
||||
static SDL_Color Yellow = { 255, 255, 0, 255 };
|
||||
static SDL_Color DarkGray = { 60, 60, 60, 255 };
|
||||
static SDL_Color LightGray = { 180, 180, 180, 255 };
|
||||
|
||||
SDL_Color ChangeColorIntensity(SDL_Color color, int delta);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Colors
|
||||
{
|
||||
static SDL_Color White = { 255, 255, 255, 255 };
|
||||
static SDL_Color Black = { 0, 0, 0, 255 };
|
||||
static SDL_Color Red = { 255, 0, 0, 255 };
|
||||
static SDL_Color Green = { 0, 255, 0, 255 };
|
||||
static SDL_Color Blue = { 0, 0, 255, 255 };
|
||||
static SDL_Color Yellow = { 255, 255, 0, 255 };
|
||||
static SDL_Color DarkGray = { 60, 60, 60, 255 };
|
||||
static SDL_Color LightGray = { 180, 180, 180, 255 };
|
||||
|
||||
SDL_Color ChangeColorIntensity(SDL_Color color, int delta);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "Audio.hpp"
|
||||
#include "Logger.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
//** Initializes the SDL_mixer library. Needs to be called before any other audio features are used
|
||||
bool Audio::Init(int flags)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "Entity.hpp"
|
||||
#include "Renderwindow.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
TextComponent::TextComponent()
|
||||
{
|
||||
|
|
172
src/logger.cpp
172
src/logger.cpp
|
@ -3,92 +3,98 @@
|
|||
#include <fstream>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
void Debug::Log(std::string text, Type type)
|
||||
namespace Birb
|
||||
{
|
||||
std::time_t t = std::time(0);
|
||||
std::tm* now = std::localtime(&t);
|
||||
std::string hours, minutes, seconds;
|
||||
|
||||
std::string line;
|
||||
std::string printline;
|
||||
|
||||
// Hours
|
||||
if (now->tm_hour < 10)
|
||||
hours = "0" + std::to_string(now->tm_hour);
|
||||
else
|
||||
hours = std::to_string(now->tm_hour);
|
||||
|
||||
// Minutes
|
||||
if (now->tm_min < 10)
|
||||
minutes = "0" + std::to_string(now->tm_min);
|
||||
else
|
||||
minutes = std::to_string(now->tm_min);
|
||||
|
||||
// Seconds
|
||||
if (now->tm_sec < 10)
|
||||
seconds = "0" + std::to_string(now->tm_sec);
|
||||
else
|
||||
seconds = std::to_string(now->tm_sec);
|
||||
|
||||
line = "[" + hours + ":" + minutes + ":" + seconds + "] ";
|
||||
|
||||
|
||||
switch (type)
|
||||
namespace Debug
|
||||
{
|
||||
case (Type::log):
|
||||
printline = line + "\033[32m[Log] " + text + "\033[0m";
|
||||
line = line + "[Log] " + text + "\n";
|
||||
break;
|
||||
|
||||
case (Type::warning):
|
||||
printline = line + "\033[33m[Warning] " + text + "\033[0m";
|
||||
line = line + "[Warning] " + text + "\n";
|
||||
break;
|
||||
|
||||
case (Type::error):
|
||||
printline = line + "\033[31m[ERROR] " + text + "\033[0m";
|
||||
line = line + "[ERROR] " + text + "\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the text to list of debug lines
|
||||
bool repeatingLine = false;
|
||||
|
||||
if (Debug::lines.size() > 0)
|
||||
{
|
||||
if (Debug::lines[Debug::lines.size() - 1] == text)
|
||||
void Log(std::string text, Type type)
|
||||
{
|
||||
repeatingLine = true;
|
||||
Debug::lines.push_back(text);
|
||||
}
|
||||
else if (Debug::lines.size() > 1)
|
||||
{
|
||||
Debug::lines.clear();
|
||||
std::cout << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug::lines.clear();
|
||||
std::time_t t = std::time(0);
|
||||
std::tm* now = std::localtime(&t);
|
||||
std::string hours, minutes, seconds;
|
||||
|
||||
std::string line;
|
||||
std::string printline;
|
||||
|
||||
// Hours
|
||||
if (now->tm_hour < 10)
|
||||
hours = "0" + std::to_string(now->tm_hour);
|
||||
else
|
||||
hours = std::to_string(now->tm_hour);
|
||||
|
||||
// Minutes
|
||||
if (now->tm_min < 10)
|
||||
minutes = "0" + std::to_string(now->tm_min);
|
||||
else
|
||||
minutes = std::to_string(now->tm_min);
|
||||
|
||||
// Seconds
|
||||
if (now->tm_sec < 10)
|
||||
seconds = "0" + std::to_string(now->tm_sec);
|
||||
else
|
||||
seconds = std::to_string(now->tm_sec);
|
||||
|
||||
line = "[" + hours + ":" + minutes + ":" + seconds + "] ";
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case (Type::log):
|
||||
printline = line + "\033[32m[Log] " + text + "\033[0m";
|
||||
line = line + "[Log] " + text + "\n";
|
||||
break;
|
||||
|
||||
case (Type::warning):
|
||||
printline = line + "\033[33m[Warning] " + text + "\033[0m";
|
||||
line = line + "[Warning] " + text + "\n";
|
||||
break;
|
||||
|
||||
case (Type::error):
|
||||
printline = line + "\033[31m[ERROR] " + text + "\033[0m";
|
||||
line = line + "[ERROR] " + text + "\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the text to list of debug lines
|
||||
bool repeatingLine = false;
|
||||
|
||||
if (Debug::lines.size() > 0)
|
||||
{
|
||||
if (Debug::lines[Debug::lines.size() - 1] == text)
|
||||
{
|
||||
repeatingLine = true;
|
||||
Debug::lines.push_back(text);
|
||||
}
|
||||
else if (Debug::lines.size() > 1)
|
||||
{
|
||||
Debug::lines.clear();
|
||||
std::cout << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug::lines.clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug::lines.push_back(text);
|
||||
}
|
||||
|
||||
// Print out the debug line
|
||||
if (!repeatingLine)
|
||||
std::cout << printline << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout << printline << " (" << Debug::lines.size() << "x)" << "\t\r" << std::flush;
|
||||
}
|
||||
|
||||
// Append the line to a logfile
|
||||
std::ofstream outfile;
|
||||
outfile.open("log.txt", std::ios_base::app);
|
||||
outfile << line;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug::lines.push_back(text);
|
||||
}
|
||||
|
||||
// Print out the debug line
|
||||
if (!repeatingLine)
|
||||
std::cout << printline << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout << printline << " (" << Debug::lines.size() << "x)" << "\t\r" << std::flush;
|
||||
}
|
||||
|
||||
// Append the line to a logfile
|
||||
std::ofstream outfile;
|
||||
outfile.open("log.txt", std::ios_base::app);
|
||||
outfile << line;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "Values.hpp"
|
||||
#include "Logger.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
Window::Window(std::string p_title, Vector2int p_window_dimensions, int p_refresh_rate)
|
||||
:refresh_rate(p_refresh_rate), window_dimensions(p_window_dimensions), win_title(p_title)
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
|
||||
TEST_CASE("logging")
|
||||
{
|
||||
CHECK_NOTHROW(Debug::Log("Log (this is only a test)"));
|
||||
CHECK_NOTHROW(Debug::Log("Log (this is only a test)", Debug::log));
|
||||
CHECK_NOTHROW(Debug::Log("Warning (this is only a test)", Debug::warning));
|
||||
CHECK_NOTHROW(Debug::Log("Error (this is only a test)", Debug::error));
|
||||
CHECK_NOTHROW(Birb::Debug::Log("Log (this is only a test)"));
|
||||
CHECK_NOTHROW(Birb::Debug::Log("Log (this is only a test)", Birb::Debug::log));
|
||||
CHECK_NOTHROW(Birb::Debug::Log("Warning (this is only a test)", Birb::Debug::warning));
|
||||
CHECK_NOTHROW(Birb::Debug::Log("Error (this is only a test)", Birb::Debug::error));
|
||||
}
|
||||
|
||||
TEST_CASE("window and rendering functions")
|
||||
{
|
||||
Birb2D::Window window("Title", Vector2int(1280, 720), 60);
|
||||
SDL_Texture* texture = Birb2D::Resources::LoadTexture("/home/toasterbirb/git/birb2d/res/textures/giga_stretch.png");
|
||||
TTF_Font* font = Birb2D::Resources::LoadFont("/home/toasterbirb/git/birb2d/res/fonts/freefont/FreeMonoBold.ttf", 32);
|
||||
Birb::Window window("Title", Birb::Vector2int(1280, 720), 60);
|
||||
SDL_Texture* texture = Birb::Resources::LoadTexture("/home/toasterbirb/git/birb2d/res/textures/giga_stretch.png");
|
||||
TTF_Font* font = Birb::Resources::LoadFont("/home/toasterbirb/git/birb2d/res/fonts/freefont/FreeMonoBold.ttf", 32);
|
||||
|
||||
CHECK(window.win_title == "Title");
|
||||
CHECK(window.window_dimensions.x == 1280);
|
||||
|
@ -45,37 +45,37 @@ TEST_CASE("window and rendering functions")
|
|||
// ### Math stuff and other utilities ###
|
||||
TEST_CASE("Default Vector2f")
|
||||
{
|
||||
Vector2f vector;
|
||||
Birb::Vector2f vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Vector2f with arguments")
|
||||
{
|
||||
CHECK(Vector2f(1, 4).x == 1);
|
||||
CHECK(Vector2f(1, 4).y == 4);
|
||||
CHECK(Vector2f(1.53f, 5.21f).x == 1.53f);
|
||||
CHECK(Vector2f(1.53f, 5.21f).y == 5.21f);
|
||||
CHECK(Birb::Vector2f(1, 4).x == 1);
|
||||
CHECK(Birb::Vector2f(1, 4).y == 4);
|
||||
CHECK(Birb::Vector2f(1.53f, 5.21f).x == 1.53f);
|
||||
CHECK(Birb::Vector2f(1.53f, 5.21f).y == 5.21f);
|
||||
}
|
||||
|
||||
TEST_CASE("Default Vector2int")
|
||||
{
|
||||
Vector2int vector;
|
||||
Birb::Vector2int vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Vector2int with arguments")
|
||||
{
|
||||
CHECK(Vector2int(1, 4).x == 1);
|
||||
CHECK(Vector2int(1, 4).y == 4);
|
||||
CHECK(Vector2int(1.53f, 5.21f).x == 2);
|
||||
CHECK(Vector2int(1.53f, 5.21f).y == 5);
|
||||
CHECK(Birb::Vector2int(1, 4).x == 1);
|
||||
CHECK(Birb::Vector2int(1, 4).y == 4);
|
||||
CHECK(Birb::Vector2int(1.53f, 5.21f).x == 2);
|
||||
CHECK(Birb::Vector2int(1.53f, 5.21f).y == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("Default Vector3f")
|
||||
{
|
||||
Vector3f vector;
|
||||
Birb::Vector3f vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
CHECK(vector.z == 0);
|
||||
|
@ -83,17 +83,17 @@ TEST_CASE("Default Vector3f")
|
|||
|
||||
TEST_CASE("Vector3f with arguments")
|
||||
{
|
||||
CHECK(Vector3f(1, 4, 2).x == 1);
|
||||
CHECK(Vector3f(1, 4, 2).y == 4);
|
||||
CHECK(Vector3f(1, 4, 2).z == 2);
|
||||
CHECK(Vector3f(1.53f, 5.21f, 2.45f).x == 1.53f);
|
||||
CHECK(Vector3f(1.53f, 5.21f, 2.45f).y == 5.21f);
|
||||
CHECK(Vector3f(1.53f, 5.21f, 2.45f).z == 2.45f);
|
||||
CHECK(Birb::Vector3f(1, 4, 2).x == 1);
|
||||
CHECK(Birb::Vector3f(1, 4, 2).y == 4);
|
||||
CHECK(Birb::Vector3f(1, 4, 2).z == 2);
|
||||
CHECK(Birb::Vector3f(1.53f, 5.21f, 2.45f).x == 1.53f);
|
||||
CHECK(Birb::Vector3f(1.53f, 5.21f, 2.45f).y == 5.21f);
|
||||
CHECK(Birb::Vector3f(1.53f, 5.21f, 2.45f).z == 2.45f);
|
||||
}
|
||||
|
||||
TEST_CASE("Default Vector3int")
|
||||
{
|
||||
Vector3int vector;
|
||||
Birb::Vector3int vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
CHECK(vector.z == 0);
|
||||
|
@ -101,17 +101,17 @@ TEST_CASE("Default Vector3int")
|
|||
|
||||
TEST_CASE("Vector3int with arguments")
|
||||
{
|
||||
CHECK(Vector3int(1, 4, 2).x == 1);
|
||||
CHECK(Vector3int(1, 4, 2).y == 4);
|
||||
CHECK(Vector3int(1, 4, 2).z == 2);
|
||||
CHECK(Vector3int(1.53f, 5.21f, 2.45f).x == 2);
|
||||
CHECK(Vector3int(1.53f, 5.21f, 2.45f).y == 5);
|
||||
CHECK(Vector3int(1.53f, 5.21f, 2.45f).z == 2);
|
||||
CHECK(Birb::Vector3int(1, 4, 2).x == 1);
|
||||
CHECK(Birb::Vector3int(1, 4, 2).y == 4);
|
||||
CHECK(Birb::Vector3int(1, 4, 2).z == 2);
|
||||
CHECK(Birb::Vector3int(1.53f, 5.21f, 2.45f).x == 2);
|
||||
CHECK(Birb::Vector3int(1.53f, 5.21f, 2.45f).y == 5);
|
||||
CHECK(Birb::Vector3int(1.53f, 5.21f, 2.45f).z == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Default Rect")
|
||||
{
|
||||
Rect defaultRect;
|
||||
Birb::Rect defaultRect;
|
||||
CHECK(defaultRect.x == 0);
|
||||
CHECK(defaultRect.y == 0);
|
||||
CHECK(defaultRect.w == 0);
|
||||
|
@ -121,7 +121,7 @@ TEST_CASE("Default Rect")
|
|||
|
||||
TEST_CASE("Rect with arguments")
|
||||
{
|
||||
Rect customRect(10.54, 20, 30.234, 40.6668);
|
||||
Birb::Rect customRect(10.54, 20, 30.234, 40.6668);
|
||||
CHECK(customRect.x == 10.54f);
|
||||
CHECK(customRect.y == 20);
|
||||
CHECK(customRect.w == 30.234f);
|
||||
|
@ -130,8 +130,8 @@ TEST_CASE("Rect with arguments")
|
|||
|
||||
TEST_CASE("Rect with rounded values (integer)")
|
||||
{
|
||||
Rect customRect(10.54, 20, 30.234, 40.6668);
|
||||
Rect roundedRect = customRect.getInt();
|
||||
Birb::Rect customRect(10.54, 20, 30.234, 40.6668);
|
||||
Birb::Rect roundedRect = customRect.getInt();
|
||||
|
||||
CHECK(roundedRect.x == 11);
|
||||
CHECK(roundedRect.y == 20);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "Timer.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
void Timer::Start()
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "Utils.hpp"
|
||||
#include "Values.hpp"
|
||||
|
||||
namespace Birb2D
|
||||
namespace Birb
|
||||
{
|
||||
void TimeStep::Init()
|
||||
{
|
||||
|
|
|
@ -1,40 +1,43 @@
|
|||
#include "Utils.hpp"
|
||||
|
||||
Rect::Rect()
|
||||
:x(0.0f), y(0.0f), w(0.0f), h(0.0f)
|
||||
{}
|
||||
|
||||
Rect::Rect(float p_x, float p_y, float p_w, float p_h)
|
||||
:x(p_x), y(p_y), w(p_w), h(p_h)
|
||||
{}
|
||||
|
||||
Rect Rect::getInt()
|
||||
namespace Birb
|
||||
{
|
||||
Rect roundedRect;
|
||||
roundedRect.x = round(x);
|
||||
roundedRect.y = round(y);
|
||||
roundedRect.w = round(w);
|
||||
roundedRect.h = round(h);
|
||||
Rect::Rect()
|
||||
:x(0.0f), y(0.0f), w(0.0f), h(0.0f)
|
||||
{}
|
||||
|
||||
return roundedRect;
|
||||
Rect::Rect(float p_x, float p_y, float p_w, float p_h)
|
||||
:x(p_x), y(p_y), w(p_w), h(p_h)
|
||||
{}
|
||||
|
||||
Rect Rect::getInt()
|
||||
{
|
||||
Rect roundedRect;
|
||||
roundedRect.x = round(x);
|
||||
roundedRect.y = round(y);
|
||||
roundedRect.w = round(w);
|
||||
roundedRect.h = round(h);
|
||||
|
||||
return roundedRect;
|
||||
}
|
||||
|
||||
SDL_Rect Rect::getSDLRect()
|
||||
{
|
||||
SDL_Rect sdlrect;
|
||||
sdlrect.h = h;
|
||||
sdlrect.w = w;
|
||||
sdlrect.x = x;
|
||||
sdlrect.y = y;
|
||||
return sdlrect;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Rect Rect::getSDLRect()
|
||||
{
|
||||
SDL_Rect sdlrect;
|
||||
sdlrect.h = h;
|
||||
sdlrect.w = w;
|
||||
sdlrect.x = x;
|
||||
sdlrect.y = y;
|
||||
return sdlrect;
|
||||
}
|
||||
|
||||
Birb2D::Texture::Texture()
|
||||
{
|
||||
sdlTexture = NULL;
|
||||
dimensions = Vector2int(-1, -1);
|
||||
}
|
||||
|
||||
Birb2D::Texture::Texture(SDL_Texture* p_sdlTexture, Vector2int p_dimensions)
|
||||
:sdlTexture(p_sdlTexture), dimensions(p_dimensions)
|
||||
{}
|
||||
//Birb2D::Texture::Texture()
|
||||
//{
|
||||
// sdlTexture = NULL;
|
||||
// dimensions = Vector2int(-1, -1);
|
||||
//}
|
||||
//
|
||||
//Birb2D::Texture::Texture(SDL_Texture* p_sdlTexture, Vector2int p_dimensions)
|
||||
//:sdlTexture(p_sdlTexture), dimensions(p_dimensions)
|
||||
//{}
|
||||
|
|
|
@ -1,55 +1,61 @@
|
|||
#include <math.h>
|
||||
#include "Values.hpp"
|
||||
|
||||
/* Dims or lightens color */
|
||||
SDL_Color Colors::ChangeColorIntensity(SDL_Color color, int delta)
|
||||
namespace Birb
|
||||
{
|
||||
SDL_Color newColor = color;
|
||||
|
||||
if (delta > 0)
|
||||
/* Dims or lightens color */
|
||||
namespace Colors
|
||||
{
|
||||
// Increase color intensity
|
||||
SDL_Color ChangeColorIntensity(SDL_Color color, int delta)
|
||||
{
|
||||
SDL_Color newColor = color;
|
||||
|
||||
// Red
|
||||
if (newColor.r + delta > 255)
|
||||
newColor.r = 255;
|
||||
else
|
||||
newColor.r += delta;
|
||||
if (delta > 0)
|
||||
{
|
||||
// Increase color intensity
|
||||
|
||||
// Green
|
||||
if (newColor.g + delta > 255)
|
||||
newColor.g = 255;
|
||||
else
|
||||
newColor.g += delta;
|
||||
// Red
|
||||
if (newColor.r + delta > 255)
|
||||
newColor.r = 255;
|
||||
else
|
||||
newColor.r += delta;
|
||||
|
||||
// Blue
|
||||
if (newColor.b + delta > 255)
|
||||
newColor.b = 255;
|
||||
else
|
||||
newColor.b += delta;
|
||||
// Green
|
||||
if (newColor.g + delta > 255)
|
||||
newColor.g = 255;
|
||||
else
|
||||
newColor.g += delta;
|
||||
|
||||
// Blue
|
||||
if (newColor.b + delta > 255)
|
||||
newColor.b = 255;
|
||||
else
|
||||
newColor.b += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decrease color intensity
|
||||
|
||||
// Red
|
||||
if (newColor.r + delta < 0)
|
||||
newColor.r = 0;
|
||||
else
|
||||
newColor.r += delta;
|
||||
|
||||
// Green
|
||||
if (newColor.g + delta < 0)
|
||||
newColor.g = 0;
|
||||
else
|
||||
newColor.g += delta;
|
||||
|
||||
// Blue
|
||||
if (newColor.b + delta < 0)
|
||||
newColor.b = 0;
|
||||
else
|
||||
newColor.b += delta;
|
||||
}
|
||||
|
||||
return newColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decrease color intensity
|
||||
|
||||
// Red
|
||||
if (newColor.r + delta < 0)
|
||||
newColor.r = 0;
|
||||
else
|
||||
newColor.r += delta;
|
||||
|
||||
// Green
|
||||
if (newColor.g + delta < 0)
|
||||
newColor.g = 0;
|
||||
else
|
||||
newColor.g += delta;
|
||||
|
||||
// Blue
|
||||
if (newColor.b + delta < 0)
|
||||
newColor.b = 0;
|
||||
else
|
||||
newColor.b += delta;
|
||||
}
|
||||
|
||||
return newColor;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue