Skip to content

Commit

Permalink
pfx fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Aug 1, 2021
1 parent ddb8cf8 commit 068fa6c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
14 changes: 8 additions & 6 deletions game/game/definitions/particlesdefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ ParticlesDefinitions::~ParticlesDefinitions() {
vm->clearReferences(Daedalus::IC_Pfx);
}

const ParticleFx* ParticlesDefinitions::get(std::string_view name) {
const ParticleFx* ParticlesDefinitions::get(std::string_view name, bool relaxed) {
if(name.empty())
return nullptr;

while(FileExt::hasExt(name,"PFX"))
name = name.substr(0,name.size()-4);

std::lock_guard<std::recursive_mutex> guard(sync);
return implGet(name);
return implGet(name,relaxed);
}

const ParticleFx* ParticlesDefinitions::get(const ParticleFx* base, const VisualFx::Key* key) {
Expand All @@ -34,13 +34,13 @@ const ParticleFx* ParticlesDefinitions::get(const ParticleFx* base, const Visual
return implGet(*base,*key);
}

const ParticleFx* ParticlesDefinitions::implGet(std::string_view name) {
const ParticleFx* ParticlesDefinitions::implGet(std::string_view name, bool relaxed) {
auto cname = std::string(name);
auto it = pfx.find(cname);
if(it!=pfx.end())
return it->second.get();
Daedalus::GEngineClasses::C_ParticleFX decl={};
if(!implGet(name,decl))
if(!implGet(name,decl,relaxed))
return nullptr;
std::unique_ptr<ParticleFx> p{new ParticleFx(decl,name)};
auto elt = pfx.insert(std::make_pair(std::move(cname),std::move(p)));
Expand All @@ -60,15 +60,17 @@ const ParticleFx* ParticlesDefinitions::implGet(const ParticleFx& base, const Vi
}

bool ParticlesDefinitions::implGet(std::string_view name,
Daedalus::GEngineClasses::C_ParticleFX& ret) {
Daedalus::GEngineClasses::C_ParticleFX& ret,
bool relaxed) {
if(!vm || name.empty())
return false;

char buf[256] = {};
std::snprintf(buf,sizeof(buf),"%.*s",int(name.size()),name.data());
auto id = vm->getDATFile().getSymbolIndexByName(buf);
if(id==size_t(-1)) {
Log::e("invalid particle system: \"",buf,"\"");
if(!relaxed)
Log::e("invalid particle system: \"",buf,"\"");
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions game/game/definitions/particlesdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ParticlesDefinitions final {
ParticlesDefinitions();
~ParticlesDefinitions();

const ParticleFx* get(std::string_view name);
const ParticleFx* get(std::string_view name, bool relaxed);
const ParticleFx* get(const ParticleFx* base, const VisualFx::Key* key);

private:
Expand All @@ -25,8 +25,8 @@ class ParticlesDefinitions final {
std::unordered_map<std::string, std::unique_ptr<ParticleFx>> pfx;
std::unordered_map<const VisualFx::Key*, std::unique_ptr<ParticleFx>> pfxKey;

const ParticleFx* implGet(std::string_view name);
const ParticleFx* implGet(std::string_view name, bool relaxed);
const ParticleFx* implGet(const ParticleFx& base, const VisualFx::Key& key);

bool implGet(std::string_view name, Daedalus::GEngineClasses::C_ParticleFX &ret);
bool implGet(std::string_view name, Daedalus::GEngineClasses::C_ParticleFX &ret, bool relaxed);
};
4 changes: 2 additions & 2 deletions game/gothic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ const VisualFx* Gothic::loadVisualFx(std::string_view name) {
return vfxDef->get(name);
}

const ParticleFx* Gothic::loadParticleFx(std::string_view name) {
return particleDef->get(name);
const ParticleFx* Gothic::loadParticleFx(std::string_view name, bool relaxed) {
return particleDef->get(name,relaxed);
}

const ParticleFx* Gothic::loadParticleFx(const ParticleFx* base, const VisualFx::Key* key) {
Expand Down
2 changes: 1 addition & 1 deletion game/gothic.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Gothic final {
SoundFx* loadSoundFx (std::string_view name);
SoundFx* loadSoundWavFx(std::string_view name);

auto loadParticleFx(std::string_view name) -> const ParticleFx*;
auto loadParticleFx(std::string_view name, bool relaxed=false) -> const ParticleFx*;
auto loadParticleFx(const ParticleFx* base, const VisualFx::Key* key) -> const ParticleFx*;
auto loadVisualFx (std::string_view name) -> const VisualFx*;

Expand Down
5 changes: 4 additions & 1 deletion game/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Sound World::addHitEffect(std::string_view src, std::string_view dst, std::strin
auto ret = Sound(*this,::Sound::T_Regular,buf,pos3,2500.f,false);

std::snprintf(buf,sizeof(buf),"CPFX_%.*s_%.*s_%.*s", int(scheme.size()),scheme.data(), int(src.size()),src.data(), int(dst.size()),dst.data());
if(Gothic::inst().loadParticleFx(buf)==nullptr) {
if(Gothic::inst().loadParticleFx(buf,true)==nullptr) {
if(dst=="ME")
std::snprintf(buf,sizeof(buf),"CPFX_%.*s_%s",int(scheme.size()),scheme.data(),"METAL");
else if(dst=="WO")
Expand All @@ -730,6 +730,9 @@ Sound World::addHitEffect(std::string_view src, std::string_view dst, std::strin
else
return ret;
}
if(Gothic::inst().loadParticleFx(buf,true)==nullptr)
return ret;

Effect e(PfxEmitter(*this,buf),"");
e.setObjMatrix(pos);
e.setActive(true);
Expand Down

0 comments on commit 068fa6c

Please sign in to comment.