Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Optmizations
#1
This isn't going to go too in-depth, but it will be a general article of how to speed up your game or engine.

First, a background of size information:
Byte is the "smallest" value. Values range from 0 to 255
Total Memory: 1 Byte

Boolean. Used to Represent if a Statement is True or False.
Total Memory: 2 Bytes

Integer is a larger value. Values range from -32765 to 32765
Total Memory: 2 Bytes

Single. Values Range from 0 to 65530
Total Memory: 2 Bytes

Long. Values Range from 0 to 131060
Total Memory: 4 Bytes

String. Are used for Recording Strings of Characters
Total Memory: 10 bytes plus the string length

Fixed String. A Pre-Determined string of characters
Total Memory: Thier Length

Double. A lot more than a Long.
Total Memory: Unknown

So basically, the smaller one that you use, the more memory it will save. Know ahead of time what you will be using variables for, and how much you will need from them. For example, a boolean is 2 bytes, but, you can use byte and instead of using true and false, you can use a 0 and a 1. Reducing memory used won't substantially speed up your game/engine, but it's a good place to start.

Convert Your Packets to Byte Arrays
This one is a bit more difficult to do, but will definately pay off in the long run. All Packets are currently sent and recieved as strings. If you use the forementioned chart, you'll notice that bytes are much smaller than strings, which well make sending/recieving packets go much faster. A full tutorial for this can be found on the back-up forum in the approved tutorials section

Use IOCP for your server if it all possible
IOCP handles connections much differently than WinSock, and can support MANY more players on a standard server than winsock can. The only "downside" is that it must be hosted on an XP, or Windows2003 Server Edition operating system. But, if you weren't planning to host on a Linux Server, why would you choose anything else?

Use a PacketBuffer and Zlib if you can't use Byte Arrays
Byte Array Packets can be a bit difficult to understand, so it may be easier for some people to use Zlib, which compresses your packets, and a Packetbuffer, which better manages the way your packets are sent or recieved. Tutorials for both can be found on the backup forum.

Get Rid of your INI files, and quick.
This is a big one, and it will greatly contribute to the speed of your project. Dave's binary tutorial has great examples of converting your INI files into Binary files which will greatly increase saving/loading/sending times. The tutorial can be found in the approved tutorial section on the Backup MSE Forum.

Stop using "".
It's slower than using vbNullString. Go through your code, and everywhere that you can find a "", replace it with vbnullstring. This will also slightly help increase your game speed.

Basic String Optimizations.
Changing your strings to the following may also slightly help to optimize your game:

The Original - The Optimized Version:

Trim( - Trim$(
Left( - Left$(
Right( - Right$(
Parse( - Parse$(
LCase( - LCase$(
UCase( - UCase$(

Finally. Converting from If/Else/ElseIf/End Ifs, to Select Case. Select Case is just a faster function. The best place to start (although it takes the longest time to complete) is in your modHandleData. At the beginning of the mod (after the dimmed statements, but before the first If LCase(Parse(0)), Add this statement.

Select Case LCase$(Parse$(0))

then, replace all of your
Code:
If Lcase(Parse(0)) = "w/e"
statements with
Code:
Case "w/e"

Then, at the end of Sub HandleData, but before the "end sub", add an "end select". Everywhere that you're able to convert from If/End If statements to Select Case statements will help you to optimize the game.



If you have any more suggestions, or corrections, please let me know so i can adjust the tutorial accordingly.
Reply
#2
Great guide Obsidian, really nice for you to making this. This will truly help my game. Since now I know which things to do, instead of going through all kinds of tutorials for speed.

Thank you.
Reply
#3
Sorry for doulbe post. But do you really need to do this:

Quote:Finally. Converting from If/Else/ElseIf/End Ifs, to Select Case. Select Case is just a faster function.

Will that actually help at all?

Isnt it better to use a Fixed String than a String since FIxed String is only its length?

I just had this idea now, for all the different player commands you are using as Long, because that can handle more than a byte (255). But no MS game needs to be able to carry more than 255. SO why not make all those longs into bytes. Wouldn't that like half the packet size all over the game?
Reply
#4
The select case is slighly faster.

It is better to use Fixed Strings. (ex. Public Const Name_Length As String * 20)

Not really sure what you mean by the last one.
Reply
#5
The last one I ment that if you check anything that handles the player index, it defined as a long. Not really necessary, since each time it sends the index, its a lond. It should be a byte instead.
Reply
#6
Yeah thats what I mean. Always a small change Tongue
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)