Added AsloEngine 0.9.0 to Repository
This commit is contained in:
parent
d017dd84b3
commit
881e6c70f2
60 changed files with 2648 additions and 0 deletions
163
asloengine/headers/aslosignals.hpp
Executable file
163
asloengine/headers/aslosignals.hpp
Executable file
|
|
@ -0,0 +1,163 @@
|
|||
//AsloSignals v1.0.0
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace aslosignals
|
||||
{
|
||||
|
||||
class SlotBase
|
||||
{
|
||||
|
||||
public:
|
||||
virtual void emit() {}
|
||||
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
class Slot : public SlotBase
|
||||
{
|
||||
|
||||
public:
|
||||
void emit() override
|
||||
{
|
||||
std::apply(slot, parameters);
|
||||
}
|
||||
std::function<void (Args...)> slot;
|
||||
std::tuple<Args...> parameters;
|
||||
|
||||
};
|
||||
|
||||
class Signal
|
||||
{
|
||||
|
||||
public:
|
||||
std::vector<SlotBase *> slots;
|
||||
|
||||
// Connect Member Method
|
||||
template <typename T, typename ...Args>
|
||||
int connect_member(T *instance, void (T::*slot)(Args...), Args... parameters)
|
||||
{
|
||||
|
||||
return bind((std::function<void (Args...)>)([=](Args...) { (instance->*slot)(parameters...); }));
|
||||
|
||||
}
|
||||
|
||||
// Connect Const Member Method
|
||||
template <typename T, typename ...Args>
|
||||
int connect_member(T *instance, void (T::*slot)(Args...) const, Args... parameters)
|
||||
{
|
||||
|
||||
return bind((std::function<void (Args...)>)([=](Args...) { (instance->*slot)(parameters...); }));
|
||||
|
||||
}
|
||||
|
||||
// Connect Function
|
||||
template <typename ...Args>
|
||||
int connect(void (*slot)(Args...), Args... parameters)
|
||||
{
|
||||
|
||||
return bind((std::function<void (Args...)>)([=](Args...) { (*slot)(parameters...); }));
|
||||
|
||||
}
|
||||
|
||||
void disconnect(int index)
|
||||
{
|
||||
|
||||
slots.erase(slots.begin() + index);
|
||||
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
|
||||
slots.clear();
|
||||
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
|
||||
for (SlotBase *& slot : slots)
|
||||
{
|
||||
slot->emit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename ...Args>
|
||||
int bind(std::function<void (Args...)> slot)
|
||||
{
|
||||
|
||||
Slot<Args...> *_slot = new Slot<Args...>();
|
||||
_slot->slot = slot;
|
||||
slots.emplace_back(_slot);
|
||||
return slots.size() - 1;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
class TypeSignal
|
||||
{
|
||||
|
||||
public:
|
||||
std::vector<std::function<void (Args...)>> slots;
|
||||
|
||||
// Connect Member Method
|
||||
template <typename T>
|
||||
int connect_member(T *instance, void (T::*slot)(Args...))
|
||||
{
|
||||
|
||||
return connect([=](Args... args) { (instance->*slot)(args...); });
|
||||
|
||||
}
|
||||
|
||||
// Connect Const Member Method
|
||||
template <typename T>
|
||||
int connect_member(T *instance, void (T::*slot)(Args...) const)
|
||||
{
|
||||
|
||||
return connect([=](Args... args) { (instance->*slot)(args...); });
|
||||
|
||||
}
|
||||
|
||||
// Connect Function
|
||||
int connect(std::function<void (Args...)> slot)
|
||||
{
|
||||
|
||||
slots.emplace_back(slot);
|
||||
return slots.size() - 1;
|
||||
|
||||
}
|
||||
|
||||
void disconnect(int index)
|
||||
{
|
||||
|
||||
slots.erase(slots.begin() + index);
|
||||
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
|
||||
slots.clear();
|
||||
|
||||
}
|
||||
|
||||
void operator()(Args... args)
|
||||
{
|
||||
|
||||
for (std::function<void (Args...)>& slot : slots)
|
||||
{
|
||||
slot(args...);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
39
asloengine/headers/clickable.hpp
Executable file
39
asloengine/headers/clickable.hpp
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class Clickable
|
||||
{
|
||||
|
||||
public:
|
||||
enum ClickAction
|
||||
{
|
||||
Nothing, Pressed, Released
|
||||
};
|
||||
|
||||
sf::Mouse::Button click_button;
|
||||
|
||||
Clickable(sf::Mouse::Button _click_button);
|
||||
virtual ~Clickable();
|
||||
|
||||
void set_clickable(sf::FloatRect rect, sf::RenderWindow *window);
|
||||
void update_clickable(sf::FloatRect rect);
|
||||
bool is_mouse_in() const;
|
||||
ClickAction get_click_action() const;
|
||||
bool clicked_press() const;
|
||||
bool clicked_release() const;
|
||||
bool clicked_press_and_release() const;
|
||||
|
||||
private:
|
||||
sf::FloatRect clickable_rect;
|
||||
sf::RenderWindow *clickable_window;
|
||||
mutable bool pressed = false;
|
||||
mutable bool clicking = false;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
14
asloengine/headers/core.hpp
Executable file
14
asloengine/headers/core.hpp
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "scenemanager.hpp"
|
||||
#include "keyboard.hpp"
|
||||
#include "mouse.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
void init(Scene *starting_scene);
|
||||
void start_main_game_loop();
|
||||
|
||||
}
|
||||
14
asloengine/headers/define.hpp
Normal file
14
asloengine/headers/define.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#define PROGRAM_NAME "Space Strategy"
|
||||
#define PROGRAM_VERSION "0.1.0"
|
||||
#define PROGRAM_INFO (std::string)PROGRAM_NAME + " v" + PROGRAM_VERSION
|
||||
#define PROGRAM_BUILD 0
|
||||
#define PROGRAM_CREATOR "Aslan2142"
|
||||
#define COPYRIGHT "Copyright 2019"
|
||||
#define RESOLUTION_X 1920
|
||||
#define RESOLUTION_Y 1080
|
||||
#define BIT_DEPTH 24
|
||||
#define MAX_FRAMERATE 60
|
||||
#define VSYNC_ENABLED true
|
||||
#define DEBUG
|
||||
76
asloengine/headers/gameobject.hpp
Executable file
76
asloengine/headers/gameobject.hpp
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <memory>
|
||||
#include "aslosignals.hpp"
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class GameObject
|
||||
{
|
||||
|
||||
public:
|
||||
sf::RenderWindow *render_window;
|
||||
sf::String name = "nonameobject";
|
||||
bool alive = true;
|
||||
|
||||
GameObject(sf::String _name);
|
||||
virtual ~GameObject();
|
||||
|
||||
virtual void start(sf::RenderWindow *window);
|
||||
virtual void update(float delta_time);
|
||||
virtual void destroy();
|
||||
|
||||
static sf::Vector2f calculate_child_position(sf::Vector2f& offset, sf::Vector2f& scale, float rotation);
|
||||
static sf::Vector2f calculate_child_position_centered(
|
||||
sf::FloatRect& parent_rect, sf::FloatRect& child_rect, sf::Vector2f& offset, sf::Vector2f& scale, float rotation
|
||||
);
|
||||
|
||||
virtual sf::View set_crop(sf::Vector2f _position, sf::Vector2f _size);
|
||||
virtual sf::View set_crop(float _left, float _top, float _width, float _height);
|
||||
|
||||
// Main Property Getters and Setters
|
||||
virtual void set_position(sf::Vector2f& _position);
|
||||
virtual void set_scale(sf::Vector2f& _scale);
|
||||
virtual void set_origin(sf::Vector2f& _origin);
|
||||
virtual void set_rotation(float _rotation);
|
||||
|
||||
virtual void set_position(float _position_x, float _position_y);
|
||||
virtual void set_scale(float _scale_x, float _scale_y);
|
||||
virtual void set_origin(float _origin_x, float _origin_y);
|
||||
|
||||
virtual sf::Vector2f get_position() const;
|
||||
virtual sf::Vector2f get_scale() const;
|
||||
virtual sf::Vector2f get_origin() const;
|
||||
virtual float get_rotation() const;
|
||||
|
||||
// Main Property Modifiers
|
||||
virtual void move(sf::Vector2f& _move);
|
||||
virtual void rescale(sf::Vector2f& _rescale);
|
||||
virtual void translate_origin(sf::Vector2f& _translate_origin);
|
||||
virtual void rotate(float _rotate);
|
||||
|
||||
virtual void move(float _move_x, float _move_y);
|
||||
virtual void rescale(float _rescale_x, float _rescale_y);
|
||||
virtual void translate_origin(float _translate_origin_x, float _translate_origin_y);
|
||||
|
||||
// Custom Derived Implementations
|
||||
virtual void draw();
|
||||
virtual void on_main_property_update();
|
||||
virtual void on_start();
|
||||
virtual void on_update(float delta_time);
|
||||
virtual void on_post_update(float delta_time);
|
||||
virtual void on_destroy();
|
||||
|
||||
protected:
|
||||
bool main_property_changed = false;
|
||||
sf::Vector2f position;
|
||||
sf::Vector2f scale;
|
||||
sf::Vector2f origin;
|
||||
float rotation;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
83
asloengine/headers/helpers.hpp
Executable file
83
asloengine/headers/helpers.hpp
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "define.hpp"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOG(message) asloengine::log((std::string)"LOG: ", message)
|
||||
#define WARN(message) asloengine::log((std::string)"WARNING: ", message)
|
||||
#define ERR(message) asloengine::log((std::string)"ERROR: ", message)
|
||||
#else
|
||||
#define LOG(message)
|
||||
#define WARN(message)
|
||||
#define ERR(message)
|
||||
#endif
|
||||
|
||||
#define DEG_TO_RAD 0.01745
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
void log(const std::string& prefix, const bool condition);
|
||||
void log(const std::string& prefix, const int number);
|
||||
void log(const std::string& prefix, const double number);
|
||||
void log(const std::string& prefix, const char* message);
|
||||
void log(const std::string& prefix, const std::string& message);
|
||||
|
||||
sf::Vector2f operator+(sf::Vector2f _vec, float add);
|
||||
sf::Vector2f operator-(sf::Vector2f _vec, float subtract);
|
||||
sf::Vector2f operator*(sf::Vector2f _vec, float multiplier);
|
||||
sf::Vector2f operator/(sf::Vector2f _vec, float divider);
|
||||
|
||||
sf::Vector2f operator+(sf::Vector2f _vec_1, sf::Vector2f _vec_2);
|
||||
sf::Vector2f operator-(sf::Vector2f _vec_1, sf::Vector2f _vec_2);
|
||||
sf::Vector2f operator*(sf::Vector2f _vec_1, sf::Vector2f _vec_2);
|
||||
sf::Vector2f operator/(sf::Vector2f _vec_1, sf::Vector2f _vec_2);
|
||||
|
||||
sf::Vector2f operator+(sf::Vector2f _vec, sf::FloatRect _rect);
|
||||
sf::Vector2f operator-(sf::Vector2f _vec, sf::FloatRect _rect);
|
||||
sf::Vector2f operator*(sf::Vector2f _vec, sf::FloatRect _rect);
|
||||
sf::Vector2f operator/(sf::Vector2f _vec, sf::FloatRect _rect);
|
||||
|
||||
float clamp(float value, float min, float max);
|
||||
|
||||
sf::Vector2i to_vector2i(sf::Vector2u _vec);
|
||||
sf::Vector2i to_vector2i(sf::Vector2f _vec);
|
||||
sf::Vector2u to_vector2u(sf::Vector2i _vec);
|
||||
sf::Vector2u to_vector2u(sf::Vector2f _vec);
|
||||
sf::Vector2f to_vector2f(sf::Vector2i _vec);
|
||||
sf::Vector2f to_vector2f(sf::Vector2u _vec);
|
||||
|
||||
template <typename T>
|
||||
T calculate_average(T *array, size_t size)
|
||||
{
|
||||
|
||||
T sum;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
sum += array[i];
|
||||
}
|
||||
|
||||
return (sum / (T)size);
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int vector_contains(std::vector<T>& vec, T element)
|
||||
{
|
||||
|
||||
for(int i = 0; i < vec.size(); i++)
|
||||
{
|
||||
if (vec[i] == element)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
16
asloengine/headers/keyboard.hpp
Executable file
16
asloengine/headers/keyboard.hpp
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class Keyboard
|
||||
{
|
||||
|
||||
public:
|
||||
static sf::Uint32 entered_text;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
16
asloengine/headers/mouse.hpp
Executable file
16
asloengine/headers/mouse.hpp
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class Mouse
|
||||
{
|
||||
|
||||
public:
|
||||
static float mouse_wheel_delta;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
41
asloengine/headers/scene.hpp
Executable file
41
asloengine/headers/scene.hpp
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "gameobject.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
typedef std::vector<GameObject *> Layer;
|
||||
|
||||
class Scene
|
||||
{
|
||||
|
||||
public:
|
||||
std::string name = "nonamescene";
|
||||
sf::RenderWindow *scene_window;
|
||||
std::vector<Layer> layers;
|
||||
std::vector<Layer> fixed_layers;
|
||||
sf::FloatRect camera_2d_rect;
|
||||
bool needs_clean = false;
|
||||
|
||||
Scene(std::string _name);
|
||||
|
||||
void draw();
|
||||
void load();
|
||||
void start(sf::RenderWindow *window);
|
||||
void update(float delta_time);
|
||||
void clean();
|
||||
void destroy();
|
||||
|
||||
void move_camera(sf::Vector2f _move);
|
||||
|
||||
// Custom Derived Implementations
|
||||
virtual void on_load();
|
||||
virtual void on_update(float delta_time);
|
||||
virtual void on_post_update(float delta_time);
|
||||
virtual void on_destroy();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
24
asloengine/headers/scenemanager.hpp
Executable file
24
asloengine/headers/scenemanager.hpp
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#define SCENE_MANAGER_H
|
||||
|
||||
#include "scene.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class SceneManager
|
||||
{
|
||||
|
||||
public:
|
||||
static Scene *scene;
|
||||
static Scene *next_scene;
|
||||
|
||||
static void load_scene(Scene *_scene);
|
||||
static void load_scene(Scene *_scene, sf::RenderWindow *window);
|
||||
static void set_scene(Scene *_scene);
|
||||
static void unload_scene();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
25
asloengine/headers/spriteobject.hpp
Executable file
25
asloengine/headers/spriteobject.hpp
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "gameobject.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class SpriteObject : public virtual GameObject
|
||||
{
|
||||
|
||||
public:
|
||||
SpriteObject(std::string _name);
|
||||
SpriteObject(std::string _name, sf::Texture& _texture);
|
||||
virtual ~SpriteObject() override;
|
||||
|
||||
void load_texture(sf::Texture& _texture);
|
||||
virtual void draw() override;
|
||||
virtual void on_main_property_update() override;
|
||||
|
||||
protected:
|
||||
sf::Sprite sprite;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
30
asloengine/headers/textobject.hpp
Executable file
30
asloengine/headers/textobject.hpp
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include "gameobject.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class TextObject : public virtual GameObject
|
||||
{
|
||||
|
||||
public:
|
||||
std::shared_ptr<sf::Text> text;
|
||||
|
||||
TextObject(std::string _name, sf::String _text, sf::Font& _font, uint _text_size = 30);
|
||||
virtual ~TextObject() override;
|
||||
|
||||
void load_font(sf::Font& _font);
|
||||
virtual void draw() override;
|
||||
virtual void on_main_property_update() override;
|
||||
|
||||
// Getters and Setters
|
||||
virtual void set_text(sf::String _text);
|
||||
virtual void set_text_size(uint _text_size);
|
||||
virtual sf::String get_text() const;
|
||||
virtual uint get_text_size() const;
|
||||
virtual int get_text_length() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue