From 67f63d34bf0a0d0a635e899da18df4e16fc47b92 Mon Sep 17 00:00:00 2001 From: Zwelf Date: Mon, 18 May 2015 21:17:20 +0200 Subject: [PATCH 01/16] Added download script Added a download script to download automatically SDL2 and freetype. Added them to the gitignore. Someone could add this to bam.lua. --- .gitignore | 2 ++ scripts/download.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 scripts/download.py diff --git a/.gitignore b/.gitignore index 45ef50c6a..581b9f83b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ scripts/work/ /SDL.dll /freetype.dll /autoexec.cfg +other/freetype +other/sdl diff --git a/scripts/download.py b/scripts/download.py new file mode 100644 index 000000000..dc7e6795c --- /dev/null +++ b/scripts/download.py @@ -0,0 +1,33 @@ +import urllib.request +import os +import zipfile +import sys + +def _downloadZip(url, filePath): + # create full path, if it doesn't exists + os.makedirs(filePath, exist_ok=True) + # create zip-file at the temp fileposition + temp_filePath = filePath + "temp.zip" + urllib.request.urlretrieve(url, temp_filePath) + # exctract full zip-file + with zipfile.ZipFile(temp_filePath) as myzip: + myzip.extractall(filePath) + os.remove(temp_filePath) + +def downloadAll(arch, conf): + downloadUrl = "https://github.com/Zwelf/tw-downloads/raw/master/{}.zip" + builddir = "../build/" + arch + "/" + conf + "/" + files = (downloadUrl.format("SDL2.dll" + "-" + arch), builddir ),\ + (downloadUrl.format("freetype.dll" + "-" + arch), builddir ),\ + (downloadUrl.format("sdl" ), "../other/sdl/" ),\ + (downloadUrl.format("freetype" ), "../other/freetype/") + for elem in files: + _downloadZip(elem[0], elem[1]) + +def main(): + arch = sys.argv[1] if len(sys.argv) >= 2 else "x86" + conf = sys.argv[2] if len(sys.argv) >= 3 else "debug" + downloadAll(arch, conf) + +if __name__ == '__main__': + main() \ No newline at end of file From e21cab322f6f8654631c07e855c76f6136ccd89c Mon Sep 17 00:00:00 2001 From: Henningstone Date: Tue, 19 May 2015 16:50:28 +0200 Subject: [PATCH 02/16] Fixup download.py and integrate into bam.lua --- bam.lua | 10 +++++++++- scripts/download.py | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bam.lua b/bam.lua index 3b94551ac..1dea8a969 100644 --- a/bam.lua +++ b/bam.lua @@ -424,7 +424,7 @@ function GenerateSettings(conf, arch, builddir, compiler) return settings end --- String formatting wth named parameters, by RiciLake http://lua-users.org/wiki/StringInterpolation +-- String formatting with named parameters, by RiciLake http://lua-users.org/wiki/StringInterpolation function interp(s, tab) return (s:gsub('%%%((%a%w*)%)([-0-9%.]*[cdeEfgGiouxXsq])', function(k, fmt) @@ -489,9 +489,17 @@ for a, cur_arch in ipairs(archs) do local settings = GenerateSettings(cur_conf, cur_arch, cur_builddir, compiler) for t, cur_target in pairs(targets) do table.insert(subtargets[cur_target], PathJoin(cur_builddir, cur_target .. settings.link.extension)) + dl = Python("scripts/download.py") + dl = dl .. " -arch " .. cur_arch .. " -conf " .. cur_conf + AddJob(cur_target .. "SDL2.dll", "Downloading SDL2.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " +pack SDL2.dll-" .. cur_arch) + AddJob(cur_target .. "freetype.dll", "Downloading freetype.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " +pack freetype.dll-" .. cur_arch) end end end + +AddJob("other/sdl/include/SDL.h", "Downloading sdl and freetype", dl .. " +pack sdl +pack freetype") --TODO: remove freetype from sdl-download +AddJob("other/freetype/include/freetype.h", "Downloading freetype", dl .. " +pack freetype") --TODO: MAKE ME WORKING (why don't I...!?) + for cur_name, cur_target in pairs(targets) do -- Supertarget for all configurations and architectures of that target PseudoTarget(cur_name, subtargets[cur_target]) diff --git a/scripts/download.py b/scripts/download.py index dc7e6795c..e4228d9f1 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -2,6 +2,7 @@ import urllib.request import os import zipfile import sys +import re def _downloadZip(url, filePath): # create full path, if it doesn't exists @@ -19,15 +20,23 @@ def downloadAll(arch, conf): builddir = "../build/" + arch + "/" + conf + "/" files = (downloadUrl.format("SDL2.dll" + "-" + arch), builddir ),\ (downloadUrl.format("freetype.dll" + "-" + arch), builddir ),\ - (downloadUrl.format("sdl" ), "../other/sdl/" ),\ - (downloadUrl.format("freetype" ), "../other/freetype/") + (downloadUrl.format("sdl" ), "other/sdl/" ),\ + (downloadUrl.format("freetype" ), "other/freetype/") for elem in files: - _downloadZip(elem[0], elem[1]) + for i in range(1,len(sys.argv)): + sTmp = re.search('master/(.+?).zip', elem[0]) + curr_pack = sTmp.group(1) + if sys.argv[i] == "+pack" and sys.argv[i + 1] == curr_pack: + _downloadZip(elem[0], elem[1]) def main(): - arch = sys.argv[1] if len(sys.argv) >= 2 else "x86" - conf = sys.argv[2] if len(sys.argv) >= 3 else "debug" + arch = "x86" + conf = "debug" + for i in range(1,len(sys.argv)): # this is expandable infinitly for more args + if sys.argv[i] == "-arch": arch = sys.argv[i + 1] + if sys.argv[i] == "-conf": conf = sys.argv[i + 1] + downloadAll(arch, conf) if __name__ == '__main__': - main() \ No newline at end of file + main() From 3da60b89f2ab8f119d38ee5e39aa28d456c52672 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Tue, 19 May 2015 20:06:53 +0200 Subject: [PATCH 03/16] Use Python's argparse and only run download.py on Windows --- bam.lua | 16 ++++++++++------ scripts/download.py | 39 ++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/bam.lua b/bam.lua index 1dea8a969..2ccb9cffa 100644 --- a/bam.lua +++ b/bam.lua @@ -489,16 +489,20 @@ for a, cur_arch in ipairs(archs) do local settings = GenerateSettings(cur_conf, cur_arch, cur_builddir, compiler) for t, cur_target in pairs(targets) do table.insert(subtargets[cur_target], PathJoin(cur_builddir, cur_target .. settings.link.extension)) - dl = Python("scripts/download.py") - dl = dl .. " -arch " .. cur_arch .. " -conf " .. cur_conf - AddJob(cur_target .. "SDL2.dll", "Downloading SDL2.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " +pack SDL2.dll-" .. cur_arch) - AddJob(cur_target .. "freetype.dll", "Downloading freetype.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " +pack freetype.dll-" .. cur_arch) + if family == "windows" then + dl = Python("scripts/download.py") + dl = dl .. " --arch " .. cur_arch .. " --conf " .. cur_conf + AddJob(cur_target .. "SDL2.dll", "Downloading SDL2.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " SDL2.dll") + AddJob(cur_target .. "freetype.dll", "Downloading freetype.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " freetype.dll") + end end end end -AddJob("other/sdl/include/SDL.h", "Downloading sdl and freetype", dl .. " +pack sdl +pack freetype") --TODO: remove freetype from sdl-download -AddJob("other/freetype/include/freetype.h", "Downloading freetype", dl .. " +pack freetype") --TODO: MAKE ME WORKING (why don't I...!?) +if family == "windows" then + AddJob("other/sdl/include/SDL.h", "Downloading sdl and freetype", dl .. " sdl freetype") -- TODO: remove freetype from sdl-download + AddJob("other/freetype/include/freetype.h", "Downloading freetype", dl .. " freetype") -- TODO: MAKE ME WORKING (why don't I...!?) +end for cur_name, cur_target in pairs(targets) do -- Supertarget for all configurations and architectures of that target diff --git a/scripts/download.py b/scripts/download.py index e4228d9f1..cd63749b2 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -15,28 +15,29 @@ def _downloadZip(url, filePath): myzip.extractall(filePath) os.remove(temp_filePath) -def downloadAll(arch, conf): - downloadUrl = "https://github.com/Zwelf/tw-downloads/raw/master/{}.zip" - builddir = "../build/" + arch + "/" + conf + "/" - files = (downloadUrl.format("SDL2.dll" + "-" + arch), builddir ),\ - (downloadUrl.format("freetype.dll" + "-" + arch), builddir ),\ - (downloadUrl.format("sdl" ), "other/sdl/" ),\ - (downloadUrl.format("freetype" ), "other/freetype/") - for elem in files: - for i in range(1,len(sys.argv)): - sTmp = re.search('master/(.+?).zip', elem[0]) - curr_pack = sTmp.group(1) - if sys.argv[i] == "+pack" and sys.argv[i + 1] == curr_pack: - _downloadZip(elem[0], elem[1]) +def downloadAll(arch, conf, targets): + download_url = "https://github.com/Zwelf/tw-downloads/raw/master/{}.zip".format + builddir = "build/" + arch + "/" + conf + "/" + files = { + "SDL2.dll": ("SDL2.dll" + "-" + arch, builddir), + "freetype.dll": ("freetype.dll" + "-" + arch, builddir), + "sdl": ("sdl", "other/sdl/"), + "freetype": ("freetype", "other/freetype/"), + } + + for target in targets: + download_file, target_dir = files[target] + _downloadZip(download_url(download_file), target_dir) def main(): - arch = "x86" - conf = "debug" - for i in range(1,len(sys.argv)): # this is expandable infinitly for more args - if sys.argv[i] == "-arch": arch = sys.argv[i + 1] - if sys.argv[i] == "-conf": conf = sys.argv[i + 1] + import argparse + p = argparse.ArgumentParser(description="Download freetype and SDL library and header files for Windows.") + p.add_argument("--arch", default="x86", choices=["x86", "x86_64"], help="Architecture for the downloaded libraries (Default: x86)") + p.add_argument("--conf", default="debug", choices=["debug", "release"], help="Build type (Default: debug)") + p.add_argument("targets", metavar="TARGET", nargs='+', choices=["SDL.dll", "freetype.dll", "sdl", "freetype"], help='Target to download. Valid choices are "SDL.dll", "freetype.dll", "sdl" and "freetype"') + args = p.parse_args() - downloadAll(arch, conf) + downloadAll(args.arch, args.conf, args.targets) if __name__ == '__main__': main() From a1f9f1c8e070a0c6b002568e681534829e857db3 Mon Sep 17 00:00:00 2001 From: Henningstone Date: Wed, 20 May 2015 23:43:24 +0200 Subject: [PATCH 04/16] Fix autodownload in bam.lua and download.py --- bam.lua | 18 ++++++++++-------- scripts/download.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bam.lua b/bam.lua index 2ccb9cffa..81eb68f4f 100644 --- a/bam.lua +++ b/bam.lua @@ -486,22 +486,24 @@ end for a, cur_arch in ipairs(archs) do for c, cur_conf in ipairs(confs) do cur_builddir = interp(builddir, {platform=family, arch=cur_arch, target=cur_target, conf=cur_conf, compiler=compiler}) + if family == "windows" then + dl = Python("scripts/download.py") + dl = dl .. " --arch " .. cur_arch .. " --conf " .. cur_conf + AddJob(cur_builddir .. "/SDL2.dll", "Downloading SDL.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " SDL2.dll") -- TODO: Make me working! + AddJob(cur_builddir .. "/freetype.dll", "Downloading freetype.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " freetype.dll") + end local settings = GenerateSettings(cur_conf, cur_arch, cur_builddir, compiler) for t, cur_target in pairs(targets) do table.insert(subtargets[cur_target], PathJoin(cur_builddir, cur_target .. settings.link.extension)) - if family == "windows" then - dl = Python("scripts/download.py") - dl = dl .. " --arch " .. cur_arch .. " --conf " .. cur_conf - AddJob(cur_target .. "SDL2.dll", "Downloading SDL2.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " SDL2.dll") - AddJob(cur_target .. "freetype.dll", "Downloading freetype.dll for " .. cur_arch .. "/" .. cur_conf, dl .. " freetype.dll") - end end end end if family == "windows" then - AddJob("other/sdl/include/SDL.h", "Downloading sdl and freetype", dl .. " sdl freetype") -- TODO: remove freetype from sdl-download - AddJob("other/freetype/include/freetype.h", "Downloading freetype", dl .. " freetype") -- TODO: MAKE ME WORKING (why don't I...!?) + AddJob("other/sdl/include/SDL.h", "Downloading SDL2 headers and DLL...", dl .. " sdl SDL2.dll") -- TODO: split up dll and headers! + AddJob("other/freetype/include/ft2build.h", "Downloading freetype headers and DLL...", dl .. " freetype freetype.dll") + AddDependency(cur_builddir .. "/objs/engine/client/backend_sdl.obj","other/sdl/include/SDL.h") + AddDependency(cur_builddir .. "/objs/engine/client/text.obj","other/freetype/include/ft2build.h") end for cur_name, cur_target in pairs(targets) do diff --git a/scripts/download.py b/scripts/download.py index cd63749b2..1dd189d80 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -34,7 +34,7 @@ def main(): p = argparse.ArgumentParser(description="Download freetype and SDL library and header files for Windows.") p.add_argument("--arch", default="x86", choices=["x86", "x86_64"], help="Architecture for the downloaded libraries (Default: x86)") p.add_argument("--conf", default="debug", choices=["debug", "release"], help="Build type (Default: debug)") - p.add_argument("targets", metavar="TARGET", nargs='+', choices=["SDL.dll", "freetype.dll", "sdl", "freetype"], help='Target to download. Valid choices are "SDL.dll", "freetype.dll", "sdl" and "freetype"') + p.add_argument("targets", metavar="TARGET", nargs='+', choices=["SDL2.dll", "freetype.dll", "sdl", "freetype"], help='Target to download. Valid choices are "SDL.dll", "freetype.dll", "sdl" and "freetype"') args = p.parse_args() downloadAll(args.arch, args.conf, args.targets) From b37f77574ee71d6f2f63561dff3055522bdf3213 Mon Sep 17 00:00:00 2001 From: Zwelf Date: Thu, 1 Jun 2017 20:22:58 +0200 Subject: [PATCH 05/16] Added ctrl+arrows/backspace/delete keys for text input --- src/game/client/components/chat.cpp | 5 +++ src/game/client/components/chat.h | 1 + src/game/client/components/console.cpp | 1 + src/game/client/components/menus.cpp | 2 +- src/game/client/lineinput.cpp | 56 +++++++++++++++++++++----- src/game/client/lineinput.h | 5 ++- src/game/editor/editor.cpp | 2 +- 7 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 08362f55e..5e92c373e 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -136,6 +136,11 @@ void CChat::ConShowChat(IConsole::IResult *pResult, void *pUserData) ((CChat *)pUserData)->m_Show = pResult->GetInteger(0) != 0; } +void CChat::OnInit() +{ + m_Input.Init(Input()); +} + void CChat::OnConsoleInit() { Console()->Register("say", "r", CFGFLAG_CLIENT, ConSay, this, "Say in chat"); diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h index aac6a558c..732a7b79a 100644 --- a/src/game/client/components/chat.h +++ b/src/game/client/components/chat.h @@ -81,6 +81,7 @@ public: void Say(int Team, const char *pLine); + virtual void OnInit(); virtual void OnReset(); virtual void OnConsoleInit(); virtual void OnStateChange(int NewState, int OldState); diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index d275f09cf..bec0c0c9c 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -57,6 +57,7 @@ CGameConsole::CInstance::CInstance(int Type) void CGameConsole::CInstance::Init(CGameConsole *pGameConsole) { m_pGameConsole = pGameConsole; + m_Input.Init(m_pGameConsole->Input()); }; void CGameConsole::CInstance::ClearBacklog() diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 36b7cdb0c..1fc6ecd30 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -473,7 +473,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS { Len = str_length(pStr); int NumChars = Len; - ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars); + ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars, Input()); } } } diff --git a/src/game/client/lineinput.cpp b/src/game/client/lineinput.cpp index b60b0f8a8..a118aab93 100644 --- a/src/game/client/lineinput.cpp +++ b/src/game/client/lineinput.cpp @@ -1,11 +1,13 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include +#include #include "lineinput.h" CLineInput::CLineInput() { Clear(); + m_pInput = 0; } void CLineInput::Clear() @@ -16,6 +18,11 @@ void CLineInput::Clear() m_NumChars = 0; } +void CLineInput::Init(IInput *pInput) +{ + m_pInput = pInput; +} + void CLineInput::Set(const char *pString) { str_copy(m_Str, pString, sizeof(m_Str)); @@ -30,7 +37,15 @@ void CLineInput::Set(const char *pString) } } -bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr) +bool CLineInput::CtrlStop(char c) +{ + // jump to spaces and special ASCII characters + return ((32 <= c && c <= 47) || // !"#$%&'()*+,-./ + (58 <= c && c <= 64) || // :;<=>?@ + (91 <= c && c <= 96)); // [\]^_` +} + +bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr, IInput *pInput) { int NumChars = *pNumCharsPtr; int CursorPos = *pCursorPosPtr; @@ -74,31 +89,50 @@ bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, in if(Event.m_Flags&IInput::FLAG_PRESS) { int Key = Event.m_Key; + bool Ctrl = false; + if(pInput && (pInput->KeyIsPressed(KEY_LCTRL) || pInput->KeyIsPressed(KEY_RCTRL))) + Ctrl = true; if(Key == KEY_BACKSPACE && CursorPos > 0) { - int NewCursorPos = str_utf8_rewind(pStr, CursorPos); + int NewCursorPos = CursorPos; + do + { + NewCursorPos = str_utf8_rewind(pStr, NewCursorPos); + NumChars -= 1; + } while(Ctrl && NewCursorPos > 0 && !CtrlStop(pStr[NewCursorPos - 1])); int CharSize = CursorPos-NewCursorPos; mem_move(pStr+NewCursorPos, pStr+CursorPos, Len - NewCursorPos - CharSize + 1); // +1 == null term CursorPos = NewCursorPos; Len -= CharSize; - if(CharSize > 0) - --NumChars; Changes = true; } else if(Key == KEY_DELETE && CursorPos < Len) { - int p = str_utf8_forward(pStr, CursorPos); - int CharSize = p-CursorPos; + int EndCursorPos = CursorPos; + do + { + EndCursorPos = str_utf8_forward(pStr, EndCursorPos); + NumChars -= 1; + } while(Ctrl && EndCursorPos < Len && !CtrlStop(pStr[EndCursorPos - 1])); + int CharSize = EndCursorPos - CursorPos; mem_move(pStr + CursorPos, pStr + CursorPos + CharSize, Len - CursorPos - CharSize + 1); // +1 == null term Len -= CharSize; - if(CharSize > 0) - --NumChars; Changes = true; } else if(Key == KEY_LEFT && CursorPos > 0) - CursorPos = str_utf8_rewind(pStr, CursorPos); + { + do + { + CursorPos = str_utf8_rewind(pStr, CursorPos); + } while(Ctrl && CursorPos > 0 && !CtrlStop(pStr[CursorPos - 1])); + } else if(Key == KEY_RIGHT && CursorPos < Len) - CursorPos = str_utf8_forward(pStr, CursorPos); + { + do + { + CursorPos = str_utf8_forward(pStr, CursorPos); + } while(Ctrl && CursorPos < Len && !CtrlStop(pStr[CursorPos - 1])); + } else if(Key == KEY_HOME) CursorPos = 0; else if(Key == KEY_END) @@ -114,5 +148,5 @@ bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, in bool CLineInput::ProcessInput(IInput::CEvent e) { - return Manipulate(e, m_Str, MAX_SIZE, MAX_CHARS, &m_Len, &m_CursorPos, &m_NumChars); + return Manipulate(e, m_Str, MAX_SIZE, MAX_CHARS, &m_Len, &m_CursorPos, &m_NumChars, m_pInput); } diff --git a/src/game/client/lineinput.h b/src/game/client/lineinput.h index 5e1f1d74d..fae3a5ef4 100644 --- a/src/game/client/lineinput.h +++ b/src/game/client/lineinput.h @@ -17,8 +17,10 @@ class CLineInput int m_Len; int m_CursorPos; int m_NumChars; + IInput *m_pInput; public: - static bool Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr); + static bool CtrlStop(char c); + static bool Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr, IInput *pInput); class CCallback { @@ -28,6 +30,7 @@ public: }; CLineInput(); + void Init(IInput *pInput); void Clear(); bool ProcessInput(IInput::CEvent e); void Set(const char *pString); diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 413cfa716..a6c1be23f 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -340,7 +340,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str { Len = str_length(pStr); int NumChars = Len; - ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars); + ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars, Input()); } } From 68920a037ef4684da64b9b7e26d6d06ed4193e50 Mon Sep 17 00:00:00 2001 From: Zwelf Date: Mon, 12 Jun 2017 09:25:07 +0200 Subject: [PATCH 06/16] Set alt key to move between words for OSX --- src/game/client/lineinput.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/game/client/lineinput.cpp b/src/game/client/lineinput.cpp index a118aab93..50f9f82db 100644 --- a/src/game/client/lineinput.cpp +++ b/src/game/client/lineinput.cpp @@ -90,7 +90,11 @@ bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, in { int Key = Event.m_Key; bool Ctrl = false; +#ifdef CONF_PLATFORM_MACOSX + if(pInput && (pInput->KeyIsPressed(KEY_LALT) || pInput->KeyIsPressed(KEY_RALT))) +#else if(pInput && (pInput->KeyIsPressed(KEY_LCTRL) || pInput->KeyIsPressed(KEY_RCTRL))) +#endif Ctrl = true; if(Key == KEY_BACKSPACE && CursorPos > 0) { From 4a92b40b0c370db7e64fecd0e921cc6c802a01ee Mon Sep 17 00:00:00 2001 From: msiglreith Date: Sun, 23 Dec 2018 16:16:14 +0100 Subject: [PATCH 07/16] Fix build for msvc --- src/engine/client/backend_sdl.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 1bf9ae531..36f164bda 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -12,11 +12,10 @@ #include "graphics_threaded.h" #include "backend_sdl.h" - #if defined(CONF_FAMILY_WINDOWS) PFNGLTEXIMAGE3DPROC glTexImage3DInternal; - GLAPI void GLAPIENTRY glTexImage3D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) + GLAPI void APIENTRY glTexImage3D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { glTexImage3DInternal(target, level, internalFormat, width, height, depth, border, format, type, pixels); } @@ -160,7 +159,7 @@ void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &St } else glDisable(GL_SCISSOR_TEST); - + // texture int SrcBlendMode = GL_ONE; @@ -335,7 +334,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: } } m_aTextures[pCommand->m_Slot].m_Format = pCommand->m_Format; - + // int Oglformat = TexFormatToOpenGLFormat(pCommand->m_Format); int StoreOglformat = TexFormatToOpenGLFormat(pCommand->m_StoreFormat); @@ -384,7 +383,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: m_aTextures[pCommand->m_Slot].m_MemSize += TexWidth*TexHeight*pCommand->m_PixelSize; } } - + // 3D texture if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_TEXTURE3D) && m_Max3DTexSize >= CTexture::MIN_GL_MAX_3D_TEXTURE_SIZE) { @@ -410,12 +409,12 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: } mem_free(pTexData); - + // glGenTextures(m_TextureArraySize, m_aTextures[pCommand->m_Slot].m_Tex3D); m_aTextures[pCommand->m_Slot].m_State |= CTexture::STATE_TEX3D; for(int i = 0; i < m_TextureArraySize; ++i) - { + { glBindTexture(GL_TEXTURE_3D, m_aTextures[pCommand->m_Slot].m_Tex3D[i]); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -425,7 +424,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: m_aTextures[pCommand->m_Slot].m_MemSize += Width*Height*pCommand->m_PixelSize; } pTexData = pTmpData; - } + } *m_pTextureMemoryUsage += m_aTextures[pCommand->m_Slot].m_MemSize; @@ -441,7 +440,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Clear(const CCommandBuffer::SCommand_ void CCommandProcessorFragment_OpenGL::Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand) { SetState(pCommand->m_State); - + glVertexPointer(3, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices); glTexCoordPointer(3, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices + sizeof(float)*3); glColorPointer(4, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices + sizeof(float)*6); @@ -472,7 +471,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Screenshot(const CCommandBuffer::SCom int h = pCommand->m_H == -1 ? aViewport[3] : pCommand->m_H; int x = pCommand->m_X; int y = aViewport[3] - pCommand->m_Y - 1 - (h - 1); - + // we allocate one more row to use when we are flipping the texture unsigned char *pPixelData = (unsigned char *)mem_alloc(w*(h+1)*3, 1); unsigned char *pTempRow = pPixelData+w*h*3; @@ -626,16 +625,16 @@ void CCommandProcessor_SDL_OpenGL::RunBuffer(CCommandBuffer *pBuffer) const CCommandBuffer::SCommand *pBaseCommand = pBuffer->GetCommand(&CmdIndex); if(pBaseCommand == 0x0) break; - + if(m_OpenGL.RunCommand(pBaseCommand)) continue; - + if(m_SDL.RunCommand(pBaseCommand)) continue; if(m_General.RunCommand(pBaseCommand)) continue; - + dbg_msg("graphics", "unknown command %d", pBaseCommand->m_Cmd); } } @@ -703,7 +702,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt #else SdlFlags |= SDL_WINDOW_FULLSCREEN; #endif - + // set gl attributes SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if(FsaaSamples) @@ -786,7 +785,7 @@ int CGraphicsBackend_SDL_OpenGL::Shutdown() CmdBuffer.AddCommand(Cmd); RunBuffer(&CmdBuffer); WaitForIdle(); - + // stop and delete the processor StopProcessor(); delete m_pProcessor; From ba1450490b38c948aa4ac83cc940d62014cd1af2 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Fri, 28 Dec 2018 19:32:24 +0100 Subject: [PATCH 08/16] Call option votes with a double click --- src/game/client/components/menus.h | 2 +- src/game/client/components/menus_ingame.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index ec9c3526a..7f32e2d24 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -531,7 +531,7 @@ private: void HandleCallvote(int Page, bool Force); void RenderServerControl(CUIRect MainView); void RenderServerControlKick(CUIRect MainView, bool FilterSpectators); - void RenderServerControlServer(CUIRect MainView); + bool RenderServerControlServer(CUIRect MainView); // found in menus_browser.cpp // int m_ScrollOffset; diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 00a58e5de..455cc3450 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -469,8 +469,9 @@ void CMenus::RenderServerInfo(CUIRect MainView) TextRender()->Text(0, Motd.x, Motd.y, ButtonHeight*ms_FontmodHeight*0.8f, m_pClient->m_pMotd->GetMotd(), (int)Motd.w); } -void CMenus::RenderServerControlServer(CUIRect MainView) +bool CMenus::RenderServerControlServer(CUIRect MainView) { + bool doCallVote = false; static int s_VoteList = 0; static CListBoxState s_ListBoxState; CUIRect List = MainView; @@ -482,14 +483,15 @@ void CMenus::RenderServerControlServer(CUIRect MainView) CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState, pOption); if(Item.m_Visible) - { + { Item.m_Rect.VMargin(5.0f, &Item.m_Rect); Item.m_Rect.y += 2.0f; UI()->DoLabel(&Item.m_Rect, pOption->m_aDescription, Item.m_Rect.h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); } } - m_CallvoteSelectedOption = UiDoListboxEnd(&s_ListBoxState, 0); + m_CallvoteSelectedOption = UiDoListboxEnd(&s_ListBoxState, &doCallVote); + return doCallVote; } void CMenus::RenderServerControlKick(CUIRect MainView, bool FilterSpectators) @@ -676,9 +678,10 @@ void CMenus::RenderServerControl(CUIRect MainView) MainView.HSplitBottom(90.0f+2*20.0f, &MainView, &Extended); RenderTools()->DrawUIRect(&Extended, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 5.0f); + bool doCallVote = false; // render page if(s_ControlPage == 0) - RenderServerControlServer(MainView); + doCallVote = RenderServerControlServer(MainView); // double click triggers vote else if(s_ControlPage == 1) RenderServerControlKick(MainView, false); else if(s_ControlPage == 2) @@ -720,7 +723,7 @@ void CMenus::RenderServerControl(CUIRect MainView) { // call vote static CButtonContainer s_CallVoteButton; - if(DoButton_Menu(&s_CallVoteButton, Localize("Call vote"), 0, &Button)) + if(DoButton_Menu(&s_CallVoteButton, Localize("Call vote"), 0, &Button) || doCallVote) HandleCallvote(s_ControlPage, false); } else From 0c6efd1873802545ccb2b5e65e777b0bc25cd11f Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 30 Dec 2018 19:19:02 +0100 Subject: [PATCH 09/16] use official lib repository for building on windows --- scripts/download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/download.py b/scripts/download.py index 1dd189d80..9a7fe70b4 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -16,7 +16,7 @@ def _downloadZip(url, filePath): os.remove(temp_filePath) def downloadAll(arch, conf, targets): - download_url = "https://github.com/Zwelf/tw-downloads/raw/master/{}.zip".format + download_url = "https://github.com/teeworlds/teeworlds-libs/archive/master.zip".format builddir = "build/" + arch + "/" + conf + "/" files = { "SDL2.dll": ("SDL2.dll" + "-" + arch, builddir), From a62048e641538289e1948af7d753c922bfa14505 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 30 Dec 2018 19:39:24 +0100 Subject: [PATCH 10/16] fixed dependency downloading on windows --- bam.lua | 13 ++++----- scripts/download.py | 70 ++++++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/bam.lua b/bam.lua index 143cdc1ba..53c81e9f7 100644 --- a/bam.lua +++ b/bam.lua @@ -268,6 +268,12 @@ function GenerateWindowsSettings(settings, conf, target_arch, compiler) -- Content BuildContent(settings) + + -- dependencies + AddJob("other/sdl/include/SDL.h", "Downloading SDL2 headers and DLL...", dl .. " sdl SDL2.dll") -- TODO: split up dll and headers! + AddJob("other/freetype/include/ft2build.h", "Downloading freetype headers and DLL...", dl .. " freetype freetype.dll") + AddDependency(cur_builddir .. "/objs/engine/client/backend_sdl" .. settings.cc.extension, "other/sdl/include/SDL.h") + AddDependency(cur_builddir .. "/objs/engine/client/text" .. settings.cc.extension, "other/freetype/include/ft2build.h") end function SharedCommonFiles() @@ -506,13 +512,6 @@ for a, cur_arch in ipairs(archs) do end end -if family == "windows" then - AddJob("other/sdl/include/SDL.h", "Downloading SDL2 headers and DLL...", dl .. " sdl SDL2.dll") -- TODO: split up dll and headers! - AddJob("other/freetype/include/ft2build.h", "Downloading freetype headers and DLL...", dl .. " freetype freetype.dll") - AddDependency(cur_builddir .. "/objs/engine/client/backend_sdl.obj","other/sdl/include/SDL.h") - AddDependency(cur_builddir .. "/objs/engine/client/text.obj","other/freetype/include/ft2build.h") -end - for cur_name, cur_target in pairs(targets) do -- Supertarget for all configurations and architectures of that target PseudoTarget(cur_name, subtargets[cur_target]) diff --git a/scripts/download.py b/scripts/download.py index 9a7fe70b4..b001b394f 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -1,33 +1,51 @@ -import urllib.request -import os -import zipfile -import sys -import re +import shutil, os, re, sys, zipfile +from distutils.dir_util import copy_tree +os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])) + "/..") +import twlib -def _downloadZip(url, filePath): - # create full path, if it doesn't exists - os.makedirs(filePath, exist_ok=True) - # create zip-file at the temp fileposition - temp_filePath = filePath + "temp.zip" - urllib.request.urlretrieve(url, temp_filePath) - # exctract full zip-file - with zipfile.ZipFile(temp_filePath) as myzip: - myzip.extractall(filePath) - os.remove(temp_filePath) +def unzip(filename, where): + try: + z = zipfile.ZipFile(filename, "r") + except: + return False + for name in z.namelist(): + z.extract(name, where) + z.close() + return z.namelist()[0] def downloadAll(arch, conf, targets): - download_url = "https://github.com/teeworlds/teeworlds-libs/archive/master.zip".format - builddir = "build/" + arch + "/" + conf + "/" - files = { - "SDL2.dll": ("SDL2.dll" + "-" + arch, builddir), - "freetype.dll": ("freetype.dll" + "-" + arch, builddir), - "sdl": ("sdl", "other/sdl/"), - "freetype": ("freetype", "other/freetype/"), - } + url = "https://github.com/teeworlds/teeworlds-libs/archive/master.zip" + if arch == "x86_64": + _arch = "x64" + else: + _arch = arch + builddir = "build/" + arch + "/" + conf + "/" + + # download and unzip + src_package_libs = twlib.fetch_file(url) + if not src_package_libs: + print("couldn't download libs") + sys.exit(-1) + libs_dir = unzip(src_package_libs, ".") + if not libs_dir: + print("couldn't unzip libs") + sys.exit(-1) + libs_dir = "teeworlds-libs-master" - for target in targets: - download_file, target_dir = files[target] - _downloadZip(download_url(download_file), target_dir) + if "SDL2.dll" in targets: + shutil.copy(libs_dir + "/sdl/windows/lib/" + _arch + "/SDL2.dll", builddir) + if "freetype.dll" in targets: + shutil.copy(libs_dir + "/freetype/windows/lib/" + _arch + "/freetype.dll", builddir) + if "sdl" in targets: + copy_tree(libs_dir + "/sdl/windows/", "other/sdl/") + if "freetype" in targets: + copy_tree(libs_dir + "/freetype/windows/", "other/freetype/") + + # cleanup + try: + shutil.rmtree(libs_dir) + os.remove(src_package_libs) + except: pass def main(): import argparse From 9ce941048033d510058ee0d46fdbdee9d7429306 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Sun, 30 Dec 2018 23:43:31 +0100 Subject: [PATCH 11/16] Sanitize gametypes with str_sanitize_filename --- src/base/system.c | 16 ++++++++++++++++ src/base/system.h | 13 +++++++++++++ src/game/client/components/menus_browser.cpp | 6 +++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/base/system.c b/src/base/system.c index bcab1771e..4ea45b45b 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -1793,6 +1793,22 @@ void str_sanitize(char *str_in) } } +/* removes all forbidden windows/unix characters in filenames*/ +char* str_sanitize_filename(char* aName) +{ + char *str = (char *)aName; + while(*str) + { + // replace forbidden characters with a whispace + if(*str == '/' || *str == '<' || *str == '>' || *str == ':' || *str == '"' + || *str == '/' || *str == '\\' || *str == '|' || *str == '?' || *str == '*') + *str = ' '; + str++; + } + str_clean_whitespaces(aName); + return aName; +} + /* removes leading and trailing spaces and limits the use of multiple spaces */ void str_clean_whitespaces(char *str_in) { diff --git a/src/base/system.h b/src/base/system.h index 3f842279e..26c9a2aa7 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -826,6 +826,19 @@ void str_sanitize_cc(char *str); */ void str_sanitize(char *str); +/* + Function: str_sanitize_filename + Replaces all forbidden Windows/Unix characters with whitespace + or nothing if leading or trailing. + + Parameters: + str - String to sanitize. + + Remarks: + - The strings are treated as zero-terminated strings. +*/ +char* str_sanitize_filename(char* aName); + /* Function: str_check_pathname Check if the string contains '..' (parent directory) paths. diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index ab942cc33..4c37fcef3 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -2132,11 +2132,15 @@ void CMenus::RenderServerbrowserBottomBox(CUIRect MainView) } void CMenus::DoGameIcon(const char *pName, const CUIRect *pRect, int Type) { + char aNameBuf[128]; + str_copy(aNameBuf, pName, sizeof(aNameBuf)); + str_sanitize_filename(aNameBuf); + // get texture IGraphics::CTextureHandle Tex = m_GameIconDefault; for(int i = 0; i < m_lGameIcons.size(); ++i) { - if(!str_comp_nocase(pName, m_lGameIcons[i].m_Name)) + if(!str_comp_nocase(aNameBuf, m_lGameIcons[i].m_Name)) { Tex = m_lGameIcons[i].m_IconTexture; break; From 51b2b5cafe519f1e44d41135fc70adbda23d4113 Mon Sep 17 00:00:00 2001 From: Speedy Consoles Date: Mon, 31 Dec 2018 16:20:23 +0100 Subject: [PATCH 12/16] Fix audio panning --- src/engine/client/sound.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index 6d7088f33..4058d6cbf 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -122,21 +122,19 @@ static void Mix(short *pFinalOut, unsigned Frames) float Dist = sqrtf((float)dx*dx+dy*dy); if(Dist >= 0.0f && Dist < m_MaxDistance) { - // constant panning (-3dB center) - float a = 0.5f; - if(dx < 0) - a -= (Dist/m_MaxDistance)/2.0f; - else - a += (Dist/m_MaxDistance)/2.0f; - - float Lgain = sinf((1-a)*pi/2.0f); - float Rgain = sinf(a*pi/2.0f); - // linear falloff float Falloff = 1.0f - Dist/m_MaxDistance; - Lvol = Lvol*Lgain*Falloff; - Rvol = Rvol*Rgain*Falloff; + // volume after falloff + float FalloffVol = v->m_pChannel->m_Vol * Falloff; + + // distribute volume to the channels depending on x difference + float Lpan = 0.5f - dx/m_MaxDistance/2.0f; + float Rpan = 1.0f - Lpan; + + // volume of the channels + Lvol = FalloffVol*Lpan; + Rvol = FalloffVol*Rpan; } else { From f06a5eb64955c1fd15a5d855cb2ab30837136590 Mon Sep 17 00:00:00 2001 From: Speedy Consoles Date: Tue, 1 Jan 2019 16:00:11 +0100 Subject: [PATCH 13/16] Add square-law panning --- src/engine/client/sound.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/engine/client/sound.cpp b/src/engine/client/sound.cpp index 4058d6cbf..c0951bf04 100644 --- a/src/engine/client/sound.cpp +++ b/src/engine/client/sound.cpp @@ -125,16 +125,20 @@ static void Mix(short *pFinalOut, unsigned Frames) // linear falloff float Falloff = 1.0f - Dist/m_MaxDistance; - // volume after falloff - float FalloffVol = v->m_pChannel->m_Vol * Falloff; + // amplitude after falloff + float FalloffAmp = v->m_pChannel->m_Vol * Falloff; // distribute volume to the channels depending on x difference float Lpan = 0.5f - dx/m_MaxDistance/2.0f; float Rpan = 1.0f - Lpan; + // apply square root to preserve sound power after panning + float LampFactor = sqrt(Lpan); + float RampFactor = sqrt(Rpan); + // volume of the channels - Lvol = FalloffVol*Lpan; - Rvol = FalloffVol*Rpan; + Lvol = FalloffAmp*LampFactor; + Rvol = FalloffAmp*RampFactor; } else { From 0027eff1c601e8a1de83c3c3638c02687555d2de Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 2 Jan 2019 15:46:33 +0100 Subject: [PATCH 14/16] fixed line endings --- scripts/download.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/download.py b/scripts/download.py index b001b394f..850af96e7 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -32,13 +32,13 @@ def downloadAll(arch, conf, targets): sys.exit(-1) libs_dir = "teeworlds-libs-master" - if "SDL2.dll" in targets: + if "SDL2.dll" in targets: shutil.copy(libs_dir + "/sdl/windows/lib/" + _arch + "/SDL2.dll", builddir) - if "freetype.dll" in targets: + if "freetype.dll" in targets: shutil.copy(libs_dir + "/freetype/windows/lib/" + _arch + "/freetype.dll", builddir) - if "sdl" in targets: + if "sdl" in targets: copy_tree(libs_dir + "/sdl/windows/", "other/sdl/") - if "freetype" in targets: + if "freetype" in targets: copy_tree(libs_dir + "/freetype/windows/", "other/freetype/") # cleanup From 7b21682fec2c89b395b4eafe7ff9ab98707a6043 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 2 Jan 2019 15:47:52 +0100 Subject: [PATCH 15/16] speeded up rcon command update process. closes #1941 --- src/engine/server/server.cpp | 15 ++++++++------- src/engine/server/server.h | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index cce7789c0..d86a8300c 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -760,15 +760,16 @@ void CServer::SendRconCmdRem(const IConsole::CCommandInfo *pCommandInfo, int Cli void CServer::UpdateClientRconCommands() { - int ClientID = Tick() % MAX_CLIENTS; - - if(m_aClients[ClientID].m_State != CClient::STATE_EMPTY && m_aClients[ClientID].m_Authed) + for(int ClientID = Tick() % MAX_RCONCMD_RATIO; ClientID < MaxClients(); ClientID += MAX_RCONCMD_RATIO) { - int ConsoleAccessLevel = m_aClients[ClientID].m_Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD; - for(int i = 0; i < MAX_RCONCMD_SEND && m_aClients[ClientID].m_pRconCmdToSend; ++i) + if(m_aClients[ClientID].m_State != CClient::STATE_EMPTY && m_aClients[ClientID].m_Authed) { - SendRconCmdAdd(m_aClients[ClientID].m_pRconCmdToSend, ClientID); - m_aClients[ClientID].m_pRconCmdToSend = m_aClients[ClientID].m_pRconCmdToSend->NextCommandInfo(ConsoleAccessLevel, CFGFLAG_SERVER); + int ConsoleAccessLevel = m_aClients[ClientID].m_Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD; + for(int i = 0; i < MAX_RCONCMD_SEND && m_aClients[ClientID].m_pRconCmdToSend; ++i) + { + SendRconCmdAdd(m_aClients[ClientID].m_pRconCmdToSend, ClientID); + m_aClients[ClientID].m_pRconCmdToSend = m_aClients[ClientID].m_pRconCmdToSend->NextCommandInfo(ConsoleAccessLevel, CFGFLAG_SERVER); + } } } } diff --git a/src/engine/server/server.h b/src/engine/server/server.h index f71b943de..2112092f1 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -76,6 +76,7 @@ public: AUTHED_ADMIN, MAX_RCONCMD_SEND=16, + MAX_RCONCMD_RATIO=8, }; class CClient From 2d2fe8bf57e64ab13e78505eb345491c9340fcb2 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 2 Jan 2019 19:27:40 +0100 Subject: [PATCH 16/16] reverted edit boxes to 0.6 behavior. closes #1937 --- src/game/client/components/menus.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 72d170428..724d9c850 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -448,11 +448,10 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS s_DoScroll = true; s_ScrollStart = UI()->MouseX(); int MxRel = (int)(UI()->MouseX() - pRect->x); - float Offset = pRect->w/2.0f-TextRender()->TextWidth(0, FontSize, pStr, -1)/2.0f; for(int i = 1; i <= Len; i++) { - if(Offset + TextRender()->TextWidth(0, FontSize, pStr, i) - *pOffset > MxRel) + if(TextRender()->TextWidth(0, FontSize, pStr, i) - *pOffset > MxRel) { s_AtIndex = i - 1; break; @@ -562,15 +561,14 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS UI()->ClipEnable(pRect); Textbox.x -= *pOffset; - UI()->DoLabel(&Textbox, pDisplayStr, FontSize, CUI::ALIGN_CENTER); + UI()->DoLabel(&Textbox, pDisplayStr, FontSize, CUI::ALIGN_LEFT); // render the cursor if(UI()->LastActiveItem() == pID && !JustGotActive) { - float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1); + float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex); Textbox = *pRect; - Textbox.x += Textbox.w/2.0f-w/2.0f; - w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex); + Textbox.VSplitLeft(2.0f, 0, &Textbox); Textbox.x += (w-*pOffset-TextRender()->TextWidth(0, FontSize, "|", -1)/2); if((2*time_get()/time_freq()) % 2) // make it blink