OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
particlesdefinitions.cpp
Go to the documentation of this file.
2
3#include <Tempest/Log>
4
6#include "utils/fileext.h"
7#include "gothic.h"
8
9using namespace Tempest;
10
14
17
18const ParticleFx* ParticlesDefinitions::get(std::string_view name, bool relaxed) {
19 if(name.empty())
20 return nullptr;
21
22 while(FileExt::hasExt(name,"PFX"))
23 name = name.substr(0,name.size()-4);
24
25 std::lock_guard<std::recursive_mutex> guard(sync);
26 return implGet(name,relaxed);
27 }
28
30 if(base==nullptr || key==nullptr)
31 return base;
32 std::lock_guard<std::recursive_mutex> guard(sync);
33 return implGet(*base,*key);
34 }
35
36const ParticleFx* ParticlesDefinitions::implGet(std::string_view name, bool relaxed) {
37 auto cname = std::string(name);
38 auto it = pfx.find(cname);
39 if(it!=pfx.end())
40 return it->second.get();
41 auto decl=implGetDirect(name, relaxed);
42 if(!decl)
43 return nullptr;
44 std::unique_ptr<ParticleFx> p{new ParticleFx(*decl,name)};
45 auto elt = pfx.insert(std::make_pair(std::move(cname),std::move(p)));
46
47 return elt.first->second.get();
48 }
49
50const ParticleFx* ParticlesDefinitions::implGet(const ParticleFx& base, const VisualFx::Key& key) {
51 auto it = pfxKey.find(&key);
52 if(it!=pfxKey.end())
53 return it->second.get();
54
55 std::unique_ptr<ParticleFx> p{new ParticleFx(base,key)};
56 auto elt = pfxKey.insert(std::make_pair(&key,std::move(p)));
57
58 return elt.first->second.get();
59 }
60
61std::shared_ptr<zenkit::IParticleEffect> ParticlesDefinitions::implGetDirect(std::string_view name, bool relaxed) {
62 if(!vm || name.empty())
63 return nullptr;
64
65 auto id = vm->find_symbol_by_name(name);
66 if(id==nullptr) {
67 if(!relaxed)
68 Log::e("invalid particle system: \"",name,"\"");
69 return nullptr;
70 }
71
72 auto ret = std::make_shared<zenkit::IParticleEffect>();
73 ret->vis_tex_is_quadpoly = 1; // seem to be default
74 vm->init_instance(ret, id);
75 return ret;
76 }
static Gothic & inst()
Definition gothic.cpp:249
std::unique_ptr< zenkit::DaedalusVm > createPhoenixVm(std::string_view datFile, const ScriptLang lang=ScriptLang::NONE)
Definition gothic.cpp:711
const ParticleFx * get(std::string_view name, bool relaxed)
bool hasExt(std::string_view s, const char *extIn)
Definition fileext.h:8