could someone help me with comparing?
1st function is very simple.
I want to know how much 2nd's CPU usage is greater than 1st's one. It's obviously much more but how much?
// loop thru all dictionary entries new szDictRetrievedName[MAX_SITENAME_LENGTH] new szArrayRetrievedName[MAX_SITENAME_LENGTH] for(new i; i <= g_iMaxPossibleIndexByName; i++) { server_print("^ti = %i", i)
// retrieve name from dictionary by index ArrayGetString(g_BSnameDict, i, szDictRetrievedName, charsmax(szDictRetrievedName)) server_print("^t^t%s retrieved from dictionary", szDictRetrievedName)
// loop thru all registered entities to finish the job // it could be pretty messed up but is is working for(new j; j <= g_iMaxPossibleIndexByEnt; j++) { server_print("^t^t^tj = %i", j)
if(equal(szArrayRetrievedName, szDictRetrievedName)) { if(equal(szArrayRetrievedName, szSelectedName)) { server_print("^t^t^t^t%s is equal to %s. ok", szArrayRetrievedName, szSelectedName) } else { server_print("^t^t^t^t%s not equal to %s. removing", szArrayRetrievedName, szSelectedName) removeSiteByIndex(j, true) } }
/* if(equal(szDictRetrievedName, szSelectedName)) { server_print("^t^t^t^t%s is equal to %s. ok", szDictRetrievedName, szSelectedName) } else { server_print("^t^t^t^t%s not equal to %s. removing", szDictRetrievedName, szSelectedName) removeSiteByIndex(j, true) } */ } }
server_print("===========") }
2nd (shortened, without debug messages)
PHP Code:
pickSiteByName(const szSelectedName[]) { new szDictRetrievedName[MAX_SITENAME_LENGTH] new szArrayRetrievedName[MAX_SITENAME_LENGTH]
// loop thru all dictionary entries for(new i; i <= g_iMaxPossibleIndexByName; i++) { // retrieve name from dictionary by index ArrayGetString(g_BSnameDict, i, szDictRetrievedName, charsmax(szDictRetrievedName))
// loop thru all registered entities to finish the job // it could be pretty messed up but is is working for(new j; j <= g_iMaxPossibleIndexByEnt; j++) { ArrayGetString(g_BSname, j, szArrayRetrievedName, charsmax(szArrayRetrievedName))
This is not an answer to your question but I see you're doing something wrong while create the loop
PHP Code:
// The loop should not start from zero because it is an unkown number make 'i = 1' or remove '='
pickSiteByIndex(selected)
{
for(new i; i <= g_iMaxPossibleIndexByEnt; i++)
{
if(i != selected)
{
removeSiteByIndex(i, false)
}
}
}
This is not an answer to your question but I see you're doing something wrong while create the loop
PHP Code:
// The loop should not start from zero because it is an unkown number make 'i = 1' or remove '=' pickSiteByIndex(selected) { for(new i; i <= g_iMaxPossibleIndexByEnt; i++) { if(i != selected) { removeSiteByIndex(i, false) } } }
No its not, first item index in an array is zero, zero is always the first id of a cell. ( Memory address + index )
Now for an answer for the TOPIC, its very obvious the first method is the best for the least CPU usage.
Also show the function where you increment this variable g_iMaxPossibleIndexByEnt
Now for an answer for the TOPIC, its very obvious the first method is the best for the least CPU usage.
2nd method should be used if map designed like a ... (please, check the picture under 2nd spoiler)
Quote:
Originally Posted by Natsheh
Also show the function where you increment this variable g_iMaxPossibleIndexByEnt
sure
It changes only on startup. At the end of this function
PHP Code:
register() { // // what would we have in the vault: // // key - value // mapname:entityID - siteName // de_dust2:48 - B // de_dust2:74 - A //
// open vault g_vault = nvault_open(g_vaultName)
// check if this map already in our database new ent, Float:fOrigin[3] new found, tempKey[MAX_MAPNAME_LENGTH2], tempValue[MAX_SITENAME_LENGTH], timestamp
g_entCount = 0
for(new i; i < charsmax(TARGET_ENTITY); i++) { ent = -1
do { ent = find_ent_by_class(ent, TARGET_ENTITY[i])
if(is_valid_ent(ent)) { // add entity index to database ArrayPushCell(g_BS, ent)
// get entity origin for teleportation purpose get_brush_entity_origin(ent, fOrigin) // add entity origin to database ArrayPushArray(g_BSbrushorigin, fOrigin)
// format a key (mapname:ent) formatex(tempKey, charsmax(tempKey), "%s:%i", g_szMapname, ent)
// try to find it found = nvault_lookup(g_vault, tempKey, tempValue, charsmax(tempValue), timestamp)
// if key is not found then create a dummy (mapname:ent - index) if(!found) { // create the key from mapname and entity index formatex(tempKey, charsmax(tempKey), "%s:%i", g_szMapname, ent) // create a value that should be manually changed ingame formatex(tempValue, charsmax(tempValue), "%i", g_entCount)
// push key-value to the vault nvault_set(g_vault, tempKey, tempValue)
log_amx("[nVault] Entry %i: added new key ^"%s^" with value of ^"%s^"", g_entCount, tempKey, tempValue) } else { log_amx("[nVault] Entry %i: found key ^"%s^" with value of ^"%s^"", g_entCount, tempKey, tempValue) }
// add a value to database ArrayPushString(g_BSname, tempValue) server_print("pushed %s to g_BSname", tempValue)
// if key is exist, get its value and ++ it // otherwise create it new j if(TrieGetCell(g_BScount, tempValue, j)) { // sure, we can do nothing here instead of changing that cell :D j++ TrieSetCell(g_BScount, tempValue, j) } else { TrieSetCell(g_BScount, tempValue, 0) }
g_entCount++ } } while(ent) }
// create an iterator for filling dictionary // maybe will use another method new TrieIter:iter = TrieIterCreate(g_BScount) { new key[MAX_SITENAME_LENGTH]
while(!TrieIterEnded(iter)) { // get site name TrieIterGetKey(iter, key, charsmax(key)) //add the existing one to the dictionary ArrayPushString(g_BSnameDict, key)
log_amx("[TrieIter] %s site registered in the dictionary", key)
// go to next iteration TrieIterNext(iter) } }
// destroy an iterator TrieIterDestroy(iter)
if(g_entCount) { log_amx("====================") log_amx("found %i bombsite(s)", g_entCount) } else { log_amx("no bombsites have been found") }
if you have a question: why do u create another one stupid trie?
I added a cVar designed to avoid incidents, such as in "de_prodigy" or "de_torn" where for 1 site there are 3 separate entities.
And it gonna choose between that 4 entities. And sure will remove 3 of them.
(This plugin is pretty useless in that cases.)
But if this cvar is enabled, plugin gonna choose bombsites by their names instead of their entities.
A site on de_torn:
It is made of 3 separate entities. And removing by index will remove 3 random entities of 4. (I just write here the same was written above xd)