Glitter: Change load logic a bit

This commit is contained in:
korenkonder
2024-01-28 21:34:34 +03:00
parent 4fb12ee771
commit 54d42d6964
5 changed files with 243 additions and 132 deletions
+161 -109
View File
@@ -10,7 +10,8 @@
namespace Glitter {
EffectInst::EffectInst(GPM, GLT, Effect* eff,
size_t id, float_t emission, bool appear_now) : data(GLT_VAL) {
size_t id, bool appear_now, bool init) : data(GLT_VAL) {
this->init = init;
effect = eff;
data = eff->data;
color = 1.0f;
@@ -112,13 +113,13 @@ namespace Glitter {
}
F2EffectInst::F2EffectInst(GPM, GLT, Effect* eff,
size_t id, float_t emission, bool appear_now)
: EffectInst(GPM_VAL, GLT_VAL, eff, id, emission, appear_now) {
F2EffectInst::F2EffectInst(GPM, GLT, Effect* eff, size_t id,
Scene* sc, bool appear_now, bool init)
: EffectInst(GPM_VAL, GLT_VAL, eff, id, appear_now, init) {
random_ptr = &Glitter::random;
ext_anim = 0;
if (!(eff->data.flags & EFFECT_LOCAL) && data.ext_anim) {
if (!init && !(eff->data.flags & EFFECT_LOCAL) && data.ext_anim) {
F2EffectInst::ExtAnim* inst_ext_anim = new F2EffectInst::ExtAnim;
if (inst_ext_anim) {
Effect::ExtAnim* ext_anim = data.ext_anim;
@@ -156,11 +157,13 @@ namespace Glitter {
if (!i)
continue;
F2EmitterInst* emitter = new F2EmitterInst(i, this, emission);
F2EmitterInst* emitter = new F2EmitterInst(i, this, sc->emission);
if (emitter)
emitters.push_back(emitter);
}
CtrlInit(GPM_VAL, GLT_VAL, emission);
if (!init)
ResetInit(GPM_VAL, GLT_VAL, sc);
}
F2EffectInst::~F2EffectInst() {
@@ -258,7 +261,7 @@ namespace Glitter {
return true;
}
void F2EffectInst::Reset(GPM, GLT, float_t emission) {
void F2EffectInst::Reset(GPM, GLT, Scene* sc) {
frame0 = -(float_t)data.appear_time;
frame1 = 0.0;
@@ -282,55 +285,13 @@ namespace Glitter {
if (i)
i->Reset();
CtrlInit(GPM_VAL, GLT_VAL, emission);
ResetInit(GPM_VAL, GLT_VAL, sc);
}
void F2EffectInst::CtrlInit(GPM, GLT, float_t emission) {
if (data.start_time < 1)
return;
float_t delta_frame = 2.0f;
float_t start_time = (float_t)data.start_time - frame1;
while (start_time > 0.0f) {
enum_or(flags, EFFECT_INST_JUST_INIT);
if (start_time < delta_frame)
delta_frame -= start_time;
if (frame0 >= 0.0f) {
GetValue(GLT_VAL);
mat4 mat;
mat4_translate(&translation, &mat);
vec3 rot = rotation;
vec3 scale = this->scale * scale_all;
mat4_mul_rotate_zyx(&mat, &rot, &mat);
mat4_scale_rot(&mat, &scale, &this->mat);
for (F2EmitterInst*& i : emitters)
if (i)
i->CtrlInit(GPM_VAL, GLT_VAL, this, delta_frame);
if (frame0 < (float_t)data.life_time) {
for (F2EmitterInst*& i : emitters)
if (i)
i->Emit(GPM_VAL, GLT_VAL, delta_frame, emission);
}
else if (data.flags & EFFECT_LOOP)
frame0 -= (float_t)data.life_time;
else
Free(GPM_VAL, GLT_VAL, emission, false);
render_scene.Ctrl(GLT_VAL, delta_frame);
}
frame0 += delta_frame;
frame1 += delta_frame;
start_time -= delta_frame;
}
CtrlMat(GPM_VAL, GLT_VAL);
bool F2EffectInst::ResetCheckInit(GPM, GLT, Scene* sc, float_t* a3) {
if (init)
return ResetInit(GPM_VAL, GLT_VAL, sc, a3);
return false;
}
void F2EffectInst::CtrlMat(GPM, GLT) {
@@ -592,6 +553,72 @@ namespace Glitter {
}
}
bool F2EffectInst::ResetInit(GPM, GLT, Glitter::Scene* sc, float_t* a3) {
if (data.start_time < 1)
return false;
if (!init && sc->effect_group && sc->effect_group->scene
&& sc->effect_group->scene->Copy(this, sc)) {
frame1 = (float_t)data.start_time;
return false;
}
float_t delta_frame = 2.0f;
float_t start_time = (float_t)data.start_time - frame1;
bool ret = false;
if (a3) {
if (start_time >= *a3) {
start_time = *a3;
*a3 = 0.0f;
ret = true;
}
else
*a3 -= start_time;
}
while (start_time > 0.0f) {
enum_or(flags, EFFECT_INST_JUST_INIT);
if (start_time < delta_frame)
delta_frame -= start_time;
if (frame0 >= 0.0f) {
GetValue(GLT_VAL);
vec3 trans = translation;
vec3 rot = rotation;
vec3 scale = this->scale * scale_all;
mat4 mat;
mat4_translate(&trans, &mat);
mat4_mul_rotate_zyx(&mat, &rot, &mat);
mat4_scale_rot(&mat, &scale, &this->mat);
for (F2EmitterInst*& i : emitters)
if (i)
i->CtrlInit(GPM_VAL, GLT_VAL, this, delta_frame);
if (frame0 < (float_t)data.life_time) {
for (F2EmitterInst*& i : emitters)
if (i)
i->Emit(GPM_VAL, GLT_VAL, delta_frame, sc->emission);
}
else if (data.flags & EFFECT_LOOP)
frame0 -= (float_t)data.life_time;
else
Free(GPM_VAL, GLT_VAL, sc->emission, false);
render_scene.Ctrl(GLT_VAL, delta_frame);
}
frame0 += delta_frame;
frame1 += delta_frame;
start_time -= delta_frame;
}
CtrlMat(GPM_VAL, GLT_VAL);
return ret;
}
XEffectInst::ExtAnim::ExtAnim() {
object_index = -1;
mesh_index = -1;
@@ -609,9 +636,9 @@ namespace Glitter {
}
XEffectInst::XEffectInst(GPM, Effect* eff,
size_t id, float_t emission, bool appear_now, uint8_t load_flags)
: EffectInst(GPM_VAL, Glitter::X, eff, id, emission, appear_now) {
XEffectInst::XEffectInst(GPM, Effect* eff, size_t id,
Scene* sc, bool appear_now, bool init, uint8_t load_flags)
: EffectInst(GPM_VAL, Glitter::X, eff, id, appear_now, init) {
mat_rot = mat4_identity;
mat_rot_eff_rot = mat4_identity;
random_shared.XReset();
@@ -629,7 +656,7 @@ namespace Glitter {
random = counter.GetValue();
random_shared.value = random;
if (!(eff->data.flags & EFFECT_LOCAL) && data.ext_anim_x) {
if (!init && !(eff->data.flags & EFFECT_LOCAL) && data.ext_anim_x) {
XEffectInst::ExtAnim* inst_ext_anim = new XEffectInst::ExtAnim;
if (inst_ext_anim) {
Effect::ExtAnimX* ext_anim = data.ext_anim_x;
@@ -673,12 +700,13 @@ namespace Glitter {
if (!i)
continue;
XEmitterInst* emitter = new XEmitterInst(i, this, emission);
XEmitterInst* emitter = new XEmitterInst(i, this, sc->emission);
if (emitter)
emitters.push_back(emitter);
}
CtrlInit(GPM_VAL, emission);
if (!init)
ResetInit(GPM_VAL, sc);
}
XEffectInst::~XEffectInst() {
@@ -795,7 +823,7 @@ namespace Glitter {
return true;
}
void XEffectInst::Reset(GPM, GLT, float_t emission) {
void XEffectInst::Reset(GPM, GLT, Scene* sc) {
frame0 = -(float_t)data.appear_time;
frame1 = 0.0;
@@ -827,55 +855,13 @@ namespace Glitter {
if (i)
i->Reset();
CtrlInit(GPM_VAL, emission);
ResetInit(GPM_VAL, sc);
}
void XEffectInst::CtrlInit(GPM, float_t emission) {
if (data.start_time < 1)
return;
float_t delta_frame = 2.0f;
float_t start_time = (float_t)data.start_time - frame1;
while (start_time > 0.0f) {
enum_or(flags, EFFECT_INST_JUST_INIT);
if (start_time < delta_frame)
delta_frame -= start_time;
if (frame0 >= 0.0f) {
GetValue();
vec3 trans = translation;
vec3 rot = rotation;
vec3 scale = this->scale * scale_all;
mat4 mat;
mat4_translate(&trans, &mat);
mat4_mul_rotate_zyx(&mat, &rot, &mat);
mat4_scale_rot(&mat, &scale, &this->mat);
for (XEmitterInst*& i : emitters)
if (i)
i->CtrlInit(this, delta_frame);
if (frame0 < (float_t)data.life_time) {
for (XEmitterInst*& i : emitters)
if (i)
i->Emit(delta_frame, emission);
}
else if (data.flags & EFFECT_LOOP)
frame0 -= (float_t)data.life_time;
else
Free(GPM_VAL, Glitter::X, emission, false);
render_scene.Ctrl(delta_frame, false);
}
frame0 += delta_frame;
frame1 += delta_frame;
start_time -= delta_frame;
}
CtrlMat(GPM_VAL);
bool XEffectInst::ResetCheckInit(GPM, GLT, Scene* sc, float_t* a3) {
if (init)
return ResetInit(GPM_VAL, sc, a3);
return false;
}
void XEffectInst::CtrlMat(GPM) {
@@ -1128,6 +1114,72 @@ namespace Glitter {
}
}
}
bool XEffectInst::ResetInit(GPM, Scene* sc, float_t* a3) {
if (data.start_time < 1)
return false;
if (!init && sc->effect_group && sc->effect_group->scene
&& sc->effect_group->scene->Copy(this, sc)) {
frame1 = (float_t)data.start_time;
return false;
}
float_t delta_frame = 2.0f;
float_t start_time = (float_t)data.start_time - frame1;
bool ret = false;
if (a3) {
if (start_time >= *a3) {
start_time = *a3;
*a3 = 0.0f;
ret = true;
}
else
*a3 -= start_time;
}
while (start_time > 0.0f) {
enum_or(flags, EFFECT_INST_JUST_INIT);
if (start_time < delta_frame)
delta_frame -= start_time;
if (frame0 >= 0.0f) {
GetValue();
vec3 trans = translation;
vec3 rot = rotation;
vec3 scale = this->scale * scale_all;
mat4 mat;
mat4_translate(&trans, &mat);
mat4_mul_rotate_zyx(&mat, &rot, &mat);
mat4_scale_rot(&mat, &scale, &this->mat);
for (XEmitterInst*& i : emitters)
if (i)
i->CtrlInit(this, delta_frame);
if (frame0 < (float_t)data.life_time) {
for (XEmitterInst*& i : emitters)
if (i)
i->Emit(delta_frame, sc->emission);
}
else if (data.flags & EFFECT_LOOP)
frame0 -= (float_t)data.life_time;
else
Free(GPM_VAL, Glitter::X, sc->emission, false);
render_scene.Ctrl(delta_frame, false);
}
frame0 += delta_frame;
frame1 += delta_frame;
start_time -= delta_frame;
}
CtrlMat(GPM_VAL);
return ret;
}
void XEffectInst::SetExtAnim(const mat4* a2, const mat4* a3, const vec3* trans, bool set_flags) {
EffectInstFlag flags = this->flags;
+36 -1
View File
@@ -49,6 +49,35 @@ namespace Glitter {
delete file_handler;
}
bool FileReader::CheckInit(GPM) {
if (!effect_group)
return true;
bool ret = 0;
if (!effect_group->scene_init) {
float_t v20 = Glitter::glt_particle_manager->field_D4;
if (Glitter::glt_particle_manager->field_D4 > 0.0f) {
if (effect_group->scene) {
if (effect_group->scene->ResetCheckInit(GPM_VAL, &v20))
ret = true;
else
effect_group->scene_init = true;
glt_particle_manager->sub_1403A53E0(v20);
}
else
effect_group->scene_init = true;
}
else
ret = true;
}
if (!ret) {
effect_group = 0;
return true;
}
return false;
}
bool FileReader::LoadFarc(void* data, const char* path,
const char* file, uint64_t hash, object_database* obj_db) {
this->obj_db = obj_db;
@@ -361,8 +390,14 @@ namespace Glitter {
}
bool FileReader::ReadFarc(GPM) {
if (state)
if (state) {
if (state == 1)
if (CheckInit(GPM_VAL))
state = 2;
else
return false;
return true;
}
if (file_handler && !file_handler->check_not_ready()) {
farc->read(file_handler->get_data(), file_handler->get_size(), true);
+16 -8
View File
@@ -876,6 +876,7 @@ namespace Glitter {
class EffectInst {
public:
bool init;
#if defined(CRE_DEV)
std::string name;
#endif
@@ -900,7 +901,7 @@ namespace Glitter {
float_t some_scale;
EffectInst(GPM, GLT, Effect* eff,
size_t id, float_t emission, bool appear_now);
size_t id, bool appear_now, bool init);
virtual ~EffectInst();
virtual void CalcDisp(GPM) = 0;
@@ -911,7 +912,8 @@ namespace Glitter {
virtual size_t GetCtrlCount(ParticleType type) = 0;
virtual size_t GetDispCount(ParticleType type) = 0;
virtual bool HasEnded(bool a2) = 0;
virtual void Reset(GPM, GLT, float_t emission) = 0;
virtual void Reset(GPM, GLT, Scene* sc) = 0;
virtual bool ResetCheckInit(GPM, GLT, Scene* sc, float_t* a3 = 0) = 0;
bool GetExtAnimScale(vec3* ext_anim_scale, float_t* some_scale);
void SetExtColor(bool set, float_t r, float_t g, float_t b, float_t a);
@@ -948,7 +950,7 @@ namespace Glitter {
ExtAnim* ext_anim;
F2RenderScene render_scene;
F2EffectInst(GPM, GLT, Effect* eff, size_t id, float_t emission, bool appear_now);
F2EffectInst(GPM, GLT, Effect* eff, size_t id, Scene* sc, bool appear_now, bool init);
virtual ~F2EffectInst() override;
virtual void CalcDisp(GPM) override;
@@ -959,9 +961,9 @@ namespace Glitter {
virtual size_t GetCtrlCount(ParticleType type) override;
virtual size_t GetDispCount(ParticleType type) override;
virtual bool HasEnded(bool a2) override;
virtual void Reset(GPM, GLT, float_t emission) override;
virtual void Reset(GPM, GLT, Scene* sc) override;
virtual bool ResetCheckInit(GPM, GLT, Scene* sc, float_t* a3 = 0) override;
void CtrlInit(GPM, GLT, float_t emission);
void CtrlMat(GPM, GLT);
DispType GetDispType();
void GetExtAnim();
@@ -969,6 +971,7 @@ namespace Glitter {
void GetExtColor(float_t& r, float_t& g, float_t& b, float_t& a);
FogType GetFog();
void GetValue(GLT);
bool ResetInit(GPM, GLT, Scene* sc, float_t* a3 = 0);
};
class XEffectInst : public EffectInst {
@@ -1004,7 +1007,7 @@ namespace Glitter {
ExtAnim* ext_anim;
XRenderScene render_scene;
XEffectInst(GPM, Effect* eff, size_t id, float_t emission, bool appear_now, uint8_t load_flags = 0);
XEffectInst(GPM, Effect* eff, size_t id, Scene* sc, bool appear_now, bool init, uint8_t load_flags = 0);
virtual ~XEffectInst() override;
virtual void CalcDisp(GPM) override;
@@ -1015,9 +1018,9 @@ namespace Glitter {
virtual size_t GetCtrlCount(ParticleType type) override;
virtual size_t GetDispCount(ParticleType type) override;
virtual bool HasEnded(bool a2) override;
virtual void Reset(GPM, GLT, float_t emission) override;
virtual void Reset(GPM, GLT, Scene* sc) override;
virtual bool ResetCheckInit(GPM, GLT, Scene* sc, float_t* a3 = 0) override;
void CtrlInit(GPM, float_t emission);
void CtrlMat(GPM);
DispType GetDispType();
void GetExtAnim();
@@ -1025,6 +1028,7 @@ namespace Glitter {
void GetExtColor(float_t& r, float_t& g, float_t& b, float_t& a);
FogType GetFog();
void GetValue();
bool ResetInit(GPM, Scene* sc, float_t* a3 = 0);
void SetExtAnim(const mat4* a2, const mat4* a3, const vec3* trans, bool set_flags);
};
@@ -1186,6 +1190,7 @@ namespace Glitter {
FileReader(GLT, const wchar_t* path, const wchar_t* file, float_t emission);
virtual ~FileReader();
bool CheckInit(GPM);
bool LoadFarc(void* data, const char* path, const char* file,
uint64_t hash, object_database* obj_db = 0);
void ParseAnimation(f2_struct* st, Animation* anim);
@@ -1581,6 +1586,7 @@ namespace Glitter {
bool HasEnded(bool a2);
bool HasEnded(size_t id, bool a3);
void InitEffect(GPM, Effect* eff, size_t id, bool appear_now, uint8_t load_flags = 0);
bool ResetCheckInit(GPM, float_t* a2);
bool ResetEffect(GPM, uint64_t effect_hash, size_t* id = 0);
bool SetExtColor(bool set, uint64_t effect_hash, float_t r, float_t g, float_t b, float_t a);
bool SetExtColorByID(bool set, size_t id, float_t r, float_t g, float_t b, float_t a);
@@ -1606,6 +1612,8 @@ namespace Glitter {
Camera cam;
ParticleManagerFlag flags;
int32_t scene_load_counter;
float_t field_D0;
float_t field_D4;
float_t emission;
float_t delta_frame;
uint32_t texture_counter;
+9 -5
View File
@@ -23,6 +23,8 @@ namespace Glitter {
#endif
bone_data(), frame_rate(), cam(), flags(),
scene_load_counter(), texture_counter(), draw_selected() {
field_D0 = 20.0f;
field_D4 = 20.0f;
emission = 1.5f;
delta_frame = 2.0f;
draw_all = true;
@@ -42,6 +44,7 @@ namespace Glitter {
bool GltParticleManager::ctrl() {
if (flags & PARTICLE_MANAGER_READ_FILES) {
field_D4 = field_D0;
for (auto i = file_readers.begin(); i != file_readers.end();)
if (!*i || (*i)->ReadFarc(this)) {
delete* i;
@@ -571,7 +574,7 @@ namespace Glitter {
if (!counter)
return 0;
Scene* scene = new Scene(counter, effect_group_hash, eff_group, 0);
Scene* scene = new Scene(counter, effect_group_hash, eff_group, false);
if (!scene)
return 0;
@@ -781,7 +784,7 @@ namespace Glitter {
if (!counter)
return 0;
Scene* scene = new Scene(counter, i.first, i.second, 0);
Scene* scene = new Scene(counter, i.first, i.second, false);
if (!scene)
return 0;
@@ -950,9 +953,10 @@ namespace Glitter {
}
void GltParticleManager::sub_1403A53E0(float_t a2) {
//field_D4 = a2;
//if (a2 <= 0.0)
// field_D4 = -1.0;
if (a2 <= 0.0f)
field_D4 = -1.0f;
else
field_D4 = a2;
}
void glt_particle_manager_init() {
+21 -9
View File
@@ -274,17 +274,19 @@ namespace Glitter {
if (!eff)
return;
for (SceneEffect& i : effects)
if (i.ptr && i.disp && i.ptr->id == id) {
i.ptr->Reset(GPM_VAL, type, emission);
return;
}
bool init = !!(flags & SCENE_FLAG_3);
if (!init)
for (SceneEffect& i : effects)
if (i.ptr && i.disp && i.ptr->id == id) {
i.ptr->Reset(GPM_VAL, type, this);
return;
}
SceneEffect effect;
if (type != Glitter::X)
effect.ptr = new F2EffectInst(GPM_VAL, type, eff, id, emission, appear_now);
effect.ptr = new F2EffectInst(GPM_VAL, type, eff, id, this, appear_now, init);
else
effect.ptr = new XEffectInst(GPM_VAL, eff, id, emission, appear_now, load_flags);
effect.ptr = new XEffectInst(GPM_VAL, eff, id, this, appear_now, init, load_flags);
effect.disp = true;
effects.push_back(effect);
@@ -294,6 +296,16 @@ namespace Glitter {
#endif
}
bool Scene::ResetCheckInit(GPM, float_t* a2) {
if (!(flags & SCENE_FLAG_3) || !effects.size())
return false;
for (SceneEffect& i : effects)
if (i.disp && i.ptr && i.ptr->ResetCheckInit(GPM_VAL, type, this, a2))
return true;
return false;
}
bool Scene::ResetEffect(GPM, uint64_t effect_hash, size_t* id) {
#if defined(CRE_DEV)
if (type == Glitter::X) {
@@ -328,13 +340,13 @@ namespace Glitter {
|| type != Glitter::FT && effect_hash == hash_murmurhash_empty) {
for (SceneEffect& i : effects)
if (i.disp && i.ptr)
i.ptr->Reset(GPM_VAL, type, emission);
i.ptr->Reset(GPM_VAL, type, this);
return true;
}
else
for (SceneEffect& i : effects)
if (i.disp && i.ptr && i.ptr->data.name_hash == effect_hash) {
i.ptr->Reset(GPM_VAL, type, emission);
i.ptr->Reset(GPM_VAL, type, this);
#if defined(CRE_DEV)
enum_and(flags, ~SCENE_ENDED);