Richy420Rich Posted February 15, 2015 Author Share Posted February 15, 2015 Hello, I figured I would release this under the credits of Robin and jcsnider.What is it?zlib API utilizes packet compression and decompression, ya'know those tons of packets you send from the server when a player joins the game?**_For i = 1 To MAX_ITEMS_**!!!What this does is caches all of that data, Example: **ItemsCache_Create**. Sends it all in one packet, Example: **SendAllItems(index)**.zlib compresses that packet to make it smaller and decompresses it on the client side.How do I haz it?I simplified this very easily. I have added everything inside a vanilla EO 2.0\. [You may download the source here](https://www.dropbox.com/s/gc4fezbzn6rfr7a/EO%202.0%20Zlib%20Finished.zip?dl=0).Use CTRL+F and search: 'zlibEverything I've ported has this quickfind comment so you can just breeze through adding it all inside your engine.I errors?I forgot to mention that the zlib.dll file must be present in both the server and client folder. :DFinal: As I said, this is credited under Robin, and to jcsnider for porting it in my project. I don't even know if I'm allowed to release this but since VB6 is uh, yeah. I'm just gon' do it. Link to comment Share on other sites More sharing options...
J. Black Posted February 17, 2015 Share Posted February 17, 2015 What are the pros and cons of using this? Link to comment Share on other sites More sharing options...
Rob Janes Posted February 17, 2015 Share Posted February 17, 2015 Size of raw data being sent to each client.The best use of this is compressing MapDataCache buffer count,Before Compression buffer count:Â 643317After Compression buffer count: 4808 Link to comment Share on other sites More sharing options...
Richy420Rich Posted February 17, 2015 Author Share Posted February 17, 2015 ProsMap cache compression is probably the best thing really worth having. As Rob pointed out, compressing is very good with the map data.This ends sending X amount of packets as a vanilla would iterate and send the data as individual packets, caching and sending the cache only requires one compressed packet.Example of what a vanilla does:```Sub SendItems(index)Dim i as longFor i = 1 To MAX_ITEMSSendItemUpdateTo(index) 'Sends each item data separatelyNextEnd Sub```Example of what this will do:```Sub SendAllItems(ByVal index As Long)   Dim Buffer As clsBuffer   Set Buffer = New clsBuffer   Buffer.WriteLong SAllItems   Buffer.WriteBytes AllItemsCache.Data 'Sends the entire cache as 1 packet.   SendDataTo index, Buffer.ToArray()   Set Buffer = NothingEnd Sub```ConsCaching Items/Npcs & etc; still goes through 'For Loop' iterations on the server after each update made to said data, as they need to be re-cached. Link to comment Share on other sites More sharing options...
J. Black Posted February 17, 2015 Share Posted February 17, 2015 > Pros> > Map cache compression is probably the best thing really worth having. As Rob pointed out, compressing is very good with the map data.> > This ends sending X amount of packets as a vanilla would iterate and send the data as individual packets, caching and sending the cache only requires one compressed packet.> >  > > Example of what a vanilla does:> > ```> > Sub SendItems(index)> Dim i as long> > For i = 1 To MAX_ITEMS> SendItemUpdateTo(index) 'Sends each item data separately> Next> > End Sub> ```> Example of what this will do:> > ```> > Sub SendAllItems(ByVal index As Long)> >    Dim Buffer As clsBuffer>    Set Buffer = New clsBuffer>    Buffer.WriteLong SAllItems>    Buffer.WriteBytes AllItemsCache.Data 'Sends the entire cache as 1 packet.>    SendDataTo index, Buffer.ToArray()>    Set Buffer = Nothing> > End Sub> ```> Cons> > Caching Items/Npcs & etc; still goes through 'For Loop' iterations on the server after each update made to said data, as they need to be re-cached.I really didn't get the cons part. They are automatically re-cached or should I do something? If yes, what and when? Link to comment Share on other sites More sharing options...
Marsh Posted February 17, 2015 Share Posted February 17, 2015 Keep in mind compressing a small amount of data may actually end up bigger. I am not sure if the code checks for this case. Either way you wasted time compressing if it does. So do not use this on tiny packets as others have mentioned. Link to comment Share on other sites More sharing options...
Richy420Rich Posted February 17, 2015 Author Share Posted February 17, 2015 @[member="Marsh"] All of the data gets cached before it gets compressed and sent, so there shouldn't be no small packets.@J. Black whenever an item/npc - etc; gets changed and saved from the client editors, it sends the changed data to the server to be saved, on the server end, it saves the data and then it calls for an entire re-cache to include the changes. This con can be primarily due to server spikes when *constantly* messing around with client editors, as it re-iterates 'For Loops' whenever something is saved/changed.```Public Sub ItemsCache_Create()Dim Buffer As clsBuffer, itemnum As LongDim ItemSize As LongDim ItemData() As Byte   Set Buffer = New clsBuffer   For itemnum = 1 To MAX_ITEMS 'Re-iteration everytime an item is saved…       If Len(Trim$(Item(itemnum).Name)) > 0 Then 'Should not send null/empty data.       ItemSize = LenB(Item(itemnum))       ReDim ItemData(ItemSize - 1)       CopyMemory ItemData(0), ByVal VarPtr(Item(itemnum)), ItemSize       Buffer.WriteLong itemnum       Buffer.WriteBytes ItemData       End If   Next   Buffer.CompressBuffer   AllItemsCache.Data = Buffer.ToArray 'Buffers entire cache for its packet sending.   Set Buffer = NothingEnd Sub```I'll follow up and say when you have constants like this:```Public Const MAX_ITEMS = 2000Public Const MAX_NPCS = 1000Public Const MAX_ANIMATIONS = 500Public Const MAX_QUESTS = 1000Public Const MAX_SPELLS = 255Public Const MAX_BOOKS = 255Public Const MAX_SHOPS = 255Public Const MAX_RESOURCES = 255```And a Sub JoinGame(index) doing this:```SendItems indexSendNpcs indexSendAnimations indexSendQuests indexSendSpells indexSendBooks indexSendShops index```And if all or alot of this data is used up (primarily speaking for long term games, such as Ambardia was....)You'd be sending upto...**5520 individual packets…**Caching and compressing turns 5520 individual packets, into 7 packets. Link to comment Share on other sites More sharing options...
JohnPony Posted February 17, 2015 Share Posted February 17, 2015 You're sacrificing CPU time for bandwidth; don't forget that that isn't free. Link to comment Share on other sites More sharing options...
Richy420Rich Posted February 17, 2015 Author Share Posted February 17, 2015 So in actuality, this may be better to be added for games that are already well-built in content, rather than games just starting out. :)Because once all the data is cached at server startup, it won't eat any more CPU (unless content was changed/added). Link to comment Share on other sites More sharing options...
J. Black Posted February 18, 2015 Share Posted February 18, 2015 So, editing things (even the smallest) will cause an unnecessary CPU usage, right? I'll only use this when my game is ready.Thank you guys for the answer and thanks Richy for sharing this! Link to comment Share on other sites More sharing options...
Richy420Rich Posted February 18, 2015 Author Share Posted February 18, 2015 Yes because re-caching uses the For Loop iteration. So even a small change on an item or something will re-init the re-caching process. Link to comment Share on other sites More sharing options...
Alerd Posted June 2, 2015 Share Posted June 2, 2015 How to compress MapData in eo 2.0? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now