Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optimize MAX_ Looping
#1
Tutorial is not yet Finished

By: William
Difficulty: 2/5

Introduction
This will make the looping smaller for all of your MAX_ (ex. MAX_MAPS, MAX_ITEMS...). So instead of looping from 1 to 1000, maybe you only have 50edited maps, then it will loop from 1 to 50 instead. Of course, if you are making your own game using a source, you can simply choose your own MAX value, and you can probably do that for a engine too. But anyway, I'll make this tutorial for all of you anyway. This is recommended for engines, since the users of the engine doesn't really consider the MAX and often has it on 1000. Which means 1000 loops for probably around 30maps for example.

Server Side
First of all, open frmServer and go into Private Sub Form_load() At the bottom of that sub, add:
Code:
Call SetHighMaxMap
Call SetHighMaxItems
Call SetHighMaxNPCS
Call SetHighMaxItems
Call SetHighMaxShops
Call SetHighMaxSpells
Now, in the bottom of modGameLogic, add:
Code:
Public Sub SetHighMaxMap()
Dim FilePath As String
Dim f As Long, i As Long, Added As Long

    For i = 1 To MAX_MAPS
        f = FreeFile
        FilePath = App.Path & "\Maps\Map" & i & ".dat"
        Open FilePath For Binary As #f
            Get #f, , HighMap(i)
            If HighMap(i).HighTile(0, 0).Ground  0 Then
                HIGH_MAX_MAPS = i
            Elseif HighMap(i).HighTile(0, 0).Mask  0 Then
                HIGH_MAX_MAPS = i
            Elseif HighMap(i).HighTile(0, 0).Fringe  0 Then
                HIGH_MAX_MAPS = i
            End if
        Close
    Next i
End Sub

Public Sub SetHighMaxItems()
End Sub
Public Sub SetHighMaxNPCS()
End Sub
Public Sub SetHighMaxItems()
End Sub
Public Sub SetHighMaxShops()
End Sub
Public Sub SetHighMaxSpells()
End Sub
Now for HIGH_MAX_MAPS replace all but these:
Code:
Sub SaveMaps()
Sub LoadMaps()
Sub CheckMaps()

Under Construction
Reply
#2
In most games i've seen, if they have say 1000 maps, and only use 50 of them, they still usually put a map at #1000, thus rendering this useless. Reguardless, this is a still a good tutorial.
Reply
#3
Just to point out, you don't have to use

Get, , HighMap(i)

You can just keep using your normal Map(i), so you don't have to point another variable at the maprec... Same with the tile part.

It may also be better... to do this by the 'Revision' variable from the maprec. When maps are cleared... it is automatically set to 0. It doesn't increase unless someone edits the map...
Reply
#4
NOt going to complete the tutorial, you get a hint from whats there now. ANd this sisnt really a good way.
Reply
#5
If it isn't a good method, then why keep the tut at all?
Reply
#6
Since it is bad practice in the first place to just jump numbers like that, and good coding/designing practice goes hand-in-hand with fast code? :wink:
Reply
#7
Advocate Wrote:If it isn't a good method, then why keep the tut at all?
It's like high_index, it decreases the numbers of loops. But still it doesn't help much.

Spodi Wrote:Since it is bad practice in the first place to just jump numbers like that, and good coding/designing practice goes hand-in-hand with fast code? :wink:
Dont understand what you mean Tongue
Reply
#8
Well what I mean is that you can't write well optimizations if the code is used poorly. For example, there is absolutely no point in skipping around the index of maps and leaving indexes open. Yeah you may want to sort your maps, but do that somewhere else - keep a document of the index, map name and description or whatever, since leaving 100 indexes open between maps "because you might use it later" is just dumb. William has the right idea on using the high index instead of the max index. This also prevents you from even having to specify a max maps value, since the high index does it for you.
Reply
#9
Spodi Wrote:Well what I mean is that you can't write well optimizations if the code is used poorly. For example, there is absolutely no point in skipping around the index of maps and leaving indexes open. Yeah you may want to sort your maps, but do that somewhere else - keep a document of the index, map name and description or whatever, since leaving 100 indexes open between maps "because you might use it later" is just dumb. William has the right idea on using the high index instead of the max index. This also prevents you from even having to specify a max maps value, since the high index does it for you.
Yes, very true. I would not add this to a game, since you have full control over the MAX_, instead it could be added for a engine, since the users are lazy when it comes to decide the max values.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)