Move multipurpose files over to rexylib so I can reuse them in other codebases

This commit is contained in:
rexy712 2022-02-23 17:01:31 -08:00
parent 8a0947e750
commit 96b409adc2
29 changed files with 101 additions and 530 deletions

View File

@ -21,8 +21,6 @@
//multiple levels just so i can stop alsa errors without stopping everything else
#define OUR_DICK_ENABLE_COLOR_DEBUG
#ifdef OUR_DICK_DEBUG
#define OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL OUR_DICK_DEBUG
@ -33,76 +31,9 @@
#define OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL 0
#endif
//Debug output section
#if OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL > 0
#define OUR_DICK_ENABLE_DEBUG_OUTPUT
#endif
#if OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL > 2
#define OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT
#endif
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
#define OUR_DICK_DEBUG_NULL_STATEMENT do{;}while(0)
#include <cstdio>
#include "util/source_location.hpp"
#define debug_print_impl(location, ...) do{ auto loc = location; std::fprintf(stderr, "%s:%s:%d: ", loc.file_name(), loc.function_name(), loc.line()); std::fprintf(stderr, __VA_ARGS__); }while(0)
#define debug_print(...) debug_print_impl(util::source_location::current(), __VA_ARGS__)
#ifdef OUR_DICK_ENABLE_COLOR_DEBUG
#define OUR_DICK_DEBUG_PRINT_RED "\033[38;5;9m"
#define OUR_DICK_DEBUG_PRINT_YELLOW "\033[38;5;11m"
#define OUR_DICK_DEBUG_PRINT_GREEN "\033[38;5;2m"
#define OUR_DICK_DEBUG_PRINT_BLUE "\033[38;5;12m"
#define OUR_DICK_DEBUG_PRINT_CLEAR "\033[0m"
#define debug_print_color_base(color, ...) do{ std::fprintf(stderr, color); debug_print(__VA_ARGS__); std::fprintf(stderr, OUR_DICK_DEBUG_PRINT_CLEAR); }while(0)
#define debug_print_warn(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_YELLOW, __VA_ARGS__)
#define debug_print_error(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_RED, __VA_ARGS__)
#define debug_print_succ(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_GREEN, __VA_ARGS__)
#define debug_print_info(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_BLUE, __VA_ARGS__)
#else
#define debug_print_error(...) debug_print(__VA_ARGS__)
#define debug_print_warn(...) debug_print(__VA_ARGS__)
#define debug_print_succ(...) debug_print(__VA_ARGS__)
#define debug_print_info(...) debug_print(__VA_ARGS__)
#endif
#ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT
#define debug_print_verbose(...) debug_print(__VA_ARGS__)
#define debug_print_verbose_warn(...) debug_print_warn(__VA_ARGS__)
#define debug_print_verbose_error(...) debug_print_error(__VA_ARGS__)
#define debug_print_verbose_succ(...) debug_print_succ(__VA_ARGS__)
#define debug_print_verbose_info(...) debug_print_info(__VA_ARGS__)
#else
#define debug_print_verbose(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_warn(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_error(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_succ(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_info(...) OUR_DICK_DEBUG_NULL_STATEMENT
#endif
#else
#define debug_print(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_error(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_warn(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_succ(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_info(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_warn(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_error(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_succ(...) OUR_DICK_DEBUG_NULL_STATEMENT
#define debug_print_verbose_info(...) OUR_DICK_DEBUG_NULL_STATEMENT
#endif
#ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT
#include <typeinfo>
#endif
#include "util/demangle.hpp"
#define REXY_ENABLE_DEBUG_LEVEL OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL
#define REXY_ENABLE_COLOR_DEBUG 1
#include <rexy/debug_print.hpp>
#endif

View File

@ -117,7 +117,7 @@ namespace egn{
}
template<class... Ts>
font_atlas font::generate_atlas(size_t glyph_w, size_t glyph_h, Ts&&... ranges){
debug_print_verbose("Generating font atlas for font '%s'\n", m_face->family_name);
rexy::debug::verbose::print("Generating font atlas for font '%s'\n", m_face->family_name);
FT_Set_Pixel_Sizes(m_face, glyph_w, glyph_h);
auto [atlas_width, atlas_height, max_glyph_width, max_glyph_height] = get_atlas_size_ranges_(std::forward<Ts>(ranges)...);
const auto format = (m_depth == 3) ? GL_RGB : GL_RED;

View File

@ -1,30 +0,0 @@
/**
This file is a part of our_dick
Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_GRAPHICS_LIGHT_HPP
#define OUR_DICK_GRAPHICS_LIGHT_HPP
#include "lightable.hpp"
namespace gfx{
class light : public lightable{};
}
#endif

View File

@ -109,14 +109,14 @@ namespace gfx::ogl{
template<class... Types>
void ubo<Types...>::buffer(const void* data, size_t datasize, size_t start){
debug_print_warn("Manually editing values of ubo!\n");
rexy::debug::print_warn("Manually editing values of ubo!\n");
if(start > get_size())
return;
glNamedBufferSubData(m_buffer, start, std::min(datasize, get_size() - start), data);
}
template<class... Types>
void ubo<Types...>::initialize(unsigned char value){
debug_print_warn("Manually editing values of ubo!\n");
rexy::debug::print_warn("Manually editing values of ubo!\n");
const size_t size = get_size();
auto m = map(buffer::maptype::WRITE);
if(!m){

View File

@ -25,7 +25,7 @@
#include <tuple>
#include <memory> //shared_ptr
#include "util/deferred.hpp"
#include <rexy/deferred.hpp>
#include "config.hpp"
@ -78,14 +78,14 @@ namespace gfx{
//must enable rtti for typeid() which is disabled by default in the makefile
//add -frtti in the DEBUG_CXXFLAGS variable
if(node n = get_value(key);!n){
debug_print_verbose("Constructing new %s in container\n", ::util::demangle(typeid(T).name()).c_str());
auto p = m_map.emplace(key, util::deferred_function(std::make_shared<T,Args&&...>, std::forward<Args>(args)...));
rexy::debug::verbose::print("Constructing new %s in container\n", ::util::demangle(typeid(T).name()).c_str());
auto p = m_map.emplace(key, rexy::deferred_function(std::make_shared<T,Args&&...>, std::forward<Args>(args)...));
return {(*p.first).second, p.second};
}else{
return {n, false};
}
#else
auto p = m_map.try_emplace(key, util::deferred_function(std::make_shared<T,Args&&...>, std::forward<Args>(args)...));
auto p = m_map.try_emplace(key, rexy::deferred_function(std::make_shared<T,Args&&...>, std::forward<Args>(args)...));
return {(*p.first).second, p.second};
#endif
}

View File

@ -1,131 +0,0 @@
/**
This file is a part of our_dick
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_UTIL_DEFERRED_HPP
#define OUR_DICK_UTIL_DEFERRED_HPP
#include <tuple>
#include <utility> //forward, index_sequence
namespace util{
template<class T, class... Args>
class deferred
{
public:
using value_type = T;
private:
std::tuple<Args&&...> m_args;
public:
template<class... FArgs>
constexpr deferred(FArgs&&... args);
deferred(const deferred&) = default;
deferred(deferred&&) = default;
~deferred(void) = default;
deferred& operator=(const deferred&) = default;
deferred& operator=(deferred&&) = default;
constexpr value_type value(void);
constexpr operator value_type(void);
private:
template<size_t... Is>
constexpr value_type get_value_(std::index_sequence<Is...>);
};
template<class Fn, class... Args>
class deferred_function
{
public:
using ret_t = decltype(std::declval<Fn>()(std::declval<Args>()...));
private:
Fn m_fn;
std::tuple<Args&&...> m_args;
public:
template<class F, class... FArgs>
constexpr deferred_function(F&& f, FArgs&&... args);
constexpr decltype(auto) operator()(void);
constexpr decltype(auto) value(void);
constexpr operator ret_t(void);
private:
template<size_t... Is>
constexpr decltype(auto) get_value_(std::index_sequence<Is...>);
};
template<class T, class... Args>
template<class... FArgs>
constexpr deferred<T,Args...>::deferred(FArgs&&... args):
m_args{std::forward<FArgs>(args)...}{}
template<class T, class... Args>
constexpr auto deferred<T,Args...>::value(void) -> value_type{
return get_value_(std::make_index_sequence<sizeof...(Args)>());
}
template<class T, class... Args>
constexpr deferred<T,Args...>::operator value_type(void){
return get_value_(std::make_index_sequence<sizeof...(Args)>());
}
template<class T, class... Args>
template<size_t... Is>
constexpr auto deferred<T,Args...>::get_value_(std::index_sequence<Is...>) -> value_type{
return T{std::forward<std::tuple_element_t<Is,decltype(m_args)>>(std::get<Is>(m_args))...};
}
template<class Fn, class... Args>
template<class F, class... FArgs>
constexpr deferred_function<Fn,Args...>::deferred_function(F&& f, FArgs&&... args):
m_fn(std::forward<F>(f)),
m_args{std::forward<FArgs>(args)...}{}
template<class Fn, class... Args>
constexpr decltype(auto) deferred_function<Fn,Args...>::operator()(void){
return get_value_(std::make_index_sequence<sizeof...(Args)>());
}
template<class Fn, class... Args>
constexpr decltype(auto) deferred_function<Fn,Args...>::value(void){
return get_value_(std::make_index_sequence<sizeof...(Args)>());
}
template<class Fn, class... Args>
constexpr deferred_function<Fn,Args...>::operator ret_t(void){
return get_value_(std::make_index_sequence<sizeof...(Args)>());
}
template<class Fn, class... Args>
template<size_t... Is>
constexpr decltype(auto) deferred_function<Fn,Args...>::get_value_(std::index_sequence<Is...>){
return std::forward<Fn>(m_fn)(std::forward<std::tuple_element_t<Is,decltype(m_args)>>(std::get<Is>(m_args))...);
}
template<class Fn, class... Args>
deferred_function(Fn&&, Args&&...) -> deferred_function<Fn&&, Args&&...>;
template<class T, class... Args>
deferred<T,Args...> make_deferred(Args&&... args){
return deferred<T,Args...>(std::forward<Args>(args)...);
}
}
#endif

View File

@ -1,29 +0,0 @@
/**
This file is a part of our_dick
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_UTIL_DEMANGLE_HPP
#define OUR_DICK_UTIL_DEMANGLE_HPP
#include <string>
namespace util{
std::string demangle(const char* name);
}
#endif

View File

@ -1,122 +0,0 @@
/**
This file is a part of our_dick
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_UTIL_SOURCE_LOCATION_HPP
#define OUR_DICK_UTIL_SOURCE_LOCATION_HPP
#include <version> //feature test macro
#ifndef __cpp_lib_source_location
#include <cstdint> //uint_least32_t
#if __cplusplus >= 202002L
#define CONSTEVAL consteval
#else
#define CONSTEVAL constexpr
#endif
namespace util{
class source_location
{
private:
const char* m_file;
const char* m_func;
uint_least32_t m_line;
uint_least32_t m_column;
public:
constexpr source_location(void)noexcept;
constexpr source_location(const source_location&);
constexpr source_location(source_location&&)noexcept;
constexpr uint_least32_t line(void)const noexcept;
constexpr uint_least32_t column(void)const noexcept;
constexpr const char* file_name(void)const noexcept;
constexpr const char* function_name(void)const noexcept;
public:
#if (defined(__clang__) && (__clang_major__ >= 9)) || (defined(_MSC_VER) && (_MSC_VER >= 1926))
static CONSTEVAL source_location current(uint_least32_t line = __builtin_LINE(),
uint_least32_t col = __builtin_COLUMN(),
const char* file = __builtin_FILE(),
const char* func = __builtin_FUNCTION())noexcept;
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
static CONSTEVAL source_location current(uint_least32_t line = __builtin_LINE(),
uint_least32_t col = 0,
const char* file = __builtin_FILE(),
const char* func = __builtin_FUNCTION())noexcept;
#else
static CONSTEVAL source_location current(uint_least32_t line = 0,
uint_least32_t col = 0,
const char* file = "unknown",
const char* func = "unknown")noexcept;
#endif
private:
constexpr source_location(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept;
};
constexpr source_location::source_location(void)noexcept:
source_location(0, 0, "unknown", "unknown"){}
constexpr source_location::source_location(const source_location& s):
source_location(s.m_line, s.m_column, s.m_file, s.m_func){}
constexpr source_location::source_location(source_location&& s)noexcept:
source_location(s.m_line, s.m_column, s.m_file, s.m_func){}
constexpr source_location::source_location(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept:
m_file(file),
m_func(func),
m_line(line),
m_column(col){}
constexpr uint_least32_t source_location::line(void)const noexcept{
return m_line;
}
constexpr uint_least32_t source_location::column(void)const noexcept{
return m_column;
}
constexpr const char* source_location::file_name(void)const noexcept{
return m_file;
}
constexpr const char* source_location::function_name(void)const noexcept{
return m_func;
}
CONSTEVAL source_location source_location::current(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept{
return source_location(line, col, file, func);
}
}
#undef CONSTEVAL
#else //__cpp_lib_source_location
#include <source_location>
namespace util{
using source_location = std::source_location;
}
#endif //__cpp_lib_source_location
#endif

View File

@ -19,7 +19,7 @@ ifeq ($(OS),Windows_NT)
WINDOWS::=1
endif
SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt src/wip src/util src/math
SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt src/wip src/math
SOURCES::=
OBJDIR::=obj
DEPDIR::=$(OBJDIR)/dep

View File

@ -65,7 +65,7 @@ namespace egn{
}
void camera_iface::recalc_view_matrix(void)const{
debug_print_verbose("Rebuilding view matrix\n");
rexy::debug::verbose::print("Rebuilding view matrix\n");
m_view_matrix = m_orientation.to_mat4();
m_view_matrix.get(3, 0) = -m_position[0];
m_view_matrix.get(3, 1) = -m_position[1];
@ -99,7 +99,7 @@ namespace egn{
}
void ortho_camera::recalc_projection_matrix(void)const{
debug_print_verbose("Rebuilding orthographic projection matrix\n");
rexy::debug::verbose::print("Rebuilding orthographic projection matrix\n");
m_projection_matrix = math::ortho_projection(m_width, m_height, m_near, m_far);
}

View File

@ -57,7 +57,7 @@ namespace egn{
{
initialize_freetype_();
if(int err = FT_New_Face(s_ft, file, 0, &m_face);err){
debug_print_error("Failed to initialize font '%s'. Error %d\n", file, err);
rexy::debug::print_error("Failed to initialize font '%s'. Error %d\n", file, err);
}
}
font::~font(void){
@ -70,7 +70,7 @@ namespace egn{
const size_t range_cnt = range.second;
for(size_t i = 0;i < range_cnt;++i){
if(int err = FT_Load_Char(m_face, i + start, freetype_load_flags);err){
debug_print_error("Failed to load character '%c' from font '%s'\n", (char)i, m_face->family_name);
rexy::debug::print_error("Failed to load character '%c' from font '%s'\n", (char)i, m_face->family_name);
continue;
}
mgw = std::max(mgw, size_t{m_face->glyph->bitmap.width});
@ -113,7 +113,7 @@ namespace egn{
int count = range.second;
for(int i = start_codepoint;i < start_codepoint + count;++i){
if(FT_Load_Char(m_face, i, freetype_load_flags)){
debug_print_error("Failed to load character '%c', from font '%s'\n", i, m_face->family_name);
rexy::debug::print_error("Failed to load character '%c', from font '%s'\n", i, m_face->family_name);
continue;
}
auto& bitmap = m_face->glyph->bitmap;
@ -135,7 +135,7 @@ namespace egn{
std::optional<gfx::ogl::texture> font::generate_glyph(char character, int width, int height){
FT_Set_Pixel_Sizes(m_face, width, height);
if(FT_Load_Char(m_face, character, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD)){
debug_print_error("Failed to load character '%c', from font '%s'\n", character, m_face->family_name);
rexy::debug::print_error("Failed to load character '%c', from font '%s'\n", character, m_face->family_name);
return {};
}
auto& bitmap = m_face->glyph->bitmap;

View File

@ -23,25 +23,25 @@
namespace egn{
static void handle_input_events(GLFWwindow* window, int key, int, int action, int mods){
if(action == GLFW_PRESS){
debug_print_verbose("Keycode %d pressed\n", key);
rexy::debug::verbose::print("Keycode %d pressed\n", key);
}else if(action == GLFW_RELEASE){
debug_print_verbose("Keycode %d released\n", key);
rexy::debug::verbose::print("Keycode %d released\n", key);
}else{
debug_print_verbose("Keycode %d repeated\n", key);
rexy::debug::verbose::print("Keycode %d repeated\n", key);
}
game* g = reinterpret_cast<game*>(glfwGetWindowUserPointer(window));
g->keypress(key, action, mods);
}
static void handle_resize_event(GLFWwindow* window, int width, int height){
debug_print_verbose("Window resized to %dx%d\n", width, height);
rexy::debug::verbose::print("Window resized to %dx%d\n", width, height);
game* g = reinterpret_cast<game*>(glfwGetWindowUserPointer(window));
g->resize(width, height);
}
static void handle_mouse_button_events(GLFWwindow* window, int button, int action, int mods){
if(action == GLFW_PRESS){
debug_print_verbose("Mouse button %d pressed\n", button);
rexy::debug::verbose::print("Mouse button %d pressed\n", button);
}else{
debug_print_verbose("Mouse button %d released\n", button);
rexy::debug::verbose::print("Mouse button %d released\n", button);
}
double x, y;
glfwGetCursorPos(window, &x, &y);

View File

@ -27,21 +27,21 @@
namespace egn{
void game_state_manager::push_state(std::unique_ptr<game_state_iface>&& state){
debug_print("Pushing new state onto game state stack\n");
rexy::debug::print("Pushing new state onto game state stack\n");
if(!m_state_stack.empty())
m_state_stack.top()->leave();
m_state_stack.push (std::move(state));
m_state_stack.top()->enter();
}
void game_state_manager::pop_state(void){
debug_print("Popping state from game state stack\n");
rexy::debug::print("Popping state from game state stack\n");
m_state_stack.top()->leave();
m_state_stack.pop();
if(!m_state_stack.empty())
m_state_stack.top()->enter();
}
void game_state_manager::replace_state(std::unique_ptr<game_state_iface>&& state){
debug_print("Replacing top state of game state stack\n");
rexy::debug::print("Replacing top state of game state stack\n");
m_state_stack.top()->leave();
m_state_stack.top() = std::move(state);
m_state_stack.top()->enter();
@ -57,14 +57,14 @@ namespace egn{
if(!m_state_stack.empty()){
m_state_stack.top()->update(time_diff);
}else{
debug_print_warn("Running update without an active game state\n");
rexy::debug::print_warn("Running update without an active game state\n");
}
}
void game_state_manager::render(void){
if(!m_state_stack.empty()){
m_state_stack.top()->render();
}else{
debug_print_warn("Running render without an active game state\n");
rexy::debug::print_warn("Running render without an active game state\n");
}
}

View File

@ -28,7 +28,7 @@ namespace egn{
stbi_set_flip_vertically_on_load(flip);
m_data = stbi_load(file, &m_width, &m_height, &m_channels, req_chan);
if(!m_data){
debug_print_error("Unable to load image file %s\n", file);
rexy::debug::print_error("Unable to load image file %s\n", file);
}
}
image::image(const image& i):

View File

@ -76,7 +76,7 @@ namespace egn{
}
void object::recalc_model_matrix(void)const{
debug_print_verbose("Rebuilding model matrix\n");
rexy::debug::verbose::print("Rebuilding model matrix\n");
m_model_matrix = m_orientation.to_mat4();
m_model_matrix.get(3, 0) = m_position[0];
m_model_matrix.get(3, 1) = m_position[1];

View File

@ -27,7 +27,7 @@ namespace gfx{
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
static void our_dick_glfw_error_callback(int code, const char* description){
debug_print_error("%d: %s\n", code, description);
rexy::debug::print_error("%d: %s\n", code, description);
}
#endif
@ -37,7 +37,7 @@ namespace gfx{
++s_ref_count;
}
if(s_status){
debug_print_warn("Call to glfwInit after already initialized\n");
rexy::debug::print_warn("Call to glfwInit after already initialized\n");
return;
}
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT

View File

@ -27,7 +27,7 @@ namespace gfx::ogl{
scoped_buffer_map<void>::scoped_buffer_map(GLuint bid, buffer::maptype m):
m_buffer(bid)
{
debug_print_verbose("Mapping buffer object %u\n", bid);
rexy::debug::verbose::print("Mapping buffer object %u\n", bid);
m_data = reinterpret_cast<pointer>(glMapNamedBuffer(m_buffer, static_cast<GLenum>(m)));
}
scoped_buffer_map<void>::scoped_buffer_map(scoped_buffer_map&& m):
@ -35,7 +35,7 @@ namespace gfx::ogl{
m_buffer(std::exchange(m.m_buffer, 0)){}
scoped_buffer_map<void>::~scoped_buffer_map(void){
if(m_data){
debug_print_verbose("Unmapping buffer object %u\n", m_buffer);
rexy::debug::verbose::print("Unmapping buffer object %u\n", m_buffer);
glUnmapNamedBuffer(m_buffer);
}
}

View File

@ -62,13 +62,13 @@ namespace gfx::ogl{
}
void rbo::resize(GLsizei w, GLsizei h){
debug_print_warn("Resizing rbo!\n");
rexy::debug::print_warn("Resizing rbo!\n");
m_width = w;
m_height = h;
glNamedRenderbufferStorageMultisample(m_buffer, m_samples, m_format, m_width, m_height);
}
void rbo::resize(GLsizei w, GLsizei h, GLenum format, GLsizei samples){
debug_print_warn("Resizing rbo!\n");
rexy::debug::print_warn("Resizing rbo!\n");
m_width = w;
m_height = h;
m_format = format;
@ -76,7 +76,7 @@ namespace gfx::ogl{
glNamedRenderbufferStorageMultisample(m_buffer, m_samples, m_format, m_width, m_height);
}
void rbo::reformat(GLenum format){
debug_print_warn("Changing rbo format!\n");
rexy::debug::print_warn("Changing rbo format!\n");
m_format = format;
glNamedRenderbufferStorageMultisample(m_buffer, m_samples, m_format, m_width, m_height);
}

View File

@ -56,7 +56,7 @@ namespace gfx::ogl{
GLuint shader_program::get_uniform_block_loc(const char* u)const{
GLuint i = glGetUniformBlockIndex(m_shader_id, u);
debug_print_info("%d\n", i);
rexy::debug::print_info("%d\n", i);
return i;
}
GLint shader_program::get_uniform_loc(const char* u)const{
@ -77,7 +77,7 @@ namespace gfx::ogl{
GLsizei retlen;
glGetProgramiv(m_shader_id, GL_INFO_LOG_LENGTH, &len);
if(!len){
debug_print_error("Attempt to read shader program error log when no error exists\n");
rexy::debug::print_error("Attempt to read shader program error log when no error exists\n");
return{};
}
std::string retval;
@ -385,7 +385,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[2])){
glProgramUniform2fv(m_shader_id, m_location, count, reinterpret_cast<const GLfloat*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 2]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -398,7 +398,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[3])){
glProgramUniform3fv(m_shader_id, m_location, count, reinterpret_cast<const GLfloat*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 3]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -412,7 +412,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[4])){
glProgramUniform4fv(m_shader_id, m_location, count, reinterpret_cast<const GLfloat*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 4]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -451,7 +451,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[2])){
glProgramUniform2iv(m_shader_id, m_location, count, reinterpret_cast<const GLint*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLint[]> arr(new GLint[count * 2]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -464,7 +464,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[3])){
glProgramUniform3iv(m_shader_id, m_location, count, reinterpret_cast<const GLint*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLint[]> arr(new GLint[count * 3]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -478,7 +478,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[4])){
glProgramUniform4iv(m_shader_id, m_location, count, reinterpret_cast<const GLint*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLint[]> arr(new GLint[count * 4]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -517,7 +517,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[2])){
glProgramUniform2uiv(m_shader_id, m_location, count, reinterpret_cast<const GLuint*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLuint[]> arr(new GLuint[count * 2]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -530,7 +530,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[3])){
glProgramUniform3uiv(m_shader_id, m_location, count, reinterpret_cast<const GLuint*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLuint[]> arr(new GLuint[count * 3]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -544,7 +544,7 @@ namespace gfx::ogl{
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[4])){
glProgramUniform4uiv(m_shader_id, m_location, count, reinterpret_cast<const GLuint*>(v_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLuint[]> arr(new GLuint[count * 4]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = v_arr[i].get(0);
@ -583,7 +583,7 @@ namespace gfx::ogl{
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[4])){
glProgramUniformMatrix2fv(m_shader_id, m_location, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 4]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = m_arr[i].get(0);
@ -598,7 +598,7 @@ namespace gfx::ogl{
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[9])){
glProgramUniformMatrix3fv(m_shader_id, m_location, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 9]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = m_arr[i].get(0);
@ -618,7 +618,7 @@ namespace gfx::ogl{
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[16])){
glProgramUniformMatrix4fv(m_shader_id, m_location, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
}else{
debug_print_warn("Using inefficient uniform initialization\n");
rexy::debug::print_warn("Using inefficient uniform initialization\n");
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 16]);
for(GLsizei i = 0; i < count; ++i){
arr[i] = m_arr[i].get(0);

View File

@ -41,7 +41,7 @@ namespace gfx::ogl{
GLsizei retlen;
glGetShaderiv(s.raw(), GL_SHADER_SOURCE_LENGTH, &len);
if(!len){
debug_print_error("Refusing to compile empty shader source\n");
rexy::debug::print_error("Refusing to compile empty shader source\n");
return;
}
std::string data;
@ -92,7 +92,7 @@ namespace gfx::ogl{
GLsizei retlen;
glGetShaderiv(m_shader_id, GL_INFO_LOG_LENGTH, &len);
if(!len){
debug_print_error("Attempt to read shader error log when no error exists\n");
rexy::debug::print_error("Attempt to read shader error log when no error exists\n");
return{};
}
std::string retval;

View File

@ -190,7 +190,7 @@ namespace gfx::ogl{
{
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
if(!create_texture_storage_()){
debug_print_error("Failed to create texture storage\n");
rexy::debug::print_error("Failed to create texture storage\n");
return;
}
set_image(data, format, w, h, type);
@ -207,13 +207,13 @@ namespace gfx::ogl{
texture_base(t)
{
//Copying textures is not preferable so generate a debug warning
debug_print_warn("Copy constructing texture!\n");
rexy::debug::print_warn("Copy constructing texture!\n");
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
GLint old_alignment = save_unpack_alignment_();
if(!create_texture_storage_()){
debug_print_error("Failed to create texture storage\n");
rexy::debug::print_error("Failed to create texture storage\n");
return;
}
glCopyImageSubData(t.m_tex_id, GL_TEXTURE_2D, 0, 0, 0, 0,
@ -228,7 +228,7 @@ namespace gfx::ogl{
texture_base(std::move(t)){}
texture& texture::operator=(const texture& t){
debug_print_warn("Copy assigning texture!\n");
rexy::debug::print_warn("Copy assigning texture!\n");
return (*this = texture(t));
}
texture& texture::operator=(texture&& t){
@ -244,7 +244,7 @@ namespace gfx::ogl{
if(m_width != w || m_height != h || m_format != format){
if(m_format != 0){
debug_print_warn("Regenerating texture\n");
rexy::debug::print_warn("Regenerating texture\n");
glDeleteTextures(1, &m_tex_id);
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
}
@ -252,7 +252,7 @@ namespace gfx::ogl{
m_height = h;
m_format = format;
if(!create_texture_storage_()){
debug_print_error("Invalid format for texture\n");
rexy::debug::print_error("Invalid format for texture\n");
return false;
}
}
@ -271,11 +271,11 @@ namespace gfx::ogl{
GLsizei xoffset, GLsizei yoffset, GLsizei w, GLsizei h)
{
if(!data){
debug_print_error("Image is invalid\n");
rexy::debug::print_error("Image is invalid\n");
return false;
}
if(yoffset >= m_height || xoffset >= m_width){
debug_print_error("Texture is smaller than requested offsets: (%d, %d)\n", xoffset, yoffset);
rexy::debug::print_error("Texture is smaller than requested offsets: (%d, %d)\n", xoffset, yoffset);
return false;
}
@ -385,7 +385,7 @@ namespace gfx::ogl{
{
glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &m_tex_id);
if(!create_texture_storage_()){
debug_print_error("Failed to create texture array storage\n");
rexy::debug::print_error("Failed to create texture array storage\n");
return;
}
}
@ -393,13 +393,13 @@ namespace gfx::ogl{
texture_base(t),
m_levels(t.m_levels)
{
debug_print_warn("Copy constructing texture array!\n");
rexy::debug::print_warn("Copy constructing texture array!\n");
glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &m_tex_id);
GLint old_alignment = save_unpack_alignment_();
if(!create_texture_storage_()){
debug_print_error("Failed to create texture array storage\n");
rexy::debug::print_error("Failed to create texture array storage\n");
return;
}
glCopyImageSubData(t.m_tex_id, GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
@ -461,7 +461,7 @@ namespace gfx::ogl{
return false;
}
if(yoffset >= m_height || xoffset >= m_width){
debug_print_error("Texture array is smaller than requested offsets: (%d, %d)\n", xoffset, yoffset);
rexy::debug::print_error("Texture array is smaller than requested offsets: (%d, %d)\n", xoffset, yoffset);
return false;
}
if(layer > m_levels || m_format != format){

View File

@ -100,21 +100,21 @@ static void APIENTRY our_dick_gl_debug_output(GLenum source, GLenum type, unsign
break;
}
if(type == GL_DEBUG_TYPE_ERROR || type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR)
debug_print_error("%s:%s:%s:%s\n", src, typ, sev, message);
rexy::debug::print_error("%s:%s:%s:%s\n", src, typ, sev, message);
else if(severity == GL_DEBUG_SEVERITY_MEDIUM || severity == GL_DEBUG_SEVERITY_HIGH)
debug_print_warn("%s:%s:%s:%s\n", src, typ, sev, message);
rexy::debug::print_warn("%s:%s:%s:%s\n", src, typ, sev, message);
else
debug_print("%s:%s:%s:%s\n", src, typ, sev, message);
rexy::debug::print("%s:%s:%s:%s\n", src, typ, sev, message);
}
static void enable_opengl_debug_context(void){
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
if(GLAD_GL_VERSION_4_3){
debug_print("Debug output enabled using core opengl profile\n");
rexy::debug::print("Debug output enabled using core opengl profile\n");
glDebugMessageCallback(our_dick_gl_debug_output, nullptr);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
}else if(GLAD_GL_ARB_debug_output){
debug_print_warn("Debug output enabled using GL_ARB_debug_output extension\n");
rexy::debug::print_warn("Debug output enabled using GL_ARB_debug_output extension\n");
glDebugMessageCallback(our_dick_gl_debug_output, nullptr);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
}
@ -123,18 +123,18 @@ static void enable_opengl_debug_context(void){
static bool has_supported_opengl_version(void){
if(GLAD_GL_VERSION_4_5){
debug_print_succ("Opengl 4.5 fully supported\n");
rexy::debug::print_succ("Opengl 4.5 fully supported\n");
return true;
}
if(GLAD_GL_VERSION_4_3){
if(GLAD_GL_ARB_direct_state_access){
debug_print_warn("Using GL_ARB_direct_state_access extension\n");
rexy::debug::print_warn("Using GL_ARB_direct_state_access extension\n");
return true;
}
}
if(GLAD_GL_ARB_direct_state_access && GLAD_GL_ARB_explicit_uniform_location){
debug_print_warn("Using GL_ARB_direct_state_access extension\n");
debug_print_warn("Using GL_ARB_explicit_uniform_location extension\n");
rexy::debug::print_warn("Using GL_ARB_direct_state_access extension\n");
rexy::debug::print_warn("Using GL_ARB_explicit_uniform_location extension\n");
return true;
}
return false;
@ -190,27 +190,27 @@ static void enable_opengl_debug_context(void){
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if(!m_window){
debug_print_error("Unable to create a GLFW window!\n");
rexy::debug::print_error("Unable to create a GLFW window!\n");
destroy();
return;
}
make_current();
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
debug_print_error("Unable to initialize OpenGL context!\n");
rexy::debug::print_error("Unable to initialize OpenGL context!\n");
destroy();
return;
}
if(!has_supported_opengl_version()){
debug_print_error("Insufficient OpenGL version\n");
rexy::debug::print_error("Insufficient OpenGL version\n");
destroy();
return;
}
debug_print("Using opengl profile version %s\n", glGetString(GL_VERSION));
rexy::debug::print("Using opengl profile version %s\n", glGetString(GL_VERSION));
#ifdef OUR_DICK_ENABLE_DEBUG_CONTEXT
enable_opengl_debug_context();
#else
debug_print("OpenGL debug context is disabled\n");
rexy::debug::print("OpenGL debug context is disabled\n");
#endif
glfwMakeContextCurrent(m_window);
glViewport(0, 0, width, height);
@ -255,21 +255,21 @@ static void enable_opengl_debug_context(void){
auto size = w.get_size();
m_window = glfwCreateWindow(size.x(), size.y(), m_title, nullptr, nullptr);
if(!m_window){
debug_print_error("Unable to create a GLFW window!\n");
rexy::debug::print_error("Unable to create a GLFW window!\n");
destroy();
return;
}
make_current();
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
debug_print_error("Unable to initialize OpenGL context!\n");
rexy::debug::print_error("Unable to initialize OpenGL context!\n");
destroy();
}
debug_print("Using opengl profile version %s\n", glGetString(GL_VERSION));
rexy::debug::print("Using opengl profile version %s\n", glGetString(GL_VERSION));
#ifdef OUR_DICK_ENABLE_DEBUG_CONTEXT
enable_opengl_debug_context();
#else
debug_print("OpenGL debug context is disabled\n");
rexy::debug::print("OpenGL debug context is disabled\n");
#endif
glfwMakeContextCurrent(m_window);

View File

@ -20,7 +20,6 @@
#include "gfx/ogl/shader_stage.hpp"
#include "ttt/square_shader.hpp"
#include "ttt/screen_shader.hpp"
#include "util/deferred.hpp"
#include "config.hpp"
#include <cstdlib> //size_t
@ -40,7 +39,7 @@ main_renderer::main_renderer(wip::gfx::renderer& res, int width, int height):
m_square_shader = res.shader_programs().emplace_value("square_shader", *vert, *frag, *geom).first;
if(m_square_shader->has_link_error()){
debug_print_error("%s\n", m_square_shader->get_error().c_str());
rexy::debug::print_error("%s\n", m_square_shader->get_error().c_str());
}
m_square_shader->get_uniform("vp_mat").set(math::mat4f{});

View File

@ -18,7 +18,6 @@
#include "ttt/pause_state.hpp"
#include "egn/game.hpp"
#include "util/deferred.hpp"
#include "egn/image.hpp"
#include "gfx/ogl/gl_include.hpp" //TODO
@ -31,6 +30,7 @@
#include <vector>
#include <utility> //pair
#include <rexy/deferred.hpp>
std::shared_ptr<wip::gfx::shader> create_base_shader(wip::gfx::renderer& r){
wip::gfx::pipeline_setup setup;
@ -53,10 +53,10 @@ pause_state::pause_state(egn::game& owner, egn::game_state_iface* under):
auto vert = renderer().shader_stages().emplace_value("base_vert", wip::gfx::base_shader::sources[0]).first;
auto frag = renderer().shader_stages().emplace_value("base_frag", wip::gfx::base_shader::sources[1]).first;
auto shader = renderer().shader_programs().emplace_value("base_shader", *vert, *frag).first;
auto tex = renderer().textures().emplace_value("test_texture", util::make_deferred<egn::image>("assets/images/x.jpg", true)).first;
auto tex = renderer().textures().emplace_value("test_texture", rexy::make_deferred<egn::image>("assets/images/x.jpg", true)).first;
auto material = renderer().materials().emplace_value("test_material", shader).first;
material->diffuse_texture = tex;
tex = renderer().textures().emplace_value("test_texture2", util::make_deferred<egn::image>("assets/images/o.jpg", true)).first;
tex = renderer().textures().emplace_value("test_texture2", rexy::make_deferred<egn::image>("assets/images/o.jpg", true)).first;
material = renderer().materials().emplace_value("test_material2", shader).first;
material->diffuse_texture = tex;
@ -78,7 +78,7 @@ void pause_state::leave(){}
void pause_state::handle_input(const egn::input_event& event){
if(event.ev_type == egn::input_event::type::KEY){
if(event.key == GLFW_KEY_SPACE && !event.mods && event.action == GLFW_PRESS){
debug_print("Exiting pause state\n");
rexy::debug::print("Exiting pause state\n");
m_owner->pop_state();
return;
}else if(event.key == GLFW_KEY_ESCAPE && !event.mods && event.action == GLFW_PRESS){

View File

@ -28,6 +28,8 @@
#include "wip/base_shader.hpp"
#include <rexy/deferred.hpp>
play_state::play_state(egn::game& owner, int width, int height):
game_state_iface(&owner),
m_main_renderer(owner.renderer(), width, height),
@ -37,9 +39,9 @@ play_state::play_state(egn::game& owner, int width, int height):
auto vert = renderer().shader_stages().emplace_value("base_vert", wip::gfx::base_shader::sources[0]).first;
auto frag = renderer().shader_stages().emplace_value("base_frag", wip::gfx::base_shader::sources[1]).first;
auto shader = renderer().shader_programs().emplace_value("base_shader", *vert, *frag).first;
auto blank_tex = renderer().textures().emplace_value("blank_texture", util::make_deferred<egn::image>("assets/images/blank.jpg", true)).first;
auto x_tex = renderer().textures().emplace_value("x_texture", util::make_deferred<egn::image>("assets/images/x.jpg", true)).first;
auto o_tex = renderer().textures().emplace_value("o_texture", util::make_deferred<egn::image>("assets/images/o.jpg", true)).first;
auto blank_tex = renderer().textures().emplace_value("blank_texture", rexy::make_deferred<egn::image>("assets/images/blank.jpg", true)).first;
auto x_tex = renderer().textures().emplace_value("x_texture", rexy::make_deferred<egn::image>("assets/images/x.jpg", true)).first;
auto o_tex = renderer().textures().emplace_value("o_texture", rexy::make_deferred<egn::image>("assets/images/o.jpg", true)).first;
auto blank_mat = renderer().materials().emplace_value("blank_mat", shader).first;
auto x_mat = renderer().materials().emplace_value("x_mat", shader).first;
auto o_mat = renderer().materials().emplace_value("o_mat", shader).first;
@ -49,7 +51,7 @@ play_state::play_state(egn::game& owner, int width, int height):
m_board.reset(new new_board(renderer(), blank_mat, x_mat, o_mat));
debug_print("First player chosen is %c\n", m_current_player ? 'X' : 'O');
rexy::debug::print("First player chosen is %c\n", m_current_player ? 'X' : 'O');
m_main_camera.set_position({0, 0, 10});
@ -85,13 +87,13 @@ math::vec4f tile_color(const new_tile& t, bool mouseclick){
void play_state::handle_input(const egn::input_event& ev){
if(ev.ev_type == egn::input_event::type::KEY){
if(ev.key == GLFW_KEY_SPACE && !ev.mods && ev.action == GLFW_PRESS){
debug_print("Entering pause state\n");
rexy::debug::print("Entering pause state\n");
m_owner->push_state(std::unique_ptr<game_state_iface>(new pause_state(*m_owner, this)));
return;
}else if(ev.key == GLFW_KEY_ESCAPE && !ev.mods && ev.action == GLFW_PRESS){
m_owner->on_notify({egn::game_state_event::state_type::SHOULD_CLOSE, 0, 0});
}else if(ev.key == GLFW_KEY_R && !ev.mods && ev.action == GLFW_PRESS){
debug_print("Resetting board state\n");
rexy::debug::print("Resetting board state\n");
m_board->reset();
}
}else if(ev.ev_type == egn::input_event::type::RESIZE){
@ -111,7 +113,7 @@ void play_state::handle_input(const egn::input_event& ev){
int new_index = m_board->click_collision_cheat(projected1);
if(new_index >= 0 && new_index != m_current_tile){
debug_print("Here\n");
rexy::debug::print("Here\n");
new_tile& t = m_board->get_tile(new_index);
t.set_color(tile_color(t, m_mouse_held));
}
@ -131,7 +133,7 @@ void play_state::handle_input(const egn::input_event& ev){
}else if(ev.action == GLFW_RELEASE){
m_mouse_held = false;
if(m_current_tile >= 0 && m_board->get_tile(m_current_tile).value == new_tile::state::BLANK){
debug_print_succ("Clicked on square %d\n", m_current_tile);
rexy::debug::print_succ("Clicked on square %d\n", m_current_tile);
m_board->set_tile(m_current_tile, (++m_current_player %= 2) ? new_tile::state::O : new_tile::state::X);
m_board->get_tile(m_current_tile).set_color({0, 1, 1, 0.1});

View File

@ -20,7 +20,6 @@
#include "gfx/ogl/shader_stage.hpp"
#include "ttt/screen_shader.hpp"
#include "util/deferred.hpp"
#include <tuple>
#include <utility> //piecewise_construct
@ -38,7 +37,7 @@ screen_renderer::screen_renderer(wip::gfx::renderer& res, int width, int height,
auto frag = res.shader_stages().emplace_value("screen_shader_frag", screen_shader::fragment_shader_text, gfx::ogl::shader_stage::type::FRAGMENT).first;
m_screen_shader = res.shader_programs().emplace_value("screen_shader", *vert, *frag).first;
if(m_screen_shader->has_link_error()){
debug_print_error("%s\n", m_screen_shader->get_error().c_str());
rexy::debug::print_error("%s\n", m_screen_shader->get_error().c_str());
}
auto attrib = m_vao.get_attribute(0);

View File

@ -35,7 +35,7 @@ bool tic_tac_toe::is_game_over()const{
void tic_tac_toe::on_notify(const egn::game_state_event& e){
if(e.type == egn::game_state_event::state_type::SHOULD_CLOSE){
debug_print("Game recieved should close notification\n");
rexy::debug::print("Game recieved should close notification\n");
m_game_over = true;
}
}

View File

@ -1,48 +0,0 @@
/**
This file is a part of our_dick
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/
#include "config.hpp"
#if defined(OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT) && (defined(__GNUC__) && !defined(_MSC_VER))
#include <cstdlib> //free
#include <string>
#include <memory>
#include <cxxabi.h>
namespace util{
std::string demangle(const char* name){
int status = 0;
std::unique_ptr<char,void(*)(void*)> res{
abi::__cxa_demangle(name, nullptr, nullptr, &status),
std::free
};
return (status == 0) ? res.get() : name;
}
}
#else
#include <string>
namespace util{
std::string demangle(const char* name){
return name;
}
}
#endif

View File

@ -129,7 +129,7 @@ namespace wip::gfx::ogl{
}
m_shader.link();
if(m_shader.has_link_error()){
debug_print_error("%s\n", m_shader.get_error().c_str());
rexy::debug::print_error("%s\n", m_shader.get_error().c_str());
}
}
}