Coder Social home page Coder Social logo

Comments (30)

glebm avatar glebm commented on April 28, 2024 4

I've made some Diablo PS1 screenshots with commentary: https://imgur.com/gallery/aXe0Vor

The biggest thing the PS1 version has in terms of controller support is Auto-Aim

from devilutionx.

glebm avatar glebm commented on April 28, 2024 4

Controller support is fully implemented in #395, give it a try.
Based on the Switch branch but with many bugfixes and improvements.

Controls (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

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024 3

Nice, thank you. We are going to tackle controller support/features as a separate issue. That way we can merge the Nintendo Switch code and then work on controller support for all platforms so that everyone benefits from improvements like the one you just mentioned.

from devilutionx.

ctrl-meta-f avatar ctrl-meta-f commented on April 28, 2024 1

JFYI, here is the minimal diff to enable SDL game controller in DevilutionX:

From 0e9cc57ee231105cb76ab6f6d3ce469b0d1dfff5 Mon Sep 17 00:00:00 2001
From: Anders Jenbo <[email protected]>
Date: Thu, 4 Jul 2019 23:59:31 +0200
Subject: Joystick


diff --git a/SourceX/DiabloUI/diabloui.h b/SourceX/DiabloUI/diabloui.h
index e30e8f64..ff52bceb 100644
--- a/SourceX/DiabloUI/diabloui.h
+++ b/SourceX/DiabloUI/diabloui.h
@@ -71,6 +71,8 @@ typedef struct UI_Item {
 	const void *context;
 } UI_Item;
 
+extern SDL_GameController *game_controller;
+
 extern TTF_Font *font;
 
 extern BYTE *FontTables[4];
@@ -95,6 +97,7 @@ constexpr size_t size(T (&)[N])
 
 extern void(*gfnSoundFunction)(char *file);
 
+void sdl_init_controller();
 bool IsInsideRect(const SDL_Event *event, const SDL_Rect *rect);
 void UiFadeIn(int steps = 16);
 bool UiFocusNavigation(SDL_Event *event);
diff --git a/SourceX/miniwin/misc.cpp b/SourceX/miniwin/misc.cpp
index 51791155..82cec493 100644
--- a/SourceX/miniwin/misc.cpp
+++ b/SourceX/miniwin/misc.cpp
@@ -30,6 +30,7 @@ unsigned int _rotr(unsigned int value, int shift)
 namespace dvl {
 
 DWORD last_error;
+SDL_GameController *game_controller;
 
 DWORD GetLastError()
 {
@@ -308,6 +309,22 @@ void FakeWMDestroy()
 	MainWndProc(NULL, DVL_WM_DESTROY, 0, 0);
 }
 
+void sdl_init_controller()
+{
+	const int num_joysticks = SDL_NumJoysticks();
+
+	SDL_Log("Found %i joysticks", num_joysticks);
+
+	game_controller = 0;
+	for (int i = 0; i < num_joysticks; ++i) {
+		if (SDL_IsGameController(i)) {
+			SDL_Log("Using game controller #%i named \'%s\'", i,
+			    SDL_GameControllerNameForIndex(i));
+			game_controller = SDL_GameControllerOpen(i);
+		}
+	}
+}
+
 HWND CreateWindowExA(
     DWORD dwExStyle,
     LPCSTR lpClassName,
@@ -349,6 +366,8 @@ HWND CreateWindowExA(
 		flags |= SDL_WINDOW_INPUT_GRABBED;
 	}
 
+	sdl_init_controller();
+
 	window = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nWidth, nHeight, flags);
 	if (window == NULL) {
 		SDL_Log(SDL_GetError());
diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp
index 669c58a2..b9b280e4 100644
--- a/SourceX/miniwin/misc_msg.cpp
+++ b/SourceX/miniwin/misc_msg.cpp
@@ -4,6 +4,8 @@
 #include "devilution.h"
 #include "stubs.h"
 
+#include "DiabloUI/diabloui.h"
+
 /** @file
  * *
  * Windows message handling and keyboard event conversion for SDL.
@@ -13,6 +15,13 @@ namespace dvl {
 
 static std::deque<MSG> message_queue;
 
+static struct {
+	SDL_GameControllerButton button;
+	int dvl_key;
+} controller_keys_mapping[] = {
+	{ SDL_CONTROLLER_BUTTON_DPAD_UP, DVL_VK_TAB }
+};
+
 static int translate_sdl_key(SDL_Keysym key)
 {
 	int sym = key.sym;
@@ -168,6 +177,26 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
 			return false_avail();
 		}
 	} break;
+	case SDL_CONTROLLERDEVICEADDED:
+	case SDL_CONTROLLERDEVICEREMOVED:
+	case SDL_CONTROLLERDEVICEREMAPPED:
+		sdl_init_controller();
+		break;
+	case SDL_CONTROLLERBUTTONDOWN:
+	case SDL_CONTROLLERBUTTONUP: {
+		int key = -1;
+		for (size_t i = 0; i < sizeof controller_keys_mapping / sizeof controller_keys_mapping[0]; ++i) {
+			if (SDL_GameControllerGetButton(game_controller, controller_keys_mapping[i].button)) {
+				key = controller_keys_mapping[i].dvl_key;
+			}
+		}
+		if (key >= 0) {
+			lpMsg->message = e.type == SDL_CONTROLLERBUTTONDOWN ? DVL_WM_KEYDOWN : DVL_WM_KEYUP;
+			lpMsg->wParam = (DWORD)key;
+		} else {
+			DUMMY_PRINT("Unkwnown controller event");
+		}
+	} break;
 	case SDL_MOUSEBUTTONUP: {
 		int button = e.button.button;
 		if (button == SDL_BUTTON_LEFT) {

GAMEPAD_DPAD - Arrow Keys

I believe using the left stick (GAMEPAD_LEFT_THUMB) is much more convenient, especially for diagonal moves.

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024 1

I also had an unexpected shutdown on the RG300, not sure if that is related, don't really have any debug info though.

Another thing though is that it is a bit odd that the attack button also interacts with doors since that can make combat hard when you are close to a door, and seams unnecessary since you can use the "use" button also.

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024 1

The check for distance is fairly primitive, it will probably target visible yet unreachable enemies (behind gate), i have made some suggestions for how to improve it. it would also be good to add priority to the one your facing.

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

Hi @ctrl-meta-f

We defiantly plan to have controller support. The PS and D3 sachems are a really good starting point, thanks for points the mappings.
@erfg12 has already started on implementing a POC: https://github.com/erfg12/devilution
https://i.imgur.com/Tdt9MuP.mp4

At this point most the work is on making the UI easy to navigate with a dpad/keyboard like like device.

from devilutionx.

ctrl-meta-f avatar ctrl-meta-f commented on April 28, 2024

Thanks for a quick reply!

Looks like @erfg12 mostly solved the first (and the hardest) problem, though he uses XInput API instead of SDL (which suits the X engine more and should support more controllers).

Are there any plans to merge the Part 1 of his plan (moving with WASD, picking/attacking things nearby, etc.) into the devilutionX engine in the near future?

I could then use his work to polish my cross-platform SDL-based code and prepare a pull-request.

from devilutionx.

erfg12 avatar erfg12 commented on April 28, 2024

sup. @ctrl-meta-f @AJenbo

Yeah I'm putting the finishing touches on my Devilution keyboard extension and game controller project. This will use XInput since using the SDL_Init(joystick || controller) function makes the game freeze. Once this is done (soon hopefully) I will move onto DevilutionX and importing my code into there along with proper SDL controller functionality.

from devilutionx.

erfg12 avatar erfg12 commented on April 28, 2024

Here's what I plan on using for the Xbox 360 controller:

GAMEPAD_A - SPACE key
GAMEPAD_B - I key
GAMEPAD_X - RETURN key
GAMEPAD_Y - X key
GAMEPAD_BACK - TAB key
GAMEPAD_START - ESCAPE key
GAMEPAD_LEFT_SHOULDER - H key
GAMEPAD_RIGHT_SHOULDER - C key
GAMEPAD_DPAD - Arrow Keys

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

This patch is failing in the latest revision (cb9ef7a) 😢

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

@neuromancer does it fail to apply or give an error?

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

This is the result after renaming SourceX/dx.h by Source/dx.h in the patch (since the file was moved)

$ patch -p1 < joy.diff 
patching file SourceX/dx.cpp
Hunk #1 FAILED at 443 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file SourceX/dx.cpp.rej
patching file Source/dx.h
Hunk #1 FAILED at 10 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file Source/dx.h.rej
patching file SourceX/miniwin/misc.cpp
Hunk #1 FAILED at 291 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file SourceX/miniwin/misc.cpp.rej
patching file SourceX/miniwin/misc_msg.cpp
patch: **** unexpected end of file in patch

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

I updated the patch so that it stays out of the Direct Draw (dx.cpp) code, use git apply joy.diff to apply it.

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

For some reason, it fails:

$ git apply joy.diff 
error: patch failed: SourceX/miniwin/misc.cpp:30
error: SourceX/miniwin/misc.cpp: patch does not apply

Are you sure you used cb9ef7a ?

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

Yes, and it still works for me, but just in case the issue is line endings or some other copy paste issue here it is as an attachment:
joy.zip

Can confirm that this actually works, not that it's of much use without additional mapping and some way to control the pointer.

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

This is now mostly implemented in #181 but some further work is needed before it will be merged into master. Note that this branch is currently broken on Mac.

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

Can confirm that this actually works, not that it's of much use without additional mapping and some way to control the pointer.

Is that solved in #181 ?

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

Yes, though there might still be some aspects that need some work.

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

If any one is able to extract the Game Controller code from #181 and clean it up so that is is ready for merge that would be a big help.

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

#181 needs a lot more of work to be merged? I tested a few months ago and it was working fine (in Linux).

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

@neuromancer I was actually just working on rebasing it on the latest master branch. Some of the issues where solved with in the past couple of weeks and the diff dropped by about 50 lines. But as you can see from it's check list there are still some outstanding issues that needs to be resolved before it can be merged.

The big issue is that it isn't clear where the Nintendo Swith platform code ends and where the game controller code start. I know that there are several features of the game controller code that are simply disabled and only the basics are functional on non-Switch platforms. There are likely also parts of the regular functionality that has been disabled or isn't performing correctly as a result of some of the changes that where done (you probably won't notice on non-Switch systems). Also as long as it breaks other platforms builds its simply a no go. All of this makes it over all very hard to maintain and as such it's not ready to be merged in to the main branch. The whole process isn't helped by me not having a Switch either, I do however have a game controller but probably won't have time to work a lot on it before we land 1.0.0 and Hellfire.

In case you have time it would be helpful if you can test that things are still working the same in my rebase branch: #271

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

@AJenbo you still need testing for #329 ? (#271 was closed/deleted)

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

@neuromancer a bit more testing on #329 would be nice, #271 has already become the new #181

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

I just tested the first level on #329. Taking with certain NPCs and melee combat works but IMHO the controller support needs a button to interact with objects (or certain people) nearby the player (when they are selected/identified). It is possible to click on objects manually using the controller, but it is too slow. Perhaps the Auto-Aim that @glebm mentions is a good solution.

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

You did a awesome job @glebm! I tested your branch for a few minutes, in the first dungeon and looks like it is definitely working as expected during combat (which was a big issue in the previous version of this feature). My only concern so far is the default for the Steam Controller (which I'm using, emulated as an xbox controller using sc-controller). When I started the game and arrived in the main menu, pressing the A button will close the game without any warning.

from devilutionx.

glebm avatar glebm commented on April 28, 2024

Another thing to improve is the top button should use the focused iventory item. Currently there is no way to read spell books.

from devilutionx.

neuromancer avatar neuromancer commented on April 28, 2024

Another thing though is that it is a bit odd that the attack button also interacts with doors since that can make combat hard when you are close to a door, and seams unnecessary since you can use the "use" button also.

I can confirm this is an issue when fighting with a large of enemies in small rooms .

Additionally, sometimes the attack button will make you face enemies outside the screen, the-hit-near-enemies feature is not always working as expected (perhaps the scope of this should be possible to configure, depending on how confident you are?)

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

Basic support is now merged to the main branch, thanks to @glebm @rsn8887 and @erfg12 for there part in this work.

from devilutionx.

AJenbo avatar AJenbo commented on April 28, 2024

Further improvement have been moved to this issue #418

from devilutionx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.