-
-
Notifications
You must be signed in to change notification settings - Fork 439
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
base: master
Are you sure you want to change the base?
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; |
This reverts commit 96a3cc4.
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! |
Client/game_sa/CGameSA.h
Outdated
@@ -333,7 +333,7 @@ class CGameSA : public CGame | |||
CExplosionManager* m_pExplosionManager; | |||
C3DMarkers* m_p3DMarkers; | |||
CRenderWareSA* m_pRenderWare; | |||
CHandlingManager* m_pHandlingManager; | |||
std::shared_ptr<CHandlingManager> m_HandlingManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be unique_ptr with access by referense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change this on the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change this on the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
Continuation of PR - #3580;
Removed the frequent useless use of eVehicleTypes.