Skip to content

Commit

Permalink
Added new startup command "-force_flushlog". Allows write to log file…
Browse files Browse the repository at this point in the history
… immediately (Thx alpet, RvP)

Environment_misc: fixed formatting
Added USE_LOG_TIMING. When used, log message is written in the following format: '[H:M:S.MS] log msg' (e.g. '[16:09:58.603] Loading DLL: xrRender_R2')
  • Loading branch information
qweasdd136963 authored and q4a committed Oct 7, 2018
1 parent aaf3df8 commit 279c86f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 40 deletions.
4 changes: 4 additions & 0 deletions src/Common/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#define NEW_SOUNDS // use new sounds. Please enclose any new sound additions with this define
#define LAYERED_SND_SHOOT// see comment down below

/* Debug: */
//#define USE_LOG_TIMING


/* LAYERED_SND_SHOOT by Alundaio
When defined, it will allow you to play a group of sounds from a specified section for snd_shoot.
You can have as many layers as you want, but you must follow naming convention,
Expand Down
74 changes: 61 additions & 13 deletions src/xrCore/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,18 @@ Lock logCS;
xr_vector<xr_string> LogFile;
LogCallback LogCB = 0;

bool ForceFlushLog = false;
IWriter* LogWriter = nullptr;
size_t CachedLog = 0;

void FlushLog()
{
if (!no_log)
{
logCS.Enter();
IWriter* f = FS.w_open(logFName);
if (f)
{
for (const auto &i : LogFile)
{
LPCSTR s = i.c_str();
f->w_string(s ? s : "");
}
FS.w_close(f);
}
if (LogWriter)
LogWriter->flush();
CachedLog = 0;
logCS.Leave();
}
}
Expand All @@ -53,6 +50,33 @@ void AddOne(const char* split)
if (LogExecCB && LogCB)
LogCB(split);

if (LogWriter)
{
#ifdef USE_LOG_TIMING
char buf[64];
char curTime[64];

auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) -
std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch());

std::strftime(buf, sizeof(buf), "%H:%M:%S", std::localtime(&time));
int len = xr_sprintf(curTime, 64, "[%s.%03lld] ", buf, ms.count());

LogWriter->w_printf("%s%s\r\n", curTime, split);
CachedLog += len;
#else
LogWriter->w_printf("%s\r\n", split);
#endif
CachedLog += xr_strlen(split) + 2;

if (ForceFlushLog || CachedLog >= 32768)
FlushLog();

//-RvP
}

logCS.Leave();
}

Expand Down Expand Up @@ -192,20 +216,44 @@ void CreateLog(BOOL nl)
FS.update_path(logFName, "$logs$", log_file_name);
if (!no_log)
{
IWriter* f = FS.w_open(logFName);
if (f == NULL)
// Alun: Backup existing log
xr_string backup_logFName = EFS.ChangeFileExt(logFName, ".bkp");
FS.file_rename(logFName, backup_logFName.c_str(), true);
//-Alun

LogWriter = FS.w_open(logFName);
if (LogWriter == nullptr)
{
#if defined(WINDOWS)
MessageBox(NULL, "Can't create log file.", "Error", MB_ICONERROR);
#endif
abort();
}
FS.w_close(f);

time_t t = time(NULL);
tm* ti = localtime(&t);
char buf[64];
strftime(buf, 64, "[%x %X]\t", ti);

for (u32 it = 0; it < LogFile.size(); it++)
{
LPCSTR s = LogFile[it].c_str();
LogWriter->w_printf("%s%s\n", buf, s ? s : "");
}
LogWriter->flush();
}

LogFile.reserve(128);

if (strstr(Core.Params, "-force_flushlog"))
ForceFlushLog = true;
}

void CloseLog(void)
{
FlushLog();
if (LogWriter)
FS.w_close(LogWriter);

LogFile.clear();
}
54 changes: 27 additions & 27 deletions src/xrEngine/Environment_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,41 +449,41 @@ void CEnvDescriptorMixer::lerp(
m_fSunShaftsIntensity = fi * A.m_fSunShaftsIntensity + f * B.m_fSunShaftsIntensity;
}

m_fWaterIntensity = fi * A.m_fWaterIntensity + f * B.m_fWaterIntensity;
m_fWaterIntensity = fi * A.m_fWaterIntensity + f * B.m_fWaterIntensity;

m_fTreeAmplitudeIntensity = fi * A.m_fTreeAmplitudeIntensity + f * B.m_fTreeAmplitudeIntensity;
m_fTreeAmplitudeIntensity = fi * A.m_fTreeAmplitudeIntensity + f * B.m_fTreeAmplitudeIntensity;

// colors
//. sky_color.lerp (A.sky_color,B.sky_color,f).add(Mdf.sky_color).mul(modif_power);
sky_color.lerp(A.sky_color, B.sky_color, f);
if (Mdf.use_flags.test(eSkyColor))
sky_color.add(Mdf.sky_color).mul(modif_power);
// colors
//. sky_color.lerp (A.sky_color,B.sky_color,f).add(Mdf.sky_color).mul(modif_power);
sky_color.lerp(A.sky_color, B.sky_color, f);
if (Mdf.use_flags.test(eSkyColor))
sky_color.add(Mdf.sky_color).mul(modif_power);

//. ambient.lerp (A.ambient,B.ambient,f).add(Mdf.ambient).mul(modif_power);
ambient.lerp(A.ambient, B.ambient, f);
if (Mdf.use_flags.test(eAmbientColor))
ambient.add(Mdf.ambient).mul(modif_power);
//. ambient.lerp (A.ambient,B.ambient,f).add(Mdf.ambient).mul(modif_power);
ambient.lerp(A.ambient, B.ambient, f);
if (Mdf.use_flags.test(eAmbientColor))
ambient.add(Mdf.ambient).mul(modif_power);

hemi_color.lerp(A.hemi_color, B.hemi_color, f);
hemi_color.lerp(A.hemi_color, B.hemi_color, f);

if (Mdf.use_flags.test(eHemiColor))
{
hemi_color.x += Mdf.hemi_color.x;
hemi_color.y += Mdf.hemi_color.y;
hemi_color.z += Mdf.hemi_color.z;
hemi_color.x *= modif_power;
hemi_color.y *= modif_power;
hemi_color.z *= modif_power;
}
if (Mdf.use_flags.test(eHemiColor))
{
hemi_color.x += Mdf.hemi_color.x;
hemi_color.y += Mdf.hemi_color.y;
hemi_color.z += Mdf.hemi_color.z;
hemi_color.x *= modif_power;
hemi_color.y *= modif_power;
hemi_color.z *= modif_power;
}

sun_color.lerp(A.sun_color, B.sun_color, f);
sun_color.lerp(A.sun_color, B.sun_color, f);

R_ASSERT(_valid(A.sun_dir));
R_ASSERT(_valid(B.sun_dir));
sun_dir.lerp(A.sun_dir, B.sun_dir, f).normalize();
R_ASSERT(_valid(sun_dir));
R_ASSERT(_valid(A.sun_dir));
R_ASSERT(_valid(B.sun_dir));
sun_dir.lerp(A.sun_dir, B.sun_dir, f).normalize();
R_ASSERT(_valid(sun_dir));

VERIFY2(sun_dir.y < 0, "Invalid sun direction settings while lerp");
VERIFY2(sun_dir.y < 0, "Invalid sun direction settings while lerp");
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 279c86f

Please sign in to comment.