if (loadedClasses.size() > 0)
{
auto it = loadedClasses.begin();
auto end = loadedClasses.end();
while (it != end)
{
if ((*it).first.Compare(*blueprintPath) == 0)
return (*it).second;
it++;
}
}
any reason to store the iterator and end as locals?for
loops implicitly do thisfor
loop it's a while
loop.
Unlike for
loops, with while
loops you want to declare your variables outside of the loop scope otherwise the loadedClasses.begin()
and loadedClasses.end()
functions would get called multiple times.
Using a for
loop is different : Everything can be declared in the for
statement (one-liner), and there is dedicated section on this line for your declarations (for (declare_here; ...
).for
loops on my work-in-progress code, except for simple things like an integer counter ^^ (edited)for
loop is turned into a while
loop at compile time anyway, so using for
loops is actually less efficient even if that's negligible). (edited) if (loadedClasses.size() > 0)
{
auto it = loadedClasses.begin();
auto end = loadedClasses.end();
while (it != end)
{
if ((*it).first.Compare(*blueprintPath) == 0)
return (*it).second;
it++;
}
}
any reason to store the iterator and end as locals? AutoFillCorp
i just want to ask about MyBPLoadClass
this thing in itc++
static std::map<unsigned long long, long long> lastRunCommandTime = std::map<unsigned long long, long long>();
MyBPLoadClass()
is to load Blueprint classes only once (instead of loading blueprint classes every time I need them). Basically, when I call MyBPLoadClass()
it will load the blueprint class and stores the result in the loadedClasses
map. Then if I call MyBPLoadClass()
again to load the same blueprint class, instead of loading it again it will return the result that was stored in loadedClasses
map. This function is not mandatory (I could call UVictoryCore::BPLoadClass
function directly), it's just an optimisation to save some processing time. (edited)lastRunCommandTime
map is to limit the number of commands that a user can perform in a given time interval (FILLCROPS_INTERVAL_DELAY
). When a user performs the fill crops command it will store his Steam ID and the current timestamp in that map. Then if the same user tries to do the same command again, the code will check if the time difference between current request and previous request is superior to the given time interval. Basically it does "if (current time - stored time > FILLCROPS_INTERVAL_DELAY)
". So if the time interval has not been reached yet the command will be rejected.
This is not mandatory to do all that (but it's good for performance and security to limit the amount of commands that can be performed in a given time). (edited)c++
static std::map<unsigned long long, long long> lastRunCommandTime = std::map<unsigned long long, long long>();
new
keyword or other memory allocation functions unless it's mandatory. Instead try to declare all your variables with fixed sizes so that they are allocated on the stack. That way you will not have to free the resources with the delete
keyword and you will avoid memory leakage. Try to use UE containers (TArray, TMap, ...) or STD containers (std::list, std::map) when possible because they are efficient and memory/thread safe. See here for details on TArray and how to use them: https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/TArrays/new
keyword or other memory allocation functions unless it's mandatory. Instead try to declare all your variables with fixed sizes so that they are allocated on the stack. That way you will not have to free the resources with the delete
keyword and you will avoid memory leakage. Try to use UE containers (TArray, TMap, ...) or STD containers (std::list, std::map) when possible because they are efficient and memory/thread safe. See here for details on TArray and how to use them: https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/TArrays/ new
keyword or other memory allocation functions unless it's mandatory. Instead try to declare all your variables with fixed sizes so that they are allocated on the stack. That way you will not have to free the resources with the delete
keyword and you will avoid memory leakage. Try to use UE containers (TArray, TMap, ...) or STD containers (std::list, std::map) when possible because they are efficient and memory/thread safe. See here for details on TArray and how to use them: https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/TArrays/ ShooterGameServer.exe
). (edited)