Skip to content

Commit

Permalink
Test bug fix ctrl+c
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 12, 2024
1 parent 91a3229 commit 01e35f6
Show file tree
Hide file tree
Showing 35 changed files with 644 additions and 518 deletions.
4 changes: 4 additions & 0 deletions ascript/angelscript/projects/msvc2022/angelscript.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<OutDir>..\..\lib\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<EnableMicrosoftCodeAnalysis>false</EnableMicrosoftCodeAnalysis>
<CodeAnalysisRuleSet>NativeMinimumRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
Expand Down
30 changes: 14 additions & 16 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,6 @@ void BspMerger::merge_textures(Bsp& mapA, Bsp& mapB)
{
BSPMIPTEX* tex = (BSPMIPTEX*)(mapA.textures + offset);
int sz = mapA.getBspTextureSize(i);
//memset(tex->nOffsets, 0, sizeof(unsigned int) * 4);

mipTexOffsets[newTexCount] = (int)(mipTexWritePtr - newMipTexData);
memcpy(mipTexWritePtr, tex, sz);
Expand Down Expand Up @@ -1421,18 +1420,20 @@ void BspMerger::merge_textures(Bsp& mapA, Bsp& mapB)
texHeader[0] = newTexCount;
for (unsigned int i = 0; i < newTexCount; i++)
{
texHeader[i + 1] = (mipTexOffsets[i] == -1) ? -1 : mipTexOffsets[i] + texHeaderSize;
if (i + 1 < newTexCount + 1) {
texHeader[i + 1] = (mipTexOffsets[i] == -1) ? -1 : mipTexOffsets[i] + texHeaderSize;
}
}

memcpy(newTextureData + texHeaderSize, newMipTexData, mipTexWritePtr - newMipTexData);

delete[] mipTexOffsets;


print_log(get_localized_string(LANG_0241), duplicates);
print_log("\n");

mapA.replace_lump(LUMP_TEXTURES, newTextureData, newLen);
delete[] newMipTexData;
}

void BspMerger::merge_vertices(Bsp& mapA, Bsp& mapB)
Expand Down Expand Up @@ -2096,17 +2097,17 @@ void BspMerger::create_merge_headnodes(Bsp& mapA, Bsp& mapB, BSPPLANE separation
}


// write new head node (clipnode BSP)

// Write new head node (clipnode BSP)
{
const int NEW_NODE_COUNT = MAX_MAP_HULLS - 1;
constexpr int NEW_NODE_COUNT = MAX_MAP_HULLS - 1; // Use constexpr as suggested

BSPCLIPNODE32 newHeadNodes[NEW_NODE_COUNT];
std::vector<BSPCLIPNODE32> newHeadNodes(NEW_NODE_COUNT);
for (int i = 0; i < NEW_NODE_COUNT; i++)
{
//print_log(get_localized_string(LANG_0246),i+1,thisWorld.iHeadnodes[i+1]);
newHeadNodes[i] = {
separationPlaneIdx, // plane idx
{ // child nodes
separationPlaneIdx, // plane idx
{ // child nodes
otherWorld.iHeadnodes[i + 1] + mapA.clipnodeCount + NEW_NODE_COUNT,
thisWorld.iHeadnodes[i + 1] + NEW_NODE_COUNT
},
Expand All @@ -2123,16 +2124,13 @@ void BspMerger::create_merge_headnodes(Bsp& mapA, Bsp& mapB, BSPPLANE separation

if (swapNodeChildren)
{
int temp = newHeadNodes[i].iChildren[0];
newHeadNodes[i].iChildren[0] = newHeadNodes[i].iChildren[1];
newHeadNodes[i].iChildren[1] = temp;
std::swap(newHeadNodes[i].iChildren[0], newHeadNodes[i].iChildren[1]);
}
}

BSPCLIPNODE32* newThisNodes = new BSPCLIPNODE32[mapA.clipnodeCount + NEW_NODE_COUNT];
memcpy(newThisNodes, newHeadNodes, NEW_NODE_COUNT * sizeof(BSPCLIPNODE32));
memcpy(newThisNodes + NEW_NODE_COUNT, mapA.clipnodes, mapA.clipnodeCount * sizeof(BSPCLIPNODE32));
std::vector<BSPCLIPNODE32> newThisClipNodes(newHeadNodes.begin(), newHeadNodes.end());
newThisClipNodes.insert(newThisClipNodes.end(), mapA.clipnodes, mapA.clipnodes + mapA.clipnodeCount);

mapA.replace_lump(LUMP_CLIPNODES, newThisNodes, (mapA.clipnodeCount + NEW_NODE_COUNT) * sizeof(BSPCLIPNODE32));
mapA.replace_lump(LUMP_CLIPNODES, newThisClipNodes.data(), newThisClipNodes.size() * sizeof(BSPCLIPNODE32));
}
}
74 changes: 27 additions & 47 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ BspRenderer::BspRenderer(Bsp* _map)
map->setBspRender(this);

lightmaps = NULL;
glTexturesSwap = NULL;
glTextures = NULL;
glTexturesSwap.clear();
glTextures.clear();

leafCube = new EntCube();
nodeCube = new EntCube();/*
Expand Down Expand Up @@ -340,7 +340,7 @@ void BspRenderer::loadTextures()

map->update_lump_pointers();

glTexturesSwap = new std::vector<Texture*>[map->textureCount];
glTexturesSwap.resize(map->textureCount);
for (int i = 0; i < map->textureCount; i++)
{
int texOffset = ((int*)map->textures)[i + 1];
Expand Down Expand Up @@ -615,9 +615,9 @@ RenderClipnodes* BspRenderer::addClipnodeModel(int modelIdx)

void BspRenderer::loadLightmaps()
{
std::vector<LightmapNode*> atlases;
std::vector<Texture*> atlasTextures;
atlases.push_back(new LightmapNode(0, 0, MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE));
std::vector<LightmapNode> atlases{};
std::vector<Texture*> atlasTextures{};
atlases.push_back(LightmapNode(0, 0, MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE));
atlasTextures.push_back(new Texture(MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE,
new unsigned char[MAX_LIGHTMAP_ATLAS_SIZE * MAX_LIGHTMAP_ATLAS_SIZE * sizeof(COLOR3)], "LIGHTMAP"));

Expand Down Expand Up @@ -698,15 +698,15 @@ void BspRenderer::loadLightmaps()
atlasId = (int)(atlases.size()) - 1;

// TODO: Try fitting in earlier atlases before using the latest one
if (!atlases[atlasId]->insert(info.w, info.h, info.x[s], info.y[s]))
if (!atlases[atlasId].insert(info.w, info.h, info.x[s], info.y[s]))
{
atlases.push_back(new LightmapNode(0, 0, MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE));
atlases.push_back(LightmapNode(0, 0, MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE));
atlasTextures.push_back(new Texture(MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE, new unsigned char[MAX_LIGHTMAP_ATLAS_SIZE * MAX_LIGHTMAP_ATLAS_SIZE * sizeof(COLOR3)], "LIGHTMAP"));

atlasId++;
memset(atlasTextures[atlasId]->get_data(), 255, MAX_LIGHTMAP_ATLAS_SIZE * MAX_LIGHTMAP_ATLAS_SIZE * sizeof(COLOR3));

if (!atlases[atlasId]->insert(info.w, info.h, info.x[s], info.y[s]))
if (!atlases[atlasId].insert(info.w, info.h, info.x[s], info.y[s]))
{
print_log(get_localized_string(LANG_0275), info.w, info.h, MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE);
continue;
Expand Down Expand Up @@ -745,15 +745,8 @@ void BspRenderer::loadLightmaps()
}
}

glLightmapTextures.assign(atlasTextures.begin(), atlasTextures.end());

glLightmapTextures = new Texture * [atlasTextures.size()];
for (size_t i = 0; i < atlasTextures.size(); i++)
{
glLightmapTextures[i] = atlasTextures[i];
delete atlases[i];
}

numLightmapAtlases = (int)(atlasTextures.size());
//lodepng_encode24_file("atlas.png", atlasTextures[0]->data, MAX_LIGHTMAP_ATLAS_SIZE, MAX_LIGHTMAP_ATLAS_SIZE);
print_log(get_localized_string(LANG_0276), lightmapCount, atlases.size());
lightmapsGenerated = true;
Expand Down Expand Up @@ -894,9 +887,9 @@ void BspRenderer::deleteRenderFaces()

void BspRenderer::deleteTextures()
{
if (glTextures)
for (int i = 0; i < numLoadedTextures; i++)
{
for (int i = 0; i < numLoadedTextures; i++)
if (glTextures[i].size())
{
for (auto& tex : glTextures[i])
{
Expand All @@ -909,28 +902,22 @@ void BspRenderer::deleteTextures()
}
}
}
delete[] glTextures;
}

glTextures = NULL;
glTextures.clear();
}

void BspRenderer::deleteLightmapTextures()
{
if (glLightmapTextures)
for (size_t i = 0; i < glLightmapTextures.size(); i++)
{
for (int i = 0; i < numLightmapAtlases; i++)
if (glLightmapTextures[i])
{
if (glLightmapTextures[i])
{
delete glLightmapTextures[i];
glLightmapTextures[i] = NULL;
}
delete glLightmapTextures[i];
glLightmapTextures[i] = NULL;
}
delete[] glLightmapTextures;
}
numLightmapAtlases = 0;
glLightmapTextures = NULL;
glLightmapTextures.clear();
}

void BspRenderer::deleteFaceMaths()
Expand Down Expand Up @@ -1460,14 +1447,11 @@ void BspRenderer::generateNavMeshBuffer() {
}

cVert* output = new cVert[allVerts.size()];
for (size_t i = 0; i < allVerts.size(); i++) {
output[i] = allVerts[i];
}
std::copy(allVerts.begin(), allVerts.end(), output);

cVert* wireOutput = new cVert[wireframeVerts.size()];
for (size_t i = 0; i < wireframeVerts.size(); i++) {
wireOutput[i] = wireframeVerts[i];
}
std::copy(wireframeVerts.begin(), wireframeVerts.end(), wireOutput);


if (allVerts.size() == 0 || wireframeVerts.size() == 0) {
renderClip->clipnodeBuffer[hull] = NULL;
Expand Down Expand Up @@ -1598,14 +1582,10 @@ void BspRenderer::generateLeafNavMeshBuffer() {
}

cVert* output = new cVert[allVerts.size()];
for (size_t i = 0; i < allVerts.size(); i++) {
output[i] = allVerts[i];
}
std::copy(allVerts.begin(), allVerts.end(), output);

cVert* wireOutput = new cVert[wireframeVerts.size()];
for (size_t i = 0; i < wireframeVerts.size(); i++) {
wireOutput[i] = wireframeVerts[i];
}
std::copy(wireframeVerts.begin(), wireframeVerts.end(), wireOutput);

if (allVerts.size() == 0 || wireframeVerts.size() == 0) {
renderClip->clipnodeBuffer[hull] = NULL;
Expand Down Expand Up @@ -2542,20 +2522,20 @@ BspRenderer::~BspRenderer()

void BspRenderer::reuploadTextures()
{
if (!glTexturesSwap)
if (!glTexturesSwap.size())
{
loadTextures();
}

if (!glTexturesSwap)
if (!glTexturesSwap.size())
return;

deleteTextures();

//loadTextures();

glTextures = glTexturesSwap;
glTexturesSwap = NULL;
glTexturesSwap.clear();

for (int i = 0; i < map->textureCount; i++)
{
Expand All @@ -2574,7 +2554,7 @@ void BspRenderer::delayLoadData()
{
if (!lightmapsUploaded && lightmapFuture.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)
{
for (int i = 0; i < numLightmapAtlases; i++)
for (int i = 0; i < glLightmapTextures.size(); i++)
{
if (glLightmapTextures[i])
glLightmapTextures[i]->upload();
Expand Down
9 changes: 4 additions & 5 deletions src/editor/BspRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,17 @@ class BspRenderer
EntCube* nodeCube;/*
EntCube* nodePlaneCube;*/

int numLightmapAtlases;

int numRenderLightmapInfos;
int numLoadedTextures;
std::vector<Polygon3D> debugFaces;
NavMesh* debugNavMesh;

std::vector<Texture*>* glTextures = NULL;
std::vector<std::vector<Texture*>> glTextures{};

// textures loaded in a separate thread
std::vector<Texture*>* glTexturesSwap;
std::vector<std::vector<Texture*>> glTexturesSwap{};

Texture** glLightmapTextures = NULL;
std::vector<Texture*> glLightmapTextures{};
std::future<void> texturesFuture;

bool lightmapsGenerated = false;
Expand Down
Loading

0 comments on commit 01e35f6

Please sign in to comment.