Solved

Video game speed optimization (opinions wanted)

Posted on 2000-03-10
3
243 Views
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
0
Comment
Question by:drdaves1
3 Comments
 
LVL 4

Expert Comment

by:rd707
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.

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

by:
Vbmaster earned 50 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

by:drdaves1
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now