Skip to content

Commit 7aa42c9

Browse files
committed
ZenKit: refactor away usage of deprecated Vob fields
GothicKit/ZenKit#90
1 parent 008fec3 commit 7aa42c9

File tree

16 files changed

+101
-86
lines changed

16 files changed

+101
-86
lines changed

game/graphics/material.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ Material::Material(const zenkit::Material& m, bool enableAlphaTest) {
4444
; // envMapping = m.environment_mapping_strength;
4545
}
4646

47-
Material::Material(const zenkit::VirtualObject& vob) {
48-
tex = Resources::loadTexture(vob.visual_name);
49-
if(tex==nullptr && !vob.visual_name.empty())
47+
Material::Material(const zenkit::VisualDecal& decal) {
48+
tex = Resources::loadTexture(decal.name);
49+
if(tex==nullptr && !decal.name.empty())
5050
tex = Resources::loadTexture("DEFAULT.TGA");
51-
loadFrames(vob.visual_name, vob.visual_decal->texture_anim_fps);
51+
loadFrames(decal.name, decal.texture_anim_fps);
5252

53-
alpha = loadAlphaFunc(vob.visual_decal->alpha_func, zenkit::MaterialGroup::UNDEFINED, vob.visual_decal->alpha_weight, tex, true);
54-
alphaWeight = float(vob.visual_decal->alpha_weight)/255.f;
53+
alpha = loadAlphaFunc(decal.alpha_func, zenkit::MaterialGroup::UNDEFINED, decal.alpha_weight, tex, true);
54+
alphaWeight = float(decal.alpha_weight)/255.f;
5555
}
5656

5757
Material::Material(const zenkit::IParticleEffect& src) {

game/graphics/material.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Material final {
1111
public:
1212
Material()=default;
1313
Material(const zenkit::Material& m, bool enableAlphaTest);
14-
Material(const zenkit::VirtualObject& vob);
14+
Material(const zenkit::VisualDecal& decal);
1515
Material(const zenkit::IParticleEffect &src);
1616

1717
enum AlphaFunc:uint8_t {

game/graphics/objvisual.cpp

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -129,65 +129,79 @@ void ObjVisual::setVisual(const zenkit::IItem& hitem, World& world, bool staticD
129129
void ObjVisual::setVisual(const zenkit::VirtualObject& vob, World& world, bool staticDraw) {
130130
cleanup();
131131

132-
// const bool enableCollision = (vob.cd_dynamic || vob.cd_static);
133-
const bool enableCollision = (vob.cd_dynamic); // collide with player
132+
const bool enableCollision = vob.cd_dynamic; // collide with player
133+
std::string_view visName = vob.visual->name; // *.PFX; *.TGA; *.3DS; *.MDS; *.ASC; *.MMS
134134

135-
// *.ZEN; *.PFX; *.TGA; *.3DS; *.MDS; *.ASC; *.MMS
136-
if(FileExt::hasExt(vob.visual_name,"ZEN")) {
137-
setType(M_Bundle);
138-
bundle = VobBundle(world,vob.visual_name,(staticDraw ? Vob::Static : Vob::None));
139-
}
140-
else if(FileExt::hasExt(vob.visual_name,"PFX") || FileExt::hasExt(vob.visual_name,"TGA")) {
141-
if(vob.sprite_camera_facing_mode==zenkit::SpriteAlignment::NONE && FileExt::hasExt(vob.visual_name,"TGA")) {
135+
if(visName.empty())
136+
return;
137+
138+
// NOTE: .ZEN / M_Bundle is unused only by items - just assert it for now
139+
assert(!FileExt::hasExt(visName,"ZEN"));
140+
141+
switch (vob.visual->type) {
142+
case zenkit::VisualType::MESH:
143+
case zenkit::VisualType::MULTI_RESOLUTION_MESH: {
144+
auto view = Resources::loadMesh(visName);
145+
if(!view)
146+
return;
142147
setType(M_Mesh);
143-
mesh.view = world.addDecalView(vob);
144-
} else {
145-
setType(M_Pfx);
146-
pfx = PfxEmitter(world,vob);
147-
pfx.setActive(true);
148-
pfx.setLooped(true);
149-
}
150-
}
151-
else if(FileExt::hasExt(vob.visual_name,"3DS")) {
152-
auto view = Resources::loadMesh(vob.visual_name);
153-
if(!view)
154-
return;
155-
setType(M_Mesh);
156-
mesh.proto = view;
157-
if(vob.show_visual) {
158-
mesh.view = world.addStaticView(view,staticDraw);
159-
mesh.view.setWind(vob.anim_mode,vob.anim_strength);
148+
mesh.proto = view;
149+
if(vob.show_visual) {
150+
mesh.view = world.addStaticView(view,staticDraw);
151+
mesh.view.setWind(vob.anim_mode,vob.anim_strength);
152+
}
153+
154+
const bool windy = (vob.anim_mode!=zenkit::AnimationType::NONE && vob.anim_strength>0);
155+
if(vob.show_visual && enableCollision && !windy) {
156+
mesh.physic = PhysicMesh(*view,*world.physic(),false);
157+
}
158+
break;
160159
}
160+
case zenkit::VisualType::MODEL:
161+
case zenkit::VisualType::MORPH_MESH:{
162+
// *.MDS; *.ASC; *.MMS
163+
auto visual = std::string(visName);
164+
FileExt::exchangeExt(visual,"ASC","MDL");
165+
166+
auto view = Resources::loadMesh(visual);
167+
if(!view)
168+
return;
169+
setType(M_Mdl);
170+
mdl.proto = view;
171+
mdl.view.setYTranslationEnable(false);
172+
mdl.view.setVisual(view->skeleton.get());
161173

162-
const bool windy = (vob.anim_mode!=zenkit::AnimationType::NONE && vob.anim_strength>0);
163-
if(vob.show_visual && enableCollision && !windy) {
164-
mesh.physic = PhysicMesh(*view,*world.physic(),false);
174+
if(vob.show_visual) {
175+
if((view->skeleton==nullptr || view->skeleton->animation()==nullptr) && enableCollision)
176+
mdl.view.setVisualBody(world,world.addStaticView(view,true)); else
177+
mdl.view.setVisualBody(world,world.addView(view));
178+
}
179+
180+
if(vob.show_visual && enableCollision) {
181+
mdl.physic = PhysicMesh(*view,*world.physic(),true);
182+
mdl.physic.setSkeleton(view->skeleton.get());
183+
}
184+
break;
165185
}
166-
}
167-
else if(FileExt::hasExt(vob.visual_name,"MDS") ||
168-
FileExt::hasExt(vob.visual_name,"MMS") ||
169-
FileExt::hasExt(vob.visual_name,"ASC")) {
170-
auto visual = vob.visual_name;
171-
FileExt::exchangeExt(visual,"ASC","MDL");
172-
173-
auto view = Resources::loadMesh(visual);
174-
if(!view)
175-
return;
176-
setType(M_Mdl);
177-
mdl.proto = view;
178-
mdl.view.setYTranslationEnable(false);
179-
mdl.view.setVisual(view->skeleton.get());
180-
181-
if(vob.show_visual) {
182-
if((view->skeleton==nullptr || view->skeleton->animation()==nullptr) && enableCollision)
183-
mdl.view.setVisualBody(world,world.addStaticView(view,true)); else
184-
mdl.view.setVisualBody(world,world.addView(view));
186+
case zenkit::VisualType::DECAL: {
187+
// *.TGA
188+
if(auto decal = dynamic_cast<const zenkit::VisualDecal*>(vob.visual.get())) {
189+
setType(M_Mesh);
190+
mesh.view = world.addDecalView(*decal);
191+
}
192+
break;
185193
}
186-
187-
if(vob.show_visual && enableCollision) {
188-
mdl.physic = PhysicMesh(*view,*world.physic(),true);
189-
mdl.physic.setSkeleton(view->skeleton.get());
194+
case zenkit::VisualType::PARTICLE_EFFECT: {
195+
// *.PFX
196+
setType(M_Pfx);
197+
pfx = PfxEmitter(world,vob);
198+
pfx.setActive(true);
199+
pfx.setLooped(true);
200+
break;
190201
}
202+
case zenkit::VisualType::AI_CAMERA:
203+
case zenkit::VisualType::UNKNOWN:
204+
break;
191205
}
192206
}
193207

game/graphics/pfx/particlefx.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
using namespace Tempest;
99

1010
ParticleFx::ParticleFx(const Material& mat, const zenkit::VirtualObject& vob) {
11-
dbgName = vob.visual_name;
11+
dbgName = vob.visual->name;
1212

1313
ppsValue = -1;
1414
lspPartAvg = 1000;
1515
dirMode = ParticleFx::Dir::Dir;
1616
visTexColorStart = Vec3(255,255,255);
1717
visTexColorEnd = Vec3(255,255,255);
18-
visSizeStart = Vec2(2.f*vob.visual_decal->dimension.x,
19-
2.f*vob.visual_decal->dimension.y);
18+
if(auto decal = dynamic_cast<const zenkit::VisualDecal*>(vob.visual.get())) {
19+
visSizeStart = Vec2(2.f*decal->dimension.x,
20+
2.f*decal->dimension.y);
21+
}
2022
visOrientation = Orientation::None;
2123

2224
visMaterial = mat;

game/graphics/worldview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ MeshObjects::Mesh WorldView::addStaticView(std::string_view visual) {
199199
return MeshObjects::Mesh();
200200
}
201201

202-
MeshObjects::Mesh WorldView::addDecalView(const zenkit::VirtualObject& vob) {
202+
MeshObjects::Mesh WorldView::addDecalView(const zenkit::VisualDecal& vob) {
203203
if(auto mesh=Resources::decalMesh(vob))
204204
return MeshObjects::Mesh(objGroup,*mesh,0,0,0,true);
205205
return MeshObjects::Mesh();

game/graphics/worldview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class WorldView {
6969
MeshObjects::Mesh addAtachView (const ProtoMesh::Attach& visual, const int32_t version);
7070
MeshObjects::Mesh addStaticView(const ProtoMesh* visual, bool staticDraw = false);
7171
MeshObjects::Mesh addStaticView(std::string_view visual);
72-
MeshObjects::Mesh addDecalView (const zenkit::VirtualObject& vob);
72+
MeshObjects::Mesh addDecalView (const zenkit::VisualDecal& vob);
7373

7474
void dbgClusters(Tempest::Painter& p, Tempest::Vec2 wsz);
7575

game/resources.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@ PfxEmitterMesh* Resources::implLoadEmiterMesh(std::string_view name) {
544544
return nullptr;
545545
}
546546

547-
ProtoMesh* Resources::implDecalMesh(const zenkit::VirtualObject& vob) {
547+
ProtoMesh* Resources::implDecalMesh(const zenkit::VisualDecal& decal) {
548548
DecalK key;
549-
key.mat = Material(vob);
550-
key.sX = vob.visual_decal->dimension.x;
551-
key.sY = vob.visual_decal->dimension.y;
552-
key.decal2Sided = vob.visual_decal->two_sided;
549+
key.mat = Material(decal);
550+
key.sX = decal.dimension.x;
551+
key.sY = decal.dimension.y;
552+
key.decal2Sided = decal.two_sided;
553553

554554
if(key.mat.tex==nullptr)
555555
return nullptr;
@@ -833,9 +833,9 @@ Dx8::PatternList Resources::loadDxMusic(std::string_view name) {
833833
return inst->implLoadDxMusic(name);
834834
}
835835

836-
const ProtoMesh* Resources::decalMesh(const zenkit::VirtualObject& vob) {
836+
const ProtoMesh* Resources::decalMesh(const zenkit::VisualDecal& decal) {
837837
std::lock_guard<std::recursive_mutex> g(inst->sync);
838-
return inst->implDecalMesh(vob);
838+
return inst->implDecalMesh(decal);
839839
}
840840

841841
const Resources::VobTree* Resources::loadVobBundle(std::string_view name) {

game/resources.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Resources final {
106106
static Tempest::Sound loadSoundBuffer(std::string_view name);
107107

108108
static Dx8::PatternList loadDxMusic(std::string_view name);
109-
static const ProtoMesh* decalMesh(const zenkit::VirtualObject& vob);
109+
static const ProtoMesh* decalMesh(const zenkit::VisualDecal& decal);
110110

111111
static const VobTree* loadVobBundle(std::string_view name);
112112

@@ -175,7 +175,7 @@ class Resources final {
175175
ProtoMesh* implLoadMesh(std::string_view name);
176176
std::unique_ptr<ProtoMesh> implLoadMeshMain(std::string name);
177177
std::unique_ptr<Animation> implLoadAnimation(std::string name);
178-
ProtoMesh* implDecalMesh(const zenkit::VirtualObject& vob);
178+
ProtoMesh* implDecalMesh(const zenkit::VisualDecal& decal);
179179
Tempest::Sound implLoadSoundBuffer(std::string_view name);
180180
Dx8::PatternList implLoadDxMusic(std::string_view name);
181181
GthFont& implLoadFont(std::string_view fname, FontType type);

game/world/objects/interactive.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ Interactive::Interactive(Vob* parent, World &world, const zenkit::VMovableObject
8585
}
8686

8787
setVisual(vob);
88-
if(vob.visual!=nullptr)
89-
mdlVisual = std::move(vob.visual->name);
88+
mdlVisual = std::move(vob.visual->name);
9089

9190
if(isLadder() && !mdlVisual.empty()) {
9291
// NOTE: there must be else way to determinate steps count, nut for now - we parse filename

game/world/objects/pfxemitter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ PfxEmitter::PfxEmitter(World& world, const zenkit::VirtualObject& vob) {
4343
std::lock_guard<std::recursive_mutex> guard(owner.sync);
4444
bucket = &owner.getBucket(*decl);
4545
id = bucket->allocEmitter();
46-
} else {
47-
Material mat(vob);
46+
}
47+
else if(auto decal = dynamic_cast<const zenkit::VisualDecal*>(vob.visual.get())) {
48+
Material mat(*decal);
4849
std::lock_guard<std::recursive_mutex> guard(owner.sync);
4950
bucket = &owner.getBucket(mat,vob);
5051
id = bucket->allocEmitter();

0 commit comments

Comments
 (0)