Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle scaling for SDL1 #5

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fc79fc6
Keyboard and Controller support for Diablo 1
erfg12 Mar 24, 2019
acf5566
plrctrls rebased
Jun 24, 2019
5a32c3d
plrctrls can now compile on other systems besides Switch
erfg12 Jul 7, 2019
2ff357e
Use SDL_GameController for portability
rsn8887 Jul 16, 2019
afba30a
Game controller support
glebm Oct 26, 2019
b67dfff
Controller: implement spellcasting
glebm Oct 28, 2019
3318e0b
SDL1 fixes
glebm Oct 28, 2019
19b0d71
Fix item flickering
glebm Oct 28, 2019
bed1b5d
Game controller: Fix spell selection
glebm Oct 31, 2019
7a06529
Define RetroFW controls via the build script
glebm Oct 31, 2019
5a438b3
Controller: Support SDL1 joystick axes
glebm Oct 31, 2019
24eec63
Controller: Support SDL1 joystick hat
glebm Oct 31, 2019
f571894
CMakeLists.txt: Fix boolean define handling
glebm Oct 31, 2019
b63d335
Fix IsJoystickHatButtonPressed
glebm Oct 31, 2019
bce7f42
Controller support: README docs
glebm Nov 1, 2019
3ecda30
Controls: Map top button to use inv item
glebm Nov 1, 2019
c794485
Drop held item when closing inventory
glebm Nov 1, 2019
28b5a35
kbcontroller.cpp: fix missing return value
glebm Nov 1, 2019
2ffcc4c
Make belt usage event based, also use heal scroll from belt
AJenbo Nov 3, 2019
7d14a93
Implement recharge and fix cursor for repair
AJenbo Nov 3, 2019
9532cc6
plrctrls: Fixup checkMonstersNearby
glebm Nov 3, 2019
ec1690e
Make controls more responsive
AJenbo Nov 4, 2019
0276514
Only allow one panel at a time
AJenbo Nov 4, 2019
29dbe41
Handle scaling for SDL1
glebm Oct 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 73 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ add_library(devilution STATIC

set(devilutionx_SRCS
SourceX/dx.cpp
SourceX/controls/devices/game_controller.cpp
SourceX/controls/devices/joystick.cpp
SourceX/controls/devices/kbcontroller.cpp
SourceX/controls/controller.cpp
SourceX/controls/controller_motion.cpp
SourceX/controls/game_controls.cpp
SourceX/controls/menu_controls.cpp
SourceX/controls/plrctrls.cpp
SourceX/miniwin/ddraw.cpp
SourceX/miniwin/misc.cpp
SourceX/miniwin/misc_io.cpp
Expand Down Expand Up @@ -283,6 +291,69 @@ target_compile_definitions(devilution PUBLIC
"$<$<BOOL:${FASTER}>:FASTER>")
target_compile_definitions(devilutionx PRIVATE ASIO_STANDALONE)

# Defines without value
foreach(
def_name
SPAWN
NONET
DINGUX
RETROFW
)
if(${def_name})
list(APPEND def_list ${def_name})
endif()
endforeach(def_name)

# Defines with value
foreach(
def_name
HAS_KBCTRL
KBCTRL_BUTTON_DPAD_LEFT
KBCTRL_BUTTON_DPAD_RIGHT
KBCTRL_BUTTON_DPAD_UP
KBCTRL_BUTTON_DPAD_DOWN
KBCTRL_BUTTON_B
KBCTRL_BUTTON_A
KBCTRL_BUTTON_Y
KBCTRL_BUTTON_X
KBCTRL_BUTTON_LEFTSTICK
KBCTRL_BUTTON_RIGHTSTICK
KBCTRL_BUTTON_RIGHTSHOULDER
KBCTRL_BUTTON_LEFTSHOULDER
KBCTRL_BUTTON_START
KBCTRL_BUTTON_BACK
KBCTRL_MODIFIER_KEY
JOY_AXIS_LEFTX
JOY_AXIS_LEFTY
JOY_AXIS_RIGHTX
JOY_AXIS_RIGHTY
JOY_HAT_DPAD_UP_HAT
JOY_HAT_DPAD_UP
JOY_HAT_DPAD_DOWN_HAT
JOY_HAT_DPAD_DOWN
JOY_HAT_DPAD_LEFT_HAT
JOY_HAT_DPAD_LEFT
JOY_HAT_DPAD_RIGHT_HAT
JOY_HAT_DPAD_RIGHT
JOY_BUTTON_DPAD_LEFT
JOY_BUTTON_DPAD_RIGHT
JOY_BUTTON_DPAD_UP
JOY_BUTTON_DPAD_DOWN
JOY_BUTTON_B
JOY_BUTTON_A
JOY_BUTTON_Y
JOY_BUTTON_X
JOY_BUTTON_LEFTSTICK
JOY_BUTTON_RIGHTSTICK
JOY_BUTTON_RIGHTSHOULDER
JOY_BUTTON_LEFTSHOULDER
JOY_BUTTON_START
JOY_BUTTON_BACK
)
if(DEFINED ${def_name})
list(APPEND def_list ${def_name}=${${def_name}})
endif()
endforeach(def_name)

foreach(target devilution devilutionx)
if(USE_SDL1)
Expand All @@ -296,14 +367,6 @@ foreach(target devilution devilutionx)
SDL2::SDL2_mixer)
endif()

if(NONET)
target_compile_definitions(${target} PRIVATE NONET)
endif()

if(SPAWN)
target_compile_definitions(${target} PRIVATE SPAWN)
endif()

if(ASAN)
target_compile_options(${target} PUBLIC -fsanitize=address -fsanitize-recover=address)
target_link_libraries(${target} PUBLIC -fsanitize=address -fsanitize-recover=address)
Expand All @@ -314,13 +377,8 @@ foreach(target devilution devilutionx)
target_link_libraries(${target} PUBLIC -fsanitize=undefined)
endif()

if(DINGUX)
target_compile_definitions(${target} PRIVATE DINGUX)
endif()
if(RETROFW)
target_compile_definitions(${target} PRIVATE RETROFW)
endif()
endforeach(target devilution devilutionx)
target_compile_definitions(${target} PRIVATE ${def_list})
endforeach(target)

if(DIST AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_link_libraries(devilutionx PUBLIC -static-libgcc -static-libstdc++)
Expand Down
4 changes: 3 additions & 1 deletion Packaging/OpenDingux/build-retrofw.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
./build.sh retrofw

declare -r DIR="$(dirname "${BASH_SOURCE[0]}")"
"${DIR}/build.sh" retrofw
4 changes: 3 additions & 1 deletion Packaging/OpenDingux/build-rg350.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
./build.sh rg350

declare -r DIR="$(dirname "${BASH_SOURCE[0]}")"
"${DIR}/build.sh" rg350
4 changes: 3 additions & 1 deletion Packaging/OpenDingux/build-rs90.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
./build.sh rs90

declare -r DIR="$(dirname "${BASH_SOURCE[0]}")"
"${DIR}/build.sh" rs90
33 changes: 26 additions & 7 deletions Packaging/OpenDingux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ fi

BUILDROOT="${BUILDROOT:-$HOME/buildroot-${TARGET}-devilutionx}"

set -x

main() {
set -x
prepare_buildroot
Expand Down Expand Up @@ -64,7 +62,9 @@ prepare_buildroot() {
make_buildroot() {
cd "$BUILDROOT"
if [[ "$TARGET" != "rg350" ]]; then
echo 'LIBSODIUM_CONF_OPTS += --enable-static' >> package/libsodium/libsodium.mk
if ! grep '--enable-static' package/libsodium/libsodium.mk; then
echo 'LIBSODIUM_CONF_OPTS += --enable-static' >> package/libsodium/libsodium.mk
fi
fi
make ${TARGET}_devilutionx_defconfig
if [[ "$TARGET" == "rg350" ]]; then
Expand All @@ -79,14 +79,33 @@ build() {
mkdir -p ../../build
cd ../../build
rm -f CMakeCache.txt

local -a defs=(-DDINGUX=ON -DBINARY_RELEASE=ON)
if [[ "$TARGET" == "rg350" ]]; then
TARGET_DEFINES="-DNONET=ON"
defs+=(-DNONET=ON)
elif [[ "$TARGET" == "rs90" ]]; then
TARGET_DEFINES="-DUSE_SDL1=ON"
defs+=(-DUSE_SDL1=ON)
else
TARGET_DEFINES="-DRETROFW=ON -DUSE_SDL1=ON"
defs+=(
-DUSE_SDL1=ON
-DRETROFW=ON
-DHAS_KBCTRL=1
-DKBCTRL_BUTTON_DPAD_LEFT=SDLK_LEFT
-DKBCTRL_BUTTON_DPAD_RIGHT=SDLK_RIGHT
-DKBCTRL_BUTTON_DPAD_UP=SDLK_UP
-DKBCTRL_BUTTON_DPAD_DOWN=SDLK_DOWN
-DKBCTRL_BUTTON_B=SDLK_LCTRL
-DKBCTRL_BUTTON_A=SDLK_LALT
-DKBCTRL_BUTTON_Y=SDLK_SPACE
-DKBCTRL_BUTTON_X=SDLK_LSHIFT
-DKBCTRL_BUTTON_RIGHTSHOULDER=SDLK_BACKSPACE
-DKBCTRL_BUTTON_LEFTSHOULDER=SDLK_TAB
-DKBCTRL_BUTTON_START=SDLK_RETURN
-DKBCTRL_BUTTON_BACK=SDLK_ESCAPE
-DKBCTRL_MODIFIER_KEY=SDLK_END
)
fi
cmake .. -DDINGUX=ON -DBINARY_RELEASE=ON ${TARGET_DEFINES} \
cmake .. ${defs[@]} \
-DCMAKE_TOOLCHAIN_FILE="$BUILDROOT/output/host/usr/share/buildroot/toolchainfile.cmake"
make -j $(nproc)
cd -
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,31 @@ Note that some features are not yet supported in SDL v1, notably upscaling, and

All games are encrypted and password protected.

# Controller support

DevilutionX supports gamepad controls.

Default controller mappings (A/B/X/Y as in Nintendo layout, so the rightmost button is attack):

- Left analog / DPad: move hero
- Right analog: simulate mouse
- A: attack nearby enemies, talk to towns people and merchants, pickup & drop items in inventory, OK while in main menu
- B: Select spell, cancel while in main menu
- X: pickup gold, potions & equipment from ground, open chests and doors that are nearby, use item when in inventory (useful to read books etc.)
- Y: cast spell, go to previous screen when talking to people and in shops, delete character while in main menu
- R1: inventory
- L1: character
- R2: drink mana potion
- L2: drink health potion
- Left analog click: quest log
- Right analog click: left mouse click
- Select: automap
- Start: game Menu, skip intro

For now, they can be re-mapped by changing `SourceX/controls` or by setting the `SDL_GAMECONTROLLERCONFIG` environment
variable (see
[SDL_GameControllerDB](https://github.com/gabomdq/SDL_GameControllerDB)).

# Contributing
[Guidelines](docs/CONTRIBUTING.md)

Expand Down
6 changes: 6 additions & 0 deletions Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ void CheckRportal()
}
}

// Controller support: Actions to run after updating the cursor state.
// Defined in SourceX/controls/plctrls.cpp.
extern void plrctrls_after_check_curs_move();

void CheckCursMove()
{
int i, sx, sy, mx, my, tx, ty, px, py, xx, yy, mi;
Expand Down Expand Up @@ -600,6 +604,8 @@ void CheckCursMove()
if (pcursmonst != -1 && monster[pcursmonst]._mFlags & MFLAG_GOLEM) {
pcursmonst = -1;
}

plrctrls_after_check_curs_move();
}

DEVILUTION_END_NAMESPACE
6 changes: 6 additions & 0 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,10 @@ void game_loop(BOOL bStartup)
}
}


// Controller support:
extern void plrctrls_after_game_logic();

void game_logic()
{
if (PauseMode == 2) {
Expand Down Expand Up @@ -1720,6 +1724,8 @@ void game_logic()
CheckQuests();
force_redraw |= 1;
pfile_update(FALSE);

plrctrls_after_game_logic();
}

void timeout_cursor(BOOL bTimeout)
Expand Down
1 change: 1 addition & 0 deletions Source/inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

extern BOOL invflag;
extern BOOL drawsbarflag;
extern const InvXY InvRect[73];

void FreeInvGFX();
void InitInv();
Expand Down
4 changes: 4 additions & 0 deletions Source/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ static void scrollrt_draw_cursor_item()
return;
}

if (sgbControllerActive && !invflag && (!chrflag || plr[myplr]._pStatPts == 0)) {
return;
}

mx = MouseX - 1;
if (mx < 0) {
mx = 0;
Expand Down
1 change: 1 addition & 0 deletions Source/scrollrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef __SCROLLRT_H__
#define __SCROLLRT_H__

extern bool sgbControllerActive;
extern int light_table_index;
extern BYTE *gpBufStart;
extern BYTE *gpBufEnd;
Expand Down
12 changes: 11 additions & 1 deletion SourceS/sdl2_to_1_2_backports.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
#define SDL_Log puts
#define SDL_floor floor

//== Events handling
Expand Down Expand Up @@ -47,6 +46,17 @@
// For now we only process ASCII input when using SDL1.
#define SDL_TEXTINPUTEVENT_TEXT_SIZE 2

#define SDL_JoystickNameForIndex SDL_JoystickName

inline void SDL_Log(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
puts("");
}

static SDL_bool SDLBackport_IsTextInputActive = SDL_FALSE;

inline SDL_bool SDL_IsTextInputActive()
Expand Down
28 changes: 28 additions & 0 deletions SourceS/sdl_compat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
// Compatibility wrappers for SDL 1 & 2.
#pragma once
#include <SDL.h>

#ifndef USE_SDL1
#define SDLC_KEYSTATE_LEFTSHIFT SDL_SCANCODE_LSHIFT
#define SDLC_KEYSTATE_RIGHTSHIFT SDL_SCANCODE_RSHIFT
#define SDLC_KEYSTATE_MENU SDL_SCANCODE_MENU
#define SDLC_KEYSTATE_UP SDL_SCANCODE_UP
#define SDLC_KEYSTATE_DOWN SDL_SCANCODE_DOWN
#define SDLC_KEYSTATE_LEFT SDL_SCANCODE_LEFT
#define SDLC_KEYSTATE_RIGHT SDL_SCANCODE_RIGHT
#else
#define SDLC_KEYSTATE_LEFTSHIFT SDLK_LSHIFT
#define SDLC_KEYSTATE_RIGHTSHIFT SDLK_LSHIFT
#define SDLC_KEYSTATE_MENU SDLK_MENU
#define SDLC_KEYSTATE_UP SDLK_UP
#define SDLC_KEYSTATE_DOWN SDLK_DOWN
#define SDLC_KEYSTATE_LEFT SDLK_LEFT
#define SDLC_KEYSTATE_RIGHT SDLK_RIGHT
#endif

inline const Uint8 *SDLC_GetKeyState()
{
#ifndef USE_SDL1
return SDL_GetKeyboardState(nullptr);
#else
return SDL_GetKeyState(nullptr);
#endif
}

inline int SDLC_SetColorKey(SDL_Surface *surface, Uint32 key)
{
#ifdef USE_SDL1
Expand Down
10 changes: 10 additions & 0 deletions SourceX/DiabloUI/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <memory>
#include <vector>

#include "controls/menu_controls.h"
#include "devilution.h"
#include "miniwin/ddraw.h"

Expand Down Expand Up @@ -259,6 +260,15 @@ BOOL UiCreditsDialog(int a1)
break;
case SDL_QUIT:
exit(0);
default:
switch (GetMenuAction(event)) {
case MenuAction::BACK:
case MenuAction::SELECT:
endMenu = true;
break;
default:
break;
}
}
}
} while (!endMenu && !credits_renderer.Finished());
Expand Down
Loading