diff --git a/include/square.hpp b/include/board.hpp
similarity index 60%
rename from include/square.hpp
rename to include/board.hpp
index d4744ed..99266c0 100644
--- a/include/square.hpp
+++ b/include/board.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of our_dick
- Copyright (C) 2020 rexy712
+ Copyright (C) 2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@@ -16,19 +16,25 @@
along with this program. If not, see .
*/
-#ifndef OUR_DICK_SQUARE_HPP
-#define OUR_DICK_SQUARE_HPP
+#ifndef OUR_DICK_BOARD_HPP
+#define OUR_DICK_BOARD_HPP
#include "graphics/mesh.hpp"
#include "graphics/model.hpp"
-#include "graphics/material.hpp"
#include "graphics/shader_program.hpp"
-#include "renderable.hpp"
+#include "graphics/material.hpp"
+
#include "engine/object.hpp"
+#include "renderable.hpp"
+#include "engine/resource_manager.hpp"
+#include "math/vec.hpp"
+#include "config.hpp"
+
+#include //unique_ptr
gfx::unified_mesh square_mesh(const gfx::material& blank, const gfx::material& o, const gfx::material& x);
-class square : public renderable_iface , public egn::object_base
+class tile : public renderable_iface, public egn::object_base
{
public:
enum class value{
@@ -43,7 +49,7 @@ private:
math::vec4 m_color_filter = {};
public:
- square(gfx::model* model);
+ tile(gfx::model* model);
void set_value(value v);
value get_value()const;
@@ -52,6 +58,32 @@ public:
void render(gfx::shader_program&)override;
+
+};
+class board : public renderable_iface, public egn::object_base
+{
+private:
+ std::unique_ptr m_tiles;
+public:
+ board(egn::resource_manager& r);
+ ~board(void) = default;
+
+ tile::value check_winner(void)const;
+
+ bool is_full(void)const;
+
+ void render(gfx::shader_program& shader);
+
+ int click_collision_cheat(const math::vec3&)const;
+
+ void set_tile(int index, tile::value value);
+ tile::value get_tile(int index)const;
+
+private:
+ tile::value check_rows_(void)const;
+ tile::value check_columns_(void)const;
+ tile::value check_diagonals_(void)const;
};
+
#endif
diff --git a/include/engine/game.hpp b/include/engine/game.hpp
index 2c0d7fb..6a89c05 100644
--- a/include/engine/game.hpp
+++ b/include/engine/game.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of our_dick
- Copyright (C) 2020 rexy712
+ Copyright (C) 2020-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@@ -22,6 +22,7 @@
#include "observable.hpp"
#include "game_state.hpp"
#include "graphics/window.hpp"
+#include "resource_manager.hpp"
#include "input.hpp"
#include
@@ -33,6 +34,7 @@ namespace egn{
protected:
gfx::window m_window;
game_state_manager m_states_manager;
+ resource_manager m_res_manager;
std::queue m_event_queue;
double m_last_time;
@@ -48,6 +50,12 @@ namespace egn{
void on_notify(const game_state_event& e)override;
+ resource_manager& resource_man(void);
+ const resource_manager& resource_man(void)const;
+
+ void push_state(std::unique_ptr&&);
+ void pop_state(void);
+
private:
void setup_window_();
};
diff --git a/include/engine/game_state.hpp b/include/engine/game_state.hpp
index 7392930..fb8f1f6 100644
--- a/include/engine/game_state.hpp
+++ b/include/engine/game_state.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of our_dick
- Copyright (C) 2020 rexy712
+ Copyright (C) 2020-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@@ -28,6 +28,8 @@
namespace egn{
+ class game;
+
struct game_state_event {
enum class state_type{
SHOULD_CLOSE,
@@ -59,10 +61,10 @@ namespace egn{
class game_state_iface
{
protected:
- game_state_manager* m_owner = nullptr;
+ game* m_owner = nullptr;
protected:
- game_state_iface(game_state_manager* owner);
+ game_state_iface(game* owner);
game_state_iface(const game_state_iface& g) = default;
game_state_iface(game_state_iface&& g) = default;
diff --git a/include/graphics/image.hpp b/include/engine/image.hpp
similarity index 65%
rename from include/graphics/image.hpp
rename to include/engine/image.hpp
index 07c885c..002c744 100644
--- a/include/graphics/image.hpp
+++ b/include/engine/image.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of our_dick
- Copyright (C) 2020 rexy712
+ Copyright (C) 2020-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@@ -16,10 +16,12 @@
along with this program. If not, see .
*/
-#ifndef OUR_DICK_GRAPHICS_IMAGE_HPP
-#define OUR_DICK_GRAPHICS_IMAGE_HPP
+#ifndef OUR_DICK_ENGINE_IMAGE_HPP
+#define OUR_DICK_ENGINE_IMAGE_HPP
-namespace gfx{
+#include
+
+namespace egn{
//class handling image loading from files
class image
@@ -52,6 +54,27 @@ namespace gfx{
unsigned char* data();
};
+ class deferred_image
+ {
+ private:
+ std::string m_filename;
+ bool m_flip = false;
+ int m_req_chan = 0;
+ public:
+ deferred_image(const char* file, bool flip = false, int req_chan = 0);
+ deferred_image(const std::string& file, bool flip = false, int req_chan = 0);
+ deferred_image(const deferred_image&) = default;
+ deferred_image(deferred_image&&) = default;
+
+ ~deferred_image(void) = default;
+
+ deferred_image& operator=(const deferred_image&) = default;
+ deferred_image& operator=(deferred_image&&) = default;
+
+ operator image(void)const;
+ image get_image(void)const;
+ };
+
}
#endif
diff --git a/include/engine/resource_manager.hpp b/include/engine/resource_manager.hpp
new file mode 100644
index 0000000..2346175
--- /dev/null
+++ b/include/engine/resource_manager.hpp
@@ -0,0 +1,78 @@
+/**
+ This file is a part of our_dick
+ Copyright (C) 2021 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+#ifndef OUR_DICK_ENGINE_RESOURCE_MANAGER_HPP
+#define OUR_DICK_ENGINE_RESOURCE_MANAGER_HPP
+
+#include "engine/image.hpp"
+#include "graphics/material.hpp"
+#include "graphics/model.hpp"
+
+#include