mirror of https://github.com/AxioDL/metaforce.git
CFactoryMgr: Make use of std::array
Same behavior, with stronger typing. We can also leverage the iterator member functions directly.
This commit is contained in:
parent
34eb507a9d
commit
91a2562fff
|
@ -1,9 +1,22 @@
|
||||||
#include "Runtime/CFactoryMgr.hpp"
|
#include "Runtime/CFactoryMgr.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <cctype>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "Runtime/CStopwatch.hpp"
|
#include "Runtime/CStopwatch.hpp"
|
||||||
#include "Runtime/IObj.hpp"
|
#include "Runtime/IObj.hpp"
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
constexpr std::array TypeTable{
|
||||||
|
FOURCC('CLSN'), FOURCC('CMDL'), FOURCC('CSKR'), FOURCC('ANIM'), FOURCC('CINF'), FOURCC('TXTR'), FOURCC('PLTT'),
|
||||||
|
FOURCC('FONT'), FOURCC('ANCS'), FOURCC('EVNT'), FOURCC('MADF'), FOURCC('MLVL'), FOURCC('MREA'), FOURCC('MAPW'),
|
||||||
|
FOURCC('MAPA'), FOURCC('SAVW'), FOURCC('SAVA'), FOURCC('PART'), FOURCC('WPSC'), FOURCC('SWHC'), FOURCC('DPSC'),
|
||||||
|
FOURCC('ELSC'), FOURCC('CRSC'), FOURCC('AFSM'), FOURCC('DCLN'), FOURCC('AGSC'), FOURCC('ATBL'), FOURCC('CSNG'),
|
||||||
|
FOURCC('STRG'), FOURCC('SCAN'), FOURCC('PATH'), FOURCC('DGRP'), FOURCC('HMAP'), FOURCC('CTWK'), FOURCC('FRME'),
|
||||||
|
FOURCC('HINT'), FOURCC('MAPU'), FOURCC('DUMB'), FOURCC('OIDS'),
|
||||||
|
};
|
||||||
|
|
||||||
CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, urde::CInputStream& in,
|
CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, urde::CInputStream& in,
|
||||||
const CVParamTransfer& paramXfer, CObjectReference* selfRef) {
|
const CVParamTransfer& paramXfer, CObjectReference* selfRef) {
|
||||||
|
@ -52,24 +65,19 @@ CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const FourCC TypeTable[] = {
|
|
||||||
FOURCC('CLSN'), FOURCC('CMDL'), FOURCC('CSKR'), FOURCC('ANIM'), FOURCC('CINF'), FOURCC('TXTR'), FOURCC('PLTT'),
|
|
||||||
FOURCC('FONT'), FOURCC('ANCS'), FOURCC('EVNT'), FOURCC('MADF'), FOURCC('MLVL'), FOURCC('MREA'), FOURCC('MAPW'),
|
|
||||||
FOURCC('MAPA'), FOURCC('SAVW'), FOURCC('SAVA'), FOURCC('PART'), FOURCC('WPSC'), FOURCC('SWHC'), FOURCC('DPSC'),
|
|
||||||
FOURCC('ELSC'), FOURCC('CRSC'), FOURCC('AFSM'), FOURCC('DCLN'), FOURCC('AGSC'), FOURCC('ATBL'), FOURCC('CSNG'),
|
|
||||||
FOURCC('STRG'), FOURCC('SCAN'), FOURCC('PATH'), FOURCC('DGRP'), FOURCC('HMAP'), FOURCC('CTWK'), FOURCC('FRME'),
|
|
||||||
FOURCC('HINT'), FOURCC('MAPU'), FOURCC('DUMB'), FOURCC('OIDS')};
|
|
||||||
|
|
||||||
CFactoryMgr::ETypeTable CFactoryMgr::FourCCToTypeIdx(FourCC fcc) {
|
CFactoryMgr::ETypeTable CFactoryMgr::FourCCToTypeIdx(FourCC fcc) {
|
||||||
for (int i = 0; i < 4; ++i)
|
for (size_t i = 0; i < 4; ++i) {
|
||||||
fcc.getChars()[i] = char(toupper(fcc.getChars()[i]));
|
fcc.getChars()[i] = char(std::toupper(fcc.getChars()[i]));
|
||||||
auto search =
|
}
|
||||||
std::find_if(std::begin(TypeTable), std::end(TypeTable), [fcc](const FourCC& test) { return test == fcc; });
|
|
||||||
if (search == std::end(TypeTable))
|
const auto search =
|
||||||
|
std::find_if(TypeTable.cbegin(), TypeTable.cend(), [fcc](const FourCC& test) { return test == fcc; });
|
||||||
|
if (search == TypeTable.cend()) {
|
||||||
return ETypeTable::Invalid;
|
return ETypeTable::Invalid;
|
||||||
return ETypeTable(search - std::begin(TypeTable));
|
}
|
||||||
|
return ETypeTable(std::distance(TypeTable.cbegin(), search));
|
||||||
}
|
}
|
||||||
|
|
||||||
FourCC CFactoryMgr::TypeIdxToFourCC(ETypeTable fcc) { return TypeTable[int(fcc)]; }
|
FourCC CFactoryMgr::TypeIdxToFourCC(ETypeTable fcc) { return TypeTable[size_t(fcc)]; }
|
||||||
|
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
Loading…
Reference in New Issue