Skip to content

Commit

Permalink
oh god
Browse files Browse the repository at this point in the history
  • Loading branch information
catriverr committed Sep 3, 2024
1 parent fede29d commit d89c851
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 116 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#.clangd
#CompileFlags:
Add: [ -D_DARWIN_C_SOURCE, -DNCURSES_WIDECHAR, -include, "/opt/homebrew/Cellar/ncurses/6.5/include/ncursesw", -include, "/opt/homebrew/Cellar/ncurses/6.5/include", -D__GMENG_OBJECTINIT__=1, -include, "./lib/bin/gmeng.h" ]
# Add: [ -D_DARWIN_C_SOURCE, -DNCURSES_WIDECHAR, -include, "/opt/homebrew/Cellar/ncurses/6.5/include/ncursesw", -include, "/opt/homebrew/Cellar/ncurses/6.5/include", -D__GMENG_OBJECTINIT__=1 ]
Binary file modified lib/.DS_Store
Binary file not shown.
95 changes: 84 additions & 11 deletions lib/bin/gmeng.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,68 @@

#ifdef __GMENG_OBJECTINIT__

using std::vector;
using std::string;


namespace Gmeng::Assertions {
typedef struct assert_t {
enum jWRAP { ON = 0, OFF = 1, NOT_SET = 2 };
std::map<string, jWRAP> headers;
const char* bound;
} vd_assert;
typedef struct assert_data_t {
string header;
assert_t::jWRAP state;
const char* bound;
} assertable_t;
static std::map<const char*, vd_assert> list;
static vd_assert to_assert_t(assertable_t data) {
vd_assert obj;
obj.headers = std::map<string, vd_assert::jWRAP>();
obj.bound = data.bound;
obj.headers.emplace(data.header, data.state);
return obj;
};
static void set_assert(assertable_t data) {
if (!Assertions::list.contains(data.bound)) list.emplace(data.bound, to_assert_t(data));
Assertions::list.find(data.bound)->second.headers.insert_or_assign(data.header, data.state);
};
static vd_assert::jWRAP get_assert(string header, const char* bound) {
if (!Assertions::list.contains(bound)) return assert_t::NOT_SET;
auto fd = Assertions::list.find(bound)->second.headers;
return fd.contains(header) ? fd.find(header)->second : assert_t::NOT_SET;
};
};

struct GMENG_NULL_T {
void* content;
};

template<typename T = int>
struct not_nullptr_t {
T val = 1;
};

static not_nullptr_t<int> not_nullptr_ref = { 1 };
static not_nullptr_t<int>* not_nullptr = &not_nullptr_ref;

#define ASSERT(x,y) Gmeng::Assertions::set_assert( \
{ \
.header = x, \
.state = y, \
.bound = __FUNCTION__ \
} \
)

#define PREF(x) Gmeng::Assertions::get_assert( \
x, \
__FUNCTION__ \
)

#define IS_SET Gmeng::Assertions::vd_assert::ON ==


#define vl_get_name(x) #x
#define vl_filename(path) (strrchr(path, '/') ? strrchr(path, '/') + 1 : path)

Expand Down Expand Up @@ -478,14 +540,20 @@ static std::string colorformat(std::string data) {
#define SAY std::cout << colorformat
#define INF std::cout << "\033[1m" + Gmeng::colors[Gmeng::BLUE] + "(i) >> \033[0m" + Gmeng::colors[Gmeng::WHITE] + colorformat

static std::string get_filename(string filepath) {
vector<string> fd = g_splitStr(filepath, "/");
return fd[fd.size()-1];
};

static void _gm_log(const char* file, int line, std::string _msg, bool use_endl = true) {
static void _gm_log(const char* file_, int line, const char* func, std::string _msg, bool use_endl = true) {
if (Gmeng::Assertions::get_assert("pref.log", func) == Gmeng::Assertions::vd_assert::OFF) return;
std::string file = get_filename(std::string(file_)); // remove path, only use filename
#ifndef __GMENG_ALLOW_LOG__
__gmeng_write_log__("gmeng.log", "logging is disallowed");
return;
#endif
#if __GMENG_ALLOW_LOG__ == true
std::string msg = std::string(file) + ":" + v_str(line) + " | " + _msg;
std::string msg = file + ":" + v_str(line) + " [" + std::string(func) + "] " + _msg;
#if __GMENG_LOG_TO_COUT__ == true
if (Gmeng::global.log_stdout) std::cout << msg << std::endl;
#endif
Expand All @@ -500,19 +568,21 @@ static void _gm_log(const char* file, int line, std::string _msg, bool use_endl
#endif
};

static void gm_log(const char* file, int line, std::string _msg, bool use_endl = true) {
static void dgm_log(const char* file, int line, std::string _msg, bool use_endl = true) {
if (Gmeng::global.shush) return;
_gm_log(file, line, _msg, use_endl);
_gm_log(file, line, "UNKNOWN_SOURCE", _msg, use_endl);
};

static void gm_log(std::string _msg, bool use_endl = true) {
static void dgm_log(std::string _msg, bool use_endl = true) {
if (Gmeng::global.shush) return;
_gm_log(":",0,_msg,use_endl);
_gm_log(":",0,"UNKNOWN_SOURCE",_msg,use_endl);
};

#define gm_log(x) _gm_log(__FILE__, __LINE__, __FUNCTION__, x)

static void gm_slog(Gmeng::color_t color, std::string title, std::string text) {
if (Gmeng::global.shush) return;
gm_log(":", 0, Gmeng::colors[color] + title + " " + Gmeng::colors[Gmeng::WHITE] + text);
_gm_log(":", 0, "UNKNOWN_SOURCE", Gmeng::colors[color] + title + " " + Gmeng::colors[Gmeng::WHITE] + text);
};

namespace Gmeng {
Expand All @@ -527,7 +597,7 @@ namespace Gmeng {
};
static void _ujoin_threads () {
__functree_call__(__FILE__, __LINE__, Gmeng::_ujoin_threads);
for (auto& thread : Gmeng::v_threads) { gm_log(FILENAME, __LINE__, "Gmeng::_ujoin_threads -> gm:v_thread, _ucreate_thread() -> T_MEMADDR: " + _uconv_1ihx(_uget_addr(&thread)) + " - MAIN THREAD ID: " + _uget_thread() + " - T_THREAD_ID: " + _uthread_id(thread)); try { if (thread.joinable()) thread.join(); _uclear_threads(); } catch (std::exception& e) { std::cerr << (Gmeng::colors[4] + "_ujoin_threads() -> *error :: could not join thread, skipping..."); gm_log(FILENAME, __LINE__, " :::: error cause -> " + std::string(e.what())); }; };
for (auto& thread : Gmeng::v_threads) { gm_log("Gmeng::_ujoin_threads -> gm:v_thread, _ucreate_thread() -> T_MEMADDR: " + _uconv_1ihx(_uget_addr(&thread)) + " - MAIN THREAD ID: " + _uget_thread() + " - T_THREAD_ID: " + _uthread_id(thread)); try { if (thread.joinable()) thread.join(); _uclear_threads(); } catch (std::exception& e) { std::cerr << (Gmeng::colors[4] + "_ujoin_threads() -> *error :: could not join thread, skipping..."); gm_log(" :::: error cause -> " + std::string(e.what())); }; };
};
}

Expand All @@ -546,7 +616,7 @@ static void _gupdate_logc_intvl(int ms = 250) {
Gmeng::completelog << Gmeng::logstream.str();
Gmeng::logstream.str(""); /// flush sstream
_uflush_display(Gmeng::logc, 5);
gm_log(FILENAME, __LINE__, "t_display *job_flush -> flushed display at gm:thread" + _uget_thread() + " (detached from gm:thread0 / generated from gm:thread0) ; display memory address: " + _uconv_1ihx(_uget_addr(&Gmeng::logc)));
gm_log("t_display *job_flush -> flushed display at gm:thread" + _uget_thread() + " (detached from gm:thread0 / generated from gm:thread0) ; display memory address: " + _uconv_1ihx(_uget_addr(&Gmeng::logc)));
};
_udraw_display(Gmeng::logc);
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
Expand All @@ -559,7 +629,7 @@ static void _gupdate_logc_intvl(int ms = 250) {
static void _gthread_catchup() {
__annotation__(_gthread_catchup, "Gmeng::_uthread catchup function, attaches to all threads and clears them.");
__functree_call__(__FILE__, __LINE__, _gthread_catchup);
gm_log(FILENAME, __LINE__, "_gthread_catchup() -> waiting for " + v_str(Gmeng::v_threads.size()) + " threads to catch-up to thread:" + (_uget_thread()));
gm_log("_gthread_catchup() -> waiting for " + v_str(Gmeng::v_threads.size()) + " threads to catch-up to thread:" + (_uget_thread()));
Gmeng::_ujoin_threads();
};

Expand Down Expand Up @@ -693,7 +763,6 @@ static void patch_argv_global(int argc, char* argv[]) {
#endif
};


#define __GMENG_INIT__ true /// initialized first because the source files check this value before initialization
#include "src/textures.cpp"
#include "src/gmeng.cpp"
Expand All @@ -705,6 +774,10 @@ static void patch_argv_global(int argc, char* argv[]) {
#include "types/interface.h"
#include "utils/interface.cpp"
/// for github build workflow
#if GMENG_SDL
#include "types/window.h"
#include "utils/window.cpp"
#endif
#endif
#endif
namespace g = Gmeng;
Expand Down
6 changes: 3 additions & 3 deletions lib/bin/src/gmeng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ namespace Gmeng {
inline std::string draw() {
__functree_call__(__FILE__, __LINE__, Gmeng::Camera::draw);
if (Gmeng::global.dont_hold_back && !Gmeng::global.shush) {
gm_log(__FILE__,__LINE__,"Gmeng::Camera job_render *draw -> total drawpoints available at this->cam::vp_mem0: " + v_str(sizeof(this->raw_unit_map)) + " , v_addr " + _uconv_1ihx(0) + " -> " + _uconv_1ihx(sizeof(this->raw_unit_map)));
gm_log(__FILE__,__LINE__,"Gmeng::Camera job_render *draw -> total drawpoints allocated for job_render at this->cam::vp_mem0: " + v_str(this->w*this->h) + " | " + _uconv_1ihx(this->w*this->h));
gm_log(__FILE__,__LINE__,"Gmeng::Camera job_render *draw -> resolution: " + v_str(this->w) + "x" + v_str(this->h));
gm_log("Gmeng::Camera job_render *draw -> total drawpoints available at this->cam::vp_mem0: " + v_str(sizeof(this->raw_unit_map)) + " , v_addr " + _uconv_1ihx(0) + " -> " + _uconv_1ihx(sizeof(this->raw_unit_map)));
gm_log("Gmeng::Camera job_render *draw -> total drawpoints allocated for job_render at this->cam::vp_mem0: " + v_str(this->w*this->h) + " | " + _uconv_1ihx(this->w*this->h));
gm_log("Gmeng::Camera job_render *draw -> resolution: " + v_str(this->w) + "x" + v_str(this->h));
};
this->clear_screen();
std::string final = "";
Expand Down
Loading

0 comments on commit d89c851

Please sign in to comment.