diff options
author | jonas <himself@jonasgunz.de> | 2018-12-26 15:18:23 +0100 |
---|---|---|
committer | jonas <himself@jonasgunz.de> | 2018-12-26 15:18:23 +0100 |
commit | 905f5ad1f16d2ea719eb40c311609f8fad46fd95 (patch) | |
tree | 95011d6ca3fdf02a08b529586575c49d88f41cb1 | |
parent | 79deae78d89757b3e1a53b5d990c28cc70d4175d (diff) | |
download | termgl-905f5ad1f16d2ea719eb40c311609f8fad46fd95.tar.gz |
Fixed render problem in performance Render mode.
in render.cpp:render() moved gotoxy() out of if(bChanged) fixed Issue.
Not optimal
-rw-r--r-- | AmpelJonas/cRender.cpp | 50 | ||||
-rw-r--r-- | AmpelJonas/cRender.h | 3 | ||||
-rw-r--r-- | AmpelJonas/main.cpp | 44 |
3 files changed, 83 insertions, 14 deletions
diff --git a/AmpelJonas/cRender.cpp b/AmpelJonas/cRender.cpp index 1463010..bc271b8 100644 --- a/AmpelJonas/cRender.cpp +++ b/AmpelJonas/cRender.cpp @@ -5,7 +5,8 @@ cRender::cRender(char _backound, WORD _color, int _sx, int _sy) { bBlockRender = false; //If this Constructor is used, this instance is not inherited, thus render() doesn't need to be blocked iLastError = _OK_; - sizeX = sizeY = 0; + sizeX = 0; + sizeY = 0; cBackound = _backound; wBackColor = _color; @@ -33,6 +34,7 @@ cRender::cRender(char _backound, WORD _color, int _sx, int _sy) setBufferSize({_sx,_sy}); #endif + setConsoleEcho(false); clear(true); //Init backround array //forceReRender(); }//render() @@ -140,25 +142,27 @@ int cRender::render(void) for (int i = 0; i < sizeY; i++) { for (int o = 0; o < sizeX; o++) { + gotoxy(o,i); //Moving this out of if fixed Render problem... Not optimal, though better for performance if(bChanged[o][i]) { - gotoxy(o,i); - #ifdef _WIN32 SetConsoleTextAttribute(hstdout, wColor[o][i] | _COL_INTENSITY); - cout << cScreen[o][i]; + //cout << cScreen[o][i]; + printf("%c", cScreen[o][i]); #elif __linux__ - - cout << "\033["<< wColor[o][i] <<"m"<< cScreen[o][i]; - + //cout << "\033["<< wColor[o][i] <<"m"<< cScreen[o][i]; + printf("\033[%im%c", wColor[o][i], cScreen[o][i]); #endif } - //else {} - bChanged[o][i] = false; + bChanged[o][i] = false; } + } + + gotoxy(sizeX - 1, sizeY - 1); + return 0; } @@ -181,7 +185,7 @@ int cRender::clear(bool _forceReRender) int cRender::clear() { - clear(false); + return clear(false); //false doesn't work! } @@ -306,3 +310,29 @@ void cRender::forceReRender() } } } + +void cRender::setConsoleEcho(bool _enable) +{ +#ifdef WIN32 + HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); + DWORD mode; + GetConsoleMode(hStdin, &mode); + + if( !_enable ) + mode &= ~ENABLE_ECHO_INPUT; + else + mode |= ENABLE_ECHO_INPUT; + + SetConsoleMode(hStdin, mode ); + +#else + struct termios tty; + tcgetattr(STDIN_FILENO, &tty); + if( !_enable ) + tty.c_lflag &= ~ECHO; + else + tty.c_lflag |= ECHO; + + (void) tcsetattr(STDIN_FILENO, TCSANOW, &tty); +#endif +} diff --git a/AmpelJonas/cRender.h b/AmpelJonas/cRender.h index 00f94e2..ba5b9aa 100644 --- a/AmpelJonas/cRender.h +++ b/AmpelJonas/cRender.h @@ -1,9 +1,11 @@ #pragma once #include <stdlib.h> +#include <stdio.h> #include <string> #include <math.h> #include <iostream> +#include <termios.h> #ifdef __linux__ #include <unistd.h> @@ -137,6 +139,7 @@ private: void forceReRender(); + void setConsoleEcho(bool _enable); #ifdef __linux__ sPos getConsoleWindowSize(); #endif diff --git a/AmpelJonas/main.cpp b/AmpelJonas/main.cpp index ea729ac..18b483e 100644 --- a/AmpelJonas/main.cpp +++ b/AmpelJonas/main.cpp @@ -9,7 +9,45 @@ int main() unsigned long int framecounter = 0; cRender a(' ', _COL_DEFAULT, 10,10); a.render(); - cObjectHandler b(&a); + + sPos pos = {0,10}; + int dirX = 1; + int dirY = -1; + + while(1) + { + pos.x += 2 * dirX; + pos.y += 1 * dirY; + + if(pos.x >= a.getSize().x) { + pos.x = a.getSize().x; + dirX *= -1; + } + if(pos.x <= 0) { + pos.x = 0; + dirX *= -1; + } + + if(pos.y >= a.getSize().y) { + pos.y = a.getSize().y; + dirY *= -1; + } + if(pos.y <= 0) { + pos.y = 0; + dirY *= -1; + } + + a.clear(); + a.drawPoint('X', pos, true, _COL_GREEN); + a.drawText(to_string(framecounter), {0,0}, _COL_RED); + a.render(); + + framecounter++; + //cin.get(); + //usleep(100*1000); + } + + /*cObjectHandler b(&a); cObject x(1,1); int i = b.createObject(&x); @@ -48,8 +86,6 @@ int main() framecounter++; //cin.get(); usleep(100*1000); - //for(unsigned int i = 0; i < 6000; i++) - //for(unsigned int o = 0; o < 3000; o++); - } + }*/ return 0; } |