Note that there are some explanatory texts on larger screens.

plurals
  1. PODOS ASCII Animation Lagging without constant input, Turbo C compiled
    primarykey
    data
    text
    <p>Here's an oddity from the past!</p> <p>I'm writing an ASCII Pong game for the command prompt (Yes yes oldschool) and I'm writing to the video memory directly (Add. 0xB8000000) so I know I'm rendering quickly (As opposed to gotoxy and then printf rendering)</p> <p>My code works fine, the code compiles fine under Turbo C++ V1.01 BUT the animation lags... now hold on hold on, there's a cavaet! Under my super fast boosted turbo Dell Core 2 Duo this seems logical however when I hold a key on the keyboard the animation becomes smooth as a newly compiled baby's bottom.</p> <p>I thought maybe it was because I was slowing the computer down by overloading the keyboard buffer (wtf really? come on...) but then I quickly smartened up and tried compiling for DJGPP and Tiny C Compiler to test if the results are the same. On Tiny C Compiler I found I coulnd't compile 'far' pointer types... still confused on that one but I was able to compile for DJGPP and it the animation ran smoothly!</p> <p>I want to compile this and have it work for Turbo C++ but this problem has been plagueing me for the past 3 days to no resolve. Does anyone know why the Turbo C++ constant calls to my rendering method (code below) will lag in the command prompt but DJGPP will not? I don't know if I'm compiling as debug or not, I don't even know how to check if I am. I did convert the code to ASM and I saw what looked to be debugging data at the header of the source so I don't know...</p> <p>Any and all comments and help will be greatly appreciated!</p> <p>Here is a quick example of what I'm up against, simple to compile so please check it out:</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;dos.h&gt; #include&lt;time.h&gt; #define bX 80 #define bY 24 #define halfX bX/2 #define halfY bY/2 #define resolution bX*bY #define LEFT 1 #define RIGHT 2 void GameLoop(); void render(); void clearBoard(); void printBoard(); void ballLogic(); typedef struct { int x, y; }vertex; vertex vertexWith(int x, int y) { vertex retVal; retVal.x = x; retVal.y = y; return retVal; } vertex vertexFrom(vertex from) { vertex retVal; retVal.x = from.x; retVal.y = from.y; return retVal; } int direction; char far *Screen_base; char *board; vertex ballPos; void main() { Screen_base = (char far*)0xB8000000; ballPos = vertexWith(halfX, halfY); direction = LEFT; board = (char *)malloc(resolution*sizeof(char)); GameLoop(); } void GameLoop() { char input; clrscr(); clearBoard(); do { if(kbhit()) input = getch(); render(); ballLogic(); delay(50); }while(input != 'p'); clrscr(); } void render() { clearBoard(); board[ballPos.y*bX+ballPos.x] = 'X'; printBoard(); } void clearBoard() { int d; for(d=0;d&lt;resolution;d++) board[d] = ' '; } void printBoard() { int d; char far *target = Screen_base+d; for(d=0;d&lt;resolution;d++) { *target = board[d]; *(target+1) = LIGHTGRAY; ++target; ++target; } } void ballLogic() { vertex newPos = vertexFrom(ballPos); if(direction == LEFT) newPos.x--; if(direction == RIGHT) newPos.x++; if(newPos.x == 0) direction = RIGHT; else if(newPos.x == bX) direction = LEFT; else ballPos = vertexFrom(newPos); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload