diff --git a/envs/models/allah.gt b/envs/models/allah.gt index bcac5fb..599caa0 100755 --- a/envs/models/allah.gt +++ b/envs/models/allah.gt @@ -3871,4 +3871,4 @@ name=allah,width=88,height=44,collision=true 0 false 1 X 0 false 1 X 0 false 1 X -; %tsgmeng::builder.texture4_0() -> auto_generated Tue Jun 25 2024 \ No newline at end of file +; %tsgmeng::builder.texture4_0() -> auto_generated Sat Aug 17 2024 \ No newline at end of file diff --git a/lib/bin/gmeng.h b/lib/bin/gmeng.h index e03da35..f21c8d6 100755 --- a/lib/bin/gmeng.h +++ b/lib/bin/gmeng.h @@ -88,6 +88,25 @@ static std::string repeatString(const std::string& str, int times) { return result; } +template +static std::vector repeatThing(Thing obj, int times) { + std::vector Things; + for (int i = 0; i < times; i++) Things.push_back(obj); + return Things; +}; + +template +static std::vector> splitThing(std::vector obj, std::function checker) { + std::vector> Things; + int vec_c = 0; + for (int i = 0; i < obj.size(); i++) { + Thing lndx = obj[i]; + if (vec_c == Things.size()) Things.push_back(std::vector{}); + if (!checker(lndx)) Things[vec_c].push_back(lndx); + else vec_c++; + }; + return Things; +}; static std::string _uconv_1ihx(int value) { //__functree_call__(__FILE__, __LINE__, _conv_1ihx); @@ -182,7 +201,7 @@ namespace Gmeng { /// "-d" suffix means the version is a developer version, high unstability level /// "-b" suffix means the version is a beta version, low unstability level but unpolished /// "-c" suffix means the version is a coroded version, low to medium unstability level but specific methods will not perform as expected - static std::string version = "8.0.0-d"; + static std::string version = "8.2.1-b"; enum color_t { WHITE = 0, BLUE = 1, @@ -243,6 +262,9 @@ namespace Gmeng { }; static std::string bgcolors[] = { "\x1B[49m", "\x1B[44m", "\x1B[42m", "\x1B[46m", "\x1B[41m", "\x1B[45m", "\x1B[43m", "\x1B[40m", "\x1B[47m" + }; + static std::string bgcolors_bright[] = { // match the 'bold' foreground colors (bright) + "\x1B[109m", "\x1B[104m", "\x1B[102m", "\x1B[106m", "\x1B[101m", "\x1B[105m", "\x1B[103m", "\x1B[40m", "\x1B[107m" }; static std::string colorids[] = { "7", "4", "2", "6", "1", "5", "3", "0" }; static std::string resetcolor = "\033[22m\033[0m"; static std::string boldcolor = "\033[1m"; diff --git a/lib/bin/src/gmeng.cpp b/lib/bin/src/gmeng.cpp index 0e2b691..ab466c2 100755 --- a/lib/bin/src/gmeng.cpp +++ b/lib/bin/src/gmeng.cpp @@ -41,7 +41,8 @@ namespace Gmeng { Gmeng::modifier { .name="cast_events", .value=1 }, Gmeng::modifier { .name="allow_teleporting", .value=1 }, Gmeng::modifier { .name="allow_dev_commands", .value=1 }, - Gmeng::modifier { .name="allow_writing_plog", .value=1 } + Gmeng::modifier { .name="allow_writing_plog", .value=1 }, + Gmeng::modifier { .name="cubic_render", .value=0 } } }; Objects::G_Entity entitymap[32767] = {}; @@ -85,18 +86,23 @@ namespace Gmeng { }; inline std::string draw() { __functree_call__(__FILE__, __LINE__, Gmeng::CameraView::draw); - gm_log(__FILE__,__LINE__,"Gmeng::CameraView 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::CameraView 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::CameraView job_render *draw -> resolution: " + v_str(this->w) + "x" + v_str(this->h)); + if (Gmeng::global.dont_hold_back && !Gmeng::global.shush) { + gm_log(__FILE__,__LINE__,"Gmeng::CameraView 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::CameraView 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::CameraView job_render *draw -> resolution: " + v_str(this->w) + "x" + v_str(this->h)); + }; this->clear_screen(); std::string final = ""; - for (int i = 0; i < (this->w*this->h); i++) { + int cubic_height = (this->h % 2 == 0) ? (this->h/2) : (this->h/2)+1; // when cubic render is on, in case the height is not even, extend the height by 1 and fill with void. + int cc = ( this->has_modifier("cubic_render") ) ? ( this->w*(cubic_height) ) : ( this->w*this->h ); + for (int i = 0; i < (cc); i++) { if (i % this->w == 0) { - if (global.debugger) gm_slog(YELLOW, "DEBUGGER", "append_newline__" + v_str( (int)(i / this->h) )); + if (global.debugger) gm_slog(YELLOW, "DEBUGGER", "append_newline__" + v_str( (int)(i / cubic_height) )); if (i > 1) final += "\x1B[38;2;246;128;25m", final += Gmeng::c_unit; final += "\n\x1B[38;2;246;128;25m"; final += Gmeng::c_unit; }; - final += this->raw_unit_map[i]; + /// if the unit is empty, make it a void pixel. should not happen though. + final += this->raw_unit_map[i].empty() ? colors[BLACK] + Gmeng::c_unit + colors[WHITE] : this->raw_unit_map[i]; }; std::string __cu = "\x1B[38;2;246;128;25m"; std::string __cf = "\x1B[38;2;246;128;25m"; @@ -185,25 +191,33 @@ namespace Gmeng { this->set_curXY(4,0); std::cout << "[ last engine build: $!__BUILD | current framework: 4.0_glvl ]"; }; - inline std::string draw_unit(Gmeng::Unit __u) { + inline std::string draw_unit(Gmeng::Unit __u, Gmeng::Unit __nu = Unit { .is_entity=1 }, bool prefer_second = false) { Gmeng::Unit current_unit = __u; + // check if cubic render is preferred, and a next unit is provided + bool nu = this->has_modifier("cubic_render") && !__nu.is_entity; + Gmeng::Unit next_unit = __nu; + // by default, colors are transparent (void/black) + std::string funit_color = Gmeng::colors[current_unit.color]; + std::string bunit_color = nu ? Gmeng::bgcolors[next_unit.color] : Gmeng::bgcolors[BLACK]; + if (current_unit.color == next_unit.color) { + if (current_unit.color == WHITE) return colors[WHITE] + Gmeng::c_unit + Gmeng::resetcolor; + return bgcolors_bright[current_unit.color] + " " + Gmeng::resetcolor; + }; + if (current_unit.special && !prefer_second) { + return bgcolors_bright[current_unit.color] + boldcolor + colors[current_unit.special_clr] + current_unit.special_c_unit + resetcolor; + } else if (nu && next_unit.special && ( !current_unit.special || prefer_second )) { + return bgcolors_bright[next_unit.color] + boldcolor + colors[next_unit.special_clr] + next_unit.special_c_unit + resetcolor; + }; if (current_unit.transparent) { - return Gmeng::colors[7] + Gmeng::c_unit + Gmeng::resetcolor; - }; - if (current_unit.is_player) { - std::string final = "\x1B[4"+Gmeng::colorids[this->playerunit.color]+"m" + (this->playerunit.color == 0 ? Gmeng::colors[8] : Gmeng::colors[current_unit.color]) + current_unit.player.c_ent_tag + Gmeng::resetcolor; - return final; - }; - if (current_unit.special) { - std::string final = "\x1B[4"+Gmeng::colorids[current_unit.color]+"m" + Gmeng::boldcolor + Gmeng::colors[current_unit.special_clr] + current_unit.special_c_unit + Gmeng::resetcolor; - return final; - }; + funit_color = Gmeng::colors[7]; + }; if (nu && next_unit.transparent) { + bunit_color = Gmeng::bgcolors[7]; + }; if (this->has_modifier("wireframe_render")) { - std::string final = "\x1B[4"+std::string(Gmeng::colorids[current_unit.color])+"m" + (current_unit.collidable || this->has_modifier("noclip") ? "x" : "X") + Gmeng::resetcolor; + std::string final = "\x1B[4"+std::string(Gmeng::colorids[current_unit.color])+"m" + (nu ? Gmeng::colors[next_unit.color] : "") + (current_unit.collidable || this->has_modifier("noclip") ? "x" : "X") + Gmeng::resetcolor; return final; }; - std::string color = Gmeng::colors[current_unit.color]; - std::string final = color + (Gmeng::c_unit) + Gmeng::resetcolor; + std::string final = ( nu ? ( bgcolors_bright[next_unit.color] + (current_unit.color != BLACK ? boldcolor : "") + colors[current_unit.color] + Gmeng::c_outer_unit_floor ) : ( funit_color + Gmeng::c_unit ) ) + Gmeng::resetcolor; return final; }; inline void rewrite_mapping(const std::vector& positions) { diff --git a/lib/bin/src/index.cpp b/lib/bin/src/index.cpp index 37e5f1b..6ca31a2 100755 --- a/lib/bin/src/index.cpp +++ b/lib/bin/src/index.cpp @@ -19,15 +19,15 @@ /* files */ #include "objects.cpp" -#include "gmeng.h" -#include "src/textures.cpp" -#include "types/map.h" +#include "../gmeng.h" +#include "textures.cpp" +#include "../types/map.h" /* index */ // this file is for the game code. Current code allows for tsgmeng & gmeng child_process connection // to test the engine. this may also be implemented into something of a game itself, similar to gary's mod // where the game engine just loads maps and modifications to use it to the fullest instead of giving out copies -// for the game engine, which sounds boring anyways. +// for the game engine, which sounds boring anyways. using std::endl; int main( int argc, char** argv ) { diff --git a/lib/bin/src/renderer.cpp b/lib/bin/src/renderer.cpp index 7948cef..85ba33f 100755 --- a/lib/bin/src/renderer.cpp +++ b/lib/bin/src/renderer.cpp @@ -12,6 +12,34 @@ #include #include "../gmeng.h" #include "../src/textures.cpp" +#include +#include +#include + + +bool kbhit(char key) { + fd_set read_fds; + struct timeval timeout; + int result; + + // Clear the file descriptor set + FD_ZERO(&read_fds); + FD_SET(STDIN_FILENO, &read_fds); + + // Set the timeout to 0 to make the call non-blocking + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + // Check if there is input available + result = select(STDIN_FILENO + 1, &read_fds, NULL, NULL, &timeout); + if (result > 0 && FD_ISSET(STDIN_FILENO, &read_fds)) { + char ch = getchar(); + return ch == key; + } + return false; +} + + namespace fs = std::filesystem; @@ -959,7 +987,7 @@ namespace Gmeng { /// { "a", "b", "c", "d", "e", "f", "g", "h", "i" } /// width = 9units, height: 2rows struct __CHROMATIZED_CHUNK_CONTROLLER_VIEWPOINT__ { - std::string data; + std::vector data; Renderer::viewpoint vp; }; @@ -981,64 +1009,68 @@ namespace Gmeng { /// example: /// { "xxxxxxx", /// "xxxxxxx", - /// "xxxoxxx", } -> VECTOR(string, 3); - inline std::vector _vconcatenate_lvl_chunks(Gmeng::Level& lvl) { + /// "xxxoxxx", } -> VECTOR(VECTOR, 3); + inline std::vector _vconcatenate_lvl_chunks(Gmeng::Level& lvl, bool cubic_render = true) { __functree_call__(__FILE__, __LINE__, Gmeng::_vconcatenate_lvl_chunks); gm_log(__FILE__,__LINE__,"Gmeng::_vconcatenate_lvl_chunks *debugger, *0.0, p0,gm:0 :: breakpoint 1"); std::vector<__CHROMATIZED_CHUNK_CONTROLLER_VIEWPOINT__> v_chunks; const int __level_base_width__ = v_static_cast(lvl.base.lvl_template.width); unsigned int p = 0; unsigned int rowc = 0; std::string t_chunk_partial = ""; - std::vector> v_rows; + std::vector> v_rows; std::string unit_seperator = v_str((char)0x1F); // hex code of 'UNIT SEPERATOR' (1-byte long) - for (int __rc = 0; __rc < lvl.base.lvl_template.height; __rc++) v_rows.push_back(g_splitStr(repeatString("\x1F", __level_base_width__), "\x1F")); + for (int __rc = 0; __rc < lvl.base.lvl_template.height; __rc++) { + std::vector current_row; + for (int __lc = 0; __lc < lvl.base.lvl_template.width; __lc++) current_row.push_back(Gmeng::Unit{.color=PINK,.special=true,.special_clr=WHITE,.special_c_unit="?"}); + v_rows.push_back(current_row); + }; // v8.2.0 / swapped to Units instead of rendered_units for (const Gmeng::r_chunk chunk : lvl.chunks) { /// Y location from the start of the deltaY position of the viewpoint int vY = chunk.vp.start.y; /// X location from the start of the deltaX position of the viewpoint int __intlc = 0; bool vb_start = true; + /// v8.2.0 / cubic_render parameter is unused in this function: moved to get_lvl_view for (const auto unit : lvl.v_render_chunk(chunk)) { if (__intlc-1 == _vcreate_vp2d_deltax(chunk.vp)) { vY++; __intlc = 0; vb_start = false; }; /// inserts to the ROW of units (y = vY calculation) to the: /// beggining + chunk coverage boundary start X location + current drawpoint X location /// \x0F is formatter to split units to prepare for trimming at get_lvl_view - v_rows[vY].insert(v_rows[vY].begin() + chunk.vp.start.x + __intlc, lvl.display.camera.draw_unit(unit) + "\x0F"); + v_rows[vY].insert(v_rows[vY].begin() + chunk.vp.start.x + __intlc, unit); if (global.debugger) { if (!vb_start && __intlc == 0) std::cout << std::endl; std::cout << (lvl.display.camera.draw_unit(unit)) + colors[RED]; }; __intlc++; - }; if (global.debugger) std::cout << std::endl; + }; + if (global.debugger) std::cout << std::endl; }; unsigned int rc = 0; - for (std::vector& row : v_rows) { - std::string joined_partial = g_joinStr(row, ""); + for (std::vector& row : v_rows) { v_chunks.push_back({ - joined_partial, + row, Renderer::viewpoint { { 0, 0 }, { __level_base_width__, 0 } } }); }; unsigned int p2 = 0; - std::string reinterpereted_data = ""; + std::vector reinterpereted_data; for (const auto partial : v_chunks) { - if (global.debugger) gm_slog(YELLOW, "DEBUGGER", "__throughout_chroma_loop__ :: &chunks spit(*) -> partial :: " + partial.data); - if (p2 != 0 && p2 % __level_base_width__ == 0) reinterpereted_data += "\n"; - if (_vcreate_vp2d_deltax(partial.vp) == lvl.base.lvl_template.width) reinterpereted_data += partial.data; - else { reinterpereted_data += repeatString(lvl.display.camera.draw_unit({ + if (p2 != 0 && p2 % __level_base_width__ == 0) reinterpereted_data.push_back(Unit{.is_entity=true}); + if (_vcreate_vp2d_deltax(partial.vp) == lvl.base.lvl_template.width) + for (int ik = 0; ik < partial.data.size(); ik++) reinterpereted_data.push_back(partial.data[ik]); + else { reinterpereted_data.push_back(repeatThing((Unit{ .color = color_t::PINK, .collidable = false, .special = true, .special_clr = color_t::RED, .special_c_unit = "X" - }), _vcreate_vp2d_deltax(lvl.display.viewpoint)); gm_slog(YELLOW, "DEBUGGER", colors[RED] + "p2 CHUNK WRITE ERROR ( UNMATCH p2 [" + v_str(_vcreate_vp2d_deltax(partial.vp)) + "] WITH lvl_base_with [" + v_str(lvl.base.lvl_template.width) + "] )" + colors[WHITE] + " at p2_of ~(" + v_str(p2) + ") [ partial_of: chunk_" + _uconv_1ihx(_uget_addr(partial)) + "_00" + v_str(p2 / _vcreate_vp2d_deltax(lvl.display.viewpoint)) + " ]"); }; + }), _vcreate_vp2d_deltax(lvl.display.viewpoint))[0]); gm_slog(YELLOW, "DEBUGGER", colors[RED] + "p2 CHUNK WRITE ERROR ( UNMATCH p2 [" + v_str(_vcreate_vp2d_deltax(partial.vp)) + "] WITH lvl_base_with [" + v_str(lvl.base.lvl_template.width) + "] )" + colors[WHITE] + " at p2_of ~(" + v_str(p2) + ") [ partial_of: chunk_" + _uconv_1ihx(_uget_addr(partial)) + "_00" + v_str(p2 / _vcreate_vp2d_deltax(lvl.display.viewpoint)) + " ]"); }; p2 += _vcreate_vp2d_deltax(partial.vp); }; if (global.debugger) { - gm_slog(YELLOW, "DEBUGGER", "\n" + reinterpereted_data); gm_slog(YELLOW, "DEBUGGER", "^^ above is reinterpereted_data from _vconcatenate_lvl_chunks"); }; - return g_splitStr(reinterpereted_data, "\n"); + return reinterpereted_data; }; /// returns all drawpoints that are included in a viewpoint as a vector. @@ -1062,35 +1094,58 @@ namespace Gmeng { /// It will trace_chunk_vector(&lvl) and render it completely. It should be used as a base image. /// Only use this when a chunk's models, textures are updated. Player and entity movement are handled /// automatically, so there is no need to put this method in any loops. - inline std::vector _vget_renderscale2dpartial_scalar(Gmeng::Level& level_t) { + inline std::vector _vget_renderscale2dpartial_scalar(Gmeng::Level& level_t, bool cubic_render = true) { __functree_call__(__FILE__, __LINE__, Gmeng::_vget_renderscale2dpartial_scalar); - std::vector v_concat_chunks = _vconcatenate_lvl_chunks(level_t); - if (global.debugger) { - gm_slog(YELLOW, "DEBUGGER", "\n" + g_joinStr(v_concat_chunks, "\n")); - }; + std::vector v_concat_chunks = _vconcatenate_lvl_chunks(level_t, cubic_render); return v_concat_chunks; }; + /// Draws a line of units + /// vector -> "[][][][]" + inline std::string draw_line_units(std::vector line) { + CameraView<1,1> camera; + /// ensure resolution - fix v8.2.0-d + camera.SetResolution(1,1); + std::string __final__ = ""; + for (const auto unit : line ) + __final__ += camera.draw_unit(unit); + return __final__; + }; /// returns the camera of the current level, with drawpoints included in level_t->display.viewpoint - inline std::string get_lvl_view(Gmeng::Level& level_t, std::vector concat_chunks) { + inline std::string get_lvl_view(Gmeng::Level& level_t, std::vector concat_chunks, bool cubic_render = true) { __functree_call__(__FILE__, __LINE__, Gmeng::get_lvl_view); gm_log(__FILE__,__LINE__,"get_lvl_view -> tracing viewpoint from level->display.vp"); /// splits each unit including its colorcode ascii characters, using the formatter \x0F defined /// in _vget_renderscale2dpartial_scalar() ~ _vconcatenate_lvl_chunks(). - std::vector trimmed_units = g_splitStr(g_joinStr(concat_chunks, ""), "\x0F"); + std::vector> trimmed_units = splitThing(concat_chunks, [&](Unit u) -> bool { + return u.is_entity == true; // (x == true) operator is required because u.is_entity can be NULL + }); /// TRIMMED_UNITS == line of units. trimmed_units[0] = vector(LINE_0) if (global.debugger) { gm_slog(GREEN, "DEBUGGER_RENDERENGINE", "inspection of trimmed_units:"); - unsigned int cc = 0; + /*unsigned int cc = 0; for ( const auto unit : trimmed_units ) { if (cc % v_static_cast(level_t.base.lvl_template.width) == 0) std::cout << std::endl; - std::cout << unit; + std::cout << level_t.display.camera.draw_unit(unit); cc++; - }; + };*/ // v8.2.0 -> swap to vector disables this functionality for the time being + gm_slog(GREEN, "DEBUGGER_RENDERENGINE", colors[RED] + "< currently disabled >"); }; + /// TODO: create arbitrary return type for get_lvl_view + /// returning this response as a string is inefficient std::string __final__ = ""; unsigned int ptr = 0; gm_log(__FILE__,__LINE__,"get_lvl_view -> expanding viewpoint of level_t's camera"); + /// expand the viewpoint to a vector of drawpoints auto resource = _vexpand_viewpoint(level_t.display.viewpoint); + // for cubic_render, skips the Y position for already-drawn lines + int skip_y_position = -1; + bool notified = false; + /// loop through each drawpoint in the camera. for (const auto dp : resource) { + if (dp.y == skip_y_position) { + if (!notified && global.dont_hold_back) gm_log(__FILE__,__LINE__, " { cubic_render } advancing to next Y position / seek_drawn( ++dp.Y )"); + ptr++; // still count the unit number + continue; + }; notified = false; if (global.dont_hold_back) gm_log(__FILE__,__LINE__," :::: get_lvl_view -> CURR_DP: " + Gmeng::Renderer::conv_dp(dp) + " *(p): " + v_str(ptr)); if (global.debugger) { gm_slog(YELLOW, "DEBUGGER", "current drawpoint: " + v_str(dp.x) + "," + v_str(dp.y)); @@ -1108,20 +1163,53 @@ namespace Gmeng { ///------------------------------------------------------------------------------------------------ /// fallback in case the viewpoint is out of bounds or extends out of the base level wrapper, /// otherwase the application would crash due to heap-extreme-overflow-access-unallocated-mem SEGV. - if ( dp.x < 0 || dp.y < 0 || - dp.x >= level_t.base.lvl_template.width || dp.y >= level_t.base.lvl_template.height ) { + #define out_of_bounds(dp) (dp.x < 0 || dp.y < 0 || dp.x >= level_t.base.lvl_template.width || dp.y >= level_t.base.lvl_template.height) + #define out_of_cbounds(dp) (dp.x < 0 || dp.y < 0 || dp.x >= level_t.base.lvl_template.width || dp.y >= (level_t.base.lvl_template.height/2)) + if ( out_of_bounds(dp) ) { if (global.debugger) gm_slog(RED, "DEBUGGER", colors[YELLOW] + "E_NO_UNIT" + colors[WHITE] + ": drawpoint out-of-bound, replace with placeholder"); + int the_depths = (ptr % 2 == 0) == 0 ? ((dp.y % 2 == 0) ? BLACK : WHITE) : ((dp.y % 2 == 0) ? WHITE : BLACK); __final__ += level_t.display.camera.draw_unit({ - .color = (ptr % 2 == 0) ? BLACK : WHITE, + .color = the_depths, .special = true, .special_clr = RED, .special_c_unit = "?" - }) + "\x0F"; ptr++; + }) + "\x0F"; ptr++; // v7.1.0 - filler unit for out-of-bounds drawpoint, to prevent crashes continue; } else { if (global.debugger) gm_slog(RED, "DEBUGGER", "dp.x: " + v_str(dp.x) + " lvl.width: " + v_str(level_t.base.lvl_template.width) + " dp.y: " + v_str(dp.y) + " lvl.height: " + v_str(level_t.base.lvl_template.height)); - __final__ += trimmed_units[ _vpos ] + "\x0F"; + if (dp.y == trimmed_units.size()) { gm_log("!! ** ooga-booga problem: trimmed_size(" + v_str(trimmed_units.size()) + ") = dp.y(" + v_str(dp.y) + ") "); continue; }; + Unit __unit; + /// v8.2.0 / vpos scales with each unit, % operator will chromatize to the current X position + int true_position = _vpos % level_t.base.lvl_template.width; + try { __unit = trimmed_units.at(dp.y).at(true_position); } catch(const std::out_of_range& e) { + gm_log(__FILE__, __LINE__, "FAULTY_POS: _vpos -> " + v_str(true_position) + " | dp.y -> " + v_str(dp.y) + " | units_size -> " + v_str(trimmed_units.size())); +#if __GMENG_LOG_TO_COUT__ + gm_log(__FILE__, __LINE__, "FATAL_STOP: " + v_str(_vpos) + "," + v_str(true_position)); +#endif + continue; + }; + /// v8.2.0 / cubir_render -> real pixel-scale 1x1 unit rendering + if (cubic_render) { + /// fallback if fetching the lower-unit fails + /// should not happen though, bounds check is performed before this operation + Unit __fallback__ = Unit {.color=PINK,.special=true,.special_clr=WHITE,.special_c_unit="?"}; + Unit __next_unit = __fallback__; + #define _draw level_t.display.camera.draw_unit + try { __next_unit = trimmed_units.at(dp.y+1).at(true_position); } catch (const std::out_of_range& e) { + __final__ += _draw(__fallback__); + continue; + }; + /// double-render in one character size + /*if (__unit.color == __next_unit.color) { + /// same color, does not require different pixels + };*/ // v8.1.1 / draw_unit() automatically handles same colors + __final__ += _draw(__unit, __next_unit); + } else { + __final__ += level_t.display.camera.draw_unit(__unit); + }; + __final__ += "\x0F"; // v8.2.1-d / delimeter fix lol }; ptr++; + if (cubic_render) skip_y_position = dp.y+1; // v8.2.1-d / skip repeating already-drawn line }; gm_log(__FILE__,__LINE__,"get_lvl_view -> level view rendered"); if (global.debugger) { diff --git a/test.cpp b/test.cpp index 91685a3..5786a04 100755 --- a/test.cpp +++ b/test.cpp @@ -8,7 +8,7 @@ #include "lib/bin/utils/interface.cpp" #include "lib/bin/utils/network.cpp" #include "lib/bin/src/renderer.cpp" -#include "lib/bin/utils/interface.hpp" +#include "lib/bin/types/interface.h" #include #include #include diff --git a/tests/ncurses_acs.cpp b/tests/ncurses_acs.cpp old mode 100644 new mode 100755 diff --git a/tests/out/test.o b/tests/out/test.o index 2201ab4..2bbda3a 100755 Binary files a/tests/out/test.o and b/tests/out/test.o differ diff --git a/tests/test.cpp b/tests/test.cpp index 8f724e7..9c513d1 100755 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -96,9 +96,9 @@ int test_renderer() { return 0; }; int test_loadglvl() { - std::cout << "test_loadglvl job_start" << std::endl; + std::cout << "test_loadglvl job_start" << '\n'; Gmeng::LevelInfo lv_inf = Gmeng::parse_glvl("envs/4.0_test.glvl"); - std::cout << "c_p1xdp - c_p2dp | vchunk_info" << std::endl; + std::cout << "c_p1xdp - c_p2dp | vchunk_info" << '\n'; Gmeng::Level lv_test; lv_test.load_level(lv_inf); std::cout << Gmeng::Renderer::conv_dp(lv_test.chunks[0].vp.start) << " - " << Gmeng::Renderer::conv_dp(lv_test.chunks[0].vp.end) << endl; @@ -109,7 +109,7 @@ int test_loadglvl() { .c_ent_tag="o" }, 1, 0); lv_test.draw_camera(0); - std::cout << "chunk id(0) num(1) displayed ^ above ~~ works" << std::endl; + std::cout << "chunk id(0) num(1) displayed ^ above ~~ works" << '\n'; std::this_thread::sleep_for(std::chrono::milliseconds(2000)); lv_test.draw_camera(1); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); @@ -118,7 +118,7 @@ int test_loadglvl() { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); lv_test.move_player(0, 2); lv_test.refresh(); - std::cout << "chunk id(1) num(2) displayed ^ above & Objects::G_Player attached to camera ~~ works" << std::endl << "~~ no modifiers required" << std::endl; + std::cout << "chunk id(1) num(2) displayed ^ above & Objects::G_Player attached to camera ~~ works" << std::endl << "~~ no modifiers required" << '\n'; std::cout << "player pos: " << lv_test.plcoords.x << "," << lv_test.plcoords.y << endl; return 0; }; @@ -147,12 +147,12 @@ int test_vgmcontent() { std::cout << "drawing texture: "; std::cout << tx.name << " | notxtr: " << (Gmeng::notxtr.name == tx.name ? "true" : "false"); for (int i = 0; i < tx.units.size(); i++) { - if ((i % tx.width) == 0) std::cout << std::endl; + if ((i % tx.width) == 0) std::cout << '\n'; std::cout << camera.draw_unit(tx.units[i]); }; - std::cout << std::endl; + std::cout << '\n'; }; - std::cout << std::endl; + std::cout << '\n'; return 0; }; @@ -163,7 +163,7 @@ int test_caketxtr() { std::cout << tx.name << " | notxtr: " << (Gmeng::notxtr.name == tx.name ? "true" : "false") << endl; camera.SetResolution(1, 1); for (int i = 0; i < tx.units.size(); i++) { - if ( i % tx.width == 0 ) std::cout << std::endl; + if ( i % tx.width == 0 ) std::cout << '\n'; std::cout << camera.draw_unit(tx.units[i]); }; return 0; @@ -201,7 +201,7 @@ int test_chunkvpoint() { level_test.draw_camera(0); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); level_test.draw_camera(1); - std::cout << "starting test for __viewpoint_vector_move_camera__" << std::endl; + std::cout << "starting test for __viewpoint_vector_move_camera__" << '\n'; /// bit to check text_data gm::global.dev_console = true; _udraw_display(Gmeng::logc); @@ -210,7 +210,7 @@ int test_chunkvpoint() { }; int test_vpointrender() { - std::cout << "starting test_vpointrender" << std::endl; + std::cout << "starting test_vpointrender" << '\n'; Gmeng::Level level_test = { .base = { .lvl_template = gm::vd_find_texture(Gmeng::vgm_defaults::vg_textures, "allah"), @@ -242,15 +242,15 @@ int test_vpointrender() { level_test.draw_camera(0); level_test.display.viewpoint = { { 10, 5 }, { 20, 10 } }; gm_log("__test_chunkvpoint__ (static test) -> __attempt_test__ ; _vcamv_gen_frame tl"); - std::cout << std::endl; + std::cout << '\n'; std::string __test__ = Gmeng::_vcamv_gen_frame(level_test); - std::cout << __test__ << std::endl; + std::cout << __test__ << '\n'; exit(0); return 0; }; int test_vwhole_renderer() { - std::cout << "beginning test" << std::endl; + std::cout << "beginning test" << '\n'; Gmeng::Level lvl = { .base = { .lvl_template = gm::vd_find_texture(Gmeng::vgm_defaults::vg_textures, "allah"), @@ -260,86 +260,105 @@ int test_vwhole_renderer() { .name = v_str(g_mkid()) }; - std::cout << "generate lvl" << std::endl; - Gmeng::Renderer::Model test_model = Gmeng::Renderer::generate_empty_model(10, 5); + std::cout << "generate lvl" << '\n'; + Gmeng::Renderer::Model test_model = Gmeng::Renderer::generate_empty_model(5, 5); test_model.position = { 0,5 }; test_model.name = v_str(g_mkid()); - std::cout << "generate model1" << std::endl; + std::cout << "generate model1" << '\n'; lvl.load_chunk({ .vp = { { 0,0 }, { 43,44 } }, .models = { test_model } }); - std::cout << "load chunk1" << std::endl; + std::cout << "load chunk1" << '\n'; Gmeng::Renderer::Model test_model_2 = { .position = { 20,0 } }; - std::cout << "generate model2" << std::endl; + std::cout << "generate model2" << '\n'; test_model_2.attach_texture(gm::vd_find_texture(Gmeng::vgm_defaults::vg_textures, "01_cake_txtr")); - std::cout << "texture model2" << std::endl; + std::cout << "texture model2" << '\n'; lvl.load_chunk({ .vp = { { 44,0 }, { 87,43 } }, .models = { test_model_2 } }); - std::cout << "load chunk2" << std::endl; - - Gmeng::Renderer::viewpoint def_vp = { { 0,0 }, { 40, 20 } }; - unsigned int def_c = 30; - unsigned int def_ms = 40; + std::cout << "load chunk2" << '\n'; + Gmeng::Renderer::viewpoint def_vp1 = { { 0,0 }, { 78, 43 } }; + Gmeng::Renderer::viewpoint def_vp = { { 0,0 }, { 20, 20 } }; + unsigned int def_cx = 30; + unsigned int def_cy = 15; + unsigned int def_ms = 20; + bool paused = false; lvl.display.set_resolution(Gmeng::_vcreate_vp2d_deltax(def_vp), Gmeng::_vcreate_vp2d_deltay(def_vp)); - lvl.display.viewpoint = def_vp; - std::vector _renderscale = Gmeng::_vget_renderscale2dpartial_scalar(lvl); - std::cout << "renderscale done" << std::endl; - std::string _lvlview = Gmeng::get_lvl_view(lvl, _renderscale); - std::cout << "level_view done" << std::endl; + lvl.display.viewpoint = def_vp1; + lvl.display.camera.set_modifier("cubic_render", true); + std::vector _renderscale = Gmeng::_vget_renderscale2dpartial_scalar(lvl, true); + //g_sleep(ms(5009)); + std::cout << "renderscale done" << '\n'; + std::string _lvlview = Gmeng::get_lvl_view(lvl, _renderscale, true); + std::cout << "level_view done" << '\n'; Gmeng::emplace_lvl_camera(lvl, _lvlview); - std::cout << "emplace_lvl_camera done" << std::endl; + std::cout << "emplace_lvl_camera done" << '\n'; lvl.display.camera.clear_screen(); - for (int c_counter_t = 0; c_counter_t < def_c; c_counter_t++) { + std::cout << lvl.display.camera.draw() << '\n'; + do + { + cout << '\n' << "Press [enter] to continue..."; + } while (cin.get() != '\n'); + lvl.display.camera.clear_screen(); + lvl.display.viewpoint = def_vp; // normal vp + for (int c_counter_t = 0; c_counter_t < def_cx; c_counter_t++) { + if (kbhit(65)) paused = !paused; + if (paused) { c_counter_t =0; continue; }; lvl.display.viewpoint.start.x += 1; lvl.display.viewpoint.end.x += 1; - Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale)); + Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale,true)); lvl.display.camera.reset_cur(); - std::cout << lvl.display.camera.draw() << std::endl; + std::cout << lvl.display.camera.draw() << '\n'; g_sleep(ms(def_ms)); }; lvl.display.camera.clear_screen(); g_sleep(ms(500)); lvl.display.viewpoint = def_vp; - for (int c_counter_t = 0; c_counter_t < def_c; c_counter_t++) { + for (int c_counter_t = 0; c_counter_t < def_cx; c_counter_t++) { + if (kbhit('p')) paused = !paused; + if (paused) { c_counter_t =0; continue; }; lvl.display.viewpoint.start.x -= 1; lvl.display.viewpoint.end.x -= 1; - Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale)); + Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale,true)); lvl.display.camera.reset_cur(); - std::cout << lvl.display.camera.draw() << std::endl; + std::cout << lvl.display.camera.draw() << '\n'; g_sleep(ms(def_ms)); }; - std::cout << "X axis movement done" << std::endl; + std::cout << "X axis movement done" << '\n'; g_sleep(ms(1000)); lvl.display.viewpoint = def_vp; - for (int c_counter_t = 0; c_counter_t < def_c; c_counter_t++) { + for (int c_counter_t = 0; c_counter_t < def_cy; c_counter_t++) { + if (kbhit('p')) paused = !paused; + if (paused) { c_counter_t =0; continue; }; lvl.display.viewpoint.start.y += 1; lvl.display.viewpoint.end.y += 1; - Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale)); - std::cout << lvl.display.camera.draw() << std::endl; + Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale,true)); + std::cout << lvl.display.camera.draw() << '\n'; g_sleep(ms(def_ms)); }; - std::cout << "Y axis movement done" << std::endl; + std::cout << "Y axis movement done" << '\n'; g_sleep(ms(1000)); lvl.display.viewpoint = def_vp; - for (int c_counter_t = 0; c_counter_t < def_c; c_counter_t++) { + for (int c_counter_t = 0; c_counter_t < def_cy; c_counter_t++) { + if (kbhit('p')) paused = !paused; + if (paused) { c_counter_t =0; continue; }; lvl.display.viewpoint.start.y += 1; lvl.display.viewpoint.end.y += 1; - lvl.display.viewpoint.start.x += 1; - lvl.display.viewpoint.end.x += 1; - Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale)); - std::cout << lvl.display.camera.draw() << std::endl; + lvl.display.viewpoint.start.x += 2; + lvl.display.viewpoint.end.x += 2; + Gmeng::emplace_lvl_camera(lvl, get_lvl_view(lvl, _renderscale,true)); + std::cout << lvl.display.camera.draw() << '\n'; g_sleep(ms(def_ms)); }; - std::cout << "double axis movement done" << std::endl; + std::cout << "double axis movement done" << '\n'; return 0; }; @@ -381,15 +400,15 @@ int main(int argc, char* argv[]) { int total = 0; for (int i = 0; i < testids.size(); i++) { auto it = std::find(do_list.begin(), do_list.end(), i); - if (it == do_list.end()) { std::cout << "skipping test_000" << i << ": since test loader do_list does not include it" << std::endl; continue; }; - std::cout << "running 000" << i << "_test_nr_" << i << " | heap_at: " << _uconv_1ihx(_uget_addr(testids[i])) << std::endl; + if (it == do_list.end()) { std::cout << "skipping test_000" << i << ": since test loader do_list does not include it" << '\n'; continue; }; + std::cout << "running 000" << i << "_test_nr_" << i << " | heap_at: " << _uconv_1ihx(_uget_addr(testids[i])) << '\n'; total++; if (testids.size() == i) break; int value = testids[i](); - std::cout << "test 000" << i << "_test returned heap_value: " << _uconv_1ihx(value) << std::endl; + std::cout << "test 000" << i << "_test returned heap_value: " << _uconv_1ihx(value) << '\n'; }; _gthread_catchup(); - std::cout << "done running tests | total: " << total << std::endl; + std::cout << "done running tests | total: " << total << '\n'; return 0; }; };