Skip to content

Commit

Permalink
1.Fixed a bug that PhysicWorld was not working.
Browse files Browse the repository at this point in the history
2.Fixed an incorrect struct in hlsdk/common/com_model.h
  • Loading branch information
hzqst committed May 20, 2024
1 parent 893828b commit c49cabf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 47 deletions.
102 changes: 56 additions & 46 deletions fallguys/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ void CPhysicsManager::GenerateBrushIndiceArray()
{
m_brushIndexArray[i] = new indexarray_t;
m_brushVertexArray[i] = new vertexarray_t;

GenerateArrayForBrushModel(mod, m_worldVertexArray, m_brushIndexArray[i], m_brushVertexArray[i]);
}
}
Expand Down Expand Up @@ -468,7 +469,7 @@ void CPhysicsManager::BuildSurfaceDisplayList(model_t *mod, msurface_t* fa, std:

glpolys.push_front(poly);

//poly->next = fa->polys;
poly->next = NULL;
poly->flags = fa->flags;
//fa->polys = poly;
poly->numverts = lnumverts;
Expand Down Expand Up @@ -546,63 +547,63 @@ void CPhysicsManager::GenerateWorldVerticeArray()

BuildSurfaceDisplayList(r_worldmodel, surf, glpolys);

if (!glpolys.empty())
{
brushface_t* brushface = &m_worldVertexArray->vFaceBuffer[i];
if (glpolys.empty())
continue;

brushface_t* brushface = &m_worldVertexArray->vFaceBuffer[i];

int iStartVert = iNumVerts;
int iStartVert = iNumVerts;

brushface->start_vertex = iStartVert;
brushface->plane_normal = surf->plane->normal;
brushface->plane_dist = surf->plane->dist;
brushface->plane_flags = surf->flags;
brushface->start_vertex = iStartVert;
brushface->plane_normal = surf->plane->normal;
brushface->plane_dist = surf->plane->dist;
brushface->plane_flags = surf->flags;

if (surf->flags & SURF_PLANEBACK)
{
brushface->plane_normal = brushface->plane_normal * (-1);
brushface->plane_dist = brushface->plane_dist * (-1);
}

if (surf->flags & SURF_PLANEBACK)
for (const auto &poly : glpolys)
{
auto v = poly->verts[0];

for (int j = 0; j < 3; j++, v += VERTEXSIZE)
{
brushface->plane_normal = brushface->plane_normal * (-1);
brushface->plane_dist = brushface->plane_dist * (-1);
Vertexes[j].pos[0] = v[0];
Vertexes[j].pos[1] = v[1];
Vertexes[j].pos[2] = v[2];
}

for (const auto &poly : glpolys)
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[0]);
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[1]);
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[2]);
iNumVerts += 3;

for (int j = 0; j < (poly->numverts - 3); j++, v += VERTEXSIZE)
{
auto v = poly->verts[0];
Vertexes[1].pos[0] = Vertexes[2].pos[0];
Vertexes[1].pos[1] = Vertexes[2].pos[1];
Vertexes[1].pos[2] = Vertexes[2].pos[2];

for (int j = 0; j < 3; j++, v += VERTEXSIZE)
{
Vertexes[j].pos[0] = v[0];
Vertexes[j].pos[1] = v[1];
Vertexes[j].pos[2] = v[2];
}
Vertexes[2].pos[0] = v[0];
Vertexes[2].pos[1] = v[1];
Vertexes[2].pos[2] = v[2];

m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[0]);
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[1]);
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[2]);
iNumVerts += 3;

for (int j = 0; j < (poly->numverts - 3); j++, v += VERTEXSIZE)
{
Vertexes[1].pos[0] = Vertexes[2].pos[0];
Vertexes[1].pos[1] = Vertexes[2].pos[1];
Vertexes[1].pos[2] = Vertexes[2].pos[2];

Vertexes[2].pos[0] = v[0];
Vertexes[2].pos[1] = v[1];
Vertexes[2].pos[2] = v[2];

m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[0]);
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[1]);
m_worldVertexArray->vVertexBuffer.emplace_back(Vertexes[2]);
iNumVerts += 3;
}
}

for (auto &poly : glpolys)
{
free(poly);
}
}

brushface->num_vertexes = iNumVerts - iStartVert;
for (auto &poly : glpolys)
{
free(poly);
}

brushface->num_vertexes = iNumVerts - iStartVert;
}
}

Expand Down Expand Up @@ -667,19 +668,28 @@ void CPhysicsManager::GenerateArrayRecursiveWorldNode(mnode_t* node, vertexarray

GenerateArrayRecursiveWorldNode(node->children[0], worldvertexarray, brushindexarray, brushvertexarray);

for (int i = node->firstsurface; i < node->numsurfaces; ++i)
for (int i = 0; i < node->numsurfaces; ++i)
{
GenerateArrayForSurface(EngineGetSurfaceByIndex(i), worldvertexarray, brushindexarray, brushvertexarray);
auto surf = EngineGetSurfaceByIndex(node->firstsurface + i);
GenerateArrayForSurface(surf, worldvertexarray, brushindexarray, brushvertexarray);
}

GenerateArrayRecursiveWorldNode(node->children[1], worldvertexarray, brushindexarray, brushvertexarray);
}

void CPhysicsManager::GenerateArrayForBrushModel(model_t* mod, vertexarray_t* vertexarray, indexarray_t* brushindexarray, vertexarray_t* brushvertexarray)
{
for (int i = mod->firstmodelsurface; i < mod->nummodelsurfaces; i++)
if (mod == r_worldmodel)
{
GenerateArrayRecursiveWorldNode(mod->nodes, vertexarray, brushindexarray, brushvertexarray);
}
else
{
GenerateArrayForSurface(EngineGetSurfaceByIndex(i), vertexarray, brushindexarray, brushvertexarray);
for (int i = 0; i < mod->nummodelsurfaces; i++)
{
auto surf = EngineGetSurfaceByIndex(mod->firstmodelsurface + i);
GenerateArrayForSurface(surf, vertexarray, brushindexarray, brushvertexarray);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion hlsdk/common/com_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ typedef struct mnode_s
int contents; // 0, to differentiate from leafs
int visframe; // node needs to be traversed if current

short minmaxs[6]; // for bounding box culling
float minmaxs[6]; // for bounding box culling // HZ FIXED: this is float instead of short in Sven Co-op

struct mnode_s *parent;

Expand Down

0 comments on commit c49cabf

Please sign in to comment.