Are MMOItems faster than sended packets ?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Are MMOItems faster than sended packets ?

Postby genar » 30 Mar 2018, 14:55

Good evening !

Im currently working on the "Inventory" mechanic especially the drop / pickup part of the items.
When the player drops an item, i delete the row out of the inventoryTable and create a new row in the items table which contains all items laying around in the world. At the same time i create a mmoItem with the ItemID, Amount and two other little variables.

I noticed that it seems to take a bit longer using MMOItems instead of just sending an packet, is this true ?
Theres also a little delay of about 500 ms - 1 sec when dropping an item im not sure if this happens due to the mysql querys or the mmoitem.

Heres a little code snippet just for showcase

Code: Select all

public static void dropItemsOutOfInventory(IDBManager dbManager, User user, String itemTypeID, String chunkName, int amount){
      
      try {
         
         if(removeItemsFromInventory(dbManager, user, itemTypeID, amount, false)){
            
            String positionX = user.getVariable(UserVariables.PositionLatLngX.toString()).getStringValue();
            
            String positionY = user.getVariable(UserVariables.PositionLatLngY.toString()).getStringValue();
            
            
            String position = positionX+";"+positionY;
            
            
            Object insertedRowID = dbManager.executeInsert("INSERT INTO "+ItemColumns.tableName+"("+ItemColumns.itemtype_ID+","+ItemColumns.chunk_ID+","+ItemColumns.position+","+ItemColumns.amount+") values("+itemTypeID+","+SQLSnippets.determineChunkID(chunkName)+",'"+position+"',"+String.valueOf(amount)+")", new Object[]{});
      
            
            InventoryManager.sendUpdatedInventoryItemToPlayer(dbManager, user, itemTypeID);
            
            
            Utils.sfsExtension.trace("<InventoryManager : Droped item and sended back the updated inventory>");
            
            
            MMOItem item = new MMOItem();
            item.setVariable(new MMOItemVariable("ID", insertedRowID.toString()));
            item.setVariable(new MMOItemVariable("itemtypes_ID", itemTypeID));
            item.setVariable(new MMOItemVariable("amount", amount));
            item.setVariable(new MMOItemVariable("chunkName", chunkName));
            
            
            
            Utils.spawnExistingMMOItemInCurrentRoom(user, item, Float.parseFloat(positionX), Float.parseFloat(positionY));
            
            
            Utils.sfsExtension.trace("<InventoryManager : Spawned MMOItem with the certain attributes>");
            
            
         }
         
         
      } catch (SQLException e) {

         Utils.sfsExtension.trace("<InventoryManager : MySql Error "+e.getMessage());
         
         return;

      }
      
   }


Any tipps to make this faster ?
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Are MMOItems faster than sended packets ?

Postby genar » 06 Apr 2018, 11:18

No ideas ?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Are MMOItems faster than sended packets ?

Postby Lapo » 09 Apr 2018, 06:54

Hi,
it's very likely that is due to the database interaction.

You can check it by yourself, by measuring the query time.

Code: Select all

long t1 = System.nanoTime();

// Database code here
// ...

trace("Query time: " + ((System.nanoTime() - t1) / 1000000));

^ Prints the milliseconds for the query time.
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 43 guests