Video game speed optimization (opinions wanted)

Okay, here's a long one. I'm working on a video game intended for the net. It will have a graphical client to display the placement of 45+ men on a field, amd the server will handle all calculations. It goes through a 45-person cycle to see what each guy is doing, once per round. The rounds are set so that he should run 1 foot per round, which would make it necessary to see him run 24 feet per second at a full bolt (meaning 24 cycles per second).
So far, even though not much AI has been added, the code seems to be running slowly. He (one of 45 in a cycle) is actually taking 45 seconds to run 30 feet at this time (or about 1.5 seconds per cycle). I'm running an AMD K6/2 400 w/64MB RAM on a nice fast ASUS 100MHz board. There are many loops and arrays (3D arrays at times), and the movement algorithms use some average trigonometry.
I've tried experimenting with the graphic optimizations, with a 0% improvement. See, even if 70% of the people aren't moving (therefore also not qualifying for any of my If statements, supposedly avoiding much code), they seem to be taking as much time as a character who is moving and thinking a lot. I'm using a timer control to try to get steady movement, but the interval is set to 5 milliseconds, which none of the cycles are qualifying for.
I guess I am not too familiar with what to expect from VB's speed, but it seems that many other similar applications are blowing away the speed of mine.
MY QUESTIONS: Since this is projected to run on a internet server, which should host many games simultaneously, will it automatically run better? Is there some way to build this code better (I've read many vague tutorials about common speed-wasting mistakes, and I don't have any in my code)? Does Visual C++ make a big difference? What are gamemakers doing to set this up, since they obviously don't have a lag anywhere NEAR this slow?
I don't think anybody will want to go into this at length, but what kind of experiences/opinions do you have? This seems slower by a long shot than my Atari Pac-Man game, circa 1981...
I know these are some difficult questions to answer, but I appreciate any ideas or theories you may be able to contribute.
Thanks in advance,
Dave Gibson
drdaves1Asked:
Who is Participating?
 
VbmasterConnect With a Mentor Commented:
The problem you are experiencing is probably because you are using a VB timer, although you set the timer's interval to 5ms, the minimum is 55 (setting the interval to 5ms will actually mean it will wait for 55ms). To use a shorter interval you will need to create a Windows Multimedia Timer, for more info you can for example look at...

http://www.mvps.org/ccrp/controls/ccrptimer5.htm  (for VB5)
http://www.mvps.org/ccrp/controls/ccrptimer6.htm  (for VB6)
0
 
rd707Commented:
The following pointers may help you to speed up the code.

- Variants as well as taking up more memory take longer to process so limit use to where necessary.

- Use longs where possible as they are 32-bit native and do not require excessive use of internal type conversion routines

- When property values are required, store property values in variables rather than continually accessing properties - this is some 10-20 times faster.

- Use ByVal instead of ByRef where you can as this is also faster. N.B. Unfortunately, ByRef is the default so there is a tendency to put ByVals in almost as an afterthought. Always explictly stating ByRef or ByVal also has the benefit of making it easy to see at a glance unmodified parameters.

But...

VB is not ideal for fast moving graphics games. The Pacman game you mentioned, I know for a fact that this was written in assembler.

I wouldn't profess to know how today's PC games are written (last time I did any serious games programming it was a hybrid of Basic and Z80 assembler on Amstrads) but you definitely need something faster than VB for the graphics intensive stuff.

C & C++ are much faster but are difficult to learn if you haven't already tried them. You could of course write C DLLs to make some bits faster and keep the rest in VB.

For visual application building I would recommend C++ builder from Borland. This is far easier than trying to do Windows programming in C++ or God forbid - C.

rd707
0
 
drdaves1Author Commented:
Yep... I did the math. 38 cycles took 46 seconds, which is 1.210 seconds per cycle. Each cycle had 22 steps for the timer, and at 55ms each step, that comes out to 1.210 cycles! Yer a god. I had a feeling it had nothing to do with the graphics...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.