Jump to content

  • Log In with Google      Sign In   
  • Create Account

ascii pong half way - how to optimise code ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 whereiswez   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 July 2001 - 03:21 AM

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

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 14 July 2001 - 03:43 AM

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.

#3 Forcas   Members   -  Reputation: 181

Like
Likes
Like

Posted 14 July 2001 - 04:10 AM

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."





#4 deadlinegrunt   Members   -  Reputation: 123

Like
Likes
Like

Posted 14 July 2001 - 03:36 PM

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 ***




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS