mirror of https://github.com/AxioDL/metaforce.git
more classes added
This commit is contained in:
parent
731d8bbcb4
commit
b51911ed3d
|
@ -1,7 +1,7 @@
|
|||
#ifndef _DNACOMMON_CMDL_HPP_
|
||||
#define _DNACOMMON_CMDL_HPP_
|
||||
|
||||
#include "DNACommon.hpp"
|
||||
#include "PAK.hpp"
|
||||
#include "BlenderConnection.hpp"
|
||||
#include "GX.hpp"
|
||||
#include "TXTR.hpp"
|
||||
|
|
|
@ -3,6 +3,7 @@ make_dnalist(liblist
|
|||
add_library(DNACommon
|
||||
DNACommon.hpp DNACommon.cpp
|
||||
${liblist}
|
||||
PAK.hpp
|
||||
GX.hpp
|
||||
STRG.hpp STRG.cpp
|
||||
TXTR.hpp TXTR.cpp
|
||||
|
|
|
@ -234,409 +234,6 @@ struct WordBitmap
|
|||
Iterator end() const {return Iterator(*this, m_bitCount);}
|
||||
};
|
||||
|
||||
/* PAK entry stream reader */
|
||||
class PAKEntryReadStream : public Athena::io::IStreamReader
|
||||
{
|
||||
std::unique_ptr<atUint8[]> m_buf;
|
||||
atUint64 m_sz;
|
||||
atUint64 m_pos;
|
||||
public:
|
||||
PAKEntryReadStream() {}
|
||||
operator bool() const {return m_buf.operator bool();}
|
||||
PAKEntryReadStream(const PAKEntryReadStream& other) = delete;
|
||||
PAKEntryReadStream(PAKEntryReadStream&& other) = default;
|
||||
PAKEntryReadStream& operator=(const PAKEntryReadStream& other) = delete;
|
||||
PAKEntryReadStream& operator=(PAKEntryReadStream&& other) = default;
|
||||
PAKEntryReadStream(std::unique_ptr<atUint8[]>&& buf, atUint64 sz, atUint64 pos)
|
||||
: m_buf(std::move(buf)), m_sz(sz), m_pos(pos)
|
||||
{
|
||||
if (m_pos >= m_sz)
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
||||
}
|
||||
inline void seek(atInt64 pos, Athena::SeekOrigin origin)
|
||||
{
|
||||
if (origin == Athena::Begin)
|
||||
m_pos = pos;
|
||||
else if (origin == Athena::Current)
|
||||
m_pos += pos;
|
||||
else if (origin == Athena::End)
|
||||
m_pos = m_sz + pos;
|
||||
if (m_pos >= m_sz)
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
||||
}
|
||||
inline atUint64 position() const {return m_pos;}
|
||||
inline atUint64 length() const {return m_sz;}
|
||||
inline const atUint8* data() const {return m_buf.get();}
|
||||
inline atUint64 readUBytesToBuf(void* buf, atUint64 len)
|
||||
{
|
||||
atUint64 bufEnd = m_pos + len;
|
||||
if (bufEnd > m_sz)
|
||||
len -= bufEnd - m_sz;
|
||||
memcpy(buf, m_buf.get() + m_pos, len);
|
||||
m_pos += len;
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
struct UniqueResult
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
UNIQUE_NOTFOUND,
|
||||
UNIQUE_LEVEL,
|
||||
UNIQUE_AREA,
|
||||
UNIQUE_LAYER
|
||||
} type = UNIQUE_NOTFOUND;
|
||||
const HECL::SystemString* areaName = nullptr;
|
||||
const HECL::SystemString* layerName = nullptr;
|
||||
UniqueResult() = default;
|
||||
UniqueResult(Type tp) : type(tp) {}
|
||||
inline HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const
|
||||
{
|
||||
if (type == UNIQUE_AREA)
|
||||
{
|
||||
HECL::ProjectPath areaDir(pakPath, *areaName);
|
||||
areaDir.makeDir();
|
||||
return areaDir;
|
||||
}
|
||||
else if (type == UNIQUE_LAYER)
|
||||
{
|
||||
HECL::ProjectPath areaDir(pakPath, *areaName);
|
||||
areaDir.makeDir();
|
||||
HECL::ProjectPath layerDir(areaDir, *layerName);
|
||||
layerDir.makeDir();
|
||||
return layerDir;
|
||||
}
|
||||
return pakPath;
|
||||
}
|
||||
};
|
||||
|
||||
template <class BRIDGETYPE>
|
||||
class PAKRouter;
|
||||
|
||||
/* Resource extractor type */
|
||||
template <class PAKBRIDGE>
|
||||
struct ResExtractor
|
||||
{
|
||||
std::function<bool(const SpecBase&, PAKEntryReadStream&, const HECL::ProjectPath&)> func_a;
|
||||
std::function<bool(const SpecBase&, PAKEntryReadStream&, const HECL::ProjectPath&, PAKRouter<PAKBRIDGE>&,
|
||||
const typename PAKBRIDGE::PAKType::Entry&, bool)> func_b;
|
||||
const char* fileExts[4];
|
||||
unsigned weight;
|
||||
};
|
||||
|
||||
/* PAKRouter (for detecting shared entry locations) */
|
||||
template <class BRIDGETYPE>
|
||||
class PAKRouter
|
||||
{
|
||||
public:
|
||||
using PAKType = typename BRIDGETYPE::PAKType;
|
||||
using IDType = typename PAKType::IDType;
|
||||
using EntryType = typename PAKType::Entry;
|
||||
private:
|
||||
const SpecBase& m_dataSpec;
|
||||
const std::vector<BRIDGETYPE>* m_bridges = nullptr;
|
||||
std::vector<std::pair<HECL::ProjectPath,HECL::ProjectPath>> m_bridgePaths;
|
||||
size_t m_curBridgeIdx = 0;
|
||||
const HECL::ProjectPath& m_gameWorking;
|
||||
const HECL::ProjectPath& m_gameCooked;
|
||||
HECL::ProjectPath m_sharedWorking;
|
||||
HECL::ProjectPath m_sharedCooked;
|
||||
const PAKType* m_pak = nullptr;
|
||||
const NOD::DiscBase::IPartition::Node* m_node = nullptr;
|
||||
std::unordered_map<IDType, std::pair<size_t, EntryType*>> m_uniqueEntries;
|
||||
std::unordered_map<IDType, std::pair<size_t, EntryType*>> m_sharedEntries;
|
||||
public:
|
||||
PAKRouter(const SpecBase& dataSpec, const HECL::ProjectPath& working, const HECL::ProjectPath& cooked)
|
||||
: m_dataSpec(dataSpec),
|
||||
m_gameWorking(working), m_gameCooked(cooked),
|
||||
m_sharedWorking(working, "Shared"), m_sharedCooked(cooked, "Shared") {}
|
||||
void build(std::vector<BRIDGETYPE>& bridges, std::function<void(float)> progress)
|
||||
{
|
||||
m_bridges = &bridges;
|
||||
m_bridgePaths.clear();
|
||||
|
||||
m_uniqueEntries.clear();
|
||||
m_sharedEntries.clear();
|
||||
size_t count = 0;
|
||||
float bridgesSz = bridges.size();
|
||||
|
||||
/* Route entries unique/shared per-pak */
|
||||
size_t bridgeIdx = 0;
|
||||
for (BRIDGETYPE& bridge : bridges)
|
||||
{
|
||||
const std::string& name = bridge.getName();
|
||||
HECL::SystemStringView sysName(name);
|
||||
|
||||
HECL::SystemString::const_iterator extit = sysName.sys_str().end() - 4;
|
||||
HECL::SystemString baseName(sysName.sys_str().begin(), extit);
|
||||
|
||||
m_bridgePaths.emplace_back(std::make_pair(HECL::ProjectPath(m_gameWorking, baseName),
|
||||
HECL::ProjectPath(m_gameCooked, baseName)));
|
||||
|
||||
bridge.build();
|
||||
const typename BRIDGETYPE::PAKType& pak = bridge.getPAK();
|
||||
for (const auto& entry : pak.m_idMap)
|
||||
{
|
||||
auto sSearch = m_sharedEntries.find(entry.first);
|
||||
if (sSearch != m_sharedEntries.end())
|
||||
continue;
|
||||
auto uSearch = m_uniqueEntries.find(entry.first);
|
||||
if (uSearch != m_uniqueEntries.end())
|
||||
{
|
||||
m_uniqueEntries.erase(uSearch);
|
||||
m_sharedEntries[entry.first] = std::make_pair(bridgeIdx, entry.second);
|
||||
}
|
||||
else
|
||||
m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, entry.second);
|
||||
}
|
||||
progress(++count / bridgesSz);
|
||||
++bridgeIdx;
|
||||
}
|
||||
}
|
||||
|
||||
void enterPAKBridge(const BRIDGETYPE& pakBridge)
|
||||
{
|
||||
auto pit = m_bridgePaths.begin();
|
||||
size_t bridgeIdx = 0;
|
||||
for (const BRIDGETYPE& bridge : *m_bridges)
|
||||
{
|
||||
if (&bridge == &pakBridge)
|
||||
{
|
||||
pit->first.makeDir();
|
||||
pit->second.makeDir();
|
||||
m_pak = &pakBridge.getPAK();
|
||||
m_node = &pakBridge.getNode();
|
||||
m_curBridgeIdx = bridgeIdx;
|
||||
return;
|
||||
}
|
||||
++pit;
|
||||
++bridgeIdx;
|
||||
}
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAKBridge provided to PAKRouter::enterPAKBridge() was not part of build()");
|
||||
}
|
||||
|
||||
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry,
|
||||
const ResExtractor<BRIDGETYPE>& extractor) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getWorkingPath()");
|
||||
auto uniqueSearch = m_uniqueEntries.find(entry->id);
|
||||
if (uniqueSearch != m_uniqueEntries.end())
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].first;
|
||||
pakPath.makeDir();
|
||||
HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath);
|
||||
HECL::SystemString entName = m_pak->bestEntryName(*entry);
|
||||
if (extractor.fileExts[0] && !extractor.fileExts[1])
|
||||
entName += extractor.fileExts[0];
|
||||
return HECL::ProjectPath(uniquePath, entName);
|
||||
}
|
||||
auto sharedSearch = m_sharedEntries.find(entry->id);
|
||||
if (sharedSearch != m_sharedEntries.end())
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[m_curBridgeIdx].first;
|
||||
HECL::ProjectPath uniquePathPre = entry->unique.uniquePath(pakPath);
|
||||
HECL::SystemString entBase = m_pak->bestEntryName(*entry);
|
||||
HECL::SystemString entName = entBase;
|
||||
if (extractor.fileExts[0] && !extractor.fileExts[1])
|
||||
entName += extractor.fileExts[0];
|
||||
HECL::ProjectPath sharedPath(m_sharedWorking, entName);
|
||||
HECL::ProjectPath uniquePath(uniquePathPre, entName);
|
||||
if (extractor.func_a || extractor.func_b)
|
||||
{
|
||||
if (extractor.fileExts[0] && !extractor.fileExts[1])
|
||||
uniquePath.makeLinkTo(sharedPath);
|
||||
else
|
||||
{
|
||||
for (int e=0 ; e<4 ; ++e)
|
||||
{
|
||||
if (!extractor.fileExts[e])
|
||||
break;
|
||||
HECL::SystemString entName = entBase + extractor.fileExts[e];
|
||||
HECL::ProjectPath sharedPath(m_sharedWorking, entName);
|
||||
HECL::ProjectPath uniquePath(uniquePathPre, entName);
|
||||
uniquePath.makeLinkTo(sharedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_sharedWorking.makeDir();
|
||||
return sharedPath;
|
||||
}
|
||||
LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str());
|
||||
return HECL::ProjectPath();
|
||||
}
|
||||
|
||||
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry) const
|
||||
{
|
||||
return getWorking(entry, BRIDGETYPE::LookupExtractor(*entry));
|
||||
}
|
||||
|
||||
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::IDType& id) const
|
||||
{
|
||||
return getWorking(lookupEntry(id));
|
||||
}
|
||||
|
||||
HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::Entry* entry) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getCookedPath()");
|
||||
auto uniqueSearch = m_uniqueEntries.find(entry->id);
|
||||
if (uniqueSearch != m_uniqueEntries.end())
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].second;
|
||||
pakPath.makeDir();
|
||||
HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath);
|
||||
return HECL::ProjectPath(uniquePath, m_pak->bestEntryName(*entry));
|
||||
}
|
||||
auto sharedSearch = m_sharedEntries.find(entry->id);
|
||||
if (sharedSearch != m_sharedEntries.end())
|
||||
{
|
||||
m_sharedCooked.makeDir();
|
||||
return HECL::ProjectPath(m_sharedCooked, m_pak->bestEntryName(*entry));
|
||||
}
|
||||
LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str());
|
||||
return HECL::ProjectPath();
|
||||
}
|
||||
|
||||
HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::IDType& id) const
|
||||
{
|
||||
return getCooked(lookupEntry(id));
|
||||
}
|
||||
|
||||
HECL::SystemString getResourceRelativePath(const typename BRIDGETYPE::PAKType::Entry& a,
|
||||
const typename BRIDGETYPE::PAKType::IDType& b) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getResourceRelativePath()");
|
||||
const typename BRIDGETYPE::PAKType::Entry* be = lookupEntry(b);
|
||||
if (!be)
|
||||
return HECL::SystemString();
|
||||
HECL::ProjectPath aPath = getWorking(&a, BRIDGETYPE::LookupExtractor(a));
|
||||
HECL::SystemString ret;
|
||||
for (int i=0 ; i<aPath.levelCount() ; ++i)
|
||||
ret += "../";
|
||||
HECL::ProjectPath bPath = getWorking(be, BRIDGETYPE::LookupExtractor(*be));
|
||||
ret += bPath.getRelativePath();
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string getBestEntryName(const typename BRIDGETYPE::PAKType::Entry& entry) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()");
|
||||
return m_pak->bestEntryName(entry);
|
||||
}
|
||||
|
||||
std::string getBestEntryName(const typename BRIDGETYPE::PAKType::IDType& entry) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()");
|
||||
const typename BRIDGETYPE::PAKType::Entry* e = m_pak->lookupEntry(entry);
|
||||
if (!e)
|
||||
return entry.toString();
|
||||
return m_pak->bestEntryName(*e);
|
||||
}
|
||||
|
||||
bool extractResources(const BRIDGETYPE& pakBridge, bool force, std::function<void(float)> progress)
|
||||
{
|
||||
enterPAKBridge(pakBridge);
|
||||
size_t count = 0;
|
||||
size_t sz = m_pak->m_idMap.size();
|
||||
float fsz = sz;
|
||||
for (unsigned w=0 ; count<sz ; ++w)
|
||||
{
|
||||
for (const auto& item : m_pak->m_idMap)
|
||||
{
|
||||
ResExtractor<BRIDGETYPE> extractor = BRIDGETYPE::LookupExtractor(*item.second);
|
||||
if (extractor.weight != w)
|
||||
continue;
|
||||
|
||||
HECL::ProjectPath cooked = getCooked(item.second);
|
||||
if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb"));
|
||||
fwrite(s.data(), 1, s.length(), fout);
|
||||
fclose(fout);
|
||||
}
|
||||
|
||||
HECL::ProjectPath working = getWorking(item.second, extractor);
|
||||
if (extractor.func_a) /* Doesn't need PAKRouter access */
|
||||
{
|
||||
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
extractor.func_a(m_dataSpec, s, working);
|
||||
}
|
||||
}
|
||||
else if (extractor.func_b) /* Needs PAKRouter access */
|
||||
{
|
||||
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
extractor.func_b(m_dataSpec, s, working, *this, *item.second, force);
|
||||
}
|
||||
}
|
||||
|
||||
progress(++count / fsz);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const typename BRIDGETYPE::PAKType::Entry* lookupEntry(const typename BRIDGETYPE::PAKType::IDType& entry,
|
||||
const NOD::DiscBase::IPartition::Node** nodeOut=nullptr) const
|
||||
{
|
||||
if (!m_bridges)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::build() must be called before PAKRouter::lookupEntry()");
|
||||
if (m_pak)
|
||||
{
|
||||
const typename BRIDGETYPE::PAKType::Entry* ent = m_pak->lookupEntry(entry);
|
||||
if (ent)
|
||||
{
|
||||
if (nodeOut)
|
||||
*nodeOut = m_node;
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
for (const BRIDGETYPE& bridge : *m_bridges)
|
||||
{
|
||||
const typename BRIDGETYPE::PAKType& pak = bridge.getPAK();
|
||||
const typename BRIDGETYPE::PAKType::Entry* ent = pak.lookupEntry(entry);
|
||||
if (ent)
|
||||
{
|
||||
if (nodeOut)
|
||||
*nodeOut = &bridge.getNode();
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
LogDNACommon.report(LogVisor::Warning, "unable to find PAK entry %s", entry.toString().c_str());
|
||||
if (nodeOut)
|
||||
*nodeOut = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename DNA>
|
||||
bool lookupAndReadDNA(const typename BRIDGETYPE::PAKType::IDType& id, DNA& out)
|
||||
{
|
||||
const NOD::DiscBase::IPartition::Node* node;
|
||||
const typename BRIDGETYPE::PAKType::Entry* entry = lookupEntry(id, &node);
|
||||
if (!entry)
|
||||
return false;
|
||||
PAKEntryReadStream rs = entry->beginReadStream(*node);
|
||||
out.read(rs);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/* Resource cooker function */
|
||||
typedef std::function<bool(const HECL::ProjectPath&, const HECL::ProjectPath&)> ResCooker;
|
||||
|
||||
|
|
|
@ -0,0 +1,414 @@
|
|||
#ifndef __DNACOMMON_PAK_HPP__
|
||||
#define __DNACOMMON_PAK_HPP__
|
||||
|
||||
#include "DNACommon.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
/* PAK entry stream reader */
|
||||
class PAKEntryReadStream : public Athena::io::IStreamReader
|
||||
{
|
||||
std::unique_ptr<atUint8[]> m_buf;
|
||||
atUint64 m_sz;
|
||||
atUint64 m_pos;
|
||||
public:
|
||||
PAKEntryReadStream() {}
|
||||
operator bool() const {return m_buf.operator bool();}
|
||||
PAKEntryReadStream(const PAKEntryReadStream& other) = delete;
|
||||
PAKEntryReadStream(PAKEntryReadStream&& other) = default;
|
||||
PAKEntryReadStream& operator=(const PAKEntryReadStream& other) = delete;
|
||||
PAKEntryReadStream& operator=(PAKEntryReadStream&& other) = default;
|
||||
PAKEntryReadStream(std::unique_ptr<atUint8[]>&& buf, atUint64 sz, atUint64 pos)
|
||||
: m_buf(std::move(buf)), m_sz(sz), m_pos(pos)
|
||||
{
|
||||
if (m_pos >= m_sz)
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
||||
}
|
||||
inline void seek(atInt64 pos, Athena::SeekOrigin origin)
|
||||
{
|
||||
if (origin == Athena::Begin)
|
||||
m_pos = pos;
|
||||
else if (origin == Athena::Current)
|
||||
m_pos += pos;
|
||||
else if (origin == Athena::End)
|
||||
m_pos = m_sz + pos;
|
||||
if (m_pos >= m_sz)
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
||||
}
|
||||
inline atUint64 position() const {return m_pos;}
|
||||
inline atUint64 length() const {return m_sz;}
|
||||
inline const atUint8* data() const {return m_buf.get();}
|
||||
inline atUint64 readUBytesToBuf(void* buf, atUint64 len)
|
||||
{
|
||||
atUint64 bufEnd = m_pos + len;
|
||||
if (bufEnd > m_sz)
|
||||
len -= bufEnd - m_sz;
|
||||
memcpy(buf, m_buf.get() + m_pos, len);
|
||||
m_pos += len;
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
struct UniqueResult
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
UNIQUE_NOTFOUND,
|
||||
UNIQUE_LEVEL,
|
||||
UNIQUE_AREA,
|
||||
UNIQUE_LAYER
|
||||
} type = UNIQUE_NOTFOUND;
|
||||
const HECL::SystemString* areaName = nullptr;
|
||||
const HECL::SystemString* layerName = nullptr;
|
||||
UniqueResult() = default;
|
||||
UniqueResult(Type tp) : type(tp) {}
|
||||
inline HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const
|
||||
{
|
||||
if (type == UNIQUE_AREA)
|
||||
{
|
||||
HECL::ProjectPath areaDir(pakPath, *areaName);
|
||||
areaDir.makeDir();
|
||||
return areaDir;
|
||||
}
|
||||
else if (type == UNIQUE_LAYER)
|
||||
{
|
||||
HECL::ProjectPath areaDir(pakPath, *areaName);
|
||||
areaDir.makeDir();
|
||||
HECL::ProjectPath layerDir(areaDir, *layerName);
|
||||
layerDir.makeDir();
|
||||
return layerDir;
|
||||
}
|
||||
return pakPath;
|
||||
}
|
||||
};
|
||||
|
||||
template <class BRIDGETYPE>
|
||||
class PAKRouter;
|
||||
|
||||
/* Resource extractor type */
|
||||
template <class PAKBRIDGE>
|
||||
struct ResExtractor
|
||||
{
|
||||
std::function<bool(const SpecBase&, PAKEntryReadStream&, const HECL::ProjectPath&)> func_a;
|
||||
std::function<bool(const SpecBase&, PAKEntryReadStream&, const HECL::ProjectPath&, PAKRouter<PAKBRIDGE>&,
|
||||
const typename PAKBRIDGE::PAKType::Entry&, bool)> func_b;
|
||||
const char* fileExts[4];
|
||||
unsigned weight;
|
||||
};
|
||||
|
||||
/* PAKRouter (for detecting shared entry locations) */
|
||||
template <class BRIDGETYPE>
|
||||
class PAKRouter
|
||||
{
|
||||
public:
|
||||
using PAKType = typename BRIDGETYPE::PAKType;
|
||||
using IDType = typename PAKType::IDType;
|
||||
using EntryType = typename PAKType::Entry;
|
||||
private:
|
||||
const SpecBase& m_dataSpec;
|
||||
const std::vector<BRIDGETYPE>* m_bridges = nullptr;
|
||||
std::vector<std::pair<HECL::ProjectPath,HECL::ProjectPath>> m_bridgePaths;
|
||||
size_t m_curBridgeIdx = 0;
|
||||
const HECL::ProjectPath& m_gameWorking;
|
||||
const HECL::ProjectPath& m_gameCooked;
|
||||
HECL::ProjectPath m_sharedWorking;
|
||||
HECL::ProjectPath m_sharedCooked;
|
||||
const PAKType* m_pak = nullptr;
|
||||
const NOD::DiscBase::IPartition::Node* m_node = nullptr;
|
||||
std::unordered_map<IDType, std::pair<size_t, EntryType*>> m_uniqueEntries;
|
||||
std::unordered_map<IDType, std::pair<size_t, EntryType*>> m_sharedEntries;
|
||||
public:
|
||||
PAKRouter(const SpecBase& dataSpec, const HECL::ProjectPath& working, const HECL::ProjectPath& cooked)
|
||||
: m_dataSpec(dataSpec),
|
||||
m_gameWorking(working), m_gameCooked(cooked),
|
||||
m_sharedWorking(working, "Shared"), m_sharedCooked(cooked, "Shared") {}
|
||||
void build(std::vector<BRIDGETYPE>& bridges, std::function<void(float)> progress)
|
||||
{
|
||||
m_bridges = &bridges;
|
||||
m_bridgePaths.clear();
|
||||
|
||||
m_uniqueEntries.clear();
|
||||
m_sharedEntries.clear();
|
||||
size_t count = 0;
|
||||
float bridgesSz = bridges.size();
|
||||
|
||||
/* Route entries unique/shared per-pak */
|
||||
size_t bridgeIdx = 0;
|
||||
for (BRIDGETYPE& bridge : bridges)
|
||||
{
|
||||
const std::string& name = bridge.getName();
|
||||
HECL::SystemStringView sysName(name);
|
||||
|
||||
HECL::SystemString::const_iterator extit = sysName.sys_str().end() - 4;
|
||||
HECL::SystemString baseName(sysName.sys_str().begin(), extit);
|
||||
|
||||
m_bridgePaths.emplace_back(std::make_pair(HECL::ProjectPath(m_gameWorking, baseName),
|
||||
HECL::ProjectPath(m_gameCooked, baseName)));
|
||||
|
||||
bridge.build();
|
||||
const typename BRIDGETYPE::PAKType& pak = bridge.getPAK();
|
||||
for (const auto& entry : pak.m_idMap)
|
||||
{
|
||||
auto sSearch = m_sharedEntries.find(entry.first);
|
||||
if (sSearch != m_sharedEntries.end())
|
||||
continue;
|
||||
auto uSearch = m_uniqueEntries.find(entry.first);
|
||||
if (uSearch != m_uniqueEntries.end())
|
||||
{
|
||||
m_uniqueEntries.erase(uSearch);
|
||||
m_sharedEntries[entry.first] = std::make_pair(bridgeIdx, entry.second);
|
||||
}
|
||||
else
|
||||
m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, entry.second);
|
||||
}
|
||||
progress(++count / bridgesSz);
|
||||
++bridgeIdx;
|
||||
}
|
||||
}
|
||||
|
||||
void enterPAKBridge(const BRIDGETYPE& pakBridge)
|
||||
{
|
||||
auto pit = m_bridgePaths.begin();
|
||||
size_t bridgeIdx = 0;
|
||||
for (const BRIDGETYPE& bridge : *m_bridges)
|
||||
{
|
||||
if (&bridge == &pakBridge)
|
||||
{
|
||||
pit->first.makeDir();
|
||||
pit->second.makeDir();
|
||||
m_pak = &pakBridge.getPAK();
|
||||
m_node = &pakBridge.getNode();
|
||||
m_curBridgeIdx = bridgeIdx;
|
||||
return;
|
||||
}
|
||||
++pit;
|
||||
++bridgeIdx;
|
||||
}
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAKBridge provided to PAKRouter::enterPAKBridge() was not part of build()");
|
||||
}
|
||||
|
||||
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry,
|
||||
const ResExtractor<BRIDGETYPE>& extractor) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getWorkingPath()");
|
||||
auto uniqueSearch = m_uniqueEntries.find(entry->id);
|
||||
if (uniqueSearch != m_uniqueEntries.end())
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].first;
|
||||
pakPath.makeDir();
|
||||
HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath);
|
||||
HECL::SystemString entName = m_pak->bestEntryName(*entry);
|
||||
if (extractor.fileExts[0] && !extractor.fileExts[1])
|
||||
entName += extractor.fileExts[0];
|
||||
return HECL::ProjectPath(uniquePath, entName);
|
||||
}
|
||||
auto sharedSearch = m_sharedEntries.find(entry->id);
|
||||
if (sharedSearch != m_sharedEntries.end())
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[m_curBridgeIdx].first;
|
||||
HECL::ProjectPath uniquePathPre = entry->unique.uniquePath(pakPath);
|
||||
HECL::SystemString entBase = m_pak->bestEntryName(*entry);
|
||||
HECL::SystemString entName = entBase;
|
||||
if (extractor.fileExts[0] && !extractor.fileExts[1])
|
||||
entName += extractor.fileExts[0];
|
||||
HECL::ProjectPath sharedPath(m_sharedWorking, entName);
|
||||
HECL::ProjectPath uniquePath(uniquePathPre, entName);
|
||||
if (extractor.func_a || extractor.func_b)
|
||||
{
|
||||
if (extractor.fileExts[0] && !extractor.fileExts[1])
|
||||
uniquePath.makeLinkTo(sharedPath);
|
||||
else
|
||||
{
|
||||
for (int e=0 ; e<4 ; ++e)
|
||||
{
|
||||
if (!extractor.fileExts[e])
|
||||
break;
|
||||
HECL::SystemString entName = entBase + extractor.fileExts[e];
|
||||
HECL::ProjectPath sharedPath(m_sharedWorking, entName);
|
||||
HECL::ProjectPath uniquePath(uniquePathPre, entName);
|
||||
uniquePath.makeLinkTo(sharedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_sharedWorking.makeDir();
|
||||
return sharedPath;
|
||||
}
|
||||
LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str());
|
||||
return HECL::ProjectPath();
|
||||
}
|
||||
|
||||
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry) const
|
||||
{
|
||||
return getWorking(entry, BRIDGETYPE::LookupExtractor(*entry));
|
||||
}
|
||||
|
||||
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::IDType& id) const
|
||||
{
|
||||
return getWorking(lookupEntry(id));
|
||||
}
|
||||
|
||||
HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::Entry* entry) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getCookedPath()");
|
||||
auto uniqueSearch = m_uniqueEntries.find(entry->id);
|
||||
if (uniqueSearch != m_uniqueEntries.end())
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].second;
|
||||
pakPath.makeDir();
|
||||
HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath);
|
||||
return HECL::ProjectPath(uniquePath, m_pak->bestEntryName(*entry));
|
||||
}
|
||||
auto sharedSearch = m_sharedEntries.find(entry->id);
|
||||
if (sharedSearch != m_sharedEntries.end())
|
||||
{
|
||||
m_sharedCooked.makeDir();
|
||||
return HECL::ProjectPath(m_sharedCooked, m_pak->bestEntryName(*entry));
|
||||
}
|
||||
LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str());
|
||||
return HECL::ProjectPath();
|
||||
}
|
||||
|
||||
HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::IDType& id) const
|
||||
{
|
||||
return getCooked(lookupEntry(id));
|
||||
}
|
||||
|
||||
HECL::SystemString getResourceRelativePath(const typename BRIDGETYPE::PAKType::Entry& a,
|
||||
const typename BRIDGETYPE::PAKType::IDType& b) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getResourceRelativePath()");
|
||||
const typename BRIDGETYPE::PAKType::Entry* be = lookupEntry(b);
|
||||
if (!be)
|
||||
return HECL::SystemString();
|
||||
HECL::ProjectPath aPath = getWorking(&a, BRIDGETYPE::LookupExtractor(a));
|
||||
HECL::SystemString ret;
|
||||
for (int i=0 ; i<aPath.levelCount() ; ++i)
|
||||
ret += "../";
|
||||
HECL::ProjectPath bPath = getWorking(be, BRIDGETYPE::LookupExtractor(*be));
|
||||
ret += bPath.getRelativePath();
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string getBestEntryName(const typename BRIDGETYPE::PAKType::Entry& entry) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()");
|
||||
return m_pak->bestEntryName(entry);
|
||||
}
|
||||
|
||||
std::string getBestEntryName(const typename BRIDGETYPE::PAKType::IDType& entry) const
|
||||
{
|
||||
if (!m_pak)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()");
|
||||
const typename BRIDGETYPE::PAKType::Entry* e = m_pak->lookupEntry(entry);
|
||||
if (!e)
|
||||
return entry.toString();
|
||||
return m_pak->bestEntryName(*e);
|
||||
}
|
||||
|
||||
bool extractResources(const BRIDGETYPE& pakBridge, bool force, std::function<void(float)> progress)
|
||||
{
|
||||
enterPAKBridge(pakBridge);
|
||||
size_t count = 0;
|
||||
size_t sz = m_pak->m_idMap.size();
|
||||
float fsz = sz;
|
||||
for (unsigned w=0 ; count<sz ; ++w)
|
||||
{
|
||||
for (const auto& item : m_pak->m_idMap)
|
||||
{
|
||||
ResExtractor<BRIDGETYPE> extractor = BRIDGETYPE::LookupExtractor(*item.second);
|
||||
if (extractor.weight != w)
|
||||
continue;
|
||||
|
||||
HECL::ProjectPath cooked = getCooked(item.second);
|
||||
if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb"));
|
||||
fwrite(s.data(), 1, s.length(), fout);
|
||||
fclose(fout);
|
||||
}
|
||||
|
||||
HECL::ProjectPath working = getWorking(item.second, extractor);
|
||||
if (extractor.func_a) /* Doesn't need PAKRouter access */
|
||||
{
|
||||
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
extractor.func_a(m_dataSpec, s, working);
|
||||
}
|
||||
}
|
||||
else if (extractor.func_b) /* Needs PAKRouter access */
|
||||
{
|
||||
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
extractor.func_b(m_dataSpec, s, working, *this, *item.second, force);
|
||||
}
|
||||
}
|
||||
|
||||
progress(++count / fsz);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const typename BRIDGETYPE::PAKType::Entry* lookupEntry(const typename BRIDGETYPE::PAKType::IDType& entry,
|
||||
const NOD::DiscBase::IPartition::Node** nodeOut=nullptr) const
|
||||
{
|
||||
if (!m_bridges)
|
||||
LogDNACommon.report(LogVisor::FatalError,
|
||||
"PAKRouter::build() must be called before PAKRouter::lookupEntry()");
|
||||
if (m_pak)
|
||||
{
|
||||
const typename BRIDGETYPE::PAKType::Entry* ent = m_pak->lookupEntry(entry);
|
||||
if (ent)
|
||||
{
|
||||
if (nodeOut)
|
||||
*nodeOut = m_node;
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
for (const BRIDGETYPE& bridge : *m_bridges)
|
||||
{
|
||||
const typename BRIDGETYPE::PAKType& pak = bridge.getPAK();
|
||||
const typename BRIDGETYPE::PAKType::Entry* ent = pak.lookupEntry(entry);
|
||||
if (ent)
|
||||
{
|
||||
if (nodeOut)
|
||||
*nodeOut = &bridge.getNode();
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
LogDNACommon.report(LogVisor::Warning, "unable to find PAK entry %s", entry.toString().c_str());
|
||||
if (nodeOut)
|
||||
*nodeOut = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename DNA>
|
||||
bool lookupAndReadDNA(const typename BRIDGETYPE::PAKType::IDType& id, DNA& out)
|
||||
{
|
||||
const NOD::DiscBase::IPartition::Node* node;
|
||||
const typename BRIDGETYPE::PAKType::Entry* entry = lookupEntry(id, &node);
|
||||
if (!entry)
|
||||
return false;
|
||||
PAKEntryReadStream rs = entry->beginReadStream(*node);
|
||||
out.read(rs);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __DNACOMMON_PAK_HPP__
|
|
@ -1,6 +1,7 @@
|
|||
#include <png.h>
|
||||
#include <squish.h>
|
||||
#include "TXTR.hpp"
|
||||
#include "PAK.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
namespace Retro
|
||||
{
|
||||
class PAKEntryReadStream;
|
||||
|
||||
struct TXTR
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __DNAMP1_MLVL_HPP__
|
||||
#define __DNAMP1_MLVL_HPP__
|
||||
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#include <NOD/DiscBase.hpp>
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __DNAMP2_STRG_HPP__
|
||||
|
||||
#include <unordered_map>
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
#include "../DNACommon/STRG.hpp"
|
||||
|
||||
namespace Retro
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <lzo/lzo1x.h>
|
||||
#include <NOD/DiscBase.hpp>
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __DNAMP3_STRG_HPP__
|
||||
|
||||
#include <unordered_map>
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
#include "../DNACommon/STRG.hpp"
|
||||
|
||||
namespace Retro
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef __RETRO_CACTOR_HPP__
|
||||
#define __RETRO_CACTOR_HPP__
|
||||
|
||||
#include "CEntity.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class CTransform;
|
||||
class CModelData;
|
||||
class CMaterialList;
|
||||
class CActorParameters;
|
||||
|
||||
class CActor : public CEntity
|
||||
{
|
||||
public:
|
||||
CActor(TUniqueId, bool, const std::string&, const CEntityInfo&,
|
||||
const CTransform&, const CModelData&, const CMaterialList&,
|
||||
const CActorParameters&, TUniqueId);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CACTOR_HPP__
|
|
@ -8,6 +8,12 @@ class CAiFuncMap
|
|||
{
|
||||
};
|
||||
|
||||
class CAi
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CAI_HPP__
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class CIOWin;
|
||||
|
||||
enum EArchMsgTarget
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <Athena/IStreamReader.hpp>
|
||||
#include <Athena/IStreamWriter.hpp>
|
||||
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CEntity.hpp"
|
||||
#include "CStateManager.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#include "RetroTypes.hpp"
|
||||
#include "ScriptObjectSupport.hpp"
|
||||
#include "CStateManager.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class CStateManager;
|
||||
|
||||
struct SConnection
|
||||
{
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef __RETRO_CFACTORYSTORE_HPP__
|
||||
#define __RETRO_CFACTORYSTORE_HPP__
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class IObjectStore
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CFACTORYSTORE_HPP__
|
|
@ -2,11 +2,11 @@
|
|||
#define __RETRO_CIOWIN_HPP__
|
||||
|
||||
#include <string>
|
||||
#include "CArchitectureMessage.hpp"
|
||||
#include "CArchitectureQueue.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class CArchitectureMessage;
|
||||
class CArchitectureQueue;
|
||||
|
||||
class CIOWin
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CIOWinManager.hpp"
|
||||
#include "CArchitectureMessage.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include "CMFGame.hpp"
|
||||
#include "CArchitectureQueue.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "CGameState.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
bool CMFGameLoader::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue)
|
||||
{
|
||||
switch (msg.GetType())
|
||||
{
|
||||
case MsgTimerTick:
|
||||
{
|
||||
const CArchMsgParmReal32& tick = MakeMsg::GetParmTimerTick(msg);
|
||||
g_GameState->WorldTransitionManager();
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMFGameLoader::Draw() const
|
||||
{
|
||||
g_GameState->WorldTransitionManager().Draw();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +1,39 @@
|
|||
#include "CMainFlow.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "CGameState.hpp"
|
||||
#include "CArchitectureQueue.hpp"
|
||||
#include "CMFGame.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
bool CMFGameLoader::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue)
|
||||
void CMainFlow::AdvanceGameState(CArchitectureQueue& queue)
|
||||
{
|
||||
}
|
||||
void CMainFlow::SetGameState(EClientFlowStates state, CArchitectureQueue& queue)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case StateGameLoad:
|
||||
queue.PushMessage(std::move(MakeMsg::CreateCreateIOWin(TargetMainFlow, 10, 1000, new CMFGameLoader())));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
bool CMainFlow::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue)
|
||||
{
|
||||
switch (msg.GetType())
|
||||
{
|
||||
case MsgTimerTick:
|
||||
AdvanceGameState(queue);
|
||||
break;
|
||||
case MsgSetGameState:
|
||||
{
|
||||
const CArchMsgParmReal32& tick = MakeMsg::GetParmTimerTick(msg);
|
||||
g_GameState->WorldTransitionManager();
|
||||
CArchMsgParmInt32 state = MakeMsg::GetParmNewGameflowState(msg);
|
||||
SetGameState(EClientFlowStates(state.m_parm), queue);
|
||||
return true;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMFGameLoader::Draw() const
|
||||
{
|
||||
g_GameState->WorldTransitionManager().Draw();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
#define __RETRO_CMAINFLOW_HPP__
|
||||
|
||||
#include "CIOWin.hpp"
|
||||
#include "CMFGame.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class CArchitectureMessage;
|
||||
class CArchitectureQueue;
|
||||
|
||||
enum EClientFlowStates
|
||||
{
|
||||
|
@ -16,36 +17,9 @@ class CMainFlow : public CIOWin
|
|||
{
|
||||
public:
|
||||
CMainFlow() : CIOWin("CMainFlow") {}
|
||||
void AdvanceGameState(CArchitectureQueue& queue)
|
||||
{
|
||||
}
|
||||
void SetGameState(EClientFlowStates state, CArchitectureQueue& queue)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case StateGameLoad:
|
||||
queue.PushMessage(std::move(MakeMsg::CreateCreateIOWin(TargetMainFlow, 10, 1000, new CMFGameLoader())));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
bool OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue)
|
||||
{
|
||||
switch (msg.GetType())
|
||||
{
|
||||
case MsgTimerTick:
|
||||
AdvanceGameState(queue);
|
||||
break;
|
||||
case MsgSetGameState:
|
||||
{
|
||||
CArchMsgParmInt32 state = MakeMsg::GetParmNewGameflowState(msg);
|
||||
SetGameState(EClientFlowStates(state.m_parm), queue);
|
||||
return true;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void AdvanceGameState(CArchitectureQueue& queue);
|
||||
void SetGameState(EClientFlowStates state, CArchitectureQueue& queue);
|
||||
bool OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue);
|
||||
bool GetIsContinueDraw() const {return false;}
|
||||
void Draw() const {}
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ add_library(RuntimeCommon
|
|||
CWorldTransManager.hpp CWorldTransManager.cpp
|
||||
CRandom16.hpp CRandom16.cpp
|
||||
CResFactory.hpp CResFactory.cpp
|
||||
CFactoryStore.hpp CFactoryStore.cpp
|
||||
IObjectStore.hpp
|
||||
CSimplePool.hpp CSimplePool.cpp
|
||||
CAi.hpp CAi.cpp
|
||||
CGameOptions.hpp CGameOptions.cpp
|
||||
|
@ -40,8 +40,12 @@ add_library(RuntimeCommon
|
|||
CArchitectureMessage.hpp
|
||||
CArchitectureQueue.hpp CArchitectureQueue.cpp
|
||||
IObj.hpp
|
||||
IVParamObj.hpp
|
||||
CToken.hpp
|
||||
CAreaOctTree.hpp CAreaOctTree.cpp
|
||||
CActor.hpp CActor.cpp
|
||||
CPhysicsActor.hpp CPhysicsActor.cpp
|
||||
rstl.hpp rstl.cpp
|
||||
GameGlobalObjects.hpp
|
||||
RetroTypes.hpp
|
||||
GCNTypes.hpp)
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef __RETRO_CMEMORY_HPP__
|
||||
#define __RETRO_CMEMORY_HPP__
|
||||
|
||||
#include "IAllocator.hpp"
|
||||
#include "COsContext.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class IAllocator;
|
||||
class COsContext;
|
||||
|
||||
class CMemory
|
||||
{
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef __RETRO_CPHYSICSACTOR_HPP__
|
||||
#define __RETRO_CPHYSICSACTOR_HPP__
|
||||
|
||||
#include "CActor.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class CPhysicsActor : public CActor
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CPHYSICSACTOR_HPP__
|
|
@ -3,4 +3,20 @@
|
|||
namespace Retro
|
||||
{
|
||||
|
||||
void CResFactory::Build(const SObjectTag&, const CVParamTransfer&)
|
||||
{
|
||||
}
|
||||
void CResFactory::BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**)
|
||||
{
|
||||
}
|
||||
void CResFactory::CancelBuild(const SObjectTag&)
|
||||
{
|
||||
}
|
||||
bool CResFactory::CanBuild(const SObjectTag&)
|
||||
{
|
||||
}
|
||||
const SObjectTag& CResFactory::GetResourceIdByName(const char*) const
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,12 @@ namespace Retro
|
|||
|
||||
class CResFactory : public IFactory
|
||||
{
|
||||
public:
|
||||
void Build(const SObjectTag&, const CVParamTransfer&);
|
||||
void BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**);
|
||||
void CancelBuild(const SObjectTag&);
|
||||
bool CanBuild(const SObjectTag&);
|
||||
const SObjectTag& GetResourceIdByName(const char*) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CSimplePool.hpp"
|
||||
#include "IVParamObj.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef __RETRO_CSIMPLEPOOL_HPP__
|
||||
#define __RETRO_CSIMPLEPOOL_HPP__
|
||||
|
||||
#include "IFactory.hpp"
|
||||
#include "CFactoryStore.hpp"
|
||||
#include "IObjectStore.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class IFactory;
|
||||
|
||||
class CSimplePool : public IObjectStore
|
||||
{
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
#include <memory>
|
||||
#include "CBasics.hpp"
|
||||
#include "CScriptMailbox.hpp"
|
||||
#include "CMapWorldInfo.hpp"
|
||||
#include "CPlayerState.hpp"
|
||||
#include "CWorldTransManager.hpp"
|
||||
#include "ScriptObjectSupport.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class CScriptMailbox;
|
||||
class CMapWorldInfo;
|
||||
class CPlayerState;
|
||||
class CWorldTransManager;
|
||||
|
||||
class CStateManager
|
||||
{
|
||||
|
|
|
@ -1,11 +1,50 @@
|
|||
#ifndef __RETRO_CTOKEN_HPP__
|
||||
#define __RETRO_CTOKEN_HPP__
|
||||
|
||||
#include <memory>
|
||||
#include "RetroTypes.hpp"
|
||||
#include "CVParamTransfer.hpp"
|
||||
#include "IObjectStore.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class IObjectStore;
|
||||
class IObj;
|
||||
|
||||
class CObjectReference
|
||||
{
|
||||
u16 x0_refCount = 0;
|
||||
bool x3_loading = false;
|
||||
SObjectTag x4_objTag;
|
||||
IObjectStore* xC_objectStore = nullptr;
|
||||
std::unique_ptr<IObj> x10_object;
|
||||
CVParamTransfer x14_params;
|
||||
public:
|
||||
CObjectReference(IObjectStore& objStore, std::unique_ptr<IObj>&& obj,
|
||||
const SObjectTag& objTag, CVParamTransfer buildParams)
|
||||
: x4_objTag(objTag), xC_objectStore(&objStore),
|
||||
x10_object(std::move(obj)), x14_params(buildParams) {}
|
||||
CObjectReference(std::unique_ptr<IObj>&& obj);
|
||||
|
||||
bool IsLoading() const {return x3_loading;}
|
||||
void Unlock() {}
|
||||
void RemoveReference() {}
|
||||
void CancelLoad() {}
|
||||
void Unload() {}
|
||||
void GetObject() {}
|
||||
|
||||
};
|
||||
|
||||
class CToken
|
||||
{
|
||||
CObjectReference* x0_objRef;
|
||||
bool x4_lockHeld = false;
|
||||
public:
|
||||
~CToken()
|
||||
{
|
||||
if (x4_lockHeld)
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef __RETRO_CANIMATIONDATABASE_HPP__
|
||||
#define __RETRO_CANIMATIONDATABASE_HPP__
|
||||
|
||||
#include "../RetroTypes.hpp"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class IMetaAnim;
|
||||
class CPrimitive;
|
||||
|
||||
class CAnimationDatabase
|
||||
{
|
||||
public:
|
||||
virtual const IMetaAnim* GetMetaAnim(u32) const=0;
|
||||
virtual u32 GetNumMetaAnims() const=0;
|
||||
virtual const char* GetMetaAnimName(u32) const=0;
|
||||
virtual void GetAllUniquePrimitives(std::vector<CPrimitive>&) const=0;
|
||||
virtual void GetUniquePrimitivesFromMetaAnim(std::set<CPrimitive>&, const std::string&) const=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CANIMATIONDATABASE_HPP__
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef __RETRO_CANIMATIONDATABASEGAME_HPP__
|
||||
#define __RETRO_CANIMATIONDATABASEGAME_HPP__
|
||||
|
||||
#include "CAnimationDatabase.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class CAnimationDatabaseGame : public CAnimationDatabase
|
||||
{
|
||||
public:
|
||||
const IMetaAnim* GetMetaAnim(u32) const;
|
||||
u32 GetNumMetaAnims() const;
|
||||
const char* GetMetaAnimName(u32) const;
|
||||
void GetAllUniquePrimitives(std::vector<CPrimitive>&) const;
|
||||
void GetUniquePrimitivesFromMetaAnim(std::set<CPrimitive>&, const std::string&) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CANIMATIONDATABASEGAME_HPP__
|
|
@ -6,9 +6,10 @@
|
|||
namespace Retro
|
||||
{
|
||||
|
||||
class CCharacterFactoryBuilder : public IFactory
|
||||
class CCharacterFactoryBuilder
|
||||
{
|
||||
public:
|
||||
CCharacterFactoryBuilder();
|
||||
class CDummyFactory : public IFactory
|
||||
{
|
||||
};
|
||||
|
|
|
@ -2,4 +2,10 @@ add_library(RuntimeCommonCharacter
|
|||
CAssetFactory.hpp CAssetFactory.cpp
|
||||
CCharacterFactory.hpp CCharacterFactory.cpp
|
||||
CAnimData.hpp CAnimData.cpp
|
||||
CCharAnimTime.hpp CCharAnimTime.cpp)
|
||||
CCharAnimTime.hpp CCharAnimTime.cpp
|
||||
IMetaAnim.hpp
|
||||
IMetaTrans.hpp
|
||||
CAnimationDatabase.hpp
|
||||
CAnimationDatabaseGame.hpp
|
||||
CTransitionDatabase.hpp
|
||||
CTransitionDatabaseGame.hpp)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __RETRO_CTRANSITIONDATABASE_HPP__
|
||||
#define __RETRO_CTRANSITIONDATABASE_HPP__
|
||||
|
||||
#include "../RetroTypes.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class IMetaTrans;
|
||||
|
||||
class CTransitionDatabase
|
||||
{
|
||||
public:
|
||||
virtual const IMetaTrans* GetMetaTrans(u32, u32) const=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CTRANSITIONDATABASE_HPP__
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef __RETRO_CTRANSITIONDATABASEGAME_HPP__
|
||||
#define __RETRO_CTRANSITIONDATABASEGAME_HPP__
|
||||
|
||||
#include "CTransitionDatabase.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class CTransitionDatabaseGame : public CTransitionDatabase
|
||||
{
|
||||
public:
|
||||
const IMetaTrans* GetMetaTrans(u32, u32);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_CTRANSITIONDATABASEGAME_HPP__
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef __RETRO_IMETAANIM_HPP__
|
||||
#define __RETRO_IMETAANIM_HPP__
|
||||
|
||||
#include "../RetroTypes.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class IMetaAnim
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_IMETAANIM_HPP__
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef __RETRO_IMETATRANS_HPP__
|
||||
#define __RETRO_IMETATRANS_HPP__
|
||||
|
||||
#include "../RetroTypes.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class IMetaTrans
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_IMETATRANS_HPP__
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef __RETRO_CBOORENDERER_HPP__
|
||||
#define __RETRO_CBOORENDERER_HPP__
|
||||
|
||||
#include "../CFactoryStore.hpp"
|
||||
#include "../COsContext.hpp"
|
||||
#include "../CMemory.hpp"
|
||||
#include "../CResFactory.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class IObjectStore;
|
||||
class COsContext;
|
||||
class CMemorySys;
|
||||
class CResFactory;
|
||||
|
||||
class CBooRenderer
|
||||
{
|
||||
|
|
|
@ -48,12 +48,12 @@ public:
|
|||
virtual void SetDrawableCallback(TDrawableCallback, const void*);
|
||||
virtual void SetWorldViewpoint(const CTransform&);
|
||||
virtual void SetPerspectiveFovScalar(float);
|
||||
virtual void SetPerspective(float,float,float,float,float);
|
||||
virtual void SetPerspective(float,float,float,float);
|
||||
virtual void SetViewportOrtho(bool,float,float);
|
||||
virtual void SetPerspective(float, float, float, float, float);
|
||||
virtual void SetPerspective(float, float, float, float);
|
||||
virtual void SetViewportOrtho(bool, float, float);
|
||||
virtual void SetClippingPlanes(const CFrustum&);
|
||||
virtual void SetViewport(int,int,int,int);
|
||||
virtual void SetDepthReadWrite(bool,bool);
|
||||
virtual void SetViewport(int, int, int, int);
|
||||
virtual void SetDepthReadWrite(bool, bool);
|
||||
virtual void SetBlendMode_AdditiveAlpha();
|
||||
virtual void SetBlendMode_AlphaBlended();
|
||||
virtual void SetBlendMode_NoColorWrite();
|
||||
|
@ -62,10 +62,10 @@ public:
|
|||
virtual void SetBlendMode_InvertSrc();
|
||||
virtual void SetBlendMode_Replace();
|
||||
virtual void SetBlendMode_AdditiveDestColor();
|
||||
virtual void SetDebugOption(EDebugOption,int);
|
||||
virtual void SetDebugOption(EDebugOption, int);
|
||||
virtual void BeginScene();
|
||||
virtual void EndScene();
|
||||
virtual void BeginPrimitive(EPrimitiveType,int);
|
||||
virtual void BeginPrimitive(EPrimitiveType, int);
|
||||
virtual void BeginLines(int);
|
||||
virtual void BeginLineStrip(int);
|
||||
virtual void BeginTriangles(int);
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
virtual void BeginTriangleFan(int);
|
||||
virtual void PrimVertex(const CVector3f&);
|
||||
virtual void PrimNormal(const CVector3f&);
|
||||
virtual void PrimColor(float,float,float,float);
|
||||
virtual void PrimColor(float, float, float, float);
|
||||
virtual void PrimColor(const CColor&);
|
||||
virtual void EndPrimitive();
|
||||
virtual void SetAmbientColor(const CColor&);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef __RETRO_IALLOCATOR_HPP__
|
||||
#define __RETRO_IALLOCATOR_HPP__
|
||||
|
||||
#include "COsContext.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class COsContext;
|
||||
|
||||
class IAllocator
|
||||
{
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
#ifndef __RETRO_IFACTORY_HPP__
|
||||
#define __RETRO_IFACTORY_HPP__
|
||||
|
||||
#include "RetroTypes.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
class CVParamTransfer;
|
||||
class IObj;
|
||||
|
||||
class IFactory
|
||||
{
|
||||
public:
|
||||
virtual ~IFactory() {}
|
||||
virtual void Build(const SObjectTag&, const CVParamTransfer&)=0;
|
||||
virtual void BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**)=0;
|
||||
virtual void CancelBuild(const SObjectTag&)=0;
|
||||
virtual bool CanBuild(const SObjectTag&)=0;
|
||||
virtual const SObjectTag& GetResourceIdByName(const char*) const=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
#ifndef __RETRO_IOBJ_HPP__
|
||||
#define __RETRO_IOBJ_HPP__
|
||||
|
||||
#include <HECL/HECL.hpp>
|
||||
#include "RetroTypes.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
struct SObjectTag
|
||||
{
|
||||
HECL::FourCC fcc;
|
||||
u32 id;
|
||||
};
|
||||
|
||||
class IObj
|
||||
{
|
||||
};
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __RETRO_IOBJECTSTORE_HPP__
|
||||
#define __RETRO_IOBJECTSTORE_HPP__
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class IObjectStore
|
||||
{
|
||||
public:
|
||||
/*
|
||||
GetObj((SObjectTag const &,CVParamTransfer const &))
|
||||
GetObj((SObjectTag const &))
|
||||
GetObj((char const *))
|
||||
GetObj((char const *,CVParamTransfer const &))
|
||||
HasObject(const(SObjectTag const &))
|
||||
.data6:80352C6C .long CSimplePool::ObjectIsLive(const(SObjectTag const &))
|
||||
.data6:80352C70 .long CSimplePool::GetFactory(const(void))
|
||||
.data6:80352C74 .long CSimplePool::Flush((void))
|
||||
.data6:80352C78 .long CSimplePool::ObjectUnreferenced((SObjectTag const &))
|
||||
*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_IOBJECTSTORE_HPP__
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef __RETRO_IVPARAMOBJ_HPP__
|
||||
#define __RETRO_IVPARAMOBJ_HPP__
|
||||
|
||||
#include "IObj.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class IVParamObj : public IObj
|
||||
{
|
||||
public:
|
||||
virtual ~IVParamObj() {}
|
||||
};
|
||||
|
||||
class CVParamTransfer
|
||||
{
|
||||
rstl::CRefData* m_refData;
|
||||
public:
|
||||
CVParamTransfer(rstl::CRefData* rd) : m_refData(rd) {m_refData->AddRef();}
|
||||
~CVParamTransfer()
|
||||
{
|
||||
if (m_refData->DelRef() <= 0)
|
||||
{
|
||||
delete static_cast<IVParamObj*>(m_refData->GetPtr());
|
||||
delete m_refData;
|
||||
}
|
||||
}
|
||||
IVParamObj* GetObj() const {return static_cast<IVParamObj*>(m_refData->GetPtr());}
|
||||
CVParamTransfer ShareTransferRef() {return CVParamTransfer(m_refData);}
|
||||
|
||||
static CVParamTransfer Null() {return CVParamTransfer(&rstl::CRefData::sNull);}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class TObjOwnerParam : public IVParamObj
|
||||
{
|
||||
T m_param;
|
||||
protected:
|
||||
~TObjOwnerParam() {}
|
||||
public:
|
||||
TObjOwnerParam(T&& obj) : m_param(std::move(obj)) {}
|
||||
CVParamTransfer NewTransferRef() {return CVParamTransfer(new rstl::CRefData(this));}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_IVPARAMOBJ_HPP__
|
|
@ -24,6 +24,7 @@
|
|||
#include "GuiSys/CConsoleOutputWindow.hpp"
|
||||
#include "Audio/CAudioStateWin.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "CArchitectureQueue.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -3,11 +3,20 @@
|
|||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include "GCNTypes.hpp"
|
||||
#include "rstl.hpp"
|
||||
#include "DataSpec/DNACommon/DNACommon.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
struct SObjectTag
|
||||
{
|
||||
FourCC type;
|
||||
UniqueID32 id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief singleton static-allocator
|
||||
*/
|
||||
|
@ -27,15 +36,15 @@ public:
|
|||
|
||||
template<typename U = T>
|
||||
TOneStatic(typename std::enable_if<!std::is_default_constructible<U>::value>::type* = 0)
|
||||
{++ReferenceCount();}
|
||||
{++m_refCount;}
|
||||
template<typename U = T>
|
||||
TOneStatic(typename std::enable_if<std::is_default_constructible<U>::value>::type* = 0)
|
||||
{++ReferenceCount(); new (m_allocspace) T();}
|
||||
{++m_refCount; new (m_allocspace) T();}
|
||||
|
||||
template<typename... Args> TOneStatic(Args&&... args)
|
||||
{++ReferenceCount(); new (m_allocspace) T(std::forward<Args>(args)...);}
|
||||
{++m_refCount; new (m_allocspace) T(std::forward<Args>(args)...);}
|
||||
|
||||
~TOneStatic() {--ReferenceCount();}
|
||||
~TOneStatic() {--m_refCount;}
|
||||
|
||||
template<typename... Args> void reset(Args&&... args)
|
||||
{new (m_allocspace) T(std::forward<Args>(args)...);}
|
||||
|
@ -53,14 +62,4 @@ using TAreaId = u32;
|
|||
|
||||
}
|
||||
|
||||
namespace rstl
|
||||
{
|
||||
template <class T, size_t N>
|
||||
class reserved_vector : public std::vector<T>
|
||||
{
|
||||
public:
|
||||
reserved_vector() {this->reserve(N);}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __RETRO_TYPES_HPP__
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#include "rstl.hpp"
|
||||
|
||||
namespace rstl
|
||||
{
|
||||
|
||||
CRefData rstl::CRefData::sNull;
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef __RSTL_HPP__
|
||||
#define __RSTL_HPP__
|
||||
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace rstl
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Vector reserved on construction
|
||||
*/
|
||||
template <class T, size_t N>
|
||||
class reserved_vector : public std::vector<T>
|
||||
{
|
||||
public:
|
||||
reserved_vector() {this->reserve(N);}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Simple data/refcount pair
|
||||
*/
|
||||
class CRefData
|
||||
{
|
||||
void* m_ptr;
|
||||
int m_refCount;
|
||||
public:
|
||||
CRefData() : m_ptr(nullptr), m_refCount(0xffffff) {}
|
||||
CRefData(void* ptr) : m_ptr(ptr), m_refCount(0) {}
|
||||
|
||||
void* GetPtr() const {return m_ptr;}
|
||||
int AddRef() {return ++m_refCount;}
|
||||
int DelRef() {return --m_refCount;}
|
||||
|
||||
static CRefData sNull;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RSTL_HPP__
|
Loading…
Reference in New Issue