Entity Index for fast ADT Array access
To save the adt_array index of entity related stuff, i wanted to use an array with all entity indices to get fast access to the adt_array:
Code:
Array[entity] = adt_index; Is it unsafe to use the entity index for that purpose, if i'm aware when an entity used that way gets destroyed/ Can an entity index change without the entity being destroyed("kill")? If yes, can you recommend another way of doing this access in constant time? If no, what is the maximum entity count in CS:GO(i found it to be 4096)... This array would be calculated on every round_start/ So no saving of that entity index in a database. |
Re: Entity Index for fast ADT Array access
Quote:
|
Re: Entity Index for fast ADT Array access
Quote:
My problem with this is, that i don't know what the maximum reference number will be(And i also did not find it anywhere). Since i have to allocate the memory for it, i have to know it beforehand. Can i assume that the maximum will be 4096(as the entity index)? Code:
#define MAX_ENTITYREF 4096 |
Re: Entity Index for fast ADT Array access
Quote:
|
Re: Entity Index for fast ADT Array access
In order for SourceMod to be able to distinguish between entity references and indexes, references have their highest bit set. This means that the actual value for references will be negative and can't easily be used as indexes.
What I would suggest you do instead is convert the entity reference into a string and use a StringMap. If you want an example of this being done check out my CustomKeyValues plugin: https://forums.alliedmods.net/showthread.php?t=306950 I'm sure you can reuse a lot of the code from that. |
Re: Entity Index for fast ADT Array access
Using the entity index directly in your case should be fine (if you only need to handle networkable entities), if you want to be extra safe, store the entref as the first block for each array item and your data after it, then check the entref resolves to the same index on get.
|
Re: Entity Index for fast ADT Array access
Thank you all for the fast responses. :wink:
Quote:
Btw. great plugin. I'm very happy to have it :) |
All times are GMT -4. The time now is 10:32. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.