Browse Source

🎨 Format source

pull/1310/head
Anders Jenbo 5 years ago
parent
commit
a2656637e4
  1. 10
      DiabloUI/diabloui.h
  2. 28
      Source/engine.h
  3. 6
      Source/init.cpp
  4. 2
      Source/lighting.cpp
  5. 1
      Source/mpqapi.h
  6. 2
      Source/pfile.cpp
  7. 7
      Source/render.cpp
  8. 5
      SourceS/file_util.h
  9. 51
      SourceS/paths.cpp
  10. 8
      SourceS/sdl_compat.h
  11. 1
      SourceS/storm_full.h
  12. 25
      SourceT/appfat_test.cpp
  13. 33
      SourceT/automap_test.cpp
  14. 6
      SourceT/codec_test.cpp
  15. 6
      SourceT/control_test.cpp
  16. 3
      SourceT/cursor_test.cpp
  17. 6
      SourceT/dead_test.cpp
  18. 6
      SourceT/doom_test.cpp
  19. 10
      SourceT/drlg_l1_test.cpp
  20. 3
      SourceT/drlg_l2_test.cpp
  21. 9
      SourceT/drlg_l3_test.cpp
  22. 6
      SourceT/drlg_l4_test.cpp
  23. 131
      SourceT/pack_test.cpp
  24. 104
      SourceT/player_test.cpp
  25. 3
      SourceX/DiabloUI/diabloui.cpp
  26. 14
      SourceX/DiabloUI/fonts.cpp
  27. 8
      SourceX/DiabloUI/scrollbar.cpp
  28. 2
      SourceX/DiabloUI/selconn.h
  29. 2
      SourceX/DiabloUI/selgame.h
  30. 3
      SourceX/DiabloUI/selhero.cpp
  31. 2
      SourceX/DiabloUI/selok.h
  32. 2
      SourceX/DiabloUI/selyesno.h
  33. 38
      SourceX/DiabloUI/support_lines.cpp
  34. 78
      SourceX/controls/axis_direction.cpp
  35. 14
      SourceX/controls/devices/game_controller.cpp
  36. 40
      SourceX/controls/devices/joystick.cpp
  37. 64
      SourceX/controls/game_controls.cpp
  38. 3
      SourceX/controls/modifier_hints.cpp
  39. 6
      SourceX/controls/plrctrls.cpp
  40. 2
      SourceX/controls/remap_keyboard.h
  41. 10
      SourceX/dvlnet/frame_queue.cpp
  42. 6
      SourceX/dvlnet/loopback.cpp
  43. 6
      SourceX/dvlnet/loopback.h
  44. 2
      SourceX/dvlnet/tcp_server.cpp
  45. 12
      SourceX/dx.cpp
  46. 4
      SourceX/main.cpp
  47. 5
      SourceX/platform/ctr/keyboard.cpp
  48. 2
      SourceX/platform/ctr/keyboard.h
  49. 36
      SourceX/platform/ctr/system.cpp
  50. 16
      SourceX/platform/switch/docking.cpp
  51. 2
      SourceX/soundsample.cpp
  52. 2
      SourceX/thread.cpp

10
DiabloUI/diabloui.h

@ -9,12 +9,12 @@ void UiTitleDialog();
void UiSetSpawned(BOOL bSpawned);
void UiInitialize();
BOOL UiValidPlayerName(const char *name); /* check */
void UiSelHeroMultDialog(BOOL(*fninfo)(BOOL(*fninfofunc)(_uiheroinfo *)), BOOL(*fncreate)(_uiheroinfo *), BOOL(*fnremove)(_uiheroinfo *), void(*fnstats)(unsigned int, _uidefaultstats *), int *dlgresult, BOOL *hero_is_created, char (* name)[16]);
void UiSelHeroSingDialog(BOOL(*fninfo)(BOOL(*fninfofunc)(_uiheroinfo *)), BOOL(*fncreate)(_uiheroinfo *), BOOL(*fnremove)(_uiheroinfo *), void(*fnstats)(unsigned int, _uidefaultstats *), int *dlgresult, char (* name)[16], int *difficulty);
void UiSelHeroMultDialog(BOOL (*fninfo)(BOOL (*fninfofunc)(_uiheroinfo *)), BOOL (*fncreate)(_uiheroinfo *), BOOL (*fnremove)(_uiheroinfo *), void (*fnstats)(unsigned int, _uidefaultstats *), int *dlgresult, BOOL *hero_is_created, char (*name)[16]);
void UiSelHeroSingDialog(BOOL (*fninfo)(BOOL (*fninfofunc)(_uiheroinfo *)), BOOL (*fncreate)(_uiheroinfo *), BOOL (*fnremove)(_uiheroinfo *), void (*fnstats)(unsigned int, _uidefaultstats *), int *dlgresult, char (*name)[16], int *difficulty);
BOOL UiCreditsDialog();
BOOL UiSupportDialog();
BOOL UiMainMenuDialog(const char *name, int *pdwResult, void(*fnSound)(const char *file), int attractTimeOut);
BOOL UiProgressDialog(const char *msg, int enable, int(*fnfunc)(), int rate);
BOOL UiMainMenuDialog(const char *name, int *pdwResult, void (*fnSound)(const char *file), int attractTimeOut);
BOOL UiProgressDialog(const char *msg, int enable, int (*fnfunc)(), int rate);
const char **UiProfileGetString();
void UiProfileCallback();
void UiProfileDraw();
@ -29,6 +29,6 @@ int UiSelectGame(int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_in
int UiSelectProvider(int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, _SNETUIDATA *ui_info, _SNETVERSIONDATA *file_info, int *type);
BOOL UiCreatePlayerDescription(_uiheroinfo *info, Uint32 mode, char (*desc)[128]);
void UiSetupPlayerInfo(char *infostr, _uiheroinfo *pInfo, Uint32 type);
}
} // namespace dvl
#endif /* __DIABLOUI_H__ */

28
Source/engine.h

@ -105,27 +105,43 @@ struct CelOutputBuffer {
*
* Only use this if the buffer owns its data.
*/
void Free() {
void Free()
{
SDL_FreeSurface(this->surface);
this->surface = NULL;
}
int w() const { return region.w; }
int h() const { return region.h; }
int w() const
{
return region.w;
}
int h() const
{
return region.h;
}
BYTE *at(int x, int y) const
{
return static_cast<BYTE *>(surface->pixels) + region.x + x + surface->pitch * (region.y + y);
}
BYTE *begin() const { return at(0, 0); }
BYTE *end() const { return at(0, region.h); }
BYTE *begin() const
{
return at(0, 0);
}
BYTE *end() const
{
return at(0, region.h);
}
/**
* @brief Line width of the raw underlying byte buffer.
* May be wider than its logical width (for power-of-2 alignment).
*/
int pitch() { return surface->pitch; }
int pitch()
{
return surface->pitch;
}
bool in_bounds(Sint16 x, Sint16 y) const
{

6
Source/init.cpp

@ -150,7 +150,8 @@ void init_archives()
paths.reserve(5);
paths.push_back(GetBasePath());
paths.push_back(GetPrefPath());
if (paths[0] == paths[1]) paths.pop_back();
if (paths[0] == paths[1])
paths.pop_back();
#ifdef __linux__
paths.push_back("/usr/share/diasurgical/devilutionx/");
@ -193,8 +194,7 @@ void init_archives()
hfopt1_mpq = init_test_access(paths, "hfopt1.mpq", "DiabloInstall", 8600, FS_PC);
hfopt2_mpq = init_test_access(paths, "hfopt2.mpq", "DiabloInstall", 8610, FS_PC);
if (gbIsHellfire && (hfmonk_mpq == NULL || hfmusic_mpq == NULL || hfvoice_mpq == NULL))
{
if (gbIsHellfire && (hfmonk_mpq == NULL || hfmusic_mpq == NULL || hfvoice_mpq == NULL)) {
UiErrorOkDialog("Some Hellfire MPQs are missing", "Not all Hellfire MPQs were found.\nPlease copy all the hf*.mpq files.");
app_fatal(NULL);
}

2
Source/lighting.cpp

@ -1175,7 +1175,7 @@ void InitVision()
int AddVision(int x, int y, int r, BOOL mine)
{
int vid = -1; // BUGFIX: if numvision >= MAXVISION behavior is undefined (fixed)
int vid = -1; // BUGFIX: if numvision >= MAXVISION behavior is undefined (fixed)
if (numvision < MAXVISION) {
VisionList[numvision]._lx = x;

1
Source/mpqapi.h

@ -40,7 +40,6 @@ typedef struct _BLOCKENTRY {
Uint32 flags;
} _BLOCKENTRY;
void mpqapi_remove_hash_entry(const char *pszName);
void mpqapi_remove_hash_entries(BOOL (*fnGetName)(DWORD, char *));
BOOL mpqapi_write_file(const char *pszName, const BYTE *pbData, DWORD dwLen);

2
Source/pfile.cpp

@ -184,7 +184,7 @@ void pfile_write_hero()
if (pfile_open_archive(save_num)) {
PackPlayer(&pkplr, myplr, !gbIsMultiplayer);
pfile_encode_hero(&pkplr);
if(!gbVanilla)
if (!gbVanilla)
SaveHotkeys();
pfile_flush(!gbIsMultiplayer, save_num);
}

7
Source/render.cpp

@ -395,8 +395,8 @@ inline void DoRenderLine(BYTE *dst, BYTE *src, int n, BYTE *tbl, DWORD mask)
assert(n != 0 && n <= sizeof(DWORD) * CHAR_BIT);
mask &= DWORD(-1) << ((sizeof(DWORD) * CHAR_BIT) - n);
if (sgOptions.Graphics.bBlendedTransparancy) { // Blended transparancy
if (light_table_index == lightmax) { // Complete darkness
if (sgOptions.Graphics.bBlendedTransparancy) { // Blended transparancy
if (light_table_index == lightmax) { // Complete darkness
for (int i = 0; i < n; i++, mask <<= 1) {
if (mask & 0x80000000)
dst[i] = 0;
@ -431,7 +431,8 @@ inline void DoRenderLine(BYTE *dst, BYTE *src, int n, BYTE *tbl, DWORD mask)
}
DVL_ATTRIBUTE_ALWAYS_INLINE
inline void RenderLine(BYTE *dst_begin, BYTE *dst_end, BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD mask) {
inline void RenderLine(BYTE *dst_begin, BYTE *dst_end, BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD mask)
{
#ifdef NO_OVERDRAW
if (*dst >= dst_begin && *dst <= dst_end)
#endif

5
SourceS/file_util.h

@ -32,7 +32,8 @@ inline bool FileExists(const char *path)
return ::access(path, F_OK) == 0;
#else
FILE *file = std::fopen(path, "rb");
if (file == NULL) return false;
if (file == NULL)
return false;
std::fclose(file);
return true;
#endif
@ -43,7 +44,7 @@ inline bool GetFileSize(const char *path, std::uintmax_t *size)
#if defined(_WIN64) || defined(_WIN32)
WIN32_FILE_ATTRIBUTE_DATA attr;
int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
wchar_t* path_utf16 = new wchar_t[path_utf16_size];
wchar_t *path_utf16 = new wchar_t[path_utf16_size];
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) {
delete[] path_utf16;
return false;

51
SourceS/paths.cpp

@ -24,42 +24,47 @@ std::string *configPath = NULL;
std::string *ttfPath = NULL;
std::string *ttfName = NULL;
void AddTrailingSlash(std::string *path) {
void AddTrailingSlash(std::string *path)
{
#ifdef _WIN32
if (!path->empty() && path->back() != '\\')
*path += '\\';
if (!path->empty() && path->back() != '\\')
*path += '\\';
#else
if (!path->empty() && path->back() != '/')
*path += '/';
if (!path->empty() && path->back() != '/')
*path += '/';
#endif
}
std::string *FromSDL(char *s) {
std::string *result = new std::string(s != NULL ? s : "");
if (s != NULL) {
SDL_free(s);
} else {
SDL_Log("%s", SDL_GetError());
SDL_ClearError();
}
return result;
std::string *FromSDL(char *s)
{
std::string *result = new std::string(s != NULL ? s : "");
if (s != NULL) {
SDL_free(s);
} else {
SDL_Log("%s", SDL_GetError());
SDL_ClearError();
}
return result;
}
} // namespace
const std::string &GetBasePath()
{
#ifdef __vita__
if (basePath == NULL) basePath = new std::string(GetPrefPath());
#else
if (basePath == NULL) basePath = FromSDL(SDL_GetBasePath());
#endif
#ifdef __vita__
if (basePath == NULL)
basePath = new std::string(GetPrefPath());
#else
if (basePath == NULL)
basePath = FromSDL(SDL_GetBasePath());
#endif
return *basePath;
}
const std::string &GetPrefPath()
{
if (prefPath == NULL) prefPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution"));
if (prefPath == NULL)
prefPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution"));
return *prefPath;
}
@ -86,14 +91,16 @@ const std::string &GetTtfName()
void SetBasePath(const char *path)
{
if (basePath == NULL) basePath = new std::string;
if (basePath == NULL)
basePath = new std::string;
*basePath = path;
AddTrailingSlash(basePath);
}
void SetPrefPath(const char *path)
{
if (prefPath == NULL) prefPath = new std::string;
if (prefPath == NULL)
prefPath = new std::string;
*prefPath = path;
AddTrailingSlash(prefPath);
}

8
SourceS/sdl_compat.h

@ -73,10 +73,10 @@ inline int SDLC_SetSurfaceAndPaletteColors(SDL_Surface *surface, SDL_Palette *pa
if (colors != (palette->colors + firstcolor))
SDL_memcpy(palette->colors + firstcolor, colors, ncolors * sizeof(*colors));
#if SDL1_VIDEO_MODE_BPP == 8
// When the video surface is 8bit, we need to set the output pallet as well.
SDL_SetColors(SDL_GetVideoSurface(), colors, firstcolor, ncolors);
#endif
#if SDL1_VIDEO_MODE_BPP == 8
// When the video surface is 8bit, we need to set the output pallet as well.
SDL_SetColors(SDL_GetVideoSurface(), colors, firstcolor, ncolors);
#endif
// In SDL1, the surface always has its own distinct palette, so we need to
// update it as well.
return SDL_SetPalette(surface, SDL_LOGPAL, colors, firstcolor, ncolors) - 1;

1
SourceS/storm_full.h

@ -4,6 +4,5 @@ namespace dvl {
extern "C" {
extern DWORD nLastError;
}
} // namespace dvl

25
SourceT/appfat_test.cpp

@ -1,22 +1,27 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Appfat, app_fatal) {
EXPECT_EXIT(dvl::app_fatal("test"), ::testing::ExitedWithCode(1), "test");
TEST(Appfat, app_fatal)
{
EXPECT_EXIT(dvl::app_fatal("test"), ::testing::ExitedWithCode(1), "test");
}
TEST(Appfat, ErrDlg) {
EXPECT_EXIT(dvl::ErrDlg("Title", "Unknown error", "appfat.cpp", 7), ::testing::ExitedWithCode(1), "Unknown error\n\nThe error occurred at: appfat.cpp line 7");
TEST(Appfat, ErrDlg)
{
EXPECT_EXIT(dvl::ErrDlg("Title", "Unknown error", "appfat.cpp", 7), ::testing::ExitedWithCode(1), "Unknown error\n\nThe error occurred at: appfat.cpp line 7");
}
TEST(Appfat, FileErrDlg) {
EXPECT_EXIT(dvl::FileErrDlg("devilution/image.cl2"), ::testing::ExitedWithCode(1), "devilution/image.cl2");
TEST(Appfat, FileErrDlg)
{
EXPECT_EXIT(dvl::FileErrDlg("devilution/image.cl2"), ::testing::ExitedWithCode(1), "devilution/image.cl2");
}
TEST(Appfat, InsertCDDlg) {
EXPECT_EXIT(dvl::InsertCDDlg(), ::testing::ExitedWithCode(1), "diabdat.mpq");
TEST(Appfat, InsertCDDlg)
{
EXPECT_EXIT(dvl::InsertCDDlg(), ::testing::ExitedWithCode(1), "diabdat.mpq");
}
TEST(Appfat, DirErrorDlg) {
EXPECT_EXIT(dvl::DirErrorDlg("/"), ::testing::ExitedWithCode(1), "Unable to write to location:\n/");
TEST(Appfat, DirErrorDlg)
{
EXPECT_EXIT(dvl::DirErrorDlg("/"), ::testing::ExitedWithCode(1), "Unable to write to location:\n/");
}

33
SourceT/automap_test.cpp

@ -1,7 +1,8 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Automap, InitAutomap) {
TEST(Automap, InitAutomap)
{
dvl::InitAutomapOnce();
EXPECT_EQ(dvl::automapflag, false);
EXPECT_EQ(dvl::AutoMapScale, 50);
@ -12,14 +13,16 @@ TEST(Automap, InitAutomap) {
EXPECT_EQ(dvl::AmLine4, 2);
}
TEST(Automap, StartAutomap) {
TEST(Automap, StartAutomap)
{
dvl::StartAutomap();
EXPECT_EQ(dvl::AutoMapXOfs, 0);
EXPECT_EQ(dvl::AutoMapYOfs, 0);
EXPECT_EQ(dvl::automapflag, true);
}
TEST(Automap, AutomapUp) {
TEST(Automap, AutomapUp)
{
dvl::AutoMapXOfs = 1;
dvl::AutoMapYOfs = 1;
dvl::AutomapUp();
@ -27,7 +30,8 @@ TEST(Automap, AutomapUp) {
EXPECT_EQ(dvl::AutoMapYOfs, 0);
}
TEST(Automap, AutomapDown) {
TEST(Automap, AutomapDown)
{
dvl::AutoMapXOfs = 1;
dvl::AutoMapYOfs = 1;
dvl::AutomapDown();
@ -35,7 +39,8 @@ TEST(Automap, AutomapDown) {
EXPECT_EQ(dvl::AutoMapYOfs, 2);
}
TEST(Automap, AutomapLeft) {
TEST(Automap, AutomapLeft)
{
dvl::AutoMapXOfs = 1;
dvl::AutoMapYOfs = 1;
dvl::AutomapLeft();
@ -43,7 +48,8 @@ TEST(Automap, AutomapLeft) {
EXPECT_EQ(dvl::AutoMapYOfs, 2);
}
TEST(Automap, AutomapRight) {
TEST(Automap, AutomapRight)
{
dvl::AutoMapXOfs = 1;
dvl::AutoMapYOfs = 1;
dvl::AutomapRight();
@ -51,7 +57,8 @@ TEST(Automap, AutomapRight) {
EXPECT_EQ(dvl::AutoMapYOfs, 0);
}
TEST(Automap, AutomapZoomIn) {
TEST(Automap, AutomapZoomIn)
{
dvl::AutoMapScale = 50;
dvl::AutomapZoomIn();
EXPECT_EQ(dvl::AutoMapScale, 55);
@ -62,7 +69,8 @@ TEST(Automap, AutomapZoomIn) {
EXPECT_EQ(dvl::AmLine4, 2);
}
TEST(Automap, AutomapZoomIn_Max) {
TEST(Automap, AutomapZoomIn_Max)
{
dvl::AutoMapScale = 195;
dvl::AutomapZoomIn();
dvl::AutomapZoomIn();
@ -74,7 +82,8 @@ TEST(Automap, AutomapZoomIn_Max) {
EXPECT_EQ(dvl::AmLine4, 8);
}
TEST(Automap, AutomapZoomOut) {
TEST(Automap, AutomapZoomOut)
{
dvl::AutoMapScale = 200;
dvl::AutomapZoomOut();
EXPECT_EQ(dvl::AutoMapScale, 195);
@ -85,7 +94,8 @@ TEST(Automap, AutomapZoomOut) {
EXPECT_EQ(dvl::AmLine4, 7);
}
TEST(Automap, AutomapZoomOut_Min) {
TEST(Automap, AutomapZoomOut_Min)
{
dvl::AutoMapScale = 55;
dvl::AutomapZoomOut();
dvl::AutomapZoomOut();
@ -97,7 +107,8 @@ TEST(Automap, AutomapZoomOut_Min) {
EXPECT_EQ(dvl::AmLine4, 2);
}
TEST(Automap, AutomapZoomReset) {
TEST(Automap, AutomapZoomReset)
{
dvl::AutoMapScale = 50;
dvl::AutoMapXOfs = 1;
dvl::AutoMapYOfs = 1;

6
SourceT/codec_test.cpp

@ -1,10 +1,12 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Codec, codec_get_encoded_len) {
TEST(Codec, codec_get_encoded_len)
{
EXPECT_EQ(dvl::codec_get_encoded_len(50), 72);
}
TEST(Codec, codec_get_encoded_len_eq) {
TEST(Codec, codec_get_encoded_len_eq)
{
EXPECT_EQ(dvl::codec_get_encoded_len(128), 136);
}

6
SourceT/control_test.cpp

@ -1,7 +1,8 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Control, SetSpell) {
TEST(Control, SetSpell)
{
dvl::pnumlines = 1;
dvl::pinfoflag = true;
dvl::pSpell = dvl::SPL_FIREBOLT;
@ -15,7 +16,8 @@ TEST(Control, SetSpell) {
EXPECT_EQ(dvl::force_redraw, 255);
}
TEST(Control, ClearPanel) {
TEST(Control, ClearPanel)
{
dvl::pnumlines = 1;
dvl::pinfoflag = true;
dvl::ClearPanel();

3
SourceT/cursor_test.cpp

@ -1,7 +1,8 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Cursor, SetCursor) {
TEST(Cursor, SetCursor)
{
int i = dvl::ICURS_SPIKED_CLUB + dvl::CURSOR_FIRSTITEM;
dvl::SetCursor_(i);
EXPECT_EQ(dvl::pcurs, i);

6
SourceT/dead_test.cpp

@ -1,12 +1,14 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Dead, AddDead) {
TEST(Dead, AddDead)
{
dvl::AddDead(21, 48, 8, dvl::DIR_W);
EXPECT_EQ(dvl::dDead[21][48], 8 + (dvl::DIR_W << 5));
}
TEST(Dead, AddDead_OOB) {
TEST(Dead, AddDead_OOB)
{
dvl::AddDead(21, 48, MAXDEAD + 1, dvl::DIR_W);
EXPECT_EQ(dvl::dDead[21][48], 0 + (dvl::DIR_W << 5));
}

6
SourceT/doom_test.cpp

@ -1,12 +1,14 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Doom, doom_get_frame_from_time) {
TEST(Doom, doom_get_frame_from_time)
{
dvl::DoomQuestState = 1200 * 8 + 548;
EXPECT_EQ(dvl::doom_get_frame_from_time(), 8);
}
TEST(Doom, doom_get_frame_from_time_max) {
TEST(Doom, doom_get_frame_from_time_max)
{
dvl::DoomQuestState = 1200 * 30 + 1;
EXPECT_EQ(dvl::doom_get_frame_from_time(), 31);
}

10
SourceT/drlg_l1_test.cpp

@ -1,23 +1,25 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Drlg_l1, DRLG_Init_Globals_4flag) {
TEST(Drlg_l1, DRLG_Init_Globals_4flag)
{
dvl::lightflag = false;
dvl::light4flag = true;
dvl::DRLG_Init_Globals();
EXPECT_EQ(dvl::dLight[0][0], 3);
}
TEST(Drlg_l1, DRLG_Init_Globals_noflag) {
TEST(Drlg_l1, DRLG_Init_Globals_noflag)
{
dvl::lightflag = false;
dvl::light4flag = false;
dvl::DRLG_Init_Globals();
EXPECT_EQ(dvl::dLight[0][0], 15);
}
TEST(Drlg_l1, DRLG_Init_Globals) {
TEST(Drlg_l1, DRLG_Init_Globals)
{
dvl::lightflag = true;
dvl::DRLG_Init_Globals();
EXPECT_EQ(dvl::dLight[0][0], 0);
}

3
SourceT/drlg_l2_test.cpp

@ -1,7 +1,8 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Drlg_l2, InitDungeon) {
TEST(Drlg_l2, InitDungeon)
{
dvl::InitDungeon();
EXPECT_EQ(dvl::predungeon[0][0], 32);
EXPECT_EQ(dvl::dflags[0][0], 0);

9
SourceT/drlg_l3_test.cpp

@ -1,7 +1,8 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Drlg_l3, AddFenceDoors_x) {
TEST(Drlg_l3, AddFenceDoors_x)
{
memset(dvl::dungeon, 0, sizeof(dvl::dungeon));
dvl::dungeon[5][5] = 7;
dvl::dungeon[5 - 1][5] = 130;
@ -10,7 +11,8 @@ TEST(Drlg_l3, AddFenceDoors_x) {
EXPECT_EQ(dvl::dungeon[5][5], 146);
}
TEST(Drlg_l3, AddFenceDoors_y) {
TEST(Drlg_l3, AddFenceDoors_y)
{
memset(dvl::dungeon, 0, sizeof(dvl::dungeon));
dvl::dungeon[5][5] = 7;
dvl::dungeon[5][5 - 1] = 130;
@ -19,7 +21,8 @@ TEST(Drlg_l3, AddFenceDoors_y) {
EXPECT_EQ(dvl::dungeon[5][5], 147);
}
TEST(Drlg_l3, AddFenceDoors_no) {
TEST(Drlg_l3, AddFenceDoors_no)
{
memset(dvl::dungeon, 0, sizeof(dvl::dungeon));
dvl::dungeon[5][5] = 7;
dvl::dungeon[5 - 1][5] = 130;

6
SourceT/drlg_l4_test.cpp

@ -1,14 +1,16 @@
#include <gtest/gtest.h>
#include "all.h"
TEST(Drlg_l4, IsDURWall) {
TEST(Drlg_l4, IsDURWall)
{
EXPECT_EQ(dvl::IsDURWall(25), true);
EXPECT_EQ(dvl::IsDURWall(28), true);
EXPECT_EQ(dvl::IsDURWall(23), true);
EXPECT_EQ(dvl::IsDURWall(20), false);
}
TEST(Drlg_l4, IsDLLWall) {
TEST(Drlg_l4, IsDLLWall)
{
EXPECT_EQ(dvl::IsDLLWall(27), true);
EXPECT_EQ(dvl::IsDLLWall(26), true);
EXPECT_EQ(dvl::IsDLLWall(22), true);

131
SourceT/pack_test.cpp

@ -61,51 +61,50 @@ typedef struct TestItemStruct {
static void CompareItems(const dvl::ItemStruct *item1, const TestItemStruct *item2)
{
ASSERT_STREQ(item1->_iIName, item2->_iIName);
ASSERT_EQ(item1->_itype, item2->_itype);
ASSERT_EQ(item1->_iClass, item2->_iClass);
ASSERT_EQ(item1->_iCurs, item2->_iCurs);
ASSERT_EQ(item1->_iIvalue, item2->_iIvalue);
ASSERT_EQ(item1->_iMinDam, item2->_iMinDam);
ASSERT_EQ(item1->_iMaxDam, item2->_iMaxDam);
ASSERT_EQ(item1->_iAC, item2->_iAC);
ASSERT_EQ(item1->_iFlags, item2->_iFlags);
ASSERT_EQ(item1->_iMiscId, item2->_iMiscId);
ASSERT_EQ(item1->_iSpell, item2->_iSpell);
ASSERT_EQ(item1->_iCharges, item2->_iCharges);
ASSERT_EQ(item1->_iMaxCharges, item2->_iMaxCharges);
ASSERT_EQ(item1->_iDurability, item2->_iDurability);
ASSERT_EQ(item1->_iMaxDur, item2->_iMaxDur);
ASSERT_EQ(item1->_iPLDam, item2->_iPLDam);
ASSERT_EQ(item1->_iPLToHit, item2->_iPLToHit);
ASSERT_EQ(item1->_iPLAC, item2->_iPLAC);
ASSERT_EQ(item1->_iPLStr, item2->_iPLStr);
ASSERT_EQ(item1->_iPLMag, item2->_iPLMag);
ASSERT_EQ(item1->_iPLDex, item2->_iPLDex);
ASSERT_EQ(item1->_iPLVit, item2->_iPLVit);
ASSERT_EQ(item1->_iPLFR, item2->_iPLFR);
ASSERT_EQ(item1->_iPLLR, item2->_iPLLR);
ASSERT_EQ(item1->_iPLMR, item2->_iPLMR);
ASSERT_EQ(item1->_iPLMana, item2->_iPLMana);
ASSERT_EQ(item1->_iPLHP, item2->_iPLHP);
ASSERT_EQ(item1->_iPLDamMod, item2->_iPLDamMod);
ASSERT_EQ(item1->_iPLGetHit, item2->_iPLGetHit);
ASSERT_EQ(item1->_iPLLight, item2->_iPLLight);
ASSERT_EQ(item1->_iSplLvlAdd, item2->_iSplLvlAdd);
ASSERT_EQ(item1->_iUid, item2->_iUid);
ASSERT_EQ(item1->_iFMinDam, item2->_iFMinDam);
ASSERT_EQ(item1->_iFMaxDam, item2->_iFMaxDam);
ASSERT_EQ(item1->_iLMinDam, item2->_iLMinDam);
ASSERT_EQ(item1->_iLMaxDam, item2->_iLMaxDam);
ASSERT_EQ(item1->_iPrePower, item2->_iPrePower);
ASSERT_EQ(item1->_iSufPower, item2->_iSufPower);
ASSERT_EQ(item1->_iMinStr, item2->_iMinStr);
ASSERT_EQ(item1->_iMinMag, item2->_iMinMag);
ASSERT_EQ(item1->_iMinDex, item2->_iMinDex);
ASSERT_EQ(item1->IDidx, item2->IDidx);
ASSERT_STREQ(item1->_iIName, item2->_iIName);
ASSERT_EQ(item1->_itype, item2->_itype);
ASSERT_EQ(item1->_iClass, item2->_iClass);
ASSERT_EQ(item1->_iCurs, item2->_iCurs);
ASSERT_EQ(item1->_iIvalue, item2->_iIvalue);
ASSERT_EQ(item1->_iMinDam, item2->_iMinDam);
ASSERT_EQ(item1->_iMaxDam, item2->_iMaxDam);
ASSERT_EQ(item1->_iAC, item2->_iAC);
ASSERT_EQ(item1->_iFlags, item2->_iFlags);
ASSERT_EQ(item1->_iMiscId, item2->_iMiscId);
ASSERT_EQ(item1->_iSpell, item2->_iSpell);
ASSERT_EQ(item1->_iCharges, item2->_iCharges);
ASSERT_EQ(item1->_iMaxCharges, item2->_iMaxCharges);
ASSERT_EQ(item1->_iDurability, item2->_iDurability);
ASSERT_EQ(item1->_iMaxDur, item2->_iMaxDur);
ASSERT_EQ(item1->_iPLDam, item2->_iPLDam);
ASSERT_EQ(item1->_iPLToHit, item2->_iPLToHit);
ASSERT_EQ(item1->_iPLAC, item2->_iPLAC);
ASSERT_EQ(item1->_iPLStr, item2->_iPLStr);
ASSERT_EQ(item1->_iPLMag, item2->_iPLMag);
ASSERT_EQ(item1->_iPLDex, item2->_iPLDex);
ASSERT_EQ(item1->_iPLVit, item2->_iPLVit);
ASSERT_EQ(item1->_iPLFR, item2->_iPLFR);
ASSERT_EQ(item1->_iPLLR, item2->_iPLLR);
ASSERT_EQ(item1->_iPLMR, item2->_iPLMR);
ASSERT_EQ(item1->_iPLMana, item2->_iPLMana);
ASSERT_EQ(item1->_iPLHP, item2->_iPLHP);
ASSERT_EQ(item1->_iPLDamMod, item2->_iPLDamMod);
ASSERT_EQ(item1->_iPLGetHit, item2->_iPLGetHit);
ASSERT_EQ(item1->_iPLLight, item2->_iPLLight);
ASSERT_EQ(item1->_iSplLvlAdd, item2->_iSplLvlAdd);
ASSERT_EQ(item1->_iUid, item2->_iUid);
ASSERT_EQ(item1->_iFMinDam, item2->_iFMinDam);
ASSERT_EQ(item1->_iFMaxDam, item2->_iFMaxDam);
ASSERT_EQ(item1->_iLMinDam, item2->_iLMinDam);
ASSERT_EQ(item1->_iLMaxDam, item2->_iLMaxDam);
ASSERT_EQ(item1->_iPrePower, item2->_iPrePower);
ASSERT_EQ(item1->_iSufPower, item2->_iSufPower);
ASSERT_EQ(item1->_iMinStr, item2->_iMinStr);
ASSERT_EQ(item1->_iMinMag, item2->_iMinMag);
ASSERT_EQ(item1->_iMinDex, item2->_iMinDex);
ASSERT_EQ(item1->IDidx, item2->IDidx);
}
const dvl::PkItemStruct PackedDiabloItems[] = {
// clang-format off
// iSeed, iCreateInfo, idx, bId, bDur, bMDur, bCh, bMCh, wValue, dwBuff
@ -233,39 +232,38 @@ TEST(pack, UnPackItem_diablo)
}
}
TEST(pack, UnPackItem_diablo_unique_bug)
{
dvl::PkItemStruct pkItemBug = { 6, 911, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - with morph bug
dvl::PkItemStruct pkItem = { 6, 655, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - fixed
dvl::PkItemStruct pkItem = { 6, 655, 14, 5, 60, 60, 0, 0, 0, 0 }; // Veil of Steel - fixed
dvl::gbIsHellfire = false;
dvl::gbIsHellfireSaveGame = false;
dvl::gbIsMultiplayer = false;
dvl::ItemStruct id;
dvl::UnPackItem(&pkItemBug, &id);
ASSERT_STREQ(id._iIName, "Veil of Steel");
ASSERT_EQ(id._itype, dvl::ITYPE_HELM);
ASSERT_EQ(id._iClass, dvl::ICLASS_ARMOR);
ASSERT_EQ(id._iCurs, 85);
ASSERT_EQ(id._iIvalue, 63800);
ASSERT_EQ(id._iAC, 18);
ASSERT_EQ(id._iMiscId, dvl::IMISC_UNIQUE);
ASSERT_EQ(id._iPLAC, 60);
ASSERT_EQ(id._iPLStr, 15);
ASSERT_EQ(id._iPLVit, 15);
ASSERT_EQ(id._iPLFR, 50);
ASSERT_EQ(id._iPLLR, 50);
ASSERT_EQ(id._iPLMR, 50);
ASSERT_EQ(id._iPLMana, -1920);
ASSERT_EQ(id._iPLLight, -2);
ASSERT_EQ(id._iUid, 6);
ASSERT_EQ(id.IDidx, dvl::IDI_STEELVEIL);
dvl::UnPackItem(&pkItemBug, &id);
ASSERT_STREQ(id._iIName, "Veil of Steel");
ASSERT_EQ(id._itype, dvl::ITYPE_HELM);
ASSERT_EQ(id._iClass, dvl::ICLASS_ARMOR);
ASSERT_EQ(id._iCurs, 85);
ASSERT_EQ(id._iIvalue, 63800);
ASSERT_EQ(id._iAC, 18);
ASSERT_EQ(id._iMiscId, dvl::IMISC_UNIQUE);
ASSERT_EQ(id._iPLAC, 60);
ASSERT_EQ(id._iPLStr, 15);
ASSERT_EQ(id._iPLVit, 15);
ASSERT_EQ(id._iPLFR, 50);
ASSERT_EQ(id._iPLLR, 50);
ASSERT_EQ(id._iPLMR, 50);
ASSERT_EQ(id._iPLMana, -1920);
ASSERT_EQ(id._iPLLight, -2);
ASSERT_EQ(id._iUid, 6);
ASSERT_EQ(id.IDidx, dvl::IDI_STEELVEIL);
dvl::PkItemStruct is;
dvl::PackItem(&is, &id);
ComparePackedItems(&is, &pkItem);
dvl::PackItem(&is, &id);
ComparePackedItems(&is, &pkItem);
}
const dvl::PkItemStruct PackedDiabloMPItems[] = {
@ -466,13 +464,12 @@ TEST(pack, UnPackItem_empty)
ASSERT_EQ(id._itype, dvl::ITYPE_NONE);
}
TEST(pack, PackItem_empty)
{
dvl::PkItemStruct is;
dvl::ItemStruct id;
id._itype = dvl::ITYPE_NONE;
id._itype = dvl::ITYPE_NONE;
dvl::PackItem(&is, &id);

104
SourceT/player_test.cpp

@ -25,7 +25,7 @@ int RunBlockTest(bool hellfire, int frames, int flags)
dvl::plr[pnum]._pAnimFrame++;
}
return i;
return i;
}
#define NORM 0
@ -41,66 +41,66 @@ int RunBlockTest(bool hellfire, int frames, int flags)
#define SRC 8
int BlockData[][4] = {
{ 6, false, WAR, NORM }, // D
{ 7, false, ROU, NORM }, // D
{ 8, false, SRC, NORM }, // D
{ 6, true, WAR, NORM }, // HF
{ 7, true, ROU, NORM }, // HF
{ 8, true, SRC, NORM }, // HF
{ 6, false, WAR, NORM }, // D
{ 7, false, ROU, NORM }, // D
{ 8, false, SRC, NORM }, // D
{ 6, true, WAR, NORM }, // HF
{ 7, true, ROU, NORM }, // HF
{ 8, true, SRC, NORM }, // HF
{ 5, false, WAR, BAL }, // D
{ 6, false, ROU, BAL }, // D
{ 7, false, SRC, BAL }, // D
{ 5, true, WAR, BAL }, // HF
{ 6, true, ROU, BAL }, // HF
{ 7, true, SRC, BAL }, // HF
{ 5, false, WAR, BAL }, // D
{ 6, false, ROU, BAL }, // D
{ 7, false, SRC, BAL }, // D
{ 5, true, WAR, BAL }, // HF
{ 6, true, ROU, BAL }, // HF
{ 7, true, SRC, BAL }, // HF
{ 4, false, WAR, STA }, // D
{ 5, false, ROU, STA }, // D
{ 6, false, SRC, STA }, // D
{ 4, true, WAR, STA }, // HF
{ 5, true, ROU, STA }, // HF
{ 6, true, SRC, STA }, // HF
{ 4, false, WAR, STA }, // D
{ 5, false, ROU, STA }, // D
{ 6, false, SRC, STA }, // D
{ 4, true, WAR, STA }, // HF
{ 5, true, ROU, STA }, // HF
{ 6, true, SRC, STA }, // HF
{ 3, false, WAR, HAR }, // D
{ 4, false, ROU, HAR }, // D
{ 5, false, SRC, HAR }, // D
{ 3, true, WAR, HAR }, // HF
{ 4, true, ROU, HAR }, // HF
{ 5, true, SRC, HAR }, // HF
{ 3, false, WAR, HAR }, // D
{ 4, false, ROU, HAR }, // D
{ 5, false, SRC, HAR }, // D
{ 3, true, WAR, HAR }, // HF
{ 4, true, ROU, HAR }, // HF
{ 5, true, SRC, HAR }, // HF
{ 4, false, WAR, BALSTA }, // D
{ 5, false, ROU, BALSTA }, // D
{ 6, false, SRC, BALSTA }, // D
{ 4, true, WAR, BALSTA }, // HF
{ 5, true, ROU, BALSTA }, // HF
{ 6, true, SRC, BALSTA }, // HF
{ 4, false, WAR, BALSTA }, // D
{ 5, false, ROU, BALSTA }, // D
{ 6, false, SRC, BALSTA }, // D
{ 4, true, WAR, BALSTA }, // HF
{ 5, true, ROU, BALSTA }, // HF
{ 6, true, SRC, BALSTA }, // HF
{ 3, false, WAR, BALHAR }, // D
{ 4, false, ROU, BALHAR }, // D
{ 5, false, SRC, BALHAR }, // D
{ 3, true, WAR, BALHAR }, // HF
{ 4, true, ROU, BALHAR }, // HF
{ 5, true, SRC, BALHAR }, // HF
{ 3, false, WAR, BALHAR }, // D
{ 4, false, ROU, BALHAR }, // D
{ 5, false, SRC, BALHAR }, // D
{ 3, true, WAR, BALHAR }, // HF
{ 4, true, ROU, BALHAR }, // HF
{ 5, true, SRC, BALHAR }, // HF
{ 3, false, WAR, STAHAR }, // D
{ 4, false, ROU, STAHAR }, // D
{ 5, false, SRC, STAHAR }, // D
{ 3, true, WAR, STAHAR }, // HF
{ 4, true, ROU, STAHAR }, // HF
{ 5, true, SRC, STAHAR }, // HF
{ 3, false, WAR, STAHAR }, // D
{ 4, false, ROU, STAHAR }, // D
{ 5, false, SRC, STAHAR }, // D
{ 3, true, WAR, STAHAR }, // HF
{ 4, true, ROU, STAHAR }, // HF
{ 5, true, SRC, STAHAR }, // HF
{ 2, false, WAR, ZEN }, // D
{ 3, false, ROU, ZEN }, // D
{ 4, false, SRC, ZEN }, // D
{ 3, true, WAR, ZEN }, // HF
{ 4, true, ROU, ZEN }, // HF
{ 5, true, SRC, ZEN }, // HF
{ 2, false, WAR, ZEN }, // D
{ 3, false, ROU, ZEN }, // D
{ 4, false, SRC, ZEN }, // D
{ 3, true, WAR, ZEN }, // HF
{ 4, true, ROU, ZEN }, // HF
{ 5, true, SRC, ZEN }, // HF
};
TEST(Player, PM_DoGotHit)
{
for (size_t i = 0; i < sizeof(BlockData) / sizeof(*BlockData); i++) {
EXPECT_EQ(BlockData[i][0], RunBlockTest(BlockData[i][1], BlockData[i][2], BlockData[i][3]));
}
for (size_t i = 0; i < sizeof(BlockData) / sizeof(*BlockData); i++) {
EXPECT_EQ(BlockData[i][0], RunBlockTest(BlockData[i][1], BlockData[i][2], BlockData[i][3]));
}
}

3
SourceX/DiabloUI/diabloui.cpp

@ -276,7 +276,8 @@ void UiFocusNavigation(SDL_Event *event)
break;
}
if (HandleMenuAction(GetMenuAction(*event))) return;
if (HandleMenuAction(GetMenuAction(*event)))
return;
#ifndef USE_SDL1
if (event->type == SDL_MOUSEWHEEL) {

14
SourceX/DiabloUI/fonts.cpp

@ -53,7 +53,8 @@ void UnloadArtFonts()
FontTables[AFT_HUGE] = NULL;
}
void LoadTtfFont() {
void LoadTtfFont()
{
if (!TTF_WasInit()) {
if (TTF_Init() == -1) {
SDL_Log("TTF_Init: %s", TTF_GetError());
@ -64,8 +65,7 @@ void LoadTtfFont() {
std::string ttf_font_path = GetTtfPath() + GetTtfName();
#ifdef __linux__
if (!FileExists(ttf_font_path.c_str()))
{
if (!FileExists(ttf_font_path.c_str())) {
ttf_font_path = "/usr/share/fonts/truetype/" + GetTtfName();
}
#endif
@ -79,14 +79,16 @@ void LoadTtfFont() {
TTF_SetFontHinting(font, TTF_HINTING_MONO);
}
void UnloadTtfFont() {
void UnloadTtfFont()
{
if (font && TTF_WasInit())
TTF_CloseFont(font);
font = NULL;
}
void FontsCleanup() {
TTF_Quit();
void FontsCleanup()
{
TTF_Quit();
}
} // namespace dvl

8
SourceX/DiabloUI/scrollbar.cpp

@ -6,16 +6,18 @@ Art ArtScrollBarBackground;
Art ArtScrollBarThumb;
Art ArtScrollBarArrow;
void LoadScrollBar() {
void LoadScrollBar()
{
LoadArt("ui_art\\sb_bg.pcx", &ArtScrollBarBackground);
LoadArt("ui_art\\sb_thumb.pcx", &ArtScrollBarThumb);
LoadArt("ui_art\\sb_arrow.pcx", &ArtScrollBarArrow, 4);
}
void UnloadScrollBar() {
void UnloadScrollBar()
{
ArtScrollBarArrow.Unload();
ArtScrollBarThumb.Unload();
ArtScrollBarBackground.Unload();
}
} // namespace
} // namespace dvl

2
SourceX/DiabloUI/selconn.h

@ -4,4 +4,4 @@ void selconn_Esc();
void selconn_Focus(int value);
void selconn_Select(int value);
}
} // namespace dvl

2
SourceX/DiabloUI/selgame.h

@ -19,4 +19,4 @@ void selgame_Password_Init(int value);
void selgame_Password_Select(int value);
void selgame_Password_Esc();
}
} // namespace dvl

3
SourceX/DiabloUI/selhero.cpp

@ -350,7 +350,8 @@ void selhero_ClassSelector_Focus(int value)
selhero_SetStats();
}
static bool shouldPrefillHeroName() {
static bool shouldPrefillHeroName()
{
#if defined __3DS__
return false;
#elif defined(PREFILL_PLAYER_NAME)

2
SourceX/DiabloUI/selok.h

@ -8,4 +8,4 @@ void selok_Free();
void selok_Select(int value);
void selok_Esc();
}
} // namespace dvl

2
SourceX/DiabloUI/selyesno.h

@ -8,4 +8,4 @@ void selyesno_Free();
void selyesno_Select(int value);
void selyesno_Esc();
}
} // namespace dvl

38
SourceX/DiabloUI/support_lines.cpp

@ -3,25 +3,25 @@
namespace dvl {
const char *const SUPPORT_LINES[] = {
"",
"GOG.com maintains a web site at https://www.gog.com/forum/diablo",
"Follow the links to visit the discussion boards associated with Diablo.",
"and the Hellfire expansion.",
"",
"DevilutionX is maintained by Diasurgical, issues and bugs can be reported",
"at this address: https://github.com/diasurgical/devilutionX",
"To help us better serve you, please be sure to include the version number,",
"operating system, and the nature of the problem.",
"",
"",
"Disclaimer:",
" DevilutionX is not supported or maintained by Blizzard Entertainment,",
" nor GOG.com. Neither Blizzard Entertainment or GOG.com has not tested",
" or certified the quality or compatibility of DevilutionX. All inquiries",
" regarding DevilutionX should be directed to Diasurgical, not to Blizzard",
" Entertainment or GOG.com.",
"",
"",
"",
"GOG.com maintains a web site at https://www.gog.com/forum/diablo",
"Follow the links to visit the discussion boards associated with Diablo.",
"and the Hellfire expansion.",
"",
"DevilutionX is maintained by Diasurgical, issues and bugs can be reported",
"at this address: https://github.com/diasurgical/devilutionX",
"To help us better serve you, please be sure to include the version number,",
"operating system, and the nature of the problem.",
"",
"",
"Disclaimer:",
" DevilutionX is not supported or maintained by Blizzard Entertainment,",
" nor GOG.com. Neither Blizzard Entertainment or GOG.com has not tested",
" or certified the quality or compatibility of DevilutionX. All inquiries",
" regarding DevilutionX should be directed to Diasurgical, not to Blizzard",
" Entertainment or GOG.com.",
"",
"",
};
const std::size_t SUPPORT_LINES_SIZE = sizeof(SUPPORT_LINES) / sizeof(SUPPORT_LINES[0]);

78
SourceX/controls/axis_direction.cpp

@ -8,48 +8,48 @@ AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction)
{
const int now = SDL_GetTicks();
switch (axis_direction.x) {
case AxisDirectionX_LEFT:
last_right_ = 0;
if (now - last_left_ < min_interval_ms_) {
axis_direction.x = AxisDirectionX_NONE;
} else {
last_left_ = now;
}
break;
case AxisDirectionX_RIGHT:
last_left_ = 0;
if (now - last_right_ < min_interval_ms_) {
axis_direction.x = AxisDirectionX_NONE;
} else {
last_right_ = now;
}
break;
case AxisDirectionX_NONE:
last_left_ = last_right_ = 0;
break;
case AxisDirectionX_LEFT:
last_right_ = 0;
if (now - last_left_ < min_interval_ms_) {
axis_direction.x = AxisDirectionX_NONE;
} else {
last_left_ = now;
}
break;
case AxisDirectionX_RIGHT:
last_left_ = 0;
if (now - last_right_ < min_interval_ms_) {
axis_direction.x = AxisDirectionX_NONE;
} else {
last_right_ = now;
}
break;
case AxisDirectionX_NONE:
last_left_ = last_right_ = 0;
break;
}
switch (axis_direction.y) {
case AxisDirectionY_UP:
last_down_ = 0;
if (now - last_up_ < min_interval_ms_) {
axis_direction.y = AxisDirectionY_NONE;
} else {
last_up_ = now;
}
break;
case AxisDirectionY_DOWN:
last_up_ = 0;
if (now - last_down_ < min_interval_ms_) {
axis_direction.y = AxisDirectionY_NONE;
} else {
last_down_ = now;
}
break;
case AxisDirectionY_NONE:
last_up_ = last_down_ = 0;
break;
case AxisDirectionY_UP:
last_down_ = 0;
if (now - last_up_ < min_interval_ms_) {
axis_direction.y = AxisDirectionY_NONE;
} else {
last_up_ = now;
}
break;
case AxisDirectionY_DOWN:
last_up_ = 0;
if (now - last_down_ < min_interval_ms_) {
axis_direction.y = AxisDirectionY_NONE;
} else {
last_down_ = now;
}
break;
case AxisDirectionY_NONE:
last_up_ = last_down_ = 0;
break;
}
return axis_direction;
}
} // namespace
} // namespace dvl

14
SourceX/controls/devices/game_controller.cpp

@ -198,13 +198,13 @@ GameController *GameController::Get(SDL_JoystickID instance_id)
GameController *GameController::Get(const SDL_Event &event)
{
switch (event.type) {
case SDL_CONTROLLERAXISMOTION:
return Get(event.caxis.which);
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
return Get(event.jball.which);
default:
return NULL;
case SDL_CONTROLLERAXISMOTION:
return Get(event.caxis.which);
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
return Get(event.jball.which);
default:
return NULL;
}
}

40
SourceX/controls/devices/joystick.cpp

@ -302,27 +302,27 @@ Joystick *Joystick::Get(const SDL_Event &event)
{
switch (event.type) {
#ifndef USE_SDL1
case SDL_JOYAXISMOTION:
return Get(event.jaxis.which);
case SDL_JOYBALLMOTION:
return Get(event.jball.which);
case SDL_JOYHATMOTION:
return Get(event.jhat.which);
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
return Get(event.jbutton.which);
return Get(event.jbutton.which);
default:
return NULL;
case SDL_JOYAXISMOTION:
return Get(event.jaxis.which);
case SDL_JOYBALLMOTION:
return Get(event.jball.which);
case SDL_JOYHATMOTION:
return Get(event.jhat.which);
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
return Get(event.jbutton.which);
return Get(event.jbutton.which);
default:
return NULL;
#else
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
return joysticks_->empty() ? NULL : &(*joysticks_)[0];
default:
return NULL;
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
return joysticks_->empty() ? NULL : &(*joysticks_)[0];
default:
return NULL;
#endif
}
}

64
SourceX/controls/game_controls.cpp

@ -79,7 +79,8 @@ bool HandleStartAndSelect(const ControllerButtonEvent &ctrl_event, GameAction *a
if (in_game_menu && (start_is_down || select_is_down) && !ctrl_event.up) {
// If both are down, do nothing because `both_received` will trigger soon.
if (start_is_down && select_is_down) return true;
if (start_is_down && select_is_down)
return true;
*action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up };
return true;
}
@ -122,14 +123,14 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
case ControllerButton_BUTTON_LEFTSHOULDER:
if ((select_modifier_active && !sgOptions.Controller.bSwapShoulderButtonMode) || (sgOptions.Controller.bSwapShoulderButtonMode && !select_modifier_active)) {
if (!IsAutomapActive())
*action = GameActionSendMouseClick{ GameActionSendMouseClick::LEFT, ctrl_event.up };
*action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrl_event.up };
return true;
}
break;
case ControllerButton_BUTTON_RIGHTSHOULDER:
if ((select_modifier_active && !sgOptions.Controller.bSwapShoulderButtonMode) || (sgOptions.Controller.bSwapShoulderButtonMode && !select_modifier_active)) {
if (!IsAutomapActive())
*action = GameActionSendMouseClick{ GameActionSendMouseClick::RIGHT, ctrl_event.up };
*action = GameActionSendMouseClick { GameActionSendMouseClick::RIGHT, ctrl_event.up };
return true;
}
break;
@ -161,29 +162,27 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
switch (ctrl_event.button) {
case ControllerButton_BUTTON_DPAD_UP:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F6, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_F6, ctrl_event.up };
else
*action = GameActionSendKey{ DVL_VK_ESCAPE, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up };
return true;
case ControllerButton_BUTTON_DPAD_RIGHT:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F8, ctrl_event.up };
else
if (!ctrl_event.up)
*action = GameAction(GameActionType_TOGGLE_INVENTORY);
*action = GameActionSendKey { DVL_VK_F8, ctrl_event.up };
else if (!ctrl_event.up)
*action = GameAction(GameActionType_TOGGLE_INVENTORY);
return true;
case ControllerButton_BUTTON_DPAD_DOWN:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F7, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_F7, ctrl_event.up };
else
*action = GameActionSendKey{ DVL_VK_TAB, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_TAB, ctrl_event.up };
return true;
case ControllerButton_BUTTON_DPAD_LEFT:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F5, ctrl_event.up };
else
if (!ctrl_event.up)
*action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO);
*action = GameActionSendKey { DVL_VK_F5, ctrl_event.up };
else if (!ctrl_event.up)
*action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO);
return true;
default:
break;
@ -192,14 +191,14 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
if (start_modifier_active) {
switch (ctrl_event.button) {
case ControllerButton_BUTTON_DPAD_UP:
*action = GameActionSendKey{ DVL_VK_ESCAPE, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up };
return true;
case ControllerButton_BUTTON_DPAD_RIGHT:
if (!ctrl_event.up)
*action = GameAction(GameActionType_TOGGLE_INVENTORY);
return true;
case ControllerButton_BUTTON_DPAD_DOWN:
*action = GameActionSendKey{ DVL_VK_TAB, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_TAB, ctrl_event.up };
return true;
case ControllerButton_BUTTON_DPAD_LEFT:
if (!ctrl_event.up)
@ -212,7 +211,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
CalcViewportGeometry();
}
#else
// Not mapped. Reserved for future use.
// Not mapped. Reserved for future use.
#endif
return true;
case ControllerButton_BUTTON_B: // Right button
@ -241,7 +240,8 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
// Bottom button: Closes menus or opens quick spell book if nothing is open.
if (ctrl_event.button == ControllerButton_BUTTON_A) { // Bottom button
if (ctrl_event.up) return true;
if (ctrl_event.up)
return true;
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F7, ctrl_event.up };
else if (invflag)
@ -264,7 +264,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
case ControllerButton_BUTTON_B: // Right button
if (!ctrl_event.up) {
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F8, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_F8, ctrl_event.up };
else
*action = GameAction(GameActionType_PRIMARY_ACTION);
}
@ -272,7 +272,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
case ControllerButton_BUTTON_Y: // Top button
if (!ctrl_event.up) {
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F6, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_F6, ctrl_event.up };
else
*action = GameAction(GameActionType_SECONDARY_ACTION);
}
@ -280,7 +280,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
case ControllerButton_BUTTON_X: // Left button
if (!ctrl_event.up) {
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey{ DVL_VK_F5, ctrl_event.up };
*action = GameActionSendKey { DVL_VK_F5, ctrl_event.up };
else
*action = GameAction(GameActionType_CAST_SPELL);
}
@ -309,24 +309,22 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
}
}
// DPad navigation is handled separately for these.
if (gmenu_is_active() || questlog || stextflag != STORE_NONE)
{
if (gmenu_is_active() || questlog || stextflag != STORE_NONE) {
switch (ctrl_event.button) {
case ControllerButton_BUTTON_DPAD_UP:
case ControllerButton_BUTTON_DPAD_DOWN:
case ControllerButton_BUTTON_DPAD_LEFT:
case ControllerButton_BUTTON_DPAD_RIGHT:
return true;
default:
break;
case ControllerButton_BUTTON_DPAD_UP:
case ControllerButton_BUTTON_DPAD_DOWN:
case ControllerButton_BUTTON_DPAD_LEFT:
case ControllerButton_BUTTON_DPAD_RIGHT:
return true;
default:
break;
}
}
// By default, map to a keyboard key.
if (ctrl_event.button != ControllerButton_NONE) {
*action = GameActionSendKey{ translate_controller_button_to_key(ctrl_event.button),
*action = GameActionSendKey { translate_controller_button_to_key(ctrl_event.button),
ctrl_event.up };
return true;
}

3
SourceX/controls/modifier_hints.cpp

@ -123,8 +123,7 @@ void DrawSelectModifierMenu(CelOutputBuffer out)
{
if (!select_modifier_active)
return;
if (sgOptions.Controller.bDpadHotkeys)
{
if (sgOptions.Controller.bDpadHotkeys) {
static const CircleMenuHint kDpad(/*is_dpad=*/true, /*top=*/"F6", /*right=*/"F8", /*bottom=*/"F7", /*left=*/"F5");
DrawCircleMenuHint(out, kDpad, PANEL_LEFT + kCircleMarginX, PANEL_TOP - kCirclesTop);
}

6
SourceX/controls/plrctrls.cpp

@ -862,7 +862,8 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
return NULL;
}
void ProcessLeftStickOrDPadGameUI() {
void ProcessLeftStickOrDPadGameUI()
{
HandleLeftStickOrDPadFn handler = GetLeftStickOrDPadGameUIHandler();
if (handler != NULL)
handler(GetLeftStickOrDpadDirection(true));
@ -1010,8 +1011,7 @@ void HandleRightStickMotion()
// cursor position events.
static int lastMouseSetTick = 0;
const int now = SDL_GetTicks();
if (now - lastMouseSetTick > 0)
{
if (now - lastMouseSetTick > 0) {
SetCursorPos(x, y);
lastMouseSetTick = now;
}

2
SourceX/controls/remap_keyboard.h

@ -19,7 +19,7 @@ inline void remap_keyboard_key(SDL_Keycode *sym)
SDL_Keycode from;
SDL_Keycode to;
};
constexpr Mapping kMappings[] = {REMAP_KEYBOARD_KEYS};
constexpr Mapping kMappings[] = { REMAP_KEYBOARD_KEYS };
for (std::size_t i = 0; i < sizeof(kMappings) / sizeof(kMappings[0]); ++i) {
if (*sym == kMappings[i].from) {
*sym = kMappings[i].to;

10
SourceX/dvlnet/frame_queue.cpp

@ -21,16 +21,16 @@ buffer_t frame_queue::read(framesize_t s)
s -= buffer_deque.front().size();
current_size -= buffer_deque.front().size();
ret.insert(ret.end(),
buffer_deque.front().begin(),
buffer_deque.front().end());
buffer_deque.front().begin(),
buffer_deque.front().end());
buffer_deque.pop_front();
}
if (s > 0) {
ret.insert(ret.end(),
buffer_deque.front().begin(),
buffer_deque.front().begin() + s);
buffer_deque.front().begin(),
buffer_deque.front().begin() + s);
buffer_deque.front().erase(buffer_deque.front().begin(),
buffer_deque.front().begin() + s);
buffer_deque.front().begin() + s);
current_size -= s;
}
return ret;

6
SourceX/dvlnet/loopback.cpp

@ -59,12 +59,12 @@ int loopback::SNetGetProviderCaps(struct _SNETCAPS *caps)
caps->latencyms = 0; // unused
caps->defaultturnssec = 10; // ?
caps->defaultturnsintransit = 1; // maximum acceptable number
// of turns in queue?
// of turns in queue?
return 1;
}
bool loopback::SNetRegisterEventHandler(event_type evtype,
SEVTHANDLER func)
SEVTHANDLER func)
{
// not called in real singleplayer mode
// not needed in pseudo multiplayer mode (?)
@ -72,7 +72,7 @@ bool loopback::SNetRegisterEventHandler(event_type evtype,
}
bool loopback::SNetUnregisterEventHandler(event_type evtype,
SEVTHANDLER func)
SEVTHANDLER func)
{
// not called in real singleplayer mode
// not needed in pseudo multiplayer mode (?)

6
SourceX/dvlnet/loopback.h

@ -26,13 +26,13 @@ public:
virtual bool SNetReceiveMessage(int *sender, char **data, int *size);
virtual bool SNetSendMessage(int dest, void *data, unsigned int size);
virtual bool SNetReceiveTurns(char **data, unsigned int *size,
DWORD *status);
DWORD *status);
virtual bool SNetSendTurn(char *data, unsigned int size);
virtual int SNetGetProviderCaps(struct _SNETCAPS *caps);
virtual bool SNetRegisterEventHandler(event_type evtype,
SEVTHANDLER func);
SEVTHANDLER func);
virtual bool SNetUnregisterEventHandler(event_type evtype,
SEVTHANDLER func);
SEVTHANDLER func);
virtual bool SNetLeaveGame(int type);
virtual bool SNetDropPlayer(int playerid, DWORD flags);
virtual bool SNetGetOwnerTurnsWaiting(DWORD *turns);

2
SourceX/dvlnet/tcp_server.cpp

@ -161,7 +161,7 @@ void tcp_server::start_accept()
void tcp_server::handle_accept(scc con, const asio::error_code &ec)
{
if(ec)
if (ec)
return;
if (next_free() == PLR_BROADCAST) {
drop_connection(con);

12
SourceX/dx.cpp

@ -38,11 +38,11 @@ SDL_Surface *pal_surface;
static void dx_create_back_buffer()
{
pal_surface = SDL_CreateRGBSurfaceWithFormat(
/*flags=*/0,
/*width=*/BUFFER_BORDER_LEFT + gnScreenWidth + BUFFER_BORDER_RIGHT,
/*height=*/BUFFER_BORDER_TOP + gnScreenHeight + BUFFER_BORDER_BOTTOM,
/*depth=*/8,
SDL_PIXELFORMAT_INDEX8);
/*flags=*/0,
/*width=*/BUFFER_BORDER_LEFT + gnScreenWidth + BUFFER_BORDER_RIGHT,
/*height=*/BUFFER_BORDER_TOP + gnScreenHeight + BUFFER_BORDER_BOTTOM,
/*depth=*/8,
SDL_PIXELFORMAT_INDEX8);
if (pal_surface == NULL) {
ErrSdl();
}
@ -131,7 +131,7 @@ CelOutputBuffer GlobalBackBuffer()
return CelOutputBuffer();
}
return CelOutputBuffer(pal_surface, SDL_Rect{BUFFER_BORDER_LEFT, BUFFER_BORDER_TOP, gnScreenWidth, gnScreenHeight});
return CelOutputBuffer(pal_surface, SDL_Rect { BUFFER_BORDER_LEFT, BUFFER_BORDER_TOP, gnScreenWidth, gnScreenHeight });
}
void dx_cleanup()

4
SourceX/main.cpp

@ -21,8 +21,8 @@ extern "C" const char *__asan_default_options()
int main(int argc, char **argv)
{
#ifdef RUN_TESTS
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
#endif
#ifdef __SWITCH__
switch_enable_network();

5
SourceX/platform/ctr/keyboard.cpp

@ -3,7 +3,7 @@
#include "platform/ctr/keyboard.h"
const char* ctr_vkbdInput(const char *hintText, const char *inText, char *outText)
const char *ctr_vkbdInput(const char *hintText, const char *inText, char *outText)
{
SwkbdState swkbd;
@ -16,8 +16,7 @@ const char* ctr_vkbdInput(const char *hintText, const char *inText, char *outTex
SwkbdButton button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf));
if (button == SWKBD_BUTTON_CONFIRM)
{
if (button == SWKBD_BUTTON_CONFIRM) {
strcpy(outText, mybuf);
return 0;
}

2
SourceX/platform/ctr/keyboard.h

@ -1,3 +1,3 @@
#include <3ds.h>
const char* ctr_vkbdInput(const char *title, const char *inText, char *outText);
const char *ctr_vkbdInput(const char *title, const char *inText, char *outText);

36
SourceX/platform/ctr/system.cpp

@ -10,22 +10,22 @@ aptHookCookie cookie;
void aptHookFunc(APT_HookType hookType, void *param)
{
switch (hookType) {
case APTHOOK_ONSUSPEND:
ctr_lcd_backlight_on();
break;
case APTHOOK_ONSLEEP:
break;
case APTHOOK_ONRESTORE:
ctr_lcd_backlight_off();
break;
case APTHOOK_ONWAKEUP:
ctr_lcd_backlight_off();
break;
case APTHOOK_ONEXIT:
ctr_lcd_backlight_on();
break;
default:
break;
case APTHOOK_ONSUSPEND:
ctr_lcd_backlight_on();
break;
case APTHOOK_ONSLEEP:
break;
case APTHOOK_ONRESTORE:
ctr_lcd_backlight_off();
break;
case APTHOOK_ONWAKEUP:
ctr_lcd_backlight_off();
break;
case APTHOOK_ONEXIT:
ctr_lcd_backlight_on();
break;
default:
break;
}
}
@ -62,13 +62,13 @@ bool ctr_check_dsp()
void ctr_sys_init()
{
if( ctr_check_dsp() == false )
if (ctr_check_dsp() == false)
exit(0);
aptHook(&cookie, aptHookFunc, NULL);
APT_CheckNew3DS(&isN3DS);
if(isN3DS)
if (isN3DS)
osSetSpeedupEnable(true);
ctr_lcd_backlight_off();

16
SourceX/platform/switch/docking.cpp

@ -14,14 +14,14 @@ void HandleDocking()
{
int docked;
switch (appletGetOperationMode()) {
case AppletOperationMode_Handheld:
docked = 0;
break;
case AppletOperationMode_Console:
docked = 1;
break;
default:
docked = 0;
case AppletOperationMode_Handheld:
docked = 0;
break;
case AppletOperationMode_Console:
docked = 1;
break;
default:
docked = 0;
}
int display_width;

2
SourceX/soundsample.cpp

@ -117,7 +117,7 @@ int SoundSample::GetLength()
bytePerSample = 1;
}
Uint64 ms = 1000; // milliseconds, 64bit to avoid overflow when multiplied by alen
Uint64 ms = 1000; // milliseconds, 64bit to avoid overflow when multiplied by alen
Uint32 bps = frequency * channels * bytePerSample; // bytes per second
return (Uint32)(chunk->alen * ms / bps);
};

2
SourceX/thread.cpp

@ -75,4 +75,4 @@ int WaitForEvent(event_emul *e)
return ret;
}
}
} // namespace dvl

Loading…
Cancel
Save