eezstreet Posted April 8, 2016 Posted April 8, 2016 (edited) This information is primarily aimed at fellow programmers and is mostly a mind dump of some design which has been a long time coming, frankly. Prior to the engine source code being released, there were two copies of an entity's inventory being stored, one for the client, and one for the server. The server contained the "master copy" of an entity's inventory. Reliable commands are sent to the client every time an item is added or removed from the inventory.This of course has several limitations:A player can only know what items are in their inventory, not other players. Although with another reliable command, you can get sent this information.If a player loses their copy of their inventory on the client (such as through a vid_restart), all of the data needs to be sent back from the server, which increases bandwidth and may drop the client if their inventory is big enough.Reliable commands are limited in size. If an item instance has lots of fields, it might be truncated and therefore invalid on the client.So instead of using a crappy reliable command system, here is a pretty radical idea which I have been sitting on for a while: put it in the entityState. The information would be networked across in the engine via delta encoding and eliminate lots of overhead as well as enable new opportunities for features like trading, variable item qualities, and an "inspect" command to use on other players. In terms of data structures, I am borrowing the concept of components from Raz0r's xsngine. Maybe he will take some inspiration from my idea. Here are my proposed data structures #define ITEMNAME_LEN 64 struct ItemData; struct ItemInstance { uint_fast64_t nHiSeed, nLoSeed; char szInternal[ITEMNAME_LEN]; ItemData* pItemData; // not networked, independently verified on client and server }; struct ItemStack { unsigned nCount; // number of items char szInternal[ITEMNAME_LEN]; // which item it is ItemData* pItemData; // not networked, independently verified on client and server }; typedef struct { bool bStack; union { ItemStack* pStack; ItemInstance* pInstance; } } ItemSlot; struct Inventory { unsigned nRevision; // not networked; change me to signal that something has changed in this inventory ItemSlot* pItemSlots; }; Edited April 8, 2016 by eezstreet removed some code Onysfx and Smoo like this
eezstreet Posted April 10, 2016 Author Posted April 10, 2016 Scrapped in favor of Binary Reliable Commands.
Recommended Posts