Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Improving engine speed


iHero
 Share

Recommended Posts

**Client~Side**

> modGameLogic

In _Sub GameLoop_ find:

```
' Lock fps

If Not FPS_Lock Then

Do While GetTickCount < Tick + 15

Sleep 1

Loop

End If
```

Replace for:

```
' Lock fps

If Not FPS_Lock Then

Do While GetTickCount < Tick + 10

Sleep 1

Loop

End If
```

**Server~Side**

> modServerLoop

At the beginning of the Sub ServerLoop add:

```
Dim MapNum as Integer, LastUpdateMapLogic As Long
```

Find:

```
If Tick > tmr25 Then

For i = 1 To Player_HighIndex

If IsPlaying(i) Then

' check if they've completed casting, and if so set the actual spell going
```

Replace for:

```
' Player loop

For i = 1 To Player_HighIndex

If IsPlaying(i) Then

If Tick > tmr25 Then

' check if they've completed casting, and if so set the actual Spell going
```

Find:

```

' Checks to update player vitals every 5 seconds - Can be tweaked

If Tick > LastUpdatePlayerVitals Then

UpdatePlayerVitals

LastUpdatePlayerVitals = GetTickCount + 5000

End If

' Checks to spawn map items every 5 minutes - Can be tweaked

If Tick > LastUpdateMapSpawnItems Then

UpdateMapSpawnItems

LastUpdateMapSpawnItems = GetTickCount + 300000

End If

' Checks to save players every 5 minutes - Can be tweaked

If Tick > LastUpdateSavePlayers Then

UpdateSavePlayers

LastUpdateSavePlayers = GetTickCount + 300000

End If
```

And delete

Find:

```
End If

Next

frmServer.lblCPS.Caption = "CPS: " & Format$(GameCPS, "#,###,###,###")

tmr25 = GetTickCount + 25

End If
```

Replace for:

```
tmr25 = GetTickCount + 25

End If

' Checks to update player vitals every 5 seconds - Can be tweaked

If Tick > LastUpdatePlayerVitals Then

UpdatePlayerVitals i

LastUpdatePlayerVitals = GetTickCount + 5000

End If

' Checks to save players every 5 minutes - Can be tweaked

If Tick > LastUpdateSavePlayers Then

UpdateSavePlayers i

LastUpdateSavePlayers = GetTickCount + 300000

End If

End If

Next
```

Find:

```
' Check for disconnections every half second

If Tick > tmr500 Then

For i = 1 To MAX_PLAYERS

If frmServer.Socket(i).State > sckConnected Then

Call CloseSocket(i)

End If

Next

UpdateMapLogic

tmr500 = GetTickCount + 500

End If
```

Replace for:

```
' Check for disconnections every half second

If Tick > tmr500 Then

For i = 1 To MAX_PLAYERS

If frmServer.Socket(i).State > sckConnected Then

Call CloseSocket(i)

End If

Next

tmr500 = GetTickCount + 500

End If
```

Find:

```
If Tick > tmr1000 Then

If isShuttingDown Then

Call HandleShutdown

End If

tmr1000 = GetTickCount + 1000

End If
```

Below add:

```
For MapNum = 1 To MAX_MAPS

' Checks to spawn map items every 5 minutes - Can be tweaked

If Tick > LastUpdateMapSpawnItems Then

UpdateMapSpawnItems MapNum

LastUpdateMapSpawnItems = GetTickCount + 300000

End If

' update map logic

If Tick > LastUpdateMapLogic Then

UpdateMapLogic MapNum

LastUpdateMapLogic = GetTickCount + 500

End If

Next
```

Find:

```
' Calculate CPS

If TickCPS < Tick Then

GameCPS = CPS

TickCPS = Tick + 1000

CPS = 0

Else

CPS = CPS + 1

End If
```

Below add:

```
' Set server CPS on label

frmServer.lblCPS.Caption = "CPS: " & Format$(GameCPS, "#,###,###,###")
```

Replace _Sub UpdateSavePlayers_ for:

```

Private Sub UpdatePlayerVitals(ByVal index As Integer)

If Not TempPlayer(index).stopRegen Then

If GetPlayerVital(index, Vitals.HP) <> GetPlayerMaxVital(index, Vitals.HP) Then

Call SetPlayerVital(index, Vitals.HP, GetPlayerVital(index, Vitals.HP) + GetPlayerVitalRegen(index, Vitals.HP))

Call SendVital(index, Vitals.HP)

' send vitals to party if in one

If TempPlayer(index).inParty > 0 Then SendPartyVitals TempPlayer(index).inParty, index

End If

If GetPlayerVital(index, Vitals.MP) <> GetPlayerMaxVital(index, Vitals.MP) Then

Call SetPlayerVital(index, Vitals.MP, GetPlayerVital(index, Vitals.MP) + GetPlayerVitalRegen(index, Vitals.MP))

Call SendVital(index, Vitals.MP)

' send vitals to party if in one

If TempPlayer(index).inParty > 0 Then SendPartyVitals TempPlayer(index).inParty, index

End If

End If

End Sub
```

Replace _Sub UpdateSavePlayers_ for:

```

Private Sub UpdateSavePlayers(ByVal index As Integer)

Dim i As Long

' Prevent subscript out range

If Not IsPlaying(index) Then Exit Sub

' Save player

Call TextAdd("Saving all online players...")

Call SavePlayer(index)

Call SaveBank(index)

End Sub
```

Find:

```
Private Sub UpdateMapSpawnItems()
```

Replace for:

```
Private Sub UpdateMapSpawnItems(Y As Integer)
```

Find:

```
Dim Y As Long

' ///////////////////////////////////////////

' // This is used for respawning map items //

' ///////////////////////////////////////////

For Y = 1 To MAX_MAPS

' Make sure no one is on the map when it respawns

If Not PlayersOnMap(Y) Then
```

And delete. At the end of the sub find:

```
End If

DoEvents

Next
```

And delete. Find:

```
Private Sub UpdateMapLogic()
```

Replace for:

```
Private Sub UpdateMapLogic(MapNum As Integer)
```

Find:

```
, mapNum As Long
```

And delete. Find:

```
For mapNum = 1 To MAX_MAPS
```

And delete. Find:

```
If PlayersOnMap(mapnum) = YES Then
```

And delete. Find:

```
End If

DoEvents

Next

' Make sure we reset the timer for npc hp regeneration

If GetTickCount > GiveNPCHPTimer + 10000 Then

GiveNPCHPTimer = GetTickCount

End If

' Make sure we reset the timer for door closing

If GetTickCount > KeyTimer + 15000 Then

KeyTimer = GetTickCount

End If
```

Replace for:

```
DoEvents

' Make sure we reset the timer for npc hp regeneration

If GetTickCount > GiveNPCHPTimer + 10000 Then

GiveNPCHPTimer = GetTickCount

End If
```

In _Sub NpcDir_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

In _Sub SendMapItemsToAll_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

In _Sub SendMapNpcVitals_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

In _Sub SendMapNpcsTo_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

In _Sub SendMapNpcsToMap_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

In _Sub SendResourceCacheToMap_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(GetPlayerMap(index)) = NO Then Exit Sub
```

In _Sub SendMapSound_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(GetPlayerMap(index)) = NO Then Exit Sub
```

In _Sub SendSpawnItemToMap_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

In _Sub SendNpcXY_ above of:

```
Set Buffer = New clsBuffer
```

Add:

```
' Check if have player on map

If PlayersOnMap(MapNum) = NO Then Exit Sub
```

**Credits**

Ricardo
Link to comment
Share on other sites

```

' Lock fps

If Not FPS_Lock Then

Do While GetTickCount < Tick + 10

Sleep 1

Loop

End If
```

Yes this will render the game faster but overall it will lead to more CPU usage. Oh and stop using integers, they're slow in VB, use longs or bytes instead.

Everything else however looks very good, great work!
Link to comment
Share on other sites

> ```
>
> ' Lock fps
>
> If Not FPS_Lock Then
>
> Do While GetTickCount < Tick + 10
>
> Sleep 1
>
> Loop
>
> End If
> ```
>
> Yes this will render the game faster but overall it will lead to more CPU usage. Oh and stop using integers, they're slow in VB, use longs or bytes instead.
>
> Everything else however looks very good, great work!

Sounds like a pretty decent compromise.
Link to comment
Share on other sites

I'd much rather exchange CPU usage for a more fluent game play. Any game that reaches any players and contains decent features will lag intensely. Hopefully this helps!
Link to comment
Share on other sites

> Actually, question.
>
> It won't compile because the variable mapnum isn't defined. Do I need to add mapNum as long in every sub that we added
>
> ' Check if have player on map
>
> If PlayersOnMap(MapNum) = NO Then Exit Sub
>
> ?

Sorry, I'll fix it. Wait a few seconds
Link to comment
Share on other sites

The fix (In topic is already tidy)

> In _Sub SendResourceCacheToMap_ above of:
>
> ```
> Set Buffer = New clsBuffer
> ```
>
> Add:
>
> ```
> ' Check if have player on map
>
> If PlayersOnMap(GetPlayerMap(index)) = NO Then Exit Sub
> ```
>
> In _Sub SendMapSound_ above of:
>
> ```
> Set Buffer = New clsBuffer
> ```
>
> Add:
>
> ```
> ' Check if have player on map
>
> If PlayersOnMap(GetPlayerMap(index)) = NO Then Exit Sub
> ```
Link to comment
Share on other sites

> Sorry, I'll fix it. Wait a few seconds

Also, on```

' Checks to update player vitals every 5 seconds - Can be tweaked

If Tick > LastUpdatePlayerVitals Then

UpdatePlayerVitals i

LastUpdatePlayerVitals = GetTickCount + 5000

End If

' Checks to save players every 5 minutes - Can be tweaked

If Tick > LastUpdateSavePlayers Then

UpdateSavePlayers i

LastUpdateSavePlayers = GetTickCount + 300000

End If

End If

Next
```

it won't compile with the "i" there after vitals and players

I removed it and it compiled.
Link to comment
Share on other sites

> The fix (In topic is already tidy)

In EO 2.0, you don't need to have the changes you made to _Sub SendResourceCacheToMap._ It already has mapnum in the sub itself.

I haven't said it yet, though, so I wanted to say THANK YOU. This is fantastic.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...