Some questing about UniverseObject usage

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
o01eg
Space Kraken
Posts: 167
Joined: Sat Dec 10, 2011 5:46 am

Some questing about UniverseObject usage

#1 Post by o01eg » Thu Sep 06, 2018 9:58 am

When I worked on https://github.com/freeorion/freeorion/issues/1897 I got some question about code to discuss:
  1. Should GeneralizedLocation in universe/Pathfinder.cpp accept std::shared_ptr by value? It doesn't looks like it takes ownership on this parameter.
  2. GeneralizedLocation outputs simple error to log if object is very wrong but actually it foreshadows segfaults. When I fixed segfault I also fix this error. Should GeneralizedLocation throw exception instead of logging error?
  3. m_existing maps aren't specialized by type but appropriate main objects' maps are. Is it intended?
  4. m_existing maps don't require to own objects because those objects are owned by appropriate main objects' maps. What if use std::weak_ptr?
  5. I suppose in possible to change boost::remove_const<T>::type to std::remove_const<T>::type as the game uses c++11.
Gentoo Linux x64, gcc-7.3, boost-1.65.0
Ubuntu Server 18.04 x64, gcc-7.3, boost-1.65.1
Welcome to multiplayer server at freeorion-test.dedyn.io.Version 0.4.8
Donates are welcome: BTC:14XLekD9ifwqLtZX4iteepvbLQNYVG87zK

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12268
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Some questing about UniverseObject usage

#2 Post by Geoff the Medio » Thu Sep 06, 2018 12:11 pm

o01eg wrote:
Thu Sep 06, 2018 9:58 am
Should GeneralizedLocation in universe/Pathfinder.cpp accept std::shared_ptr by value? It doesn't looks like it takes ownership on this parameter.
Could pass by const reference.
m_existing maps aren't specialized by type but appropriate main objects' maps are. Is it intended?
Probably. The main typed object maps are used to look up objects of a particular type and return a pointer of that type. The existing object lists aren't used like that so don't need to store more specialized UniverseObject pointers. That might be a circular rationale, though if they don't need to be specialized, then should they be?
m_existing maps don't require to own objects because those objects are owned by appropriate main objects' maps. What if use std::weak_ptr?
Seems like unnecessary overhead to convert the pointers. Aren't the sets maintained simultaneously anyway?
change boost::remove_const<T>::type to std::remove_const<T>::type as the game uses c++11.
Sounds reasonable.

Post Reply