Skip to content

Commit

Permalink
Update. Bugfixes. PVS EDIT FULLY (possible)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Jan 2, 2024
1 parent 19559a1 commit 03782dc
Show file tree
Hide file tree
Showing 16 changed files with 608 additions and 224 deletions.
4 changes: 4 additions & 0 deletions resources/languages/language.ini
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ LANG_0439 = Ctrl+C
LANG_0440 = Paste texture
LANG_0441 = Ctrl+V
LANG_0442 = Copy lightmap
SELECT_ALL_TEXTURED = Select same texture
SELECT_ALL_TEXTURED_FULL = Select all faces with same texture!
SELECT_FACE_MDL = Select model
SELECT_FACE_MDL_FULL = Select all faces of selected model.
LANG_0443 = (WIP)
LANG_0444 = Only works for faces with matching sizes/extents,\nand the lightmap might get shifted.
LANG_0445 = Paste lightmap
Expand Down
4 changes: 4 additions & 0 deletions resources/languages/language_ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ LANG_0439 = Ctrl+C
LANG_0440 = Вставить текстуру
LANG_0441 = Ctrl+V
LANG_0442 = Копировать лайтмапу
SELECT_ALL_TEXTURED = Выбрать с этой текстурой
SELECT_ALL_TEXTURED_FULL = Выбрать все грани с такой же текстурой!
SELECT_FACE_MDL = Выбрать всю модель
SELECT_FACE_MDL_FULL = Выбрать все фейсы данной модели!
LANG_0443 = (WIP)
LANG_0444 = Это работает только для фейсов с одинаковым\nразмером/границами, и лайтмапа может сдвинуться.
LANG_0445 = Вставить лайтмапу
Expand Down
17 changes: 10 additions & 7 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6577,18 +6577,21 @@ bool Bsp::leaf_del_face(int faceIdx, int leafIdx)

bool Bsp::remove_face(int faceIdx)
{
// Check if face is valid
if (faceIdx < 0 || faceIdx >= faceCount)
{
return false;
}
bool onlyleafs = false;

int leafFaceTarget = -1;
bool onlyleafs = false;
if (onlyleafs)
{
leafFaceTarget = faceIdx;
}
else
{
print_log("Remove face with id:{}\n", faceIdx);
std::vector<BSPFACE32> all_faces;
for (int f = 0; f < faceCount; f++)
{
Expand All @@ -6598,13 +6601,14 @@ bool Bsp::remove_face(int faceIdx)
}
else
{
// Shift face count in models
for (int m = 0; m < modelCount; m++)
{
if (models[m].nFaces == 0)
continue;
if (faceIdx >= models[m].iFirstFace && faceIdx < models[m].iFirstFace + models[m].nFaces)
{
//print_log("Remove face from {} model\n", m);
print_log("Remove face from {} model\n", m);
models[m].nFaces--;
}
else if (models[m].iFirstFace != 0 && models[m].iFirstFace > faceIdx)
Expand All @@ -6620,7 +6624,7 @@ bool Bsp::remove_face(int faceIdx)
continue;
if (faceIdx >= nodes[n].iFirstFace && faceIdx < nodes[n].iFirstFace + nodes[n].nFaces)
{
//print_log("Remove face from {} node\n", n);
print_log("Remove face from {} node\n", n);
nodes[n].nFaces--;
}
else if (nodes[n].iFirstFace != 0 && nodes[n].iFirstFace > faceIdx)
Expand All @@ -6637,7 +6641,7 @@ bool Bsp::remove_face(int faceIdx)

if (faceIdx == marksurfs[s])
{
//print_log("Remove face from {} surface\n", s);
print_log("Remove face from {} surface\n", s);
marksurfs[s] = leafFaceTarget;
}
else if (marksurfs[s] != 0 && marksurfs[s] > faceIdx)
Expand All @@ -6650,8 +6654,7 @@ bool Bsp::remove_face(int faceIdx)

// Update faces array
unsigned char* newLump = new unsigned char[sizeof(BSPFACE32) * all_faces.size()];
if (sizeof(BSPFACE32) * all_faces.size() > 0)
memcpy(newLump, &all_faces[0], sizeof(BSPFACE32) * all_faces.size());
memcpy(newLump, &all_faces[0], sizeof(BSPFACE32) * all_faces.size());
replace_lump(LUMP_FACES, newLump, sizeof(BSPFACE32) * all_faces.size());
}

Expand All @@ -6670,7 +6673,7 @@ bool Bsp::remove_face(int faceIdx)
continue;
if (s >= leaves[m].iFirstMarkSurface && s < leaves[m].iFirstMarkSurface + leaves[m].nMarkSurfaces)
{
//print_log("Remove face {} from {} leaf\n", faceIdx, m);
print_log("Remove face {} from {} leaf\n", faceIdx, m);
leaves[m].nMarkSurfaces--;
}
else if (leaves[m].iFirstMarkSurface != 0 && leaves[m].iFirstMarkSurface > s)
Expand Down
116 changes: 107 additions & 9 deletions src/bsp/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,111 @@ Sprite::~Sprite()
sprite_groups.clear();
}

void Sprite::DrawSprite()
{
animate_frame();
sprite_groups[current_group].sprites
[sprite_groups[current_group].current_spr].texture->bind(0);
sprite_groups[current_group].sprites
[sprite_groups[current_group].current_spr].spriteCube->cubeBuffer->drawFull();
}

void Sprite::DrawBBox()
{
sprite_groups[current_group].sprites
[sprite_groups[current_group].current_spr].spriteCube->wireframeBuffer->drawFull();
}

void Sprite::DrawAxes()
{
sprite_groups[current_group].sprites
[sprite_groups[current_group].current_spr].spriteCube->axesBuffer->drawFull();
}

void Sprite::animate_frame()
{
sprite_groups[current_group].currentinterval += fabs(g_app->curTime - anim_time);
if (sprite_groups[current_group]
.sprites[sprite_groups[current_group].current_spr].interval >
sprite_groups[current_group].currentinterval)
{
sprite_groups[current_group].currentinterval = 0.0f;
sprite_groups[current_group].current_spr++;
if (sprite_groups[current_group].current_spr >=
sprite_groups[current_group].sprites.size())
{
sprite_groups[current_group].current_spr = 0;
current_group++;
if (current_group > sprite_groups.size())
{
current_group = 0;
}
}
}
anim_time = g_app->curTime;
}

void Sprite::set_missing_sprite()
{
sprite_groups.resize(1);
sprite_groups[0].currentinterval = 0.1;
sprite_groups[0].totalinterval = 0.1;
sprite_groups[0].sprites.resize(1);
sprite_groups[0].sprites[0].image.resize(64 * 64);
memset(sprite_groups[0].sprites[0].image.data(), 255, 64 * 64 * sizeof(COLOR4));
sprite_groups[0].currentinterval = 0.0f;
sprite_groups[0].current_spr = 0;

SpriteImage& tmpSpriteImage = sprite_groups[0].sprites[0];

tmpSpriteImage.frameinfo.width = 64;
tmpSpriteImage.frameinfo.height = 64;
tmpSpriteImage.frameinfo.origin[0] = -32;
tmpSpriteImage.frameinfo.origin[1] = 32;

tmpSpriteImage.spriteCube = new EntCube();
tmpSpriteImage.spriteCube->mins = { -5.0f, 0.0f, 0.0f };
tmpSpriteImage.spriteCube->maxs = { 5.0f, tmpSpriteImage.frameinfo.width * 1.0f, tmpSpriteImage.frameinfo.height * 1.0f };
tmpSpriteImage.spriteCube->mins += vec3(0.0f, tmpSpriteImage.frameinfo.origin[0] * 1.0f, tmpSpriteImage.frameinfo.origin[1] * -1.0f);
tmpSpriteImage.spriteCube->maxs += vec3(0.0f, tmpSpriteImage.frameinfo.origin[0] * 1.0f, tmpSpriteImage.frameinfo.origin[1] * -1.0f);
tmpSpriteImage.spriteCube->Textured = true;

g_app->pointEntRenderer->genCubeBuffers(tmpSpriteImage.spriteCube);

tmpSpriteImage.texture = new Texture(tmpSpriteImage.frameinfo.width,
tmpSpriteImage.frameinfo.height, (unsigned char*)&tmpSpriteImage.image[0], "MISSING_SPRTE", true, false);

tmpSpriteImage.texture->upload(Texture::TEXTURE_TYPE::TYPE_DECAL);
}

Sprite::Sprite(const std::string& filename)
{
if (!filename.size())
{
return;
}

this->name = stripExt(basename(filename));
this->current_group = 0;

std::ifstream spr(filename, std::ios::binary);
if (!spr) {
print_log(PRINT_RED, "Failed to open file {}\n", filename);
set_missing_sprite();
return;
}

int id, version;
spr.read(reinterpret_cast<char*>(&id), sizeof(id));
if (id != 'PSDI')
if (id != 'PSDI' || !spr)
{
print_log(PRINT_RED, "Not a sprite {}\n", filename);
set_missing_sprite();
return;
}
spr.read(reinterpret_cast<char*>(&version), sizeof(version));
if (version != 2) {
if (version != 2 || !spr) {
print_log(PRINT_RED, "Wrong version {}\n", filename);
set_missing_sprite();
return;
}
spr.seekg(0);
Expand All @@ -61,13 +141,23 @@ Sprite::Sprite(const std::string& filename)
spr.read(reinterpret_cast<char*>(palette.data()), colors * sizeof(COLOR3));

sprite_groups.resize(header.numframes);
if (!spr)
{
print_log(PRINT_RED, "Bad read {}\n", filename);
set_missing_sprite();
return;
}

bool is_valid = false;

for (int i = 0; i < header.numframes; ++i)
{
int is_group;
spr.read(reinterpret_cast<char*>(&is_group), sizeof(int));

int group_frames = 1;
sprite_groups[i].currentinterval = 0.0f;
sprite_groups[i].current_spr = 0;

if (is_group != 0) {
spr.read(reinterpret_cast<char*>(&group_frames), sizeof(int));
Expand Down Expand Up @@ -107,7 +197,7 @@ Sprite::Sprite(const std::string& filename)
{
tmpSpriteImage.image[s] = COLOR4(0, 0, 0, 0);
}
else if(header.texFormat == SPR_ADDITIVE && palette[raw_image[s]] == COLOR3(0, 0, 0))
else if (header.texFormat == SPR_ADDITIVE && palette[raw_image[s]] == COLOR3(0, 0, 0))
{
tmpSpriteImage.image[s] = COLOR4(0, 0, 0, 0);
}
Expand All @@ -123,25 +213,33 @@ Sprite::Sprite(const std::string& filename)
}

tmpSpriteImage.spriteCube = new EntCube();
tmpSpriteImage.spriteCube->mins = { -1.0f, 0.0f, 0.0f };
tmpSpriteImage.spriteCube->maxs = { 1.0f, tmpSpriteImage.frameinfo.width * 1.0f, tmpSpriteImage.frameinfo.height * 1.0f };
tmpSpriteImage.spriteCube->mins = { -5.0f, 0.0f, 0.0f };
tmpSpriteImage.spriteCube->maxs = { 5.0f, tmpSpriteImage.frameinfo.width * 1.0f, tmpSpriteImage.frameinfo.height * 1.0f };
tmpSpriteImage.spriteCube->mins += vec3(0.0f, tmpSpriteImage.frameinfo.origin[0] * 1.0f, tmpSpriteImage.frameinfo.origin[1] * -1.0f);
tmpSpriteImage.spriteCube->maxs += vec3(0.0f, tmpSpriteImage.frameinfo.origin[0] * 1.0f, tmpSpriteImage.frameinfo.origin[1] * -1.0f);
tmpSpriteImage.spriteCube->Textured = true;

g_app->pointEntRenderer->genCubeBuffers(tmpSpriteImage.spriteCube);

tmpSpriteImage.texture = new Texture(tmpSpriteImage.frameinfo.width,
tmpSpriteImage.frameinfo.height, (unsigned char*)&tmpSpriteImage.image[0], fmt::format("{}_g{}_f{}", name, i, j),true, false);
tmpSpriteImage.frameinfo.height, (unsigned char*)&tmpSpriteImage.image[0], fmt::format("{}_g{}_f{}", name, i, j), true, false);
tmpSpriteImage.texture->upload(Texture::TEXTURE_TYPE::TYPE_DECAL);

is_valid = true;
}
}

if (!is_valid)
{
set_missing_sprite();
}
}


std::map<int, Sprite*> spr_models;


Sprite* AddNewSpriteToRender(const std::string & path, unsigned int sum)
Sprite* AddNewSpriteToRender(const std::string& path, unsigned int sum)
{
unsigned int crc32 = GetCrc32InMemory((unsigned char*)path.data(), path.size(), sum);

Expand All @@ -161,7 +259,7 @@ Sprite* AddNewSpriteToRender(const std::string & path, unsigned int sum)

void TestSprite()
{
Sprite * tmpSprite = AddNewSpriteToRender("d:\\SteamLibrary\\steamapps\\common\\Half-Life\\cstrike\\sprites\\pistol_smoke1.spr");
Sprite* tmpSprite = AddNewSpriteToRender("d:\\SteamLibrary\\steamapps\\common\\Half-Life\\cstrike\\sprites\\pistol_smoke1.spr");
int fileid = 0;
int groupid = 0;
for (auto& g : tmpSprite->sprite_groups)
Expand Down
12 changes: 12 additions & 0 deletions src/bsp/Sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ struct SpriteImage
float interval;
Texture* texture;
EntCube* spriteCube;
vec3 mins;
vec3 maxs;
};

struct SpriteGroup
{
std::vector<SpriteImage> sprites;
size_t current_spr;
float totalinterval;
float currentinterval;
};
Expand All @@ -74,6 +77,15 @@ class Sprite {
short colors;
std::vector<COLOR3> palette;
std::vector<SpriteGroup> sprite_groups;

void DrawSprite();
void DrawBBox();
void DrawAxes();
private:
void set_missing_sprite();
void animate_frame();
size_t current_group;
double anim_time;
};

void TestSprite();
Expand Down
Loading

0 comments on commit 03782dc

Please sign in to comment.