Skip to content

Commit

Permalink
Common: Replace GetTickCount() on SDL analogue (fix Actor death)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Nov 6, 2018
1 parent f32fbe2 commit 9dae709
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 48 deletions.
9 changes: 0 additions & 9 deletions src/Common/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,3 @@
#include "Common/FSMacros.hpp"
#include "Include/xrAPI/xrAPI.h"

#if defined(WINDOWS)
#if __has_include("SDL.h")
#include "SDL.h"
#endif

#if __has_include("SDL_syswm.h")
#include "SDL_syswm.h"
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ void TransferCallback(GPConnection * connection, void * arg_, void * param)
switch(arg->type)
{
case GP_TRANSFER_SEND_REQUEST:
transferStart = GetTickCount();
transferStart = SDL_GetTicks();
CHECK(gpAcceptTransfer(connection, arg->transfer, "I'd like your file"));
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ time_t time(time_t *timer)
gsi_time current_time() //returns current time in milliseconds
{
#if defined(_WIN32)
return (GetTickCount());
return (SDL_GetTicks());

#elif defined(_PS2)
unsigned int ticks;
Expand Down Expand Up @@ -1800,7 +1800,7 @@ static void GenerateID(char *keyval)
seed = (l1.LowPart ^ l1.HighPart);
else
seed = 0;
Util_RandSeed(seed ^ GetTickCount() ^ (unsigned long)time(NULL) ^ clock());
Util_RandSeed(seed ^ SDL_GetTicks() ^ (unsigned long)time(NULL) ^ clock());
#else
Util_RandSeed(time(NULL) ^ clock());
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/xrCore/Threading/Event.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "xrCore/_types.h"

#include "SDL.h"

class XRCORE_API Event
{
void* handle;
Expand Down
6 changes: 2 additions & 4 deletions src/xrGame/Level_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,15 @@ bool CLevel::Connect2Server(const char* options)
if (psNET_direct_connect)
m_bConnectResultReceived = true;

#ifndef LINUX // FIXME!!!
u32 EndTime = GetTickCount() + ConnectionTimeOut;
u32 EndTime = SDL_GetTicks() + ConnectionTimeOut;
while (!m_bConnectResultReceived)
{
ClientReceive();
Sleep(5);
if (Server)
Server->Update();
//-----------------------------------------
u32 CurTime = GetTickCount();
u32 CurTime = SDL_GetTicks();
if (CurTime > EndTime)
{
NET_Packet P;
Expand All @@ -393,7 +392,6 @@ bool CLevel::Connect2Server(const char* options)
}
//-----------------------------------------
}
#endif
Msg("%c client : connection %s - <%s>", m_bConnectResult ? '*' : '!', m_bConnectResult ? "accepted" : "rejected",
m_sConnectResult.c_str());
if (!m_bConnectResult)
Expand Down
6 changes: 1 addition & 5 deletions src/xrGame/game_sv_deathmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ void game_sv_Deathmatch::Create(shared_str& options)

switch_Phase(GAME_PHASE_PENDING);

#ifdef LINUX // FIXME!!!
::Random.seed(0);
#else
::Random.seed(GetTickCount());
#endif
::Random.seed(SDL_GetTicks());
m_CorpseList.clear();

m_AnomaliesPermanent.clear();
Expand Down
24 changes: 7 additions & 17 deletions src/xrGame/game_sv_event_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

GameEventQueue::GameEventQueue() :
#ifdef CONFIG_PROFILE_LOCKS
pcs(new Lock(MUTEX_PROFILE_ID(GameEventQueue)))
pcs(new Lock(MUTEX_PROFILE_ID(GameEventQueue)))
#else
pcs(new Lock)
pcs(new Lock)
#endif // CONFIG_PROFILE_LOCKS
{
unused.reserve(128);
Expand Down Expand Up @@ -38,9 +38,7 @@ GameEvent* GameEventQueue::Create()
#ifdef _DEBUG
// Msg ("* GameEventQueue::Create - ready %d, unused %d", ready.size(), unused.size());
#endif
#ifndef LINUX // FIXME!!!
LastTimeCreate = GetTickCount();
#endif
LastTimeCreate = SDL_GetTicks();
//---------------------------------------------
}
else
Expand Down Expand Up @@ -74,16 +72,14 @@ GameEvent* GameEventQueue::Create(NET_Packet& P, u16 type, u32 time, ClientID cl
pcs->Enter();
if (unused.empty())
{
#ifndef LINUX // FIXME!!!
ready.push_back(new GameEvent());
ge = ready.back();
//---------------------------------------------
#ifdef _DEBUG
// Msg ("* GameEventQueue::Create - ready %d, unused %d", ready.size(), unused.size());
#endif
LastTimeCreate = GetTickCount();
LastTimeCreate = SDL_GetTicks();
//---------------------------------------------
#endif
}
else
{
Expand All @@ -108,8 +104,7 @@ GameEvent* GameEventQueue::Retreive()
//---------------------------------------------
else
{
#ifndef LINUX // FIXME!!
u32 tmp_time = GetTickCount() - 60000;
u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
if ((LastTimeCreate < tmp_time) && (size > 32))
{
Expand All @@ -119,7 +114,6 @@ GameEvent* GameEventQueue::Retreive()
// Msg ("GameEventQueue::Retreive - ready %d, unused %d", ready.size(), unused.size());
#endif
}
#endif
}
//---------------------------------------------
pcs->Leave();
Expand All @@ -131,8 +125,7 @@ void GameEventQueue::Release()
pcs->Enter();
R_ASSERT(!ready.empty());
//---------------------------------------------
#ifndef LINUX // FIXME!!!
u32 tmp_time = GetTickCount() - 60000;
u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
if ((LastTimeCreate < tmp_time) && (size > 32))
{
Expand All @@ -143,7 +136,6 @@ void GameEventQueue::Release()
}
else
unused.push_back(ready.front());
#endif
//---------------------------------------------
ready.pop_front();
pcs->Leave();
Expand Down Expand Up @@ -183,8 +175,7 @@ u32 GameEventQueue::EraseEvents(event_predicate to_del)
while (need_to_erase != ready.end())
{
//-----
#ifndef LINUX // FIXME!!!
u32 tmp_time = GetTickCount() - 60000;
u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
if ((LastTimeCreate < tmp_time) && (size > 32))
{
Expand All @@ -197,7 +188,6 @@ u32 GameEventQueue::EraseEvents(event_predicate to_del)
{
unused.push_back(*need_to_erase);
}
#endif
//-----
#ifdef DEBUG
Msg("! GameEventQueue::EraseEvents - destroying event type[%d], sender[0x%08x]", (*need_to_erase)->type,
Expand Down
2 changes: 0 additions & 2 deletions src/xrGameSpy/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include "Common/Common.hpp"
#include "xrCore/xrCore.h"

#ifdef LINUX
#include "SDL.h"
#endif

#include <GameSpy/common/gsCommon.h>
#include <GameSpy/common/gsAvailable.h>
Expand Down
8 changes: 4 additions & 4 deletions src/xrNetServer/NET_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ NET_Packet* INetQueue::Create()
ready.push_back(new NET_Packet());
P = ready.back();
//---------------------------------------------
LastTimeCreate = GetTickCount();
LastTimeCreate = SDL_GetTicks();
//---------------------------------------------
}
else
Expand All @@ -157,7 +157,7 @@ NET_Packet* INetQueue::Create(const NET_Packet& _other)
ready.push_back(new NET_Packet());
P = ready.back();
//---------------------------------------------
LastTimeCreate = GetTickCount();
LastTimeCreate = SDL_GetTicks();
//---------------------------------------------
}
else
Expand All @@ -183,7 +183,7 @@ NET_Packet* INetQueue::Retreive()
//---------------------------------------------
else
{
u32 tmp_time = GetTickCount() - 60000;
u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
if ((LastTimeCreate < tmp_time) && (size > 32))
{
Expand All @@ -204,7 +204,7 @@ void INetQueue::Release()
//#endif
VERIFY(!ready.empty());
//---------------------------------------------
u32 tmp_time = GetTickCount() - 60000;
u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
ready.front()->B.count = 0;
if ((LastTimeCreate < tmp_time) && (size > 32))
Expand Down
8 changes: 4 additions & 4 deletions src/xrNetServer/empty/NET_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ NET_Packet* INetQueue::Create()
ready.push_back(new NET_Packet());
P = ready.back();
//---------------------------------------------
// LastTimeCreate = GetTickCount();
// LastTimeCreate = SDL_GetTicks();
//---------------------------------------------
} else {
ready.push_back(unused.back());
Expand All @@ -66,7 +66,7 @@ NET_Packet* INetQueue::Create(const NET_Packet& _other)
ready.push_back(new NET_Packet());
P = ready.back();
//---------------------------------------------
// LastTimeCreate = GetTickCount();
// LastTimeCreate = SDL_GetTicks();
//---------------------------------------------
} else {
ready.push_back(unused.back());
Expand All @@ -87,7 +87,7 @@ NET_Packet* INetQueue::Retreive()
//---------------------------------------------
else {
/*
u32 tmp_time = GetTickCount() - 60000;
u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
if ((LastTimeCreate < tmp_time) && (size > 32))
{
Expand All @@ -104,7 +104,7 @@ void INetQueue::Release()
{
VERIFY(!ready.empty());
//---------------------------------------------
// u32 tmp_time = GetTickCount() - 60000;
// u32 tmp_time = SDL_GetTicks() - 60000;
u32 size = unused.size();
ready.front()->B.count = 0;
/*
Expand Down

0 comments on commit 9dae709

Please sign in to comment.