Skip to content

Commit

Permalink
HLTV: Some fixes director part and small refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed May 13, 2017
1 parent 92b6fd6 commit 5981a4c
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 110 deletions.
109 changes: 56 additions & 53 deletions rehlds/HLTV/Console/src/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@

System gSystem;

#ifdef _WIN32
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
#else
int main(int argc, char *argv[])
#endif // _WIN32
int System::Run()
{
#ifdef _WIN32
gSystem.BuildCommandLine(lpCmdLine);
#else
gSystem.BuildCommandLine(argc, argv);
_snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]);
#endif // _WIN32

if (!gSystem.Init(&gSystem, 0, "Console"))
{
gSystem.Sleep(2000);
Expand Down Expand Up @@ -600,47 +589,6 @@ void System::ShutDown()
m_State = MODULE_DISCONNECTED;
}

#ifdef _WIN32

void System::BuildCommandLine(char *argv)
{
m_Parameters.SetLine(argv);
}

#else // _WIN32

#define MAX_LINUX_CMDLINE 2048

void System::BuildCommandLine(int argc, char **argv)
{
int len = 0;
char string[MAX_LINUX_CMDLINE];

for (int i = 1; i < argc && len < MAX_LINUX_CMDLINE; i++)
{
len += strlen(argv[i]) + 1;

if (i > 1) {
strcat(string, " ");
}

strcat(string, argv[i]);
}

m_Parameters.SetLine(string);
}

#endif // _WIN32

void System::Sleep(int msec)
{
#ifdef _WIN32
::Sleep(msec);
#else
usleep(1000 * msec);
#endif // _WIN32
}

bool System::InitFileSystem()
{
char *filesystemmodule = STDIO_FILESYSTEM_LIB;
Expand Down Expand Up @@ -1139,3 +1087,58 @@ unsigned char *System::LoadFile(const char *name, int *length)

return buf;
}

#ifdef _WIN32

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
gSystem.BuildCommandLine(lpCmdLine);
return gSystem.Run();
}

void System::BuildCommandLine(char *argv)
{
m_Parameters.SetLine(argv);
}

void System::Sleep(int msec)
{
::Sleep(msec);
}

#else // _WIN32

int main(int argc, char *argv[])
{
gSystem.BuildCommandLine(argc, argv);
_snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]);
return gSystem.Run();
}

#define MAX_LINUX_CMDLINE 2048

void System::BuildCommandLine(int argc, char **argv)
{
int len = 0;
char string[MAX_LINUX_CMDLINE];

for (int i = 1; i < argc && len < MAX_LINUX_CMDLINE; i++)
{
len += strlen(argv[i]) + 1;

if (i > 1) {
strcat(string, " ");
}

strcat(string, argv[i]);
}

m_Parameters.SetLine(string);
}

void System::Sleep(int msec)
{
usleep(1000 * msec);
}

#endif // _WIN32
6 changes: 2 additions & 4 deletions rehlds/HLTV/Console/src/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ class System: public IBaseSystem, public BaseSystemModule {
void ShutDown();
char *GetBaseDir();

#ifdef _WIN32
int Run();
void Sleep(int msec);
void BuildCommandLine(char *argv);
#else
void BuildCommandLine(int argc, char **argv);
#endif // _WIN32
void Sleep(int msec);

protected:
struct command_t {
Expand Down
43 changes: 24 additions & 19 deletions rehlds/HLTV/Core/src/BSPModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,35 +410,40 @@ bool BSPModel::InPVS(vec_t *point)
return false;
}

void BSPModel::Free(void *ptr)
{
if (ptr) {
Mem_Free(ptr);
}
}

void BSPModel::Clear()
{
#define FREE_FIELD(field) if (field) { Mem_Free(field); }
FREE_FIELD(m_model.leafs);
FREE_FIELD(m_model.nodes);
FREE_FIELD(m_model.planes);
FREE_FIELD(m_model.visdata);
FREE_FIELD(m_model.vertexes);
FREE_FIELD(m_model.entities);
FREE_FIELD(m_model.edges);
FREE_FIELD(m_model.lightdata);
FREE_FIELD(m_model.surfedges);
FREE_FIELD(m_model.surfaces);
FREE_FIELD(m_model.marksurfaces);
FREE_FIELD(m_model.clipnodes);
FREE_FIELD(m_model.hulls[0].clipnodes);
FREE_FIELD(m_model.texinfo);
Free(m_model.leafs);
Free(m_model.nodes);
Free(m_model.planes);
Free(m_model.visdata);
Free(m_model.vertexes);
Free(m_model.entities);
Free(m_model.edges);
Free(m_model.lightdata);
Free(m_model.surfedges);
Free(m_model.surfaces);
Free(m_model.marksurfaces);
Free(m_model.clipnodes);
Free(m_model.hulls[0].clipnodes);
Free(m_model.texinfo);

if (m_model.textures)
{
for (int i = 0; i < m_model.numtextures; ++i) {
FREE_FIELD(m_model.textures[i]);
Free(m_model.textures[i]);
}

FREE_FIELD(m_model.textures);
Free(m_model.textures);
}

FREE_FIELD(m_wadpath);
#undef FREE_FIELD
Free(m_wadpath);

memset(&m_model, 0, sizeof(m_model));

Expand Down
1 change: 1 addition & 0 deletions rehlds/HLTV/Core/src/BSPModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class BSPModel: public IBSPModel {
void DecompressPVS(unsigned char *in, unsigned char *decompressed, int byteCount);
unsigned char *DecompressVis(unsigned char *in);
void SetParent(mnode_t *node, mnode_t *parent);
void Free(void *ptr);

protected:
model_t m_model;
Expand Down
2 changes: 1 addition & 1 deletion rehlds/HLTV/Core/src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ char *World::GetStatusLine()
m_LevelName,
COM_FormatTime(m_WorldTime),
GetNumPlayers(),
(float)m_CacheHits / (float)(m_CacheHits + m_CacheFaults),
m_CacheHits / float(m_CacheHits + m_CacheFaults),
GetBufferedGameTime());
}
else
Expand Down
18 changes: 10 additions & 8 deletions rehlds/HLTV/Director/src/Director.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void Director::NewGame(IWorld *world, IProxy *proxy)
m_World = world;
m_Proxy = proxy;

world->RegisterListener(this);
m_World->RegisterListener(this);
m_WorldModel = m_World->GetWorldModel();

memset(m_history, 0, sizeof(*m_history) * m_historyLength);
Expand Down Expand Up @@ -203,7 +203,7 @@ void Director::AnalyseFrame(frame_t *frame)
return;
}

if (m_currentTime)
if (!m_currentTime)
{
m_nextCutTime = frame->time;
m_nextCutSeqnr = seqnr;
Expand All @@ -224,7 +224,7 @@ void Director::AnalyseFrame(frame_t *frame)
continue;
}

playerData_t *player = &now->players[i];
playerData_t *player = &now->players[index];
player->active = (ent->solid != SOLID_NOT);
if (player->active)
{
Expand Down Expand Up @@ -477,7 +477,7 @@ float Director::AddBestMODCut()

cmd = new DirectorCmd;
cmd->SetTimeScaleData(1.0);
cmd->SetTime(timepoint->time + 1.5f);
cmd->SetTime(timepoint->time + trailTime);
m_Commands.Add(cmd, cmd->GetTime());
}

Expand Down Expand Up @@ -642,7 +642,7 @@ void Director::ExecuteDirectorCommands()

if (timescale < 1.0)
{
vec3_t pos = { 0.02f, 0.85f, 0.f };
vec3_t pos = { 0.02f, 0.75f, 0.f };

DirectorCmd slowmo;
slowmo.SetMessageData(0, COM_PackRGBA(255, 160, 0, 255), pos, 0.3f, 0.1f, 2, 0, "Slow Motion");
Expand Down Expand Up @@ -685,12 +685,14 @@ void Director::CMD_SlowMotion(char *cmdLine)

Director::worldHistory_t *Director::FindBestEvent()
{
const int MAX_BEST_EVENT = 4;

This comment has been minimized.

Copy link
@WPMGPRoSToTeMa

WPMGPRoSToTeMa May 13, 2017

Contributor

I think constants now can be named as variables (because now we don't use macro for this). So, maxBestEvent or MaxBestEvent or may be maxBestEventCount? Or I didn't understand the logic of this constant.

This comment has been minimized.

Copy link
@LevShisterov

LevShisterov May 13, 2017

Collaborator

Better leave them capitalized, because it is easier to understand that this is const.


int i;
int nseqMod = m_nextCutSeqnr % m_historyLength;
int bestEvent[] = { 0, 0, 0, 0 };
int bestEventPrio[] = { 0, 0, 0, 0 };
int bestEvent[MAX_BEST_EVENT] = { 0, 0, 0, 0 };
int bestEventPrio[MAX_BEST_EVENT] = { 0, 0, 0, 0 };

for (i = 0; i < 4; i++)
for (i = 0; i < MAX_BEST_EVENT; i++)
{
bestEventPrio[i] = 0;
bestEvent[i] = 0;
Expand Down
4 changes: 2 additions & 2 deletions rehlds/HLTV/Director/src/Director.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class Director: public IDirector, public BaseSystemModule {
virtual void ShutDown();

virtual void NewGame(IWorld *world, IProxy *proxy);
virtual int AddCommand(DirectorCmd *cmd);
virtual void WriteCommands(BitBuffer *stream, float startTime, float endTime);
virtual char *GetModName();
virtual void WriteCommands(BitBuffer *stream, float startTime, float endTime);
virtual int AddCommand(DirectorCmd *cmd);
virtual bool RemoveCommand(int index);
virtual DirectorCmd *GetLastCommand();
virtual IObjectContainer *GetCommands();
Expand Down
1 change: 1 addition & 0 deletions rehlds/HLTV/Proxy/msvc/Proxy.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
<ClInclude Include="..\..\common\NetAddress.h" />
<ClInclude Include="..\..\common\net_internal.h" />
<ClInclude Include="..\..\common\random.h" />
<ClInclude Include="..\..\Director\src\Director.h" />
<ClInclude Include="..\src\DemoClient.h" />
<ClInclude Include="..\src\FakeClient.h" />
<ClInclude Include="..\src\Master.h" />
Expand Down
3 changes: 3 additions & 0 deletions rehlds/HLTV/Proxy/msvc/Proxy.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,8 @@
<ClInclude Include="..\..\..\engine\mem.h">
<Filter>engine</Filter>
</ClInclude>
<ClInclude Include="..\..\Director\src\Director.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
</Project>
9 changes: 5 additions & 4 deletions rehlds/HLTV/Proxy/src/DemoClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ class DemoClient: public IClient, public BaseSystemModule {
char *GetStatusLine();
char *GetType();
void ShutDown();

bool Connect(INetSocket *socket = nullptr, NetAddress *adr = nullptr, char *userinfo = "");
void Send(unsigned char *data, int length, bool isReliable);
void Disconnect(const char *reason);
void Reconnect();
void SetWorld(IWorld *world);
bool IsHearingVoices();
bool HasChatEnabled();
NetAddress *GetAddress();
int GetClientType();
char *GetClientName();
InfoString *GetUserInfo();
NetAddress *GetAddress();
bool IsActive();
void Send(unsigned char *data, int length, bool isReliable);
bool IsHearingVoices();
bool HasChatEnabled();

void SetProxy(IProxy *proxy);
void SetFileName(char *fileName);
Expand Down
10 changes: 5 additions & 5 deletions rehlds/HLTV/Proxy/src/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void Proxy::ReplyConnect(NetAddress *to, int protocol, int challenge, char *prot
if (type == TYPE_CLIENT && m_DispatchMode != DISPATCH_OFF)
{
float ratio = m_Status.GetBestRelayProxy(&relayProxy);
float myRatio = (float)(m_Clients.CountElements() / m_MaxClients) * 1.25f;
float myRatio = float(m_Clients.CountElements()) / float(m_MaxClients) * 1.25f;
if (myRatio > 1) {
myRatio = 1;
}
Expand Down Expand Up @@ -740,7 +740,7 @@ bool Proxy::WriteSignonData(int type, BitBuffer *stream)
stream->WriteString(COM_VarArgs("%s\n", m_SignonCommands));
}

float ex_interp = (float)(1 / GetMaxUpdateRate()) + 0.05f;
float ex_interp = (1.0f / GetMaxUpdateRate()) + 0.05f;
stream->WriteByte(svc_stufftext);
stream->WriteString(COM_VarArgs("ex_interp %.2f\n", ex_interp));

Expand Down Expand Up @@ -1811,7 +1811,7 @@ bool Proxy::CheckDirectorModule()
m_Director = dynamic_cast<IDirector *>(m_System->GetModule(DIRECTOR_INTERFACE_VERSION, szAbsoluteLibFilename, "director"));
if (m_Director)
{
m_System->Printf("Using extern director module (%s).\n", szAbsoluteLibFilename);
m_System->DPrintf("Using extern director module (%s).\n", szAbsoluteLibFilename);
return true;
}

Expand Down Expand Up @@ -2363,7 +2363,7 @@ double Proxy::GetProxyTime()
void Proxy::IncreaseCheering(int votes)
{
m_CheeringPlayers += votes;
float fraction = (float)(m_CheeringPlayers / m_Clients.CountElements());
float fraction = float(m_CheeringPlayers) / float(m_Clients.CountElements());
if (fraction > 1) {
fraction = 1;
}
Expand Down Expand Up @@ -2496,7 +2496,7 @@ void Proxy::SetClientTime(double time, bool relative)
void Proxy::SetClientTimeScale(float scale)
{
BitBuffer buf(32);
m_ClientTimeScale = clamp(scale, 4.0f, 0.5f);
m_ClientTimeScale = clamp(scale, 0.5f, 4.0f);

buf.WriteByte(svc_timescale);
buf.WriteFloat(m_ClientTimeScale);
Expand Down
2 changes: 1 addition & 1 deletion rehlds/HLTV/Proxy/src/ProxyClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IBaseSystem;

class ProxyClient: public BaseClient {
public:
ProxyClient(IProxy *proxy);
ProxyClient(IProxy *proxy = nullptr);
virtual ~ProxyClient() {}

bool Init(IBaseSystem *system, int serial, char *name);
Expand Down
Loading

0 comments on commit 5981a4c

Please sign in to comment.