Skip to content

Commit

Permalink
Fix big big models, added console!
Browse files Browse the repository at this point in the history
Fix big big models, added console for
WIN32!
  • Loading branch information
UnrealKaraulov committed Feb 14, 2024
1 parent 8f5036a commit d787625
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5851,8 +5851,8 @@ void Bsp::create_inside_box(const vec3& min, const vec3& max, BSPMODEL* targetMo
if (texOffset >= 0)
{
BSPMIPTEX tex = *((BSPMIPTEX*)(textures + texOffset));
texinfo->vS /= size[0] / tex.nWidth;
texinfo->vT /= size[1] / tex.nHeight;
texinfo->vS /= 1.0f * size[0] / tex.nWidth;
texinfo->vT /= 1.0f * size[1] / tex.nHeight;
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Gui::init()
leafIconTexture->upload();
}

ImVec4 imguiColorFromConsole(unsigned short colors)
ImVec4 imguiColorFromConsole(unsigned int colors)
{
bool intensity = (colors & PRINT_INTENSITY) != 0;
float red = (colors & PRINT_RED) ? (intensity ? 1.0f : 0.5f) : 0.0f;
Expand Down Expand Up @@ -3552,6 +3552,8 @@ void Gui::drawMenuBar()
else
replaceAll(args, "{map_path}", "\"" + bsp_path + "\"");

showConsoleWindow(true);

tmpProc->arg(args);
tmpProc->executeAndWait(0, 0, 0);

Expand Down Expand Up @@ -4480,6 +4482,12 @@ void Gui::drawMenuBar()

if (ImGui::BeginMenu(get_localized_string(LANG_0601).c_str()))
{
#ifdef WIN32
if (ImGui::MenuItem("Console", NULL, &g_console_visibled))
{
showConsoleWindow(g_console_visibled);
}
#endif
Bsp* selectedMap = app->getSelectedMap();
for (BspRenderer* bspRend : mapRenderers)
{
Expand Down Expand Up @@ -7079,7 +7087,7 @@ void Gui::drawLog()
}

static std::vector<std::string> log_buffer_copy;
static std::vector<unsigned short> color_buffer_copy;
static std::vector<unsigned int> color_buffer_copy;

g_mutex_list[0].lock();
if (log_buffer_copy.size() != g_log_buffer.size())
Expand Down
15 changes: 4 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,6 @@ bool g_verbose = false;
#include <csignal>
#endif

void hideConsoleWindow()
{
#ifdef WIN32
#ifdef NDEBUG
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
#endif
#endif
}

bool start_viewer(const char* map)
{
if (map && map[0] != '\0' && !fileExists(map))
Expand All @@ -132,9 +123,11 @@ bool start_viewer(const char* map)
renderer.addMap(new Bsp(map));
}
renderer.reloadBspModels();
hideConsoleWindow();

#ifdef WIN32
#ifdef NDEBUG
showConsoleWindow(false);
#endif
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
#endif

Expand Down Expand Up @@ -1086,7 +1079,7 @@ int main(int argc, char* argv[])
{
std::string newpath;
Bsp* tmpBsp = new Bsp(cli.bspfile);
tmpBsp->ExportExtFile(cli.hasOption("-o") ? cli.getOption("-o") : cli.bspfile,newpath);
tmpBsp->ExportExtFile(cli.hasOption("-o") ? cli.getOption("-o") : cli.bspfile, newpath);
delete tmpBsp;
return 0;
}
Expand Down
12 changes: 11 additions & 1 deletion src/mdl/mdl_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,11 @@ void StudioModel::RefreshMeshList(int body)

if (needForceUpdate)
{
if (abs(mins.x - maxs.x) > 512.f &&
abs(mins.y - maxs.y) > 512.f &&
abs(mins.z - maxs.z) > 512.f)
ExtractBBox(mins, maxs);

if (mdl_cube != NULL)
{
mdl_cube->mins = mins;
Expand Down Expand Up @@ -1143,8 +1148,13 @@ void StudioModel::ExtractBBox(vec3& _mins, vec3& _maxs)
{
mstudioseqdesc_t* pseqdesc;

pseqdesc = (mstudioseqdesc_t*)((unsigned char*)m_pstudiohdr + m_pstudiohdr->seqindex);
if (!m_pstudiohdr || m_sequence > m_pstudiohdr->numseq)
return;
if (m_sequence < 0)
return;

pseqdesc = (mstudioseqdesc_t*)((unsigned char*)m_pstudiohdr + m_pstudiohdr->seqindex);

_mins[0] = pseqdesc[m_sequence].bbmin[0];
_mins[1] = pseqdesc[m_sequence].bbmin[1];
_mins[2] = pseqdesc[m_sequence].bbmin[2];
Expand Down
18 changes: 13 additions & 5 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool DebugKeyPressed = false;
ProgressMeter g_progress = {};
int g_render_flags;
std::vector<std::string> g_log_buffer = { "" };
std::vector<unsigned short> g_color_buffer = { 0 };
std::vector<unsigned int> g_color_buffer = { 0 };

std::mutex g_mutex_list[10] = {};

Expand Down Expand Up @@ -1196,10 +1196,18 @@ void fixupPath(std::string& path, FIXUPPATH_SLASH startslash, FIXUPPATH_SLASH en
replaceAll(path, "//", "/");
}

unsigned short g_console_colors = 0;
unsigned int g_console_colors = 0;
bool g_console_visibled = true;
void showConsoleWindow(bool show)
{
g_console_visibled = show;
#ifdef WIN32
::ShowWindow(::GetConsoleWindow(), show ? SW_SHOW :SW_HIDE);
#endif
}

#ifdef WIN32
void set_console_colors(unsigned short colors)
void set_console_colors(unsigned int colors)
{
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
if (!console)
Expand All @@ -1212,7 +1220,7 @@ void set_console_colors(unsigned short colors)
}
}
#else
void set_console_colors(unsigned short colors)
void set_console_colors(unsigned int colors)
{
colors = colors ? colors : (PRINT_GREEN | PRINT_BLUE | PRINT_RED | PRINT_INTENSITY);
g_console_colors = colors;
Expand Down Expand Up @@ -1947,7 +1955,7 @@ BSPPLANE getSeparatePlane(vec3 amin, vec3 amax, vec3 bmin, vec3 bmax, bool force
{
separationPlane.nType = -1; // no simple separating axis

print_log(PRINT_RED,get_localized_string(LANG_0239));
print_log(PRINT_RED, get_localized_string(LANG_0239));
print_log(PRINT_RED, "({:6.0f}, {:6.0f}, {:6.0f})", amin.x, amin.y, amin.z);
print_log(PRINT_RED, " - ({:6.0f}, {:6.0f}, {:6.0f}) {}\n", amax.x, amax.y, amax.z, "MODEL1");

Expand Down
22 changes: 11 additions & 11 deletions src/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

#include <filesystem>
namespace fs = std::filesystem;
// not working on fucking linux (<format> file not found, or std::format not found, etc)
//#include <format>
// replaced to fmt
#include <fmt/format.h>
#include <iostream>
#include <string>
Expand All @@ -28,7 +25,7 @@ extern std::string g_version_string;
#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename), (mode)))==NULL
#endif

enum PRINT_CONST : unsigned short
enum PRINT_CONST : unsigned int
{
PRINT_BLUE = 1,
PRINT_GREEN = 2,
Expand All @@ -49,22 +46,26 @@ extern bool DebugKeyPressed;
extern bool g_verbose;
extern ProgressMeter g_progress;
extern std::vector<std::string> g_log_buffer;
extern std::vector<unsigned short> g_color_buffer;
extern std::vector<unsigned int> g_color_buffer;

extern std::mutex g_mutex_list[10];


extern unsigned short g_console_colors;
//ImVec4 imguiColorFromConsole(unsigned short colors);
void set_console_colors(unsigned short colors = 0);
extern unsigned int g_console_colors;

extern bool g_console_visibled;
void showConsoleWindow(bool show);

//ImVec4 imguiColorFromConsole(unsigned int colors);
void set_console_colors(unsigned int colors = 0);

std::vector<std::string> splitStringIgnoringQuotes(const std::string& s, const std::string& delimitter);
std::vector<std::string> splitString(const std::string& s, const std::string& delimiter, int maxParts = 0);

void replaceAll(std::string& str, const std::string& from, const std::string& to);

template<class ...Args>
inline void print_log(unsigned short colors, const std::string& format, Args ...args) noexcept
inline void print_log(unsigned int colors, const std::string& format, Args ...args) noexcept
{
set_console_colors(colors);
std::string line = fmt::vformat(format, fmt::make_format_args(args...));
Expand All @@ -77,8 +78,8 @@ inline void print_log(unsigned short colors, const std::string& format, Args ...
static std::ofstream outfile("log.txt", std::ios_base::app);
outfile << line;
outfile.flush();
std::cout << line;
#endif
std::cout << line;
//replaceAll(line, " ", "+");
auto newline = line.ends_with('\n');
auto splitstr = splitString(line, "\n");
Expand Down Expand Up @@ -138,7 +139,6 @@ inline void print_log(const std::string& format, Args ...args) noexcept
print_log(g_console_colors, "{}", line);
}


bool fileExists(const std::string& fileName);

bool copyFile(const std::string& from, const std::string& to);
Expand Down

0 comments on commit d787625

Please sign in to comment.