Browse Source

Remove unused miniwin IO

pull/568/head
Anders Jenbo 6 years ago
parent
commit
cc4d6b57d8
  1. 1
      CMakeLists.txt
  2. 4
      Source/dthread.cpp
  3. 1
      Source/mpqapi.cpp
  4. 60
      Source/multi.cpp
  5. 3
      Source/multi.h
  6. 2
      Source/nthread.cpp
  7. 1
      SourceS/miniwin.h
  8. 17
      SourceS/miniwin/misc.h
  9. 7
      SourceS/miniwin/misc_macro.h
  10. 2
      SourceS/sdl2_to_1_2_backports.h
  11. 1
      SourceS/ui_fwd.h
  12. 2
      SourceX/dvlnet/udp_p2p.cpp
  13. 4
      SourceX/miniwin/misc.cpp
  14. 143
      SourceX/miniwin/misc_io.cpp
  15. 2
      SourceX/miniwin/misc_msg.cpp
  16. 6
      SourceX/storm/storm.cpp
  17. 18
      SourceX/stubs.h
  18. 1
      types.h

1
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

4
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) {

1
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;

60
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

3
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);

2
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;
}
}

1
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"

17
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;

7
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
//

2
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;
}

1
SourceS/miniwin/ui.h → 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

2
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;

4
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;

143
SourceX/miniwin/misc_io.cpp

@ -1,143 +0,0 @@
#include <cstdio>
#include <cstring>
#include <unordered_set>
#include <string>
#include <iterator>
#include <vector>
#include <algorithm>
#include <fstream>
#include <memory>
#include <stdexcept>
#include "devilution.h"
#include "stubs.h"
namespace dvl {
struct memfile {
std::string path;
std::vector<char> buf;
std::size_t pos = 0;
};
static std::unordered_set<memfile *> 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<char>(filestream),
std::istreambuf_iterator<char>());
}
} 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<memfile *>(hFile);
UNIMPLEMENTED_UNLESS(!lpOverlapped);
size_t len = std::min<size_t>(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<memfile *>(hFile);
return file->buf.size();
}
WINBOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
{
memfile *file = static_cast<memfile *>(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<memfile *>(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<memfile *>(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<memfile *>(hObject);
const auto file_it = files.find(file);
if (file_it == files.end())
return CloseEvent(hObject);
std::unique_ptr<memfile> 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

2
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

6
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;

18
SourceX/stubs.h

@ -4,11 +4,9 @@
#include <stdio.h>
#include <stdlib.h>
#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(); \
}

1
types.h

@ -10,6 +10,7 @@
#include "miniwin.h"
#include "ssound.h"
#include "ui_fwd.h"
DEVILUTION_BEGIN_NAMESPACE

Loading…
Cancel
Save