Skip to content

Commit

Permalink
8.2.1-b (version-skip for stability): cubic-render for square-sized u…
Browse files Browse the repository at this point in the history
…nits (currently only supported for the glvl framework, working on adding backwards-compatibility with the 1.1gm framework), option color brightness, swapped chunk_vector return type to vector<Unit> from vector<string> & comments and annotations for better codebase understandability
  • Loading branch information
catriverr committed Aug 17, 2024
1 parent 1f5a1e0 commit 4738bd5
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 112 deletions.
2 changes: 1 addition & 1 deletion envs/models/allah.gt
Original file line number Diff line number Diff line change
Expand Up @@ -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
; %tsgmeng::builder.texture4_0() -> auto_generated Sat Aug 17 2024
24 changes: 23 additions & 1 deletion lib/bin/gmeng.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ static std::string repeatString(const std::string& str, int times) {
return result;
}

template<typename Thing>
static std::vector<Thing> repeatThing(Thing obj, int times) {
std::vector<Thing> Things;
for (int i = 0; i < times; i++) Things.push_back(obj);
return Things;
};

template<typename Thing>
static std::vector<std::vector<Thing>> splitThing(std::vector<Thing> obj, std::function<bool(Thing)> checker) {
std::vector<std::vector<Thing>> 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<Thing>{});
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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down
56 changes: 35 additions & 21 deletions lib/bin/src/gmeng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {};
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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<int>& positions) {
Expand Down
8 changes: 4 additions & 4 deletions lib/bin/src/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Loading

0 comments on commit 4738bd5

Please sign in to comment.