[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Video game speed optimization (opinions wanted)

Posted on 2000-03-10
Medium Priority
263 Views
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.
Dave Gibson
0
Question by:drdaves1
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 4

Expert Comment

ID: 2603920

- 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

LVL 7

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)
0

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

## Featured Post

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
###### Suggested Courses
Course of the Month12 days, 19 hours left to enroll