Skip to content

Commit

Permalink
Add rotate entities for map mirroring/rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Mar 11, 2024
1 parent 817707d commit 960d7cd
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 111 deletions.
47 changes: 25 additions & 22 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@ STRUCTCOUNT Bsp::delete_unused_hulls(bool noProgress)
{
std::string cname = usageEnts[k]->keyvalues["classname"];
std::string tname = usageEnts[k]->keyvalues["targetname"];
int spawnflags = atoi(usageEnts[k]->keyvalues["spawnflags"].c_str());
int spawnflags = str_to_int(usageEnts[k]->keyvalues["spawnflags"]);

if (k != 0)
{
Expand Down Expand Up @@ -2662,9 +2662,9 @@ bool Bsp::is_invisible_solid(Entity* ent)
return false;

std::string tname = ent->keyvalues["targetname"];
int rendermode = atoi(ent->keyvalues["rendermode"].c_str());
int renderamt = atoi(ent->keyvalues["renderamt"].c_str());
int renderfx = atoi(ent->keyvalues["renderfx"].c_str());
int rendermode = str_to_int(ent->keyvalues["rendermode"]);
int renderamt = str_to_int(ent->keyvalues["renderamt"]);
int renderfx = str_to_int(ent->keyvalues["renderfx"]);

if (rendermode == RenderMode::kRenderNormal || renderamt != 0)
{
Expand Down Expand Up @@ -3103,6 +3103,27 @@ void Bsp::write(const std::string& path)
std::swap(lumps[LUMP_PLANES], lumps[LUMP_ENTITIES]);
}

if (is_protected)
{
if (surfedgeCount > 0)
{
if (surfedges[surfedgeCount - 1] != 0)
{
int* newsurfs = new int[surfedgeCount + 1];
memcpy(newsurfs, surfedges, surfedgeCount * sizeof(int));
newsurfs[surfedgeCount] = 0;
if (replacedLump[LUMP_SURFEDGES])
{
delete[] lumps[LUMP_SURFEDGES];
replacedLump[LUMP_SURFEDGES] = true;
}
lumps[LUMP_SURFEDGES] = (unsigned char*)newsurfs;
surfedgeCount++;
bsp_header.lump[LUMP_SURFEDGES].nLength = (surfedgeCount) * sizeof(int);
}
}
}

if (g_settings.preserveCrc32 && !force_skip_crc)
{
if (world && world->hasKey("CRC"))
Expand Down Expand Up @@ -3170,24 +3191,6 @@ void Bsp::write(const std::string& path)
}
}

if (is_protected)
{
if (surfedgeCount > 0)
{
if (surfedges[surfedgeCount - 1] != 0)
{
int* newsurfs = new int[surfedgeCount + 1];
memset(newsurfs, 0, (surfedgeCount + 1) * sizeof(int));
memcpy(newsurfs, surfedges, surfedgeCount * sizeof(int));
if (replacedLump[LUMP_SURFEDGES])
delete[] lumps[LUMP_SURFEDGES];
lumps[LUMP_SURFEDGES] = (unsigned char*)newsurfs;
surfedgeCount++;
bsp_header.lump[LUMP_SURFEDGES].nLength = (surfedgeCount) * sizeof(int);
}
}
}

print_log(get_localized_string(LANG_0080), bsp_path);
// calculate lump offsets
int offset = sizeof(BSPHEADER);
Expand Down
4 changes: 2 additions & 2 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void BspMerger::update_map_series_entity_logic(Bsp* mergedMap, std::vector<MAPBL
std::string cname = ent->keyvalues["classname"];
std::string tname = ent->keyvalues["targetname"];
std::string source_map = ent->keyvalues["$s_bspguy_map_source"];
int spawnflags = atoi(ent->keyvalues["spawnflags"].c_str());
int spawnflags = str_to_int(ent->keyvalues["spawnflags"]);
bool isInFirstMap = toLowerCase(source_map) == toLowerCase(firstMapName);
vec3 origin;

Expand Down Expand Up @@ -1056,7 +1056,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)
continue;
}

size_t newModelIdx = atoi(modelIdxStr.c_str()) + otherModelCount;
size_t newModelIdx = str_to_int(modelIdxStr) + otherModelCount;
mapA.ents[i]->keyvalues["model"] = "*" + std::to_string(newModelIdx);

g_progress.tick();
Expand Down
10 changes: 5 additions & 5 deletions src/bsp/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ int Entity::getBspModelIdx()
cachedModelIdx = -1;
return -1;
}
cachedModelIdx = atoi(modelIdxStr.c_str());
cachedModelIdx = str_to_int(modelIdxStr);
return cachedModelIdx;
}

Expand All @@ -293,7 +293,7 @@ int Entity::getBspModelIdxForce()
{
return -1;
}
return atoi(modelIdxStr.c_str());
return str_to_int(modelIdxStr);
}

bool Entity::isBspModel()
Expand Down Expand Up @@ -632,17 +632,17 @@ void Entity::updateRenderModes()
rendermode = kRenderNormal;
if (hasKey("rendermode"))
{
rendermode = atoi(keyvalues["rendermode"].c_str());
rendermode = str_to_int(keyvalues["rendermode"]);
}
renderamt = 0;
if (hasKey("renderamt"))
{
renderamt = atoi(keyvalues["renderamt"].c_str());
renderamt = str_to_int(keyvalues["renderamt"]);
}
renderfx = kRenderFxNone;
if (hasKey("renderfx"))
{
renderfx = atoi(keyvalues["renderfx"].c_str());
renderfx = str_to_int(keyvalues["renderfx"]);
}
rendercolor = vec3(1.0, 1.0, 1.0);
if (hasKey("rendercolor"))
Expand Down
8 changes: 4 additions & 4 deletions src/cli/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ std::string CommandLine::getOption(const std::string& optionName)

int CommandLine::getOptionInt(const std::string& optionName)
{
return atoi(optionVals[optionName].c_str());
return str_to_int(optionVals[optionName]);
}

vec3 CommandLine::getOptionVector(const std::string& optionName)
Expand All @@ -113,9 +113,9 @@ vec3 CommandLine::getOptionVector(const std::string& optionName)
return ret;
}

ret.x = (float)atof(parts[0].c_str());
ret.y = (float)atof(parts[1].c_str());
ret.z = (float)atof(parts[2].c_str());
ret.x = str_to_float(parts[0]);
ret.y = str_to_float(parts[1]);
ret.z = str_to_float(parts[2]);

return ret;
}
Expand Down
14 changes: 7 additions & 7 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ BspRenderer::BspRenderer(Bsp* _map)
}
if (foundEnt->keyOrder[i] == "angle")
{
float y = (float)atof(foundEnt->keyvalues["angle"].c_str());
float y = str_to_float(foundEnt->keyvalues["angle"]);

if (y >= 0.0f)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ BspRenderer::BspRenderer(Bsp* _map)
}
if (ent->keyOrder[i] == "angle")
{
float y = (float)atof(ent->keyvalues["angle"].c_str());
float y = str_to_float(ent->keyvalues["angle"]);
if (y >= 0.0f)
{
Expand Down Expand Up @@ -1703,7 +1703,7 @@ void BspRenderer::refreshEnt(size_t entIdx)
if (ent->keyOrder[i] == "angle")
{
setAngles = true;
float y = (float)atof(ent->keyvalues["angle"].c_str());
float y = str_to_float(ent->keyvalues["angle"]);

if (y >= 0.0f)
{
Expand All @@ -1725,7 +1725,7 @@ void BspRenderer::refreshEnt(size_t entIdx)
if (ent->classname.size() && ent->classname.find("light") != std::string::npos && ent->keyOrder[i] == "pitch")
{
setAngles = true;
float x = (float)atof(ent->keyvalues["pitch"].c_str());
float x = str_to_float(ent->keyvalues["pitch"]);
renderEnts[entIdx].angles.x = -x;
}
}
Expand All @@ -1734,7 +1734,7 @@ void BspRenderer::refreshEnt(size_t entIdx)
{
if (ent->hasKey("sequence") && isNumeric(ent->keyvalues["sequence"]))
{
sequence = atoi(ent->keyvalues["sequence"].c_str());
sequence = str_to_int(ent->keyvalues["sequence"]);
}
if (sequence <= 0 && g_app->fgd)
{
Expand All @@ -1750,7 +1750,7 @@ void BspRenderer::refreshEnt(size_t entIdx)
{
if (ent->hasKey("skin") && isNumeric(ent->keyvalues["skin"]))
{
skin = atoi(ent->keyvalues["skin"].c_str());
skin = str_to_int(ent->keyvalues["skin"]);
}
if (skin <= 0 && g_app->fgd)
{
Expand All @@ -1766,7 +1766,7 @@ void BspRenderer::refreshEnt(size_t entIdx)
{
if (ent->hasKey("body") && isNumeric(ent->keyvalues["body"]))
{
body = atoi(ent->keyvalues["body"].c_str());
body = str_to_int(ent->keyvalues["body"]);
}
if (body == 0 && g_app->fgd)
{
Expand Down
18 changes: 8 additions & 10 deletions src/editor/Fgd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void Fgd::parseClassHeader(FgdClass& fgdClass)

if (nums.size() == 3)
{
fgdClass.color = { (unsigned char)atoi(nums[0].c_str()), (unsigned char)atoi(nums[1].c_str()), (unsigned char)atoi(nums[2].c_str()) };
fgdClass.color = { (unsigned char)str_to_int(nums[0]), (unsigned char)str_to_int(nums[1]), (unsigned char)str_to_int(nums[2]) };
}
else
{
Expand All @@ -400,7 +400,7 @@ void Fgd::parseClassHeader(FgdClass& fgdClass)

if (nums.size() == 3)
{
fgdClass.offset = { (float)atof(nums[0].c_str()), (float)atof(nums[1].c_str()),(float)atof(nums[2].c_str()) };
fgdClass.offset = { str_to_float(nums[0]), str_to_float(nums[1]),str_to_float(nums[2]) };
}
else
{
Expand All @@ -419,11 +419,11 @@ void Fgd::parseClassHeader(FgdClass& fgdClass)
}
else if (lpart.starts_with("sequence("))
{
fgdClass.modelSequence = atoi(getValueInParens(typeParts[i]).c_str());
fgdClass.modelSequence = str_to_int(getValueInParens(typeParts[i]));
}
else if (lpart.starts_with("body("))
{
fgdClass.modelBody = atoi(getValueInParens(typeParts[i]).c_str());
fgdClass.modelBody = str_to_int(getValueInParens(typeParts[i]));
}
else if (lpart.starts_with("iconsprite("))
{
Expand Down Expand Up @@ -571,7 +571,7 @@ void Fgd::parseChoicesOrFlags(KeyvalueDef& outKey)
else
{
def.svalue = trimSpaces(keyParts[0]);
def.ivalue = atoi(keyParts[0].c_str());
def.ivalue = str_to_int(keyParts[0]);
def.isInteger = true;
}

Expand Down Expand Up @@ -735,7 +735,7 @@ void Fgd::processClassInheritance()
{
if (isNumeric(classes[i]->keyvalues[c].defaultValue))
{
classes[i]->modelSequence = atoi(classes[i]->keyvalues[c].defaultValue.c_str());
classes[i]->modelSequence = str_to_int(classes[i]->keyvalues[c].defaultValue);
}
}
}
Expand All @@ -745,7 +745,7 @@ void Fgd::processClassInheritance()
{
if (isNumeric(classes[i]->keyvalues[c].defaultValue))
{
classes[i]->modelBody = atoi(classes[i]->keyvalues[c].defaultValue.c_str());
classes[i]->modelBody = str_to_int(classes[i]->keyvalues[c].defaultValue);
}
}
}
Expand All @@ -755,15 +755,13 @@ void Fgd::processClassInheritance()
{
if (isNumeric(classes[i]->keyvalues[c].defaultValue))
{
classes[i]->modelSkin = atoi(classes[i]->keyvalues[c].defaultValue.c_str());
classes[i]->modelSkin = str_to_int(classes[i]->keyvalues[c].defaultValue);
}
}
}
}
}

}

}
}

Expand Down
48 changes: 45 additions & 3 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3897,6 +3897,20 @@ void Gui::drawMenuBar()
std::swap(map->ents[i]->origin.x, map->ents[i]->origin.y);
map->ents[i]->setOrAddKeyvalue("origin", map->ents[i]->origin.toKeyvalueString());
}

if (map->ents[i]->hasKey("angle"))
{
float angle = str_to_float(map->ents[i]->keyvalues["angle"]);
angle = 90.0f - angle;
map->ents[i]->setOrAddKeyvalue("angle", std::to_string(fullnormalizeangle(angle)));
}

if (map->ents[i]->hasKey("angles"))
{
vec3 angles = parseVector(map->ents[i]->keyvalues["angles"]);
angles[1] = 90.0f - angles[1];
map->ents[i]->setOrAddKeyvalue("angles", angles.normalize_angles().toKeyvalueString());
}
}

for (int i = 0; i < map->leafCount; i++)
Expand Down Expand Up @@ -3962,6 +3976,21 @@ void Gui::drawMenuBar()

map->ents[i]->origin.x *= -1;
}

if (map->ents[i]->hasKey("angle"))
{
float angle = str_to_float(map->ents[i]->keyvalues["angle"]);
angle += 90.0f;
map->ents[i]->setOrAddKeyvalue("angle", std::to_string(fullnormalizeangle(angle)));
}

if (map->ents[i]->hasKey("angles"))
{
vec3 angles = parseVector(map->ents[i]->keyvalues["angles"]);
angles[1] += 90.0f;
angles[2] *= -1;
map->ents[i]->setOrAddKeyvalue("angles", angles.normalize_angles().toKeyvalueString());
}
}

for (int i = 0; i < map->leafCount; i++)
Expand Down Expand Up @@ -4037,6 +4066,19 @@ void Gui::drawMenuBar()

map->ents[i]->origin.y *= -1;
}
if (map->ents[i]->hasKey("angle"))
{
float angle = str_to_float(map->ents[i]->keyvalues["angle"]);
angle -= 90.0f;
map->ents[i]->setOrAddKeyvalue("angle", std::to_string(fullnormalizeangle(angle)));
}

if (map->ents[i]->hasKey("angles"))
{
vec3 angles = parseVector(map->ents[i]->keyvalues["angles"]);
angles[1] -= 90.0f;
map->ents[i]->setOrAddKeyvalue("angles", angles.normalize_angles().toKeyvalueString());
}
}

for (int i = 0; i < map->leafCount; i++)
Expand Down Expand Up @@ -6389,7 +6431,7 @@ void Gui::drawKeyvalueEditor_SmartEditTab(size_t entIdx)
if (keyvalue.iType == FGD_KEY_CHOICES && !keyvalue.choices.empty())
{
std::string selectedValue = keyvalue.choices[0].name;
int ikey = atoi(value.c_str());
int ikey = str_to_int(value);

for (size_t k = 0; k < keyvalue.choices.size(); k++)
{
Expand Down Expand Up @@ -8820,8 +8862,8 @@ void Gui::drawAbout()
ImGui::TextUnformatted(url2);
ImGui::EndTooltip();
}
static char help1[] = "https://t.me/ninjac0w, https://github.com/Qwertyus3D, etc";
ImGui::InputText("Thanks list:", help1, strlen(help1), ImGuiInputTextFlags_ReadOnly);
static char help1[] = "https://t.me/ninjac0w, https://github.com/Qwertyus3D, twhl community, etc";
ImGui::InputText("Special thanks:", help1, strlen(help1), ImGuiInputTextFlags_ReadOnly);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
Expand Down
Loading

0 comments on commit 960d7cd

Please sign in to comment.