From 18b75d6f727cfca58d506d2797c593507754a957 Mon Sep 17 00:00:00 2001 From: Coruja Date: Mon, 13 Jul 2026 06:30:42 -0300 Subject: [PATCH] Updated project files to use the same compiler flags and features on Windows/Linux builds Also updated C++ standard from C++14 to C++20 --- SphereSvr.vcxproj | 241 ++++++++++++++++++++------------------ makefile | 166 +++++++++++++++----------- src/graysvr/CNTWindow.cpp | 53 +++------ 3 files changed, 243 insertions(+), 217 deletions(-) diff --git a/SphereSvr.vcxproj b/SphereSvr.vcxproj index 85ad815e..177ccda2 100644 --- a/SphereSvr.vcxproj +++ b/SphereSvr.vcxproj @@ -34,13 +34,14 @@ Async + Precise true Level2 libmysql.lib;ws2_32.lib;%(AdditionalDependencies) src\common\mysql\lib\x64 - stdcpp14 + stdcpp20 Windows @@ -59,8 +60,8 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( - StdCall EditAndContinue + false Disabled _DEBUG;%(PreprocessorDefinitions) MultiThreadedDebugDLL @@ -75,7 +76,8 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( - FastCall + true + MaxSpeed _NIGHTLYBUILD;_THREAD_TRACK_CALLSTACK;%(PreprocessorDefinitions) true @@ -89,7 +91,8 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( - FastCall + true + MaxSpeed _THREAD_TRACK_CALLSTACK;%(PreprocessorDefinitions) true @@ -102,22 +105,53 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -147,47 +181,6 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -209,26 +202,70 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + @@ -256,68 +293,38 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - + + + + - - @@ -329,9 +336,13 @@ git rev-parse --is-inside-work-tree >nul 2>&1 && ( + + + + diff --git a/makefile b/makefile index a467039c..b176d3b4 100644 --- a/makefile +++ b/makefile @@ -1,37 +1,103 @@ +# GLOBAL SETTINGS + MAKEFLAGS := -j$(shell nproc) TARGET := spheresvr -CXX := g++ -std=c++14 +CXX := g++ -std=c++20 CC := gcc + +# CODE GENERATION FLAGS + OVERALL_FLAGS := -pipe -OPTIMIZATION_FLAGS := -O2 -ffast-math -flto=auto -fno-omit-frame-pointer -fno-strict-aliasing +OPTIMIZATION_FLAGS := -O2 -flto=auto -fno-omit-frame-pointer -fno-strict-aliasing DEBUG_FLAGS := CODE_GEN_FLAGS := -fexceptions -fnon-call-exceptions ARCH_FLAGS := -m64 -Dx64 -CPPFLAGS := -D_THREAD_TRACK_CALLSTACK ifdef DEBUG - CPPFLAGS += -D_DEBUG + CPPFLAGS := -D_DEBUG DEBUG_FLAGS += -ggdb3 +else + CPPFLAGS := -D_THREAD_TRACK_CALLSTACK endif + ifdef NIGHTLY CPPFLAGS += -D_NIGHTLYBUILD endif -WARN_CXXFLAGS := -Wall -Wno-aggressive-loop-optimizations -Wno-lto-type-mismatch -Wno-return-local-addr -WARN_CFLAGS := -Wall -Wno-implicit-function-declaration -Wno-misleading-indentation -Wno-unused-result +# C/C++ FLAGS + +WARN_CXXFLAGS := -Wall -Wno-register CXXFLAGS := $(OVERALL_FLAGS) $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) $(CODE_GEN_FLAGS) $(ARCH_FLAGS) $(CPPFLAGS) $(WARN_CXXFLAGS) + +WARN_CFLAGS := -Wall -Wno-implicit-function-declaration -Wno-misleading-indentation -Wno-unused-result CFLAGS := $(OVERALL_FLAGS) $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) $(CODE_GEN_FLAGS) $(ARCH_FLAGS) $(CPPFLAGS) $(WARN_CFLAGS) -LDLIBS := -lmysqlclient -lpthread -ldl -LDFLAGS := -pthread -L/usr/lib/mysql + +# LINKER FLAGS + +WARN_LDFLAGS := -Wno-aggressive-loop-optimizations -Wno-lto-type-mismatch -Wno-return-local-addr +LDFLAGS := -L/usr/lib/mysql -pthread $(OPTIMIZATION_FLAGS) $(CODE_GEN_FLAGS) $(ARCH_FLAGS) $(WARN_LDFLAGS) + ifndef DEBUG LDFLAGS += -s endif -SRC := ./src/graysvr/CAccount.cpp \ +LDLIBS := -lmysqlclient -lpthread -ldl + + +# SOURCE FILES + +SRC := ./src/common/CArray.cpp \ + ./src/common/CAssoc.cpp \ + ./src/common/CCacheableScriptFile.cpp \ + ./src/common/CCSVFile.cpp \ + ./src/common/CDataBase.cpp \ + ./src/common/CEncrypt.cpp \ + ./src/common/CException.cpp \ + ./src/common/CExpression.cpp \ + ./src/common/CFile.cpp \ + ./src/common/CFileList.cpp \ + ./src/common/CGrayData.cpp \ + ./src/common/CGrayInst.cpp \ + ./src/common/CGrayMap.cpp \ + ./src/common/CListDefMap.cpp \ + ./src/common/CMD5.cpp \ + ./src/common/CQueue.cpp \ + ./src/common/CRect.cpp \ + ./src/common/CRegion.cpp \ + ./src/common/CResourceBase.cpp \ + ./src/common/CScript.cpp \ + ./src/common/CScriptObj.cpp \ + ./src/common/CSectorTemplate.cpp \ + ./src/common/CSocket.cpp \ + ./src/common/CString.cpp \ + ./src/common/CTime.cpp \ + ./src/common/CVarDefMap.cpp \ + ./src/common/CVarFloat.cpp \ + ./src/common/graycom.cpp \ + ./src/common/libev/wrapper_ev.c \ + ./src/common/sqlite/SQLite.cpp \ + ./src/common/sqlite/sqlite3.c \ + ./src/common/twofish/twofish2.cpp \ + ./src/common/zlib/adler32.c \ + ./src/common/zlib/compress.c \ + ./src/common/zlib/crc32.c \ + ./src/common/zlib/deflate.c \ + ./src/common/zlib/gzclose.c \ + ./src/common/zlib/gzlib.c \ + ./src/common/zlib/gzread.c \ + ./src/common/zlib/gzwrite.c \ + ./src/common/zlib/infback.c \ + ./src/common/zlib/inffast.c \ + ./src/common/zlib/inflate.c \ + ./src/common/zlib/inftrees.c \ + ./src/common/zlib/trees.c \ + ./src/common/zlib/uncompr.c \ + ./src/common/zlib/zutil.c \ + ./src/graysvr/CAccount.cpp \ ./src/graysvr/CBase.cpp \ ./src/graysvr/CChar.cpp \ ./src/graysvr/CCharAct.cpp \ @@ -80,68 +146,26 @@ SRC := ./src/graysvr/CAccount.cpp \ ./src/graysvr/CWorldImport.cpp \ ./src/graysvr/CWorldMap.cpp \ ./src/graysvr/graysvr.cpp \ - ./src/common/twofish/twofish2.cpp \ - ./src/common/libev/wrapper_ev.c \ - ./src/common/zlib/adler32.c \ - ./src/common/zlib/compress.c \ - ./src/common/zlib/crc32.c \ - ./src/common/zlib/deflate.c \ - ./src/common/zlib/gzclose.c \ - ./src/common/zlib/gzlib.c \ - ./src/common/zlib/gzread.c \ - ./src/common/zlib/gzwrite.c \ - ./src/common/zlib/infback.c \ - ./src/common/zlib/inffast.c \ - ./src/common/zlib/inflate.c \ - ./src/common/zlib/inftrees.c \ - ./src/common/zlib/trees.c \ - ./src/common/zlib/uncompr.c \ - ./src/common/zlib/zutil.c \ - ./src/common/CArray.cpp \ - ./src/common/CAssoc.cpp \ - ./src/common/CCacheableScriptFile.cpp \ - ./src/common/CCSVFile.cpp \ - ./src/common/CDataBase.cpp \ - ./src/common/CEncrypt.cpp \ - ./src/common/CExpression.cpp \ - ./src/common/CException.cpp \ - ./src/common/CFile.cpp \ - ./src/common/CFileList.cpp \ - ./src/common/CGrayData.cpp \ - ./src/common/CGrayInst.cpp \ - ./src/common/CGrayMap.cpp \ - ./src/common/CListDefMap.cpp \ - ./src/common/CMD5.cpp \ - ./src/common/CQueue.cpp \ - ./src/common/CRect.cpp \ - ./src/common/CRegion.cpp \ - ./src/common/CResourceBase.cpp \ - ./src/common/CScript.cpp \ - ./src/common/CScriptObj.cpp \ - ./src/common/CSectorTemplate.cpp \ - ./src/common/CSocket.cpp \ - ./src/common/CTime.cpp \ - ./src/common/CString.cpp \ - ./src/common/CVarDefMap.cpp \ - ./src/common/CVarFloat.cpp \ - ./src/common/graycom.cpp \ - ./src/common/sqlite/SQLite.cpp \ - ./src/common/sqlite/sqlite3.c \ - ./src/sphere/mutex.cpp \ - ./src/sphere/strings.cpp \ - ./src/sphere/threads.cpp \ - ./src/sphere/linuxev.cpp \ - ./src/sphere/asyncdb.cpp \ - ./src/sphere/ProfileData.cpp \ ./src/network/network.cpp \ ./src/network/packet.cpp \ + ./src/network/receive.cpp \ ./src/network/send.cpp \ - ./src/network/receive.cpp + ./src/sphere/asyncdb.cpp \ + ./src/sphere/linuxev.cpp \ + ./src/sphere/mutex.cpp \ + ./src/sphere/ProfileData.cpp \ + ./src/sphere/strings.cpp \ + ./src/sphere/threads.cpp + + +# OBJECT FILES OBJS := $(patsubst %.cpp,%.o,$(filter %.cpp,$(SRC))) \ $(patsubst %.c,%.o,$(filter %.c,$(SRC))) +# BUILD RULES + .PHONY: all clean flags version all: $(TARGET) @@ -151,13 +175,21 @@ clean: @find . -name "*.o" -type f -delete flags: - @echo 'Compiler flags: $(CXX) $(CXXFLAGS)' + @echo 'C++ compiler: $(CXX)' + @echo 'C++ flags: $(CXXFLAGS)' + @echo '' + @echo 'C compiler: $(CC)' + @echo 'C flags: $(CFLAGS)' + @echo '' + @echo 'Linker flags: $(LDFLAGS)' + @echo 'Linker libs: $(LDLIBS)' + @echo '' version: flags @VERSIONING_FILE="./src/common/version.h"; \ echo "// This file is auto-generated by compiler pre-build event. Do not edit." > "$${VERSIONING_FILE}"; \ if [ "$$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then \ - GIT_COMMIT_COUNT=$$(expr $$(git rev-list --count HEAD) - 2406); \ + GIT_COMMIT_COUNT=$$(( $$(git rev-list --count HEAD) - 2406 )); \ GIT_COMMIT_HASH=$$(git rev-parse --short HEAD); \ echo "#define GIT_COMMIT_COUNT $${GIT_COMMIT_COUNT}" >> "$${VERSIONING_FILE}"; \ echo "#define GIT_COMMIT_HASH \"$${GIT_COMMIT_HASH}\"" >> "$${VERSIONING_FILE}"; \ @@ -169,8 +201,8 @@ version: flags $(OBJS): version $(TARGET): $(OBJS) - @$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LDLIBS) - @echo ' $(lastword $(MAKEFILE_LIST)) -> $(shell readlink -f $(TARGET))' + @$(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) + @echo ' $(lastword $(MAKEFILE_LIST)) -> $(shell readlink -f $@)' %.o: %.cpp @echo ' $(notdir $<)' diff --git a/src/graysvr/CNTWindow.cpp b/src/graysvr/CNTWindow.cpp index bfb2e4fe..0e78d051 100644 --- a/src/graysvr/CNTWindow.cpp +++ b/src/graysvr/CNTWindow.cpp @@ -211,12 +211,7 @@ void CNTWindow::List_Add( COLORREF color, LPCTSTR pszText ) // If the select is on screen then keep scrolling. if ( ! m_fLogScrollLock && ! GetCapture()) - { - if ( GRAY_GetOSInfo()->dwPlatformId == VER_PLATFORM_WIN32_NT ) - { - m_wndLog.Scroll(); - } - } + m_wndLog.Scroll(); } bool CNTWindow::RegisterClass(char *className) // static @@ -282,18 +277,15 @@ int CNTWindow::OnCreate( HWND hWnd, LPCREATESTRUCT lParam ) (HMENU)(UINT) IDC_M_INPUT, theApp.m_hInstance, NULL ); ASSERT( m_wndInput.m_hWnd ); - if ( GRAY_GetOSInfo()->dwPlatformId > VER_PLATFORM_WIN32s ) - { - memset(&pnid,0,sizeof(pnid)); - pnid.cbSize = sizeof(NOTIFYICONDATA); - pnid.hWnd = m_hWnd; - pnid.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE; - pnid.uCallbackMessage = WM_USER_TRAY_NOTIFY; - pnid.hIcon = theApp.LoadIcon( IDR_MAINFRAME ); - strncpy(pnid.szTip, theApp.m_pszAppName, sizeof(pnid.szTip)); - pnid.szTip[sizeof(pnid.szTip) - 1] = '\0'; - Shell_NotifyIcon(NIM_ADD, &pnid); - } + memset(&pnid,0,sizeof(pnid)); + pnid.cbSize = sizeof(NOTIFYICONDATA); + pnid.hWnd = m_hWnd; + pnid.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE; + pnid.uCallbackMessage = WM_USER_TRAY_NOTIFY; + pnid.hIcon = theApp.LoadIcon(IDR_MAINFRAME); + strncpy(pnid.szTip, theApp.m_pszAppName, sizeof(pnid.szTip)); + pnid.szTip[sizeof(pnid.szTip) - 1] = '\0'; + Shell_NotifyIcon(NIM_ADD, &pnid); NTWindow_SetWindowTitle(); @@ -505,11 +497,8 @@ bool CNTWindow::OnSysCommand( WPARAM uCmdType, int xPos, int yPos ) switch ( uCmdType ) { case SC_MINIMIZE: - if ( GRAY_GetOSInfo()->dwPlatformId > VER_PLATFORM_WIN32s ) - { - ShowWindow(SW_HIDE); - return( true ); - } + ShowWindow(SW_HIDE); + return true; break; } return( false ); @@ -782,11 +771,8 @@ bool NTWindow_Init(HINSTANCE hInstance, int nCmdShow) void NTWindow_DeleteIcon() { - if ( GRAY_GetOSInfo()->dwPlatformId > VER_PLATFORM_WIN32s ) - { - theApp.m_wndMain.pnid.uFlags = 0; - Shell_NotifyIcon(NIM_DELETE, &theApp.m_wndMain.pnid); - } + theApp.m_wndMain.pnid.uFlags = 0; + Shell_NotifyIcon(NIM_DELETE, &theApp.m_wndMain.pnid); } void NTWindow_Exit() @@ -843,13 +829,10 @@ void NTWindow_SetWindowTitle( LPCTSTR pszText ) snprintf(szTitle, sizeof(szTitle), "%s - %s (%s) %s", theApp.m_pszAppName, g_Serv.GetName(), pszMode, pszText ? pszText : ""); theApp.m_wndMain.SetWindowText(szTitle); - if ( GRAY_GetOSInfo()->dwPlatformId > VER_PLATFORM_WIN32s ) - { - theApp.m_wndMain.pnid.uFlags = NIF_TIP; - strncpy(theApp.m_wndMain.pnid.szTip, szTitle, sizeof(theApp.m_wndMain.pnid.szTip)); - theApp.m_wndMain.pnid.szTip[sizeof(theApp.m_wndMain.pnid.szTip) - 1] = '\0'; - Shell_NotifyIcon(NIM_MODIFY, &theApp.m_wndMain.pnid); - } + theApp.m_wndMain.pnid.uFlags = NIF_TIP; + strncpy(theApp.m_wndMain.pnid.szTip, szTitle, sizeof(theApp.m_wndMain.pnid.szTip)); + theApp.m_wndMain.pnid.szTip[sizeof(theApp.m_wndMain.pnid.szTip) - 1] = '\0'; + Shell_NotifyIcon(NIM_MODIFY, &theApp.m_wndMain.pnid); } bool NTWindow_PostMsgColor( COLORREF color )