![]() |
Optimizing Looping (v1 & v2) - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: Optimizing Looping (v1 & v2) (/showthread.php?tid=508) |
Optimizing Looping (v1 & v2) - William - 20-12-2006 Originally posted by Dark Dragon Name: Optimize Looping By: Dark//Dragon Difficulty: 3/5 Version: 1 Notes: Ok, what this will do is add a variable HighIndex, that is equal to the highest assigned index. With that we can greatly optimize looping, because if you have IOCP for example and you're MAX_PLAYERS is 500, 4 players were playing then the player with index 3 left, using the old system, you would waste 497 loops every time there is a "1 To MAX_PLAYERS", but once you have added this system only 1 loop will be wasted. In This version (1), only the server will have the variable, projected in version 2 i will parse the variable to client to opti that too. This was programmed in 3.03, i know many of the MSE changes so i'll try to change my code to be complient, but if there is a mistake, figure it out :wink: All Server Side ++++++++++++++ Part1 : Atcuall Code ++++++++++++++ at the top of modGlobals, under: Code: ' Used for logging add: Code: ' Used for Player looping this is our variable, and we will store stuff here! :wink: At the bottom of modGameLogic, add: Code: Sub SetHighIndex() this will set the variable = to the highest assigned index. now! in modServerTCP, in the sub SocketConnected, under Code: If Not IsBanned(GetPlayerIP(index)) Then add: Code: ' Set The High Index this will set the high index whenever anyone connects also in ModServerTCP, in the sub "CloseSocket", under Code: Call UpdateCaption add Code: Call SetHighIndex this will recalculate the High index whenver anyone disconnects. Ok, Part1 (The Real Code) is done, the next part is mindless :wink: +++++++++++++++ Part2: Mindlessness!! +++++++++++++++ Ok, this entire Part is me telling you where to change Code: For I = 1 to MAX_PLAYERS Code: For I = 1 to HighIndex ModDatabase ============= Sub SaveAllPlayersOnline() ModGameLogic ============= Function TotalOnlinePlayers() As Long Function FindPlayer(ByVal Name As String) As Long Function CanNpcMove(ByVal MapNum As Long, ByVal MapNpcNum As Long, ByVal Dir) As Boolean [4 times for the 4 dirs] Function GetTotalMapPlayers(ByVal MapNum As Long) As Long ModGeneral ============= Sub GameAI() Sub CheckGiveHP() Sub PlayerSaveTimer() ModServerTCP ============= Function IsMultiAccounts(ByVal Login As String) As Boolean Function IsMultiIPOnline(ByVal IP As String) As Boolean Sub SendDataToAll(ByVal Data As String) Sub SendDataToAllBut(ByVal index As Long, ByVal Data As String) Sub SendDataToMap(ByVal MapNum As Long, ByVal Data As String) Sub SendDataToMapBut(ByVal index As Long, ByVal MapNum As Long, ByVal Data As String) Sub AdminMsg(ByVal Msg As String, ByVal Color As Byte) Sub SendWhosOnline(ByVal index As Long) Sub SendJoinMap(ByVal index As Long) modHandleData ============== Player attack packet Map data packet Search packet some of the Subs I might have forgotten, (And not all of them), you need to figure it out, like some of them needed to be left, howver, it will work if they are left out You're done!!! ;_; :lol: Name: Optimize Looping By: Dark//Dragon Difficulty: 3/5 Version: 2 Notes: Ok, in this tutorial, I assume you have already completed V1 of the tutorial, available HERE. What this tutorial is, is the extention onto that tutorial, where i extend the HighIndex variable over to the client, alowing for much optimised looping client side :wink: As Always: Back up your source before starting ANY tutorial! Server Side What will be added server side is a sub to send the variable, and calling that sub wherever the HighIndex is calculated so, At the bottom of modTCP, add: Code: Sub SendHighIndex() i know it LOOKs like it should be SendDataToAll, but for reasons God only knows, it did not work for me, so i did this instead... now, do a search for Code: Call SetHighIndex Code: Call SendHighIndex Server Side Done! Client Side Basically, all the client side is, is a HandleData packet to recive the packet the server is sending, and the mindless replaceing of MAX_PLAYERS is most but not all places..., so without further adu... in modGlobals, under: Code: ' Used for parsing add: Code: ' Used for HighIndex now in modHandleData, under: Code: ' ::::::::::::::::::: add: Code: ' ::::::::::::::::::::::: this recives the highindex packet. Now in all the folowing places, you will have to change Code: For i = 1 to MAX_PLAYERS Code: For i = 1 to HighIndex ModHandleData =========== Check for map packet modGameLogic =========== GameLoop [all of them] Function CanMove [4] FindPlayer there may be more... but it wont hurt if you left them out Name: Optimize Looping By: Dark//Dragon Difficulty: 3/5 Version: 2 Notes: Ok, in this tutorial, I assume you have already completed V1 of the tutorial, available HERE. What this tutorial is, is the extention onto that tutorial, where i extend the HighIndex variable over to the client, alowing for much optimised looping client side :wink: As Always: Back up your source before starting ANY tutorial! Server Side What will be added server side is a sub to send the variable, and calling that sub wherever the HighIndex is calculated so, At the bottom of modTCP, add: Code: Sub SendHighIndex() i know it LOOKs like it should be SendDataToAll, but for reasons God only knows, it did not work for me, so i did this instead... now, do a search for Code: Call SetHighIndex Code: Call SendHighIndex Server Side Done! Client Side Basically, all the client side is, is a HandleData packet to recive the packet the server is sending, and the mindless replaceing of MAX_PLAYERS is most but not all places..., so without further adu... in modGlobals, under: Code: ' Used for parsing add: Code: ' Used for HighIndex now in modHandleData, under: Code: ' ::::::::::::::::::: add: Code: ' ::::::::::::::::::::::: this recives the highindex packet. Now in all the folowing places, you will have to change Code: For i = 1 to MAX_PLAYERS Code: For i = 1 to HighIndex ModHandleData =========== Check for map packet modGameLogic =========== GameLoop [all of them] Function CanMove [4] FindPlayer there may be more... but it wont hurt if you left them out |