Jump to content

efficient guid generation


darkstalker

Recommended Posts

I think it would be nice to re-implement the guid generator so it re-uses unused guids. Currently the code just takes the max value from DB and starts adding from that:

- from ObjectMgr::SetHighestGuids

result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" );
   if( result )
   {
       m_hiItemGuid = (*result)[0].GetUInt32()+1;
       delete result;
   }

- from ObjectMgr::GenerateLowGuid

        case HIGHGUID_ITEM:
           if(m_hiItemGuid>=0xFFFFFFFE)
           {
               sLog.outError("Item guid overflow!! Can't continue, shutting down server. ");
               World::StopNow(ERROR_EXIT_CODE);
           }
           return m_hiItemGuid++;

my item_instance maximum guid is over 3,4 billion, and don't even have that amount of items in db, so this might be a problem.

Link to comment
Share on other sites

there are some SQLs around that lower character/item/creature/gameobject/whatever guids, these do work quite well.

if you want to re-use unused guids, you would have to store them in some array and check for each new guid if its used or free. would consume a LOT of memory and CPU if you ask me...

possibly some auto-renumbering could be implemented on startup, but this would delay startup a lot. imho its better to stick with the current implementation and renumber guids once a month by hand.

Link to comment
Share on other sites

Some guidstypes recently moved and will be moved more into per-map mode.

This for example meaning that each map will have own guid counter and in general will affect only specific map/instance copy until unload. Ofc continents still moslty loaded always, but and in continent this also help slowdown guid counters increase.

Not implemented yet move guid generationfor creatures/GOs to per-map mode also let not generate dynamic guids for static instance spawn, that also slow creature/GO guid counter grow.

Possible item guids can be per-player. I not reseach this case but i think this possible and not remember real need in global item guids counting.

Global guid counters still need for : player guids, pet numbers (maybe per player), guild ids, and auction ids (maybe per auctionhouse).

Link to comment
Share on other sites

i talk about the guids already stored in char db, they can be really high, and all unused guids are lost atm.

i can do this to generate 1 guid from DB

SELECT l.guid + 1 AS start
FROM item_instance AS l
LEFT OUTER JOIN item_instance AS r ON l.guid + 1 = r.guid
WHERE r.guid IS NULL
LIMIT 1;

but really dont know how it would be done correctly

Link to comment
Share on other sites

  • 1 year later...
Some guidstypes recently moved and will be moved more into per-map mode.

This for example meaning that each map will have own guid counter and in general will affect only specific map/instance copy until unload. Ofc continents still moslty loaded always, but and in continent this also help slowdown guid counters increase.

Not implemented yet move guid generationfor creatures/GOs to per-map mode also let not generate dynamic guids for static instance spawn, that also slow creature/GO guid counter grow.

Possible item guids can be per-player. I not reseach this case but i think this possible and not remember real need in global item guids counting.

Global guid counters still need for : player guids, pet numbers (maybe per player), guild ids, and auction ids (maybe per auctionhouse).

I know this topic is old, but this approach is very interesting and needs to be brought up, at least someone will read it and think about a way to implement it, I am sure it's the guid generating used in most games.

Link to comment
Share on other sites

you can use an sql to pack your item guids:

-- Generate a new guid
ALTER TABLE item_instance ADD COLUMN guid_new INT(11) UNSIGNED AUTO_INCREMENT UNIQUE AFTER guid/*, AUTO_INCREMENT = 1000*/;

-- Item data field
UPDATE item_instance SET data = CONCAT(guid_new, ' ', RIGHT(data, LENGTH(data)-LENGTH(SUBSTRING_INDEX(data, ' ', 1))-1));

-- auctionhouse
UPDATE auctionhouse AS ah, item_instance AS it SET ah.itemguid = it.guid_new WHERE ah.itemguid = it.guid;

-- character_gifts
UPDATE character_gifts AS cg, item_instance AS it SET cg.item_guid = it.guid_new WHERE cg.item_guid = it.guid;

-- character_inventory
UPDATE character_inventory AS ci, item_instance AS it SET ci.bag = it.guid_new WHERE ci.bag = it.guid;
UPDATE character_inventory AS ci, item_instance AS it SET ci.item = it.guid_new WHERE ci.item = it.guid;

-- guild_bank_item
UPDATE guild_bank_item AS gb, item_instance AS it SET gb.item_guid = it.guid_new WHERE gb.item_guid = it.guid;

-- mail_items
UPDATE mail_items AS mi, item_instance AS it SET mi.item_guid = it.guid_new WHERE mi.item_guid = it.guid;

-- petition
UPDATE petition AS p, item_instance AS it SET p.petitionguid = it.guid_new WHERE p.petitionguid = it.guid;

-- petition_sign
UPDATE petition_sign AS ps, item_instance AS it SET ps.petitionguid = it.guid_new WHERE ps.petitionguid = it.guid;

-- Put the new guid in place
UPDATE item_instance SET guid = guid_new;
ALTER TABLE item_instance DROP COLUMN guid_new;

this is a bit old so might need update for newer mangos versions

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use