Merge pull request #1002 from matricks/cleanup

Cleanup and bugfixes
This commit is contained in:
oy 2012-08-18 03:40:24 -07:00
commit 2c6b573217
21 changed files with 81 additions and 67 deletions

36
.gitignore vendored
View file

@ -1,24 +1,24 @@
bam /bam
.bam /.bam
config.lua /config.lua
objs /objs
__pycache__/ __pycache__/
*.pyc *.pyc
*.pyo *.pyo
scripts/work/ scripts/work/
src/game/generated/ src/game/generated/
SDL.dll /SDL.dll
freetype.dll /freetype.dll
autoexec.cfg /autoexec.cfg
crapnet* /crapnet*
dilate* /dilate*
fake_server* /fake_server*
map_resave* /map_resave*
map_version* /map_version*
mastersrv* /mastersrv*
packetgen* /packetgen*
teeworlds* /teeworlds*
teeworlds_srv* /teeworlds_srv*
tileset_border* /tileset_border*
versionsrv* /versionsrv*

View file

@ -80,7 +80,7 @@ void dbg_assert_imp(const char *filename, int line, int test, const char *msg)
void dbg_break() void dbg_break()
{ {
*((unsigned*)0) = 0x0; *((volatile unsigned*)0) = 0x0;
} }
void dbg_msg(const char *sys, const char *fmt, ...) void dbg_msg(const char *sys, const char *fmt, ...)
@ -166,6 +166,8 @@ void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned al
MEMTAIL *tail; MEMTAIL *tail;
MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL)); MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL));
dbg_assert(header != 0, "mem_alloc failure"); dbg_assert(header != 0, "mem_alloc failure");
if(!header)
return NULL;
tail = (struct MEMTAIL *)(((char*)(header+1))+size); tail = (struct MEMTAIL *)(((char*)(header+1))+size);
header->size = size; header->size = size;
header->filename = filename; header->filename = filename;

View file

@ -33,6 +33,13 @@ void dbg_assert(int test, const char *msg);
#define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg) #define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
void dbg_assert_imp(const char *filename, int line, int test, const char *msg); void dbg_assert_imp(const char *filename, int line, int test, const char *msg);
#ifdef __clang_analyzer__
#include <assert.h>
#undef dbg_assert
#define dbg_assert(test,msg) assert(test)
#endif
/* /*
Function: dbg_break Function: dbg_break
Breaks into the debugger. Breaks into the debugger.

View file

@ -154,7 +154,7 @@ public:
void pop_back() { tl_assert(!empty()); end--; } void pop_back() { tl_assert(!empty()); end--; }
T& front() { tl_assert(!empty()); return *begin; } T& front() { tl_assert(!empty()); return *begin; }
T& back() { tl_assert(!empty()); return *(end-1); } T& back() { tl_assert(!empty()); return *(end-1); }
T& index(unsigned i) { tl_assert(i >= 0 && i < (unsigned)(end-begin)); return begin[i]; } T& index(unsigned i) { tl_assert(i < (unsigned)(end-begin)); return begin[i]; }
unsigned size() const { return (unsigned)(end-begin); } unsigned size() const { return (unsigned)(end-begin); }
plain_range slice(unsigned startindex, unsigned endindex) plain_range slice(unsigned startindex, unsigned endindex)
{ {

View file

@ -1300,7 +1300,6 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
} }
// unpack delta // unpack delta
PurgeTick = DeltaTick;
SnapSize = m_SnapshotDelta.UnpackDelta(pDeltaShot, pTmpBuffer3, pDeltaData, DeltaSize); SnapSize = m_SnapshotDelta.UnpackDelta(pDeltaShot, pTmpBuffer3, pDeltaData, DeltaSize);
if(SnapSize < 0) if(SnapSize < 0)
{ {
@ -1339,7 +1338,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
if(m_aSnapshots[SNAP_PREV] && m_aSnapshots[SNAP_PREV]->m_Tick < PurgeTick) if(m_aSnapshots[SNAP_PREV] && m_aSnapshots[SNAP_PREV]->m_Tick < PurgeTick)
PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick;
if(m_aSnapshots[SNAP_CURRENT] && m_aSnapshots[SNAP_CURRENT]->m_Tick < PurgeTick) if(m_aSnapshots[SNAP_CURRENT] && m_aSnapshots[SNAP_CURRENT]->m_Tick < PurgeTick)
PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; PurgeTick = m_aSnapshots[SNAP_CURRENT]->m_Tick;
m_SnapshotStorage.PurgeUntil(PurgeTick); m_SnapshotStorage.PurgeUntil(PurgeTick);
// add new // add new

View file

@ -296,6 +296,8 @@ public:
INITFLAG_BORDERLESS = 8, INITFLAG_BORDERLESS = 8,
}; };
virtual ~IGraphicsBackend() {}
virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0; virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0;
virtual int Shutdown() = 0; virtual int Shutdown() = 0;

View file

@ -145,7 +145,7 @@ void CSnapIDPool::FreeID(int ID)
} }
void CServerBan::Init(IConsole *pConsole, IStorage *pStorage, CServer* pServer) void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer* pServer)
{ {
CNetBan::Init(pConsole, pStorage); CNetBan::Init(pConsole, pStorage);
@ -1609,7 +1609,7 @@ void CServer::RegisterCommands()
Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this); Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this);
// register console commands in sub parts // register console commands in sub parts
m_ServerBan.Init(Console(), Storage(), this); m_ServerBan.InitServerBan(Console(), Storage(), this);
m_pGameServer->OnConsoleInit(); m_pGameServer->OnConsoleInit();
} }

View file

@ -50,10 +50,10 @@ class CServerBan : public CNetBan
public: public:
class CServer *Server() const { return m_pServer; } class CServer *Server() const { return m_pServer; }
void Init(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer); void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer);
int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason);
int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason);
static void ConBanExt(class IConsole::IResult *pResult, void *pUser); static void ConBanExt(class IConsole::IResult *pResult, void *pUser);
}; };

View file

@ -16,21 +16,21 @@
const char *CConsole::CResult::GetString(unsigned Index) const char *CConsole::CResult::GetString(unsigned Index)
{ {
if (Index < 0 || Index >= m_NumArgs) if (Index >= m_NumArgs)
return ""; return "";
return m_apArgs[Index]; return m_apArgs[Index];
} }
int CConsole::CResult::GetInteger(unsigned Index) int CConsole::CResult::GetInteger(unsigned Index)
{ {
if (Index < 0 || Index >= m_NumArgs) if (Index >= m_NumArgs)
return 0; return 0;
return str_toint(m_apArgs[Index]); return str_toint(m_apArgs[Index]);
} }
float CConsole::CResult::GetFloat(unsigned Index) float CConsole::CResult::GetFloat(unsigned Index)
{ {
if (Index < 0 || Index >= m_NumArgs) if (Index >= m_NumArgs)
return 0.0f; return 0.0f;
return str_tofloat(m_apArgs[Index]); return str_tofloat(m_apArgs[Index]);
} }
@ -68,7 +68,7 @@ int CConsole::ParseStart(CResult *pResult, const char *pString, int Length)
if(Length < Len) if(Length < Len)
Len = Length; Len = Length;
str_copy(pResult->m_aStringStorage, pString, Length); str_copy(pResult->m_aStringStorage, pString, Len);
pStr = pResult->m_aStringStorage; pStr = pResult->m_aStringStorage;
// get command // get command

View file

@ -6,6 +6,7 @@
#include <engine/storage.h> #include <engine/storage.h>
#include <versionsrv/versionsrv.h> #include <versionsrv/versionsrv.h>
#include <versionsrv/mapversions.h>
#include "datafile.h" #include "datafile.h"
#include "memheap.h" #include "memheap.h"

View file

@ -170,7 +170,7 @@ public:
class IStorage *Storage() const { return m_pStorage; } class IStorage *Storage() const { return m_pStorage; }
virtual ~CNetBan() {} virtual ~CNetBan() {}
virtual void Init(class IConsole *pConsole, class IStorage *pStorage); void Init(class IConsole *pConsole, class IStorage *pStorage);
void Update(); void Update();
virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason);

View file

@ -195,13 +195,14 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
// fetch previous indices // fetch previous indices
// we do this as a separate pass because it helps the cache // we do this as a separate pass because it helps the cache
for(i = 0; i < pTo->NumItems(); i++) const int NumItems = pTo->NumItems();
for(i = 0; i < NumItems; i++)
{ {
pCurItem = pTo->GetItem(i); // O(1) .. O(n) pCurItem = pTo->GetItem(i); // O(1) .. O(n)
aPastIndecies[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n) aPastIndecies[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n)
} }
for(i = 0; i < pTo->NumItems(); i++) for(i = 0; i < NumItems; i++)
{ {
// do delta // do delta
ItemSize = pTo->GetItemSize(i); // O(1) .. O(n) ItemSize = pTo->GetItemSize(i); // O(1) .. O(n)
@ -474,7 +475,7 @@ int CSnapshotStorage::Get(int Tick, int64 *pTagtime, CSnapshot **ppData, CSnapsh
if(ppData) if(ppData)
*ppData = pHolder->m_pSnap; *ppData = pHolder->m_pSnap;
if(ppAltData) if(ppAltData)
*ppData = pHolder->m_pAltSnap; *ppAltData = pHolder->m_pAltSnap;
return pHolder->m_SnapSize; return pHolder->m_SnapSize;
} }

View file

@ -1287,7 +1287,7 @@ void CGameClient::SendStartInfo()
Msg.m_aUseCustomColors[p] = *gs_apUCCVariables[p]; Msg.m_aUseCustomColors[p] = *gs_apUCCVariables[p];
Msg.m_aSkinPartColors[p] = *gs_apColorVariables[p]; Msg.m_aSkinPartColors[p] = *gs_apColorVariables[p];
} }
Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); Client()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH);
} }
void CGameClient::SendKill() void CGameClient::SendKill()

View file

@ -2295,8 +2295,6 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN))
s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f);
} }
else
ScrollNum = 0;
} }
} }
@ -2619,8 +2617,6 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN))
s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f);
} }
else
ScrollNum = 0;
} }
} }

View file

@ -578,7 +578,6 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View)
{ {
if(pEditor->m_SelectedPoints&(1<<v)) if(pEditor->m_SelectedPoints&(1<<v))
{ {
Color = 0;
pQuad->m_aColors[v].r = (NewVal>>24)&0xff; pQuad->m_aColors[v].r = (NewVal>>24)&0xff;
pQuad->m_aColors[v].g = (NewVal>>16)&0xff; pQuad->m_aColors[v].g = (NewVal>>16)&0xff;
pQuad->m_aColors[v].b = (NewVal>>8)&0xff; pQuad->m_aColors[v].b = (NewVal>>8)&0xff;

View file

@ -680,11 +680,14 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgID, pUnpacker); void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgID, pUnpacker);
CPlayer *pPlayer = m_apPlayers[ClientID]; CPlayer *pPlayer = m_apPlayers[ClientID];
if(!pRawMsg && g_Config.m_Debug) if(!pRawMsg)
{
if(g_Config.m_Debug)
{ {
char aBuf[256]; char aBuf[256];
str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgID), MsgID, m_NetObjHandler.FailedMsgOn()); str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgID), MsgID, m_NetObjHandler.FailedMsgOn());
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf);
}
return; return;
} }
@ -1025,7 +1028,6 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
{ {
OptionMsg.m_NumOptions = NumOptions; OptionMsg.m_NumOptions = NumOptions;
Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID);
NumOptions = 0;
} }
// send tuning parameters to client // send tuning parameters to client

View file

@ -924,8 +924,8 @@ void IGameController::CycleMap()
pNextMap = pMapRotation; pNextMap = pMapRotation;
// cut out the next map // cut out the next map
char aBuf[512]; char aBuf[512] = {0};
for(int i = 0; i < 512; i++) for(int i = 0; i < 511; i++)
{ {
aBuf[i] = pNextMap[i]; aBuf[i] = pNextMap[i];
if(IsSeparator(pNextMap[i]) || pNextMap[i] == 0) if(IsSeparator(pNextMap[i]) || pNextMap[i] == 0)

View file

@ -21,7 +21,7 @@ CGameControllerCTF::CGameControllerCTF(CGameContext *pGameServer)
} }
// balancing // balancing
bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID) bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID) const
{ {
CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter(); CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter();
if(Character) if(Character)

View file

@ -8,7 +8,7 @@
class CGameControllerCTF : public IGameController class CGameControllerCTF : public IGameController
{ {
// balancing // balancing
virtual bool CanBeMovedOnBalance(int ClientID); virtual bool CanBeMovedOnBalance(int ClientID) const;
// game // game
class CFlag *m_apFlags[2]; class CFlag *m_apFlags[2];

View file

@ -0,0 +1,22 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#ifndef VERSIONSRV_MAPVERSIONS_H
#define VERSIONSRV_MAPVERSIONS_H
static CMapVersion s_aMapVersionList[] = {
{"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}},
{"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}},
{"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}},
{"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}},
{"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}},
{"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}},
{"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}},
{"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}},
{"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}},
{"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}},
{"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}},
{"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}},
{"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}},
};
static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion);
#endif

View file

@ -11,23 +11,6 @@ struct CMapVersion
unsigned char m_aSize[4]; unsigned char m_aSize[4];
}; };
static CMapVersion s_aMapVersionList[] = {
{"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}},
{"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}},
{"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}},
{"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}},
{"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}},
{"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}},
{"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}},
{"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}},
{"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}},
{"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}},
{"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}},
{"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}},
{"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}},
};
static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion);
static const unsigned char VERSIONSRV_GETVERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 'g'}; static const unsigned char VERSIONSRV_GETVERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 'g'};
static const unsigned char VERSIONSRV_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'}; static const unsigned char VERSIONSRV_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'};