Skip to content

Commit

Permalink
preparation :) fix alpha sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Jan 1, 2024
1 parent af2a525 commit edd29c3
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 128 deletions.
5 changes: 3 additions & 2 deletions resources/languages/language.ini
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ LANG_0605 = (DEBUG)
LANG_0606 = toolbar
LANG_0607 = Object selection mode
LANG_0608 = Face selection mode
FACE_LEAF_MODE = Face selection and pvs edit mode
LANG_0609 = Overlay
LANG_0610 = %.0f FPS
LANG_0611 = VSync
Expand Down Expand Up @@ -637,10 +638,10 @@ LANG_0639 = Undo Memory Usage: %.2f MB
LANG_0640 = Show DragAxes
LANG_0641 = PRESS ME TO DECAL
LANG_0642 = TEST VIS DATA[CLIPNODES]
LANG_0643 = MARK ALL VISIBLED CLIPNODES FACES FROM CAMERA POS
LANG_0643 = MARK ALL VISIBLE CLIPNODES FACES FROM CAMERA POS
LANG_0644 = TEST PVS VIS DATA
LANG_0645 = TEST VIS DATA[FACES]
LANG_0646 = MARK ALL VISIBLED AND INVISIBLED FACES FROM CAMERA POS
LANG_0646 = MARK ALL VISIBLE AND INVISIBLE FACES FROM CAMERA POS
LANG_0647 = Model 1 ##mdl1
LANG_0648 = Model 2 ##mdl1
LANG_0649 = Swap models
Expand Down
5 changes: 3 additions & 2 deletions resources/languages/language_ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ LANG_0603 = Показать справку
LANG_0604 = О программе
LANG_0605 = (ОТЛАДКА)
LANG_0606 = панель инструментов
LANG_0607 = Режим выбора сущностей (0)
LANG_0608 = Режим выбора фейсов (1)
LANG_0607 = Режим выбора сущностей
LANG_0608 = Режим выбора фейсов
FACE_LEAF_MODE = Режим выбора фейсов и редактирования VIS
LANG_0609 = Оверлей
LANG_0610 = %.0f FPS
LANG_0611 = VSync
Expand Down
Binary file added resources/pictures/leaf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 45 additions & 3 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6500,8 +6500,8 @@ bool Bsp::leaf_add_face(int faceIdx, int leafIdx)
{
return false;
}


std::vector<int> all_mark_surfaces;
int surface_idx = 0;
for (int i = 0; i < leafCount; i++)
Expand Down Expand Up @@ -6533,13 +6533,55 @@ bool Bsp::leaf_add_face(int faceIdx, int leafIdx)
return true;
}

bool Bsp::remove_face(int faceIdx, bool onlyleafs)

bool Bsp::leaf_del_face(int faceIdx, int leafIdx)
{
if (faceIdx < 0 || faceIdx >= faceCount)
{
return false;
}

std::vector<int> all_mark_surfaces;
int surface_idx = 0;
for (int i = 0; i < leafCount; i++)
{
int del_faces = 0;
for (int n = 0; n < leaves[i].nMarkSurfaces; n++)
{
if (marksurfs[leaves[i].iFirstMarkSurface + n] == faceIdx && (leafIdx == -1 || leafIdx == i))
{
del_faces++;
}
else
{
all_mark_surfaces.push_back(marksurfs[leaves[i].iFirstMarkSurface + n]);
}
}

leaves[i].iFirstMarkSurface = surface_idx;

if (del_faces > 0)
{
leaves[i].nMarkSurfaces -= del_faces;
}

surface_idx += leaves[i].nMarkSurfaces;
}

unsigned char* newLump = new unsigned char[sizeof(int) * all_mark_surfaces.size()];
memcpy(newLump, &all_mark_surfaces[0], sizeof(int) * all_mark_surfaces.size());
replace_lump(LUMP_MARKSURFACES, newLump, sizeof(int) * all_mark_surfaces.size());

return true;
}

bool Bsp::remove_face(int faceIdx)
{
if (faceIdx < 0 || faceIdx >= faceCount)
{
return false;
}
bool onlyleafs = false;
int leafFaceTarget = -1;
if (onlyleafs)
{
Expand Down
3 changes: 2 additions & 1 deletion src/bsp/Bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ class Bsp
int duplicate_model(int modelIdx);
void duplicate_model_structures(int modelIdx);
bool leaf_add_face(int faceIdx, int leafIdx);
bool remove_face(int faceid, bool onlyleafs = false);
bool leaf_del_face(int faceIdx, int leafIdx);
bool remove_face(int faceid);
int merge_two_models(int src_model, int dst_model);

// if the face's texinfo is not unique, a new one is created and returned. Otherwise, it's current texinfo is returned
Expand Down
33 changes: 27 additions & 6 deletions src/bsp/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,47 @@ Sprite::Sprite(const std::string& filename)
spr.read(reinterpret_cast<char*>(&tmpSpriteImage.frameinfo), sizeof(dspriteframe_t));

int frame_size = tmpSpriteImage.frameinfo.width * tmpSpriteImage.frameinfo.height;
tmpSpriteImage.raw_image.resize(frame_size);

spr.read(reinterpret_cast<char*>(tmpSpriteImage.raw_image.data()), frame_size);
std::vector<unsigned char> raw_image;
raw_image.resize(frame_size);

spr.read(reinterpret_cast<char*>(raw_image.data()), frame_size);

tmpSpriteImage.image.resize(frame_size);

tmpSpriteImage.last_color = palette[colors - 1];

for (int s = 0; s < frame_size; s++)
{
tmpSpriteImage.image[s] = palette[tmpSpriteImage.raw_image[s]];
if (header.texFormat == SPR_ALPHTEST && raw_image[s] == colors - 1)
{
tmpSpriteImage.image[s] = COLOR4(0, 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);
}
else if (header.texFormat == SPR_INDEXALPHA)
{
tmpSpriteImage.image[s] = tmpSpriteImage.last_color;
tmpSpriteImage.image[s].a = raw_image[s];
}
else
{
tmpSpriteImage.image[s] = palette[raw_image[s]];
}
}

tmpSpriteImage.spriteCube = new EntCube();
tmpSpriteImage.spriteCube->mins = { -4.0f, 0.0f, 0.0f };
tmpSpriteImage.spriteCube->maxs = { 4.0f, tmpSpriteImage.frameinfo.width * 1.0f, tmpSpriteImage.frameinfo.height * 1.0f };
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 += 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), false, 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);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/bsp/Sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ struct dspriteframe_t {
struct SpriteImage
{
dspriteframe_t frameinfo;
std::vector<COLOR3> image;
std::vector<unsigned char> raw_image;
std::vector<COLOR4> image;
COLOR3 last_color;
float interval;
Texture* texture;
EntCube* spriteCube;
Expand All @@ -62,6 +62,7 @@ struct SpriteGroup
{
std::vector<SpriteImage> sprites;
float totalinterval;
float currentinterval;
};

class Sprite {
Expand Down
11 changes: 5 additions & 6 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,10 @@ void BspRenderer::drawPointEntities(std::vector<int> highlightEnts)
{
renderEnts[i].mdl->mdl_cube->wireframeBuffer->drawFull();
}
else
{
renderEnts[i].pointEntCube->axesBuffer->drawFull();
}

renderEnts[i].pointEntCube->wireframeBuffer->drawFull();
}
Expand Down Expand Up @@ -2680,6 +2684,7 @@ void BspRenderer::drawPointEntities(std::vector<int> highlightEnts)
}
else
{
renderEnts[i].pointEntCube->axesBuffer->drawFull();
renderEnts[i].pointEntCube->wireframeBuffer->drawFull();
}
}
Expand All @@ -2697,12 +2702,6 @@ void BspRenderer::drawPointEntities(std::vector<int> highlightEnts)
}

renderEnts[i].pointEntCube->axesBuffer->drawFull();

if (renderEnts[i].pointEntCube->Textured)
{
g_app->modelShader->bind();
missingTex->bind(0);
}
renderEnts[i].pointEntCube->cubeBuffer->drawFull();
}
}
Expand Down
Loading

0 comments on commit edd29c3

Please sign in to comment.