ptitSeb / hydracastlelabyrinth

A port to Linux (and OpenPandora / DragonBox Pyra / ODroid / PocketCHIP / GameShell / AmigaOS4 / MorphOS / Emscripten) of Hydra Castle Labyrinth (a "metroidvania" kind of game). Status: Working.
https://ptitseb.github.io/hydracastlelabyrinth/
GNU General Public License v2.0
84 stars 24 forks source link

amigaos4 build #3

Closed kas1e closed 5 years ago

kas1e commented 5 years ago

I was able to build binary for aos4, but then it crashes from start, i check the code and it has some getenv("HOME") things in the files:

main.c:

#ifdef __amigaos4__ strcpy(buff,"PROGDIR:.hydracastlelabyrinth"); #else strcpy(buff, getenv("HOME")); strcat(buff, "/.hydracastlelabyrinth"); #endif

ini.c in 3 places:

#ifdef __amigaos4__ strcpy(fullPath, "PROGDIR:.hydracastlelabyrinth/"); #else strcpy(fullPath, getenv("HOME")); strcat(fullPath, "/.hydracastlelabyrinth/"); #endif

and game.c in one place:

void game() { #ifdef _SDL #ifdef __amigaos4__ const char* home = "PROGDIR:"; #else const char* home = getenv("HOME"); #endif if(home) { #ifdef __amigaos4__ strcpy(savename, home); strcat(savename, ".hydracastlelabyrinth/"); #else strcpy(savename, home); strcat(savename, "/.hydracastlelabyrinth/"); #endif strcpy(savemap, savename); strcat(savename, "save.tmp"); strcat(savemap, "save.map"); } else { strcpy(savename, "data/save.tmp"); strcpy(savemap, savemap); } #endif

After that it create 640x480 window, write in console :

Hydra Castle Labyrynth, Windowed 640x480 scale=x2, using Joystik=1

Then it create for me .hydracastlelabyrinh directory in which "system.ini" file, and the it crashes on the PHL_LoadBMP() , which i assume again, because of different endianes :(

ptitSeb commented 5 years ago

Ah yes, maybe it needs some bigendian fixes. I'll check that.

ptitSeb commented 5 years ago

Ok, I have pushed some commit. Maybe it start now.

kas1e commented 5 years ago

Tried , nope, it crashes same on PHL_LoadBMP().. :(

When it build it produce some warning about :

amigaos.h:15:28: note: expected ‘uint32_t *’ {aka ‘unsigned int *’} but argument is of type ‘long unsigned int *’

and qda.c:53:12: warning: passing argument 1 of ‘BE32’ from incompatible pointer type , but they probabaly harmless ?

ptitSeb commented 5 years ago

Mmm, I would expect long unsigned int and uint32_t to be the same. Strange. (can you check if sizeof(long unsigned int)==4?)

Can you try to put some debug printf, because I haven't seen much bigendian trap in the code (the palette stuff maybe is wrong, but that shouldn't crash, just looks weird).

kas1e commented 5 years ago

Added debug to see where it crashes exactly, and this is sdl2/graphics.c , line 203, which are:

int tmp = fread(QDAFile, 1, headers[index].size, f);

Our fread :)

kas1e commented 5 years ago

And i can see, that before crash, it eat up about 800mb (!) of main memory, which mean something read/write in some very wrong way

ptitSeb commented 5 years ago

Can you printf("%d", sizeof(long unsigned int)); also ?

kas1e commented 5 years ago

Yeah, it is 4

ptitSeb commented 5 years ago

Strange. Just below the last BE32(...) in line 55 of qda.c can you add

printf("headers[%d]: offs=%p, sz=%d, bytes=%d\n", headers[i].offset, headers[i].size, headers[i].bytes);

To see what's going on...

kas1e commented 5 years ago

There is: http://kas1e.mikendezign.com/aos4/gl4es/games/hcl/hcl.txt

ptitSeb commented 5 years ago

Mmm, no I forget something. Here is the correct line:

printf("headers[%d]: offs=%p, sz=%d, bytes=%d\n", i, headers[i].offset, headers[i].size, headers[i].bytes);
kas1e commented 5 years ago

There is: http://kas1e.mikendezign.com/aos4/gl4es/games/hcl/hcl2.txt

ptitSeb commented 5 years ago

And there is the BE32(...) stuff before???

ptitSeb commented 5 years ago

Ok, found the issue, and just pushed a not commit

kas1e commented 5 years ago

Oh yes ! It runs, works, plays, i can heard sounds, but no music strangely .. is music works for you ?

kas1e commented 5 years ago

Anyway, music can wait for later, as whole game works, so i probabaly can give it to testers with joystick, to see how it works ?

ptitSeb commented 5 years ago

Music are midi tracks, so needs timidity on Linux to works. No ideas how midi music are played back on AmigaOS. (on some other platforms, midi are replaced with mp3 or something else because they can be tricky to use).

Yeah, testing joystick code will help (hopefully, that code just works).

kas1e commented 5 years ago

I know we do have timidy, probably i just need to install it , so music will just start to works. Will check it tomorrow.. Anyway, i send test archive to 2 testers, let's see how it will be. Hope it all will just works :)

kas1e commented 5 years ago

Got answer from one tester:

I tested the game with Competition Pro USB. The game character moves left, right, up and down with the joystick. But pressing fire buttons 1 and 2 nothing happens. Pressing buttons 3 and 4 the character moves left and right. The joystick was recognized automatically.

Is it mean our sdl2 need some more love or it expected to be like this ?

ptitSeb commented 5 years ago

I was expecting buttons to work. The Gamecontroller interface of SDL2 is very simple to use, and you don't need to setup any mapping in the program: when a controller is recognise, you simple have pad and buttons and everyhting already configured (well, of course there is the possibility to add a mapping at runtime). So I guess there is a small issue on Amiga side, with a not entirely recognise controler for example. I haven't tested much my implementation on linux, I'll try to do so soon. In the mean time, here is a page with some tuto on SDL Gamecontroller interface: http://lazyfoo.net/tutorials/SDL/19_gamepads_and_joysticks/index.php

kas1e commented 5 years ago

Aha ok, so its our sdl2 then. How in that game joystik buttons react on pandora ? Jumping ? Other buttons do nothing ?

ptitSeb commented 5 years ago

I don't need any joystick on the Pandora, there are some builtin game controller (that are wired to keys). Look at my Profile picture, it's a pandora. Or a bigger picture: pandora_gorynlich

kas1e commented 5 years ago

:) looks nice !

What i mean, is maybe in that game it exactly works like this : just up/down/left/right, and first 2 buttons do nothing , and 3,4st button also left/right just because nothing else is set on ?

ptitSeb commented 5 years ago

I have yet to try, but no buttons are supposed to something. In fact 3 of the 4 face buttons should do things, and also 2 triggers (shoulders buttons) and Start and select also do stuffs. Remember that Gamecontroller interface matchs somehow Xinput on windows, so targeting controller like the XBox360, with Pad, 2 Analogs, 4 faces buttons, 4 triggers and a start and back buttons...

kas1e commented 5 years ago

Got an answer from our SDL2 developer, and that what he say:

It supports only one joystick currently, Competition Pro. Some pads like XBOX-360 and Steam controller were not recognized by AmigaInput so they cannot be used right now. Reference: https://github.com/AmigaPorts/SDL/blob/master/src/joystick/SDL_gamecontrollerdb.h#L590

This database can be appended by using test/controllermap which generates entries. I have made a test archive available ( http://capehill.kapsi.fi/sdl2/SDL_joystick_test.lha ) that can be used to:

1) test (AI-compatible) joystick: testjoystick 2) test gamecontroller (Competition Pro only!): testgamecontroller 3) configure mappings: controllermap. If you have some joystick you can send the mappings to me or make a PR on Github.

I just tested Competition Pro using test/testgamecontroller application. Directions worked, same with four buttons: A, B, X and Y.

But for tester something still wrong with HCL .. go figure ..

ptitSeb commented 5 years ago

So, I finaly tested on my side... and yes, it doesn't work :( I have the same behaviour as your tester.

I'll fix that.

ptitSeb commented 5 years ago

Ok, I think I have fixed it now. Check with latest commit (by the way, it's a pretty nice game).

kas1e commented 5 years ago

Cool ! Sended it to tester, wait for his answer, but probabaly all will be fine then. Also will try to deal with timidy on my setup, and then can release aos4 version of HCL as well :)

kas1e commented 5 years ago

Have answer about new build:

Now fire buttons 1 and 2 are jump and attack but I can't move the character any more with the new build.

ptitSeb commented 5 years ago

Really? Strange. How that controller looks like? The character movement, is this done using analog stick or dpad?

kas1e commented 5 years ago

Waiting answer from tester, but strange that before only up/down/left/right works, and no fire/jump buttons, but with last gix buttons start works, but no left/right/up/down.

On linux all fine ?

ptitSeb commented 5 years ago

I couldn't test completly on linux yesterday.

The direction was working before it was the "Joystick" interface that was working, not the Gamecontroler that was not enabled. So enabled Gamecontroler interface and made sure to not use Joystick interface if the joystick is recognised as a Gamecontroleur (so the mapping is correct out-of-the-box)

kas1e commented 5 years ago

Tester didnt answer at moment, just want to be sure that on linux all allright so issue on our side.

Or, i just need to buy Competition Pro and all can be tested easy :)

ptitSeb commented 5 years ago

My son just tested on Linux (with an XBox360), and it worked perfectly.

kas1e commented 5 years ago

Did i understand right, that there is 2 ways to handle joysticks in SDL2 apps ? One are SDL joystick API and another one is SDL game controller API ?

kas1e commented 5 years ago

Btw, found probabaly another endian issue : when i play in game, then exit, then start it again , i have words "ops, blalbal you need to load blblalb" , so i choice "load game", and it crashes then in the game.c:945, hcl:LoadScreen()

ptitSeb commented 5 years ago

Yes. The Joystick API is the legacy API. It was already present in SDL 1.2, and basically, every joystick works with this API. The issue with this API is that every Axis (i.e. analog parts) and every buttons (and also, Hats, that most of the time are DPad) are just Numbers. You don't know which number is which physical button on the jostick, unless you use the Joystick name (the API can provide that) with some mapping... The Gamecontroller API just does that. It has a database of joystick and provide a unified API. You just ask for Button 'A' or X axis from left Thumb...

ptitSeb commented 5 years ago

Btw, found probabaly another endian issue : when i play in game, then exit, then start it again , i have words "ops, blalbal you need to load blblalb" , so i choice "load game", and it crashes then in the game.c:945, hcl:LoadScreen()

Yes, probably, I'll look into that latter.

ptitSeb commented 5 years ago

Can you try with latest commit, hopefully the crash at reload is fixed.

kas1e commented 5 years ago

Sec, will check. But just in case , for us PROGDIR:data/ and just "data/" , mean the same - directory from which we run binary.

I also tryied to run 3 times old binary and doing "load game", and for second load game it didn't crash, just saying map not found, and for 3st run, it loads new game.. Strange..

Is there any button so i can do "save game", to see if it works for save/load ?

ps. i also install "timidity" , and music works !

ptitSeb commented 5 years ago

Yeah I just added "PROGDIR:" just in case. I don't see any potential crash, but I guess there is still some bigendian issue. I need to think about it more.

And no, there is no "Save". It's automatic, and design to forbid abuse of the save system. The save state is created when you quit, and is delete when you load it...

ptitSeb commented 5 years ago

Ok, I have pushed something for the Load/Save issue, if you can try.

kas1e commented 5 years ago

As for competition pro and whole joystick's thing..

Testers send me a link on, it is digital stick + 4 buttons: https://www.speedlink.com/en/COMPETITION-PRO-USB-SPORTS-TOURNAMENT-EDITION-EU-VERSION-BLACK-RED.html

Also i bring on SDL2's os4 mantainer all the question about, and that what he answer:

I checked some code, HCL makes an assumption that there are leftx/lefty axes defined: https://github.com/ptitSeb/hydracastlelabyrinth/blob/master/src/sdl2/input.c#L201 Competition Pro has mapping for only rightx/righty: https://github.com/AmigaPorts/SDL/blob/master/src/joystick/SDL_gamecontrollerdb.h#L590 Regarding joystick API, I don't know right now what are the button numbers for Competition Pro. Probably from 0 to upwards, I have used "0" in Super Methane Bros and some other apps. Then again, if we check Hydra code, buttons 0-3 set directions: https://github.com/ptitSeb/hydracastlelabyrinth/blob/master/src/sdl2/input.c#L156 What exactly should happen when joystick fire buttons (Comp Pro has 4) are active?

ps. will check soon that load/save stuff

ptitSeb commented 5 years ago

So, ok, only Right axis and no Left axis explain why there is no direction with Competition Pro. I'll do a #ifdef to add right axis on amiga. The choice to use Right axis and Left is a bit strange, I would assume default to be left, but it doesn't matter much, I'll adapt the code.

For the buttons, that mapping is when using the Joystick interface, not the Gamecontroller one. Anyway, that mapping is bad, and I'll just put some default value, not that xbox360 mapping (that will be used in Gamecontroller mode anyway).

kas1e commented 5 years ago

I mostly about if we need to fix something in SDL2 to make it all be easy to use later when crosscompile anything else (so we will have no needs for ifdef amiga)..

kas1e commented 5 years ago

Btw, for making "save" working, all i need its start game, pass one screen, then press "esc", choice exit, and by logic it should do "save" ?

kas1e commented 5 years ago

And i think i found some bug : if you run HCL in window mode, and then press "Close gadget" on the window, then, instead of quit, its instead start a new game. Like, it send wrong break, or not full interrupt main game's code.

ptitSeb commented 5 years ago

So I have pushed some commits. I fixed the "Quit" by GUI issue. I forced the use of Right Stick for Gamecontroller on Amiga, and used simpler button and axis mapping on Joystick mode. Now, for Gamecontroller, the idea behind this API is to propose a Plug'n Play way to use a joystick: you plug it in, and because the Layout and mapping is standardized (look at XB360, XBOne, PS3 or PS4 controlleurs: they all offerts similar basic functions on a similar layout: left and right stick, left dpad, 4 fae buttons, 4 triggers, 1 back and 1 start buttons basically). So, for Gamecontroller, the point is to not have any config screen, it just work, with a fixed layout.

For joystick, a config screen would be needed. But as I don't like programming GUI, I don't think I'll do that (plus, it's a long and tedious work to program that GUI for joystick option for just 20 sec of use). I will, maybe, think about some config field in the config file...

kas1e commented 5 years ago

Did i understand right, that in Hydra you have support at the same time 2 apis ? Joystick one and Gamecontroller one ? And if so, which one are in favor ? I mean, you says that for buttons some mapping was used in Joystick mode, so i just looses there :)

Also, about axis, didn't SDL offers a way to query axis and in case of failure, return NULL ? If so, it can be better to not have any ifdefs, but just do query all those 6 or how many axis SDL provide, and those which is not NULL are our ones.

As for Joystick interface in whole : for sure it have no needs to be supported. Programming gui (always new) for every new port its just boring and not interesting work for sure. Its enough to just deal with Gamecontroller, write one time good code which works everywhere, and then just copy+paste it all the time . Programming gui its really time consuming and not worth of it

ptitSeb commented 5 years ago

For Hydra I do that: I query SDL if there is at least 1 joystick connected. If yes, I try to use Gamecontroller API first. If the joystick is recognized as a Gamecontroller by SDL, I use that API. If not, I fallback to Joystick mode.

About Axis, yes, you can query SDL the number of Axis, Buttons and Hat per joystick. I don't do that because I have no configuration screen, so that information is useless, plus I simply used the the X & Y of the Axis 0, nothing fancy here (well, for the Joystick interface, because for the Gamecontroller interface I took the left stick because it's the one you normally use for Movement, the Right Stick is for Camera usualy).