-
-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimization Handling (part 3) and Remove big use eVehicleTypes #3848
Optimization Handling (part 3) and Remove big use eVehicleTypes #3848
Conversation
Good initiative! 😀 |
@TracerDS Hello. Maybe I should add WriteDebugEvent to some events? |
what for |
For try-catch Example:
|
No need. |
@TracerDS Would it be worth making AddVehicle return std::unique_ptr? |
if it returns raw pointer then yes |
@TracerDS Do you like the idea of refining the function this way? CHandlingEntry* CHandlingManager::GetModelHandlingData(std::uint32_t model) const noexcept
{
// Within range?
if (!CVehicleManager::IsValidModel(model))
return nullptr;
auto entries = m_ModelEntries.find(model);
if (entries == m_ModelEntries.end())
{
// Get our Handling ID
eHandlingTypes eHandling = GetHandlingID(model);
auto entry = std::make_unique<CHandlingEntry>(&m_OriginalHandlingData[eHandling]);
entries = m_ModelEntries.emplace(model, std::move(entry)).first;
}
return entries->second.get();
} |
I very much do not like the
|
std::move transfers the owner to m_ModelEntries, at least I don't see anything wrong or risky in this. Can set a condition with the "entry" check |
No. |
It transfers ownership, as I know |
No. It only converts the value to rvalue. Thats all. If the value is already a rvalue then the conversion does nothing. This is the basic implementation of template <typename T>
typename remove_reference<T>::type&& move(T&& arg)
{
return static_cast<typename remove_reference<T>::type&&>(arg);
} Lets format it into int only: template<class T> struct remove_reference { typedef T type; };
template<class T> struct remove_reference<T&> { typedef T type; };
template<class T> struct remove_reference<T&&> { typedef T type; };
inline
int&& move(int&& arg)
{
return static_cast<int&&>(arg);
} As you can see no transfer is done by move manually. |
Is that better? // Get our Handling ID
eHandlingTypes eHandling = GetHandlingID(model);
m_ModelEntries[model] = std::make_unique<CHandlingEntry>(&m_OriginalHandlingData[eHandling]);
if (!m_ModelEntries[model])
return nullptr;
entries = m_ModelEntries.find(model); |
Yes |
Is it possible to change to this? // Original handling data
static std::unordered_map<std::size_t, tHandlingData> m_OriginalHandlingData;
static std::unordered_map<std::size_t, std::unique_ptr<CHandlingEntry>> m_OriginalEntries;
// Model handling data
static std::unordered_map<std::size_t, std::unique_ptr<CHandlingEntry>> m_ModelEntries;
static std::unordered_map<std::size_t, bool> m_bModelHandlingChanged;
static std::map<std::string, eHandlingProperty> m_HandlingNames; |
what are the original declarations? |
std::unordered_map will help us for a more dynamic and convenient use std::map<std::string, eHandlingProperty> m_HandlingNames;
// Original handling data unaffected by handling.cfg changes
static SFixedArray<tHandlingData, HT_MAX> m_OriginalHandlingData;
// Array with the original handling entries
static SFixedArray<std::unique_ptr<CHandlingEntry>, HT_MAX> m_OriginalEntries;
// Array with the model handling entries
static SFixedArray<std::unique_ptr<CHandlingEntry>, HT_MAX> m_ModelEntries;
SFixedArray<bool, HT_MAX> m_bModelHandlingChanged; |
I've requested reviews from @TheNormalnij and @tederis, this PR has to be scrutinized for the same reasons as author's prior PR's. Thanks for the PR! |
Thanks for addressing all code reviews, the ones requested by me as per this comment were also fulfilled. Good work with the PR, merging, @G-Moris // Edit: you need to address this one asap, for now we'll have the PR's changes in (and in the upcoming build) with that review comment up for clarification later, because the PR already gives more performance boost than any (trivial) effect of copying data would, so it'll allow early testing and performance benefits for users. Still, answer it, and resolve it properly, thanks. |
Comment due to #mtasa-blue in discord bridge not having that this PR was in fact merged. After discussing with TheNormalnij, we need to keep these things in mind too: #3848 (comment) (see "Edit" at bottom) |
Sorry, I'll make the edits today, I just didn't have time before. |
* Update * Update 2 * Update 3 --------- Co-authored-by: G_Moris <[email protected]>
Continuation of PR - #3580;
Removed the frequent useless use of eVehicleTypes.