Skip to content

Commit

Permalink
Fix nav stuff. Fix sprites scale (use model bbox),
Browse files Browse the repository at this point in the history
Fix nav stuff. Fix sprites scale (use model bbox), optimizations, bug fixes, bug adding, etc
  • Loading branch information
UnrealKaraulov committed Nov 17, 2024
1 parent 7eb363c commit 8ee54f4
Show file tree
Hide file tree
Showing 35 changed files with 979 additions and 979 deletions.
2 changes: 1 addition & 1 deletion resources/languages/language.ini
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ LANG_0276 = Loaded {} lightmaps into {} atlases\n
LANG_0277 = TODO: Recalculate lightmaps when faces deleted\n
LANG_0278 = Added {} empty lightmaps after face added\n
LANG_0279 = Added new solid render group.\n
LANG_0280 = Bad model idx\n
LANG_0280 = Bad model idx {} of {}\n
LANG_0281 = {} for {} {}\n
LANG_0282 = Degenerate clipnode face discarded\n
LANG_0283 = Failed to find non-duplicate vert for clipnode face\n
Expand Down
2 changes: 1 addition & 1 deletion resources/languages/language_ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ LANG_0276 = Загружено {} лайтмап в {} атласах\n
LANG_0277 = TODO: Перерасчёт лайтмап после удаления фейсов\n
LANG_0278 = Добавлено {} пустых лайтмап после добавления фейса\n
LANG_0279 = Добавлена новая группа рендерера солидов.\n
LANG_0280 = Некорректный индекс модели\n
LANG_0280 = Некорректный индекс модели {} из {}\n
LANG_0281 = {} для {} {}\n
LANG_0282 = Удалена деформированная грань клипноды\n
LANG_0283 = Не удалось найти уникальную вершину для грани клипноды\n
Expand Down
80 changes: 38 additions & 42 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void Bsp::get_model_vertex_bounds(int modelIdx, vec3& mins, vec3& maxs)

std::vector<CMesh> solidMeshes;
for (int k = 0; k < solidNodes.size(); k++) {
solidMeshes.push_back(clipper.clip(solidNodes[k].cuts));
solidMeshes.emplace_back(clipper.clip(solidNodes[k].cuts));
}

for (int m = 0; m < solidMeshes.size(); m++) {
Expand All @@ -460,8 +460,6 @@ void Bsp::get_model_vertex_bounds(int modelIdx, vec3& mins, vec3& maxs)
continue;
}

std::set<int> uniqueFaceVerts;

for (int k = 0; k < mesh.faces[i].edges.size(); k++) {
for (int v = 0; v < 2; v++) {
int vertIdx = mesh.edges[mesh.faces[i].edges[k]].verts[v];
Expand Down Expand Up @@ -870,36 +868,37 @@ bool Bsp::vertex_manipulation_sync(int modelIdx, const std::vector<TransformVert
return false;

std::set<int> affectedPlanes;

std::map<int, std::vector<vec3>> planeVerts;
std::vector<vec3> allVertPos;

for (size_t i = 0; i < hullVerts.size(); i++)
for (const auto& vert : hullVerts)
{
for (size_t k = 0; k < hullVerts[i].iPlanes.size(); k++) {
int iPlane = hullVerts[i].iPlanes[k];
affectedPlanes.insert(hullVerts[i].iPlanes[k]);
planeVerts[iPlane].push_back(hullVerts[i].pos);
for (int iPlane : vert.iPlanes)
{
affectedPlanes.insert(iPlane);
planeVerts[iPlane].push_back(vert.pos);
}
allVertPos.push_back(hullVerts[i].pos);
allVertPos.push_back(vert.pos);
}

int planeUpdates = 0;
std::map<int, BSPPLANE> newPlanes;
std::map<int, bool> shouldFlipChildren;
for (auto it = planeVerts.begin(); it != planeVerts.end(); ++it)
for (const auto& [iPlane, tverts] : planeVerts)
{
int iPlane = it->first;

std::vector<vec3>& tverts = it->second;

if (tverts.size() < 3)
{
if (g_settings.verboseLogs)
print_log(get_localized_string(LANG_0045));
return false; // invalid solid
}

if (iPlane >= planeCount)
{
print_log("Fatal error sync plane bad {} of {}\n", iPlane, planeCount);
return false; // invalid solid
}

BSPPLANE newPlane;
if (!getPlaneFromVerts(tverts, newPlane.vNormal, newPlane.fDist))
{
Expand Down Expand Up @@ -935,11 +934,8 @@ bool Bsp::vertex_manipulation_sync(int modelIdx, const std::vector<TransformVert
if (convexCheckOnly)
return planeVerts.size();

for (auto it = newPlanes.begin(); it != newPlanes.end(); ++it)
for (const auto& [iPlane, newPlane] : newPlanes)
{
auto iPlane = it->first;
BSPPLANE& newPlane = it->second;

planes[iPlane] = newPlane;
planeUpdates++;

Expand All @@ -958,15 +954,13 @@ bool Bsp::vertex_manipulation_sync(int modelIdx, const std::vector<TransformVert
BSPNODE32& node = nodes[i];
if (node.iPlane == iPlane)
{
int temp = node.iChildren[0];
node.iChildren[0] = node.iChildren[1];
node.iChildren[1] = temp;
std::swap(node.iChildren[0], node.iChildren[1]);
}
}
}
}

//print_log(get_localized_string(LANG_0047),planeUpdates);
//print_log(get_localized_string(LANG_0047), planeUpdates);
return true;
}

Expand Down Expand Up @@ -1481,7 +1475,7 @@ void Bsp::split_shared_model_structures(int modelIdx)
replace_lump(LUMP_TEXINFO, newTexinfos, newTexinfoCount * sizeof(BSPTEXTUREINFO));

std::vector<bool> newVisitedClipnodes(newClipnodeCount, false);
remappedStuff.visitedClipnodes = newVisitedClipnodes;
remappedStuff.visitedClipnodes = std::move(newVisitedClipnodes);

remap_model_structures(modelIdx, &remappedStuff);

Expand Down Expand Up @@ -2936,7 +2930,7 @@ void Bsp::delete_oob_data(int clipFlags) {
int deletedEnts = (int)ents.size() - (int)newEnts.size();
if (deletedEnts)
print_log(" Deleted {} entities\n", deletedEnts);
ents = newEnts;
ents = std::move(newEnts);

unsigned char* oobFaces = new unsigned char[faceCount];
memset(oobFaces, 0, faceCount * sizeof(bool));
Expand Down Expand Up @@ -3034,6 +3028,7 @@ void Bsp::delete_oob_data(int clipFlags) {
leaf.iFirstMarkSurface = 0;

if (oobCount != leaf.nMarkSurfaces) {
// always true
//print_log("leaf {} partially OOB\n", i);
}
}
Expand Down Expand Up @@ -3262,7 +3257,7 @@ void Bsp::delete_box_data(vec3 clipMins, vec3 clipMaxs) {
int deletedEnts = (int)ents.size() - (int)newEnts.size();
if (deletedEnts)
print_log(" Deleted {} entities\n", deletedEnts);
ents = newEnts;
ents = std::move(newEnts);

unsigned char* oobFaces = new unsigned char[faceCount];
memset(oobFaces, 0, faceCount * sizeof(bool));
Expand Down Expand Up @@ -3353,6 +3348,7 @@ void Bsp::delete_box_data(vec3 clipMins, vec3 clipMaxs) {
leaf.iFirstMarkSurface = 0;

if (oobCount != leaf.nMarkSurfaces) {
// always true
//print_log("leaf {} partially OOB\n", i);
}
}
Expand Down Expand Up @@ -8716,12 +8712,12 @@ int Bsp::create_node_box(const vec3& mins, const vec3& maxs, BSPMODEL* targetMod
std::vector<BSPPLANE> addPlanes;
std::vector<BSPNODE32> addNodes;

addPlanes.push_back({ vec3(1.0f, 0.0f, 0.0f), min.x, PLANE_X }); // left
addPlanes.push_back({ vec3(1.0f, 0.0f, 0.0f), max.x, PLANE_X }); // right
addPlanes.push_back({ vec3(0.0f, 1.0f, 0.0f), min.y, PLANE_Y }); // front
addPlanes.push_back({ vec3(0.0f, 1.0f, 0.0f), max.y, PLANE_Y }); // back
addPlanes.push_back({ vec3(0.0f, 0.0f, 1.0f), min.z, PLANE_Z }); // bottom
addPlanes.push_back({ vec3(0.0f, 0.0f, 1.0f), max.z, PLANE_Z }); // top
addPlanes.emplace_back(vec3(1.0f, 0.0f, 0.0f), min.x, PLANE_X); // left
addPlanes.emplace_back(vec3(1.0f, 0.0f, 0.0f), max.x, PLANE_X); // right
addPlanes.emplace_back(vec3(0.0f, 1.0f, 0.0f), min.y, PLANE_Y); // front
addPlanes.emplace_back(vec3(0.0f, 1.0f, 0.0f), max.y, PLANE_Y); // back
addPlanes.emplace_back(vec3(0.0f, 0.0f, 1.0f), min.z, PLANE_Z); // bottom
addPlanes.emplace_back(vec3(0.0f, 0.0f, 1.0f), max.z, PLANE_Z); // top

int solidNodeIdx = 0;

Expand Down Expand Up @@ -8792,12 +8788,12 @@ int Bsp::create_clipnode_box(const vec3& mins, const vec3& maxs, BSPMODEL* targe
int clipnodeIdx = clipnodeCount + (int)addNodes.size();
int planeIdx = planeCount + (int)addPlanes.size();

addPlanes.push_back({ vec3(1.0f, 0.0f, 0.0f), min.x, PLANE_X }); // left
addPlanes.push_back({ vec3(1.0f, 0.0f, 0.0f), max.x, PLANE_X }); // right
addPlanes.push_back({ vec3(0.0f, 1.0f, 0.0f), min.y, PLANE_Y }); // front
addPlanes.push_back({ vec3(0.0f, 1.0f, 0.0f), max.y, PLANE_Y }); // back
addPlanes.push_back({ vec3(0.0f, 0.0f, 1.0f), min.z, PLANE_Z }); // bottom
addPlanes.push_back({ vec3(0.0f, 0.0f, 1.0f), max.z, PLANE_Z }); // top
addPlanes.emplace_back(vec3(1.0f, 0.0f, 0.0f), min.x, PLANE_X); // left
addPlanes.emplace_back(vec3(1.0f, 0.0f, 0.0f), max.x, PLANE_X); // right
addPlanes.emplace_back(vec3(0.0f, 1.0f, 0.0f), min.y, PLANE_Y); // front
addPlanes.emplace_back(vec3(0.0f, 1.0f, 0.0f), max.y, PLANE_Y); // back
addPlanes.emplace_back(vec3(0.0f, 0.0f, 1.0f), min.z, PLANE_Z); // bottom
addPlanes.emplace_back(vec3(0.0f, 0.0f, 1.0f), max.z, PLANE_Z); // top

targetModel->iHeadnodes[i] = clipnodeCount + (int)addNodes.size();

Expand Down Expand Up @@ -8902,7 +8898,7 @@ int Bsp::create_clipnode(bool force_reversed, int reversed_id)
for (int i = 0; i < clipnodeCount; i++)
{
if (i == reversed_id)
newNodes.push_back(BSPCLIPNODE32());
newNodes.emplace_back(BSPCLIPNODE32());
newNodes.push_back(clipnodes[i]);
}

Expand Down Expand Up @@ -8950,7 +8946,7 @@ int Bsp::create_node(bool force_reversed, int reversed_id)
for (int i = 0; i < nodeCount; i++)
{
if (i == reversed_id)
newNodes.push_back(BSPNODE32());
newNodes.emplace_back(BSPNODE32());
newNodes.push_back(nodes[i]);
}

Expand Down Expand Up @@ -11257,7 +11253,7 @@ void Bsp::ExportToSmdWIP(const std::string& path, bool split, bool oneRoot)
}
}
if (!found)
total_verts.push_back({ t.verts[v],bones_to[t.boneid] });
total_verts.emplace_back(t.verts[v],bones_to[t.boneid]);
}

bool found = false;
Expand Down Expand Up @@ -11845,7 +11841,7 @@ void Bsp::ExportToObjWIP(const std::string& path, int iscale, bool lightmapmode,
rndColor.b = 50 + rand() % 206;
rndColor.a = 255;

csm_export->vertices.push_back({ org_pos,org_norm,rndColor });
csm_export->vertices.emplace_back(org_pos,org_norm,rndColor);

int cur_faceIdx = (int)(csm_export->faces.size()) - 1;
if (cur_faceIdx >= 0)
Expand Down
9 changes: 5 additions & 4 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ MergeResult BspMerger::merge(std::vector<Bsp*> maps, const vec3& gap, const std:

for (size_t i = 0; i < mapB->ents.size(); i++)
{
if (mapB->ents[i]->keyvalues["classname"].find("light") != std::string::npos)
Entity* mapent = mapB->ents[i];
if (mapent->keyvalues["classname"].find("light") != std::string::npos)
{
if (mapB->ents[i]->hasKey("style"))
if (mapent->hasKey("style"))
{
int style = str_to_int(mapB->ents[i]->keyvalues["style"]);
int style = str_to_int(mapent->keyvalues["style"]);
if (style < 255 && style >= start_toggle_lightstyle && remap_light_styles.find((unsigned char)style) != remap_light_styles.end())
{
remapped_lightents++;
mapB->ents[i]->setOrAddKeyvalue("style", std::to_string(remap_light_styles[(unsigned char)style]));
mapent->setOrAddKeyvalue("style", std::to_string(remap_light_styles[(unsigned char)style]));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bsp/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Entity::setOrAddKeyvalue(const std::string& key, const std::string& value)
addKeyvalue(key, value);
}

void Entity::removeKeyvalue(const std::string key)
void Entity::removeKeyvalue(const std::string& key)
{
if (!key.size())
return;
Expand Down
2 changes: 1 addition & 1 deletion src/bsp/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Entity
setOrAddKeyvalue("classname", _classname);
}
void addKeyvalue(const std::string& key, const std::string& value, bool multisupport = false);
void removeKeyvalue(const std::string key);
void removeKeyvalue(const std::string& key);
bool renameKey(int idx, const std::string& newName);
bool renameKey(const std::string& oldName, const std::string& newName);
void clearAllKeyvalues();
Expand Down
Loading

0 comments on commit 8ee54f4

Please sign in to comment.