Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/libs/geometry/include/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "service.h"
#include "vma.hpp"


constexpr size_t TECHNIQUES_COUNT = 10;

class ANIMATION
{
public:
Expand Down Expand Up @@ -31,7 +34,8 @@ class VGEOMETRY : public SERVICE
const char *lmPath = nullptr) = 0;
virtual void DeleteGeometry(GEOS *) = 0;
virtual ANIMATION *LoadAnimation(const char *anim) = 0;
virtual void SetTechnique(const char *name) = 0;
virtual void SetTechnique(const char *name, size_t index) = 0;
virtual void SetTechniques(char aTechniques[TECHNIQUES_COUNT][256]) = 0;
virtual void SetVBConvertFunc(VERTEX_TRANSFORM _transform_func) = 0;
virtual ANIMATION_VB GetAnimationVBDesc(int32_t avb) = 0;

Expand Down
8 changes: 7 additions & 1 deletion src/libs/geometry/include/geos.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Import library main header
#include <cstdint>
#include <fstream>


typedef size_t NameToTechniqueFunc(const char *name);

class GEOS
{
public:
Expand Down Expand Up @@ -177,12 +180,14 @@ class GEOS
ID vertex_buff;
int32_t start_vertex, num_vertices;
int32_t bones[4];
int32_t technology_index;
};

virtual int32_t FindObjN(int32_t start_index, int32_t name_id) = 0;
virtual int32_t FindObjG(int32_t start_index, int32_t group_name_id) = 0;
virtual void GetObj(int32_t o, OBJECT &ob) const = 0;
virtual void SetObj(int32_t o, const OBJECT &ob) = 0;
virtual void SetTechniques(NameToTechniqueFunc) = 0;

//-----------------------------------------
// light sources
Expand Down Expand Up @@ -302,7 +307,8 @@ class GEOM_SERVICE

virtual void SetIndexBuffer(GEOS::ID ibuff) = 0;
virtual void SetVertexBuffer(int32_t vsize, GEOS::ID vbuff) = 0;
virtual void DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vrtsize, int32_t startidx, int32_t numtrg) = 0;
virtual void DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vrtsize, int32_t startidx, int32_t numtrg,
size_t iTechIndex) = 0;

virtual GEOS::ID CreateLight(GEOS::LIGHT) = 0;
virtual void ActivateLight(GEOS::ID n) = 0;
Expand Down
1 change: 1 addition & 0 deletions src/libs/geometry/src/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class GEOM : public GEOS
virtual int32_t FindObjG(int32_t start_index, int32_t group_name_id);
virtual void GetObj(int32_t o, OBJECT &ob) const;
virtual void SetObj(int32_t o, const OBJECT &ob);
virtual void SetTechniques(NameToTechniqueFunc);

virtual int32_t FindMaterialN(int32_t start_index, int32_t name_id);
virtual int32_t FindMaterialG(int32_t start_index, int32_t group_name_id);
Expand Down
15 changes: 14 additions & 1 deletion src/libs/geometry/src/geom_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ GEOM::GEOM(const char *fname, const char *lightname, GEOM_SERVICE &_srv, int32_t
object[o].vertex_buff = obj[o].vertex_buff;
object[o].start_vertex = obj[o].svertex;
object[o].num_vertices = obj[o].nvertices;
object[o].technology_index = 0;
atriangles[o] = obj[o].atriangles;
}
srv.free(obj);
Expand Down Expand Up @@ -292,8 +293,11 @@ void GEOM::Draw(const PLANE *pl, int32_t np, MATERIAL_FUNC mtf) const
srv.SetMaterial(material[object[o].material]);
if (mtf != nullptr)
mtf(material[object[o].material]);

size_t iTechIndex = object[o].technology_index;

srv.DrawIndexedPrimitive(object[o].start_vertex, object[o].num_vertices, vb->stride, object[o].striangle * 3,
object[o].ntriangles);
object[o].ntriangles, iTechIndex);
}
}

Expand Down Expand Up @@ -387,6 +391,15 @@ void GEOM::GetObj(int32_t o, OBJECT &ob) const
ob.vertex_buff = vbuff[object[o].vertex_buff].dev_buff;
}

void GEOM::SetTechniques(NameToTechniqueFunc ntt)
{
for (int32_t o = 0; o < rhead.nobjects; o++)
{
object[o].technology_index = ntt(object[o].name);
}
}


void GEOM::GetInfo(INFO &i) const
{
i.ntextures = rhead.ntextures;
Expand Down
32 changes: 24 additions & 8 deletions src/libs/geometry/src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CREATE_SERVICE(GEOMETRY)

IDirect3DVertexDeclaration9 *GEOM_SERVICE_R::vertexDecl_ = nullptr;

char technique[256] = "";
char techniques[TECHNIQUES_COUNT][256] = {0};

char RenderServiceName[] = "dx9render";
GEOM_SERVICE_R GSR;
char texturePath[256];
Expand All @@ -34,9 +35,16 @@ void GEOMETRY::SetTexturePath(const char *path)
//=================================================================================================
// Block 1
//=================================================================================================
void GEOMETRY::SetTechnique(const char *name)
void GEOMETRY::SetTechnique(const char *name, size_t index)
{
if (index >= TECHNIQUES_COUNT)
return;
strcpy_s(techniques[index], name);
}

void GEOMETRY::SetTechniques(char aTechniques[TECHNIQUES_COUNT][256])
{
strcpy_s(technique, name);
memcpy(techniques, aTechniques, sizeof(techniques));
}

GEOMETRY::ANIMATION_VB GEOMETRY::GetAnimationVBDesc(int32_t vb)
Expand Down Expand Up @@ -86,6 +94,10 @@ int vrtSize;

GEOS *GEOMETRY::CreateGeometry(const char *file_name, const char *light_file_name, int32_t flags, const char *lmPath)
{
if (!strcmp(file_name, "characters\\Blad_0"))
{
file_name = file_name;
}
char fnt[256], lfn[256];
if (light_file_name != nullptr)
{
Expand Down Expand Up @@ -425,7 +437,8 @@ void GEOM_SERVICE_R::SetVertexBuffer(int32_t vsize, GEOS::ID vbuff)
CurentVertexBufferSize = vsize;
}

void GEOM_SERVICE_R::DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vrtsize, int32_t startidx, int32_t numtrg)
void GEOM_SERVICE_R::DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vrtsize, int32_t startidx, int32_t numtrg,
size_t iTechIndex)
{
if (!RenderService)
return;
Expand Down Expand Up @@ -456,7 +469,10 @@ void GEOM_SERVICE_R::DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vr
// float SSBias = -0.6f;
// RenderService->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *(int*)&SSBias);
}

if (iTechIndex >= TECHNIQUES_COUNT || !techniques[iTechIndex][0])
{
iTechIndex = 0;
}
// draw animation
if (transform_func != nullptr)
{
Expand All @@ -468,8 +484,8 @@ void GEOM_SERVICE_R::DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vr
{
RenderService->SetStreamSource(0, transformed_vb, cavb->stride);
RenderService->SetFVF(cavb->fvf);

RenderService->DrawBuffer(-1, cavb->stride, CurentIndexBuffer, minv, numv, startidx, numtrg, technique);
RenderService->DrawBuffer(-1, cavb->stride, CurentIndexBuffer, minv, numv, startidx, numtrg,
techniques[iTechIndex]);
}
else
{
Expand All @@ -483,7 +499,7 @@ void GEOM_SERVICE_R::DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vr
{
if (!bCaustic)
RenderService->DrawBuffer(CurentVertexBuffer, vrtsize, CurentIndexBuffer, minv, numv, startidx, numtrg,
technique);
techniques[iTechIndex]);
else
RenderService->DrawIndexedPrimitiveNoVShader(D3DPT_TRIANGLELIST, CurentVertexBuffer, vrtsize,
CurentIndexBuffer, minv, numv, startidx, numtrg, "caustic");
Expand Down
6 changes: 4 additions & 2 deletions src/libs/geometry/src/geometry_r.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class GEOMETRY final : public VGEOMETRY
GEOS *CreateGeometry(const char *file_name, const char *light_file_name, int32_t flags, const char *lmPath);
void DeleteGeometry(GEOS *);
ANIMATION *LoadAnimation(const char *anim);
void SetTechnique(const char *name);
void SetTechnique(const char *name, size_t index);
void SetTechniques(char aTechniques[TECHNIQUES_COUNT][256]);
void SetVBConvertFunc(VERTEX_TRANSFORM _transform_func);
ANIMATION_VB GetAnimationVBDesc(int32_t avb);

Expand Down Expand Up @@ -64,7 +65,8 @@ class GEOM_SERVICE_R final : public GEOM_SERVICE

void SetIndexBuffer(GEOS::ID ibuff);
void SetVertexBuffer(int32_t vsize, GEOS::ID vbuff);
void DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vrtsize, int32_t startidx, int32_t numtrg);
void DrawIndexedPrimitive(int32_t minv, int32_t numv, int32_t vrtsize, int32_t startidx,
int32_t numtrg, size_t iTechIndex);

GEOS::ID CreateLight(const GEOS::LIGHT);
void ActivateLight(GEOS::ID n);
Expand Down
25 changes: 25 additions & 0 deletions src/libs/location/src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ void Character::RTuner::Set(MODEL *model, VDX9RENDER *rs)
if (a >= 1.0f)
{
n->SetTechnique("Animation");
n->SetTechnique("EnvAmmoShader", 1);
}
else
{
Expand Down Expand Up @@ -3147,6 +3148,21 @@ void Character::ReleaseSound(int32_t id)
// Encapsulation
// ============================================================================================


static size_t characterNameToTechIndex(const char *name)
{
if (!name)
return 0;

const char *metalPrefix = "metal_";
if (!strncmp(metalPrefix, name, strlen(metalPrefix)))
{
return 1;
}

return 0;
}

bool Character::zLoadModel(MESSAGE &message)
{
char mpath[300];
Expand Down Expand Up @@ -3178,6 +3194,15 @@ bool Character::zLoadModel(MESSAGE &message)
}
if (gs)
gs->SetTexturePath("");


auto model = Model();
auto node = model->GetNode(0);
if (node)
{
node->SetTechniqueIndexes(characterNameToTechIndex);
}

if (!core.Send_Message(mdl, "ls", MSG_MODEL_LOAD_ANI, ani.c_str()) != 0)
{
core.Trace("Character animation '%s' not loaded", ani.c_str());
Expand Down
17 changes: 17 additions & 0 deletions src/libs/location/src/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,20 @@ bool Location::CheckIfLocatorExists(const char *lName)
return false;
}

static size_t locationNameToTechIndex(const char *name)
{
if (!name)
return 0;

const char *metalPrefix = "metal_";
if (!strncmp(metalPrefix, name, strlen(metalPrefix)))
{
return 1;
}

return 0;
}

int32_t Location::LoadStaticModel(const char *modelName, const char *tech, int32_t level, bool useDynamicLights)
{
lights = static_cast<Lights *>(core.GetEntityPointer(lightsid));
Expand All @@ -496,6 +510,9 @@ int32_t Location::LoadStaticModel(const char *modelName, const char *tech, int32
model.DeleteModel(im);
return -1;
}

node->SetTechniqueIndexesRec(locationNameToTechIndex);
node->SetTechniqueRec("EnvAmmoShader", 1); // for metal
auto *const g = node->geo;
if (!g)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/locator/src/blast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void BLAST::Realize(uint32_t Delta_Time)

ProcessTime(Delta_Time);

gs->SetTechnique("");
gs->SetTechnique("", 0);
for (n = 0; n < ItemsNum; n++)
{
if (Item[n].geo)
Expand Down
21 changes: 19 additions & 2 deletions src/libs/model/include/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,31 @@ class NODE
// link model to node
virtual void Link(entid_t model, bool transform = true) = 0;

virtual void SetTechnique(const char *name) = 0;
virtual const char *GetTechnique() = 0;
virtual void SetTechnique(const char *name, size_t index = 0) = 0;
virtual void SetTechniqueRec(const char *name, size_t index = 0) = 0;
virtual const char *GetTechnique(size_t index = 0) = 0;
virtual bool Init(const char *lightPath, const char *pname, const char *oname, const CMatrix &m,
const CMatrix &globm, NODER *par, const char *lmPath) = 0;

virtual float Trace(const CVECTOR &src, const CVECTOR &dst) = 0;

virtual void SubstituteGeometry(const std::string& new_model) = 0;

void SetTechniqueIndexes(NameToTechniqueFunc ntt)
{
if (geo)
geo->SetTechniques(ntt);
}

void SetTechniqueIndexesRec(NameToTechniqueFunc ntt)
{
SetTechniqueIndexes(ntt);
for (auto& cur : next)
{
if (cur)
cur->SetTechniqueIndexesRec(ntt);
}
}
};

class VDX9RENDER;
Expand Down
7 changes: 4 additions & 3 deletions src/libs/model/src/modelr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NODER : public NODE

static int32_t depth, node;
uintptr_t idGeoGroup; // id of "geometry" string
char technique[256], name[256];
char techniques[TECHNIQUES_COUNT][256], name[256];

// local radius and center of geometry
float geo_radius;
Expand Down Expand Up @@ -56,8 +56,9 @@ class NODER : public NODE
// link model to node
void Link(entid_t model, bool transform = true) override;

void SetTechnique(const char *name) override;
const char *GetTechnique() override;
void SetTechnique(const char *name, size_t index = 0) override;
void SetTechniqueRec(const char *name, size_t index = 0) override;
const char *GetTechnique(size_t index = 0) override;

// replace only this node model without touching anything else
void SubstituteGeometry(const std::string &new_model) override;
Expand Down
27 changes: 20 additions & 7 deletions src/libs/model/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool NODER::Init(const char *lightPath, const char *pname, const char *oname, co
{
isReleased = false;
name[0] = 0;
technique[0] = 0;
memset(techniques, 0, sizeof(techniques));
geoMaterialFunc = nullptr;
flags = VISIBLE | VISIBLE_TREE | CLIP_ENABLE | CLIP_ENABLE_TREE | TRACE_ENABLE | TRACE_ENABLE_TREE;

Expand Down Expand Up @@ -394,10 +394,10 @@ void NODER::Draw()
if (p == 4)
{
rs->SetTransform(D3DTS_WORLD, (D3DMATRIX *)&glob_mtx);
gs->SetTechnique(&technique[0]);
gs->SetTechniques(techniques);
if (max_view_dist > 0.f && distance_blend > 0.f)
{
gs->SetTechnique("geomdistanceblend");
gs->SetTechnique("geomdistanceblend", 0);
uint32_t dwTFColor;
dwTFColor = (static_cast<uint32_t>(255.f - 255.f * distance_blend) << 24) | 0xFFFFFF;
rs->SetRenderState(D3DRS_TEXTUREFACTOR, dwTFColor);
Expand Down Expand Up @@ -563,17 +563,30 @@ void NODER::Link(entid_t id, bool transform)
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
void NODER::SetTechnique(const char *name)
void NODER::SetTechnique(const char *name, size_t index)
{
strcpy_s(technique, name);
if (index >= TECHNIQUES_COUNT)
return;
strcpy_s(techniques[index], name);
}

void NODER::SetTechniqueRec(const char *name, size_t index)
{
if (index >= TECHNIQUES_COUNT)
return;
SetTechnique(name, index);
for (auto &n : next)
n->SetTechniqueRec(name, index);
}

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
const char *NODER::GetTechnique()
const char *NODER::GetTechnique(size_t index)
{
return &technique[0];
if (index >= TECHNIQUES_COUNT)
index = 0;
return &techniques[index][0];
}

void NODER::SetMaxViewDist(float fDist)
Expand Down
Loading
Loading