Code cleanup and add NamedResourceCatalog

This commit is contained in:
Phillip Stephens 2016-02-20 00:31:11 -08:00
parent 5229f95fb7
commit 8af98fb2f3
5 changed files with 154 additions and 14 deletions

View File

@ -21,6 +21,7 @@ add_library(DNACommon
ParticleCommon.cpp
DeafBabe.hpp
BabeDead.hpp
NamedResourceCatalog.hpp
Tweaks/ITweakGame.hpp
Tweaks/ITweakParticle.hpp
Tweaks/ITweakPlayer.hpp

View File

@ -0,0 +1,132 @@
#ifndef __DNACOMMON_NAMEDRESOURCECATALOG_HPP__
#define __DNACOMMON_NAMEDRESOURCECATALOG_HPP__
#include "DNACommon.hpp"
namespace DataSpec
{
template <class IDType>
struct NamedResourceCatalog : BigYAML
{
Delete _d;
Value<atUint32> namedResCount;
struct NamedResource : BigYAML
{
Delete _d;
DNAFourCC type;
String<-1> name;
IDType uid;
void read(Athena::io::IStreamReader& __dna_reader)
{
/* type */
type.read(__dna_reader);
/* name */
name = __dna_reader.readString(-1);
/* uid */
uid.read(__dna_reader);
}
void write(Athena::io::IStreamWriter& __dna_writer) const
{
/* type */
type.write(__dna_writer);
/* name */
__dna_writer.writeString(name, -1);
/* uid */
uid.write(__dna_writer);
}
void read(Athena::io::YAMLDocReader& __dna_docin)
{
/* type */
__dna_docin.enumerate("type", type);
/* name */
name = __dna_docin.readString("name");
/* uid */
__dna_docin.enumerate("uid", uid);
}
void write(Athena::io::YAMLDocWriter& __dna_docout) const
{
/* type */
__dna_docout.enumerate("type", type);
/* name */
__dna_docout.writeString("name", name);
/* uid */
__dna_docout.enumerate("uid", uid);
}
static const char* DNAType() { return "DataSpec::DNACommon::NameResourceCatalog::NamedResource"; }
size_t binarySize(size_t __isz) const
{
__isz = type.binarySize(__isz);
__isz += name.size() + 1;
__isz = uid.binarySize(__isz);
return __isz;
}
};
Vector<NamedResource, DNA_COUNT(namedResCount)> namedResources;
void read(Athena::io::IStreamReader& __dna_reader)
{
/* namedResCount */
namedResCount = __dna_reader.readUint32Big();
/* namedResources */
__dna_reader.enumerate(namedResources, namedResCount);
}
void write(Athena::io::IStreamWriter& __dna_writer) const
{
/* namedResCount */
__dna_writer.writeUint32Big(namedResCount);
/* namedResources */
__dna_writer.enumerate(namedResources);
}
void read(Athena::io::YAMLDocReader& __dna_docin)
{
/* namedResCount */
namedResCount = __dna_docin.readUint32("namedResCount");
/* namedResources */
__dna_docin.enumerate("namedResources", namedResources, namedResCount);
}
void write(Athena::io::YAMLDocWriter& __dna_docout) const
{
/* namedResCount */
__dna_docout.writeUint32("namedResCount", namedResCount);
/* namedResources */
__dna_docout.enumerate("namedResources", namedResources);
}
static const char* DNAType()
{
return "DataSpec::DNACommon::NameResourceCatalog";
}
size_t binarySize(size_t __isz) const
{
__isz = __EnumerateSize(__isz, namedResources);
return __isz + 4;
}
void addNamedResource(const std::string& name, const IDType& id, const DNAFourCC& type)
{
NamedResource res;
res.type = type;
res.name = name;
res.uid = id;
auto it = std::find_if(namedResources.begin(), namedResources.end(), [res](const NamedResource& a)->bool
{ return (a.name == res.name && a.type == res.type && a.uid == res.uid); });
if (it != namedResources.end())
return;
namedResources.push_back(std::move(res));
namedResCount++;
}
};
}
#endif // NAMEDRESOURCECATALOG_HPP

View File

@ -2,6 +2,7 @@
#define __DNACOMMON_PAK_HPP__
#include "DNACommon.hpp"
#include "NamedResourceCatalog.hpp"
namespace DataSpec
{
@ -240,6 +241,7 @@ public:
using EntryType = typename PAKType::Entry;
using RigPair = std::pair<IDType, IDType>;
private:
NamedResourceCatalog<IDType> m_catalog;
const SpecBase& m_dataSpec;
const std::vector<BRIDGETYPE>* m_bridges = nullptr;
std::vector<std::pair<HECL::ProjectPath,HECL::ProjectPath>> m_bridgePaths;
@ -309,9 +311,21 @@ public:
/* Add RigPairs to global map */
bridge.addCMDLRigPairs(*this, m_cmdlRigs);
/* Add named resources to catalog */
for (const auto& namedEntry : pak.m_nameEntries)
m_catalog.addNamedResource(namedEntry.name, namedEntry.id, namedEntry.type);
progress(++count / bridgesSz);
++bridgeIdx;
}
HECL::SystemString catalogPath = m_gameCooked.getAbsolutePath() + _S("/catalog.yaml");
FILE* catalog = HECL::Fopen(catalogPath.c_str(), _S("wb"));
if (catalog)
{
m_catalog.toYAMLFile(catalog);
fclose(catalog);
}
}
void enterPAKBridge(const BRIDGETYPE& pakBridge)

View File

@ -25,6 +25,13 @@ class CInputGenerator : public boo::DeviceFinder
float m_leftDiv;
float m_rightDiv;
CKeyboardMouseControllerData m_data;
CFinalInput m_lastUpdate;
const CFinalInput& getFinalInput(unsigned idx, float dt)
{
m_lastUpdate = CFinalInput(idx, dt, m_data, m_lastUpdate);
return m_lastUpdate;
}
public:
CInputGenerator(float leftDiv, float rightDiv)
: boo::DeviceFinder({typeid(boo::DolphinSmashAdapter)}),
@ -90,13 +97,6 @@ public:
m_data.m_accumScroll.zeroOut();
}
CFinalInput m_lastUpdate;
const CFinalInput& getFinalInput(unsigned idx, float dt)
{
m_lastUpdate = CFinalInput(idx, dt, m_data, m_lastUpdate);
return m_lastUpdate;
}
/* Input via the smash adapter is received asynchronously on a USB
* report thread. This class atomically exchanges that data to the
* game thread as needed */

View File

@ -225,10 +225,6 @@ int CMain::appMain(boo::IApplication* app)
float rgba[4] = { 0.2f, 0.2f, 0.2f, 1.0f};
gfxQ->setClearColor(rgba);
float time = 0.0f;
int frame = 0;
CTimeProvider test(time);
while (!xe8_b24_finished)
{
mainWindow->waitForRetrace();
@ -237,9 +233,6 @@ int CMain::appMain(boo::IApplication* app)
gfxQ->resolveDisplay(nullptr);
gfxQ->execute();
time = (frame++) / 60.f;
//fprintf(stderr, "%f\n", test.x0_currentTime);
}
return 0;
}