Changeset 25279

Timestamp:
Apr 16, 2021, 6:04:01 PM (3 years ago)
Author:
wraitii
Message:

Improvements on rP25210

See rP25210. Follows comments by @vladislavbelov.

Differential Revision: https://code.wildfiregames.com/D3852

Location:
ps/trunk/source
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/ObjectBase.cpp

    r25210 r25279  
    3232#include <boost/random/uniform_int_distribution.hpp>
    3333
    34 namespace {
    35     int GetQuality(CStr& value)
    36     {
    37         if (value == "low")
    38             return 100;
    39         else if (value == "medium")
    40             return 150;
    41         else if (value == "high")
    42             return 200;
    43         else
    44             return value.ToInt();
    45     }
    46 }
     34namespace
     35{
     36/**
     37 * The maximal quality for an actor.
     38 */
     39static constexpr int MAX_QUALITY = 255;
     40
     41/**
     42 * How many quality levels a given actor can have.
     43 */
     44static constexpr int MAX_LEVELS_PER_ACTOR_DEF = 5;
     45
     46int GetQuality(const CStr& value)
     47{
     48    if (value == "low")
     49        return 100;
     50    else if (value == "medium")
     51        return 150;
     52    else if (value == "high")
     53        return 200;
     54    else
     55        return value.ToInt();
     56}
     57} // anonymous namespace
    4758
    4859CObjectBase::CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, u8 qualityLevel)
     
    762773            return base;
    763774    // This code path ought to be impossible to take,
    764     // because by construction we must have at least one valid CObjectBase of quality 255
     775    // because by construction we must have at least one valid CObjectBase of quality
    765776    // (which necessarily fits the u8 comparison above).
    766777    // However compilers will warn that we return a reference to a local temporary if I return nullptr,
     
    807818    if (root.GetNodeName() == el_actor)
    808819    {
    809         std::unique_ptr<CObjectBase> base = std::make_unique<CObjectBase>(m_ObjectManager, *this, 255);
     820        std::unique_ptr<CObjectBase> base = std::make_unique<CObjectBase>(m_ObjectManager, *this, );
    810821        base->Load(XeroFile, root);
    811822        m_ObjectBases.emplace_back(std::move(base));
     
    841852                {
    842853                    int v = GetQuality(attr.Value);
    843                     if (v > 255)
     854                    if (v > )
    844855                    {
    845                         LOGERROR("Qualitylevel to attribute must not be above 255 (file %s)", pathname.string8());
     856                        LOGERROR("Qualitylevel to attribute must not be above , pathname.string8());
    846857                        return false;
    847858                    }
     
    864875            }
    865876            if (!found_quality)
    866                 quality = 255;
     877                quality = ;
    867878            std::unique_ptr<CObjectBase> base = std::make_unique<CObjectBase>(m_ObjectManager, *this, quality);
    868879            if (use_inline)
     
    904915            m_ObjectBases.emplace_back(std::move(base));
    905916        }
    906         if (quality != 255)
    907         {
    908             LOGERROR("Quality levels must go up to 255 (file %s)", pathname.string8().c_str());
     917        if (quality != )
     918        {
     919            LOGERROR("Quality levels must go up to , pathname.string8().c_str());
    909920            return false;
    910921        }
     
    916927        base->GetQualitySplits(splits);
    917928    ENSURE(splits.size() >= 1);
    918     if (splits.size() > 5)
    919     {
    920         LOGERROR("Too many quality levels (%i) for actor %s", splits.size(), pathname.string8().c_str());
     929    if (splits.size() > )
     930    {
     931        LOGERROR("Too many quality levels (%i) for actor %s);
    921932        return false;
    922933    }
  • ps/trunk/source/ps/ConfigDB.cpp

    r25210 r25279  
    497497void CConfigDB::UnregisterHook(CConfigDBHook&& hook)
    498498{
    499     if (hook.ptr != m_Hooks.end())
    500         m_Hooks.erase(hook.ptr);
    501 }
    502 
    503 void CConfigDB::UnregisterHook(std::unique_ptr<CConfigDBHook>&& hook)
     499    if (hook.tr != m_Hooks.end())
     500        m_Hooks.erase(hook.tr);
     501}
     502
     503void CConfigDB::UnregisterHook(std::unique_ptr<CConfigDBHook> hook)
    504504{
    505505    UnregisterHook(std::move(*hook.get()));
  • ps/trunk/source/ps/ConfigDB.h

    r25210 r25279  
    183183
    184184    void UnregisterHook(CConfigDBHook&& hook);
    185     void UnregisterHook(std::unique_ptr<CConfigDBHook>&& hook);
     185    void UnregisterHook(std::unique_ptr<CConfigDBHook> hook);
    186186
    187187private:
     
    199199    // Point the moved-from hook to end, which is checked for in UnregisterHook,
    200200    // to avoid a double-erase error.
    201     CConfigDBHook(CConfigDBHook&& h) : configDB(h.configDB) { ptr = std::move(h.ptr); h.ptr = configDB.m_Hooks.end(); }
     201    CConfigDBHook(CConfigDBHook&& h) : onfigDB.m_Hooks.end(); }
    202202    CConfigDBHook(const CConfigDBHook&) = delete;
    203203private:
    204     CConfigDBHook(CConfigDB& cdb, std::multimap<CStr, std::function<void()>>::iterator p) : configDB(cdb), ptr(p) {};
    205 
    206     std::multimap<CStr, std::function<void()>>::iterator ptr;
    207     CConfigDB& configDB;
     204    CConfigDBHook(CConfigDB& cdb, std::multimap<CStr, std::function<void()>>::iterator p) : tr(p) {};
     205
     206    std::multimap<CStr, std::function<void()>>::iterator tr;
     207    CConfigDB& onfigDB;
    208208};
    209209
Note: See TracChangeset for help on using the changeset viewer.