From b4ed006f836e8b15f27352a8403b7cdeb7576c5b Mon Sep 17 00:00:00 2001 From: Teetime Date: Mon, 13 Feb 2012 23:22:40 +0100 Subject: fix for saving bans in a file --- src/engine/shared/netban.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/shared/netban.cpp b/src/engine/shared/netban.cpp index ee3b057e..d26d64d4 100644 --- a/src/engine/shared/netban.cpp +++ b/src/engine/shared/netban.cpp @@ -583,7 +583,7 @@ void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser) { int Min = pBan->m_Info.m_Expires>-1 ? (pBan->m_Info.m_Expires-Now+59)/60 : -1; net_addr_str(&pBan->m_Data, aAddrStr1, sizeof(aAddrStr1), false); - str_format(aBuf, sizeof(aBuf), "ban_ip %s %i %s", aAddrStr1, Min, pBan->m_Info.m_aReason); + str_format(aBuf, sizeof(aBuf), "ban %s %i %s", aAddrStr1, Min, pBan->m_Info.m_aReason); io_write(File, aBuf, str_length(aBuf)); io_write_newline(File); } @@ -592,7 +592,7 @@ void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser) int Min = pBan->m_Info.m_Expires>-1 ? (pBan->m_Info.m_Expires-Now+59)/60 : -1; net_addr_str(&pBan->m_Data.m_LB, aAddrStr1, sizeof(aAddrStr1), false); net_addr_str(&pBan->m_Data.m_UB, aAddrStr2, sizeof(aAddrStr2), false); - str_format(aBuf, sizeof(aBuf), "ban_range %s %i %s", aAddrStr1, aAddrStr2, Min, pBan->m_Info.m_aReason); + str_format(aBuf, sizeof(aBuf), "ban_range %s %s %i %s", aAddrStr1, aAddrStr2, Min, pBan->m_Info.m_aReason); io_write(File, aBuf, str_length(aBuf)); io_write_newline(File); } -- cgit 1.4.1 From 38256d0d45ff929796cc85d0dfcb39242290f3ba Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 4 Mar 2012 12:46:46 +0100 Subject: skip screenshot when window isn't active. Closes #931 --- src/engine/client/graphics.cpp | 3 ++- src/engine/client/graphics_threaded.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 2111703e..ae0fcade 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -929,7 +929,8 @@ void CGraphics_SDL::Swap() { if(m_DoScreenshot) { - ScreenshotDirect(m_aScreenshotName); + if(WindowActive()) + ScreenshotDirect(m_aScreenshotName); m_DoScreenshot = false; } diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index b19e8a83..846f0369 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -843,7 +843,8 @@ void CGraphics_Threaded::Swap() // TODO: screenshot support if(m_DoScreenshot) { - ScreenshotDirect(m_aScreenshotName); + if(WindowActive()) + ScreenshotDirect(m_aScreenshotName); m_DoScreenshot = false; } -- cgit 1.4.1 From 2a4af1573b385f1c30ce376eee1385581d42beab Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 4 Mar 2012 12:46:55 +0100 Subject: auto adjust the screen resolution on first start. Closes #921 --- src/engine/client/backend_sdl.cpp | 11 +++++++++-- src/engine/client/backend_sdl.h | 2 +- src/engine/client/graphics.cpp | 13 ++++++++++--- src/engine/client/graphics_threaded.cpp | 2 +- src/engine/client/graphics_threaded.h | 2 +- src/engine/shared/config_variables.h | 4 ++-- 6 files changed, 24 insertions(+), 10 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index e7975aca..b04b729e 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -388,7 +388,7 @@ void CCommandProcessor_SDL_OpenGL::RunBuffer(CCommandBuffer *pBuffer) // ------------ CGraphicsBackend_SDL_OpenGL -int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Width, int Height, int FsaaSamples, int Flags) +int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) { if(!SDL_WasInit(SDL_INIT_VIDEO)) { @@ -407,6 +407,13 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Width, int Height, const SDL_VideoInfo *pInfo = SDL_GetVideoInfo(); SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows + // use current resolution as default + if(*Width == 0 || *Height == 0) + { + *Width = pInfo->current_w; + *Height = pInfo->current_h; + } + // set flags int SdlFlags = SDL_OPENGL; if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE) @@ -442,7 +449,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Width, int Height, SDL_WM_SetCaption(pName, pName); // create window - m_pScreenSurface = SDL_SetVideoMode(Width, Height, 0, SdlFlags); + m_pScreenSurface = SDL_SetVideoMode(*Width, *Height, 0, SdlFlags); if(!m_pScreenSurface) { dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError()); diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index c6c2255a..305453f2 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -188,7 +188,7 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded ICommandProcessor *m_pProcessor; SGLContext m_GLContext; public: - virtual int Init(const char *pName, int Width, int Height, int FsaaSamples, int Flags); + virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags); virtual int Shutdown(); virtual void Minimize(); diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index ae0fcade..bf432356 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -761,12 +761,19 @@ int CGraphics_OpenGL::Init() int CGraphics_SDL::TryInit() { - m_ScreenWidth = g_Config.m_GfxScreenWidth; - m_ScreenHeight = g_Config.m_GfxScreenHeight; - const SDL_VideoInfo *pInfo = SDL_GetVideoInfo(); SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows + // use current resolution as default + if(g_Config.m_GfxScreenWidth == 0 || g_Config.m_GfxScreenHeight == 0) + { + g_Config.m_GfxScreenWidth = pInfo->current_w; + g_Config.m_GfxScreenHeight = pInfo->current_h; + } + + m_ScreenWidth = g_Config.m_GfxScreenWidth; + m_ScreenHeight = g_Config.m_GfxScreenHeight; + // set flags int Flags = SDL_OPENGL; if(g_Config.m_DbgResizable) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 846f0369..0c99ebf7 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -716,7 +716,7 @@ int CGraphics_Threaded::IssueInit() if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC; if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE; - return m_pBackend->Init("Teeworlds", g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags); + return m_pBackend->Init("Teeworlds", &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags); } int CGraphics_Threaded::InitWindow() diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index f90f818d..d3ccc61e 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -302,7 +302,7 @@ public: INITFLAG_RESIZABLE = 4, }; - 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 void Minimize() = 0; diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index ac913162..2bee031d 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -57,8 +57,8 @@ MACRO_CONFIG_INT(SndDevice, snd_device, -1, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, " MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 800, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width") -MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 600, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height") +MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width") +MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height") MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen") MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)") MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)") -- cgit 1.4.1 From fa85cede5336c399f9b12efde169bad6f6842d8d Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 4 Mar 2012 12:47:02 +0100 Subject: reset rcon AuthTries on logout. Closes #941 --- src/engine/server/server.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/engine') diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index a231d1e8..f7b54df5 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1544,6 +1544,7 @@ void CServer::ConLogout(IConsole::IResult *pResult, void *pUser) pServer->SendMsgEx(&Msg, MSGFLAG_VITAL, pServer->m_RconClientID, true); pServer->m_aClients[pServer->m_RconClientID].m_Authed = AUTHED_NO; + pServer->m_aClients[pServer->m_RconClientID].m_AuthTries = 0; pServer->m_aClients[pServer->m_RconClientID].m_pRconCmdToSend = 0; pServer->SendRconLine(pServer->m_RconClientID, "Logout successful."); char aBuf[32]; -- cgit 1.4.1 From ffd89938d7caebe2ecd7bf18d00283e6aadea981 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 4 Mar 2012 12:47:09 +0100 Subject: fixed registering of ban commands. Closes #942 --- src/engine/server/server.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/engine') diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index f7b54df5..34eaddc4 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1255,10 +1255,6 @@ void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterS int CServer::Run() { - m_pGameServer = Kernel()->RequestInterface(); - m_pMap = Kernel()->RequestInterface(); - m_pStorage = Kernel()->RequestInterface(); - // m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_ConsoleOutputLevel, SendRconLineAuthed, this); @@ -1291,7 +1287,6 @@ int CServer::Run() m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this); - m_ServerBan.Init(Console(), Storage(), this); m_Econ.Init(Console(), &m_ServerBan); char aBuf[256]; @@ -1609,7 +1604,11 @@ void CServer::ConchainConsoleOutputLevelUpdate(IConsole::IResult *pResult, void void CServer::RegisterCommands() { m_pConsole = Kernel()->RequestInterface(); + m_pGameServer = Kernel()->RequestInterface(); + m_pMap = Kernel()->RequestInterface(); + m_pStorage = Kernel()->RequestInterface(); + // register console commands Console()->Register("kick", "i?r", CFGFLAG_SERVER, ConKick, this, "Kick player with specified id for any reason"); Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "List players"); Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "Shut down"); @@ -1626,6 +1625,10 @@ void CServer::RegisterCommands() Console()->Chain("sv_max_clients_per_ip", ConchainMaxclientsperipUpdate, this); Console()->Chain("mod_command", ConchainModCommandUpdate, this); Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this); + + // register console commands in sub parts + m_ServerBan.Init(Console(), Storage(), this); + m_pGameServer->OnConsoleInit(); } @@ -1706,7 +1709,6 @@ int main(int argc, const char **argv) // ignore_convention // register all console commands pServer->RegisterCommands(); - pGameServer->OnConsoleInit(); // execute autoexec file pConsole->ExecuteFile("autoexec.cfg"); -- cgit 1.4.1 From 13d06e45ac14d5f584462d0611f85a4e1dafcf17 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 4 Mar 2012 12:47:16 +0100 Subject: fixed used nettype in server browser and try to use ipv4 and ipv6 socket when using a bindaddr. Closes #940 --- src/engine/client/client.cpp | 9 +++++++-- src/engine/client/serverbrowser.cpp | 2 +- src/engine/server/server.cpp | 1 + src/engine/shared/econ.cpp | 4 ++++ src/engine/shared/network.h | 2 +- src/mastersrv/mastersrv.cpp | 4 ++++ 6 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index d5da647b..6d1d8f4f 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1746,14 +1746,19 @@ void CClient::Run() // open socket { NETADDR BindAddr; - if(g_Config.m_Bindaddr[0] == 0 || net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) != 0) + if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) + { + // got bindaddr + BindAddr.type = NETTYPE_ALL; + } + else { mem_zero(&BindAddr, sizeof(BindAddr)); BindAddr.type = NETTYPE_ALL; } if(!m_NetClient.Open(BindAddr, 0)) { - dbg_msg("client", "couldn't start network"); + dbg_msg("client", "couldn't open socket"); return; } } diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 4dda9da9..588194ea 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -495,7 +495,7 @@ void CServerBrowser::Refresh(int Type) /* do the broadcast version */ Packet.m_ClientID = -1; mem_zero(&Packet, sizeof(Packet)); - Packet.m_Address.type = NETTYPE_ALL|NETTYPE_LINK_BROADCAST; + Packet.m_Address.type = m_pNetClient->NetType()|NETTYPE_LINK_BROADCAST; Packet.m_Flags = NETSENDFLAG_CONNLESS; Packet.m_DataSize = sizeof(Buffer); Packet.m_pData = Buffer; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 34eaddc4..704d4e37 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1270,6 +1270,7 @@ int CServer::Run() if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) { // sweet! + BindAddr.type = NETTYPE_ALL; BindAddr.port = g_Config.m_SvPort; } else diff --git a/src/engine/shared/econ.cpp b/src/engine/shared/econ.cpp index eb7df872..e0df8635 100644 --- a/src/engine/shared/econ.cpp +++ b/src/engine/shared/econ.cpp @@ -75,7 +75,11 @@ void CEcon::Init(IConsole *pConsole, CNetBan *pNetBan) NETADDR BindAddr; if(g_Config.m_EcBindaddr[0] && net_host_lookup(g_Config.m_EcBindaddr, &BindAddr, NETTYPE_ALL) == 0) + { + // got bindaddr + BindAddr.type = NETTYPE_ALL; BindAddr.port = g_Config.m_EcPort; + } else { mem_zero(&BindAddr, sizeof(BindAddr)); diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index dd43389e..d633c3fc 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -353,7 +353,7 @@ public: int ResetErrorString(); // error and state - int NetType() { return m_Socket.type; } + int NetType() const { return m_Socket.type; } int State(); int GotProblems(); const char *ErrorString(); diff --git a/src/mastersrv/mastersrv.cpp b/src/mastersrv/mastersrv.cpp index c88a9e78..922577ca 100644 --- a/src/mastersrv/mastersrv.cpp +++ b/src/mastersrv/mastersrv.cpp @@ -348,7 +348,11 @@ int main(int argc, const char **argv) // ignore_convention m_pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) + { + // got bindaddr + BindAddr.type = NETTYPE_ALL; BindAddr.port = MASTERSERVER_PORT; + } else { mem_zero(&BindAddr, sizeof(BindAddr)); -- cgit 1.4.1 From 0e40ab434a2416b685027f401251b28b0e935efc Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 24 Feb 2013 17:31:57 +0100 Subject: fixed a check --- src/engine/shared/netban.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/engine') diff --git a/src/engine/shared/netban.cpp b/src/engine/shared/netban.cpp index d26d64d4..707b709b 100644 --- a/src/engine/shared/netban.cpp +++ b/src/engine/shared/netban.cpp @@ -243,7 +243,7 @@ typename CNetBan::CBan *CNetBan::CBanPool::Get(int Index) const template void CNetBan::MakeBanInfo(const CBan *pBan, char *pBuf, unsigned BuffSize, int Type) const { - if(pBan == 0) + if(pBan == 0 || pBuf == 0) { if(BuffSize > 0) pBuf[0] = 0; -- cgit 1.4.1 From f1fc3337f5cc5ac3b89da80a1fdff5251f130cb5 Mon Sep 17 00:00:00 2001 From: oy Date: Fri, 20 Apr 2012 21:39:49 +0200 Subject: prevent that the server uses close messages from clients. Closes #950 --- src/engine/shared/network.h | 3 ++- src/engine/shared/network_client.cpp | 2 +- src/engine/shared/network_conn.cpp | 30 +++++++++++++++++------------- src/engine/shared/network_server.cpp | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src/engine') diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index d633c3fc..fbe4d391 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -140,6 +140,7 @@ private: int m_Token; int m_RemoteClosed; + bool m_BlockCloseMsg; TStaticRingBuffer m_Buffer; @@ -167,7 +168,7 @@ private: void Resend(); public: - void Init(NETSOCKET Socket); + void Init(NETSOCKET Socket, bool BlockCloseMsg); int Connect(NETADDR *pAddr); void Disconnect(const char *pReason); diff --git a/src/engine/shared/network_client.cpp b/src/engine/shared/network_client.cpp index 2c035606..8e0e2910 100644 --- a/src/engine/shared/network_client.cpp +++ b/src/engine/shared/network_client.cpp @@ -16,7 +16,7 @@ bool CNetClient::Open(NETADDR BindAddr, int Flags) // init m_Socket = Socket; - m_Connection.Init(m_Socket); + m_Connection.Init(m_Socket, false); return true; } diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index 6531f5aa..32fa159f 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -37,12 +37,13 @@ void CNetConnection::SetError(const char *pString) str_copy(m_ErrorString, pString, sizeof(m_ErrorString)); } -void CNetConnection::Init(NETSOCKET Socket) +void CNetConnection::Init(NETSOCKET Socket, bool BlockCloseMsg) { Reset(); ResetStats(); m_Socket = Socket; + m_BlockCloseMsg = BlockCloseMsg; mem_zero(m_ErrorString, sizeof(m_ErrorString)); } @@ -213,21 +214,24 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr) m_State = NET_CONNSTATE_ERROR; m_RemoteClosed = 1; - if(pPacket->m_DataSize) + if(!m_BlockCloseMsg) { - // make sure to sanitize the error string form the other party - char Str[128]; - if(pPacket->m_DataSize < 128) - str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize); + if(pPacket->m_DataSize) + { + // make sure to sanitize the error string form the other party + char Str[128]; + if(pPacket->m_DataSize < 128) + str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize); + else + str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str)); + str_sanitize_strong(Str); + + // set the error string + SetError(Str); + } else - str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str)); - str_sanitize_strong(Str); - - // set the error string - SetError(Str); + SetError("No reason given"); } - else - SetError("No reason given"); if(g_Config.m_Debug) dbg_msg("conn", "closed reason='%s'", ErrorString()); diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 1264a4a5..add51c9b 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -30,7 +30,7 @@ bool CNetServer::Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int Ma m_MaxClientsPerIP = MaxClientsPerIP; for(int i = 0; i < NET_MAX_CLIENTS; i++) - m_aSlots[i].m_Connection.Init(m_Socket); + m_aSlots[i].m_Connection.Init(m_Socket, true); return true; } -- cgit 1.4.1 From 14cd83de10e5725db6f159a9cfe8d0c8d7bd9b59 Mon Sep 17 00:00:00 2001 From: oy Date: Fri, 20 Apr 2012 22:20:11 +0200 Subject: fixed ban range check to make sure the whole ip matches and not just rely on the hash. Closes #946 --- src/engine/shared/netban.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/engine') diff --git a/src/engine/shared/netban.h b/src/engine/shared/netban.h index 447a838d..6d690164 100644 --- a/src/engine/shared/netban.h +++ b/src/engine/shared/netban.h @@ -34,7 +34,7 @@ protected: bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr, int Start, int Length) const { - return pRange->m_LB.type == pAddr->type && + return pRange->m_LB.type == pAddr->type && (Start == 0 || mem_comp(&pRange->m_LB.ip[0], &pAddr->ip[0], Start) == 0) && mem_comp(&pRange->m_LB.ip[Start], &pAddr->ip[Start], Length-Start) <= 0 && mem_comp(&pRange->m_UB.ip[Start], &pAddr->ip[Start], Length-Start) >= 0; } -- cgit 1.4.1 From 86cd0cefd7cdefd7443cb9602b3c834fa85134e1 Mon Sep 17 00:00:00 2001 From: oy Date: Sat, 21 Apr 2012 00:23:48 +0200 Subject: fixed wrapping problems when rendering console input --- src/engine/client/text.cpp | 2 +- src/game/client/components/console.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index af06fc11..d838ef29 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -639,7 +639,7 @@ public: Compare.m_Y = DrawY; Compare.m_Flags &= ~TEXTFLAG_RENDER; Compare.m_LineWidth = -1; - TextEx(&Compare, pText, Wlen); + TextEx(&Compare, pCurrent, Wlen); if(Compare.m_X-DrawX > pCursor->m_LineWidth) { diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index d16d56cd..01bf5351 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -434,12 +434,6 @@ void CGameConsole::OnRender() x = Cursor.m_X; - // render console input (wrap line) - int Lines = TextRender()->TextLineCount(0, FontSize, pConsole->m_Input.GetString(), Screen.w - 10.0f - x); - y -= (Lines - 1) * FontSize; - TextRender()->SetCursor(&Cursor, x, y, FontSize, TEXTFLAG_RENDER); - Cursor.m_LineWidth = Screen.w - 10.0f - x; - //hide rcon password char aInputString[256]; str_copy(aInputString, pConsole->m_Input.GetString(), sizeof(aInputString)); @@ -449,10 +443,22 @@ void CGameConsole::OnRender() aInputString[i] = '*'; } + // render console input (wrap line) + TextRender()->SetCursor(&Cursor, x, y, FontSize, 0); + Cursor.m_LineWidth = Screen.w - 10.0f - x; + TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset()); + TextRender()->TextEx(&Cursor, aInputString+pConsole->m_Input.GetCursorOffset(), -1); + int Lines = Cursor.m_LineCount; + + y -= (Lines - 1) * FontSize; + TextRender()->SetCursor(&Cursor, x, y, FontSize, TEXTFLAG_RENDER); + Cursor.m_LineWidth = Screen.w - 10.0f - x; + TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset()); static float MarkerOffset = TextRender()->TextWidth(0, FontSize, "|", -1)/3; CTextCursor Marker = Cursor; Marker.m_X -= MarkerOffset; + Marker.m_LineWidth = -1; TextRender()->TextEx(&Marker, "|", -1); TextRender()->TextEx(&Cursor, aInputString+pConsole->m_Input.GetCursorOffset(), -1); -- cgit 1.4.1 From 7be3c2e634b04008c1df3b9ee04c09a13f753794 Mon Sep 17 00:00:00 2001 From: oy Date: Sat, 21 Apr 2012 18:20:41 +0200 Subject: fixed resetting the error string of a net connection. Closes #954 --- src/engine/shared/network_conn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index 32fa159f..6a63f82d 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -25,6 +25,8 @@ void CNetConnection::Reset() m_Buffer.Init(); mem_zero(&m_Construct, sizeof(m_Construct)); + + mem_zero(m_ErrorString, sizeof(m_ErrorString)); } const char *CNetConnection::ErrorString() @@ -44,7 +46,6 @@ void CNetConnection::Init(NETSOCKET Socket, bool BlockCloseMsg) m_Socket = Socket; m_BlockCloseMsg = BlockCloseMsg; - mem_zero(m_ErrorString, sizeof(m_ErrorString)); } void CNetConnection::AckChunks(int Ack) @@ -168,7 +169,6 @@ int CNetConnection::Connect(NETADDR *pAddr) // init connection Reset(); m_PeerAddr = *pAddr; - mem_zero(m_ErrorString, sizeof(m_ErrorString)); m_State = NET_CONNSTATE_CONNECT; SendControl(NET_CTRLMSG_CONNECT, 0, 0); return 0; -- cgit 1.4.1 From b7e5bb54ad77545ae139115a1a64f9ebb7160006 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 10 Jun 2012 12:14:41 +0200 Subject: fixed semaphore on macosx --- src/base/system.c | 26 ++++++++++++++------------ src/base/system.h | 26 ++++++++++++++------------ src/base/tl/threading.h | 24 +++++++++++++++--------- src/engine/client/backend_sdl.h | 10 ++++++++++ src/engine/client/client.h | 2 -- src/engine/client/graphics.cpp | 14 ++++++++++++++ 6 files changed, 67 insertions(+), 35 deletions(-) (limited to 'src/engine') diff --git a/src/base/system.c b/src/base/system.c index 7f98efe1..1c4d3a48 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -505,18 +505,20 @@ void lock_release(LOCK lock) #endif } -#if defined(CONF_FAMILY_UNIX) -void semaphore_init(SEMAPHORE *sem) { sem_init(sem, 0, 0); } -void semaphore_wait(SEMAPHORE *sem) { sem_wait(sem); } -void semaphore_signal(SEMAPHORE *sem) { sem_post(sem); } -void semaphore_destroy(SEMAPHORE *sem) { sem_destroy(sem); } -#elif defined(CONF_FAMILY_WINDOWS) -void semaphore_init(SEMAPHORE *sem) { *sem = CreateSemaphore(0, 0, 10000, 0); } -void semaphore_wait(SEMAPHORE *sem) { WaitForSingleObject((HANDLE)*sem, 0L); } -void semaphore_signal(SEMAPHORE *sem) { ReleaseSemaphore((HANDLE)*sem, 1, NULL); } -void semaphore_destroy(SEMAPHORE *sem) { CloseHandle((HANDLE)*sem); } -#else - #error not implemented on this platform +#if !defined(CONF_PLATFORM_MACOSX) + #if defined(CONF_FAMILY_UNIX) + void semaphore_init(SEMAPHORE *sem) { sem_init(sem, 0, 0); } + void semaphore_wait(SEMAPHORE *sem) { sem_wait(sem); } + void semaphore_signal(SEMAPHORE *sem) { sem_post(sem); } + void semaphore_destroy(SEMAPHORE *sem) { sem_destroy(sem); } + #elif defined(CONF_FAMILY_WINDOWS) + void semaphore_init(SEMAPHORE *sem) { *sem = CreateSemaphore(0, 0, 10000, 0); } + void semaphore_wait(SEMAPHORE *sem) { WaitForSingleObject((HANDLE)*sem, 0L); } + void semaphore_signal(SEMAPHORE *sem) { ReleaseSemaphore((HANDLE)*sem, 1, NULL); } + void semaphore_destroy(SEMAPHORE *sem) { CloseHandle((HANDLE)*sem); } + #else + #error not implemented on this platform + #endif #endif diff --git a/src/base/system.h b/src/base/system.h index b3588dbf..032cf785 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -403,20 +403,22 @@ void lock_release(LOCK lock); /* Group: Semaphores */ -#if defined(CONF_FAMILY_UNIX) - #include - typedef sem_t SEMAPHORE; -#elif defined(CONF_FAMILY_WINDOWS) - typedef void* SEMAPHORE; -#else - #error missing sempahore implementation +#if !defined(CONF_PLATFORM_MACOSX) + #if defined(CONF_FAMILY_UNIX) + #include + typedef sem_t SEMAPHORE; + #elif defined(CONF_FAMILY_WINDOWS) + typedef void* SEMAPHORE; + #else + #error missing sempahore implementation + #endif + + void semaphore_init(SEMAPHORE *sem); + void semaphore_wait(SEMAPHORE *sem); + void semaphore_signal(SEMAPHORE *sem); + void semaphore_destroy(SEMAPHORE *sem); #endif -void semaphore_init(SEMAPHORE *sem); -void semaphore_wait(SEMAPHORE *sem); -void semaphore_signal(SEMAPHORE *sem); -void semaphore_destroy(SEMAPHORE *sem); - /* Group: Timer */ #ifdef __GNUC__ /* if compiled with -pedantic-errors it will complain about long diff --git a/src/base/tl/threading.h b/src/base/tl/threading.h index dbf788cd..5caf8588 100644 --- a/src/base/tl/threading.h +++ b/src/base/tl/threading.h @@ -58,15 +58,21 @@ #error missing atomic implementation for this compiler #endif -class semaphore -{ - SEMAPHORE sem; -public: - semaphore() { semaphore_init(&sem); } - ~semaphore() { semaphore_destroy(&sem); } - void wait() { semaphore_wait(&sem); } - void signal() { semaphore_signal(&sem); } -}; +#if defined(CONF_PLATFORM_MACOSX) + /* + use semaphore provided by SDL on macosx + */ +#else + class semaphore + { + SEMAPHORE sem; + public: + semaphore() { semaphore_init(&sem); } + ~semaphore() { semaphore_destroy(&sem); } + void wait() { semaphore_wait(&sem); } + void signal() { semaphore_signal(&sem); } + }; +#endif class lock { diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index 305453f2..2ef04a1f 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -30,6 +30,16 @@ #include + class semaphore + { + SDL_sem *sem; + public: + semaphore() { sem = SDL_CreateSemaphore(0); } + ~semaphore() { SDL_DestroySemaphore(sem); } + void wait() { SDL_SemWait(sem); } + void signal() { SDL_SemPost(sem); } + }; + struct SGLContext { AGLContext m_Context; diff --git a/src/engine/client/client.h b/src/engine/client/client.h index d958b49a..87e2bc70 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -175,8 +175,6 @@ class CClient : public IClient, public CDemoPlayer::IListner class CHostLookup m_VersionServeraddr; } m_VersionInfo; - semaphore m_GfxRenderSemaphore; - semaphore m_GfxStateSemaphore; volatile int m_GfxState; static void GraphicsThreadProxy(void *pThis) { ((CClient*)pThis)->GraphicsThread(); } void GraphicsThread(); diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index bf432356..8816e1ed 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -22,6 +22,20 @@ #include "graphics.h" +#if defined(CONF_PLATFORM_MACOSX) + + class semaphore + { + SDL_sem *sem; + public: + semaphore() { sem = SDL_CreateSemaphore(0); } + ~semaphore() { SDL_DestroySemaphore(sem); } + void wait() { SDL_SemWait(sem); } + void signal() { SDL_SemPost(sem); } + }; +#endif + + static CVideoMode g_aFakeModes[] = { {320,240,8,8,8}, {400,300,8,8,8}, {640,480,8,8,8}, {720,400,8,8,8}, {768,576,8,8,8}, {800,600,8,8,8}, -- cgit 1.4.1 From 7b545f3ed941d45c3a42016b9de667a08f8d4dc6 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Wed, 27 Jun 2012 11:46:11 +0200 Subject: Added borderless window functionality This might become handy for users with multiple monitors, might resolve other issues aswell --- src/engine/client/backend_sdl.cpp | 7 +++++++ src/engine/client/graphics.cpp | 10 +++++++++- src/engine/client/graphics_threaded.cpp | 9 ++++++++- src/engine/client/graphics_threaded.h | 1 + src/engine/shared/config_variables.h | 1 + src/game/client/components/menus_settings.cpp | 13 +++++++++++++ 6 files changed, 39 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index b04b729e..18f1cee6 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -427,6 +427,13 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height if(pInfo->blit_hw) // ignore_convention SdlFlags |= SDL_HWACCEL; + dbg_assert(!(Flags&IGraphicsBackend::INITFLAG_BORDERLESS) + || !(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN), + "only one of borderless and fullscreen may be activated at the same time"); + + if(Flags&IGraphicsBackend::INITFLAG_BORDERLESS) + SdlFlags |= SDL_NOFRAME; + if(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN) SdlFlags |= SDL_FULLSCREEN; diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 8816e1ed..314669e2 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -801,7 +801,15 @@ int CGraphics_SDL::TryInit() if(pInfo->blit_hw) // ignore_convention Flags |= SDL_HWACCEL; - if(g_Config.m_GfxFullscreen) + if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen) + { + dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless"); + g_Config.m_GfxBorderless = 0; + } + + if(g_Config.m_GfxBorderless) + Flags |= SDL_NOFRAME; + else if(g_Config.m_GfxFullscreen) Flags |= SDL_FULLSCREEN; // set gl attributes diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 0c99ebf7..f67753fb 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -712,7 +712,14 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, float r, float int CGraphics_Threaded::IssueInit() { int Flags = 0; - if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN; + if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen) + { + dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless"); + g_Config.m_GfxBorderless = 0; + } + + if(g_Config.m_GfxBorderless) Flags |= IGraphicsBackend::INITFLAG_BORDERLESS; + else if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN; if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC; if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE; diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index d3ccc61e..253059ec 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -300,6 +300,7 @@ public: INITFLAG_FULLSCREEN = 1, INITFLAG_VSYNC = 2, INITFLAG_RESIZABLE = 4, + INITFLAG_BORDERLESS = 8, }; virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0; diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 2bee031d..659d1087 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -59,6 +59,7 @@ MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFG MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width") MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height") +MACRO_CONFIG_INT(GfxBorderless, gfx_borderless, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Borderless window (not to be used with fullscreen)") MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen") MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)") MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)") diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 13993783..467ef500 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -613,6 +613,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) static int s_GfxScreenWidth = g_Config.m_GfxScreenWidth; static int s_GfxScreenHeight = g_Config.m_GfxScreenHeight; static int s_GfxColorDepth = g_Config.m_GfxColorDepth; + static int s_GfxBorderless = g_Config.m_GfxBorderless; static int s_GfxFullscreen = g_Config.m_GfxFullscreen; static int s_GfxVsync = g_Config.m_GfxVsync; static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples; @@ -667,10 +668,21 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) } // switches + MainView.HSplitTop(20.0f, &Button, &MainView); + if(DoButton_CheckBox(&g_Config.m_GfxBorderless, Localize("Borderless window"), g_Config.m_GfxBorderless, &Button)) + { + g_Config.m_GfxBorderless ^= 1; + if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen) + g_Config.m_GfxFullscreen = 0; + CheckSettings = true; + } + MainView.HSplitTop(20.0f, &Button, &MainView); if(DoButton_CheckBox(&g_Config.m_GfxFullscreen, Localize("Fullscreen"), g_Config.m_GfxFullscreen, &Button)) { g_Config.m_GfxFullscreen ^= 1; + if(g_Config.m_GfxFullscreen && g_Config.m_GfxBorderless) + g_Config.m_GfxBorderless = 0; CheckSettings = true; } @@ -713,6 +725,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) if(s_GfxScreenWidth == g_Config.m_GfxScreenWidth && s_GfxScreenHeight == g_Config.m_GfxScreenHeight && s_GfxColorDepth == g_Config.m_GfxColorDepth && + s_GfxBorderless == g_Config.m_GfxBorderless && s_GfxFullscreen == g_Config.m_GfxFullscreen && s_GfxVsync == g_Config.m_GfxVsync && s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples && -- cgit 1.4.1 From 86fe9757c5ca48349bf6d4035ffa33f745026a7e Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Wed, 27 Jun 2012 11:47:31 +0200 Subject: Removed useless enum --- src/engine/client/backend_sdl.cpp | 2 +- src/engine/client/graphics_threaded.h | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 18f1cee6..cb865bae 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -450,7 +450,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Flags&CCommandBuffer::INITFLAG_VSYNC ? 1 : 0); + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Flags&IGraphicsBackend::INITFLAG_VSYNC ? 1 : 0); // set caption SDL_WM_SetCaption(pName, pName); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 253059ec..b88ee3cb 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -96,13 +96,6 @@ public: TEXFLAG_NOMIPMAPS = 1, }; - enum - { - INITFLAG_FULLSCREEN = 1, - INITFLAG_VSYNC = 2, - INITFLAG_RESIZABLE = 4, - }; - enum { // -- cgit 1.4.1 From 0adaf8a75206bcc3cdba5c4eadd5014a3d696aff Mon Sep 17 00:00:00 2001 From: BeaR Date: Wed, 2 May 2012 13:53:28 +0200 Subject: #913 Fix Input Handling --- src/engine/client/input.cpp | 13 +++++++++---- src/engine/input.h | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp index 0b4a44a4..7ff8d6fe 100644 --- a/src/engine/client/input.cpp +++ b/src/engine/client/input.cpp @@ -35,6 +35,7 @@ CInput::CInput() m_InputCurrent = 0; m_InputGrabbed = 0; + m_InputDispatched = false; m_LastRelease = 0; m_ReleaseDelta = -1; @@ -116,10 +117,14 @@ int CInput::Update() /*if(!input_grabbed && Graphics()->WindowActive()) Input()->MouseModeRelative();*/ - // clear and begin count on the other one - m_InputCurrent^=1; - mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent])); - mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent])); + if(m_InputDispatched) + { + // clear and begin count on the other one + m_InputCurrent^=1; + mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent])); + mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent])); + m_InputDispatched = false; + } { int i; diff --git a/src/engine/input.h b/src/engine/input.h index 7d28be10..93ceccd2 100644 --- a/src/engine/input.h +++ b/src/engine/input.h @@ -38,6 +38,7 @@ protected: unsigned char m_aInputState[2][1024]; int m_InputCurrent; + bool m_InputDispatched; int KeyWasPressed(int Key) { return m_aInputState[m_InputCurrent^1][Key]; } @@ -51,7 +52,11 @@ public: // events int NumEvents() const { return m_NumEvents; } - void ClearEvents() { m_NumEvents = 0; } + void ClearEvents() + { + m_NumEvents = 0; + m_InputDispatched = true; + } CEvent GetEvent(int Index) const { if(Index < 0 || Index >= m_NumEvents) -- cgit 1.4.1 From 865d0f736588337fc7b8cc925eb84bc2dd2ae7f0 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 8 Jul 2012 11:40:23 +0200 Subject: limit characters within player names to ascii range to prevent utf8 impersonating --- src/engine/server/server.cpp | 72 ++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) (limited to 'src/engine') diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 704d4e37..611441d8 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -36,45 +36,23 @@ #include #endif -static const char *StrUTF8Ltrim(const char *pStr) +static const char *StrLtrim(const char *pStr) { - while(*pStr) - { - const char *pStrOld = pStr; - int Code = str_utf8_decode(&pStr); - - // check if unicode is not empty - if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) && - (Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) && - Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC)) - { - return pStrOld; - } - } + while(*pStr && *pStr >= 0 && *pStr <= 32) + pStr++; return pStr; } -static void StrUTF8Rtrim(char *pStr) +static void StrRtrim(char *pStr) { - const char *p = pStr; - const char *pEnd = 0; - while(*p) + int i = str_length(pStr); + while(i >= 0) { - const char *pStrOld = p; - int Code = str_utf8_decode(&p); - - // check if unicode is not empty - if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) && - (Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) && - Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC)) - { - pEnd = 0; - } - else if(pEnd == 0) - pEnd = pStrOld; + if(pStr[i] < 0 || pStr[i] > 32) + break; + pStr[i] = 0; + i--; } - if(pEnd != 0) - *(const_cast(pEnd)) = 0; } @@ -316,8 +294,12 @@ int CServer::TrySetClientName(int ClientID, const char *pName) char aTrimmedName[64]; // trim the name - str_copy(aTrimmedName, StrUTF8Ltrim(pName), sizeof(aTrimmedName)); - StrUTF8Rtrim(aTrimmedName); + str_copy(aTrimmedName, StrLtrim(pName), sizeof(aTrimmedName)); + StrRtrim(aTrimmedName); + + // check for empty names + if(!aTrimmedName[0]) + return -1; // check if new and old name are the same if(m_aClients[ClientID].m_aName[0] && str_comp(m_aClients[ClientID].m_aName, aTrimmedName) == 0) @@ -328,11 +310,6 @@ int CServer::TrySetClientName(int ClientID, const char *pName) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); pName = aTrimmedName; - - // check for empty names - if(!pName[0]) - return -1; - // make sure that two clients doesn't have the same name for(int i = 0; i < MAX_CLIENTS; i++) if(i != ClientID && m_aClients[i].m_State >= CClient::STATE_READY) @@ -356,14 +333,23 @@ void CServer::SetClientName(int ClientID, const char *pName) if(!pName) return; - char aNameTry[MAX_NAME_LENGTH]; - str_copy(aNameTry, pName, MAX_NAME_LENGTH); - if(TrySetClientName(ClientID, aNameTry)) + char aCleanName[MAX_NAME_LENGTH]; + str_copy(aCleanName, pName, sizeof(aCleanName)); + + // clear name + for(char *p = aCleanName; *p; ++p) + { + if(*p < 32) + *p = ' '; + } + + if(TrySetClientName(ClientID, aCleanName)) { // auto rename for(int i = 1;; i++) { - str_format(aNameTry, MAX_NAME_LENGTH, "(%d)%s", i, pName); + char aNameTry[MAX_NAME_LENGTH]; + str_format(aNameTry, sizeof(aCleanName), "(%d)%s", i, aCleanName); if(TrySetClientName(ClientID, aNameTry) == 0) break; } -- cgit 1.4.1 From 521eaf038baeefe5aca026ba077c0ce7f72310b7 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 8 Jul 2012 18:37:32 +0200 Subject: fixed missing messages when net connection closes --- src/engine/shared/network_conn.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index 6a63f82d..24c8f066 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -25,8 +25,6 @@ void CNetConnection::Reset() m_Buffer.Init(); mem_zero(&m_Construct, sizeof(m_Construct)); - - mem_zero(m_ErrorString, sizeof(m_ErrorString)); } const char *CNetConnection::ErrorString() @@ -46,6 +44,7 @@ void CNetConnection::Init(NETSOCKET Socket, bool BlockCloseMsg) m_Socket = Socket; m_BlockCloseMsg = BlockCloseMsg; + mem_zero(m_ErrorString, sizeof(m_ErrorString)); } void CNetConnection::AckChunks(int Ack) @@ -169,6 +168,7 @@ int CNetConnection::Connect(NETADDR *pAddr) // init connection Reset(); m_PeerAddr = *pAddr; + mem_zero(m_ErrorString, sizeof(m_ErrorString)); m_State = NET_CONNSTATE_CONNECT; SendControl(NET_CTRLMSG_CONNECT, 0, 0); return 0; @@ -248,6 +248,7 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr) Reset(); m_State = NET_CONNSTATE_PENDING; m_PeerAddr = *pAddr; + mem_zero(m_ErrorString, sizeof(m_ErrorString)); m_LastSendTime = Now; m_LastRecvTime = Now; m_LastUpdateTime = Now; -- cgit 1.4.1 From 8ca79336533b891b0cc11ccccf178b661777185a Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 29 Jul 2012 12:17:16 +0200 Subject: Show user authlevel on status command. Closes #985 --- src/engine/server/server.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 611441d8..3cad5d1c 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1449,8 +1449,12 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) { net_addr_str(pThis->m_NetServer.ClientAddr(i), aAddrStr, sizeof(aAddrStr), true); if(pThis->m_aClients[i].m_State == CClient::STATE_INGAME) - str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d", i, aAddrStr, - pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score); + { + const char *pAuthStr = pThis->m_aClients[i].m_Authed == CServer::AUTHED_ADMIN ? "(Admin)" : + pThis->m_aClients[i].m_Authed == CServer::AUTHED_MOD ? "(Mod)" : ""; + str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d %s", i, aAddrStr, + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pAuthStr); + } else str_format(aBuf, sizeof(aBuf), "id=%d addr=%s connecting", i, aAddrStr); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); -- cgit 1.4.1 From 98042012a6c6e639c9736b32518dd082ca539615 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Fri, 17 Aug 2012 00:03:53 +0200 Subject: cleaned up warnings that clang spits out. some bugs found with it. Conflicts: src/game/server/gamemodes/ctf.cpp src/game/server/gamemodes/ctf.h --- src/base/tl/range.h | 2 +- src/engine/client/graphics_threaded.h | 2 ++ src/engine/server/server.cpp | 4 ++-- src/engine/server/server.h | 6 +++--- src/engine/shared/console.cpp | 6 +++--- src/engine/shared/mapchecker.cpp | 1 + src/engine/shared/netban.h | 2 +- src/versionsrv/mapversions.h | 22 ++++++++++++++++++++++ src/versionsrv/versionsrv.h | 17 ----------------- 9 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 src/versionsrv/mapversions.h (limited to 'src/engine') diff --git a/src/base/tl/range.h b/src/base/tl/range.h index f1fc070b..1d225f49 100644 --- a/src/base/tl/range.h +++ b/src/base/tl/range.h @@ -154,7 +154,7 @@ public: void pop_back() { tl_assert(!empty()); end--; } T& front() { tl_assert(!empty()); return *begin; } 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); } plain_range slice(unsigned startindex, unsigned endindex) { diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index b88ee3cb..5c15d062 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -296,6 +296,8 @@ public: INITFLAG_BORDERLESS = 8, }; + virtual ~IGraphicsBackend() {} + virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0; virtual int Shutdown() = 0; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 3cad5d1c..4b7f6332 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -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); @@ -1618,7 +1618,7 @@ void CServer::RegisterCommands() Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this); // register console commands in sub parts - m_ServerBan.Init(Console(), Storage(), this); + m_ServerBan.InitServerBan(Console(), Storage(), this); m_pGameServer->OnConsoleInit(); } diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 696b472d..c3c1794d 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -50,10 +50,10 @@ class CServerBan : public CNetBan public: 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); - int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); + virtual int BanAddr(const NETADDR *pAddr, 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); }; diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 443c5904..3ff3c5b3 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -16,21 +16,21 @@ const char *CConsole::CResult::GetString(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return ""; return m_apArgs[Index]; } int CConsole::CResult::GetInteger(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return 0; return str_toint(m_apArgs[Index]); } float CConsole::CResult::GetFloat(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return 0.0f; return str_tofloat(m_apArgs[Index]); } diff --git a/src/engine/shared/mapchecker.cpp b/src/engine/shared/mapchecker.cpp index f8ba30ae..5a7d062f 100644 --- a/src/engine/shared/mapchecker.cpp +++ b/src/engine/shared/mapchecker.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "datafile.h" #include "memheap.h" diff --git a/src/engine/shared/netban.h b/src/engine/shared/netban.h index 6d690164..70164832 100644 --- a/src/engine/shared/netban.h +++ b/src/engine/shared/netban.h @@ -170,7 +170,7 @@ public: class IStorage *Storage() const { return m_pStorage; } virtual ~CNetBan() {} - virtual void Init(class IConsole *pConsole, class IStorage *pStorage); + void Init(class IConsole *pConsole, class IStorage *pStorage); void Update(); virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); diff --git a/src/versionsrv/mapversions.h b/src/versionsrv/mapversions.h new file mode 100644 index 00000000..fe9e4229 --- /dev/null +++ b/src/versionsrv/mapversions.h @@ -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 diff --git a/src/versionsrv/versionsrv.h b/src/versionsrv/versionsrv.h index 383f1ac4..46f64251 100644 --- a/src/versionsrv/versionsrv.h +++ b/src/versionsrv/versionsrv.h @@ -11,23 +11,6 @@ struct CMapVersion 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_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'}; -- cgit 1.4.1 From 1711be955b54b9d12431b341ea290bad406023cc Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Fri, 17 Aug 2012 18:32:56 +0200 Subject: fixed all the errors that the clang static analayzer found --- src/base/system.c | 4 +++- src/base/system.h | 7 +++++++ src/engine/client/client.cpp | 3 +-- src/engine/shared/console.cpp | 2 +- src/engine/shared/snapshot.cpp | 7 ++++--- src/game/editor/editor.cpp | 4 ---- src/game/editor/popups.cpp | 1 - src/game/server/gamecontext.cpp | 10 ++++++---- src/game/server/gamecontroller.cpp | 4 ++-- 9 files changed, 24 insertions(+), 18 deletions(-) (limited to 'src/engine') diff --git a/src/base/system.c b/src/base/system.c index a849e807..410cb699 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -80,7 +80,7 @@ void dbg_assert_imp(const char *filename, int line, int test, const char *msg) void dbg_break() { - *((unsigned*)0) = 0x0; + *((volatile unsigned*)0) = 0x0; } 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; MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL)); dbg_assert(header != 0, "mem_alloc failure"); + if(!header) + return NULL; tail = (struct MEMTAIL *)(((char*)(header+1))+size); header->size = size; header->filename = filename; diff --git a/src/base/system.h b/src/base/system.h index 032cf785..7ba0c0a0 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -33,6 +33,13 @@ void dbg_assert(int test, const char *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); + +#ifdef __clang_analyzer__ +#include +#undef dbg_assert +#define dbg_assert(test,msg) assert(test) +#endif + /* Function: dbg_break Breaks into the debugger. diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 6d1d8f4f..a88fe3cb 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1310,7 +1310,6 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket) } // unpack delta - PurgeTick = DeltaTick; SnapSize = m_SnapshotDelta.UnpackDelta(pDeltaShot, pTmpBuffer3, pDeltaData, DeltaSize); if(SnapSize < 0) { @@ -1349,7 +1348,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket) if(m_aSnapshots[SNAP_PREV] && m_aSnapshots[SNAP_PREV]->m_Tick < PurgeTick) PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; 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); // add new diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 3ff3c5b3..399f5323 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -68,7 +68,7 @@ int CConsole::ParseStart(CResult *pResult, const char *pString, int Length) if(Length < Len) Len = Length; - str_copy(pResult->m_aStringStorage, pString, Length); + str_copy(pResult->m_aStringStorage, pString, Len); pStr = pResult->m_aStringStorage; // get command diff --git a/src/engine/shared/snapshot.cpp b/src/engine/shared/snapshot.cpp index 9ef8fdc3..1514278b 100644 --- a/src/engine/shared/snapshot.cpp +++ b/src/engine/shared/snapshot.cpp @@ -195,13 +195,14 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData // fetch previous indices // 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) 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 ItemSize = pTo->GetItemSize(i); // O(1) .. O(n) @@ -474,7 +475,7 @@ int CSnapshotStorage::Get(int Tick, int64 *pTagtime, CSnapshot **ppData, CSnapsh if(ppData) *ppData = pHolder->m_pSnap; if(ppAltData) - *ppData = pHolder->m_pAltSnap; + *ppAltData = pHolder->m_pAltSnap; return pHolder->m_SnapSize; } diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index ee26a3f0..7109adca 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2292,8 +2292,6 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); } - else - ScrollNum = 0; } } @@ -2615,8 +2613,6 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); } - else - ScrollNum = 0; } } diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 2382823d..f281c6aa 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -554,7 +554,6 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View) { if(pEditor->m_SelectedPoints&(1<m_aColors[v].r = (NewVal>>24)&0xff; pQuad->m_aColors[v].g = (NewVal>>16)&0xff; pQuad->m_aColors[v].b = (NewVal>>8)&0xff; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 5d2f22b8..bab48308 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -599,9 +599,12 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) if(!pRawMsg) { - char aBuf[256]; - 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); + if(g_Config.m_Debug) + { + char aBuf[256]; + 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); + } return; } @@ -940,7 +943,6 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) { OptionMsg.m_NumOptions = NumOptions; Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); - NumOptions = 0; } // send tuning parameters to client diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 7001ca32..0ee250e8 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -281,8 +281,8 @@ void IGameController::CycleMap() pNextMap = pMapRotation; // cut out the next map - char aBuf[512]; - for(int i = 0; i < 512; i++) + char aBuf[512] = {0}; + for(int i = 0; i < 511; i++) { aBuf[i] = pNextMap[i]; if(IsSeparator(pNextMap[i]) || pNextMap[i] == 0) -- cgit 1.4.1 From 678b6faceb8f8bd550de32b8fe59f7c34e2a3172 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sun, 26 Aug 2012 20:02:04 +0200 Subject: Fixed threaded gfx and building on Mac OS X --- src/engine/client/backend_sdl.cpp | 3 +++ src/engine/client/backend_sdl.h | 52 +++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 7 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index cb865bae..22c48e53 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -11,6 +11,9 @@ void CGraphicsBackend_Threaded::ThreadFunc(void *pUser) { + #ifdef CONF_PLATFORM_MACOSX + CAutoreleasePool AutoreleasePool; + #endif CGraphicsBackend_Threaded *pThis = (CGraphicsBackend_Threaded *)pUser; while(!pThis->m_Shutdown) diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index 2ef04a1f..619ba84d 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -28,7 +28,7 @@ static void GL_SwapBuffers(const SGLContext &Context) { SwapBuffers(Context.m_hDC); } #elif defined(CONF_PLATFORM_MACOSX) - #include + #include class semaphore { @@ -42,20 +42,58 @@ struct SGLContext { - AGLContext m_Context; + id m_Context; }; static SGLContext GL_GetCurrentContext() { SGLContext Context; - Context.m_Context = aglGetCurrentContext(); + Class NSOpenGLContextClass = (Class) objc_getClass("NSOpenGLContext"); + SEL selector = sel_registerName("currentContext"); + Context.m_Context = objc_msgSend((objc_object*) NSOpenGLContextClass, selector); return Context; } - static void GL_MakeCurrent(const SGLContext &Context) { aglSetCurrentContext(Context.m_Context); } - static void GL_ReleaseContext(const SGLContext &Context) { aglSetCurrentContext(NULL); } - static void GL_SwapBuffers(const SGLContext &Context) { aglSwapBuffers(Context.m_Context); } - + static void GL_MakeCurrent(const SGLContext &Context) + { + SEL selector = sel_registerName("makeCurrentContext"); + objc_msgSend(Context.m_Context, selector); + } + + static void GL_ReleaseContext(const SGLContext &Context) + { + Class NSOpenGLContextClass = (Class) objc_getClass("NSOpenGLContext"); + SEL selector = sel_registerName("clearCurrentContext"); + objc_msgSend((objc_object*) NSOpenGLContextClass, selector); + } + + static void GL_SwapBuffers(const SGLContext &Context) + { + SEL selector = sel_registerName("flushBuffer"); + objc_msgSend(Context.m_Context, selector); + } + + class CAutoreleasePool + { + private: + id m_Pool; + + public: + CAutoreleasePool() + { + Class NSAutoreleasePoolClass = (Class) objc_getClass("NSAutoreleasePool"); + m_Pool = class_createInstance(NSAutoreleasePoolClass, 0); + SEL selector = sel_registerName("init"); + objc_msgSend(m_Pool, selector); + } + + ~CAutoreleasePool() + { + SEL selector = sel_registerName("drain"); + objc_msgSend(m_Pool, selector); + } + }; + #elif defined(CONF_FAMILY_UNIX) #include -- cgit 1.4.1 From c3dd09cebfeca29a33ab77dfcfb27ec7a64a9687 Mon Sep 17 00:00:00 2001 From: BeaR Date: Mon, 27 Aug 2012 18:58:30 +0200 Subject: Readded Texturecompression-support --- src/engine/client/backend_sdl.cpp | 10 ++++++++++ src/engine/client/graphics_threaded.h | 1 + 2 files changed, 11 insertions(+) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 22c48e53..7fa1db77 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -176,6 +176,16 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: int Oglformat = TexFormatToOpenGLFormat(pCommand->m_Format); int StoreOglformat = TexFormatToOpenGLFormat(pCommand->m_StoreFormat); + if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_COMPRESSED) + { + switch(StoreOglformat) + { + case GL_RGB: StoreOglformat = GL_COMPRESSED_RGB_ARB; + case GL_ALPHA: StoreOglformat = GL_COMPRESSED_ALPHA_ARB; + case GL_RGBA: StoreOglformat = GL_COMPRESSED_RGBA_ARB; + default: StoreOglformat = GL_COMPRESSED_RGBA_ARB; + } + } glGenTextures(1, &m_aTextures[pCommand->m_Slot]); glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot]); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 5c15d062..e482f6e5 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -94,6 +94,7 @@ public: TEXFORMAT_ALPHA, TEXFLAG_NOMIPMAPS = 1, + TEXFLAG_COMPRESSED = 2, }; enum -- cgit 1.4.1 From 1cfbfda6fa429ab0ee2e503262946a8adbfd9a2e Mon Sep 17 00:00:00 2001 From: BeaR Date: Mon, 3 Sep 2012 11:39:12 +0200 Subject: Missed a file.. --- src/engine/client/graphics_threaded.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/engine') diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index f67753fb..8653b62a 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -359,6 +359,8 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const Cmd.m_Flags = 0; if(Flags&IGraphics::TEXLOAD_NOMIPMAPS) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NOMIPMAPS; + if(g_Config.m_GfxTextureCompression) + Cmd.m_Flags |= CCommandBuffer::TEXFLAG_COMPRESSED; // calculate memory usage int PixelSize = 4; -- cgit 1.4.1 From 2948d2392b509c5cc743d517687a8d941e4ef9d0 Mon Sep 17 00:00:00 2001 From: oy Date: Sat, 6 Oct 2012 13:24:31 +0200 Subject: fixed last commit --- src/engine/client/backend_sdl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 7fa1db77..5f57fa30 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -180,9 +180,9 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: { switch(StoreOglformat) { - case GL_RGB: StoreOglformat = GL_COMPRESSED_RGB_ARB; - case GL_ALPHA: StoreOglformat = GL_COMPRESSED_ALPHA_ARB; - case GL_RGBA: StoreOglformat = GL_COMPRESSED_RGBA_ARB; + case GL_RGB: StoreOglformat = GL_COMPRESSED_RGB_ARB; break; + case GL_ALPHA: StoreOglformat = GL_COMPRESSED_ALPHA_ARB; break; + case GL_RGBA: StoreOglformat = GL_COMPRESSED_RGBA_ARB; break; default: StoreOglformat = GL_COMPRESSED_RGBA_ARB; } } -- cgit 1.4.1 From 71af97a5e30739577bde35db24ec9f160b0bea65 Mon Sep 17 00:00:00 2001 From: oy Date: Sat, 6 Oct 2012 23:31:02 +0200 Subject: fixed texture memory usage calculation in graphics threaded Conflicts: src/engine/client/graphics_threaded.cpp --- src/engine/client/backend_sdl.cpp | 46 +++++++++++++++++++++------ src/engine/client/backend_sdl.h | 28 +++++++++++++++-- src/engine/client/graphics_threaded.cpp | 55 ++++++++++++--------------------- src/engine/client/graphics_threaded.h | 16 ++++------ 4 files changed, 89 insertions(+), 56 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 5f57fa30..d99f765b 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -133,7 +133,7 @@ void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &St if(State.m_Texture >= 0 && State.m_Texture < CCommandBuffer::MAX_TEXTURES) { glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, m_aTextures[State.m_Texture]); + glBindTexture(GL_TEXTURE_2D, m_aTextures[State.m_Texture].m_Tex); } else glDisable(GL_TEXTURE_2D); @@ -158,9 +158,14 @@ void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &St glOrtho(State.m_ScreenTL.x, State.m_ScreenBR.x, State.m_ScreenBR.y, State.m_ScreenTL.y, 1.0f, 10.f); } +void CCommandProcessorFragment_OpenGL::Cmd_Init(const SCommand_Init *pCommand) +{ + m_pTextureMemoryUsage = pCommand->m_pTextureMemoryUsage; +} + void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) { - glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot]); + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); glTexSubImage2D(GL_TEXTURE_2D, 0, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height, TexFormatToOpenGLFormat(pCommand->m_Format), GL_UNSIGNED_BYTE, pCommand->m_pData); mem_free(pCommand->m_pData); @@ -168,7 +173,8 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer:: void CCommandProcessorFragment_OpenGL::Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand) { - glDeleteTextures(1, &m_aTextures[pCommand->m_Slot]); + glDeleteTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); + *m_pTextureMemoryUsage -= m_aTextures[pCommand->m_Slot].m_MemSize; } void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) @@ -186,8 +192,8 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: default: StoreOglformat = GL_COMPRESSED_RGBA_ARB; } } - glGenTextures(1, &m_aTextures[pCommand->m_Slot]); - glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot]); + glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS) { @@ -202,6 +208,18 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, pCommand->m_Width, pCommand->m_Height, Oglformat, GL_UNSIGNED_BYTE, pCommand->m_pData); } + // calculate memory usage + int Width = pCommand->m_Width; + int Height = pCommand->m_Height; + m_aTextures[pCommand->m_Slot].m_MemSize = Width*Height*pCommand->m_PixelSize; + while(Width > 2 && Height > 2) + { + Width>>=1; + Height>>=1; + m_aTextures[pCommand->m_Slot].m_MemSize += Width*Height*pCommand->m_PixelSize; + } + *m_pTextureMemoryUsage += m_aTextures[pCommand->m_Slot].m_MemSize; + mem_free(pCommand->m_pData); } @@ -273,12 +291,14 @@ void CCommandProcessorFragment_OpenGL::Cmd_Screenshot(const CCommandBuffer::SCom CCommandProcessorFragment_OpenGL::CCommandProcessorFragment_OpenGL() { mem_zero(m_aTextures, sizeof(m_aTextures)); + m_pTextureMemoryUsage = 0; } bool CCommandProcessorFragment_OpenGL::RunCommand(const CCommandBuffer::SCommand * pBaseCommand) { switch(pBaseCommand->m_Cmd) { + case CMD_INIT: Cmd_Init(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_TEXTURE_CREATE: Cmd_Texture_Create(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_TEXTURE_DESTROY: Cmd_Texture_Destroy(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_TEXTURE_UPDATE: Cmd_Texture_Update(static_cast(pBaseCommand)); break; @@ -487,11 +507,14 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height m_pProcessor = new CCommandProcessor_SDL_OpenGL; StartProcessor(m_pProcessor); - // issue a init command + // issue init commands for OpenGL and SDL CCommandBuffer CmdBuffer(1024, 512); - CCommandProcessorFragment_SDL::SCommand_Init Cmd; - Cmd.m_Context = m_GLContext; - CmdBuffer.AddCommand(Cmd); + CCommandProcessorFragment_OpenGL::SCommand_Init CmdOpenGL; + CmdOpenGL.m_pTextureMemoryUsage = &m_TextureMemoryUsage; + CmdBuffer.AddCommand(CmdOpenGL); + CCommandProcessorFragment_SDL::SCommand_Init CmdSDL; + CmdSDL.m_Context = m_GLContext; + CmdBuffer.AddCommand(CmdSDL); RunBuffer(&CmdBuffer); WaitForIdle(); @@ -517,6 +540,11 @@ int CGraphicsBackend_SDL_OpenGL::Shutdown() return 0; } +int CGraphicsBackend_SDL_OpenGL::MemoryUsage() const +{ + return m_TextureMemoryUsage; +} + void CGraphicsBackend_SDL_OpenGL::Minimize() { SDL_WM_IconifyWindow(); diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index 619ba84d..e1fc60b0 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -167,11 +167,32 @@ public: // takes care of opengl related rendering class CCommandProcessorFragment_OpenGL { - GLuint m_aTextures[CCommandBuffer::MAX_TEXTURES]; + struct CTexture + { + GLuint m_Tex; + int m_MemSize; + }; + CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES]; + volatile int *m_pTextureMemoryUsage; + +public: + enum + { + CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL, + }; + + struct SCommand_Init : public CCommandBuffer::SCommand + { + SCommand_Init() : SCommand(CMD_INIT) {} + volatile int *m_pTextureMemoryUsage; + }; + +private: static int TexFormatToOpenGLFormat(int TexFormat); void SetState(const CCommandBuffer::SState &State); + void Cmd_Init(const SCommand_Init *pCommand); void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand); void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand); void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand); @@ -193,7 +214,7 @@ class CCommandProcessorFragment_SDL public: enum { - CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM, + CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_SDL, CMD_SHUTDOWN, }; @@ -235,10 +256,13 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded SDL_Surface *m_pScreenSurface; ICommandProcessor *m_pProcessor; SGLContext m_GLContext; + volatile int m_TextureMemoryUsage; public: virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags); virtual int Shutdown(); + virtual int MemoryUsage() const; + virtual void Minimize(); virtual void Maximize(); virtual int WindowActive(); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 8653b62a..751e4ad2 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -228,7 +228,7 @@ void CGraphics_Threaded::WrapClamp() int CGraphics_Threaded::MemoryUsage() const { - return m_TextureMemoryUsage; + return m_pBackend->MemoryUsage(); } void CGraphics_Threaded::MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) @@ -293,8 +293,7 @@ int CGraphics_Threaded::UnloadTexture(int Index) Cmd.m_Slot = Index; m_pCommandBuffer->AddCommand(Cmd); - m_aTextures[Index].m_Next = m_FirstFreeTexture; - m_TextureMemoryUsage -= m_aTextures[Index].m_MemSize; + m_aTextures[Index] = m_FirstFreeTexture; m_FirstFreeTexture = Index; return 0; } @@ -307,6 +306,16 @@ static int ImageFormatToTexFormat(int Format) return CCommandBuffer::TEXFORMAT_RGBA; } +static int ImageFormatToPixelSize(int Format) +{ + switch(Format) + { + case CImageInfo::FORMAT_RGB: return 3; + case CImageInfo::FORMAT_ALPHA: return 1; + default: return 4; + } +} + int CGraphics_Threaded::LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData) { @@ -319,13 +328,7 @@ int CGraphics_Threaded::LoadTextureRawSub(int TextureID, int x, int y, int Width Cmd.m_Format = ImageFormatToTexFormat(Format); // calculate memory usage - int PixelSize = 4; - if(Format == CImageInfo::FORMAT_RGB) - PixelSize = 3; - else if(Format == CImageInfo::FORMAT_ALPHA) - PixelSize = 1; - - int MemSize = Width*Height*PixelSize; + int MemSize = Width*Height*ImageFormatToPixelSize(Format); // copy texture data void *pTmpData = mem_alloc(MemSize, sizeof(void*)); @@ -345,13 +348,14 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const // grab texture int Tex = m_FirstFreeTexture; - m_FirstFreeTexture = m_aTextures[Tex].m_Next; - m_aTextures[Tex].m_Next = -1; + m_FirstFreeTexture = m_aTextureIndices[Tex]; + m_aTextureIndices[Tex] = -1; CCommandBuffer::SCommand_Texture_Create Cmd; Cmd.m_Slot = Tex; Cmd.m_Width = Width; Cmd.m_Height = Height; + Cmd.m_PixelSize = ImageFormatToPixelSize(Format); Cmd.m_Format = ImageFormatToTexFormat(Format); Cmd.m_StoreFormat = ImageFormatToTexFormat(StoreFormat); @@ -362,16 +366,8 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const if(g_Config.m_GfxTextureCompression) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_COMPRESSED; - // calculate memory usage - int PixelSize = 4; - if(Format == CImageInfo::FORMAT_RGB) - PixelSize = 3; - else if(Format == CImageInfo::FORMAT_ALPHA) - PixelSize = 1; - - int MemSize = Width*Height*PixelSize; - // copy texture data + int MemSize = Width*Height*Cmd.m_PixelSize; void *pTmpData = mem_alloc(MemSize, sizeof(void*)); mem_copy(pTmpData, pData, MemSize); Cmd.m_pData = pTmpData; @@ -379,17 +375,6 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const // m_pCommandBuffer->AddCommand(Cmd); - // calculate memory usage - int MemUsage = MemSize; - while(Width > 2 && Height > 2) - { - Width>>=1; - Height>>=1; - MemUsage += Width*Height*PixelSize; - } - - m_TextureMemoryUsage += MemUsage; - //mem_free(pTmpData); return Tex; } @@ -775,9 +760,9 @@ int CGraphics_Threaded::Init() // init textures m_FirstFreeTexture = 0; - for(int i = 0; i < MAX_TEXTURES; i++) - m_aTextures[i].m_Next = i+1; - m_aTextures[MAX_TEXTURES-1].m_Next = -1; + for(int i = 0; i < MAX_TEXTURES-1; i++) + m_aTextureIndices[i] = i+1; + m_aTextureIndices[MAX_TEXTURES-1] = -1; m_pBackend = CreateGraphicsBackend(); if(InitWindow() != 0) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index e482f6e5..6b3963ee 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -57,7 +57,8 @@ public: { // commadn groups CMDGROUP_CORE = 0, // commands that everyone has to implement - CMDGROUP_PLATFORM = 10000, // commands specific to a platform + CMDGROUP_PLATFORM_OPENGL = 10000, // commands specific to a platform + CMDGROUP_PLATFORM_SDL = 20000, // CMD_NOP = CMDGROUP_CORE, @@ -211,6 +212,7 @@ public: int m_Width; int m_Height; + int m_PixelSize; int m_Format; int m_StoreFormat; int m_Flags; @@ -302,6 +304,8 @@ public: virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0; virtual int Shutdown() = 0; + virtual int MemoryUsage() const = 0; + virtual void Minimize() = 0; virtual void Maximize() = 0; virtual int WindowActive() = 0; @@ -351,15 +355,7 @@ class CGraphics_Threaded : public IEngineGraphics int m_InvalidTexture; - struct CTexture - { - int m_State; - int m_MemSize; - int m_Flags; - int m_Next; - }; - - CTexture m_aTextures[MAX_TEXTURES]; + int m_aTextureIndices[MAX_TEXTURES]; int m_FirstFreeTexture; int m_TextureMemoryUsage; -- cgit 1.4.1 From df5ab998c276e34a4870085d6ddafd812a9b1912 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 7 Oct 2012 11:22:49 +0200 Subject: readded texture resampling --- src/engine/client/backend_sdl.cpp | 76 ++++++++++++++++++++++++++++++--- src/engine/client/backend_sdl.h | 2 + src/engine/client/graphics_threaded.cpp | 37 +--------------- src/engine/client/graphics_threaded.h | 4 +- 4 files changed, 76 insertions(+), 43 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index d99f765b..6fa6de01 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -100,6 +100,41 @@ int CCommandProcessorFragment_OpenGL::TexFormatToOpenGLFormat(int TexFormat) return GL_RGBA; } +unsigned char CCommandProcessorFragment_OpenGL::Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp) +{ + int Value = 0; + for(int x = 0; x < ScaleW; x++) + for(int y = 0; y < ScaleH; y++) + Value += pData[((v+y)*w+(u+x))*Bpp+Offset]; + return Value/(ScaleW*ScaleH); +} + +void *CCommandProcessorFragment_OpenGL::Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData) +{ + unsigned char *pTmpData; + int ScaleW = Width/NewWidth; + int ScaleH = Height/NewHeight; + + int Bpp = 3; + if(Format == CCommandBuffer::TEXFORMAT_RGBA) + Bpp = 4; + + pTmpData = (unsigned char *)mem_alloc(NewWidth*NewHeight*Bpp, 1); + + int c = 0; + for(int y = 0; y < NewHeight; y++) + for(int x = 0; x < NewWidth; x++, c++) + { + pTmpData[c*Bpp] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 0, ScaleW, ScaleH, Bpp); + pTmpData[c*Bpp+1] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 1, ScaleW, ScaleH, Bpp); + pTmpData[c*Bpp+2] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 2, ScaleW, ScaleH, Bpp); + if(Bpp == 4) + pTmpData[c*Bpp+3] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 3, ScaleW, ScaleH, Bpp); + } + + return pTmpData; +} + void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &State) { // blend @@ -179,6 +214,39 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Destroy(const CCommandBuffer: void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) { + int Width = pCommand->m_Width; + int Height = pCommand->m_Height; + void *pTexData = pCommand->m_pData; + + // resample if needed + if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB) + { + int MaxTexSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); + if(Width > MaxTexSize || Height > MaxTexSize) + { + do + { + Width>>=1; + Height>>=1; + } + while(Width > MaxTexSize || Height > MaxTexSize); + + void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast(pCommand->m_pData)); + mem_free(pTexData); + pTexData = pTmpData; + } + else if(Width > 16 && Height > 16 && (pCommand->m_Flags&CCommandBuffer::TEXFLAG_QUALITY) == 0) + { + Width>>=1; + Height>>=1; + + void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast(pCommand->m_pData)); + mem_free(pTexData); + pTexData = pTmpData; + } + } + int Oglformat = TexFormatToOpenGLFormat(pCommand->m_Format); int StoreOglformat = TexFormatToOpenGLFormat(pCommand->m_StoreFormat); @@ -199,18 +267,16 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, pCommand->m_Width, pCommand->m_Height, 0, Oglformat, GL_UNSIGNED_BYTE, pCommand->m_pData); + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, pCommand->m_Width, pCommand->m_Height, Oglformat, GL_UNSIGNED_BYTE, pCommand->m_pData); + gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData); } // calculate memory usage - int Width = pCommand->m_Width; - int Height = pCommand->m_Height; m_aTextures[pCommand->m_Slot].m_MemSize = Width*Height*pCommand->m_PixelSize; while(Width > 2 && Height > 2) { @@ -220,7 +286,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: } *m_pTextureMemoryUsage += m_aTextures[pCommand->m_Slot].m_MemSize; - mem_free(pCommand->m_pData); + mem_free(pTexData); } void CCommandProcessorFragment_OpenGL::Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand) diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index e1fc60b0..e90f9455 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -189,6 +189,8 @@ public: private: static int TexFormatToOpenGLFormat(int TexFormat); + static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp); + static void *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData); void SetState(const CCommandBuffer::SState &State); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 751e4ad2..7a2687c5 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -107,41 +107,6 @@ void CGraphics_Threaded::Rotate4(const CCommandBuffer::SPoint &rCenter, CCommand } } -unsigned char CGraphics_Threaded::Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp) -{ - int Value = 0; - for(int x = 0; x < ScaleW; x++) - for(int y = 0; y < ScaleH; y++) - Value += pData[((v+y)*w+(u+x))*Bpp+Offset]; - return Value/(ScaleW*ScaleH); -} - -unsigned char *CGraphics_Threaded::Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData) -{ - unsigned char *pTmpData; - int ScaleW = Width/NewWidth; - int ScaleH = Height/NewHeight; - - int Bpp = 3; - if(Format == CImageInfo::FORMAT_RGBA) - Bpp = 4; - - pTmpData = (unsigned char *)mem_alloc(NewWidth*NewHeight*Bpp, 1); - - int c = 0; - for(int y = 0; y < NewHeight; y++) - for(int x = 0; x < NewWidth; x++, c++) - { - pTmpData[c*Bpp] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 0, ScaleW, ScaleH, Bpp); - pTmpData[c*Bpp+1] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 1, ScaleW, ScaleH, Bpp); - pTmpData[c*Bpp+2] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 2, ScaleW, ScaleH, Bpp); - if(Bpp == 4) - pTmpData[c*Bpp+3] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 3, ScaleW, ScaleH, Bpp); - } - - return pTmpData; -} - CGraphics_Threaded::CGraphics_Threaded() { m_State.m_ScreenTL.x = 0; @@ -365,6 +330,8 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NOMIPMAPS; if(g_Config.m_GfxTextureCompression) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_COMPRESSED; + if(g_Config.m_GfxTextureQuality || Flags&TEXLOAD_NORESAMPLE) + Cmd.m_Flags |= CCommandBuffer::TEXFLAG_QUALITY; // copy texture data int MemSize = Width*Height*Cmd.m_PixelSize; diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 6b3963ee..809a383a 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -96,6 +96,7 @@ public: TEXFLAG_NOMIPMAPS = 1, TEXFLAG_COMPRESSED = 2, + TEXFLAG_QUALITY = 4, }; enum @@ -363,9 +364,6 @@ class CGraphics_Threaded : public IEngineGraphics void AddVertices(int Count); void Rotate4(const CCommandBuffer::SPoint &rCenter, CCommandBuffer::SVertex *pPoints); - static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp); - static unsigned char *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData); - void KickCommandBuffer(); int IssueInit(); -- cgit 1.4.1 From d58afefaae99f239151483025e516e8da5b6dd17 Mon Sep 17 00:00:00 2001 From: BeaR Date: Sun, 14 Oct 2012 14:04:48 +0200 Subject: Some graphic batching: Speed up for displaying debugtext and envelopepreview (This reduces the performance hit especially for the 'Show Info' mode in the editor) Conflicts: src/engine/client/client.cpp src/game/editor/editor.cpp src/game/editor/editor.h --- src/engine/client/client.cpp | 18 ++-- src/engine/client/graphics_threaded.cpp | 7 +- src/engine/client/graphics_threaded.h | 2 +- src/engine/graphics.h | 2 +- src/game/editor/editor.cpp | 183 +++++++++++++++++++------------- src/game/editor/editor.h | 2 +- src/game/editor/layer_tiles.cpp | 6 +- 7 files changed, 128 insertions(+), 92 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index a88fe3cb..c481102b 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -137,14 +137,16 @@ void CGraph::Render(IGraphics *pGraphics, int Font, float x, float y, float w, f pGraphics->LinesEnd(); pGraphics->TextureSet(Font); - pGraphics->QuadsText(x+2, y+h-16, 16, 1,1,1,1, pDescription); + pGraphics->QuadsBegin(); + pGraphics->QuadsText(x+2, y+h-16, 16, pDescription); char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%.2f", m_Max); - pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+2, 16, 1,1,1,1, aBuf); + pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+2, 16, aBuf); str_format(aBuf, sizeof(aBuf), "%.2f", m_Min); - pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+h-16, 16, 1,1,1,1, aBuf); + pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+h-16, 16, aBuf); + pGraphics->QuadsEnd(); } @@ -678,6 +680,7 @@ void CClient::DebugRender() //m_pGraphics->BlendNormal(); Graphics()->TextureSet(m_DebugFont); Graphics()->MapScreen(0,0,Graphics()->ScreenWidth(),Graphics()->ScreenHeight()); + Graphics()->QuadsBegin(); if(time_get()-LastSnap > time_freq()) { @@ -699,7 +702,7 @@ void CClient::DebugRender() mem_stats()->total_allocations, Graphics()->MemoryUsage()/1024, (int)(1.0f/FrameTimeAvg + 0.5f)); - Graphics()->QuadsText(2, 2, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 2, 16, aBuffer); { @@ -715,7 +718,7 @@ void CClient::DebugRender() str_format(aBuffer, sizeof(aBuffer), "send: %3d %5d+%4d=%5d (%3d kbps) avg: %5d\nrecv: %3d %5d+%4d=%5d (%3d kbps) avg: %5d", SendPackets, SendBytes, SendPackets*42, SendTotal, (SendTotal*8)/1024, SendBytes/SendPackets, RecvPackets, RecvBytes, RecvPackets*42, RecvTotal, (RecvTotal*8)/1024, RecvBytes/RecvPackets); - Graphics()->QuadsText(2, 14, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 14, 16, aBuffer); } // render rates @@ -728,7 +731,7 @@ void CClient::DebugRender() { str_format(aBuffer, sizeof(aBuffer), "%4d %20s: %8d %8d %8d", i, GameClient()->GetItemName(i), m_SnapshotDelta.GetDataRate(i)/8, m_SnapshotDelta.GetDataUpdates(i), (m_SnapshotDelta.GetDataRate(i)/m_SnapshotDelta.GetDataUpdates(i))/8); - Graphics()->QuadsText(2, 100+y*12, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 100+y*12, 16, aBuffer); y++; } } @@ -736,7 +739,8 @@ void CClient::DebugRender() str_format(aBuffer, sizeof(aBuffer), "pred: %d ms", (int)((m_PredictedTime.Get(Now)-m_GameTime.Get(Now))*1000/(float)time_freq())); - Graphics()->QuadsText(2, 70, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 70, 16, aBuffer); + Graphics()->QuadsEnd(); // render graphs if(g_Config.m_DbgGraphs) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 7a2687c5..8a3e4f50 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -629,13 +629,10 @@ void CGraphics_Threaded::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) AddVertices(4*Num); } -void CGraphics_Threaded::QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) +void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pText) { float StartX = x; - QuadsBegin(); - SetColor(r,g,b,a); - while(*pText) { char c = *pText; @@ -659,8 +656,6 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, float r, float x += Size/2; } } - - QuadsEnd(); } int CGraphics_Threaded::IssueInit() diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 809a383a..ff03c6bb 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -419,7 +419,7 @@ public: virtual void QuadsDraw(CQuadItem *pArray, int Num); virtual void QuadsDrawTL(const CQuadItem *pArray, int Num); virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num); - virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText); + virtual void QuadsText(float x, float y, float Size, const char *pText); virtual void Minimize(); virtual void Maximize(); diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 7f272497..a2fe4741 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -120,7 +120,7 @@ public: : m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {} }; virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0; - virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) = 0; + virtual void QuadsText(float x, float y, float Size, const char *pText) = 0; struct CColorVertex { diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 7109adca..07f50110 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1408,96 +1408,131 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V) Graphics()->QuadsDraw(&QuadItem, 1); } -void CEditor::DoQuadEnvelopes(CQuad *pQuad, int Index, int TexID) +void CEditor::DoQuadEnvelopes(CQuad *pQuad, int Num, int TexID) { - CEnvelope *pEnvelope = 0x0; - if(pQuad->m_PosEnv >= 0 && pQuad->m_PosEnv < m_Map.m_lEnvelopes.size()) - pEnvelope = m_Map.m_lEnvelopes[pQuad->m_PosEnv]; - if (!pEnvelope) - return; - - //QuadParams - CPoint *pPoints = pQuad->m_aPoints; + CEnvelope **apEnvelope = new CEnvelope*[Num](); + for(int i = 0; i < Num; i++) + { + if((m_ShowEnvelopePreview == 1 && pQuad[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2) + if(pQuad[i].m_PosEnv >= 0 && pQuad[i].m_PosEnv < m_Map.m_lEnvelopes.size()) + apEnvelope[i] = m_Map.m_lEnvelopes[pQuad[i].m_PosEnv]; + } //Draw Lines Graphics()->TextureSet(-1); Graphics()->LinesBegin(); - Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f); - for(int i = 0; i < pEnvelope->m_lPoints.size()-1; i++) + Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f); + for(int j = 0; j < Num; j++) + { + if(!apEnvelope[j]) + continue; + + //QuadParams + CPoint *pPoints = pQuad[j].m_aPoints; + for(int i = 0; i < apEnvelope[j]->m_lPoints.size()-1; i++) { - float OffsetX = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); - float OffsetY = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); + float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); + float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]); vec2 Pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); - OffsetX = fx2f(pEnvelope->m_lPoints[i+1].m_aValues[0]); - OffsetY = fx2f(pEnvelope->m_lPoints[i+1].m_aValues[1]); + OffsetX = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[0]); + OffsetY = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[1]); vec2 Pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); IGraphics::CLineItem Line = IGraphics::CLineItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y); Graphics()->LinesDraw(&Line, 1); } - Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + } + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); Graphics()->LinesEnd(); //Draw Quads - for(int i = 0; i < pEnvelope->m_lPoints.size(); i++) + Graphics()->TextureSet(Texture); + Graphics()->QuadsBegin(); + + for(int j = 0; j < Num; j++) { - Graphics()->TextureSet(TexID); - Graphics()->QuadsBegin(); - - //Calc Env Position - float OffsetX = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); - float OffsetY = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); - float Rot = fx2f(pEnvelope->m_lPoints[i].m_aValues[2])/360.0f*pi*2; - - //Set Colours - float Alpha = (m_SelectedQuadEnvelope == pQuad->m_PosEnv && m_SelectedEnvelopePoint == i) ? 0.65f : 0.35f; - IGraphics::CColorVertex aArray[4] = { - IGraphics::CColorVertex(0, pQuad->m_aColors[0].r, pQuad->m_aColors[0].g, pQuad->m_aColors[0].b, Alpha), - IGraphics::CColorVertex(1, pQuad->m_aColors[1].r, pQuad->m_aColors[1].g, pQuad->m_aColors[1].b, Alpha), - IGraphics::CColorVertex(2, pQuad->m_aColors[2].r, pQuad->m_aColors[2].g, pQuad->m_aColors[2].b, Alpha), - IGraphics::CColorVertex(3, pQuad->m_aColors[3].r, pQuad->m_aColors[3].g, pQuad->m_aColors[3].b, Alpha)}; - Graphics()->SetColorVertex(aArray, 4); - - //Rotation - if(Rot != 0) - { - static CPoint aRotated[4]; - aRotated[0] = pQuad->m_aPoints[0]; - aRotated[1] = pQuad->m_aPoints[1]; - aRotated[2] = pQuad->m_aPoints[2]; - aRotated[3] = pQuad->m_aPoints[3]; - pPoints = aRotated; - - Rotate(&pQuad->m_aPoints[4], &aRotated[0], Rot); - Rotate(&pQuad->m_aPoints[4], &aRotated[1], Rot); - Rotate(&pQuad->m_aPoints[4], &aRotated[2], Rot); - Rotate(&pQuad->m_aPoints[4], &aRotated[3], Rot); - } - - //Set Texture Coords - Graphics()->QuadsSetSubsetFree( - fx2f(pQuad->m_aTexcoords[0].x), fx2f(pQuad->m_aTexcoords[0].y), - fx2f(pQuad->m_aTexcoords[1].x), fx2f(pQuad->m_aTexcoords[1].y), - fx2f(pQuad->m_aTexcoords[2].x), fx2f(pQuad->m_aTexcoords[2].y), - fx2f(pQuad->m_aTexcoords[3].x), fx2f(pQuad->m_aTexcoords[3].y) - ); - - //Set Quad Coords & Draw - IGraphics::CFreeformItem Freeform( - fx2f(pPoints[0].x)+OffsetX, fx2f(pPoints[0].y)+OffsetY, - fx2f(pPoints[1].x)+OffsetX, fx2f(pPoints[1].y)+OffsetY, - fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY, - fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY); - Graphics()->QuadsDrawFreeform(&Freeform, 1); + if(!apEnvelope[j]) + continue; - Graphics()->QuadsEnd(); - - Graphics()->TextureSet(-1); - Graphics()->QuadsBegin(); - DoQuadEnvPoint(pQuad, Index, i); - Graphics()->QuadsEnd(); + //QuadParams + CPoint *pPoints = pQuad[j].m_aPoints; + + for(int i = 0; i < apEnvelope[j]->m_lPoints.size(); i++) + { + //Calc Env Position + float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); + float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]); + float Rot = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[2])/360.0f*pi*2; + + //Set Colours + float Alpha = (m_SelectedQuadEnvelope == pQuad[j].m_PosEnv && m_SelectedEnvelopePoint == i) ? 0.65f : 0.35f; + IGraphics::CColorVertex aArray[4] = { + IGraphics::CColorVertex(0, pQuad[j].m_aColors[0].r, pQuad[j].m_aColors[0].g, pQuad[j].m_aColors[0].b, Alpha), + IGraphics::CColorVertex(1, pQuad[j].m_aColors[1].r, pQuad[j].m_aColors[1].g, pQuad[j].m_aColors[1].b, Alpha), + IGraphics::CColorVertex(2, pQuad[j].m_aColors[2].r, pQuad[j].m_aColors[2].g, pQuad[j].m_aColors[2].b, Alpha), + IGraphics::CColorVertex(3, pQuad[j].m_aColors[3].r, pQuad[j].m_aColors[3].g, pQuad[j].m_aColors[3].b, Alpha)}; + Graphics()->SetColorVertex(aArray, 4); + + //Rotation + if(Rot != 0) + { + static CPoint aRotated[4]; + aRotated[0] = pQuad[j].m_aPoints[0]; + aRotated[1] = pQuad[j].m_aPoints[1]; + aRotated[2] = pQuad[j].m_aPoints[2]; + aRotated[3] = pQuad[j].m_aPoints[3]; + pPoints = aRotated; + + Rotate(&pQuad[j].m_aPoints[4], &aRotated[0], Rot); + Rotate(&pQuad[j].m_aPoints[4], &aRotated[1], Rot); + Rotate(&pQuad[j].m_aPoints[4], &aRotated[2], Rot); + Rotate(&pQuad[j].m_aPoints[4], &aRotated[3], Rot); + } + + //Set Texture Coords + Graphics()->QuadsSetSubsetFree( + fx2f(pQuad[j].m_aTexcoords[0].x), fx2f(pQuad[j].m_aTexcoords[0].y), + fx2f(pQuad[j].m_aTexcoords[1].x), fx2f(pQuad[j].m_aTexcoords[1].y), + fx2f(pQuad[j].m_aTexcoords[2].x), fx2f(pQuad[j].m_aTexcoords[2].y), + fx2f(pQuad[j].m_aTexcoords[3].x), fx2f(pQuad[j].m_aTexcoords[3].y) + ); + + //Set Quad Coords & Draw + IGraphics::CFreeformItem Freeform( + fx2f(pPoints[0].x)+OffsetX, fx2f(pPoints[0].y)+OffsetY, + fx2f(pPoints[1].x)+OffsetX, fx2f(pPoints[1].y)+OffsetY, + fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY, + fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY); + Graphics()->QuadsDrawFreeform(&Freeform, 1); + } + } + Graphics()->QuadsEnd(); + Graphics()->TextureClear(); + Graphics()->QuadsBegin(); + + // Draw QuadPoints + for(int j = 0; j < Num; j++) + { + if(!apEnvelope[j]) + continue; + + //QuadParams + CPoint *pPoints = pQuad[j].m_aPoints; + for(int i = 0; i < apEnvelope[j]->m_lPoints.size()-1; i++) + { + float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); + float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]); + vec2 Pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); + + OffsetX = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[0]); + OffsetY = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[1]); + vec2 Pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); + + DoQuadEnvPoint(&pQuad[j], j, i); + } } + Graphics()->QuadsEnd(); } void CEditor::DoQuadEnvPoint(CQuad *pQuad, int QIndex, int PIndex) @@ -2093,12 +2128,12 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size()) TexID = m_Map.m_lImages[pLayer->m_Image]->m_TexID; - for(int i = 0; i < pLayer->m_lQuads.size(); i++) + /*for(int i = 0; i < pLayer->m_lQuads.size(); i++) { if((m_ShowEnvelopePreview == 1 && pLayer->m_lQuads[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2) DoQuadEnvelopes(&pLayer->m_lQuads[i], i, TexID); - } - + }*/ + DoQuadEnvelopes(&pLayer->m_lQuads[0], pLayer->m_lQuads.size(), TexID); m_ShowEnvelopePreview = 0; } diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index a81474d9..2807d35c 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -761,7 +761,7 @@ public: vec4 ButtonColorMul(const void *pID); - void DoQuadEnvelopes(CQuad *pQuad, int Index, int TexID = -1); + void DoQuadEnvelopes(CQuad *pQuad, int Num, int TexID = -1); void DoQuadEnvPoint(CQuad *pQuad, int QIndex, int pIndex); void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v); diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 325d527b..032f391f 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -338,6 +338,7 @@ void CLayerTiles::ShowInfo() float ScreenX0, ScreenY0, ScreenX1, ScreenY1; Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); Graphics()->TextureSet(m_pEditor->Client()->GetDebugFont()); + Graphics()->QuadsBegin(); int StartY = max(0, (int)(ScreenY0/32.0f)-1); int StartX = max(0, (int)(ScreenX0/32.0f)-1); @@ -352,17 +353,18 @@ void CLayerTiles::ShowInfo() { char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%i", m_pTiles[c].m_Index); - m_pEditor->Graphics()->QuadsText(x*32, y*32, 16.0f, 1,1,1,1, aBuf); + m_pEditor->Graphics()->QuadsText(x*32, y*32, 16.0f, aBuf); char aFlags[4] = { m_pTiles[c].m_Flags&TILEFLAG_VFLIP ? 'V' : ' ', m_pTiles[c].m_Flags&TILEFLAG_HFLIP ? 'H' : ' ', m_pTiles[c].m_Flags&TILEFLAG_ROTATE? 'R' : ' ', 0}; - m_pEditor->Graphics()->QuadsText(x*32, y*32+16, 16.0f, 1,1,1,1, aFlags); + m_pEditor->Graphics()->QuadsText(x*32, y*32+16, 16.0f, aFlags); } x += m_pTiles[c].m_Skip; } + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } -- cgit 1.4.1 From 68390fe04afce9767b152eadaefd9a3bc8462854 Mon Sep 17 00:00:00 2001 From: BeaR Date: Tue, 13 Nov 2012 15:39:23 +0100 Subject: Bug: Losing render-commands if commandbuffer is full(gfx) Problem: If there is a new draw call, it is checked if there is enough free memory for the vertices in the databuffer but not if we have enough free space in the commandbuffer to add the command So we lose some commands during a frame cuz the commandbuffer is full This fixes the 2nd part of issue 1004 --- src/engine/client/graphics_threaded.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/engine') diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 8a3e4f50..50a116b4 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -81,7 +81,19 @@ void CGraphics_Threaded::FlushVertices() } mem_copy(Cmd.m_pVertices, m_aVertices, sizeof(CCommandBuffer::SVertex)*NumVerts); - m_pCommandBuffer->AddCommand(Cmd); + + // check if we have enough free memory in the commandbuffer + if(!m_pCommandBuffer->AddCommand(Cmd)) + { + // kick command buffer and try again + KickCommandBuffer(); + + if(!m_pCommandBuffer->AddCommand(Cmd)) + { + dbg_msg("graphics", "failed to allocate memory for render command"); + return; + } + } } void CGraphics_Threaded::AddVertices(int Count) -- cgit 1.4.1 From 73386fdf0f23563e1c4a92857810f8103407fd6b Mon Sep 17 00:00:00 2001 From: oy Date: Tue, 13 Nov 2012 21:37:46 +0100 Subject: fixed last commit --- src/engine/client/graphics_threaded.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 50a116b4..0357c41a 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -80,13 +80,18 @@ void CGraphics_Threaded::FlushVertices() } } - mem_copy(Cmd.m_pVertices, m_aVertices, sizeof(CCommandBuffer::SVertex)*NumVerts); - // check if we have enough free memory in the commandbuffer if(!m_pCommandBuffer->AddCommand(Cmd)) { // kick command buffer and try again KickCommandBuffer(); + + Cmd.m_pVertices = (CCommandBuffer::SVertex *)m_pCommandBuffer->AllocData(sizeof(CCommandBuffer::SVertex)*NumVerts); + if(Cmd.m_pVertices == 0x0) + { + dbg_msg("graphics", "failed to allocate data for vertices"); + return; + } if(!m_pCommandBuffer->AddCommand(Cmd)) { @@ -94,6 +99,8 @@ void CGraphics_Threaded::FlushVertices() return; } } + + mem_copy(Cmd.m_pVertices, m_aVertices, sizeof(CCommandBuffer::SVertex)*NumVerts); } void CGraphics_Threaded::AddVertices(int Count) -- cgit 1.4.1 From 07c97822bba0f7b59c911aab2d6e85f84785b6ed Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 20 Feb 2013 15:51:46 +0100 Subject: increased sleep time when tw is minimized and made it adjustable via cputhrottle otherwise --- src/engine/client/client.cpp | 6 +++--- src/engine/shared/config_variables.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index c481102b..30f92eb0 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1945,10 +1945,10 @@ void CClient::Run() break; // beNice - if(g_Config.m_DbgStress) + if(g_Config.m_ClCpuThrottle) + thread_sleep(g_Config.m_ClCpuThrottle); + else if(g_Config.m_DbgStress || !m_pGraphics->WindowActive()) thread_sleep(5); - else if(g_Config.m_ClCpuThrottle || !m_pGraphics->WindowActive()) - thread_sleep(1); if(g_Config.m_DbgHitch) { diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 659d1087..3215ee0e 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -15,7 +15,7 @@ MACRO_CONFIG_STR(Password, password, 32, "", CFGFLAG_CLIENT|CFGFLAG_SERVER, "Pas MACRO_CONFIG_STR(Logfile, logfile, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Filename to log all output to") MACRO_CONFIG_INT(ConsoleOutputLevel, console_output_level, 0, 0, 2, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Adjusts the amount of information in the console") -MACRO_CONFIG_INT(ClCpuThrottle, cl_cpu_throttle, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") +MACRO_CONFIG_INT(ClCpuThrottle, cl_cpu_throttle, 0, 0, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(ClEditor, cl_editor, 0, 0, 1, CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(ClLoadCountryFlags, cl_load_country_flags, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Load and show country flags") -- cgit 1.4.1 From 118d2ac837537cd625679a57aca03cd47f2e71a1 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 20 Feb 2013 16:49:21 +0100 Subject: show reason for closing a connection within a debug message. Closes #1061 --- src/engine/shared/network_conn.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/engine') diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index 24c8f066..cd2df048 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -214,27 +214,25 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr) m_State = NET_CONNSTATE_ERROR; m_RemoteClosed = 1; - if(!m_BlockCloseMsg) + char Str[128] = {0}; + if(pPacket->m_DataSize > 1) { - if(pPacket->m_DataSize) - { - // make sure to sanitize the error string form the other party - char Str[128]; - if(pPacket->m_DataSize < 128) - str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize); - else - str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str)); - str_sanitize_strong(Str); - - // set the error string - SetError(Str); - } + // make sure to sanitize the error string form the other party + if(pPacket->m_DataSize < 128) + str_copy(Str, (char *)&pPacket->m_aChunkData[1], pPacket->m_DataSize); else - SetError("No reason given"); + str_copy(Str, (char *)&pPacket->m_aChunkData[1], sizeof(Str)); + str_sanitize_strong(Str); + } + + if(!m_BlockCloseMsg) + { + // set the error string + SetError(Str); } if(g_Config.m_Debug) - dbg_msg("conn", "closed reason='%s'", ErrorString()); + dbg_msg("conn", "closed reason='%s'", Str); } return 0; } -- cgit 1.4.1 From 0e92dd560300a0b255b5c173e715f2714e7c1765 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 24 Feb 2013 18:55:55 +0100 Subject: fixed some merge problems --- src/engine/client/graphics.cpp | 7 +------ src/engine/client/graphics.h | 2 +- src/engine/client/graphics_threaded.cpp | 2 +- src/game/editor/editor.cpp | 4 ++-- src/game/server/gamemodes/ctf.cpp | 2 +- src/versionsrv/versionsrv.cpp | 1 + 6 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src/engine') diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 314669e2..3168903d 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -700,13 +700,10 @@ void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) AddVertices(4*Num); } -void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) +void CGraphics_OpenGL::QuadsText(float x, float y, float Size, const char *pText) { float StartX = x; - QuadsBegin(); - SetColor(r,g,b,a); - while(*pText) { char c = *pText; @@ -730,8 +727,6 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, x += Size/2; } } - - QuadsEnd(); } int CGraphics_OpenGL::Init() diff --git a/src/engine/client/graphics.h b/src/engine/client/graphics.h index fdd83aa7..670c22b4 100644 --- a/src/engine/client/graphics.h +++ b/src/engine/client/graphics.h @@ -119,7 +119,7 @@ public: virtual void QuadsDraw(CQuadItem *pArray, int Num); virtual void QuadsDrawTL(const CQuadItem *pArray, int Num); virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num); - virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText); + virtual void QuadsText(float x, float y, float Size, const char *pText); virtual int Init(); }; diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 0357c41a..e34b7259 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -277,7 +277,7 @@ int CGraphics_Threaded::UnloadTexture(int Index) Cmd.m_Slot = Index; m_pCommandBuffer->AddCommand(Cmd); - m_aTextures[Index] = m_FirstFreeTexture; + m_aTextureIndices[Index] = m_FirstFreeTexture; m_FirstFreeTexture = Index; return 0; } diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index ccd1757f..28a4eda9 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1449,7 +1449,7 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, int TexID) Graphics()->LinesEnd(); //Draw Quads - Graphics()->TextureSet(Texture); + Graphics()->TextureSet(TexID); Graphics()->QuadsBegin(); for(int j = 0; j < Num; j++) @@ -1510,7 +1510,7 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, int TexID) } } Graphics()->QuadsEnd(); - Graphics()->TextureClear(); + Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); // Draw QuadPoints diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index 9e45c1fe..140dadf9 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -98,7 +98,7 @@ bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID) for(int fi = 0; fi < 2; fi++) { CFlag *F = m_apFlags[fi]; - if(F->m_pCarryingCharacter == Character) + if(F && F->m_pCarryingCharacter == Character) return false; } } diff --git a/src/versionsrv/versionsrv.cpp b/src/versionsrv/versionsrv.cpp index da55e717..9d6e2960 100644 --- a/src/versionsrv/versionsrv.cpp +++ b/src/versionsrv/versionsrv.cpp @@ -7,6 +7,7 @@ #include #include "versionsrv.h" +#include "mapversions.h" enum { MAX_MAPS_PER_PACKET=48, -- cgit 1.4.1 From 313a0949b0c4d077e61051fd773208d889649c37 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 24 Feb 2013 18:57:23 +0100 Subject: make sure clients are authed for map downloads --- src/engine/server/server.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/engine') diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 4b7f6332..581c7e67 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -841,6 +841,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) } else if(Msg == NETMSG_REQUEST_MAP_DATA) { + if(m_aClients[ClientID].m_State < CClient::STATE_CONNECTING) + return; + int Chunk = Unpacker.GetInt(); int ChunkSize = 1024-128; int Offset = Chunk * ChunkSize; -- cgit 1.4.1 From ea2898e94a6d50e326cb68976d9fabbc378a3b9d Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 24 Feb 2013 19:13:45 +0100 Subject: prevent quick join/quit flood. #1070 --- src/engine/shared/network.h | 1 + src/engine/shared/network_server.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/engine') diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index fbe4d391..259d600f 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -188,6 +188,7 @@ public: // Needed for GotProblems in NetClient int64 LastRecvTime() const { return m_LastRecvTime; } + int64 ConnectTime() const { return m_LastUpdateTime; } int AckSequence() const { return m_Ack; } }; diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index add51c9b..bdc10935 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -69,11 +69,17 @@ int CNetServer::Drop(int ClientID, const char *pReason) int CNetServer::Update() { + int64 Now = time_get(); for(int i = 0; i < MaxClients(); i++) { m_aSlots[i].m_Connection.Update(); if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR) - Drop(i, m_aSlots[i].m_Connection.ErrorString()); + { + if(Now - m_aSlots[i].m_Connection.ConnectTime() < time_freq()/2 && NetBan()) + NetBan()->BanAddr(ClientAddr(i), 60, "Stressing network"); + else + Drop(i, m_aSlots[i].m_Connection.ErrorString()); + } } return 0; -- cgit 1.4.1 From 718653ff85e8cfbda407ccc467dcbfc36895b16c Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 24 Feb 2013 19:18:13 +0100 Subject: set default values for threaded graphics and async renderer to 0 --- src/engine/shared/config_variables.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/engine') diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 3215ee0e..47327296 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -72,9 +72,9 @@ MACRO_CONFIG_INT(GfxTextureQuality, gfx_texture_quality, 1, 0, 1, CFGFLAG_SAVE|C MACRO_CONFIG_INT(GfxFsaaSamples, gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE|CFGFLAG_CLIENT, "FSAA Samples") MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen refresh rate") MACRO_CONFIG_INT(GfxFinish, gfx_finish, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(GfxAsyncRender, gfx_asyncrender, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Do rendering async from the the update") +MACRO_CONFIG_INT(GfxAsyncRender, gfx_asyncrender, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Do rendering async from the the update") -MACRO_CONFIG_INT(GfxThreaded, gfx_threaded, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use the threaded graphics backend") +MACRO_CONFIG_INT(GfxThreaded, gfx_threaded, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use the threaded graphics backend") MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity") -- cgit 1.4.1 From ebdd1af7a3fbf609f7123e8355f18ca980b1921e Mon Sep 17 00:00:00 2001 From: PsychoGod Date: Mon, 25 Feb 2013 13:48:31 +0200 Subject: window center position when windowed on Windows :3 --- src/engine/client/backend_sdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/engine') diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 6fa6de01..37d1019a 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -499,7 +499,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height #ifdef CONF_FAMILY_WINDOWS if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention - putenv("SDL_VIDEO_WINDOW_POS=8,27"); // ignore_convention + putenv("SDL_VIDEO_WINDOW_POS=center"); // ignore_convention #endif } -- cgit 1.4.1 From 5e090fbfed8af54a98a6ab71d895fad04d1bf398 Mon Sep 17 00:00:00 2001 From: oy Date: Tue, 26 Feb 2013 00:00:38 +0100 Subject: made the demoplayer support 0.6.1 based demos --- src/engine/demo.h | 4 ++++ src/engine/shared/demo.cpp | 30 ++++++++++++++++++------------ src/engine/shared/demo.h | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/engine') diff --git a/src/engine/demo.h b/src/engine/demo.h index 7b7365c7..bd4a307a 100644 --- a/src/engine/demo.h +++ b/src/engine/demo.h @@ -21,6 +21,10 @@ struct CDemoHeader char m_aType[8]; char m_aLength[4]; char m_aTimestamp[20]; +}; + +struct CTimelineMarkers +{ char m_aNumTimelineMarkers[4]; char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][4]; }; diff --git a/src/engine/shared/demo.cpp b/src/engine/shared/demo.cpp index 37c82cce..953d8b56 100644 --- a/src/engine/shared/demo.cpp +++ b/src/engine/shared/demo.cpp @@ -14,6 +14,7 @@ static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0}; static const unsigned char gs_ActVersion = 4; +static const unsigned char gs_OldVersion = 3; static const int gs_LengthOffset = 152; static const int gs_NumMarkersOffset = 176; @@ -29,6 +30,7 @@ CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta) int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, unsigned Crc, const char *pType) { CDemoHeader Header; + CTimelineMarkers TimelineMarkers; if(m_File) return -1; @@ -90,9 +92,8 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con str_copy(Header.m_aType, pType, sizeof(Header.m_aType)); // Header.m_Length - add this on stop str_timestamp(Header.m_aTimestamp, sizeof(Header.m_aTimestamp)); - // Header.m_aNumTimelineMarkers - add this on stop - // Header.m_aTimelineMarkers - add this on stop io_write(DemoFile, &Header, sizeof(Header)); + io_write(DemoFile, &TimelineMarkers, sizeof(TimelineMarkers)); // fill this on stop // write map data while(1) @@ -615,7 +616,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const return -1; } - if(m_Info.m_Header.m_Version < gs_ActVersion) + if(m_Info.m_Header.m_Version < gs_OldVersion) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "demo version %d is not supported", m_Info.m_Header.m_Version); @@ -624,6 +625,8 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const m_File = 0; return -1; } + else if(m_Info.m_Header.m_Version > gs_OldVersion) + io_read(m_File, &m_Info.m_TimelineMarkers, sizeof(m_Info.m_TimelineMarkers)); // get demo type if(!str_comp(m_Info.m_Header.m_aType, "client")) @@ -663,15 +666,18 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const mem_free(pMapData); } - // get timeline markers - int Num = ((m_Info.m_Header.m_aNumTimelineMarkers[0]<<24)&0xFF000000) | ((m_Info.m_Header.m_aNumTimelineMarkers[1]<<16)&0xFF0000) | - ((m_Info.m_Header.m_aNumTimelineMarkers[2]<<8)&0xFF00) | (m_Info.m_Header.m_aNumTimelineMarkers[3]&0xFF); - m_Info.m_Info.m_NumTimelineMarkers = Num; - for(int i = 0; i < Num && i < MAX_TIMELINE_MARKERS; i++) + if(m_Info.m_Header.m_Version > gs_OldVersion) { - char *pTimelineMarker = m_Info.m_Header.m_aTimelineMarkers[i]; - m_Info.m_Info.m_aTimelineMarkers[i] = ((pTimelineMarker[0]<<24)&0xFF000000) | ((pTimelineMarker[1]<<16)&0xFF0000) | - ((pTimelineMarker[2]<<8)&0xFF00) | (pTimelineMarker[3]&0xFF); + // get timeline markers + int Num = ((m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[0]<<24)&0xFF000000) | ((m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[1]<<16)&0xFF0000) | + ((m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[2]<<8)&0xFF00) | (m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[3]&0xFF); + m_Info.m_Info.m_NumTimelineMarkers = Num; + for(int i = 0; i < Num && i < MAX_TIMELINE_MARKERS; i++) + { + char *pTimelineMarker = m_Info.m_TimelineMarkers.m_aTimelineMarkers[i]; + m_Info.m_Info.m_aTimelineMarkers[i] = ((pTimelineMarker[0]<<24)&0xFF000000) | ((pTimelineMarker[1]<<16)&0xFF0000) | + ((pTimelineMarker[2]<<8)&0xFF00) | (pTimelineMarker[3]&0xFF); + } } // scan the file for interessting points @@ -843,7 +849,7 @@ bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, i return false; io_read(File, pDemoHeader, sizeof(CDemoHeader)); - if(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_ActVersion) + if(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_OldVersion) { io_close(File); return false; diff --git a/src/engine/shared/demo.h b/src/engine/shared/demo.h index 760e7256..d27f4ab6 100644 --- a/src/engine/shared/demo.h +++ b/src/engine/shared/demo.h @@ -51,6 +51,7 @@ public: struct CPlaybackInfo { CDemoHeader m_Header; + CTimelineMarkers m_TimelineMarkers; IDemoPlayer::CInfo m_Info; -- cgit 1.4.1 From 471d479300cf7ec34daaca5576040ef25045ea94 Mon Sep 17 00:00:00 2001 From: PsychoGod Date: Sun, 3 Mar 2013 13:42:25 +0200 Subject: one more centering window in graphics --- src/engine/client/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/engine') diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 3168903d..2e8a855d 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -900,7 +900,7 @@ int CGraphics_SDL::Init() #ifdef CONF_FAMILY_WINDOWS if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention - putenv("SDL_VIDEO_WINDOW_POS=8,27"); // ignore_convention + putenv("SDL_VIDEO_WINDOW_POS=center"); // ignore_convention #endif if(InitWindow() != 0) -- cgit 1.4.1