diff --git a/CMakeLists.txt b/CMakeLists.txt index 63ad5763f..f52ec6732 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,7 +251,6 @@ set(devilutionx_SRCS SourceX/controls/touch.cpp SourceX/miniwin/ddraw.cpp SourceX/miniwin/misc.cpp - SourceX/miniwin/misc_io.cpp SourceX/miniwin/misc_msg.cpp SourceX/miniwin/rand.cpp SourceX/miniwin/thread.cpp diff --git a/Source/dthread.cpp b/Source/dthread.cpp index 21a81bee6..2c497d908 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -127,10 +127,10 @@ void dthread_cleanup() error_buf = TraceLastError(); app_fatal("dthread3:\n(%s)", error_buf); } - CloseHandle(sghThread); + CloseEvent(sghThread); sghThread = INVALID_HANDLE_VALUE; } - CloseHandle(sghWorkToDoEvent); + CloseEvent(sghWorkToDoEvent); sghWorkToDoEvent = NULL; while (sgpInfoHead) { diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index ef381ba07..a3cb43cdc 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -326,7 +326,6 @@ BOOL OpenMPQ(const char *pszArchive, DWORD dwChar) _FILEHEADER fhdr; InitHash(); - dwFlagsAndAttributes = gbMaxPlayers > 1 ? FILE_FLAG_WRITE_THROUGH : 0; if (archive != nullptr) { delete archive; diff --git a/Source/multi.cpp b/Source/multi.cpp index 69c65dc3c..5f0d239fb 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -5,9 +5,6 @@ DEVILUTION_BEGIN_NAMESPACE BOOLEAN gbSomebodyWonGameKludge; -#ifdef _DEBUG -DWORD gdwHistTicks; -#endif TBuffer sgHiPriBuf; char szPlayerDescript[128]; WORD sgwPackPlrOffsetTbl[MAX_PLRS]; @@ -38,43 +35,6 @@ const int event_types[3] = { EVENT_TYPE_PLAYER_MESSAGE }; -#ifdef _DEBUG -void dumphist(const char *pszFmt, ...) -{ - static FILE *sgpHistFile = NULL; - DWORD dwTicks; - va_list va; - - va_start(va, pszFmt); - - char path[MAX_PATH], dumpHistPath[MAX_PATH]; - if (sgpHistFile == NULL) { - GetPrefPath(path, MAX_PATH); - snprintf(dumpHistPath, MAX_PATH, "%sdumphist.txt", path); - sgpHistFile = fopen(dumpHistPath, "wb"); - if (sgpHistFile == NULL) { - return; - } - } - - dwTicks = GetTickCount(); - fprintf(sgpHistFile, "%4u.%02u ", (dwTicks - gdwHistTicks) / 1000, (dwTicks - gdwHistTicks) % 1000 / 10); - vfprintf(sgpHistFile, pszFmt, va); - fprintf( - sgpHistFile, - "\r\n (%d,%d)(%d,%d)(%d,%d)(%d,%d)\r\n", - plr[0].plractive, - player_state[0], - plr[1].plractive, - player_state[1], - plr[2].plractive, - player_state[2], - plr[3].plractive, - player_state[3]); - fflush(sgpHistFile); -} -#endif - void multi_msg_add(BYTE *pbMsg, BYTE bLen) { if (pbMsg && bLen) { @@ -408,16 +368,6 @@ void multi_begin_timeout() /// ASSERT: assert(nLowestActive != -1); /// ASSERT: assert(nLowestPlayer != -1); -#ifdef _DEBUG - dumphist( - "(%d) grp:%d ngrp:%d lowp:%d lowa:%d", - myplr, - bGroupPlayers, - bGroupCount, - nLowestPlayer, - nLowestActive); -#endif - if (bGroupPlayers < bGroupCount) { gbGameDestroyed = TRUE; } else if (bGroupPlayers == bGroupCount) { @@ -730,10 +680,6 @@ BOOL NetInit(BOOL bSinglePlayer, BOOL *pfExitProgram) if (!multi_init_multi(&ProgramData, &plrdata, &UiData, pfExitProgram)) return FALSE; } -#ifdef _DEBUG - gdwHistTicks = GetTickCount(); - dumphist("(%d) new game started", myplr); -#endif sgbNetInited = TRUE; sgbTimeout = FALSE; delta_init(); @@ -946,9 +892,6 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, BOOL recv) UnPackPlayer(&netplr[pnum], pnum, TRUE); if (!recv) { -#ifdef _DEBUG - dumphist("(%d) received all %d plrinfo", myplr, pnum); -#endif return; } @@ -978,9 +921,6 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, BOOL recv) dFlags[plr[pnum].WorldX][plr[pnum].WorldY] |= BFLAG_DEAD_PLAYER; } } -#ifdef _DEBUG - dumphist("(%d) making %d active -- recv_plrinfo", myplr, pnum); -#endif } DEVILUTION_END_NAMESPACE diff --git a/Source/multi.h b/Source/multi.h index 4b62c778f..6435139d8 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -15,9 +15,6 @@ extern char szPlayerName[128]; extern BYTE gbDeltaSender; extern int player_state[MAX_PLRS]; -#ifdef _DEBUG -void dumphist(const char *pszFmt, ...); -#endif void multi_msg_add(BYTE *pbMsg, BYTE bLen); void NetSendLoPri(BYTE *pbMsg, BYTE bLen); void multi_copy_packet(TBuffer *pBuf, void *packet, BYTE size); diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 8d7bd5f7e..fb4d7e90a 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -204,7 +204,7 @@ void nthread_cleanup() if (WaitForSingleObject(sghThread, 0xFFFFFFFF) == -1) { app_fatal("nthread3:\n(%s)", TraceLastError()); } - CloseHandle(sghThread); + CloseEvent(sghThread); sghThread = INVALID_HANDLE_VALUE; } } diff --git a/SourceS/miniwin.h b/SourceS/miniwin.h index fc76a5746..175fe53f4 100644 --- a/SourceS/miniwin.h +++ b/SourceS/miniwin.h @@ -22,7 +22,6 @@ #endif #include "miniwin/misc.h" -#include "miniwin/ui.h" #include "miniwin/thread.h" #include "miniwin/rand.h" #include "storm_full.h" diff --git a/SourceS/miniwin/misc.h b/SourceS/miniwin/misc.h index 4ad7033a5..16e0f4e7d 100644 --- a/SourceS/miniwin/misc.h +++ b/SourceS/miniwin/misc.h @@ -89,8 +89,6 @@ typedef void *LPSECURITY_ATTRIBUTES; DWORD GetTickCount(); -WINBOOL CloseHandle(HANDLE hObject); - HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINBOOL bManualReset, WINBOOL bInitialState, LPCSTR lpName); BOOL CloseEvent(HANDLE event); @@ -126,16 +124,6 @@ int _strcmpi(const char *_Str1, const char *_Str2); typedef void *LPOVERLAPPED; -WINBOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, - LPOVERLAPPED lpOverlapped); -DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); -WINBOOL SetEndOfFile(HANDLE hFile); -HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); -WINBOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, - LPOVERLAPPED lpOverlapped); -DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); WINBOOL DeleteFileA(LPCSTR lpFileName); // @@ -150,11 +138,6 @@ typedef struct { constexpr auto DVL_WM_SYSKEYUP = 0x0105; -constexpr auto DVL_CREATE_ALWAYS = 2; -constexpr auto DVL_GENERIC_READ = 0x80000000L; -constexpr auto DVL_GENERIC_WRITE = 0x40000000L; -constexpr auto DVL_OPEN_EXISTING = 3; -constexpr auto DVL_FILE_BEGIN = 0; constexpr auto DVL_FILE_CURRENT = 1; constexpr auto DVL_WM_QUIT = 0x0012; diff --git a/SourceS/miniwin/misc_macro.h b/SourceS/miniwin/misc_macro.h index ce55adc64..5d03781f2 100644 --- a/SourceS/miniwin/misc_macro.h +++ b/SourceS/miniwin/misc_macro.h @@ -28,19 +28,12 @@ // File I/O // -#define FILE_BEGIN DVL_FILE_BEGIN #define FILE_CURRENT DVL_FILE_CURRENT -#define FILE_FLAG_WRITE_THROUGH 0x80000000 -#define CREATE_ALWAYS DVL_CREATE_ALWAYS -#define GENERIC_READ DVL_GENERIC_READ -#define GENERIC_WRITE DVL_GENERIC_WRITE -#define OPEN_EXISTING DVL_OPEN_EXISTING // // Calculate the byte offset of a field in a structure of type type. // -#define CreateFile CreateFileA #define DeleteFile DeleteFileA // diff --git a/SourceS/sdl2_to_1_2_backports.h b/SourceS/sdl2_to_1_2_backports.h index 938964d8a..97bb566e7 100644 --- a/SourceS/sdl2_to_1_2_backports.h +++ b/SourceS/sdl2_to_1_2_backports.h @@ -103,7 +103,7 @@ inline int SDL_ShowSimpleMessageBox(Uint32 flags, const char *message, SDL_Surface *window) { - fprintf(stderr, "MSGBOX: %s\n%s\n", title, message); + SDL_Log("MSGBOX: %s\n%s", title, message); return 0; } diff --git a/SourceS/miniwin/ui.h b/SourceS/ui_fwd.h similarity index 71% rename from SourceS/miniwin/ui.h rename to SourceS/ui_fwd.h index 4f46dd905..1068ade55 100644 --- a/SourceS/miniwin/ui.h +++ b/SourceS/ui_fwd.h @@ -2,7 +2,6 @@ namespace dvl { -BOOL EndDialog(HWND hDlg, INT_PTR nResult); void UiErrorOkDialog(const char *text, const char *caption, bool error = true); } // namespace dvl diff --git a/SourceX/dvlnet/udp_p2p.cpp b/SourceX/dvlnet/udp_p2p.cpp index db53d23f0..0a065704e 100644 --- a/SourceX/dvlnet/udp_p2p.cpp +++ b/SourceX/dvlnet/udp_p2p.cpp @@ -23,7 +23,7 @@ int udp_p2p::create(std::string addrstr, std::string passwd) try { sock.bind(asio::ip::udp::endpoint(asio::ip::address_v6(), port)); } catch (std::exception &e) { - eprintf("bind: %s, %s\n", asio::ip::address_v6().to_string(), + SDL_Log("bind: %s, %s", asio::ip::address_v6().to_string(), e.what()); } ++port; diff --git a/SourceX/miniwin/misc.cpp b/SourceX/miniwin/misc.cpp index d5b5ddc17..f96f94aa0 100644 --- a/SourceX/miniwin/misc.cpp +++ b/SourceX/miniwin/misc.cpp @@ -59,9 +59,9 @@ WINBOOL DeleteFileA(LPCSTR lpFileName) fclose(f); remove(name); f = NULL; - eprintf("Removed file: %s\n", name); + SDL_Log("Removed file: %s", name); } else { - eprintf("Failed to remove file: %s\n", name); + SDL_Log("Failed to remove file: %s", name); } return true; diff --git a/SourceX/miniwin/misc_io.cpp b/SourceX/miniwin/misc_io.cpp deleted file mode 100644 index 6f4fe927e..000000000 --- a/SourceX/miniwin/misc_io.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "devilution.h" -#include "stubs.h" - -namespace dvl { - -struct memfile { - std::string path; - std::vector buf; - std::size_t pos = 0; -}; - -static std::unordered_set files; - -HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) -{ - char name[DVL_MAX_PATH]; - TranslateFileName(name, sizeof(name), lpFileName); - SDL_Log("file: %s (%s)", lpFileName, name); - UNIMPLEMENTED_UNLESS(!(dwDesiredAccess & ~(DVL_GENERIC_READ | DVL_GENERIC_WRITE))); - memfile *file = new memfile; - file->path = name; - if (dwCreationDisposition == DVL_OPEN_EXISTING) { - // read contents of existing file into buffer - std::ifstream filestream(file->path, std::ios::binary); - if (!filestream.fail()) { - file->buf.insert(file->buf.begin(), - std::istreambuf_iterator(filestream), - std::istreambuf_iterator()); - } - } else if (dwCreationDisposition == DVL_CREATE_ALWAYS) { - // start with empty file - } else { - UNIMPLEMENTED(); - } - files.insert(file); - return file; -} - -WINBOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, - LPOVERLAPPED lpOverlapped) -{ - memfile *file = static_cast(hFile); - UNIMPLEMENTED_UNLESS(!lpOverlapped); - size_t len = std::min(file->buf.size() - file->pos, nNumberOfBytesToRead); - std::memcpy(lpBuffer, file->buf.data() + file->pos, len); - file->pos += len; - *lpNumberOfBytesRead = len; - return true; -} - -DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) -{ - memfile *file = static_cast(hFile); - return file->buf.size(); -} - -WINBOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped) -{ - memfile *file = static_cast(hFile); - UNIMPLEMENTED_UNLESS(!lpOverlapped); - if (!nNumberOfBytesToWrite) - return true; - if (file->buf.size() < file->pos + nNumberOfBytesToWrite) - file->buf.resize(file->pos + nNumberOfBytesToWrite); - std::memcpy(file->buf.data() + file->pos, lpBuffer, nNumberOfBytesToWrite); - file->pos += nNumberOfBytesToWrite; - *lpNumberOfBytesWritten = nNumberOfBytesToWrite; - return true; -} - -DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) -{ - memfile *file = static_cast(hFile); - UNIMPLEMENTED_UNLESS(!lpDistanceToMoveHigh); - if (dwMoveMethod == DVL_FILE_BEGIN) { - file->pos = lDistanceToMove; - } else if (dwMoveMethod == DVL_FILE_CURRENT) { - file->pos += lDistanceToMove; - } else { - UNIMPLEMENTED(); - - } - if (file->buf.size() < file->pos + 1) - file->buf.resize(file->pos + 1); - return file->pos; -} - -WINBOOL SetEndOfFile(HANDLE hFile) -{ - memfile *file = static_cast(hFile); - file->buf.erase(file->buf.begin() + file->pos, file->buf.end()); - return true; -} - -void ShowOutOfDiskError() -{ - constexpr char text[] = "Failed to save, please free some disk space and try again."; - UiErrorOkDialog("Out of Disk Space", text); -} - -WINBOOL CloseHandle(HANDLE hObject) -{ - memfile *file = static_cast(hObject); - const auto file_it = files.find(file); - if (file_it == files.end()) - return CloseEvent(hObject); - std::unique_ptr ufile(file); // ensure that delete file is - // called on returning - files.erase(file_it); - std::ofstream filestream(file->path + ".tmp", std::ios::binary | std::ios::trunc); - if (filestream.fail()) { - ShowOutOfDiskError(); - return false; - } - filestream.write(file->buf.data(), file->buf.size()); - if (filestream.fail()) { - ShowOutOfDiskError(); - return false; - } - filestream.close(); - std::remove(file->path.c_str()); - if (std::rename((file->path + ".tmp").c_str(), file->path.c_str())) { - ShowOutOfDiskError(); - return false; - } - return true; -} - -} // namespace dvl diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index 51f6436ab..196178282 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -717,7 +717,7 @@ WINBOOL TranslateMessage(const MSG *lpMsg) #ifdef _DEBUG if (key >= 32) { - DUMMY_PRINT("char: %c", key); + SDL_Log("char: %c", key); } #endif diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 30243661f..85858f2bd 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -162,8 +162,6 @@ unsigned char AsciiToLowerTable_Path[256] = { BOOL SFileOpenFile(const char *filename, HANDLE *phFile) { - //eprintf("%s: %s\n", __FUNCTION__, filename); - bool result = false; if (directFileAccess) { @@ -183,7 +181,7 @@ BOOL SFileOpenFile(const char *filename, HANDLE *phFile) } if (!result || !*phFile) { - eprintf("%s: Not found: %s\n", __FUNCTION__, filename); + SDL_Log("%s: Not found: %s", __FUNCTION__, filename); } return result; } @@ -309,14 +307,12 @@ BOOL SBmpLoadImage(const char *pszFileName, SDL_Color *pPalette, BYTE *pBuffer, void *SMemAlloc(unsigned int amount, char *logfilename, int logline, int defaultValue) { - // fprintf(stderr, "%s: %d (%s:%d)\n", __FUNCTION__, amount, logfilename, logline); assert(amount != -1u); return malloc(amount); } BOOL SMemFree(void *location, char *logfilename, int logline, char defaultValue) { - // fprintf(stderr, "%s: (%s:%d)\n", __FUNCTION__, logfilename, logline); assert(location); free(location); return true; diff --git a/SourceX/stubs.h b/SourceX/stubs.h index dd6968ad8..b09ed3392 100644 --- a/SourceX/stubs.h +++ b/SourceX/stubs.h @@ -4,11 +4,9 @@ #include #include -#define eprintf(...) fprintf(stderr, __VA_ARGS__) - #define UNIMPLEMENTED() \ do { \ - eprintf("UNIMPLEMENTED: %s @ %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \ + SDL_Log("UNIMPLEMENTED: %s @ %s:%d", __FUNCTION__, __FILE__, __LINE__); \ abort(); \ } while (0) @@ -20,11 +18,11 @@ #define ABORT() \ do { \ - eprintf("ABORT: %s @ %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \ + SDL_Log("ABORT: %s @ %s:%d", __FUNCTION__, __FILE__, __LINE__); \ abort(); \ } while (0) -#define DUMMY() eprintf("DUMMY: %s @ %s:%d\n", __FUNCTION__, __FILE__, __LINE__) +#define DUMMY() SDL_Log("DUMMY: %s @ %s:%d", __FUNCTION__, __FILE__, __LINE__) #define DUMMY_ONCE() \ do { \ @@ -35,15 +33,13 @@ } \ } while (0) -#define DUMMY_PRINT(fmt, ...) eprintf("DUMMY: %s : " fmt "\n", __FUNCTION__, ##__VA_ARGS__) - static inline const char *nullstr(const char *a) { return a ? a : "(null)"; } -#define ASSERT(x) \ - if (!(x)) { \ - fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #x); \ - abort(); \ +#define ASSERT(x) \ + if (!(x)) { \ + SDL_Log("Assertion failed in %s:%d: %s", __FILE__, __LINE__, #x); \ + abort(); \ } diff --git a/types.h b/types.h index 4a793198d..3a3cd65d1 100644 --- a/types.h +++ b/types.h @@ -10,6 +10,7 @@ #include "miniwin.h" #include "ssound.h" +#include "ui_fwd.h" DEVILUTION_BEGIN_NAMESPACE