Move generic helpers out of miniwin

This commit is contained in:
Anders Jenbo 2020-01-31 22:59:20 +01:00
commit 08aa6a860a
44 changed files with 132 additions and 179 deletions

View file

@ -249,13 +249,12 @@ set(devilutionx_SRCS
SourceX/controls/modifier_hints.cpp
SourceX/controls/plrctrls.cpp
SourceX/controls/touch.cpp
SourceX/miniwin/ddraw.cpp
SourceX/miniwin/misc.cpp
SourceX/display.cpp
SourceX/miniwin/misc_msg.cpp
SourceX/miniwin/rand.cpp
SourceX/miniwin/thread.cpp
SourceX/sound.cpp
SourceX/ssound.cpp
SourceX/soundsample.cpp
SourceX/storm/storm.cpp
SourceX/storm/storm_net.cpp
SourceX/storm/storm_dx.cpp

View file

@ -25,24 +25,24 @@ void app_fatal(const char *pszFmt, ...)
void MsgBox(const char *pszFmt, va_list va)
{
char Text[256];
char text[256];
wvsprintf(Text, pszFmt, va);
vsnprintf(text, 256, pszFmt, va);
UiErrorOkDialog("Error", Text);
UiErrorOkDialog("Error", text);
}
void FreeDlg()
{
if (terminating && cleanup_thread_id != GetCurrentThreadId())
Sleep(20000);
SDL_Delay(20000);
terminating = TRUE;
cleanup_thread_id = GetCurrentThreadId();
if (gbMaxPlayers > 1) {
if (SNetLeaveGame(3))
Sleep(2000);
SDL_Delay(2000);
}
SNetDestroy();
@ -51,11 +51,11 @@ void FreeDlg()
void DrawDlg(char *pszFmt, ...)
{
char text[256];
va_list arglist;
va_list va;
va_start(arglist, pszFmt);
wvsprintf(text, pszFmt, arglist);
va_end(arglist);
va_start(va, pszFmt);
vsnprintf(text, 256, pszFmt, va);
va_end(va);
UiErrorOkDialog(PROJECT_NAME, text, false);
}

View file

@ -150,12 +150,12 @@ void CaptureScreen()
if (!success) {
SDL_Log("Failed to save screenshot at %s", FileName);
DeleteFile(FileName);
RemoveFile(FileName);
} else {
SDL_Log("Screenshot saved at %s", FileName);
}
Sleep(300);
SDL_Delay(300);
PaletteGetEntries(256, palette);
delete out;
}

View file

@ -266,7 +266,7 @@ void diablo_init()
ReadOnlyTest();
srand(GetTickCount());
srand(SDL_GetTicks());
InitHash();
diablo_init_screen();

View file

@ -104,7 +104,7 @@ unsigned int dthread_handler(void *)
mem_free_dbg(pkt);
if (dwMilliseconds)
Sleep(dwMilliseconds);
SDL_Delay(dwMilliseconds);
}
}

View file

@ -70,7 +70,7 @@ void InitDiabloMsg(char e)
msgcnt++;
msgflag = msgtable[0];
msgdelay = GetTickCount();
msgdelay = SDL_GetTicks();
}
void ClrDiabloMsg()
@ -133,7 +133,7 @@ void DrawDiabloMsg()
sx += fontkern[c] + 1;
}
if (msgdelay > 0 && msgdelay <= GetTickCount() - 3500) {
if (msgdelay > 0 && msgdelay <= SDL_GetTicks() - 3500) {
msgdelay = 0;
}
if (msgdelay == 0) {
@ -142,7 +142,7 @@ void DrawDiabloMsg()
msgflag = 0;
} else {
msgflag = msgtable[msgcnt];
msgdelay = GetTickCount();
msgdelay = SDL_GetTicks();
}
}
}

View file

@ -164,7 +164,7 @@ void gmenu_draw()
}
}
ticks = GetTickCount();
ticks = SDL_GetTicks();
if ((int)(ticks - PentSpin_tick) > 50) { // BUGFIX: thould be 50ms (Fixed)
PentSpin_frame++;
if (PentSpin_frame == 9)

View file

@ -1736,7 +1736,7 @@ void DrawInvMsg(char *msg)
{
DWORD dwTicks;
dwTicks = GetTickCount();
dwTicks = SDL_GetTicks();
if (dwTicks - sgdwLastTime >= 5000) {
sgdwLastTime = dwTicks;
ErrorPlrMsg(msg);

View file

@ -3998,7 +3998,7 @@ BOOL GetItemRecord(int nSeed, WORD wCI, int nIndex)
int i;
DWORD dwTicks;
dwTicks = GetTickCount();
dwTicks = SDL_GetTicks();
for (i = 0; i < gnNumGetRecords; i++) {
if (dwTicks - itemrecord[i].dwTimestamp > 6000) {
@ -4030,7 +4030,7 @@ void SetItemRecord(int nSeed, WORD wCI, int nIndex)
{
DWORD dwTicks;
dwTicks = GetTickCount();
dwTicks = SDL_GetTicks();
if (gnNumGetRecords == MAXITEMS) {
return;
@ -4048,7 +4048,7 @@ void PutItemRecord(int nSeed, WORD wCI, int nIndex)
int i;
DWORD dwTicks;
dwTicks = GetTickCount();
dwTicks = SDL_GetTicks();
for (i = 0; i < gnNumGetRecords; i++) {
if (dwTicks - itemrecord[i].dwTimestamp > 6000) {

View file

@ -67,7 +67,7 @@ void InitQTextMsg(int m)
scrolltexty = 50 / -(sgLastScroll - 1);
else
scrolltexty = ((sgLastScroll + 1) * 50) / sgLastScroll;
qtextSpd = GetTickCount();
qtextSpd = SDL_GetTicks();
}
PlaySFX(alltext[m].sfxnr);
}
@ -156,7 +156,7 @@ void DrawQText()
}
}
for (currTime = GetTickCount(); qtextSpd + scrolltexty < currTime; qtextSpd += scrolltexty) {
for (currTime = SDL_GetTicks(); qtextSpd + scrolltexty < currTime; qtextSpd += scrolltexty) {
qtexty--;
if (qtexty <= 209) {
qtexty += 38;

View file

@ -2534,7 +2534,7 @@ void DoEnding()
music_stop();
if (gbMaxPlayers > 1) {
Sleep(1000);
SDL_Delay(1000);
}
#ifndef SPAWN

View file

@ -1,6 +1,6 @@
#include "diablo.h"
#include "../3rdParty/Storm/Source/storm.h"
#include "../SourceX/miniwin/ddraw.h"
#include "../SourceX/display.h"
DEVILUTION_BEGIN_NAMESPACE

View file

@ -77,7 +77,7 @@ BOOL msg_wait_resync()
sgnCurrMegaPlayer = -1;
sgbRecvCmd = CMD_DLEVEL_END;
gbBufferMsgs = 1;
sgdwOwnerWait = GetTickCount();
sgdwOwnerWait = SDL_GetTicks();
success = UiProgressDialog(ghMainWnd, "Waiting for game data...", 1, msg_wait_for_turns, 20);
gbBufferMsgs = 0;
if (!success) {
@ -118,7 +118,7 @@ int msg_wait_for_turns()
nthread_send_and_recv_turn(0, 0);
if (!SNetGetOwnerTurnsWaiting(&turns) && SErrGetLastError() == STORM_ERROR_NOT_IN_GAME)
return 100;
if (GetTickCount() - sgdwOwnerWait <= 2000 && turns < gdwTurnsInTransit)
if (SDL_GetTicks() - sgdwOwnerWait <= 2000 && turns < gdwTurnsInTransit)
return 0;
sgbDeltaChunks++;
}
@ -803,7 +803,7 @@ void NetSendCmdGItem2(BOOL usonly, BYTE bCmd, BYTE mast, BYTE pnum, TCmdGItem *p
return;
}
ticks = GetTickCount();
ticks = SDL_GetTicks();
if (!cmd.dwTime) {
cmd.dwTime = ticks;
} else if (ticks - cmd.dwTime > 5000) {
@ -823,7 +823,7 @@ BOOL NetSendCmdReq2(BYTE bCmd, BYTE mast, BYTE pnum, TCmdGItem *p)
cmd.bPnum = pnum;
cmd.bMaster = mast;
ticks = GetTickCount();
ticks = SDL_GetTicks();
if (!cmd.dwTime) {
cmd.dwTime = ticks;
} else if (ticks - cmd.dwTime > 5000) {
@ -1377,7 +1377,7 @@ void msg_errorf(const char *pszFmt, ...)
va_list va;
va_start(va, pszFmt);
ticks = GetTickCount();
ticks = SDL_GetTicks();
if (ticks - msg_err_timer >= 5000) {
msg_err_timer = ticks;
vsprintf(msg, pszFmt, va);

View file

@ -261,7 +261,7 @@ void multi_player_left_msg(int pnum, int left)
void multi_net_ping()
{
sgbTimeout = TRUE;
sglTimeoutStart = GetTickCount();
sglTimeoutStart = SDL_GetTicks();
}
int multi_handle_delta()
@ -334,7 +334,7 @@ void multi_begin_timeout()
}
#endif
nTicks = GetTickCount() - sglTimeoutStart;
nTicks = SDL_GetTicks() - sglTimeoutStart;
if (nTicks > 20000) {
gbRunGame = FALSE;
return;
@ -565,7 +565,7 @@ void NetClose()
multi_event_handler(FALSE);
SNetLeaveGame(3);
if (gbMaxPlayers > 1)
Sleep(2000);
SDL_Delay(2000);
}
void multi_event_handler(BOOL add)

View file

@ -95,7 +95,7 @@ BOOL nthread_recv_turns(BOOL *pfSendAsync)
} else {
if (!sgbTicsOutOfSync) {
sgbTicsOutOfSync = TRUE;
last_tick = GetTickCount();
last_tick = SDL_GetTicks();
}
sgbSyncCountdown = 4;
multi_msg_countdown();
@ -116,7 +116,7 @@ void nthread_start(BOOL set_turn_upper_bit)
DWORD largestMsgSize;
_SNETCAPS caps;
last_tick = GetTickCount();
last_tick = SDL_GetTicks();
sgbPacketCountdown = 1;
sgbSyncCountdown = 1;
sgbTicsOutOfSync = TRUE;
@ -178,12 +178,12 @@ unsigned int nthread_handler(void *)
break;
nthread_send_and_recv_turn(0, 0);
if (nthread_recv_turns(&received))
delta = last_tick - GetTickCount();
delta = last_tick - SDL_GetTicks();
else
delta = 50;
sgMemCrit.Leave();
if (delta > 0)
Sleep(delta);
SDL_Delay(delta);
if (!nthread_should_run)
return 0;
}
@ -225,7 +225,7 @@ BOOL nthread_has_500ms_passed(BOOL unused)
DWORD currentTickCount;
int ticksElapsed;
currentTickCount = GetTickCount();
currentTickCount = SDL_GetTicks();
ticksElapsed = currentTickCount - last_tick;
if (gbMaxPlayers == 1 && ticksElapsed > 500) {
last_tick = currentTickCount;

View file

@ -1,6 +1,7 @@
#include "diablo.h"
#include "../3rdParty/Storm/Source/storm.h"
#include "../DiabloUI/diabloui.h"
#include "file_util.h"
DEVILUTION_BEGIN_NAMESPACE
@ -371,7 +372,7 @@ BOOL pfile_delete_save(_uiheroinfo *hero_info)
if (save_num < MAX_CHARACTERS) {
hero_names[save_num][0] = '\0';
pfile_get_save_path(FileName, sizeof(FileName), save_num);
DeleteFile(FileName);
RemoveFile(FileName);
}
return TRUE;
}
@ -574,7 +575,7 @@ void pfile_update(BOOL force_save)
static int save_prev_tc;
if (gbMaxPlayers != 1) {
int tick = GetTickCount();
int tick = SDL_GetTicks();
if (force_save || tick - save_prev_tc > 60000) {
save_prev_tc = tick;
pfile_write_hero();

View file

@ -534,7 +534,7 @@ void CreatePlayer(int pnum, char c)
int i;
ClearPlrRVars(&plr[pnum]);
SetRndSeed(GetTickCount());
SetRndSeed(SDL_GetTicks());
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("CreatePlayer: illegal player %d", pnum);

View file

@ -14,11 +14,11 @@ void plrmsg_delay(BOOL delay)
static DWORD plrmsg_ticks;
if (delay) {
plrmsg_ticks = -GetTickCount();
plrmsg_ticks = -SDL_GetTicks();
return;
}
plrmsg_ticks += GetTickCount();
plrmsg_ticks += SDL_GetTicks();
pMsg = plr_msgs;
for (i = 0; i < PMSG_COUNT; i++, pMsg++)
pMsg->time += plrmsg_ticks;
@ -30,7 +30,7 @@ char *ErrorPlrMsg(const char *pszMsg)
_plrmsg *pMsg = &plr_msgs[plr_msg_slot];
plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1);
pMsg->player = MAX_PLRS;
pMsg->time = GetTickCount();
pMsg->time = SDL_GetTicks();
result = strncpy(pMsg->str, pszMsg, sizeof(pMsg->str));
pMsg->str[sizeof(pMsg->str) - 1] = '\0';
return result;
@ -45,7 +45,7 @@ size_t EventPlrMsg(const char *pszFmt, ...)
pMsg = &plr_msgs[plr_msg_slot];
plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1);
pMsg->player = MAX_PLRS;
pMsg->time = GetTickCount();
pMsg->time = SDL_GetTicks();
vsprintf(pMsg->str, pszFmt, va);
va_end(va);
return strlen(pMsg->str);
@ -56,7 +56,7 @@ void SendPlrMsg(int pnum, const char *pszStr)
_plrmsg *pMsg = &plr_msgs[plr_msg_slot];
plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1);
pMsg->player = pnum;
pMsg->time = GetTickCount();
pMsg->time = SDL_GetTicks();
strlen(plr[pnum]._pName); /* these are used in debug */
strlen(pszStr);
sprintf(pMsg->str, "%s (lvl %d): %s", plr[pnum]._pName, plr[pnum]._pLevel, pszStr);
@ -66,7 +66,7 @@ void ClearPlrMsg()
{
int i;
_plrmsg *pMsg = plr_msgs;
DWORD tick = GetTickCount();
DWORD tick = SDL_GetTicks();
for (i = 0; i < PMSG_COUNT; i++, pMsg++) {
if ((int)(tick - pMsg->time) > 10000)

View file

@ -1048,7 +1048,7 @@ void ScrollView()
void EnableFrameCount()
{
frameflag = frameflag == 0;
framestart = GetTickCount();
framestart = SDL_GetTicks();
}
/**
@ -1062,7 +1062,7 @@ static void DrawFPS()
if (frameflag && gbActive && pPanelText) {
frameend++;
tc = GetTickCount();
tc = SDL_GetTicks();
frames = tc - framestart;
if (tc - framestart >= 1000) {
framestart = tc;

View file

@ -73,7 +73,7 @@ void InitStores()
void PentSpn2Spin()
{
DWORD ticks = GetTickCount();
DWORD ticks = SDL_GetTicks();
if (ticks - PentSpn2Tick > 50) {
PentSpn2Frame = (PentSpn2Frame & 7) + 1;
PentSpn2Tick = ticks;
@ -84,7 +84,7 @@ void SetupTownStores()
{
int i, l;
SetRndSeed(glSeedTbl[currlevel] * GetTickCount());
SetRndSeed(glSeedTbl[currlevel] * SDL_GetTicks());
if (gbMaxPlayers == 1) {
l = 0;
for (i = 0; i < NUMLEVELS; i++) {

View file

@ -12,7 +12,7 @@ int tmsg_get(BYTE *pbMsg, DWORD dwMaxLen)
if (!sgpTimedMsgHead)
return 0;
if ((int)(sgpTimedMsgHead->hdr.dwTime - GetTickCount()) >= 0)
if ((int)(sgpTimedMsgHead->hdr.dwTime - SDL_GetTicks()) >= 0)
return 0;
head = sgpTimedMsgHead;
sgpTimedMsgHead = head->hdr.pNext;
@ -29,7 +29,7 @@ void tmsg_add(BYTE *pbMsg, BYTE bLen)
TMsg *msg = (TMsg *)DiabloAllocPtr(bLen + sizeof(*msg));
msg->hdr.pNext = NULL;
msg->hdr.dwTime = GetTickCount() + 500;
msg->hdr.dwTime = SDL_GetTicks() + 500;
msg->hdr.bLen = bLen;
memcpy(msg->body, pbMsg, bLen);
for (tail = &sgpTimedMsgHead; *tail; tail = &(*tail)->hdr.pNext) {

View file

@ -18,7 +18,7 @@ void track_process()
return;
if (cursmx != plr[myplr]._ptargx || cursmy != plr[myplr]._ptargy) {
DWORD tick = GetTickCount();
DWORD tick = SDL_GetTicks();
if ((int)(tick - sgdwLastWalk) >= 300) {
sgdwLastWalk = tick;
NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy);
@ -36,7 +36,7 @@ void track_repeat_walk(BOOL rep)
sgbIsWalking = rep;
if (rep) {
sgbIsScrolling = 0;
sgdwLastWalk = GetTickCount() - 50;
sgdwLastWalk = SDL_GetTicks() - 50;
NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy);
} else if (sgbIsScrolling) {
sgbIsScrolling = 0;

View file

@ -59,4 +59,20 @@ inline bool ResizeFile(const char *path, std::uint32_t size)
#endif
}
inline void RemoveFile(char *lpFileName)
{
char name[DVL_MAX_PATH];
TranslateFileName(name, sizeof(name), lpFileName);
FILE *f = fopen(name, "r+");
if (f) {
fclose(f);
remove(name);
f = NULL;
SDL_Log("Removed file: %s", name);
} else {
SDL_Log("Failed to remove file: %s", name);
}
}
} // namespace dvl

View file

@ -87,8 +87,6 @@ typedef struct tagMSG {
//
typedef void *LPSECURITY_ATTRIBUTES;
DWORD GetTickCount();
HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINBOOL bManualReset, WINBOOL bInitialState,
LPCSTR lpName);
BOOL CloseEvent(HANDLE event);
@ -107,24 +105,10 @@ WINBOOL TranslateMessage(const MSG *lpMsg);
LRESULT DispatchMessageA(const MSG *lpMsg);
WINBOOL PostMessageA(UINT Msg, WPARAM wParam, LPARAM lParam);
bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight);
uintptr_t DVL_beginthreadex(void *_Security, unsigned _StackSize, unsigned(*_StartAddress)(void *),
void *_ArgList, unsigned _InitFlag, unsigned *_ThrdAddr);
DWORD GetCurrentThreadId();
WINBOOL SetThreadPriority(HANDLE hThread, int nPriority);
void Sleep(DWORD dwMilliseconds);
int wvsprintfA(LPSTR dest, LPCSTR format, va_list arglist);
int _strcmpi(const char *_Str1, const char *_Str2);
//
// File I/O
//
typedef void *LPOVERLAPPED;
WINBOOL DeleteFileA(LPCSTR lpFileName);
//
// Total fakes

View file

@ -20,9 +20,9 @@
#define DispatchMessage DispatchMessageA
#define PostMessage PostMessageA
#define THREAD_PRIORITY_HIGHEST 2
#define _strcmpi(a, b) strcasecmp(a, b)
#define wvsprintf wvsprintfA
#define THREAD_PRIORITY_HIGHEST 2
//
// File I/O

View file

@ -2,6 +2,7 @@
namespace dvl {
bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight);
void UiErrorOkDialog(const char *text, const char *caption, bool error = true);
} // namespace dvl

View file

@ -4,7 +4,7 @@
#include "controls/menu_controls.h"
#include "devilution.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include "DiabloUI/diabloui.h"
#include "DiabloUI/credits_lines.h"

View file

@ -1,5 +1,5 @@
#include "devilution.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include "stubs.h"
#include "utf8.h"
#include <string>

View file

@ -34,7 +34,7 @@ void mainmenu_Esc()
void mainmenu_restart_repintro()
{
dwAttractTicks = GetTickCount() + mainmenu_attract_time_out * 1000;
dwAttractTicks = SDL_GetTicks() + mainmenu_attract_time_out * 1000;
}
void mainmenu_Load(char *name, void (*fnSound)(char *file))
@ -67,7 +67,7 @@ BOOL UiMainMenuDialog(char *name, int *pdwResult, void (*fnSound)(char *file), i
while (MainMenuResult == 0) {
UiPollAndRender();
if (!gbSpawned && GetTickCount() >= dwAttractTicks) {
if (!gbSpawned && SDL_GetTicks() >= dwAttractTicks) {
MainMenuResult = MAINMENU_ATTRACT_MODE;
}
}

View file

@ -1,5 +1,5 @@
#include "devilution.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include "DiabloUI/button.h"
#include "DiabloUI/diabloui.h"

View file

@ -448,7 +448,7 @@ void AttrIncBtnSnap(MoveDirectionY dir)
if (chrbtnactive && plr[myplr]._pStatPts <= 0)
return;
DWORD ticks = GetTickCount();
DWORD ticks = SDL_GetTicks();
if (ticks - invmove < repeatRate) {
return;
}
@ -485,7 +485,7 @@ void AttrIncBtnSnap(MoveDirectionY dir)
// small inventory squares are 29x29 (roughly)
void InvMove(MoveDirection dir)
{
DWORD ticks = GetTickCount();
DWORD ticks = SDL_GetTicks();
if (ticks - invmove < repeatRate) {
return;
}
@ -654,7 +654,7 @@ void HotSpellMove(MoveDirection dir)
int x = 0;
int y = 0;
DWORD ticks = GetTickCount();
DWORD ticks = SDL_GetTicks();
if (ticks - invmove < repeatRate) {
return;
}
@ -721,7 +721,7 @@ void HotSpellMove(MoveDirection dir)
void SpellBookMove(MoveDirection dir)
{
DWORD ticks = GetTickCount();
DWORD ticks = SDL_GetTicks();
if (ticks - invmove < repeatRate) {
return;
}

View file

@ -1,5 +1,5 @@
#ifndef USE_SDL1
#include "miniwin/ddraw.h"
#include "display.h"
#include "touch.h"
#include "../../defs.h"
#include <math.h>

View file

@ -1,12 +1,6 @@
#include "devilution.h"
#include "miniwin/ddraw.h"
#include "stubs.h"
#include <SDL.h>
#include <string>
#include "controls/controller.h"
#include "display.h"
#include "DiabloUI/diabloui.h"
#include "DiabloUI/dialogs.h"
#include "controls/controller.h"
#if defined(USE_SDL1) && defined(RETROFW)
#include <unistd.h>
@ -29,43 +23,7 @@
namespace dvl {
int wvsprintfA(LPSTR dest, LPCSTR format, va_list arglist)
{
return vsnprintf(dest, 256, format, arglist);
}
int _strcmpi(const char *_Str1, const char *_Str2)
{
return strcasecmp(_Str1, _Str2);
}
DWORD GetTickCount()
{
return SDL_GetTicks();
}
void Sleep(DWORD dwMilliseconds)
{
SDL_Delay(dwMilliseconds);
}
WINBOOL DeleteFileA(LPCSTR lpFileName)
{
char name[DVL_MAX_PATH];
TranslateFileName(name, sizeof(name), lpFileName);
FILE *f = fopen(name, "r+");
if (f) {
fclose(f);
remove(name);
f = NULL;
SDL_Log("Removed file: %s", name);
} else {
SDL_Log("Failed to remove file: %s", name);
}
return true;
}
extern SDL_Surface *renderer_texture_surface; // defined in dx.cpp
namespace {
@ -181,4 +139,36 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
return window != NULL;
}
SDL_Surface *GetOutputSurface()
{
#ifdef USE_SDL1
return SDL_GetVideoSurface();
#else
if (renderer)
return renderer_texture_surface;
return SDL_GetWindowSurface(window);
#endif
}
bool OutputRequiresScaling()
{
#ifdef USE_SDL1
return SCREEN_WIDTH != GetOutputSurface()->w || SCREEN_HEIGHT != GetOutputSurface()->h;
#else // SDL2, scaling handled by renderer.
return false;
#endif
}
void ScaleOutputRect(SDL_Rect *rect)
{
if (!OutputRequiresScaling())
return;
const auto *surface = GetOutputSurface();
rect->x = rect->x * surface->w / SCREEN_WIDTH;
rect->y = rect->y * surface->h / SCREEN_HEIGHT;
rect->w = rect->w * surface->w / SCREEN_WIDTH;
rect->h = rect->h * surface->h / SCREEN_HEIGHT;
}
} // namespace dvl

View file

@ -1,6 +1,6 @@
#include "diablo.h"
#include "../3rdParty/Storm/Source/storm.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include <SDL.h>
namespace dvl {

View file

@ -1,38 +0,0 @@
#include "miniwin/ddraw.h"
namespace dvl {
extern SDL_Surface *renderer_texture_surface; // defined in dx.cpp
SDL_Surface *GetOutputSurface()
{
#ifdef USE_SDL1
return SDL_GetVideoSurface();
#else
if (renderer)
return renderer_texture_surface;
return SDL_GetWindowSurface(window);
#endif
}
bool OutputRequiresScaling()
{
#ifdef USE_SDL1
return SCREEN_WIDTH != GetOutputSurface()->w || SCREEN_HEIGHT != GetOutputSurface()->h;
#else // SDL2, scaling handled by renderer.
return false;
#endif
}
void ScaleOutputRect(SDL_Rect *rect)
{
if (!OutputRequiresScaling())
return;
const auto *surface = GetOutputSurface();
rect->x = rect->x * surface->w / SCREEN_WIDTH;
rect->y = rect->y * surface->h / SCREEN_HEIGHT;
rect->w = rect->w * surface->w / SCREEN_WIDTH;
rect->h = rect->h * surface->h / SCREEN_HEIGHT;
}
} // namespace dvl

View file

@ -3,13 +3,13 @@
#include <SDL.h>
#include "devilution.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include "stubs.h"
#include "controls/controller_motion.h"
#include "controls/game_controls.h"
#include "controls/plrctrls.h"
#include "controls/touch.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include "controls/controller.h"
#ifdef __SWITCH__

View file

@ -1,6 +1,6 @@
#include <switch.h>
#include <SDL.h>
#include "miniwin/ddraw.h"
#include "display.h"
#include "platform/switch/docking.h"
namespace dvl {

View file

@ -57,7 +57,7 @@ void snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
return;
}
tc = GetTickCount();
tc = SDL_GetTicks();
if (tc - pSnd->start_tc < 80) {
return;
}
@ -84,7 +84,7 @@ TSnd *sound_file_load(char *path)
pSnd = (TSnd *)DiabloAllocPtr(sizeof(TSnd));
memset(pSnd, 0, sizeof(TSnd));
pSnd->sound_path = path;
pSnd->start_tc = GetTickCount() - 81;
pSnd->start_tc = SDL_GetTicks() - 81;
dwBytes = SFileGetFileSize(file, NULL);
wave_file = DiabloAllocPtr(dwBytes);

View file

@ -4,7 +4,7 @@
#include <queue>
#endif
#include "miniwin/ddraw.h"
#include "display.h"
#include "stubs.h"
#include <Radon.hpp>
#include <SDL.h>
@ -225,7 +225,7 @@ BOOL SBmpLoadImage(const char *pszFileName, SDL_Color *pPalette, BYTE *pBuffer,
pszFileName = strchr(pszFileName, 46);
// omit all types except PCX
if (!pszFileName || _strcmpi(pszFileName, ".pcx")) {
if (!pszFileName || strcasecmp(pszFileName, ".pcx")) {
return false;
}

View file

@ -1,7 +1,7 @@
#include <SDL.h>
#include "devilution.h"
#include "miniwin/ddraw.h"
#include "display.h"
#include "stubs.h"
namespace dvl {

View file

@ -9,7 +9,7 @@
#define DEVILUTION_END_NAMESPACE }
#include "miniwin.h"
#include "ssound.h"
#include "soundsample.h"
#include "ui_fwd.h"
DEVILUTION_BEGIN_NAMESPACE