From 678fe76566863b4ab441f303c488b04998100c8e Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 15 Aug 2010 20:04:03 +0200 Subject: [PATCH 01/27] reverted input key handling back to 0.52(the keyboard layout problem should be fixed with sdl 1.3 or a customised one). Closes #3. Closes #15. --- src/engine/client/input.cpp | 14 ++------------ src/engine/client/input.h | 2 -- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp index 9f5462261..32e61bbb8 100644 --- a/src/engine/client/input.cpp +++ b/src/engine/client/input.cpp @@ -31,7 +31,6 @@ CInput::CInput() { mem_zero(m_aInputCount, sizeof(m_aInputCount)); mem_zero(m_aInputState, sizeof(m_aInputState)); - mem_zero(m_Keys, sizeof(m_Keys)); m_InputCurrent = 0; m_InputGrabbed = 0; @@ -146,20 +145,11 @@ void CInput::Update() // handle keys case SDL_KEYDOWN: AddEvent(Event.key.keysym.unicode, 0, 0); // ignore_convention - if(Event.key.keysym.unicode != 0 && Event.key.keysym.unicode < 256) // ignore_convention - { - Key = Event.key.keysym.unicode; // ignore_convention - m_Keys[Event.key.keysym.sym] = Event.key.keysym.unicode; // ignore_convention - } - else - Key = Event.key.keysym.sym; // ignore_convention + Key = Event.key.keysym.sym; // ignore_convention break; case SDL_KEYUP: Action = IInput::FLAG_RELEASE; - if(m_Keys[Event.key.keysym.sym] != 0) // ignore_convention - Key = m_Keys[Event.key.keysym.sym]; // ignore_convention - else - Key = Event.key.keysym.sym; // ignore_convention + Key = Event.key.keysym.sym; // ignore_convention break; // handle mouse buttons diff --git a/src/engine/client/input.h b/src/engine/client/input.h index bf7739abf..cc4e32e33 100644 --- a/src/engine/client/input.h +++ b/src/engine/client/input.h @@ -10,8 +10,6 @@ class CInput : public IEngineInput unsigned int m_LastRelease; unsigned int m_ReleaseDelta; - int m_Keys[1024]; - void AddEvent(int Unicode, int Key, int Flags); IEngineGraphics *Graphics() { return m_pGraphics; } From 5922cbb56d17e9bff2a160c141c069a6004b7940 Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 16 Aug 2010 00:45:04 +0200 Subject: [PATCH 02/27] added localisation fixes by sworddragon --- src/game/editor/ed_popups.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp index 19b0af26c..18351d7a6 100644 --- a/src/game/editor/ed_popups.cpp +++ b/src/game/editor/ed_popups.cpp @@ -134,17 +134,17 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) }; CProperty aProps[] = { - {"Order", pEditor->m_SelectedGroup, PROPTYPE_INT_STEP, 0, pEditor->m_Map.m_lGroups.size()-1}, - {"Pos X", -pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_OffsetX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Pos Y", -pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_OffsetY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Para X", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ParallaxX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Para Y", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ParallaxY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Order"), pEditor->m_SelectedGroup, PROPTYPE_INT_STEP, 0, pEditor->m_Map.m_lGroups.size()-1}, + {Localize("Pos X"), -pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_OffsetX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Pos Y"), -pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_OffsetY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Para X"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ParallaxX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Para Y"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ParallaxY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Use Clipping", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_UseClipping, PROPTYPE_BOOL, 0, 1}, - {"Clip X", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Clip Y", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Clip W", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipW, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Clip H", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipH, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Use Clipping"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_UseClipping, PROPTYPE_BOOL, 0, 1}, + {Localize("Clip X"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Clip Y"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Clip W"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipW, PROPTYPE_INT_SCROLL, -1000000, 1000000}, + {Localize("Clip H"), pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ClipH, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {0}, }; From 4c2dcc4f2b5f061a1d75aa2aa0b316c4b86bc1d8 Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 16 Aug 2010 01:29:11 +0200 Subject: [PATCH 03/27] added localisation fixes and map editor tool tips by sworddragon --- src/game/editor/ed_editor.cpp | 29 +++++++++++++++++------------ src/game/editor/ed_editor.h | 2 +- src/game/editor/ed_layer_quads.cpp | 3 ++- src/game/editor/ed_popups.cpp | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 3220e4203..a2ecfb7ee 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -462,7 +462,7 @@ void CEditor::RenderBackground(CUIRect View, int Texture, float Size, float Brig Graphics()->QuadsEnd(); } -int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale) +int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale, const char *pToolTip) { // logic static float s_Value; @@ -496,7 +496,8 @@ int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Cu Current = Max; } } - m_pTooltip = Localize("Use left mouse button to drag and the change the value. Hold shift to be more precise."); + if(pToolTip) + m_pTooltip = pToolTip; } else if(UI()->HotItem() == pId) { @@ -506,7 +507,8 @@ int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Cu s_Value = 0; UI()->SetActiveItem(pId); } - m_pTooltip = Localize("Use left mouse button to drag and the change the value. Hold shift to be more precise."); + if(pToolTip) + m_pTooltip = pToolTip; } if(Inside) @@ -728,7 +730,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_RotationAmount = 90; - s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, 1, 360, 2.0f); + s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, 1, 360, 2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); TB_Top.VSplitLeft(5.0f, &Button, &TB_Top); TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); @@ -1603,7 +1605,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * } else if(pProps[i].m_Type == PROPTYPE_INT_SCROLL) { - int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1.0f); + int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); if(NewValue != pProps[i].m_Value) { *pNewVal = NewValue; @@ -1619,7 +1621,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * for(int c = 0; c < 4; c++) { int v = (pProps[i].m_Value >> s_aShift[c])&0xff; - NewColor |= UiDoValueSelector(((char *)&pIds[i])+c, &Shifter, s_paTexts[c], v, 0, 255, 1.0f)<channels-1) draw_func = draw_editor_button_r; else draw_func = draw_editor_button_m;*/ - if(DoButton_Editor(&s_aChannelButtons[i], s_paNames[pEnvelope->m_Channels-1][i], s_ActiveChannels&Bit, &Button, 0, 0)) + if(DoButton_Editor(&s_aChannelButtons[i], s_paNames[pEnvelope->m_Channels-3][i], s_ActiveChannels&Bit, &Button, 0, paDescriptions[pEnvelope->m_Channels-3][i])) s_ActiveChannels ^= Bit; } } @@ -2721,7 +2726,7 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View) View.HSplitTop(10.0f, &Slot, &View); View.HSplitTop(12.0f, &Slot, &View); - if(pEditor->DoButton_MenuItem(&s_ExitButton, "Exit", 0, &Slot, 0, Localize("Exits from the editor"))) + if(pEditor->DoButton_MenuItem(&s_ExitButton, Localize("Exit"), 0, &Slot, 0, Localize("Exits from the editor"))) { g_Config.m_ClEditor = 0; return 1; diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index e459e70f8..9ccb32030 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -574,7 +574,7 @@ public: void UiInvokePopupMenu(void *pId, int Flags, float x, float y, float w, float h, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect), void *pExtra=0); void UiDoPopupMenu(); - int UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale); + int UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale, const char *pToolTip); static int PopupGroup(CEditor *pEditor, CUIRect View); static int PopupLayer(CEditor *pEditor, CUIRect View); diff --git a/src/game/editor/ed_layer_quads.cpp b/src/game/editor/ed_layer_quads.cpp index 3aeffc73b..023fd29f8 100644 --- a/src/game/editor/ed_layer_quads.cpp +++ b/src/game/editor/ed_layer_quads.cpp @@ -5,6 +5,7 @@ #include "ed_editor.h" #include #include +#include CLayerQuads::CLayerQuads() { @@ -220,7 +221,7 @@ int CLayerQuads::RenderProperties(CUIRect *pToolBox) }; CProperty aProps[] = { - {"Image", m_Image, PROPTYPE_IMAGE, -1, 0}, + {Localize("Image"), m_Image, PROPTYPE_IMAGE, -1, 0}, {0}, }; diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp index 18351d7a6..8152c67c8 100644 --- a/src/game/editor/ed_popups.cpp +++ b/src/game/editor/ed_popups.cpp @@ -346,7 +346,7 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View) CProperty aProps[] = { - {"Color", Color, PROPTYPE_COLOR, -1, pEditor->m_Map.m_lEnvelopes.size()}, + {Localize("Color"), Color, PROPTYPE_COLOR, -1, pEditor->m_Map.m_lEnvelopes.size()}, {0}, }; From abc84ac0b0ff77b3b30a20252f86332c699e4466 Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 16 Aug 2010 02:21:18 +0200 Subject: [PATCH 04/27] added fixes for compiler errors and warnings by sworddragon --- src/base/system.c | 18 +++++++++--------- src/engine/client/input.cpp | 4 ++-- src/engine/client/input.h | 2 +- src/engine/client/sound.cpp | 2 +- src/engine/client/text.cpp | 8 ++++---- src/engine/shared/datafile.cpp | 2 +- src/engine/shared/huffman.cpp | 4 ++-- src/engine/shared/huffman.h | 2 +- src/engine/textrender.h | 2 +- src/game/client/components/chat.cpp | 4 ++-- src/game/server/gamecontroller.cpp | 2 +- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 84f732e7f..6c735c28b 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -654,7 +654,7 @@ NETSOCKET net_udp_create(NETADDR bindaddr) { /* TODO: IPv6 support */ struct sockaddr addr; - unsigned int mode = 1; + unsigned long mode = 1; int broadcast = 1; /* create socket */ @@ -672,9 +672,9 @@ NETSOCKET net_udp_create(NETADDR bindaddr) /* set non-blocking */ #if defined(CONF_FAMILY_WINDOWS) - ioctlsocket(sock, FIONBIO, (unsigned long *)&mode); + ioctlsocket(sock, FIONBIO, &mode); #else - ioctl(sock, FIONBIO, (unsigned long *)&mode); + ioctl(sock, FIONBIO, &mode); #endif /* set boardcast */ @@ -755,21 +755,21 @@ NETSOCKET net_tcp_create(const NETADDR *a) int net_tcp_set_non_blocking(NETSOCKET sock) { - unsigned int mode = 1; + unsigned long mode = 1; #if defined(CONF_FAMILY_WINDOWS) - return ioctlsocket(sock, FIONBIO, (unsigned long *)&mode); + return ioctlsocket(sock, FIONBIO, &mode); #else - return ioctl(sock, FIONBIO, (unsigned long *)&mode); + return ioctl(sock, FIONBIO, &mode); #endif } int net_tcp_set_blocking(NETSOCKET sock) { - unsigned int mode = 0; + unsigned long mode = 0; #if defined(CONF_FAMILY_WINDOWS) - return ioctlsocket(sock, FIONBIO, (unsigned long *)&mode); + return ioctlsocket(sock, FIONBIO, &mode); #else - return ioctl(sock, FIONBIO, (unsigned long *)&mode); + return ioctl(sock, FIONBIO, &mode); #endif } diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp index 32e61bbb8..c6d3f58e1 100644 --- a/src/engine/client/input.cpp +++ b/src/engine/client/input.cpp @@ -65,8 +65,8 @@ void CInput::MouseRelative(int *x, int *y) } } - *x = nx*Sens; - *y = ny*Sens; + *x = (int)(nx*Sens); + *y = (int)(ny*Sens); } void CInput::MouseModeAbsolute() diff --git a/src/engine/client/input.h b/src/engine/client/input.h index cc4e32e33..0b6d5b76f 100644 --- a/src/engine/client/input.h +++ b/src/engine/client/input.h @@ -8,7 +8,7 @@ class CInput : public IEngineInput int m_InputGrabbed; unsigned int m_LastRelease; - unsigned int m_ReleaseDelta; + int m_ReleaseDelta; void AddEvent(int Unicode, int Key, int Flags); diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index df8fa66b4..b829686c8 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -121,7 +121,7 @@ static void Mix(short *pFinalOut, unsigned Frames) const int Range = 1500; // magic value, remove int dx = v->m_X - m_CenterX; int dy = v->m_Y - m_CenterY; - int Dist = sqrtf((float)dx*dx+dy*dy); // float here. nasty + int Dist = (int)sqrtf((float)dx*dx+dy*dy); // float here. nasty int p = IntAbs(dx); if(Dist < Range) { diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index 672fde60d..ef741c129 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -509,7 +509,7 @@ public: return Cursor.m_X; } - virtual float TextLineCount(void *pFontSetV, float Size, const char *pText, int LineWidth) + virtual int TextLineCount(void *pFontSetV, float Size, const char *pText, float LineWidth) { CTextCursor Cursor; SetCursor(&Cursor, 0, 0, Size, 0); @@ -551,14 +551,14 @@ public: FakeToScreenX = (Graphics()->ScreenWidth()/(ScreenX1-ScreenX0)); FakeToScreenY = (Graphics()->ScreenHeight()/(ScreenY1-ScreenY0)); - ActualX = pCursor->m_X * FakeToScreenX; - ActualY = pCursor->m_Y * FakeToScreenY; + ActualX = (int)(pCursor->m_X * FakeToScreenX); + ActualY = (int)(pCursor->m_Y * FakeToScreenY); CursorX = ActualX / FakeToScreenX; CursorY = ActualY / FakeToScreenY; // same with size - ActualSize = Size * FakeToScreenY; + ActualSize = (int)(Size * FakeToScreenY); Size = ActualSize / FakeToScreenY; // fetch pFont data diff --git a/src/engine/shared/datafile.cpp b/src/engine/shared/datafile.cpp index e7905f811..69b187eac 100644 --- a/src/engine/shared/datafile.cpp +++ b/src/engine/shared/datafile.cpp @@ -383,7 +383,7 @@ bool CDataFileReader::Close() unsigned CDataFileReader::Crc() { - if(!m_pDataFile) return -1; + if(!m_pDataFile) return 0xFFFFFFFF; return m_pDataFile->m_Crc; } diff --git a/src/engine/shared/huffman.cpp b/src/engine/shared/huffman.cpp index 8b0c1cd01..bb7aeaa8f 100644 --- a/src/engine/shared/huffman.cpp +++ b/src/engine/shared/huffman.cpp @@ -7,7 +7,7 @@ struct CHuffmanConstructNode int m_Frequency; }; -void CHuffman::Setbits_r(CNode *pNode, int Bits, int Depth) +void CHuffman::Setbits_r(CNode *pNode, int Bits, unsigned Depth) { if(pNode->m_aLeafs[1] != 0xffff) Setbits_r(&m_aNodes[pNode->m_aLeafs[1]], Bits|(1<TextEx(&Cursor, m_Input.GetString()+m_Input.GetCursorOffset(), -1); } - y -= 8; + y -= 8.0f; int i; int64 Now = time_get(); @@ -225,7 +225,7 @@ void CChat::OnRender() y -= Cursor.m_Y + Cursor.m_FontSize; // cut off if msgs waste too much space - int HeightLimit = m_Show ? 0.0f : 200.0f; + float HeightLimit = m_Show ? 0.0f : 200.0f; if(y < HeightLimit) break; diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 07f8bf86a..04eb8c6ee 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -423,7 +423,7 @@ void IGameController::Tick() do { CPlayer *pP = 0; - int PD = aTScore[M]; + float PD = aTScore[M]; for(int i = 0; i < MAX_CLIENTS; i++) { if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i)) From e966cdb334356ad96aeccb19481a85f46f6a4b55 Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 16 Aug 2010 04:09:21 +0200 Subject: [PATCH 05/27] fixed that Collision::IntersectLine gets stuck in a loop forever. Closes #6 --- src/game/collision.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 0dee57c8f..f114fd069 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -67,11 +67,12 @@ bool CCollision::IsTileSolid(int x, int y) int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) { float d = distance(Pos0, Pos1); + int End(d+1); vec2 Last = Pos0; - for(float f = 0; f < d; f++) + for(int i = 0; i < End; i++) { - float a = f/d; + float a = i/d; vec2 Pos = mix(Pos0, Pos1, a); if(CheckPoint(Pos.x, Pos.y)) { From 16f201794de61e237b4a7644d28f043dc1b987bb Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 16 Aug 2010 04:12:03 +0200 Subject: [PATCH 06/27] fixed a variable name --- src/game/client/components/menus.h | 2 +- src/game/client/components/menus_demo.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 53f819540..de711a1e8 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -33,7 +33,7 @@ class CMenus : public CComponent int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect); - int DoButton_DemoPlayer_Sprite(const void *pID, int spriteId, int Checked, const CUIRect *pRect); + int DoButton_DemoPlayer_Sprite(const void *pID, int SpriteId, int Checked, const CUIRect *pRect); int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect); int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners); int DoButton_SettingsTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 18d9ddeec..ef9ac62d1 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -22,12 +22,12 @@ int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, return UI()->DoButtonLogic(pID, pText, Checked, pRect); } -int CMenus::DoButton_DemoPlayer_Sprite(const void *pID, int spriteId, int Checked, const CUIRect *pRect) +int CMenus::DoButton_DemoPlayer_Sprite(const void *pID, int SpriteId, int Checked, const CUIRect *pRect) { RenderTools()->DrawUIRect(pRect, vec4(1,1,1, Checked ? 0.10f : 0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_DEMOBUTTONS].m_Id); Graphics()->QuadsBegin(); - RenderTools()->SelectSprite(spriteId); + RenderTools()->SelectSprite(SpriteId); IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); @@ -138,7 +138,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) else { if(DoButton_DemoPlayer_Sprite(&s_PlayPauseButton, SPRITE_DEMOBUTTON_PLAY, !pInfo->m_Paused, &Button)) - DemoPlayer()->Unpause(); + DemoPlayer()->Unpause(); } ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); From cabecb7fa937b5e4efa859ea62722468f91a5089 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 18 Aug 2010 00:06:00 +0200 Subject: [PATCH 07/27] added output level for console print function, categorised the debug messages and merged them into the new functionality. Closes #8 --- src/engine/client/client.cpp | 91 ++++++++++----- src/engine/client/graphics.cpp | 6 +- src/engine/client/graphics.h | 1 + src/engine/client/srvbrowse.cpp | 16 ++- src/engine/client/srvbrowse.h | 1 + src/engine/console.h | 9 +- src/engine/server/register.cpp | 27 +++-- src/engine/server/register.h | 3 +- src/engine/server/server.cpp | 107 ++++++++++++------ src/engine/server/server.h | 4 +- src/engine/shared/config_variables.h | 1 + src/engine/shared/console.cpp | 35 ++++-- src/engine/shared/console.h | 2 +- src/engine/shared/demorec.cpp | 45 +++++--- src/engine/shared/demorec.h | 6 +- src/engine/shared/network.h | 2 +- src/engine/shared/network_client.cpp | 2 +- src/engine/shared/network_server.cpp | 9 +- src/game/client/components/binds.cpp | 18 ++- src/game/client/components/chat.cpp | 6 +- src/game/client/components/menus_browser.cpp | 2 +- src/game/client/components/menus_settings.cpp | 2 +- src/game/client/components/skins.cpp | 6 +- src/game/client/gameclient.cpp | 22 +++- src/game/editor/ed_editor.cpp | 8 +- src/game/editor/ed_editor.h | 2 + src/game/editor/ed_io.cpp | 14 ++- src/game/editor/ed_layer_quads.cpp | 3 +- src/game/editor/ed_popups.cpp | 3 +- src/game/localization.cpp | 12 +- src/game/localization.h | 2 +- src/game/server/entities/character.cpp | 8 +- src/game/server/entities/pickup.cpp | 4 +- src/game/server/gamecontext.cpp | 42 ++++--- src/game/server/gamecontroller.cpp | 31 +++-- src/game/server/gamemodes/ctf.cpp | 19 ++-- src/game/server/player.cpp | 18 +-- 37 files changed, 398 insertions(+), 191 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index ce27e46fa..6ddf364f4 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -437,7 +437,11 @@ void CClient::SetState(int s) { int Old = m_State; if(g_Config.m_Debug) - dbg_msg("client", "state change. last=%d current=%d", m_State, s); + { + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "state change. last=%d current=%d", m_State, s); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf); + } m_State = s; if(Old != s) GameClient()->OnStateChange(m_State, Old); @@ -484,7 +488,8 @@ void CClient::Connect(const char *pAddress) str_copy(m_aServerAddressStr, pAddress, sizeof(m_aServerAddressStr)); - dbg_msg("client", "connecting to '%s'", m_aServerAddressStr); + str_format(aBuf, sizeof(aBuf), "connecting to '%s'", m_aServerAddressStr); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); ServerInfoRequest(); str_copy(aBuf, m_aServerAddressStr, sizeof(aBuf)); @@ -502,7 +507,9 @@ void CClient::Connect(const char *pAddress) // TODO: IPv6 support if(net_host_lookup(aBuf, &m_ServerAddress, NETTYPE_IPV4) != 0) { - dbg_msg("client", "could not find the address of %s, connecting to localhost", aBuf); + char aBufMsg[256]; + str_format(aBufMsg, sizeof(aBufMsg), "could not find the address of %s, connecting to localhost", aBuf); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBufMsg); net_host_lookup("localhost", &m_ServerAddress, NETTYPE_IPV4); } @@ -520,6 +527,10 @@ void CClient::Connect(const char *pAddress) void CClient::DisconnectWithReason(const char *pReason) { + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "disconnecting. reason='%s'", pReason?pReason:"unknown"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); + // stop demo playback and recorder m_DemoPlayer.Stop(); m_DemoRecorder.Stop(); @@ -593,9 +604,9 @@ void CClient::SnapInvalidateItem(int SnapId, int Index) if(i) { if((char *)i < (char *)m_aSnapshots[SnapId]->m_pAltSnap || (char *)i > (char *)m_aSnapshots[SnapId]->m_pAltSnap + m_aSnapshots[SnapId]->m_SnapSize) - dbg_msg("ASDFASDFASdf", "ASDFASDFASDF"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", "snap invalidate problem"); if((char *)i >= (char *)m_aSnapshots[SnapId]->m_pSnap && (char *)i < (char *)m_aSnapshots[SnapId]->m_pSnap + m_aSnapshots[SnapId]->m_SnapSize) - dbg_msg("ASDFASDFASdf", "ASDFASDFASDF"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", "snap invalidate problem"); i->m_TypeAndID = -1; } } @@ -764,7 +775,9 @@ const char *CClient::LoadMap(const char *pName, const char *pFilename, unsigned // stop demo recording if we loaded a new map m_DemoRecorder.Stop(); - dbg_msg("client", "loaded map '%s'", pFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "loaded map '%s'", pFilename); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf); m_RecivedSnapshots = 0; str_copy(m_aCurrentMap, pName, sizeof(m_aCurrentMap)); @@ -779,7 +792,8 @@ const char *CClient::LoadMapSearch(const char *pMapName, int WantedCrc) { const char *pError = 0; char aBuf[512]; - dbg_msg("client", "loading map, map=%s wanted crc=%08x", pMapName, WantedCrc); + str_format(aBuf, sizeof(aBuf), "loading map, map=%s wanted crc=%08x", pMapName, WantedCrc); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf); SetState(IClient::STATE_LOADING); // try the normal maps folder @@ -816,9 +830,11 @@ void CClient::ProcessPacket(CNetChunk *pPacket) unsigned char *pVersionData = (unsigned char*)pPacket->m_pData + sizeof(VERSIONSRV_VERSION); int VersionMatch = !mem_comp(pVersionData, VERSION_DATA, sizeof(VERSION_DATA)); - dbg_msg("client/version", "version does %s (%d.%d.%d)", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "version does %s (%d.%d.%d)", VersionMatch ? "match" : "NOT match", pVersionData[1], pVersionData[2], pVersionData[3]); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/version", aBuf); // assume version is out of date when version-data doesn't match if (!VersionMatch) @@ -954,7 +970,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket) if(!pError) { - dbg_msg("client/network", "loading done"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", "loading done"); SendReady(); GameClient()->OnConnected(); } @@ -962,7 +978,9 @@ void CClient::ProcessPacket(CNetChunk *pPacket) { str_format(m_aMapdownloadFilename, sizeof(m_aMapdownloadFilename), "downloadedmaps/%s_%08x.map", pMap, MapCrc); - dbg_msg("client/network", "starting to download map to '%s'", m_aMapdownloadFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "starting to download map to '%s'", m_aMapdownloadFilename); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", aBuf); m_MapdownloadChunk = 0; str_copy(m_aMapdownloadName, pMap, sizeof(m_aMapdownloadName)); @@ -976,7 +994,10 @@ void CClient::ProcessPacket(CNetChunk *pPacket) SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH); if(g_Config.m_Debug) - dbg_msg("client/network", "requested chunk %d", m_MapdownloadChunk); + { + str_format(aBuf, sizeof(aBuf), "requested chunk %d", m_MapdownloadChunk); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client/network", aBuf); + } } } } @@ -999,7 +1020,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket) if(Last) { const char *pError; - dbg_msg("client/network", "download complete, loading map"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", "download complete, loading map"); io_close(m_MapdownloadFile); m_MapdownloadFile = 0; @@ -1010,7 +1031,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket) pError = LoadMap(m_aMapdownloadName, m_aMapdownloadFilename, m_MapdownloadCrc); if(!pError) { - dbg_msg("client/network", "loading done"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", "loading done"); SendReady(); GameClient()->OnConnected(); } @@ -1027,7 +1048,11 @@ void CClient::ProcessPacket(CNetChunk *pPacket) SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH); if(g_Config.m_Debug) - dbg_msg("client/network", "requested chunk %d", m_MapdownloadChunk); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "requested chunk %d", m_MapdownloadChunk); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client/network", aBuf); + } } } else if(Msg == NETMSG_PING) @@ -1048,7 +1073,11 @@ void CClient::ProcessPacket(CNetChunk *pPacket) GameClient()->OnRconLine(pLine); } else if(Msg == NETMSG_PING_REPLY) - dbg_msg("client/network", "latency %.2f", (time_get() - m_PingStartTime)*1000 / (float)time_freq()); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "latency %.2f", (time_get() - m_PingStartTime)*1000 / (float)time_freq()); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client/network", aBuf); + } else if(Msg == NETMSG_INPUTTIMING) { int InputPredTick = Unpacker.GetInt(); @@ -1143,7 +1172,11 @@ void CClient::ProcessPacket(CNetChunk *pPacket) // couldn't find the delta snapshots that the server used // to compress this snapshot. force the server to resync if(g_Config.m_Debug) - dbg_msg("client", "error, couldn't find the delta snapshot"); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "error, couldn't find the delta snapshot"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf); + } // ack snapshot // TODO: combine this with the input message @@ -1172,7 +1205,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket) SnapSize = m_SnapshotDelta.UnpackDelta(pDeltaShot, pTmpBuffer3, pDeltaData, DeltaSize); if(SnapSize < 0) { - dbg_msg("client", "delta unpack failed!"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", "delta unpack failed!"); return; } @@ -1180,8 +1213,10 @@ void CClient::ProcessPacket(CNetChunk *pPacket) { if(g_Config.m_Debug) { - dbg_msg("client", "snapshot crc error #%d - tick=%d wantedcrc=%d gotcrc=%d compressed_size=%d delta_tick=%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "snapshot crc error #%d - tick=%d wantedcrc=%d gotcrc=%d compressed_size=%d delta_tick=%d", m_SnapCrcErrors, GameTick, Crc, pTmpBuffer3->Crc(), CompleteSize, DeltaTick); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf); } m_SnapCrcErrors++; @@ -1273,14 +1308,16 @@ void CClient::PumpNetwork() { SetState(IClient::STATE_OFFLINE); Disconnect(); - dbg_msg("client", "offline error='%s'", m_NetClient.ErrorString()); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "offline error='%s'", m_NetClient.ErrorString()); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); } // if(State() == IClient::STATE_CONNECTING && m_NetClient.State() == NETSTATE_ONLINE) { // we switched to online - dbg_msg("client", "connected, sending info"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", "connected, sending info"); SetState(IClient::STATE_LOADING); SendInfo(); } @@ -1434,7 +1471,7 @@ void CClient::Update() if(NewPredTick < m_aSnapshots[SNAP_PREV]->m_Tick-SERVER_TICK_SPEED || NewPredTick > m_aSnapshots[SNAP_PREV]->m_Tick+SERVER_TICK_SPEED) { - dbg_msg("client", "prediction time reset!"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "prediction time reset!"); m_PredictedTime.Init(m_aSnapshots[SNAP_CURRENT]->m_Tick*time_freq()/50); } @@ -1477,7 +1514,7 @@ void CClient::Update() { if(Now > ActionTaken+time_freq()*2) { - dbg_msg("stress", "reconnecting!"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "stress", "reconnecting!"); Connect(g_Config.m_DbgStressServer); ActionTaken = Now; } @@ -1590,7 +1627,9 @@ void CClient::Run() return; GameClient()->OnInit(); - dbg_msg("client", "version %s", GameClient()->NetVersion()); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "version %s", GameClient()->NetVersion()); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); // open socket { @@ -1836,7 +1875,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename) // try to start playback m_DemoPlayer.SetListner(this); - if(m_DemoPlayer.Load(Storage(), pFilename)) + if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename)) return "error loading demo"; // load map @@ -1887,12 +1926,12 @@ void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData) void CClient::DemoRecorder_Start(const char *pFilename) { if(State() != IClient::STATE_ONLINE) - dbg_msg("demorec/record", "client is not online"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demorec/record", "client is not online"); else { char aFilename[512]; str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pFilename); - m_DemoRecorder.Start(Storage(), aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client"); + m_DemoRecorder.Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client"); } } diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 09ee4784b..1e9a79cf7 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -446,7 +447,9 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename) io_close(File); // save png - dbg_msg("client", "saved screenshot to '%s'", aWholePath); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); png_open_file_write(&Png, aWholePath); // ignore_convention png_set_data(&Png, w, h, 8, PNG_TRUECOLOR, (unsigned char *)pPixelData); // ignore_convention png_close_file(&Png); // ignore_convention @@ -663,6 +666,7 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, bool CGraphics_OpenGL::Init() { m_pStorage = Kernel()->RequestInterface(); + m_pConsole = Kernel()->RequestInterface(); // Set all z to -5.0f for(int i = 0; i < MAX_VERTICES; i++) diff --git a/src/engine/client/graphics.h b/src/engine/client/graphics.h index cb8681f39..fa360a22a 100644 --- a/src/engine/client/graphics.h +++ b/src/engine/client/graphics.h @@ -5,6 +5,7 @@ class CGraphics_OpenGL : public IEngineGraphics { protected: class IStorage *m_pStorage; + class IConsole *m_pConsole; // typedef struct { float x, y, z; } CPoint; diff --git a/src/engine/client/srvbrowse.cpp b/src/engine/client/srvbrowse.cpp index d0c8393d5..aed0d5146 100644 --- a/src/engine/client/srvbrowse.cpp +++ b/src/engine/client/srvbrowse.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -62,6 +63,7 @@ void CServerBrowser::SetBaseInfo(class CNetClient *pClient, const char *pNetVers m_pNetClient = pClient; str_copy(m_aNetVersion, pNetVersion, sizeof(m_aNetVersion)); m_pMasterServer = Kernel()->RequestInterface(); + m_pConsole = Kernel()->RequestInterface(); IConfig *pConfig = Kernel()->RequestInterface(); if(pConfig) pConfig->RegisterCallback(ConfigSaveCallback, this); @@ -514,7 +516,7 @@ void CServerBrowser::Refresh(int Type) } if(g_Config.m_Debug) - dbg_msg("client", "broadcasting for servers"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", "broadcasting for servers"); } else if(Type == IServerBrowser::TYPE_INTERNET) m_NeedRefresh = 1; @@ -532,9 +534,11 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons if(g_Config.m_Debug) { - dbg_msg("client", "requesting server info from %d.%d.%d.%d:%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf),"requesting server info from %d.%d.%d.%d:%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf); } /*mem_copy(buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO)); @@ -595,7 +599,7 @@ void CServerBrowser::Update() } if(g_Config.m_Debug) - dbg_msg("client", "requesting server list"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", "requesting server list"); } // do timeouts @@ -676,7 +680,11 @@ void CServerBrowser::AddFavorite(const NETADDR &Addr) pEntry->m_Info.m_Favorite = 1; if(g_Config.m_Debug) - dbg_msg("", "added fav, %d.%d.%d.%d:%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "added fav, %d.%d.%d.%d:%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf); + } } void CServerBrowser::RemoveFavorite(const NETADDR &Addr) diff --git a/src/engine/client/srvbrowse.h b/src/engine/client/srvbrowse.h index 1c2557926..ecaed7efb 100644 --- a/src/engine/client/srvbrowse.h +++ b/src/engine/client/srvbrowse.h @@ -50,6 +50,7 @@ public: private: CNetClient *m_pNetClient; IMasterServer *m_pMasterServer; + class IConsole *m_pConsole; char m_aNetVersion[128]; CHeap m_ServerlistHeap; diff --git a/src/engine/console.h b/src/engine/console.h index 050347347..80a995c33 100644 --- a/src/engine/console.h +++ b/src/engine/console.h @@ -8,6 +8,13 @@ class IConsole : public IInterface MACRO_INTERFACE("console", 0) public: + enum + { + OUTPUT_LEVEL_STANDARD=0, + OUTPUT_LEVEL_ADDINFO, + OUTPUT_LEVEL_DEBUG + }; + // TODO: rework this interface to reduce the amount of virtual calls class IResult { @@ -51,7 +58,7 @@ public: virtual void ExecuteFile(const char *pFilename) = 0; virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData) = 0; - virtual void Print(const char *pStr) = 0; + virtual void Print(int Level, const char *pFrom, const char *pStr) = 0; }; extern IConsole *CreateConsole(int FlagMask); diff --git a/src/engine/server/register.cpp b/src/engine/server/register.cpp index e9616ca17..925fef305 100644 --- a/src/engine/server/register.cpp +++ b/src/engine/server/register.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -12,6 +13,7 @@ CRegister::CRegister() { m_pNetServer = 0; m_pMasterServer = 0; + m_pConsole = 0; m_RegisterState = REGISTERSTATE_START; m_RegisterStateStart = 0; @@ -87,10 +89,11 @@ void CRegister::RegisterGotCount(CNetChunk *pChunk) } } -void CRegister::Init(CNetServer *pNetServer, IEngineMasterServer *pMasterServer) +void CRegister::Init(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole) { m_pNetServer = pNetServer; m_pMasterServer = pMasterServer; + m_pConsole = pConsole; } void CRegister::RegisterUpdate() @@ -109,7 +112,7 @@ void CRegister::RegisterUpdate() m_RegisterFirst = 1; RegisterNewState(REGISTERSTATE_UPDATE_ADDRS); m_pMasterServer->RefreshAddresses(); - dbg_msg("register", "refreshing ip addresses"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "refreshing ip addresses"); } else if(m_RegisterState == REGISTERSTATE_UPDATE_ADDRS) { @@ -134,7 +137,7 @@ void CRegister::RegisterUpdate() } } - dbg_msg("register", "fetching server counts"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "fetching server counts"); RegisterNewState(REGISTERSTATE_QUERY_COUNT); } } @@ -176,12 +179,14 @@ void CRegister::RegisterUpdate() m_RegisterRegisteredServer = Best; if(m_RegisterRegisteredServer == -1) { - dbg_msg("register", "WARNING: No master servers. Retrying in 60 seconds"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "WARNING: No master servers. Retrying in 60 seconds"); RegisterNewState(REGISTERSTATE_ERROR); } else { - dbg_msg("register", "choosen '%s' as master, sending heartbeats", m_pMasterServer->GetName(m_RegisterRegisteredServer)); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "choosen '%s' as master, sending heartbeats", m_pMasterServer->GetName(m_RegisterRegisteredServer)); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", aBuf); m_aMasterserverInfo[m_RegisterRegisteredServer].m_LastSend = 0; RegisterNewState(REGISTERSTATE_HEARTBEAT); } @@ -198,14 +203,14 @@ void CRegister::RegisterUpdate() if(Now > m_RegisterStateStart+Freq*60) { - dbg_msg("register", "WARNING: Master server is not responding, switching master"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "WARNING: Master server is not responding, switching master"); RegisterNewState(REGISTERSTATE_START); } } else if(m_RegisterState == REGISTERSTATE_REGISTERED) { if(m_RegisterFirst) - dbg_msg("register", "server registered"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "server registered"); m_RegisterFirst = 0; @@ -258,15 +263,17 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket) mem_comp(pPacket->m_pData, SERVERBROWSE_FWOK, sizeof(SERVERBROWSE_FWOK)) == 0) { if(m_RegisterFirst) - dbg_msg("register", "no firewall/nat problems detected"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "no firewall/nat problems detected"); RegisterNewState(REGISTERSTATE_REGISTERED); return 1; } else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWERROR) && mem_comp(pPacket->m_pData, SERVERBROWSE_FWERROR, sizeof(SERVERBROWSE_FWERROR)) == 0) { - dbg_msg("register", "ERROR: the master server reports that clients can not connect to this server."); - dbg_msg("register", "ERROR: configure your firewall/nat to let through udp on port %d.", g_Config.m_SvPort); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "ERROR: the master server reports that clients can not connect to this server."); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "ERROR: configure your firewall/nat to let through udp on port %d.", g_Config.m_SvPort); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", aBuf); RegisterNewState(REGISTERSTATE_ERROR); return 1; } diff --git a/src/engine/server/register.h b/src/engine/server/register.h index ea1d9dcc8..bc98b7d90 100644 --- a/src/engine/server/register.h +++ b/src/engine/server/register.h @@ -23,6 +23,7 @@ class CRegister class CNetServer *m_pNetServer; class IEngineMasterServer *m_pMasterServer; + class IConsole *m_pConsole; int m_RegisterState; int64 m_RegisterStateStart; @@ -40,7 +41,7 @@ class CRegister public: CRegister(); - void Init(class CNetServer *pNetServer, class IEngineMasterServer *pMasterServer); + void Init(class CNetServer *pNetServer, class IEngineMasterServer *pMasterServer, class IConsole *pConsole); void RegisterUpdate(); int RegisterProcessPacket(class CNetChunk *pPacket); }; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 9c2af7901..710b54e1c 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -192,7 +192,9 @@ int CServer::TrySetClientName(int ClientID, const char *pName) // trim the name str_copy(aTrimmedName, StrLtrim(pName), sizeof(aTrimmedName)); StrRtrim(aTrimmedName); - dbg_msg("", "'%s' -> '%s'", pName, aTrimmedName); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "'%s' -> '%s'", pName, aTrimmedName); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); pName = aTrimmedName; @@ -535,10 +537,19 @@ int CServer::NewClientCallback(int ClientId, void *pUser) return 0; } -int CServer::DelClientCallback(int ClientId, void *pUser) +int CServer::DelClientCallback(int ClientId, const char *pReason, void *pUser) { CServer *pThis = (CServer *)pUser; + NETADDR Addr = pThis->m_NetServer.ClientAddr(ClientId); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "client dropped. cid=%d ip=%d.%d.%d.%d reason=\"%s\"", + ClientId, + Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], + pReason + ); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); + // notify the mod about the drop if(pThis->m_aClients[ClientId].m_State >= CClient::STATE_READY) pThis->GameServer()->OnClientDrop(ClientId); @@ -670,7 +681,11 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientId, true); if(g_Config.m_Debug) - dbg_msg("server", "sending chunk %d with size %d", Chunk, ChunkSize); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "sending chunk %d with size %d", Chunk, ChunkSize); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + } } else if(Msg == NETMSG_READY) { @@ -678,8 +693,10 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) { Addr = m_NetServer.ClientAddr(ClientId); - dbg_msg("server", "player is ready. ClientId=%x ip=%d.%d.%d.%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "player is ready. ClientId=%x ip=%d.%d.%d.%d", ClientId, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); m_aClients[ClientId].m_State = CClient::STATE_READY; GameServer()->OnClientConnected(ClientId); } @@ -690,8 +707,10 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) { Addr = m_NetServer.ClientAddr(ClientId); - dbg_msg("server", "player has entered the game. ClientId=%x ip=%d.%d.%d.%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "player has entered the game. ClientId=%x ip=%d.%d.%d.%d", ClientId, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); m_aClients[ClientId].m_State = CClient::STATE_INGAME; GameServer()->OnClientEnter(ClientId); } @@ -754,7 +773,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) if(Unpacker.Error() == 0 && m_aClients[ClientId].m_Authed) { - dbg_msg("server", "ClientId=%d rcon='%s'", ClientId, pCmd); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "ClientId=%d rcon='%s'", ClientId, pCmd); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); Console()->ExecuteLine(pCmd); } } @@ -778,7 +799,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) m_aClients[ClientId].m_Authed = 1; SendRconLine(ClientId, "Authentication successful. Remote console access granted."); - dbg_msg("server", "ClientId=%d authed", ClientId); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "ClientId=%d authed", ClientId); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); } else { @@ -804,8 +827,10 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) aBuf[b*3+3] = 0; } - dbg_msg("server", "strange message ClientId=%d msg=%d data_size=%d", ClientId, Msg, pPacket->m_DataSize); - dbg_msg("server", "%s", aBuf); + char aBufMsg[256]; + str_format(aBufMsg, sizeof(aBufMsg), "strange message ClientId=%d msg=%d data_size=%d", ClientId, Msg, pPacket->m_DataSize); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); } } @@ -963,7 +988,9 @@ int CServer::LoadMap(const char *pMapName) // get the crc of the map m_CurrentMapCrc = m_pMap->Crc(); - dbg_msg("server", "%s crc is %08x", aBuf, m_CurrentMapCrc); + char aBufMsg[256]; + str_format(aBufMsg, sizeof(aBufMsg), "%s crc is %08x", aBuf, m_CurrentMapCrc); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg); str_copy(m_aCurrentMap, pMapName, sizeof(m_aCurrentMap)); //map_set(df); @@ -986,9 +1013,9 @@ void CServer::InitEngine(const char *pAppname) m_Engine.Init(pAppname); } -void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer) +void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole) { - m_Register.Init(pNetServer, pMasterServer); + m_Register.Init(pNetServer, pMasterServer, pConsole); } int CServer::Run() @@ -1033,10 +1060,13 @@ int CServer::Run() m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this); - dbg_msg("server", "server name is '%s'", g_Config.m_SvName); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "server name is '%s'", g_Config.m_SvName); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); GameServer()->OnInit(); - dbg_msg("server", "version %s", GameServer()->NetVersion()); + str_format(aBuf, sizeof(aBuf), "version %s", GameServer()->NetVersion()); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); // process pending commands m_pConsole->StoreCommands(false); @@ -1050,7 +1080,10 @@ int CServer::Run() m_GameStartTime = time_get(); if(g_Config.m_Debug) - dbg_msg("server", "baseline memory usage %dk", mem_stats()->allocated/1024); + { + str_format(aBuf, sizeof(aBuf), "baseline memory usage %dk", mem_stats()->allocated/1024); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + } while(m_RunServer) { @@ -1086,7 +1119,8 @@ int CServer::Run() } else { - dbg_msg("server", "failed to load map. mapname='%s'", g_Config.m_SvMap); + str_format(aBuf, sizeof(aBuf), "failed to load map. mapname='%s'", g_Config.m_SvMap); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); str_copy(g_Config.m_SvMap, m_aCurrentMap, sizeof(g_Config.m_SvMap)); } } @@ -1194,7 +1228,7 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser) if(ClientId < 0 || ClientId >= MAX_CLIENTS || ((CServer *)pUser)->m_aClients[ClientId].m_State == CClient::STATE_EMPTY) { - dbg_msg("server", "invalid client id"); + ((CServer *)pUser)->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id"); return; } @@ -1205,10 +1239,12 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser) Addr.port = 0; net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + char aBuf[256]; if(Minutes) - dbg_msg("server", "banned %s for %d minutes", aAddrStr, Minutes); + str_format(aBuf, sizeof(aBuf), "banned %s for %d minutes", aAddrStr, Minutes); else - dbg_msg("server", "banned %s for life", aAddrStr); + str_format(aBuf, sizeof(aBuf), "banned %s for life", aAddrStr); + ((CServer *)pUser)->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); } void CServer::ConUnban(IConsole::IResult *pResult, void *pUser) @@ -1217,19 +1253,27 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser) CServer *pServer = (CServer *)pUser; const char *pStr = pResult->GetString(0); - if(net_addr_from_str(&Addr, pStr) == 0) - pServer->BanRemove(Addr); + if(net_addr_from_str(&Addr, pStr) == 0 && !pServer->BanRemove(Addr)) + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "unbanned %d.%d.%d.%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + } else if(StrAllnum(pStr)) { int BanIndex = str_toint(pStr); CNetServer::CBanInfo Info; if(BanIndex < 0 || !pServer->m_NetServer.BanGet(BanIndex, &Info)) - dbg_msg("server", "invalid ban index"); - else - pServer->BanRemove(Info.m_Addr); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid ban index"); + else if(!pServer->BanRemove(Info.m_Addr)) + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "unbanned %d.%d.%d.%d", Info.m_Addr.ip[0], Info.m_Addr.ip[1], Info.m_Addr.ip[2], Info.m_Addr.ip[3]); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + } } else - dbg_msg("server", "invalid network address"); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address"); } void CServer::ConBans(IConsole::IResult *pResult, void *pUser) @@ -1254,12 +1298,10 @@ void CServer::ConBans(IConsole::IResult *pResult, void *pUser) unsigned t = Info.m_Expires - Now; str_format(aBuf, sizeof(aBuf), "#%d %d.%d.%d.%d for %d minutes and %d seconds", i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], t/60, t%60); } - pServer->Console()->Print(aBuf); - dbg_msg("server", "%s", aBuf); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); } str_format(aBuf, sizeof(aBuf), "%d ban(s)", Num); - pServer->Console()->Print(aBuf); - dbg_msg("server", "%s", aBuf); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); } void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) @@ -1281,8 +1323,7 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) else str_format(aBuf, sizeof(aBuf), "id=%d addr=%d.%d.%d.%d:%d connecting", i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port); - pServer->Console()->Print(aBuf); - dbg_msg("server", "%s", aBuf); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); } } } @@ -1296,7 +1337,7 @@ void CServer::ConRecord(IConsole::IResult *pResult, void *pUser) { char aFilename[512]; str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pResult->GetString(0)); - ((CServer *)pUser)->m_DemoRecorder.Start(((CServer *)pUser)->Storage(), aFilename, ((CServer *)pUser)->GameServer()->NetVersion(), ((CServer *)pUser)->m_aCurrentMap, ((CServer *)pUser)->m_CurrentMapCrc, "server"); + ((CServer *)pUser)->m_DemoRecorder.Start(((CServer *)pUser)->Storage(), ((CServer *)pUser)->Console(), aFilename, ((CServer *)pUser)->GameServer()->NetVersion(), ((CServer *)pUser)->m_aCurrentMap, ((CServer *)pUser)->m_CurrentMapCrc, "server"); } void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser) @@ -1399,7 +1440,7 @@ int main(int argc, const char **argv) // ignore_convention IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention IConfig *pConfig = CreateConfig(); - pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer); + pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConsole); { bool RegisterFail = false; diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 70c8899c6..756c1054e 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -152,7 +152,7 @@ public: void DoSnapshot(); static int NewClientCallback(int ClientId, void *pUser); - static int DelClientCallback(int ClientId, void *pUser); + static int DelClientCallback(int ClientId, const char *pReason, void *pUser); void SendMap(int ClientId); void SendRconLine(int ClientId, const char *pLine); @@ -172,7 +172,7 @@ public: int LoadMap(const char *pMapName); void InitEngine(const char *pAppname); - void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer); + void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole); int Run(); static void ConKick(IConsole::IResult *pResult, void *pUser); diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 9fb67e809..03d8f9074 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -10,6 +10,7 @@ MACRO_CONFIG_STR(PlayerName, player_name, 24, "nameless tee", CFGFLAG_SAVE|CFGFL MACRO_CONFIG_STR(ClanName, clan_name, 32, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "(not used)") MACRO_CONFIG_STR(Password, password, 32, "", CFGFLAG_CLIENT|CFGFLAG_SERVER, "Password to the server") 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(ClEditor, cl_editor, 0, 0, 1, CFGFLAG_CLIENT, "") diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 367e7e87c..dc2e1a252 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -157,11 +157,15 @@ void CConsole::RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUse m_pPrintCallbackUserdata = pUserData; } -void CConsole::Print(const char *pStr) +void CConsole::Print(int Level, const char *pFrom, const char *pStr) { - dbg_msg("console" ,"%s", pStr); - if (m_pfnPrintCallback) - m_pfnPrintCallback(pStr, m_pPrintCallbackUserdata); + dbg_msg(pFrom ,"%s", pStr); + if (Level <= g_Config.m_ConsoleOutputLevel && m_pfnPrintCallback) + { + char aBuf[1024]; + str_format(aBuf, sizeof(aBuf), "[%s]: %s", pFrom, pStr); + m_pfnPrintCallback(aBuf, m_pPrintCallbackUserdata); + } } void CConsole::ExecuteLineStroked(int Stroke, const char *pStr) @@ -218,7 +222,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Invalid arguments... Usage: %s %s", pCommand->m_pName, pCommand->m_pParams); - Print(aBuf); + Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); } else if(m_StoreCommands && pCommand->m_Flags&CFGFLAG_STORE) { @@ -234,7 +238,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "No such command: %s.", pResult->m_pCommand); - Print(aBuf); + Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); } pStr = pNextPart; @@ -298,12 +302,14 @@ void CConsole::ExecuteFile(const char *pFilename) // exec the file IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ); + char aBuf[256]; if(File) { char *pLine; CLineReader lr; - dbg_msg("console", "executing '%s'", pFilename); + str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename); + Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); lr.Init(File); while((pLine = lr.Get())) @@ -312,14 +318,17 @@ void CConsole::ExecuteFile(const char *pFilename) io_close(File); } else - dbg_msg("console", "failed to open '%s'", pFilename); + { + str_format(aBuf, sizeof(aBuf), "failed to open '%s'", pFilename); + Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); + } m_pFirstExec = pPrev; } void CConsole::Con_Echo(IResult *pResult, void *pUserData) { - ((CConsole*)pUserData)->Print(pResult->GetString(0)); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", pResult->GetString(0)); } void CConsole::Con_Exec(IResult *pResult, void *pUserData) @@ -365,7 +374,7 @@ static void IntVariableCommand(IConsole::IResult *pResult, void *pUserData) { char aBuf[1024]; str_format(aBuf, sizeof(aBuf), "Value: %d", *(pData->m_pVariable)); - pData->m_pConsole->Print(aBuf); + pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuf); } } @@ -379,7 +388,7 @@ static void StrVariableCommand(IConsole::IResult *pResult, void *pUserData) { char aBuf[1024]; str_format(aBuf, sizeof(aBuf), "Value: %s", pData->m_pStr); - pData->m_pConsole->Print(aBuf); + pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuf); } } @@ -466,7 +475,9 @@ void CConsole::Chain(const char *pName, FChainCommandCallback pfnChainFunc, void if(!pCommand) { - dbg_msg("console", "failed to chain '%s'", pName); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "failed to chain '%s'", pName); + Print(IConsole::OUTPUT_LEVEL_DEBUG, "console", aBuf); return; } diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index 9c127ae01..87df6dea5 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -123,7 +123,7 @@ public: virtual void ExecuteFile(const char *pFilename); virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData); - virtual void Print(const char *pStr); + virtual void Print(int Level, const char *pFrom, const char *pStr); }; #endif diff --git a/src/engine/shared/demorec.cpp b/src/engine/shared/demorec.cpp index 6c2ba07dc..23da24785 100644 --- a/src/engine/shared/demorec.cpp +++ b/src/engine/shared/demorec.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include "demorec.h" @@ -20,17 +21,20 @@ CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta) //static IOHANDLE m_File = 0; // Record -int CDemoRecorder::Start(class IStorage *pStorage, const char *pFilename, const char *pNetVersion, const char *pMap, int Crc, const char *pType) +int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, int Crc, const char *pType) { CDemoHeader Header; if(m_File) return -1; + m_pConsole = pConsole; m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE); if(!m_File) { - dbg_msg("demorec/record", "Unable to open '%s' for recording", pFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "Unable to open '%s' for recording", pFilename); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf); return -1; } @@ -49,7 +53,9 @@ int CDemoRecorder::Start(class IStorage *pStorage, const char *pFilename, const m_LastKeyFrame = -1; m_LastTickMarker = -1; - dbg_msg("demorec/record", "Recording to '%s'", pFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "Recording to '%s'", pFilename); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf); return 0; } @@ -193,7 +199,7 @@ int CDemoRecorder::Stop() if(!m_File) return -1; - dbg_msg("demorec/record", "Stopped recording"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", "Stopped recording"); io_close(m_File); m_File = 0; return 0; @@ -348,7 +354,7 @@ void CDemoPlayer::DoTick() if(ReadChunkHeader(&ChunkType, &ChunkSize, &ChunkTick)) { // stop on error or eof - dbg_msg("demorec", "end of file"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", "end of file"); Pause(); break; } @@ -359,7 +365,7 @@ void CDemoPlayer::DoTick() if(io_read(m_File, aCompresseddata, ChunkSize) != (unsigned)ChunkSize) { // stop on error or eof - dbg_msg("demorec", "error reading chunk"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", "error reading chunk"); Stop(); break; } @@ -368,7 +374,7 @@ void CDemoPlayer::DoTick() if(DataSize < 0) { // stop on error or eof - dbg_msg("demorec", "error during network decompression"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", "error during network decompression"); Stop(); break; } @@ -377,7 +383,7 @@ void CDemoPlayer::DoTick() if(DataSize < 0) { - dbg_msg("demorec", "error during intpack decompression"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", "error during intpack decompression"); Stop(); break; } @@ -401,7 +407,11 @@ void CDemoPlayer::DoTick() mem_copy(m_aLastSnapshotData, aNewsnap, DataSize); } else - dbg_msg("demorec", "error duing unpacking of delta, err=%d", DataSize); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "error during unpacking of delta, err=%d", DataSize); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", aBuf); + } } else if(ChunkType == CHUNKTYPE_SNAPSHOT) { @@ -452,12 +462,15 @@ void CDemoPlayer::Unpause() } } -int CDemoPlayer::Load(class IStorage *pStorage, const char *pFilename) +int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename) { + m_pConsole = pConsole; m_File = pStorage->OpenFile(pFilename, IOFLAG_READ); if(!m_File) { - dbg_msg("demorec/playback", "could not open '%s'", pFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "could not open '%s'", pFilename); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf); return -1; } @@ -477,7 +490,9 @@ int CDemoPlayer::Load(class IStorage *pStorage, const char *pFilename) io_read(m_File, &m_Info.m_Header, sizeof(m_Info.m_Header)); if(mem_comp(m_Info.m_Header.m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) != 0) { - dbg_msg("demorec/playback", "'%s' is not a demo file", pFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "'%s' is not a demo file", pFilename); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf); io_close(m_File); m_File = 0; return -1; @@ -599,8 +614,10 @@ int CDemoPlayer::Update() if(m_Info.m_Info.m_CurrentTick == m_Info.m_PreviousTick || m_Info.m_Info.m_CurrentTick == m_Info.m_NextTick) { - dbg_msg("demorec/playback", "tick error prev=%d cur=%d next=%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "tick error prev=%d cur=%d next=%d", m_Info.m_PreviousTick, m_Info.m_Info.m_CurrentTick, m_Info.m_NextTick); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", aBuf); } } @@ -612,7 +629,7 @@ int CDemoPlayer::Stop() if(!m_File) return -1; - dbg_msg("demorec/playback", "Stopped playback"); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", "Stopped playback"); io_close(m_File); m_File = 0; mem_free(m_pKeyFrames); diff --git a/src/engine/shared/demorec.h b/src/engine/shared/demorec.h index 294a088b9..cdf46e99a 100644 --- a/src/engine/shared/demorec.h +++ b/src/engine/shared/demorec.h @@ -15,6 +15,7 @@ struct CDemoHeader class CDemoRecorder : public IDemoRecorder { + class IConsole *m_pConsole; IOHANDLE m_File; int m_LastTickMarker; int m_LastKeyFrame; @@ -26,7 +27,7 @@ class CDemoRecorder : public IDemoRecorder public: CDemoRecorder(class CSnapshotDelta *pSnapshotDelta); - int Start(class IStorage *pStorage, const char *pFilename, const char *pNetversion, const char *pMap, int MapCrc, const char *pType); + int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, int MapCrc, const char *pType); int Stop(); void RecordSnapshot(int Tick, const void *pData, int Size); @@ -80,6 +81,7 @@ private: CKeyFrameSearch *m_pNext; }; + class IConsole *m_pConsole; IOHANDLE m_File; CKeyFrame *m_pKeyFrames; @@ -99,7 +101,7 @@ public: void SetListner(IListner *pListner); - int Load(class IStorage *pStorage, const char *pFilename); + int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename); int Play(); void Pause(); void Unpause(); diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index 7de534a44..a2232320c 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -79,7 +79,7 @@ enum }; -typedef int (*NETFUNC_DELCLIENT)(int ClientID, void *pUser); +typedef int (*NETFUNC_DELCLIENT)(int ClientID, const char* pReason, void *pUser); typedef int (*NETFUNC_NEWCLIENT)(int ClientID, void *pUser); struct CNetChunk diff --git a/src/engine/shared/network_client.cpp b/src/engine/shared/network_client.cpp index f7859c0a8..57ed08a88 100644 --- a/src/engine/shared/network_client.cpp +++ b/src/engine/shared/network_client.cpp @@ -21,7 +21,7 @@ int CNetClient::Close() int CNetClient::Disconnect(const char *pReason) { - dbg_msg("netclient", "disconnected. reason=\"%s\"", pReason); + //dbg_msg("netclient", "disconnected. reason=\"%s\"", pReason); m_Connection.Disconnect(pReason); return 0; } diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 2d30a7d1b..ed714365f 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -79,16 +79,15 @@ int CNetServer::Drop(int ClientID, const char *pReason) // TODO: insert lots of checks here NETADDR Addr = ClientAddr(ClientID); - dbg_msg("net_server", "client dropped. cid=%d ip=%d.%d.%d.%d reason=\"%s\"", + /*dbg_msg("net_server", "client dropped. cid=%d ip=%d.%d.%d.%d reason=\"%s\"", ClientID, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], pReason - ); + );*/ + if(m_pfnDelClient) + m_pfnDelClient(ClientID, pReason, m_UserPtr); m_aSlots[ClientID].m_Connection.Disconnect(pReason); - - if(m_pfnDelClient) - m_pfnDelClient(ClientID, m_UserPtr); return 0; } diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp index 1fb5ecc57..4b0db425e 100644 --- a/src/game/client/components/binds.cpp +++ b/src/game/client/components/binds.cpp @@ -30,10 +30,12 @@ void CBinds::Bind(int KeyId, const char *pStr) return; str_copy(m_aaKeyBindings[KeyId], pStr, sizeof(m_aaKeyBindings[KeyId])); + char aBuf[256]; if(!m_aaKeyBindings[KeyId][0]) - dbg_msg("binds", "unbound %s (%d)", Input()->KeyName(KeyId), KeyId); + str_format(aBuf, sizeof(aBuf), "unbound %s (%d)", Input()->KeyName(KeyId), KeyId); else - dbg_msg("binds", "bound %s (%d) = %s", Input()->KeyName(KeyId), KeyId, m_aaKeyBindings[KeyId]); + str_format(aBuf, sizeof(aBuf), "bound %s (%d) = %s", Input()->KeyName(KeyId), KeyId, m_aaKeyBindings[KeyId]); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf); } @@ -136,7 +138,9 @@ void CBinds::ConBind(IConsole::IResult *pResult, void *pUserData) if(!id) { - dbg_msg("binds", "key %s not found", pKeyName); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "key %s not found", pKeyName); + pBinds->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf); return; } @@ -152,7 +156,9 @@ void CBinds::ConUnbind(IConsole::IResult *pResult, void *pUserData) if(!id) { - dbg_msg("binds", "key %s not found", pKeyName); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "key %s not found", pKeyName); + pBinds->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf); return; } @@ -175,8 +181,8 @@ void CBinds::ConDumpBinds(IConsole::IResult *pResult, void *pUserData) { if(pBinds->m_aaKeyBindings[i][0] == 0) continue; - str_format(aBuf, sizeof(aBuf), "[binds] %s (%d) = %s", pBinds->Input()->KeyName(i), i, pBinds->m_aaKeyBindings[i]); - pBinds->Console()->Print(aBuf); + str_format(aBuf, sizeof(aBuf), "%s (%d) = %s", pBinds->Input()->KeyName(i), i, pBinds->m_aaKeyBindings[i]); + pBinds->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf); } } diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 7b64aac7b..21fa0e007 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -61,7 +61,7 @@ void CChat::ConChat(IConsole::IResult *pResult, void *pUserData) else if(str_comp(pMode, "team") == 0) ((CChat*)pUserData)->EnableMode(1); else - dbg_msg("console", "expected all or team as mode"); + ((CChat*)pUserData)->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", "expected all or team as mode"); } void CChat::ConShowChat(IConsole::IResult *pResult, void *pUserData) @@ -165,8 +165,8 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine) } char aBuf[1024]; - str_format(aBuf, sizeof(aBuf), "[chat]%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText); - Console()->Print(aBuf); + str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "chat", aBuf); } // play sound diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index c1ad18f28..bd643a3ce 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -699,7 +699,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView) static int s_JoinButton = 0; if(DoButton_Menu(&s_JoinButton, Localize("Connect"), 0, &Button) || m_EnterPressed) { - dbg_msg("", "%s", g_Config.m_UiServerAddress); + //dbg_msg("", "%s", g_Config.m_UiServerAddress); Client()->Connect(g_Config.m_UiServerAddress); m_EnterPressed = false; } diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 364d0b82e..3a97e3ec9 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -706,7 +706,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) if(OldSelected != s_SelectedLanguage) { str_copy(g_Config.m_ClLanguagefile, s_Languages[s_SelectedLanguage].m_FileName, sizeof(g_Config.m_ClLanguagefile)); - g_Localization.Load(s_Languages[s_SelectedLanguage].m_FileName); + g_Localization.Load(s_Languages[s_SelectedLanguage].m_FileName, Console()); } } diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 582adb10b..73cf954da 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -29,7 +29,8 @@ void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) CImageInfo Info; if(!pSelf->Graphics()->LoadPNG(&Info, aBuf)) { - dbg_msg("game", "failed to load skin from %s", pName); + str_format(aBuf, sizeof(aBuf), "failed to load skin from %s", pName); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); return; } @@ -111,7 +112,8 @@ void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) // set skin data str_copy(pSelf->m_aSkins[pSelf->m_NumSkins].m_aName, pName, min((int)sizeof(pSelf->m_aSkins[pSelf->m_NumSkins].m_aName),l-3)); - dbg_msg("game", "load skin %s", pSelf->m_aSkins[pSelf->m_NumSkins].m_aName); + str_format(aBuf, sizeof(aBuf), "load skin %s", pSelf->m_aSkins[pSelf->m_NumSkins].m_aName); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); pSelf->m_NumSkins++; } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index acf29eb7e..8c500079a 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -223,7 +223,7 @@ void CGameClient::OnInit() //m_pServerBrowser = Kernel()->RequestInterface(); // set the language - g_Localization.Load(g_Config.m_ClLanguagefile); + g_Localization.Load(g_Config.m_ClLanguagefile, Console()); // init all components for(int i = 0; i < m_All.m_Num; i++) @@ -288,7 +288,9 @@ void CGameClient::OnInit() m_All.m_paComponents[i]->OnReset(); int64 End = time_get(); - dbg_msg("", "%f.2ms", ((End-Start)*1000)/(float)time_freq()); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "initialisation finished after %f.2ms", ((End-Start)*1000)/(float)time_freq()); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "gameclient", aBuf); m_ServerMode = SERVERMODE_PURE; } @@ -517,7 +519,9 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker) void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgId, pUnpacker); if(!pRawMsg) { - dbg_msg("client", "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgId), MsgId, m_NetObjHandler.FailedMsgOn()); + 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_ADDINFO, "client", aBuf); return; } @@ -635,7 +639,11 @@ void CGameClient::OnNewSnapshot() if(m_NetObjHandler.ValidateObj(Item.m_Type, pData, Item.m_DataSize) != 0) { if(g_Config.m_Debug) - dbg_msg("game", "invalidated index=%d type=%d (%s) size=%d id=%d", Index, Item.m_Type, m_NetObjHandler.GetObjName(Item.m_Type), Item.m_DataSize, Item.m_Id); + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "invalidated index=%d type=%d (%s) size=%d id=%d", Index, Item.m_Type, m_NetObjHandler.GetObjName(Item.m_Type), Item.m_DataSize, Item.m_Id); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); + } Client()->SnapInvalidateItem(IClient::SNAP_CURRENT, Index); } } @@ -904,11 +912,13 @@ void CGameClient::OnPredict() if(mem_comp(&Before, &Now, sizeof(CNetObj_CharacterCore)) != 0) { - dbg_msg("client", "prediction error"); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", "prediction error"); for(unsigned i = 0; i < sizeof(CNetObj_CharacterCore)/sizeof(int); i++) if(((int *)&Before)[i] != ((int *)&Now)[i]) { - dbg_msg("", "\t%d %d %d (%d %d)", i, ((int *)&Before)[i], ((int *)&Now)[i], ((int *)&BeforePrev)[i], ((int *)&NowPrev)[i]); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), " %d %d %d (%d %d)", i, ((int *)&Before)[i], ((int *)&Now)[i], ((int *)&BeforePrev)[i], ((int *)&NowPrev)[i]); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf); } } } diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index a2ecfb7ee..aa6b78291 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1271,7 +1272,9 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) if(!UI()->MouseButton(0)) { // grab brush - dbg_msg("editor", "grabbing %f %f %f %f", r.x, r.y, r.w, r.h); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf),"grabbing %f %f %f %f", r.x, r.y, r.w, r.h); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", aBuf); // TODO: do all layers int Grabs = 0; @@ -1820,7 +1823,7 @@ static void ExtractName(const char *pFileName, char *pName) int FinalLen = End-Start; mem_copy(pName, &pFileName[Start], FinalLen); pName[FinalLen] = 0; - dbg_msg("", "%s %s %d %d", pFileName, pName, Start, End); + //dbg_msg("", "%s %s %d %d", pFileName, pName, Start, End); } void CEditor::ReplaceImage(const char *pFileName, void *pUser) @@ -3006,6 +3009,7 @@ void CEditor::Init() { m_pInput = Kernel()->RequestInterface(); m_pClient = Kernel()->RequestInterface(); + m_pConsole = Kernel()->RequestInterface(); m_pGraphics = Kernel()->RequestInterface(); m_pTextRender = Kernel()->RequestInterface(); m_RenderTools.m_pGraphics = m_pGraphics; diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index 9ccb32030..bbc3c45ff 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -427,6 +427,7 @@ class CEditor : public IEditor { class IInput *m_pInput; class IClient *m_pClient; + class IConsole *m_pConsole; class IGraphics *m_pGraphics; class ITextRender *m_pTextRender; CRenderTools m_RenderTools; @@ -434,6 +435,7 @@ class CEditor : public IEditor public: class IInput *Input() { return m_pInput; }; class IClient *Client() { return m_pClient; }; + class IConsole *Console() { return m_pConsole; }; class IGraphics *Graphics() { return m_pGraphics; }; class ITextRender *TextRender() { return m_pTextRender; }; CUI *UI() { return &m_UI; } diff --git a/src/game/editor/ed_io.cpp b/src/game/editor/ed_io.cpp index 4d5140514..6eae9fb5c 100644 --- a/src/game/editor/ed_io.cpp +++ b/src/game/editor/ed_io.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -197,11 +198,14 @@ int CEditor::Save(const char *pFilename) int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) { - dbg_msg("editor", "saving to '%s'...", pFileName); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "saving to '%s'...", pFileName); + m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "editor", aBuf); CDataFileWriter df; if(!df.Open(pStorage, pFileName)) { - dbg_msg("editor", "failed to open file '%s'...", pFileName); + str_format(aBuf, sizeof(aBuf), "failed to open file '%s'...", pFileName); + m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "editor", aBuf); return 0; } @@ -259,7 +263,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) { if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_TILES) { - dbg_msg("editor", "saving tiles layer"); + m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving tiles layer"); CLayerTiles *pLayer = (CLayerTiles *)pGroup->m_lLayers[l]; pLayer->PrepareForSave(); @@ -288,7 +292,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) } else if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_QUADS) { - dbg_msg("editor", "saving quads layer"); + m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving quads layer"); CLayerQuads *pLayer = (CLayerQuads *)pGroup->m_lLayers[l]; if(pLayer->m_lQuads.size()) { @@ -346,7 +350,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) // finish the data file df.Finish(); - dbg_msg("editor", "done"); + m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving done"); // send rcon.. if we can /* diff --git a/src/game/editor/ed_layer_quads.cpp b/src/game/editor/ed_layer_quads.cpp index 023fd29f8..83fd43929 100644 --- a/src/game/editor/ed_layer_quads.cpp +++ b/src/game/editor/ed_layer_quads.cpp @@ -1,5 +1,6 @@ #include +#include #include #include "ed_editor.h" @@ -124,7 +125,7 @@ int CLayerQuads::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) if(px > Rect.x && px < Rect.x+Rect.w && py > Rect.y && py < Rect.y+Rect.h) { - dbg_msg("", "grabbed one"); + m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", "grabbed one"); CQuad n; n = *q; diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp index 8152c67c8..68f804b58 100644 --- a/src/game/editor/ed_popups.cpp +++ b/src/game/editor/ed_popups.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -19,7 +20,7 @@ static int g_UiNumPopups = 0; void CEditor::UiInvokePopupMenu(void *Id, int Flags, float x, float y, float w, float h, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect), void *pExtra) { - dbg_msg("", "invoked"); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", "invoked"); if(x + w > UI()->Screen()->w) x -= w; if(y + h > UI()->Screen()->h) diff --git a/src/game/localization.cpp b/src/game/localization.cpp index 02065e365..fc9ac3df4 100644 --- a/src/game/localization.cpp +++ b/src/game/localization.cpp @@ -3,6 +3,7 @@ #include #include +#include const char *Localize(const char *pStr) { @@ -39,7 +40,7 @@ void CLocalizationDatabase::AddString(const char *pOrgStr, const char *pNewStr) m_Strings.add(s); } -bool CLocalizationDatabase::Load(const char *pFilename) +bool CLocalizationDatabase::Load(const char *pFilename, IConsole *pConsole) { // empty string means unload if(pFilename[0] == 0) @@ -53,7 +54,9 @@ bool CLocalizationDatabase::Load(const char *pFilename) if(!IoHandle) return false; - dbg_msg("localization", "loaded '%s'", pFilename); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "loaded '%s'", pFilename); + pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf); m_Strings.clear(); CLineReader LineReader; @@ -70,13 +73,14 @@ bool CLocalizationDatabase::Load(const char *pFilename) char *pReplacement = LineReader.Get(); if(!pReplacement) { - dbg_msg("", "unexpected end of file"); + pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "unexpected end of file"); break; } if(pReplacement[0] != '=' || pReplacement[1] != '=' || pReplacement[2] != ' ') { - dbg_msg("", "malform replacement line for '%s'", pLine); + str_format(aBuf, sizeof(aBuf), "malform replacement line for '%s'", pLine); + pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf); continue; } diff --git a/src/game/localization.h b/src/game/localization.h index 2e96ef04e..e117c4ffe 100644 --- a/src/game/localization.h +++ b/src/game/localization.h @@ -24,7 +24,7 @@ class CLocalizationDatabase public: CLocalizationDatabase(); - bool Load(const char *pFilename); + bool Load(const char *pFilename, class IConsole *pConsole); int Version() { return m_CurrentVersion; } diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 5dd212a95..ef60cd4cb 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -604,7 +604,8 @@ void CCharacter::TickDefered() StartVelX.f = StartVel.x; StartVelY.f = StartVel.y; - dbg_msg("char_core", "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x", StuckBefore, StuckAfterMove, StuckAfterQuant, @@ -612,6 +613,7 @@ void CCharacter::TickDefered() StartVel.x, StartVel.y, StartPosX.u, StartPosY.u, StartVelX.u, StartVelY.u); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); } int Events = m_Core.m_TriggeredEvents; @@ -669,9 +671,11 @@ void CCharacter::Die(int Killer, int Weapon) { int ModeSpecial = GameServer()->m_pController->OnCharacterDeath(this, GameServer()->m_apPlayers[Killer], Weapon); - dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", Killer, Server()->ClientName(Killer), m_pPlayer->GetCID(), Server()->ClientName(m_pPlayer->GetCID()), Weapon, ModeSpecial); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); // send the kill message CNetMsg_Sv_KillMsg Msg; diff --git a/src/game/server/entities/pickup.cpp b/src/game/server/entities/pickup.cpp index 9798e2c3e..020b4c601 100644 --- a/src/game/server/entities/pickup.cpp +++ b/src/game/server/entities/pickup.cpp @@ -109,8 +109,10 @@ void CPickup::Tick() if(RespawnTime >= 0) { - dbg_msg("game", "pickup player='%d:%s' item=%d/%d", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "pickup player='%d:%s' item=%d/%d", pChr->GetPlayer()->GetCID(), Server()->ClientName(pChr->GetPlayer()->GetCID()), m_Type, m_Subtype); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime; } } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 3f7a5b141..1b96b812c 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -215,10 +215,12 @@ void CGameContext::SendChatTarget(int To, const char *pText) void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText) { + char aBuf[256]; if(ChatterClientId >= 0 && ChatterClientId < MAX_CLIENTS) - dbg_msg("chat", "%d:%d:%s: %s", ChatterClientId, Team, Server()->ClientName(ChatterClientId), pText); + str_format(aBuf, sizeof(aBuf), "%d:%d:%s: %s", ChatterClientId, Team, Server()->ClientName(ChatterClientId), pText); else - dbg_msg("chat", "*** %s", pText); + str_format(aBuf, sizeof(aBuf), "*** %s", pText); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "chat", aBuf); if(Team == CHAT_ALL) { @@ -353,7 +355,7 @@ void CGameContext::CheckPureTuning() CTuningParams p; if(mem_comp(&p, &m_Tuning, sizeof(p)) != 0) { - dbg_msg("server", "resetting tuning due to pure server"); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "resetting tuning due to pure server"); m_Tuning = p; } } @@ -496,14 +498,12 @@ void CGameContext::OnClientEnter(int ClientId) { //world.insert_entity(&players[client_id]); m_apPlayers[ClientId]->Respawn(); - dbg_msg("game", "join player='%d:%s'", ClientId, Server()->ClientName(ClientId)); - - char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s entered and joined the %s", Server()->ClientName(ClientId), m_pController->GetTeamName(m_apPlayers[ClientId]->GetTeam())); SendChat(-1, CGameContext::CHAT_ALL, aBuf); - dbg_msg("game", "team_join player='%d:%s' team=%d", ClientId, Server()->ClientName(ClientId), m_apPlayers[ClientId]->GetTeam()); + str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' team=%d", ClientId, Server()->ClientName(ClientId), m_apPlayers[ClientId]->GetTeam()); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); m_VoteUpdate = true; } @@ -555,7 +555,9 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) if(!pRawMsg) { - dbg_msg("server", "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgId), MsgId, m_NetObjHandler.FailedMsgOn()); + 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_ADDINFO, "server", aBuf); return; } @@ -813,13 +815,15 @@ void CGameContext::ConTuneParam(IConsole::IResult *pResult, void *pUserData) const char *pParamName = pResult->GetString(0); float NewValue = pResult->GetFloat(1); + char aBuf[256]; if(pSelf->Tuning()->Set(pParamName, NewValue)) { - dbg_msg("tuning", "%s changed to %.2f", pParamName, NewValue); + str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); pSelf->SendTuningParams(-1); } else - dbg_msg("tuning", "No such tuning parameter"); + str_format(aBuf, sizeof(aBuf), "No such tuning parameter"); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } void CGameContext::ConTuneReset(IConsole::IResult *pResult, void *pUserData) @@ -828,17 +832,19 @@ void CGameContext::ConTuneReset(IConsole::IResult *pResult, void *pUserData) CTuningParams p; *pSelf->Tuning() = p; pSelf->SendTuningParams(-1); - dbg_msg("tuning", "Tuning reset"); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", "Tuning reset"); } void CGameContext::ConTuneDump(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; + char aBuf[256]; for(int i = 0; i < pSelf->Tuning()->Num(); i++) { float v; pSelf->Tuning()->Get(i, &v); - dbg_msg("tuning", "%s %.2f", pSelf->Tuning()->m_apNames[i], v); + str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->m_apNames[i], v); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } } @@ -875,7 +881,9 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) int ClientId = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); - dbg_msg("", "%d %d", ClientId, Team); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientId, Team); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); if(!pSelf->m_apPlayers[ClientId]) return; @@ -899,7 +907,9 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->m_pVoteOptionFirst = pOption; mem_copy(pOption->m_aCommand, pResult->GetString(0), Len+1); - dbg_msg("server", "added option '%s'", pOption->m_aCommand); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "added option '%s'", pOption->m_aCommand); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); CNetMsg_Sv_VoteOption OptionMsg; OptionMsg.m_pCommand = pOption->m_aCommand; @@ -913,7 +923,9 @@ void CGameContext::ConVote(IConsole::IResult *pResult, void *pUserData) pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_YES; else if(str_comp_nocase(pResult->GetString(0), "no") == 0) pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_NO; - dbg_msg("server", "forcing vote %s", pResult->GetString(0)); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "forcing vote %s", pResult->GetString(0)); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); } void CGameContext::ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 04eb8c6ee..854787d66 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -200,7 +200,9 @@ void IGameController::StartRound() m_aTeamscore[0] = 0; m_aTeamscore[1] = 0; m_ForceBalanced = false; - dbg_msg("game","start round type='%s' teamplay='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "start round type='%s' teamplay='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); } void IGameController::ChangeMap(const char *pToMap) @@ -213,7 +215,9 @@ void IGameController::CycleMap() { if(m_aMapWish[0] != 0) { - dbg_msg("game", "rotating map to %s", m_aMapWish); + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "rotating map to %s", m_aMapWish); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); str_copy(g_Config.m_SvMap, m_aMapWish, sizeof(g_Config.m_SvMap)); m_aMapWish[0] = 0; m_RoundCount = 0; @@ -255,26 +259,28 @@ void IGameController::CycleMap() pNextMap = pMapRotation; // cut out the next map - char Buf[512]; + char aBuf[512]; for(int i = 0; i < 512; i++) { - Buf[i] = pNextMap[i]; + aBuf[i] = pNextMap[i]; if(IsSeparator(pNextMap[i]) || pNextMap[i] == 0) { - Buf[i] = 0; + aBuf[i] = 0; break; } } // skip spaces int i = 0; - while(IsSeparator(Buf[i])) + while(IsSeparator(aBuf[i])) i++; m_RoundCount = 0; - dbg_msg("game", "rotating map to %s", &Buf[i]); - str_copy(g_Config.m_SvMap, &Buf[i], sizeof(g_Config.m_SvMap)); + char aBufMsg[256]; + str_format(aBufMsg, sizeof(aBufMsg), "rotating map to %s", &aBuf[i]); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); + str_copy(g_Config.m_SvMap, &aBuf[i], sizeof(g_Config.m_SvMap)); } void IGameController::PostReset() @@ -398,7 +404,7 @@ void IGameController::Tick() // do team-balancing if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) { - dbg_msg("game", "Balancing teams"); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams"); int aT[2] = {0,0}; float aTScore[2] = {0,0}; @@ -570,16 +576,19 @@ bool IGameController::CheckTeamBalance() aT[pP->GetTeam()]++; } + char aBuf[256]; if(absolute(aT[0]-aT[1]) >= 2) { - dbg_msg("game", "Team is NOT balanced (red=%d blue=%d)", aT[0], aT[1]); + str_format(aBuf, sizeof(aBuf), "Team is NOT balanced (red=%d blue=%d)", aT[0], aT[1]); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); if(GameServer()->m_pController->m_UnbalancedTick == -1) GameServer()->m_pController->m_UnbalancedTick = Server()->Tick(); return false; } else { - dbg_msg("game", "Team is balanced (red=%d blue=%d)", aT[0], aT[1]); + str_format(aBuf, sizeof(aBuf), "Team is balanced (red=%d blue=%d)", aT[0], aT[1]); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); GameServer()->m_pController->m_UnbalancedTick = -1; return true; } diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index 3c052a918..4b25fc478 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -111,21 +111,22 @@ void CGameControllerCTF::Tick() m_aTeamscore[fi^1] += 100; F->m_pCarryingCharacter->GetPlayer()->m_Score += 5; - dbg_msg("game", "flag_capture player='%d:%s'", + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "flag_capture player='%d:%s'", F->m_pCarryingCharacter->GetPlayer()->GetCID(), Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); - char Buf[512]; float CaptureTime = (Server()->Tick() - F->m_GrabTick)/(float)Server()->TickSpeed(); if(CaptureTime <= 60) { - str_format(Buf, sizeof(Buf), "The %s flag was captured by %s (%d.%s%d seconds)", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID()), (int)CaptureTime%60, ((int)(CaptureTime*100)%100)<10?"0":"", (int)(CaptureTime*100)%100); + str_format(aBuf, sizeof(aBuf), "The %s flag was captured by %s (%d.%s%d seconds)", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID()), (int)CaptureTime%60, ((int)(CaptureTime*100)%100)<10?"0":"", (int)(CaptureTime*100)%100); } else { - str_format(Buf, sizeof(Buf), "The %s flag was captured by %s", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); + str_format(aBuf, sizeof(aBuf), "The %s flag was captured by %s", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); } - GameServer()->SendChat(-1, -2, Buf); + GameServer()->SendChat(-1, -2, aBuf); for(int i = 0; i < 2; i++) m_apFlags[i]->Reset(); @@ -150,9 +151,11 @@ void CGameControllerCTF::Tick() CCharacter *pChr = apCloseCCharacters[i]; pChr->GetPlayer()->m_Score += 1; - dbg_msg("game", "flag_return player='%d:%s'", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "flag_return player='%d:%s'", pChr->GetPlayer()->GetCID(), Server()->ClientName(pChr->GetPlayer()->GetCID())); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); GameServer()->CreateSoundGlobal(SOUND_CTF_RETURN); F->Reset(); @@ -171,9 +174,11 @@ void CGameControllerCTF::Tick() F->m_pCarryingCharacter = apCloseCCharacters[i]; F->m_pCarryingCharacter->GetPlayer()->m_Score += 1; - dbg_msg("game", "flag_grab player='%d:%s'", + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "flag_grab player='%d:%s'", F->m_pCarryingCharacter->GetPlayer()->GetCID(), Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); for(int c = 0; c < MAX_CLIENTS; c++) { diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 2d5d244f9..cc89c11d6 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -95,11 +95,12 @@ void CPlayer::OnDisconnect() if(Server()->ClientIngame(m_ClientID)) { - char Buf[512]; - str_format(Buf, sizeof(Buf), "%s has left the game", Server()->ClientName(m_ClientID)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, Buf); + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "%s has left the game", Server()->ClientName(m_ClientID)); + GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); - dbg_msg("game", "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID)); + str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID)); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf); } } @@ -151,16 +152,17 @@ void CPlayer::SetTeam(int Team) if(m_Team == Team) return; - char Buf[512]; - str_format(Buf, sizeof(Buf), "%s joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, Buf); + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "%s joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); + GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); KillCharacter(); m_Team = Team; // we got to wait 0.5 secs before respawning m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2; - dbg_msg("game", "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team); + str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team); + GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); GameServer()->m_pController->OnPlayerInfoChange(GameServer()->m_apPlayers[m_ClientID]); } From 0f72fd19ef9f03b335c9bc4e4dae764079e1f30d Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 18 Aug 2010 00:21:38 +0200 Subject: [PATCH 08/27] fixed text rendering problem. Closes #12 --- src/engine/client/text.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index ef741c129..bdf71dbb4 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -570,6 +570,8 @@ public: pSizeData = GetSize(pFont, ActualSize); RenderSetup(pFont, ActualSize); + + float Scale = 1/pSizeData->m_FontSize; // set length if(Length < 0) @@ -679,7 +681,7 @@ public: Graphics()->QuadsDrawTL(&QuadItem, 1); } - Advance = pChr->m_AdvanceX + Kerning(pFont, Character, Nextcharacter)/Size; + Advance = pChr->m_AdvanceX + Kerning(pFont, Character, Nextcharacter)*Scale; } if(pCursor->m_Flags&TEXTFLAG_STOP_AT_END && DrawX+(Advance+pChr->m_Width)*Size-pCursor->m_StartX > pCursor->m_LineWidth) From 538d968349faaec96ca010cc3fa0efdc13a05aed Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 18 Aug 2010 03:57:35 +0200 Subject: [PATCH 09/27] fixed that scoreboard overlaps the chat. Closes #14 --- src/game/client/components/chat.cpp | 11 ++++++----- src/game/client/components/scoreboard.cpp | 5 +++++ src/game/client/components/scoreboard.h | 2 ++ src/game/client/gameclient.cpp | 1 + src/game/client/gameclient.h | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 21fa0e007..4429837ba 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -9,6 +9,7 @@ #include +#include #include #include @@ -205,9 +206,10 @@ void CChat::OnRender() y -= 8.0f; - int i; int64 Now = time_get(); - for(i = 0; i < MAX_LINES; i++) + float LineWidth = m_pClient->m_pScoreboard->Active() ? 95.0f : 200.0f; + float HeightLimit = m_pClient->m_pScoreboard->Active() ? 220.0f : m_Show ? 50.0f : 200.0f; + for(int i = 0; i < MAX_LINES; i++) { int r = ((m_CurrentLine-i)+MAX_LINES)%MAX_LINES; if(Now > m_aLines[r].m_Time+15*time_freq() && !m_Show) @@ -219,19 +221,18 @@ void CChat::OnRender() // get the y offset CTextCursor Cursor; TextRender()->SetCursor(&Cursor, Begin, 0, FontSize, 0); - Cursor.m_LineWidth = 200.0f; + Cursor.m_LineWidth = LineWidth; TextRender()->TextEx(&Cursor, m_aLines[r].m_aName, -1); TextRender()->TextEx(&Cursor, m_aLines[r].m_aText, -1); y -= Cursor.m_Y + Cursor.m_FontSize; // cut off if msgs waste too much space - float HeightLimit = m_Show ? 0.0f : 200.0f; if(y < HeightLimit) break; // reset the cursor TextRender()->SetCursor(&Cursor, Begin, y, FontSize, TEXTFLAG_RENDER); - Cursor.m_LineWidth = 200.0f; + Cursor.m_LineWidth = LineWidth; // render name TextRender()->TextColor(0.8f,0.8f,0.8f,1); diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index 27e577e82..5f9aeea76 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -322,3 +322,8 @@ void CScoreboard::OnRender() RenderGoals(Width/2-w/2, 150+750+25, w); RenderSpectators(Width/2-w/2, 150+750+25+50+25, w); } + +bool CScoreboard::Active() +{ + return m_Active | (m_pClient->m_Snap.m_pGameobj && m_pClient->m_Snap.m_pGameobj->m_GameOver); +} diff --git a/src/game/client/components/scoreboard.h b/src/game/client/components/scoreboard.h index 5aa2f0a71..f94c6b49f 100644 --- a/src/game/client/components/scoreboard.h +++ b/src/game/client/components/scoreboard.h @@ -17,6 +17,8 @@ public: virtual void OnReset(); virtual void OnConsoleInit(); virtual void OnRender(); + + bool Active(); }; #endif diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 8c500079a..841571b18 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -134,6 +134,7 @@ void CGameClient::OnConsoleInit() m_pDamageind = &::gsDamageInd; m_pMapimages = &::gs_MapImages; m_pVoting = &::gs_Voting; + m_pScoreboard = &::gs_Scoreboard; // make a list of all the systems, make sure to add them in the corrent render order m_All.Add(m_pSkins); diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 211e3b11b..888188db6 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -205,6 +205,7 @@ public: class CMotd *m_pMotd; class CMapImages *m_pMapimages; class CVoting *m_pVoting; + class CScoreboard *m_pScoreboard; }; extern const char *Localize(const char *Str); From 4123f28bbaa169ba8bb273f813fd7165e4f3a867 Mon Sep 17 00:00:00 2001 From: Fujnky Date: Fri, 3 Sep 2010 22:30:46 +0200 Subject: [PATCH 10/27] Improved demo player another bit. * Replaced the reset button by more common stop button * Made the demo player automatically reset after demo ended --- data/demo_buttons.png | Bin 599 -> 616 bytes datasrc/content.py | 2 +- src/game/client/components/menus_demo.cpp | 18 +++++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/data/demo_buttons.png b/data/demo_buttons.png index 47a5c2f11e750612f6c080541a25921eb48d49a3..5f39410268da128de73d6c2031d0504bd2966c4c 100644 GIT binary patch delta 532 zcmV+v0_*+P1n2~iUw;T54ks4dNYuIj00HPpL_t(|+U=S>P6AOBh0i5Q2n1F@i92x% zZotCQgv!Rs&Wgm+!j<4oOx%Y`j?FUxoq0dQdv6fVmrTVS?tAxqL&D4eLI@#*5JCtc zgb+fAlZWJrrza|4SN_PD zx`sf_)aBB;*O;2rysJ9VFw_T<6A4&Hz@~FaPFxPHdyT2-ns-$vJj1;wIhKHR1a!yP z&E40}TazR2s!jw3ydilkp&4vK30L*nKHHo>K+wchY z*62hD0bc=JnAxS7z00YjpQd*JmjEu@982`*V{5HW41WqWd6Q0i@m5;I9>i;OVj%I3 zO2pSnQq^<9^EZ1x(~Q>EZp3E{k%0f@~-McU*btX@1wXz$x>^&=3Ui^zQmJ& zQ7`Nn5Y#^VxB9EvRh5aPru#t#eyYj*4t zers_)>al;wz52etbu1q^=BmpopPYV8;bnQCx?B2x<_Gl-jLk-T-|igQ>htXPv5L>m z*%Q9(ULo8kSHpZG_`uDb)zy9nxB9S_bZVTu4$<~umOjJot=twfH*bEvXx-DP4U_(e zn0ow*y~26Mm|+L=jdi{UPTp8++n)GtgA$9#)8#81Z@e$^b2!HEV4Cxha^VY#$9xsq z!VW9|>Qa!+te?XX^M&()u*3EOM(f?@(@#C?&kA_De`Z7GoB+LF+z+@CHajq`FRQnl zwZHSEf1um3(z$*$DZgG`lT6k-HsdnWdN+Nbq($nv^_}N9TVL8Xd_E+9FnzawN)^lM zPxrqF$~@zLU`+u>@P}H zVN+PdFWLz%h6Dmo>`&;N;HH-KkM{h$C8hFL?-kInDB%F5MQ#q~CGzVscqi3~moA!C zv6jo?tdzHamA{qSB>lCHm)_svD!VEy*>FVdQ&MBb@0CiIA ACjbBd diff --git a/datasrc/content.py b/datasrc/content.py index a11988b4c..92e71b96e 100644 --- a/datasrc/content.py +++ b/datasrc/content.py @@ -368,7 +368,7 @@ container.sprites.Add(Sprite("browse_unpure", set_browseicons, 3,0,1,1)) container.sprites.Add(Sprite("demobutton_play", set_demobuttons, 0,0,1,1)) container.sprites.Add(Sprite("demobutton_pause", set_demobuttons, 1,0,1,1)) -container.sprites.Add(Sprite("demobutton_reset", set_demobuttons, 2,0,1,1)) +container.sprites.Add(Sprite("demobutton_stop", set_demobuttons, 2,0,1,1)) container.sprites.Add(Sprite("demobutton_slower", set_demobuttons, 3,0,1,1)) container.sprites.Add(Sprite("demobutton_faster", set_demobuttons, 4,0,1,1)) diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index ef9ac62d1..82be758dc 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -59,6 +59,9 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) CUIRect SeekBar, ButtonBar; + int CurrentTick = pInfo->m_CurrentTick - pInfo->m_FirstTick; + int TotalTicks = pInfo->m_LastTick - pInfo->m_FirstTick; + if(m_MenuActive) { MainView.HSplitTop(SeekBarHeight, &SeekBar, &ButtonBar); @@ -75,9 +78,6 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) RenderTools()->DrawUIRect(&SeekBar, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 5.0f); - int CurrentTick = pInfo->m_CurrentTick - pInfo->m_FirstTick; - int TotalTicks = pInfo->m_LastTick - pInfo->m_FirstTick; - float Amount = CurrentTick/(float)TotalTicks; CUIRect FilledBar = SeekBar; @@ -120,7 +120,12 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) if(Inside) UI()->SetHotItem(id); } - + + if(CurrentTick == TotalTicks) + { + DemoPlayer()->Pause(); + DemoPlayer()->SetPos(0); + } if(m_MenuActive) { @@ -141,11 +146,14 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) DemoPlayer()->Unpause(); } + // stop button + ButtonBar.VSplitLeft(Margins, 0, &ButtonBar); ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar); static int s_ResetButton = 0; - if(DoButton_DemoPlayer_Sprite(&s_ResetButton, SPRITE_DEMOBUTTON_RESET, false, &Button)) + if(DoButton_DemoPlayer_Sprite(&s_ResetButton, SPRITE_DEMOBUTTON_STOP, false, &Button)) { + DemoPlayer()->Pause(); DemoPlayer()->SetPos(0); } From 25be8b1be3bfe57a3d7a2c86be68dec4e51b93c3 Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 19:39:20 +0200 Subject: [PATCH 11/27] fixed so clicking 3 times doesn't generate 2 double-clicks --- src/engine/client/input.cpp | 8 +++++++- src/game/client/components/menus_demo.cpp | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp index c6d3f58e1..195b78aac 100644 --- a/src/engine/client/input.cpp +++ b/src/engine/client/input.cpp @@ -87,7 +87,13 @@ void CInput::MouseModeRelative() int CInput::MouseDoubleClick() { - return m_ReleaseDelta < (time_freq() >> 2); + if(m_ReleaseDelta >= 0 && m_ReleaseDelta < (time_freq() >> 2)) + { + m_LastRelease = 0; + m_ReleaseDelta = -1; + return 1; + } + return 0; } void CInput::ClearKeyStates() diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 82be758dc..45a96d80d 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -342,6 +342,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(void *pId, bool Selected) if(m_EnterPressed || (Input()->MouseDoubleClick() && UI()->ActiveItem() == pId)) { gs_ListBoxItemActivated = true; + UI()->SetActiveItem(0); } else { From 8522cab449122a69303ca938ae7898d803d23eaf Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 14:04:50 +0200 Subject: [PATCH 12/27] fixed variable types --- src/engine/client/input.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/client/input.h b/src/engine/client/input.h index 0b6d5b76f..aeaefca1a 100644 --- a/src/engine/client/input.h +++ b/src/engine/client/input.h @@ -7,8 +7,8 @@ class CInput : public IEngineInput int m_InputGrabbed; - unsigned int m_LastRelease; - int m_ReleaseDelta; + int64 m_LastRelease; + int64 m_ReleaseDelta; void AddEvent(int Unicode, int Key, int Flags); From 44cf6acc3a6fb0c559e9e0e53d725af8a65fd3b6 Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 19:41:18 +0200 Subject: [PATCH 13/27] fixed so png files are closed after loading --- src/engine/client/graphics.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 1e9a79cf7..87cabd089 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -387,10 +387,16 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename) IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, aCompleteFilename, sizeof(aCompleteFilename)); if(File) io_close(File); + else + { + dbg_msg("game/png", "failed to open file. filename='%s'", aCompleteFilename); + return 0; + } if(png_open_file(&Png, aCompleteFilename) != PNG_NO_ERROR) // ignore_convention { dbg_msg("game/png", "failed to open file. filename='%s'", aCompleteFilename); + png_close_file(&Png); // ignore_convention return 0; } From 18632b7f5f8fc1e03746f482a15741e94e559b58 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 14:09:55 +0200 Subject: [PATCH 14/27] fixed last commit --- src/engine/client/graphics.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 87cabd089..14a88394b 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -393,10 +393,12 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename) return 0; } - if(png_open_file(&Png, aCompleteFilename) != PNG_NO_ERROR) // ignore_convention + int Error = png_open_file(&Png, aCompleteFilename); // ignore_convention + if(Error != PNG_NO_ERROR) { dbg_msg("game/png", "failed to open file. filename='%s'", aCompleteFilename); - png_close_file(&Png); // ignore_convention + if(Error != PNG_FILE_ERROR) + png_close_file(&Png); // ignore_convention return 0; } From 885d695f9292a44280d34efe1f294b43b23b789f Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 21:28:31 +0200 Subject: [PATCH 15/27] show map name without his folder in server info --- src/engine/server/server.cpp | 24 ++++++++++++++---------- src/engine/server/server.h | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 710b54e1c..b0038a5cd 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -564,16 +564,8 @@ int CServer::DelClientCallback(int ClientId, const char *pReason, void *pUser) void CServer::SendMap(int ClientId) { - //get the name of the map without his path - char * pMapShortName = &g_Config.m_SvMap[0]; - for(int i = 0; i < str_length(g_Config.m_SvMap)-1; i++) - { - if(g_Config.m_SvMap[i] == '/' || g_Config.m_SvMap[i] == '\\') - pMapShortName = &g_Config.m_SvMap[i+1]; - } - CMsgPacker Msg(NETMSG_MAP_CHANGE); - Msg.AddString(pMapShortName, 0); + Msg.AddString(GetMapName(), 0); Msg.AddInt(m_CurrentMapCrc); SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientId, true); } @@ -874,7 +866,7 @@ void CServer::SendServerInfo(NETADDR *pAddr, int Token) p.AddString(GameServer()->Version(), 32); p.AddString(g_Config.m_SvName, 64); - p.AddString(g_Config.m_SvMap, 32); + p.AddString(GetMapName(), 32); // gametype p.AddString(m_aBrowseinfoGametype, 16); @@ -967,6 +959,18 @@ void CServer::PumpNetwork() } } +char *CServer::GetMapName() +{ + // get the name of the map without his path + char *pMapShortName = &g_Config.m_SvMap[0]; + for(int i = 0; i < str_length(g_Config.m_SvMap)-1; i++) + { + if(g_Config.m_SvMap[i] == '/' || g_Config.m_SvMap[i] == '\\') + pMapShortName = &g_Config.m_SvMap[i+1]; + } + return pMapShortName; +} + int CServer::LoadMap(const char *pMapName) { //DATAFILE *df; diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 756c1054e..123338984 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -169,6 +169,7 @@ public: void PumpNetwork(); + char *GetMapName(); int LoadMap(const char *pMapName); void InitEngine(const char *pAppname); From 8f3e98208ec750276f67e52de24ff00716d2095f Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 21:41:37 +0200 Subject: [PATCH 16/27] fixed demo browser (#61) --- src/game/client/components/menus_demo.cpp | 39 +++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 45a96d80d..b356bb331 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -399,7 +399,6 @@ struct FETCH_CALLBACKINFO { CMenus *m_pSelf; const char *m_pPrefix; - int m_Count; }; void CMenus::DemolistFetchCallback(const char *pName, int IsDir, void *pUser) @@ -420,7 +419,7 @@ void CMenus::DemolistPopulate() m_lDemos.clear(); - if(str_comp_num(m_aCurrentDemoFolder, "demos", 256)) //add parent folder + if(str_comp(m_aCurrentDemoFolder, "demos") != 0) //add parent folder { CDemoItem Item; str_copy(Item.m_aName, "..", sizeof(Item.m_aName)); @@ -432,7 +431,7 @@ void CMenus::DemolistPopulate() char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", Client()->UserDirectory(), m_aCurrentDemoFolder); - FETCH_CALLBACKINFO Info = {this, aBuf, m_aCurrentDemoFolder[6]}; //skip "demos/" + FETCH_CALLBACKINFO Info = {this, aBuf}; fs_listdir(aBuf, DemolistFetchCallback, &Info); Info.m_pPrefix = m_aCurrentDemoFolder; fs_listdir(m_aCurrentDemoFolder, DemolistFetchCallback, &Info); @@ -474,13 +473,12 @@ void CMenus::RenderDemoList(CUIRect MainView) RefreshRect.VSplitRight(130.0f, &RefreshRect, &PlayRect); PlayRect.VSplitRight(120.0f, 0x0, &PlayRect); - bool IsDir = false; - if(!str_comp_num(m_lDemos[s_SelectedItem].m_aName, "..", 256)) //parent folder - IsDir = true; - else if(fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) - IsDir = true; - + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) + { + if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) + IsDir = true; + } static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) @@ -496,22 +494,24 @@ void CMenus::RenderDemoList(CUIRect MainView) str_copy(aTitleButton, Localize("Play"), sizeof(aTitleButton)); if(DoButton_Menu(&s_PlayButton, aTitleButton, 0, &PlayRect) || Activated) - { + { if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) { - if(!str_comp_num(m_lDemos[s_SelectedItem].m_aName, "..", 256)) + if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0) //parent folder { DemoSetParentDirectory(); DemolistPopulate(); - s_SelectedItem = 0; + s_SelectedItem = -1; } - else if(IsDir) + else if(IsDir) //folder { - str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", m_aCurrentDemoFolder, m_lDemos[s_SelectedItem].m_aName); + char aTemp[256]; + str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); + str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[s_SelectedItem].m_aName); DemolistPopulate(); s_SelectedItem = 0; } - else + else //file { const char *pError = Client()->DemoPlayer_Play(m_lDemos[s_SelectedItem].m_aFilename); if(pError) @@ -522,22 +522,19 @@ void CMenus::RenderDemoList(CUIRect MainView) } - - void CMenus::DemoSetParentDirectory() { int Stop = 0; - int i; - for(i = 0; i < 256; i++) + for(int i = 0; i < 256; i++) { if(m_aCurrentDemoFolder[i] == '/') Stop = i; } //keeps chars which are before the last '/' and remove chars which are after - for(i = 0; i < 256; i++) + for(int i = 0; i < 256; i++) { if(i >= Stop) - m_aCurrentDemoFolder[i] = 0; + m_aCurrentDemoFolder[i] = '\0'; } } From 62fe7cd5b2d0c845beae164369e39f5815832af7 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 14:28:08 +0200 Subject: [PATCH 17/27] link selected item in the demo list to the first entry (if available) on startup and browse --- src/game/client/components/menus_demo.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index b356bb331..ae4873c10 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -440,10 +440,15 @@ void CMenus::DemolistPopulate() void CMenus::RenderDemoList(CUIRect MainView) { + static int s_SelectedItem = -1; static int s_Inited = 0; if(!s_Inited) + { DemolistPopulate(); - s_Inited = 1; + s_Inited = 1; + if(m_lDemos.size() > 0) + s_SelectedItem = 0; + } // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); @@ -453,7 +458,6 @@ void CMenus::RenderDemoList(CUIRect MainView) MainView.HSplitBottom(ms_ButtonHeight+5.0f, &MainView, &ButtonBar); ButtonBar.HSplitTop(5.0f, 0, &ButtonBar); - static int s_SelectedItem = -1; static int s_DemoListId = 0; static float s_ScrollValue = 0; @@ -501,7 +505,7 @@ void CMenus::RenderDemoList(CUIRect MainView) { DemoSetParentDirectory(); DemolistPopulate(); - s_SelectedItem = -1; + s_SelectedItem = m_lDemos.size() > 0 ? 0 : -1; } else if(IsDir) //folder { @@ -509,7 +513,7 @@ void CMenus::RenderDemoList(CUIRect MainView) str_copy(aTemp, m_aCurrentDemoFolder, sizeof(aTemp)); str_format(m_aCurrentDemoFolder, sizeof(m_aCurrentDemoFolder), "%s/%s", aTemp, m_lDemos[s_SelectedItem].m_aName); DemolistPopulate(); - s_SelectedItem = 0; + s_SelectedItem = m_lDemos.size() > 0 ? 0 : -1; } else //file { From 3dd1ea0d8f6cb442ac41bd223279f41d1ed1b2bb Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 21:19:01 +0200 Subject: [PATCH 18/27] fixed header and swap sizes in datafiles (may fixes #14) --- src/engine/shared/datafile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/shared/datafile.cpp b/src/engine/shared/datafile.cpp index 69b187eac..318639b54 100644 --- a/src/engine/shared/datafile.cpp +++ b/src/engine/shared/datafile.cpp @@ -511,7 +511,7 @@ int CDataFileWriter::Finish() // calculate the complete size TypesSize = m_NumItemTypes*sizeof(CDatafileItemType); HeaderSize = sizeof(CDatafileHeader); - OffsetSize = m_NumItems*sizeof(int) + m_NumDatas*sizeof(int); + OffsetSize = (m_NumItems + m_NumDatas + m_NumDatas) * sizeof(int); //ItemOffsets, DataOffsets, DataSizes FileSize = HeaderSize + TypesSize + OffsetSize + ItemSize + DataSize; SwapSize = FileSize - DataSize; From 0198e51fa35a8ac17fa4f345296574fd9cf45d7b Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 21:17:32 +0200 Subject: [PATCH 19/27] made demo readable for custom map that user doesn't have (#5) --- src/base/system.c | 2 +- src/base/system.h | 2 +- src/engine/shared/demorec.cpp | 78 +++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 6c735c28b..5f4f9d0da 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -289,7 +289,7 @@ unsigned io_read(IOHANDLE io, void *buffer, unsigned size) return fread(buffer, 1, size, (FILE*)io); } -unsigned io_skip(IOHANDLE io, unsigned size) +unsigned io_skip(IOHANDLE io, int size) { fseek((FILE*)io, size, SEEK_CUR); return size; diff --git a/src/base/system.h b/src/base/system.h index c49fbdadf..1b4d52aa7 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -222,7 +222,7 @@ unsigned io_read(IOHANDLE io, void *buffer, unsigned size); Returns: Number of bytes skipped. */ -unsigned io_skip(IOHANDLE io, unsigned size); +unsigned io_skip(IOHANDLE io, int size); /* Function: io_write diff --git a/src/engine/shared/demorec.cpp b/src/engine/shared/demorec.cpp index 23da24785..ce390f828 100644 --- a/src/engine/shared/demorec.cpp +++ b/src/engine/shared/demorec.cpp @@ -10,6 +10,8 @@ #include "engine.h" static const unsigned char gs_aHeaderMarker[8] = {'T', 'W', 'D', 'E', 'M', 'O', 0, 1}; +static const unsigned char gs_aMapMarker[5] = {'M', 'A', 'P', 0, 1}; + CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta) { @@ -50,6 +52,38 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con Header.m_aCrc[3] = (Crc)&0xff; io_write(m_File, &Header, sizeof(Header)); + + // write map + char aMapFilename[128]; + str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", pMap, Crc); + IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ); + if(MapFile) + { + // write map marker + io_write(m_File, &gs_aMapMarker, sizeof(gs_aMapMarker)); + + // write map size + int MapSize = io_length(MapFile); + unsigned char aBufMapSize[4]; + aBufMapSize[0] = (MapSize>>24)&0xff; + aBufMapSize[1] = (MapSize>>16)&0xff; + aBufMapSize[2] = (MapSize>>8)&0xff; + aBufMapSize[3] = (MapSize)&0xff; + io_write(m_File, &aBufMapSize, sizeof(aBufMapSize)); + + // write map data + while(1) + { + unsigned char aChunk[1024*64]; + int Bytes = io_read(MapFile, &aChunk, sizeof(aChunk)); + if(Bytes <= 0) + break; + io_write(m_File, &aChunk, Bytes); + } + io_close(MapFile); + } + + m_LastKeyFrame = -1; m_LastTickMarker = -1; @@ -498,6 +532,50 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const return -1; } + + // check if the demo includes a map + unsigned char aMapMarker[5]; + io_read(m_File, &aMapMarker, sizeof(aMapMarker)); + + if(mem_comp(aMapMarker, gs_aMapMarker, sizeof(gs_aMapMarker)) == 0) + { + // get map size + unsigned char aBufMapSize[4]; + io_read(m_File, &aBufMapSize, sizeof(aBufMapSize)); + int MapSize = (aBufMapSize[0]<<24) | (aBufMapSize[1]<<16) | (aBufMapSize[2]<<8) | (aBufMapSize[3]); + + // check if we already have the map + int Crc = (m_Info.m_Header.m_aCrc[0]<<24) | (m_Info.m_Header.m_aCrc[1]<<16) | (m_Info.m_Header.m_aCrc[2]<<8) | (m_Info.m_Header.m_aCrc[3]); + char aMapFilename[128]; + str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", m_Info.m_Header.m_aMap, Crc); + IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ); + + if(MapFile) + { + io_skip(m_File, MapSize); + io_close(MapFile); + } + else if(MapSize != 0) + { + // get map data + unsigned char *pMapData = (unsigned char *)mem_alloc(MapSize, 1); + io_read(m_File, pMapData, MapSize); + + // save map + MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE); + io_write(MapFile, pMapData, MapSize); + io_close(MapFile); + + // free data + mem_free(pMapData); + } + } + else // no map in the demo + { + io_skip(m_File, -sizeof(aMapMarker)); + } + + // scan the file for interessting points ScanFile(); From 2800832e12684b5961bbef5291922d11e23b032a Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 17:39:55 +0200 Subject: [PATCH 20/27] add maps from maps folder to the demo as well and prevent that 0.5 demo players read the new demos --- src/engine/shared/demorec.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/engine/shared/demorec.cpp b/src/engine/shared/demorec.cpp index ce390f828..960634b19 100644 --- a/src/engine/shared/demorec.cpp +++ b/src/engine/shared/demorec.cpp @@ -9,8 +9,9 @@ #include "network.h" #include "engine.h" -static const unsigned char gs_aHeaderMarker[8] = {'T', 'W', 'D', 'E', 'M', 'O', 0, 1}; -static const unsigned char gs_aMapMarker[5] = {'M', 'A', 'P', 0, 1}; +static const unsigned char gs_aHeaderMarker[8] = {'T', 'W', 'D', 'E', 'M', 'O', '1', 0}; +static const unsigned char gs_aHeaderMarkerOld[8] = {'T', 'W', 'D', 'E', 'M', 'O', 0, 1}; // TODO: remove this later on +static const unsigned char gs_aMapMarker[8] = {'M', 'A', 'P', 'D', 'A', 'T', 'A', 0,}; CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta) @@ -55,8 +56,15 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con // write map char aMapFilename[128]; - str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", pMap, Crc); + // try the normal maps folder + str_format(aMapFilename, sizeof(aMapFilename), "maps/%s.map", pMap); IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ); + if(!MapFile) + { + // try the downloaded maps + str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", pMap, Crc); + MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ); + } if(MapFile) { // write map marker @@ -522,7 +530,8 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const // read the header io_read(m_File, &m_Info.m_Header, sizeof(m_Info.m_Header)); - if(mem_comp(m_Info.m_Header.m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) != 0) + if(mem_comp(m_Info.m_Header.m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) != 0 && + mem_comp(m_Info.m_Header.m_aMarker, gs_aHeaderMarkerOld, sizeof(gs_aHeaderMarkerOld)) != 0) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "'%s' is not a demo file", pFilename); @@ -534,7 +543,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const // check if the demo includes a map - unsigned char aMapMarker[5]; + unsigned char aMapMarker[8]; io_read(m_File, &aMapMarker, sizeof(aMapMarker)); if(mem_comp(aMapMarker, gs_aMapMarker, sizeof(gs_aMapMarker)) == 0) @@ -545,6 +554,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const int MapSize = (aBufMapSize[0]<<24) | (aBufMapSize[1]<<16) | (aBufMapSize[2]<<8) | (aBufMapSize[3]); // check if we already have the map + // TODO: improve map checking int Crc = (m_Info.m_Header.m_aCrc[0]<<24) | (m_Info.m_Header.m_aCrc[1]<<16) | (m_Info.m_Header.m_aCrc[2]<<8) | (m_Info.m_Header.m_aCrc[3]); char aMapFilename[128]; str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", m_Info.m_Header.m_aMap, Crc); @@ -555,7 +565,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const io_skip(m_File, MapSize); io_close(MapFile); } - else if(MapSize != 0) + else if(MapSize > 0) { // get map data unsigned char *pMapData = (unsigned char *)mem_alloc(MapSize, 1); From fcfaa8389f968bc89fbd4afbfc70ea7c3815c7bb Mon Sep 17 00:00:00 2001 From: Choupom Date: Fri, 3 Sep 2010 20:05:22 +0200 Subject: [PATCH 21/27] added Remove button in demos browser (#66) --- src/engine/shared/storage.cpp | 13 +++++++++++++ src/engine/storage.h | 1 + src/game/client/components/menus.cpp | 14 +++++++++++--- src/game/client/components/menus.h | 1 + src/game/client/components/menus_demo.cpp | 19 +++++++++++++++---- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index e8b0f8bb5..74f7cd3f7 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -1,4 +1,5 @@ // copyright (c) 2007 magnus auvinen, see licence.txt for more info +#include //remove() #include #include #include "engine.h" @@ -193,6 +194,18 @@ public: pBuffer[0] = 0; return 0; } + + virtual bool RemoveFile(const char *pFilename) + { + char aBuffer[1024]; + str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aApplicationSavePath, pFilename); + bool Fail = remove(aBuffer); + + if(Fail) + Fail = remove(pFilename); + + return !Fail; + } static IStorage *Create(const char *pApplicationName, int NumArgs, const char **ppArguments) { diff --git a/src/engine/storage.h b/src/engine/storage.h index 4c80446e9..c79f16a83 100644 --- a/src/engine/storage.h +++ b/src/engine/storage.h @@ -17,6 +17,7 @@ public: virtual void ListDirectory(int Types, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0; virtual IOHANDLE OpenFile(const char *pFilename, int Flags, char *pBuffer = 0, int BufferSize = 0) = 0; + virtual bool RemoveFile(const char *pFilename) = 0; }; extern IStorage *CreateStorage(const char *pApplicationName, int NumArgs, const char **ppArguments); diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 42f68978b..f12509143 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -91,6 +91,7 @@ CMenus::CMenus() m_EscapePressed = false; m_EnterPressed = false; + m_DeletePressed = false; m_NumInputEvents = 0; m_LastInput = time_get(); @@ -1029,9 +1030,14 @@ bool CMenus::OnInput(IInput::CEvent e) if(IsActive()) { - // special for popups - if(e.m_Flags&IInput::FLAG_PRESS && e.m_Key == KEY_RETURN) - m_EnterPressed = true; + if(e.m_Flags&IInput::FLAG_PRESS) + { + // special for popups + if(e.m_Key == KEY_RETURN) + m_EnterPressed = true; + else if(e.m_Key == KEY_DELETE) + m_DeletePressed = true; + } if(m_NumInputEvents < MAX_INPUTEVENTS) m_aInputEvents[m_NumInputEvents++] = e; @@ -1116,6 +1122,7 @@ void CMenus::OnRender() { m_EscapePressed = false; m_EnterPressed = false; + m_DeletePressed = false; m_NumInputEvents = 0; return; } @@ -1183,6 +1190,7 @@ void CMenus::OnRender() m_EscapePressed = false; m_EnterPressed = false; + m_DeletePressed = false; m_NumInputEvents = 0; } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index de711a1e8..ec2ff264c 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -146,6 +146,7 @@ class CMenus : public CComponent // bool m_EscapePressed; bool m_EnterPressed; + bool m_DeletePressed; // for call vote int m_CallvoteSelectedOption; diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index ae4873c10..5321b0878 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -472,10 +473,11 @@ void CMenus::RenderDemoList(CUIRect MainView) bool Activated = false; s_SelectedItem = UiDoListboxEnd(&s_ScrollValue, &Activated); - CUIRect RefreshRect, PlayRect; - ButtonBar.VSplitRight(250.0f, &ButtonBar, &RefreshRect); - RefreshRect.VSplitRight(130.0f, &RefreshRect, &PlayRect); - PlayRect.VSplitRight(120.0f, 0x0, &PlayRect); + CUIRect RefreshRect, PlayRect, DeleteRect; + ButtonBar.VSplitRight(130.0f, &ButtonBar, &PlayRect); + ButtonBar.VSplitLeft(130.0f, &RefreshRect, &ButtonBar); + ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar); + ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar); bool IsDir = false; if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) @@ -524,6 +526,15 @@ void CMenus::RenderDemoList(CUIRect MainView) } } + static int s_DeleteButton = 0; + if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) + { + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) + { + Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); + DemolistPopulate(); + } + } } void CMenus::DemoSetParentDirectory() From 5588e1ec8caff39e2a21ce6d9d7c13c5f4d603f1 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 17:53:31 +0200 Subject: [PATCH 22/27] fixed selected index when deleting a demo and added a popup to confirm the deletion --- src/game/client/components/menus.cpp | 30 +++++++++++++++++++ src/game/client/components/menus.h | 2 ++ src/game/client/components/menus_demo.cpp | 36 +++++++++++++++-------- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index f12509143..78b6b0fca 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -88,6 +88,7 @@ CMenus::CMenus() m_NeedSendinfo = false; m_MenuActive = true; m_UseMouseButtons = true; + m_DemolistDelEntry = false; m_EscapePressed = false; m_EnterPressed = false; @@ -846,6 +847,12 @@ int CMenus::Render() pButtonText = Localize("Ok"); ExtraAlign = -1; } + else if(m_Popup == POPUP_DELETE_DEMO) + { + pTitle = Localize("Delete demo"); + pExtraText = Localize("Are you sure that you want to delete the demo?"); + ExtraAlign = -1; + } else if(m_Popup == POPUP_PASSWORD) { pTitle = Localize("Password incorrect"); @@ -939,6 +946,29 @@ int CMenus::Render() static float Offset = 0.0f; DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true); } + else if(m_Popup == POPUP_DELETE_DEMO) + { + CUIRect Yes, No; + Box.HSplitBottom(20.f, &Box, &Part); + Box.HSplitBottom(24.f, &Box, &Part); + Part.VMargin(80.0f, &Part); + + Part.VSplitMid(&No, &Yes); + + Yes.VMargin(20.0f, &Yes); + No.VMargin(20.0f, &No); + + static int s_ButtonAbort = 0; + if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed) + m_Popup = POPUP_NONE; + + static int s_ButtonTryAgain = 0; + if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed) + { + m_Popup = POPUP_NONE; + m_DemolistDelEntry = true; + } + } else if(m_Popup == POPUP_FIRST_LAUNCH) { CUIRect Label, TextBox; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index ec2ff264c..6998acfe1 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -95,6 +95,7 @@ class CMenus : public CComponent POPUP_MESSAGE, POPUP_DISCONNECTED, POPUP_PURE, + POPUP_DELETE_DEMO, POPUP_PASSWORD, POPUP_QUIT, }; @@ -163,6 +164,7 @@ class CMenus : public CComponent sorted_array m_lDemos; char m_aCurrentDemoFolder[256]; + bool m_DemolistDelEntry; void DemolistPopulate(); static void DemolistCountCallback(const char *pName, int IsDir, void *pUser); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 5321b0878..859dedc42 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -450,6 +450,25 @@ void CMenus::RenderDemoList(CUIRect MainView) if(m_lDemos.size() > 0) s_SelectedItem = 0; } + + bool IsDir = false; + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) + { + if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) + IsDir = true; + } + + // delete demo + if(m_DemolistDelEntry) + { + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) + { + Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); + DemolistPopulate(); + s_SelectedItem = s_SelectedItem-1 < 0 ? m_lDemos.size() > 0 ? 0 : -1 : s_SelectedItem-1; + } + m_DemolistDelEntry = false; + } // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); @@ -479,13 +498,6 @@ void CMenus::RenderDemoList(CUIRect MainView) ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar); - bool IsDir = false; - if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) - { - if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) - IsDir = true; - } - static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) { @@ -526,13 +538,13 @@ void CMenus::RenderDemoList(CUIRect MainView) } } - static int s_DeleteButton = 0; - if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) + if(!IsDir) { - if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) + static int s_DeleteButton = 0; + if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) { - Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); - DemolistPopulate(); + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) + m_Popup = POPUP_DELETE_DEMO; } } } From 995d63d7f447d68771f0ea87a599a0d804cff8d3 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 19:01:01 +0200 Subject: [PATCH 23/27] added the possibility to rotate tiles in the editor by SushiTee --- src/game/client/render_map.cpp | 42 ++++++++++++++++++++++-------- src/game/editor/ed_editor.cpp | 19 ++++++++++---- src/game/editor/ed_editor.h | 3 ++- src/game/editor/ed_layer_tiles.cpp | 40 +++++++++++++++++++++++++--- src/game/mapitems.h | 1 + 5 files changed, 85 insertions(+), 20 deletions(-) diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index 2d0875caf..1af41f996 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -244,26 +244,46 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 int Px1 = Px0+(1024/16)-1; int Py1 = Py0+(1024/16)-1; - float u0 = Nudge + Px0/TexSize+Frac; - float v0 = Nudge + Py0/TexSize+Frac; - float u1 = Nudge + Px1/TexSize-Frac; - float v1 = Nudge + Py1/TexSize-Frac; + float x0 = Nudge + Px0/TexSize+Frac; + float y0 = Nudge + Py0/TexSize+Frac; + float x1 = Nudge + Px1/TexSize-Frac; + float y1 = Nudge + Py0/TexSize+Frac; + float x2 = Nudge + Px1/TexSize-Frac; + float y2 = Nudge + Py1/TexSize-Frac; + float x3 = Nudge + Px0/TexSize+Frac; + float y3 = Nudge + Py1/TexSize-Frac; if(Flags&TILEFLAG_VFLIP) { - float Tmp = u0; - u0 = u1; - u1 = Tmp; + x0 = x2; + x1 = x3; + x2 = x3; + x3 = x0; } if(Flags&TILEFLAG_HFLIP) { - float Tmp = v0; - v0 = v1; - v1 = Tmp; + y0 = y3; + y2 = y1; + y3 = y1; + y1 = y0; } - Graphics()->QuadsSetSubset(u0,v0,u1,v1); + if(Flags&TILEFLAG_ROTATE) + { + float Tmp = x0; + x0 = x3; + x3 = x2; + x2 = x1; + x1 = Tmp; + Tmp = y0; + y0 = y3; + y3 = y2; + y2 = y1; + y1 = Tmp; + } + + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale); Graphics()->QuadsDrawTL(&QuadItem, 1); } diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index aa6b78291..7046f1c47 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -463,7 +463,7 @@ void CEditor::RenderBackground(CUIRect View, int Texture, float Size, float Brig Graphics()->QuadsEnd(); } -int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale, const char *pToolTip) +int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip) { // logic static float s_Value; @@ -490,7 +490,7 @@ int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Cu { int Count = (int)(s_Value/Scale); s_Value = fmod(s_Value, Scale); - Current += Count; + Current += Step*Count; if(Current < Min) Current = Min; if(Current > Max) @@ -731,7 +731,16 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_RotationAmount = 90; - s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, 1, 360, 2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); + bool TileLayer = false; + // check for tile layers in brush selection + for(int i = 0; i < m_Brush.m_lLayers.size(); i++) + if(m_Brush.m_lLayers[i]->m_Type == LAYERTYPE_TILES) + { + TileLayer = true; + s_RotationAmount = max(90, (s_RotationAmount/90)*90); + break; + } + s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, TileLayer?90:1, 360, TileLayer?90:1, TileLayer?10.0f:2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); TB_Top.VSplitLeft(5.0f, &Button, &TB_Top); TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); @@ -1608,7 +1617,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * } else if(pProps[i].m_Type == PROPTYPE_INT_SCROLL) { - int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); + int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); if(NewValue != pProps[i].m_Value) { *pNewVal = NewValue; @@ -1624,7 +1633,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * for(int c = 0; c < 4; c++) { int v = (pProps[i].m_Value >> s_aShift[c])&0xff; - NewColor |= UiDoValueSelector(((char *)&pIds[i])+c, &Shifter, s_paTexts[c], v, 0, 255, 1.0f, Localize("Use left mouse button to drag and change the color value. Hold shift to be more precise."))<= 0; --y, ++pDst) + { + *pDst = pTempData[y*m_Width+x]; + if(pDst->m_Flags&TILEFLAG_ROTATE) + pDst->m_Flags ^= (TILEFLAG_HFLIP|TILEFLAG_VFLIP); + pDst->m_Flags ^= TILEFLAG_ROTATE; + } + + int Temp = m_Width; + m_Width = m_Height; + m_Height = Temp; + delete[] pTempData; + } + + if(Rotation == 2 || Rotation == 3) + { + BrushFlipX(); + BrushFlipY(); + } } void CLayerTiles::Resize(int NewW, int NewH) diff --git a/src/game/mapitems.h b/src/game/mapitems.h index 06ceab4e2..3c3095611 100644 --- a/src/game/mapitems.h +++ b/src/game/mapitems.h @@ -48,6 +48,7 @@ enum TILEFLAG_VFLIP=1, TILEFLAG_HFLIP=2, TILEFLAG_OPAQUE=4, + TILEFLAG_ROTATE=8, LAYERFLAG_DETAIL=1, From 0cfd1de7603c16be64df6db6315c63aea3daaceb Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 19:06:27 +0200 Subject: [PATCH 24/27] fixed line endings --- src/game/client/components/menus_demo.cpp | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 859dedc42..8e89ee061 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -451,23 +451,23 @@ void CMenus::RenderDemoList(CUIRect MainView) s_SelectedItem = 0; } - bool IsDir = false; - if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) - { - if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) - IsDir = true; - } - - // delete demo - if(m_DemolistDelEntry) - { - if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) - { - Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); - DemolistPopulate(); - s_SelectedItem = s_SelectedItem-1 < 0 ? m_lDemos.size() > 0 ? 0 : -1 : s_SelectedItem-1; - } - m_DemolistDelEntry = false; + bool IsDir = false; + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) + { + if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) + IsDir = true; + } + + // delete demo + if(m_DemolistDelEntry) + { + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) + { + Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); + DemolistPopulate(); + s_SelectedItem = s_SelectedItem-1 < 0 ? m_lDemos.size() > 0 ? 0 : -1 : s_SelectedItem-1; + } + m_DemolistDelEntry = false; } // render background From 69adb4800eca6fafb0754197ef5586f5a463c66b Mon Sep 17 00:00:00 2001 From: Fujnky Date: Sun, 5 Sep 2010 20:18:14 +0200 Subject: [PATCH 25/27] Put quotes around player names in server messages. --- src/game/server/gamecontext.cpp | 2 +- src/game/server/gamemodes/ctf.cpp | 4 ++-- src/game/server/player.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 1b96b812c..9db02cea6 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -499,7 +499,7 @@ void CGameContext::OnClientEnter(int ClientId) //world.insert_entity(&players[client_id]); m_apPlayers[ClientId]->Respawn(); char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "%s entered and joined the %s", Server()->ClientName(ClientId), m_pController->GetTeamName(m_apPlayers[ClientId]->GetTeam())); + str_format(aBuf, sizeof(aBuf), "\"%s\" entered and joined the %s", Server()->ClientName(ClientId), m_pController->GetTeamName(m_apPlayers[ClientId]->GetTeam())); SendChat(-1, CGameContext::CHAT_ALL, aBuf); str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' team=%d", ClientId, Server()->ClientName(ClientId), m_apPlayers[ClientId]->GetTeam()); diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index 4b25fc478..b28191af3 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -120,11 +120,11 @@ void CGameControllerCTF::Tick() float CaptureTime = (Server()->Tick() - F->m_GrabTick)/(float)Server()->TickSpeed(); if(CaptureTime <= 60) { - str_format(aBuf, sizeof(aBuf), "The %s flag was captured by %s (%d.%s%d seconds)", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID()), (int)CaptureTime%60, ((int)(CaptureTime*100)%100)<10?"0":"", (int)(CaptureTime*100)%100); + str_format(aBuf, sizeof(aBuf), "The %s flag was captured by \"%s\" (%d.%s%d seconds)", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID()), (int)CaptureTime%60, ((int)(CaptureTime*100)%100)<10?"0":"", (int)(CaptureTime*100)%100); } else { - str_format(aBuf, sizeof(aBuf), "The %s flag was captured by %s", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); + str_format(aBuf, sizeof(aBuf), "The %s flag was captured by \"%s\"", fi ? "blue" : "red", Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); } GameServer()->SendChat(-1, -2, aBuf); for(int i = 0; i < 2; i++) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index cc89c11d6..6fb6281c9 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -153,7 +153,7 @@ void CPlayer::SetTeam(int Team) return; char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "%s joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); + str_format(aBuf, sizeof(aBuf), "\"%s\" joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); KillCharacter(); From 3857096a2014f69e60d3ac137c1f5aa15fa2b697 Mon Sep 17 00:00:00 2001 From: oy Date: Tue, 7 Sep 2010 01:18:06 +0200 Subject: [PATCH 26/27] Put quotes around player names in leave message. --- src/game/server/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 6fb6281c9..e3ee71b3f 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -96,7 +96,7 @@ void CPlayer::OnDisconnect() if(Server()->ClientIngame(m_ClientID)) { char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "%s has left the game", Server()->ClientName(m_ClientID)); + str_format(aBuf, sizeof(aBuf), "\"%s\" has left the game", Server()->ClientName(m_ClientID)); GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID)); From 5ff7836638d69e3a0a9df63a458d4326fe9ea315 Mon Sep 17 00:00:00 2001 From: oy Date: Tue, 7 Sep 2010 02:06:11 +0200 Subject: [PATCH 27/27] fixed problems with the tilelayer dumping. Closes #86. Closes #149 --- src/game/client/components/maplayers.cpp | 33 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 62b32a1f2..9c93c771e 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -1,7 +1,8 @@ -#include #include -#include //temp +#include +#include #include +#include #include #include @@ -126,20 +127,30 @@ void CMapLayers::OnRender() Render = true; } - if(pLayer->m_Type == LAYERTYPE_TILES && Input()->KeyPressed(KEY_KP0)) + if(Render && pLayer->m_Type == LAYERTYPE_TILES && Input()->KeyPressed(KEY_LCTRL) && Input()->KeyPressed(KEY_LSHIFT) && Input()->KeyDown(KEY_KP0)) { CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer; CTile *pTiles = (CTile *)m_pLayers->Map()->GetData(pTMap->m_Data); - char buf[256]; - str_format(buf, sizeof(buf), "%d%d_%dx%d", g, l, pTMap->m_Width, pTMap->m_Height); - FILE *f = fopen(buf, "w"); - for(int y = 0; y < pTMap->m_Height; y++) + CServerInfo CurrentServerInfo; + Client()->GetServerInfo(&CurrentServerInfo); + char aFilename[256]; + str_format(aFilename, sizeof(aFilename), "dumps/tilelayer_dump_%s-%d-%d-%dx%d.txt", CurrentServerInfo.m_aMap, g, l, pTMap->m_Width, pTMap->m_Height); + IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE); + if(File) { - for(int x = 0; x < pTMap->m_Width; x++) - fprintf(f, "%d,", pTiles[y*pTMap->m_Width + x].m_Index); - fprintf(f, "\n"); + #if defined(CONF_FAMILY_WINDOWS) + static const char Newline[] = "\r\n"; + #else + static const char Newline[] = "\n"; + #endif + for(int y = 0; y < pTMap->m_Height; y++) + { + for(int x = 0; x < pTMap->m_Width; x++) + io_write(File, &(pTiles[y*pTMap->m_Width + x].m_Index), sizeof(pTiles[y*pTMap->m_Width + x].m_Index)); + io_write(File, Newline, sizeof(Newline)-1); + } + io_close(File); } - fclose(f); } if(Render && !IsGameLayer)