Skip to content

Commit

Permalink
Merge pull request #113 from Gratt-5r2/dev_meshlib
Browse files Browse the repository at this point in the history
Provides an unique meshlib for each npc
  • Loading branch information
SaiyansKing committed Mar 14, 2023
2 parents 4b63097 + 5b1934d commit 7e931b7
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 3 deletions.
49 changes: 46 additions & 3 deletions D3D11Engine/GothicAPI.cpp
Expand Up @@ -610,7 +610,11 @@ void GothicAPI::ResetVobs() {
for ( auto const& it : SkeletalMeshVisuals ) {
delete it.second;
}
for ( auto const& it : SkeletalMeshNpcs ) {
delete it.second;
}
SkeletalMeshVisuals.clear();
SkeletalMeshNpcs.clear();

// Delete static mesh vobs
for ( auto const& it : VobMap ) {
Expand Down Expand Up @@ -1219,6 +1223,10 @@ void GothicAPI::OnMaterialDeleted( zCMaterial* mat ) {
it.second->Meshes.erase( mat );
it.second->SkeletalMeshes.erase( mat );
}
for ( auto&& it : SkeletalMeshNpcs ) {
it.second->Meshes.erase( mat );
it.second->SkeletalMeshes.erase( mat );
}
}

/** Called when a material got created */
Expand Down Expand Up @@ -1361,10 +1369,27 @@ void GothicAPI::OnVisualDeleted( zCVisual* visual ) {
vobInfo->VisualInfo = nullptr;
}
}

delete SkeletalMeshVisuals[str];
SkeletalMeshVisuals.erase( str );
}

delete SkeletalMeshVisuals[str];
SkeletalMeshVisuals.erase( str );
zCVob* homeVob = zmodel->GetHomeVob();
if ( homeVob && homeVob->GetVobType() == zVOB_TYPE_NSC ) {
oCNPC* npc = static_cast<oCNPC*>(homeVob);
auto it = SkeletalMeshNpcs.find( npc );
if ( it != SkeletalMeshNpcs.end() ) {
// Find vobs using this visual
for ( SkeletalVobInfo* vobInfo : SkeletalMeshVobs ) {
if ( vobInfo->VisualInfo == it->second ) {
vobInfo->VisualInfo = nullptr;
}
}

delete SkeletalMeshNpcs[npc];
SkeletalMeshNpcs.erase( npc );
}
}
}
break;
}
Expand Down Expand Up @@ -1766,7 +1791,9 @@ void GothicAPI::OnAddVob( zCVob* vob, zCWorld* world ) {
// Add vob to the skeletal list
SkeletalVobInfo* vi = new SkeletalVobInfo;
vi->Vob = vob;
vi->VisualInfo = SkeletalMeshVisuals[str];
vi->VisualInfo = vob->GetVobType() == zVOB_TYPE_NSC ?
LoadzCModelData( static_cast<oCNPC*>(vob) ) :
LoadzCModelData( static_cast<zCModel*>(vob->GetVisual()) );

// Add to map
VobsByVisual[vob->GetVisual()].push_back( vi );
Expand Down Expand Up @@ -1818,6 +1845,22 @@ SkeletalMeshVisualInfo* GothicAPI::LoadzCModelData( zCModel* model ) {
return mi;
}

SkeletalMeshVisualInfo* GothicAPI::LoadzCModelData( oCNPC* npc ) {
SkeletalMeshVisualInfo* mi = SkeletalMeshNpcs[npc];
if ( !mi ) {
mi = new SkeletalMeshVisualInfo;
SkeletalMeshNpcs[npc] = mi;
}

zCModel* model = static_cast<zCModel*>(npc->GetVisual());
mi->Visual = model;

// Update a visual information
mi->ClearMeshes();
WorldConverter::ExtractSkeletalMeshFromVob( model, mi );
return mi;
}

// TODO: REMOVE THIS!
#include "D3D11GraphicsEngine.h"

Expand Down
2 changes: 2 additions & 0 deletions D3D11Engine/GothicAPI.h
Expand Up @@ -659,6 +659,7 @@ class GothicAPI {

/** Loads the data out of a zCModel and stores it in the cache */
SkeletalMeshVisualInfo* LoadzCModelData( zCModel* model );
SkeletalMeshVisualInfo* LoadzCModelData( oCNPC* npc );

/** Prints a message to the screen for the given amount of time */
void PrintMessageTimed( const INT2& position, const std::string& strMessage, float time = 3000.0f, DWORD color = 0xFFFFFFFF );
Expand Down Expand Up @@ -752,6 +753,7 @@ class GothicAPI {

/** Map for skeletal mesh visuals */
std::unordered_map<std::string, SkeletalMeshVisualInfo*> SkeletalMeshVisuals;
std::unordered_map<oCNPC*, SkeletalMeshVisualInfo*> SkeletalMeshNpcs;

/** Set of all vobs we registered by now */
std::unordered_set<zCVob*> RegisteredVobs;
Expand Down
1 change: 1 addition & 0 deletions D3D11Engine/GothicMemoryLocations1_08k.h
Expand Up @@ -518,6 +518,7 @@ struct GothicMemoryLocations {
struct zCModel {
static const unsigned int RenderNodeList = 0x0055FA50;
static const unsigned int UpdateAttachedVobs = 0x005667F0;
static const unsigned int Offset_HomeVob = 0x54;
static const unsigned int Offset_ModelProtoList = 0x58;
static const unsigned int Offset_NodeList = 0x64;
static const unsigned int Offset_MeshSoftSkinList = 0x70;
Expand Down
1 change: 1 addition & 0 deletions D3D11Engine/GothicMemoryLocations1_12f.h
Expand Up @@ -496,6 +496,7 @@ struct GothicMemoryLocations {
struct zCModel {
static const unsigned int RenderNodeList = 0x00577E70;
static const unsigned int UpdateAttachedVobs = 0x0057F330;
static const unsigned int Offset_HomeVob = 0x54;
static const unsigned int Offset_ModelProtoList = 0x58;
static const unsigned int Offset_NodeList = 0x64;
static const unsigned int Offset_MeshSoftSkinList = 0x70;
Expand Down
1 change: 1 addition & 0 deletions D3D11Engine/GothicMemoryLocations2_6_fix.h
Expand Up @@ -364,6 +364,7 @@ struct GothicMemoryLocations {
struct zCModel {
static const unsigned int RenderNodeList = 0x00579560;
static const unsigned int UpdateAttachedVobs = 0x00580900;
static const unsigned int Offset_HomeVob = 0x60;
static const unsigned int Offset_ModelProtoList = 0x64;
static const unsigned int Offset_NodeList = 0x70;
static const unsigned int Offset_MeshSoftSkinList = 0x7C;
Expand Down
1 change: 1 addition & 0 deletions D3D11Engine/GothicMemoryLocations2_6_fix_Spacer.h
Expand Up @@ -262,6 +262,7 @@ struct GothicMemoryLocations {
struct zCModel {
static const unsigned int RenderNodeList = 0x00704840;
static const unsigned int UpdateAttachedVobs = 0x0070BBE0;
static const unsigned int Offset_HomeVob = 0x60;
static const unsigned int Offset_ModelProtoList = 0x64;
static const unsigned int Offset_NodeList = 0x70;
static const unsigned int Offset_MeshSoftSkinList = 0x7C;
Expand Down
13 changes: 13 additions & 0 deletions D3D11Engine/WorldObjects.h
Expand Up @@ -299,6 +299,19 @@ struct SkeletalMeshVisualInfo : public BaseVisualInfo {
}
}

void ClearMeshes() {
for ( auto& [k, meshes] : SkeletalMeshes )
for ( SkeletalMeshInfo* smi : meshes )
delete smi;

for ( auto& [k, meshes] : Meshes )
for ( MeshInfo* mi : meshes )
delete mi;

SkeletalMeshes.clear();
Meshes.clear();
}

#if ENABLE_TESSELATION > 0
/** Creates PNAEN-Info for all meshes if not already there */
void CreatePNAENInfo( bool softNormals = false );
Expand Down
4 changes: 4 additions & 0 deletions D3D11Engine/zCModel.h
Expand Up @@ -333,6 +333,10 @@ class zCModel : public zCVisual {
return str;
}

zCVob* GetHomeVob() {
return reinterpret_cast<zCVob*>(THISPTR_OFFSET( GothicMemoryLocations::zCModel::Offset_HomeVob ));
}

private:

};

0 comments on commit 7e931b7

Please sign in to comment.