ascii pong half way - how to optimise code ?

Started by
2 comments, last by whereiswez 22 years, 9 months ago
i''ve completed my ascii pong game yay ! most of the way eheh .. but it''s quite a ginormous gamefile for being such a simple game .. 1) what''s the best way to optimize its code ? .. 2) what do i have to learn and wheres best to get this ? i got an idea itll be learning to recode it as classes and using bit-math for most of it .. 3) *lol* .. gfx wise is there any way to make the animation better ? .. like a virtual page flipping ascii screen ? .. 4) would i be able to find THAT kind of info online or by tutorial ? .. of course i have started searching .. i just wanted to kno if somebody has better answers to the problem .. 5a) basic code wise .. do if''s compile to less thn switches ? 5b) while loops to for loops ? thanx all for your help, you''ve given me back my programming confidence by helping me complete this sodding game that i thought would''ve been much simpler and found out i was wrong *L*OLO*! ;D
Advertisement
1) direct screen access.

Then you can write directly to those words. I do not know now if high or low byte is the color or the character, but you can try it. In TC it saves you from using ; but I do not know the TC notation of real mode pointers now. I would guess:

#define screen(x,y) ((unsigned short *) (0xB8000000)) [x+80*y]

After which you may do

screen(17,22) = 0x0707 (grey dot, perhaps a ball).

Unfortunately you cannot fix up x/y in Pascal - they are swapped.

If you use C but a more advanced compiler, try compiling it in Turbo C, which generates small DOS executables.

2) Ralf Brown''s Interrupt List

3) Perhaps you can. Double buffering is easy (just make a screen array somewhere), look at memcpy. You could also do page flipping (see Interrupt List, somewhere in INT 10h). An interesting way of improving textmode graphics is by loading your own textmode font - but you do not have an _ASCII_ pong game after that.

4) ???

5 a/b) depends on your compiler. A _good_ compiler generates equal code in these cases. But you can give your compiler a hint: do what is better to read. Do not use ifs do distinguish 100 cases; do not use switch to distinguish exactly two.

If you do not have Turbo C: http://community.borland.com/museum . It is a rather old C/C++ compiler (no STL), but since you did it in C it should work. And avoid where possible!

Just look at the code generated for a

gotoxy/cputch

combination compared to direct graphics memory access.

BTW: If you have Turbo C, you also have a good C online help and graphics library. However, if you want to make bigger projects, get DJGPP (http://www.delorie.com) or Mingw32 (http://www.mingw32.org) and the Allegro graphics library (http://alleg.sourceforge.net), which runs on Windoze, DOS and Linux.
Make sure you compile it in Release mode, too. Taht''ll always reduce the file size.

-Forcas

"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



-Forcaswriteln("Does this actually work?");
quote:Original post by Midnight Coder
An ASCII pong game should run pretty fast in the first place, and because it doesn''t have any real graphics, there''s no optimization you can do their. The only things you can do is optimize some of the math and stuff that the game uses.


*** I moved this response becuase I deleted the double posted topic ***

~deadlinegrunt

This topic is closed to new replies.

Advertisement