29-05-2006, 07:47 PM
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
statements with
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.
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"
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.