[Webinar] Learn how to a build a cloud-first strategyRegister Now


Video game speed optimization (opinions wanted)

Posted on 2000-03-10
Medium Priority
Last Modified: 2010-05-02
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
Question by:drdaves1

Expert Comment

ID: 2603920
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.


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.


Accepted Solution

Vbmaster earned 200 total points
ID: 2604057
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)

Author Comment

ID: 2605596
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...

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question