diff options
| author | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
| commit | 06115dd49dca2f8eb5f14606437e8fd20037cc4d (patch) | |
| tree | 5ec4bca6158319b3f5285d7689c5f94ae8da8c93 /src/engine/client | |
| parent | 63e059b8fff6498e42b765a1dca000e53005ea77 (diff) | |
| download | zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.tar.gz zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.zip | |
added "Whitespace and line Endings cleanup" by GreYFoX
Diffstat (limited to 'src/engine/client')
| -rw-r--r-- | src/engine/client/client.cpp | 14 | ||||
| -rw-r--r-- | src/engine/client/friends.h | 8 | ||||
| -rw-r--r-- | src/engine/client/graphics.cpp | 140 | ||||
| -rw-r--r-- | src/engine/client/graphics.h | 26 | ||||
| -rw-r--r-- | src/engine/client/input.cpp | 2 | ||||
| -rw-r--r-- | src/engine/client/serverbrowser.cpp | 8 | ||||
| -rw-r--r-- | src/engine/client/serverbrowser.h | 2 | ||||
| -rw-r--r-- | src/engine/client/text.cpp | 160 |
8 files changed, 180 insertions, 180 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 5cce547e..61a96eee 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -545,7 +545,7 @@ void CClient::RconAuth(const char *pName, const char *pPassword) { if(RconAuthed()) return; - + CMsgPacker Msg(NETMSG_RCON_AUTH); Msg.AddString(pName, 32); Msg.AddString(pPassword, 32); @@ -860,7 +860,7 @@ void CClient::DebugRender() total = 42 */ FrameTimeAvg = FrameTimeAvg*0.9f + m_FrameTime*0.1f; - str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d", + str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d", m_CurGameTick, m_PredTick, mem_stats()->allocated/1024, mem_stats()->total_allocations, @@ -1030,7 +1030,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket) // version info if(pPacket->m_DataSize == (int)(sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)) && mem_comp(pPacket->m_pData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)) == 0) - + { unsigned char *pVersionData = (unsigned char*)pPacket->m_pData + sizeof(VERSIONSRV_VERSION); int VersionMatch = !mem_comp(pVersionData, VERSION_DATA, sizeof(VERSION_DATA)); @@ -1060,7 +1060,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket) // map version list if(pPacket->m_DataSize >= (int)sizeof(VERSIONSRV_MAPLIST) && - mem_comp(pPacket->m_pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST)) == 0) + mem_comp(pPacket->m_pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST)) == 0) { int Size = pPacket->m_DataSize-sizeof(VERSIONSRV_MAPLIST); int Num = Size/sizeof(CMapVersion); @@ -1114,7 +1114,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket) mem_copy(Addr.ip, pAddrs[i].m_aIp, sizeof(Addr.ip)); } Addr.port = (pAddrs[i].m_aPort[0]<<8) | pAddrs[i].m_aPort[1]; - + m_ServerBrowser.Set(Addr, IServerBrowser::SET_MASTER_ADD, -1, 0x0); } } @@ -1125,7 +1125,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket) // we got ze info CUnpacker Up; CServerInfo Info = {0}; - + Up.Reset((unsigned char*)pPacket->m_pData+sizeof(SERVERBROWSE_INFO), pPacket->m_DataSize-sizeof(SERVERBROWSE_INFO)); int Token = str_toint(Up.GetString()); str_copy(Info.m_aVersion, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aVersion)); @@ -1282,7 +1282,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket) if(!pError) { m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", "loading done"); - SendReady(); + SendReady(); } else DisconnectWithReason(pError); diff --git a/src/engine/client/friends.h b/src/engine/client/friends.h index e3258ec2..be0cfa49 100644 --- a/src/engine/client/friends.h +++ b/src/engine/client/friends.h @@ -14,14 +14,14 @@ class CFriends : public IFriends static void ConRemoveFriend(IConsole::IResult *pResult, void *pUserData); static void ConfigSaveCallback(IConfig *pConfig, void *pUserData); - + public: CFriends(); - + void Init(); - + int NumFriends() const { return m_NumFriends; } - const CFriendInfo *GetFriend(int Index) const; + const CFriendInfo *GetFriend(int Index) const; bool IsFriend(const char *pName, const char *pClan, bool PlayersOnly) const; void AddFriend(const char *pName, const char *pClan); diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 99f5e095..641f9dfb 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -50,7 +50,7 @@ static CVideoMode g_aFakeModes[] = { {1800,1440,8,8,8}, {1856,1392,8,8,8}, {1920,1080,8,8,8}, {1920,1200,8,8,8}, {1920,1440,8,8,8}, {1920,2400,8,8,8}, {2048,1536,8,8,8}, - + {320,240,5,6,5}, {400,300,5,6,5}, {640,480,5,6,5}, {720,400,5,6,5}, {768,576,5,6,5}, {800,600,5,6,5}, {1024,600,5,6,5}, {1024,768,5,6,5}, {1152,864,5,6,5}, @@ -67,7 +67,7 @@ void CGraphics_OpenGL::Flush() { if(m_NumVertices == 0) return; - + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -83,7 +83,7 @@ void CGraphics_OpenGL::Flush() glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - + if(m_RenderEnable) { if(m_Drawing == DRAWING_QUADS) @@ -91,7 +91,7 @@ void CGraphics_OpenGL::Flush() else if(m_Drawing == DRAWING_LINES) glDrawArrays(GL_LINES, 0, m_NumVertices); } - + // Reset pointer m_NumVertices = 0; } @@ -125,26 +125,26 @@ unsigned char CGraphics_OpenGL::Sample(int w, int h, const unsigned char *pData, pData[(v*w+u+1)*4+Offset]+ pData[((v+1)*w+u)*4+Offset]+ pData[((v+1)*w+u+1)*4+Offset])/4; -} +} CGraphics_OpenGL::CGraphics_OpenGL() { m_NumVertices = 0; - + m_ScreenX0 = 0; m_ScreenY0 = 0; m_ScreenX1 = 0; m_ScreenY1 = 0; - + m_ScreenWidth = -1; m_ScreenHeight = -1; - + m_Rotation = 0; m_Drawing = 0; m_InvalidTexture = 0; - + m_TextureMemoryUsage = 0; - + m_RenderEnable = true; m_DoScreenshot = false; } @@ -161,7 +161,7 @@ void CGraphics_OpenGL::ClipDisable() //if(no_gfx) return; glDisable(GL_SCISSOR_TEST); } - + void CGraphics_OpenGL::BlendNone() { glDisable(GL_BLEND); @@ -180,10 +180,10 @@ void CGraphics_OpenGL::BlendAdditive() } int CGraphics_OpenGL::MemoryUsage() const -{ +{ return m_TextureMemoryUsage; -} - +} + void CGraphics_OpenGL::MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) { m_ScreenX0 = TopLeftX; @@ -220,7 +220,7 @@ void CGraphics_OpenGL::LinesEnd() void CGraphics_OpenGL::LinesDraw(const CLineItem *pArray, int Num) { dbg_assert(m_Drawing == DRAWING_LINES, "called draw without begin"); - + for(int i = 0; i < Num; ++i) { m_aVertices[m_NumVertices + 2*i].m_Pos.x = pArray[i].m_X0; @@ -241,10 +241,10 @@ int CGraphics_OpenGL::UnloadTexture(int Index) { if(Index == m_InvalidTexture) return 0; - + if(Index < 0) return 0; - + glDeleteTextures(1, &m_aTextures[Index].m_Tex); m_aTextures[Index].m_Next = m_FirstFreeTexture; m_TextureMemoryUsage -= m_aTextures[Index].m_MemSize; @@ -261,16 +261,16 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo int Oglformat = 0; int StoreOglformat = 0; int Tex = 0; - + // don't waste memory on texture if we are stress testing if(g_Config.m_DbgStress) return m_InvalidTexture; - + // grab texture Tex = m_FirstFreeTexture; m_FirstFreeTexture = m_aTextures[Tex].m_Next; m_aTextures[Tex].m_Next = -1; - + // resample if needed if(!(Flags&TEXLOAD_NORESAMPLE) && g_Config.m_GfxTextureQuality==0) { @@ -296,13 +296,13 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo pTexData = pTmpData; } } - + Oglformat = GL_RGBA; if(Format == CImageInfo::FORMAT_RGB) Oglformat = GL_RGB; else if(Format == CImageInfo::FORMAT_ALPHA) Oglformat = GL_ALPHA; - + // upload texture if(g_Config.m_GfxTextureCompression) { @@ -320,13 +320,13 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo else if(StoreFormat == CImageInfo::FORMAT_ALPHA) StoreOglformat = GL_ALPHA; } - + glGenTextures(1, &m_aTextures[Tex].m_Tex); glBindTexture(GL_TEXTURE_2D, m_aTextures[Tex].m_Tex); 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, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData); - + // calculate memory usage { int PixelSize = 4; @@ -346,7 +346,7 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo } } } - + m_TextureMemoryUsage += m_aTextures[Tex].m_MemSize; mem_free(pTmpData); return Tex; @@ -358,7 +358,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int St int l = str_length(pFilename); int ID; CImageInfo Img; - + if(l < 3) return -1; if(LoadPNG(&Img, pFilename, StorageType)) @@ -370,7 +370,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int St mem_free(Img.m_pData); return ID; } - + return m_InvalidTexture; } @@ -379,7 +379,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora char aCompleteFilename[512]; unsigned char *pBuffer; png_t Png; // ignore_convention - + // open file for reading png_init(0,0); // ignore_convention @@ -391,7 +391,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora dbg_msg("game/png", "failed to open file. filename='%s'", pFilename); return 0; } - + int Error = png_open_file(&Png, aCompleteFilename); // ignore_convention if(Error != PNG_NO_ERROR) { @@ -400,18 +400,18 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora png_close_file(&Png); // ignore_convention return 0; } - + if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA)) // ignore_convention { dbg_msg("game/png", "invalid format. filename='%s'", aCompleteFilename); png_close_file(&Png); // ignore_convention return 0; } - + pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp, 1); // ignore_convention png_get_data(&Png, pBuffer); // ignore_convention png_close_file(&Png); // ignore_convention - + pImg->m_Width = Png.width; // ignore_convention pImg->m_Height = Png.height; // ignore_convention if(Png.color_type == PNG_TRUECOLOR) // ignore_convention @@ -435,7 +435,7 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename) glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0,0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData); glPixelStorei(GL_PACK_ALIGNMENT, Alignment); - + // flip the pixel because opengl works from bottom left corner for(y = 0; y < h/2; y++) { @@ -443,16 +443,16 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename) mem_copy(pPixelData+y*w*3, pPixelData+(h-y-1)*w*3, w*3); mem_copy(pPixelData+(h-y-1)*w*3, pTempRow,w*3); } - + // find filename { char aWholePath[1024]; png_t Png; // ignore_convention - IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath)); + IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath)); if(File) io_close(File); - + // save png char aBuf[256]; str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath); @@ -490,7 +490,7 @@ void CGraphics_OpenGL::QuadsBegin() { dbg_assert(m_Drawing == 0, "called quads_begin twice"); m_Drawing = DRAWING_QUADS; - + QuadsSetSubset(0,0,1,1); QuadsSetRotation(0); SetColor(1,1,1,1); @@ -609,7 +609,7 @@ void CGraphics_OpenGL::QuadsDrawTL(const CQuadItem *pArray, int Num) void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) { dbg_assert(m_Drawing == DRAWING_QUADS, "called quads_draw_freeform without begin"); - + for(int i = 0; i < Num; ++i) { m_aVertices[m_NumVertices + 4*i].m_Pos.x = pArray[i].m_X0; @@ -632,7 +632,7 @@ void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) m_aVertices[m_NumVertices + 4*i + 3].m_Tex = m_aTexture[2]; m_aVertices[m_NumVertices + 4*i + 3].m_Color = m_aColor[2]; } - + AddVertices(4*Num); } @@ -647,7 +647,7 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, { char c = *pText; pText++; - + if(c == '\n') { x = StartX; @@ -660,13 +660,13 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, (c/16)/16.0f, (c%16)/16.0f+1.0f/16.0f, (c/16)/16.0f+1.0f/16.0f); - + CQuadItem QuadItem(x, y, Size, Size); QuadsDrawTL(&QuadItem, 1); x += Size/2; } } - + QuadsEnd(); } @@ -674,7 +674,7 @@ bool CGraphics_OpenGL::Init() { m_pStorage = Kernel()->RequestInterface<IStorage>(); m_pConsole = Kernel()->RequestInterface<IConsole>(); - + // Set all z to -5.0f for(int i = 0; i < MAX_VERTICES; i++) m_aVertices[i].m_Pos.z = -5.0f; @@ -691,21 +691,21 @@ bool CGraphics_OpenGL::Init() glDisable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + glAlphaFunc(GL_GREATER, 0); glEnable(GL_ALPHA_TEST); glDepthMask(0); // create null texture, will get id=0 static const unsigned char aNullTextureData[] = { - 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, - 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, + 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, + 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, }; - + m_InvalidTexture = LoadTextureRaw(4,4,CImageInfo::FORMAT_RGBA,aNullTextureData,CImageInfo::FORMAT_RGBA,TEXLOAD_NORESAMPLE); - + return true; } @@ -713,7 +713,7 @@ int CGraphics_SDL::TryInit() { const SDL_VideoInfo *pInfo; int Flags = SDL_OPENGL; - + m_ScreenWidth = g_Config.m_GfxScreenWidth; m_ScreenHeight = g_Config.m_GfxScreenHeight; @@ -721,7 +721,7 @@ int CGraphics_SDL::TryInit() SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // set flags - Flags = SDL_OPENGL; + Flags = SDL_OPENGL; Flags |= SDL_GL_DOUBLEBUFFER; Flags |= SDL_HWPALETTE; if(g_Config.m_DbgResizable) @@ -755,7 +755,7 @@ int CGraphics_SDL::TryInit() // set caption SDL_WM_SetCaption("Teeworlds", "Teeworlds"); - + // create window m_pScreenSurface = SDL_SetVideoMode(m_ScreenWidth, m_ScreenHeight, 0, Flags); if(m_pScreenSurface == NULL) @@ -763,7 +763,7 @@ int CGraphics_SDL::TryInit() dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError()); return -1; } - + return 0; } @@ -772,12 +772,12 @@ int CGraphics_SDL::InitWindow() { if(TryInit() == 0) return 0; - + // try disabling fsaa while(g_Config.m_GfxFsaaSamples) { g_Config.m_GfxFsaaSamples--; - + if(g_Config.m_GfxFsaaSamples) dbg_msg("gfx", "lowering FSAA to %d and trying again", g_Config.m_GfxFsaaSamples); else @@ -799,8 +799,8 @@ int CGraphics_SDL::InitWindow() } dbg_msg("gfx", "out of ideas. failed to init graphics"); - - return -1; + + return -1; } @@ -813,34 +813,34 @@ bool CGraphics_SDL::Init() { { int Systems = SDL_INIT_VIDEO; - + if(g_Config.m_SndEnable) Systems |= SDL_INIT_AUDIO; if(g_Config.m_ClEventthread) Systems |= SDL_INIT_EVENTTHREAD; - + if(SDL_Init(Systems) < 0) { dbg_msg("gfx", "unable to init SDL: %s", SDL_GetError()); return true; } } - + atexit(SDL_Quit); // ignore_convention #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 #endif - + if(InitWindow() != 0) return true; SDL_ShowCursor(0); - + CGraphics_OpenGL::Init(); - + MapScreen(0,0,g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight); return false; } @@ -887,11 +887,11 @@ void CGraphics_SDL::Swap() ScreenshotDirect(m_aScreenshotName); m_DoScreenshot = false; } - + SDL_GL_SwapBuffers(); - + if(g_Config.m_GfxFinish) - glFinish(); + glFinish(); } @@ -908,9 +908,9 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes) Count = MaxModes; return Count; } - + // TODO: fix this code on osx or windows - + ppModes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN); if(ppModes == NULL) { @@ -936,7 +936,7 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes) NumModes++; } } - + return NumModes; } diff --git a/src/engine/client/graphics.h b/src/engine/client/graphics.h index 20be3504..4367ccfc 100644 --- a/src/engine/client/graphics.h +++ b/src/engine/client/graphics.h @@ -8,7 +8,7 @@ class CGraphics_OpenGL : public IEngineGraphics protected: class IStorage *m_pStorage; class IConsole *m_pConsole; - + // typedef struct { float x, y, z; } CPoint; typedef struct { float u, v; } CTexCoord; @@ -20,14 +20,14 @@ protected: CTexCoord m_Tex; CColor m_Color; } CVertex; - + enum { MAX_VERTICES = 32*1024, MAX_TEXTURES = 1024*4, - + DRAWING_QUADS=1, - DRAWING_LINES=2 + DRAWING_LINES=2 }; CVertex m_aVertices[MAX_VERTICES]; @@ -65,27 +65,27 @@ protected: void Flush(); void AddVertices(int Count); void Rotate4(const CPoint &rCenter, CVertex *pPoints); - + static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset); public: CGraphics_OpenGL(); - + virtual void ClipEnable(int x, int y, int w, int h); virtual void ClipDisable(); - + virtual void BlendNone(); virtual void BlendNormal(); virtual void BlendAdditive(); virtual int MemoryUsage() const; - + virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY); virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY); virtual void LinesBegin(); virtual void LinesEnd(); virtual void LinesDraw(const CLineItem *pArray, int Num); - + virtual int UnloadTexture(int Index); virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags); @@ -115,14 +115,14 @@ public: 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 bool Init(); }; class CGraphics_SDL : public CGraphics_OpenGL { - SDL_Surface *m_pScreenSurface; - + SDL_Surface *m_pScreenSurface; + int TryInit(); int InitWindow(); public: @@ -141,7 +141,7 @@ public: virtual void Swap(); virtual int GetVideoModes(CVideoMode *pModes, int MaxModes); - + }; #endif diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp index 5cd58342..0b4a44a4 100644 --- a/src/engine/client/input.cpp +++ b/src/engine/client/input.cpp @@ -154,7 +154,7 @@ int CInput::Update() // skip private use area of the BMP(contains the unicodes for keyboard function keys on MacOS) if(Event.key.keysym.unicode < 0xE000 || Event.key.keysym.unicode > 0xF8FF) // ignore_convention AddEvent(Event.key.keysym.unicode, 0, 0); // ignore_convention - Key = Event.key.keysym.sym; // ignore_convention + Key = Event.key.keysym.sym; // ignore_convention break; case SDL_KEYUP: Action = IInput::FLAG_RELEASE; diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 436c8c15..64d06116 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -86,7 +86,7 @@ bool CServerBrowser::SortCompareName(int Index1, int Index2) const CServerEntry *a = m_ppServerlist[Index1]; CServerEntry *b = m_ppServerlist[Index2]; // make sure empty entries are listed last - return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp(a->m_Info.m_aName, b->m_Info.m_aName) < 0 : + return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp(a->m_Info.m_aName, b->m_Info.m_aName) < 0 : a->m_GotInfo ? true : false; } @@ -535,7 +535,7 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons Packet.m_Flags = NETSENDFLAG_CONNLESS; Packet.m_DataSize = sizeof(Buffer); Packet.m_pData = Buffer; - + m_pNetClient->Send(&Packet); if(pEntry) @@ -659,7 +659,7 @@ void CServerBrowser::AddFavorite(const NETADDR &Addr) if(pEntry) pEntry->m_Info.m_Favorite = 1; - if(g_Config.m_Debug) + if(g_Config.m_Debug) { char aAddrStr[NETADDR_MAXSTRSIZE]; net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); @@ -705,7 +705,7 @@ int CServerBrowser::LoadingProgression() const { if(m_NumServers == 0) return 0; - + int Servers = m_NumServers; int Loaded = m_NumServers-m_NumRequests; return 100.0f * Loaded/Servers; diff --git a/src/engine/client/serverbrowser.h b/src/engine/client/serverbrowser.h index e0d39aad..a9111d15 100644 --- a/src/engine/client/serverbrowser.h +++ b/src/engine/client/serverbrowser.h @@ -103,7 +103,7 @@ private: CServerEntry *Find(const NETADDR &Addr); CServerEntry *Add(const NETADDR &Addr); - + void RemoveRequest(CServerEntry *pEntry); void QueueRequest(CServerEntry *pEntry); diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index da91980d..b0896b92 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -36,7 +36,7 @@ static int aFontSizes[] = {8,9,10,11,12,13,14,15,16,17,18,19,20,36,64}; struct CFontChar { int m_ID; - + // these values are scaled to the pFont size // width * font_size == real_size float m_Width; @@ -44,7 +44,7 @@ struct CFontChar float m_OffsetX; float m_OffsetY; float m_AdvanceX; - + float m_aUvs[4]; int64 m_TouchTime; }; @@ -57,16 +57,16 @@ struct CFontSizeData GLuint m_aTextures[2]; int m_TextureWidth; int m_TextureHeight; - + int m_NumXChars; int m_NumYChars; - + int m_CharMaxWidth; int m_CharMaxHeight; - + CFontChar m_aCharacters[MAX_CHARACTERS*MAX_CHARACTERS]; - - int m_CurrentCharacter; + + int m_CurrentCharacter; }; class CFont @@ -82,7 +82,7 @@ class CTextRender : public IEngineTextRender { IGraphics *m_pGraphics; IGraphics *Graphics() { return m_pGraphics; } - + int WordLength(const char *pText) { int s = 1; @@ -106,13 +106,13 @@ class CTextRender : public IEngineTextRender float m_TextOutlineG; float m_TextOutlineB; float m_TextOutlineA; - + int m_FontTextureFormat; CFont *m_pDefaultFont; FT_Library m_FTLibrary; - + int GetFontSizeIndex(int Pixelsize) { for(unsigned i = 0; i < NUM_FONT_SIZES; i++) @@ -120,18 +120,18 @@ class CTextRender : public IEngineTextRender if(aFontSizes[i] >= Pixelsize) return i; } - + return NUM_FONT_SIZES-1; } - + void Grow(unsigned char *pIn, unsigned char *pOut, int w, int h) { - for(int y = 0; y < h; y++) - for(int x = 0; x < w; x++) - { - int c = pIn[y*w+x]; + for(int y = 0; y < h; y++) + for(int x = 0; x < w; x++) + { + int c = pIn[y*w+x]; for(int sy = -1; sy <= 1; sy++) for(int sx = -1; sx <= 1; sx++) @@ -142,7 +142,7 @@ class CTextRender : public IEngineTextRender { int Index = GetY*w+GetX; if(pIn[Index] > c) - c = pIn[Index]; + c = pIn[Index]; } } @@ -157,18 +157,18 @@ class CTextRender : public IEngineTextRender int Height = CharHeight*Ychars; void *pMem = mem_alloc(Width*Height, 1); mem_zero(pMem, Width*Height); - + if(pSizeData->m_aTextures[0] == 0) glGenTextures(2, pSizeData->m_aTextures); else FontMemoryUsage -= pSizeData->m_TextureWidth*pSizeData->m_TextureHeight*2; - + pSizeData->m_NumXChars = Xchars; pSizeData->m_NumYChars = Ychars; pSizeData->m_TextureWidth = Width; pSizeData->m_TextureHeight = Height; pSizeData->m_CurrentCharacter = 0; - + for(int i = 0; i < 2; i++) { glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[i]); @@ -177,9 +177,9 @@ class CTextRender : public IEngineTextRender glTexImage2D(GL_TEXTURE_2D, 0, m_FontTextureFormat, Width, Height, 0, m_FontTextureFormat, GL_UNSIGNED_BYTE, pMem); FontMemoryUsage += Width*Height; } - + dbg_msg("", "pFont memory usage: %d", FontMemoryUsage); - + mem_free(pMem); } @@ -198,43 +198,43 @@ class CTextRender : public IEngineTextRender pSizeData->m_NumXChars <<= 1; else pSizeData->m_NumYChars <<= 1; - InitTexture(pSizeData, pSizeData->m_CharMaxWidth, pSizeData->m_CharMaxHeight, pSizeData->m_NumXChars, pSizeData->m_NumYChars); + InitTexture(pSizeData, pSizeData->m_CharMaxWidth, pSizeData->m_CharMaxHeight, pSizeData->m_NumXChars, pSizeData->m_NumYChars); } - - + + // TODO: Refactor: move this into a pFont class void InitIndex(CFont *pFont, int Index) { CFontSizeData *pSizeData = &pFont->m_aSizes[Index]; - + pSizeData->m_FontSize = aFontSizes[Index]; FT_Set_Pixel_Sizes(pFont->m_FtFace, 0, pSizeData->m_FontSize); - + int OutlineThickness = AdjustOutlineThicknessToFontSize(1, pSizeData->m_FontSize); - + { unsigned GlyphIndex; int MaxH = 0; int MaxW = 0; - + int Charcode = FT_Get_First_Char(pFont->m_FtFace, &GlyphIndex); while(GlyphIndex != 0) - { + { // do stuff FT_Load_Glyph(pFont->m_FtFace, GlyphIndex, FT_LOAD_DEFAULT); - + if(pFont->m_FtFace->glyph->metrics.width > MaxW) MaxW = pFont->m_FtFace->glyph->metrics.width; // ignore_convention if(pFont->m_FtFace->glyph->metrics.height > MaxH) MaxH = pFont->m_FtFace->glyph->metrics.height; // ignore_convention Charcode = FT_Get_Next_Char(pFont->m_FtFace, Charcode, &GlyphIndex); } - + MaxW = (MaxW>>6)+2+OutlineThickness*2; MaxH = (MaxH>>6)+2+OutlineThickness*2; - + for(pSizeData->m_CharMaxWidth = 1; pSizeData->m_CharMaxWidth < MaxW; pSizeData->m_CharMaxWidth <<= 1); for(pSizeData->m_CharMaxHeight = 1; pSizeData->m_CharMaxHeight < MaxH; pSizeData->m_CharMaxHeight <<= 1); } - + //dbg_msg("pFont", "init size %d, texture size %d %d", pFont->sizes[index].font_size, w, h); //FT_New_Face(m_FTLibrary, "data/fonts/vera.ttf", 0, &pFont->ft_face); InitTexture(pSizeData, pSizeData->m_CharMaxWidth, pSizeData->m_CharMaxHeight, 8, 8); @@ -253,7 +253,7 @@ class CTextRender : public IEngineTextRender { int x = (SlotID%pSizeData->m_NumXChars) * (pSizeData->m_TextureWidth/pSizeData->m_NumXChars); int y = (SlotID/pSizeData->m_NumXChars) * (pSizeData->m_TextureHeight/pSizeData->m_NumYChars); - + glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[Texnum]); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, pSizeData->m_TextureWidth/pSizeData->m_NumXChars, @@ -284,13 +284,13 @@ class CTextRender : public IEngineTextRender if(pSizeData->m_aCharacters[i].m_TouchTime < pSizeData->m_aCharacters[Oldest].m_TouchTime) Oldest = i; } - + if(time_get()-pSizeData->m_aCharacters[Oldest].m_TouchTime < time_freq()) { IncreaseTextureSize(pSizeData); return GetSlot(pSizeData); } - + return Oldest; } } @@ -315,12 +315,12 @@ class CTextRender : public IEngineTextRender } pBitmap = &pFont->m_FtFace->glyph->bitmap; // ignore_convention - + // fetch slot SlotID = GetSlot(pSizeData); if(SlotID < 0) return -1; - + // adjust spacing int OutlineThickness = AdjustOutlineThicknessToFontSize(1, pSizeData->m_FontSize); x += OutlineThickness; @@ -337,7 +337,7 @@ class CTextRender : public IEngineTextRender } else if(pBitmap->pixel_mode == FT_PIXEL_MODE_MONO) // ignore_convention { - for(py = 0; py < pBitmap->rows; py++) // ignore_convention + for(py = 0; py < pBitmap->rows; py++) // ignore_convention for(px = 0; px < pBitmap->width; px++) // ignore_convention { if(pBitmap->buffer[py*pBitmap->pitch+px/8]&(1<<(7-(px%8)))) // ignore_convention @@ -345,13 +345,13 @@ class CTextRender : public IEngineTextRender } } - if(0) for(py = 0; py < SlotW; py++) - for(px = 0; px < SlotH; px++) + if(0) for(py = 0; py < SlotW; py++) + for(px = 0; px < SlotH; px++) ms_aGlyphData[py*SlotW+px] = 255; - + // upload the glyph UploadGlyph(pSizeData, 0, SlotID, Chr, ms_aGlyphData); - + if(OutlineThickness == 1) { Grow(ms_aGlyphData, ms_aGlyphDataOutlined, SlotW, SlotH); @@ -366,7 +366,7 @@ class CTextRender : public IEngineTextRender } UploadGlyph(pSizeData, 1, SlotID, Chr, ms_aGlyphData); } - + // set char info { CFontChar *pFontchr = &pSizeData->m_aCharacters[SlotID]; @@ -375,27 +375,27 @@ class CTextRender : public IEngineTextRender float Vscale = 1.0f/pSizeData->m_TextureHeight; int Height = pBitmap->rows + OutlineThickness*2 + 2; // ignore_convention int Width = pBitmap->width + OutlineThickness*2 + 2; // ignore_convention - + pFontchr->m_ID = Chr; pFontchr->m_Height = Height * Scale; pFontchr->m_Width = Width * Scale; pFontchr->m_OffsetX = (pFont->m_FtFace->glyph->bitmap_left-1) * Scale; // ignore_convention pFontchr->m_OffsetY = (pSizeData->m_FontSize - pFont->m_FtFace->glyph->bitmap_top) * Scale; // ignore_convention pFontchr->m_AdvanceX = (pFont->m_FtFace->glyph->advance.x>>6) * Scale; // ignore_convention - + pFontchr->m_aUvs[0] = (SlotID%pSizeData->m_NumXChars) / (float)(pSizeData->m_NumXChars); pFontchr->m_aUvs[1] = (SlotID/pSizeData->m_NumXChars) / (float)(pSizeData->m_NumYChars); pFontchr->m_aUvs[2] = pFontchr->m_aUvs[0] + Width*Uscale; pFontchr->m_aUvs[3] = pFontchr->m_aUvs[1] + Height*Vscale; } - + return SlotID; } CFontChar *GetChar(CFont *pFont, CFontSizeData *pSizeData, int Chr) { CFontChar *pFontchr = NULL; - + // search for the character // TODO: remove this linear search int i; @@ -407,7 +407,7 @@ class CTextRender : public IEngineTextRender break; } } - + // check if we need to render the character if(!pFontchr) { @@ -415,12 +415,12 @@ class CTextRender : public IEngineTextRender if(Index >= 0) pFontchr = &pSizeData->m_aCharacters[Index]; } - + // touch the character // TODO: don't call time_get here if(pFontchr) pFontchr->m_TouchTime = time_get(); - + return pFontchr; } @@ -436,8 +436,8 @@ class CTextRender : public IEngineTextRender FT_Get_Kerning(pFont->m_FtFace, Left, Right, FT_KERNING_DEFAULT, &Kerning); return (Kerning.x>>6); } - - + + public: CTextRender() { @@ -457,21 +457,21 @@ public: // GL_LUMINANCE can be good for debugging m_FontTextureFormat = GL_ALPHA; } - + virtual void Init() { m_pGraphics = Kernel()->RequestInterface<IGraphics>(); FT_Init_FreeType(&m_FTLibrary); } - + virtual CFont *LoadFont(const char *pFilename) { CFont *pFont = (CFont *)mem_alloc(sizeof(CFont), 1); - + mem_zero(pFont, sizeof(*pFont)); str_copy(pFont->m_aFilename, pFilename, sizeof(pFont->m_aFilename)); - + if(FT_New_Face(m_FTLibrary, pFont->m_aFilename, 0, &pFont->m_FtFace)) { mem_free(pFont); @@ -480,7 +480,7 @@ public: for(unsigned i = 0; i < NUM_FONT_SIZES; i++) pFont->m_aSizes[i].m_FontSize = -1; - + dbg_msg("textrender", "loaded pFont from '%s'", pFilename); return pFont; }; @@ -495,8 +495,8 @@ public: dbg_msg("textrender", "default pFont set %p", pFont); m_pDefaultFont = pFont; } - - + + virtual void SetCursor(CTextCursor *pCursor, float x, float y, float FontSize, int Flags) { mem_zero(pCursor, sizeof(*pCursor)); @@ -510,8 +510,8 @@ public: pCursor->m_Flags = Flags; pCursor->m_CharCount = 0; } - - + + virtual void Text(void *pFontSetV, float x, float y, float Size, const char *pText, int MaxWidth) { CTextCursor Cursor; @@ -527,7 +527,7 @@ public: TextEx(&Cursor, pText, Length); return Cursor.m_X; } - + virtual int TextLineCount(void *pFontSetV, float Size, const char *pText, float LineWidth) { CTextCursor Cursor; @@ -552,12 +552,12 @@ public: m_TextOutlineB = b; m_TextOutlineA = a; } - + virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length) { CFont *pFont = pCursor->m_pFont; CFontSizeData *pSizeData = NULL; - + //dbg_msg("textrender", "rendering text '%s'", text); float ScreenX0, ScreenY0, ScreenX1, ScreenY1; @@ -576,7 +576,7 @@ public: // to correct coords, convert to screen coords, round, and convert back Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); - + FakeToScreenX = (Graphics()->ScreenWidth()/(ScreenX1-ScreenX0)); FakeToScreenY = (Graphics()->ScreenHeight()/(ScreenY1-ScreenY0)); ActualX = (int)(pCursor->m_X * FakeToScreenX); @@ -592,7 +592,7 @@ public: // fetch pFont data if(!pFont) pFont = m_pDefaultFont; - + if(!pFont) return; @@ -600,11 +600,11 @@ public: RenderSetup(pFont, ActualSize); float Scale = 1/pSizeData->m_FontSize; - + // set length if(Length < 0) Length = str_length(pText); - + pEnd = pText + Length; // if we don't want to render, we can just skip the first outline pass @@ -649,7 +649,7 @@ public: Compare.m_Flags &= ~TEXTFLAG_RENDER; Compare.m_LineWidth = -1; TextEx(&Compare, pText, Wlen); - + if(Compare.m_X-DrawX > pCursor->m_LineWidth) { // word can't be fitted in one line, cut it @@ -659,11 +659,11 @@ public: Cutter.m_Y = DrawY; Cutter.m_Flags &= ~TEXTFLAG_RENDER; Cutter.m_Flags |= TEXTFLAG_STOP_AT_END; - + TextEx(&Cutter, (const char *)pCurrent, Wlen); Wlen = Cutter.m_CharCount; NewLine = 1; - + if(Wlen <= 3) // if we can't place 3 chars of the word on this line, take the next Wlen = 0; } @@ -672,10 +672,10 @@ public: NewLine = 1; Wlen = 0; } - + pBatchEnd = pCurrent + Wlen; } - + const char *pTmp = pCurrent; int NextCharacter = str_utf8_decode(&pTmp); while(pCurrent < pBatchEnd) @@ -683,7 +683,7 @@ public: int Character = NextCharacter; pCurrent = pTmp; NextCharacter = str_utf8_decode(&pTmp); - + if(Character == '\n') { DrawX = pCursor->m_StartX; @@ -718,14 +718,14 @@ public: pCursor->m_CharCount++; } } - + if(NewLine) { DrawX = pCursor->m_StartX; DrawY += Size; GotNewLine = 1; DrawX = (int)(DrawX * FakeToScreenX) / FakeToScreenX; // realign - DrawY = (int)(DrawY * FakeToScreenY) / FakeToScreenY; + DrawY = (int)(DrawY * FakeToScreenY) / FakeToScreenY; ++LineCount; } } @@ -736,11 +736,11 @@ public: pCursor->m_X = DrawX; pCursor->m_LineCount = LineCount; - + if(GotNewLine) pCursor->m_Y = DrawY; } - + }; IEngineTextRender *CreateEngineTextRender() { return new CTextRender; } |