ptitSeb / gorynlich

gorynlich, 2d platform dungeon romp. Version adapted for the Pandora. Status: Working (but a bit slow)
3 stars 0 forks source link

amigaos4 port #1

Open kas1e opened 4 years ago

kas1e commented 4 years ago

Howdy ! Its me :)

So, to make amigaos4 version possible need to add those changes:

  1. src/backtrace.c

replace all #ifndef _WIN32 (in 1 place) and #ifndef WIN32 (in 5 places) , on #if !defined(_WIN32) && !defined(__amigaos4__)

  1. src/main.h

at top change as for Pandora to use float instead of double:

#ifdef __amigaos4__
 #undef Double
 #define Double float
#endif

and get rid of "#error KO":

#ifdef NEON
 #include <arm_neon.h>
#else
#ifndef __amigaos4__
 #error KO
#endif
#endif
  1. src/time_util.h

line 72 : #if 1 change on #if 0 for amigaos4 line 103: #if 1 change on #if 0 for amigaos4

  1. src/term.c

replace all #ifndef _WIN32 on #if !defined(_WIN32) && !defined(__amigaos4__)

  1. src/main.c

at moment comment out execve():

#ifndef __amigaos4__
#ifdef _WIN32
    execve(executable, (const char *const *) args, 0);
#else
    execve(executable, (char *const *) args, 0);
#endif
#endif

And that all. + changes in makefiles , but that can go for latter (i can create just makefile.os4 and makefile_os4.ramdisk).

Now, when i run game, i have as usuall for big-endian inverted colors. As well, as menu didn't draws (or just can't be seen) and character at left also can't be seen.

There is screenshot of menu:

http://kas1e.mikendezign.com/aos4/gl4es/games/gorynlich/gorynlich_1.jpg

Then, i check how it all loads, and find out that its load_image() from tex.c. And that one for sure have ENDIAN checks. So, for sake of tests, i comment out big-endian ifdefs in that functinos, and wtf , colors start to be right ! Check this out:

http://kas1e.mikendezign.com/aos4/gl4es/games/gorynlich/gorynlich_2.jpg

Through, menu not visibly still, and no character visibly at left bottom of screen.

And strange, why removing of endian ifdefs make colors be better , but not in other way :)

kas1e commented 4 years ago

Music plays fine btw , etc. And clicking on any area where is menu for play game, in 90% of times cause

DYING: Died at util.c:myzalloc_():21
FATAL ERROR : No memory(1 384 241 048) , map_jigsaw.c:generate_level():3099

But that probabaly also same endian issues there .. But if it for real want 1.3gb to alloc, then that probably will fail for sure..

kas1e commented 4 years ago

And some more things to add:

  1. in src/stb_image.c add #include <string.h> , to avoid warnings about memset. That one probabaly can be added for all platforms, not amigaos4 ifdefed.
  2. there is makefile for amigaos4: http://kas1e.mikendezign.com/aos4/gl4es/games/gorynlich/Makefile.aos4

Interesting that there is that stb_image.c file at all, if i remember right, we have some issues with back in past (with prototype?) , or it was something else ..

Also what make me curious, we have in main makefile include of both Makefile.ramdisk.deps and Makefile.ramdisk, but none of them is used , so maybe we can just delete them ?

kas1e commented 4 years ago

Oh, i found ! Its indeed want to alloc 1.3gb by default seems so ? I just add the same change as you do on Pandor inside of map_jigsaw.h , i.e.:

#if defined(NEON) || defined(__amigaos4__)
#define JIGPIECE_MAX                    10000
#else
#define JIGPIECE_MAX                    20000
#endif 

And levels can be starts more offten. Through one time when i die, i have the same error again, just this time it wasn't 1.3gb , but 692 mb. Which is probabaly also too much to allow for me, so maybe set it to 5000 will be the safe side ? Or even 1000 so to be 100% safe. If of course, it not cause some impact on something very important.

Also offten i have now another error when about to start a level (after i set it to 10000) :

DYING: Died at map_jigsaw.c:dieat():278
FATAL ERROR: Died at line 1982, col 0: expecting start of line

But when i was still able start level, it looks like this: http://kas1e.mikendezign.com/aos4/gl4es/games/gorynlich/gorynlich_3.jpg

(that with commented out SDL_ENDIAN check in the load_image() from tex.c).

Seems everything renders more or less fine, just no Text (same as in menu), and probabaly some textures missing still (same as in menu, where i miss that character at left).

ptitSeb commented 4 years ago

Ah, I had forgot to activate the "Watch" feature on this repo, and I hadn't been notified you openned a ticket.

Lot's of stuff here, interresting. I'll look deeper tomorrow. (also, why the BigEndian was not needed: probably because the glTexture created with the data is also bigendian ready, so no need to swap bytes 2 times).

kas1e commented 4 years ago

Tring to check in meantime why fonts didn't renders, so as i can see , src/ttf.c is handle it all, and maybe something with Endianes there. It didn't have any fread() or fwrite(), but it did have some structures there and there. For example "glyph" structure are full of "doubles" , "glyphtex" structure have one int32 (for texture exactly, so maybe that one need to be converted). Will check it more

ptitSeb commented 4 years ago

Maybe the texture built with / for the glyph is inverted, and alpha end's up beeing empty? I have to check all this code, but I haven't yet.

kas1e commented 4 years ago

Have some more news about : i just enable in config file ENABLE_GENERATE_TTF define (that used in the font.c and ttf.c files), and then, font start renders !

http://kas1e.mikendezign.com/aos4/gl4es/games/gorynlich/gorynlich_4.jpg

It is through seems on running always generate something a little, but fonts and lettrs now visibly. Dunno if it point out us on something related to the how to make it works without ENABLE_GENERATE_TTF define ? Probabaly it point out us only on the fact that fonts loads fine, etc, just didn't visibly. Like, fonts coming as data files are big-endian or something with alpha in them ..

Through, that didn't fix issue with non-drawing character in menu at left-bottom, and in the intro there is no background too (that probabaly same issue in both cases).

But what at moment is not that good, is FPS ! It just suck :)

On my windows machine, i have in menu : 300 fps, on amigaos4 have 150fps in meanu : ok, kind of expected. But in the game itself, when do "quick start", then on windows machine i have ~160 fps, but on amigaos4 just a 25-35 fps only ! Was expected to have at least 60, or 80, but 25-35 :(

I tried LIBGL_BATCH 40, but that make no differences (even make it a little slower)

There is screenshot from gamesplay when there is no enimies, almost nothing to render, and it's 36 fps :) :

http://kas1e.mikendezign.com/aos4/gl4es/games/gorynlich/gorynlich_5.jpg

I also think that something is wrong with 2d blitting in some functions (or just in general in aos4 driver, or, which unluckyly, gl4es ). Why i think is it , its because i notice already in few games, that some operations which is pure "Scrolling" are slow. I can't say when exactly, but at least in the Foobillard++ , when you press on gadget for drop-down menus, those menus moves pretty slow. Same with Logo of Gorynlich in the menu : it scrolls not very smooth. Dunno what can be cause of it and how to debug it .. But that probabaly for the latter.

ptitSeb commented 4 years ago

Mmm, now that have used ENABLE_GENERATE_TTF, I think you have generated new tga with font. So I guess the endianness is fixed. Do some git status to see if some tga have changed.

A note about FPS. I do have slow speed on the Pandora too. I checked to see if it was the Graphics, but it doesn't seems so. I think it's more CPU constraint. I'm unsure, but that was my quick analysis shown.

kas1e commented 4 years ago

Mmm, now that have used ENABLE_GENERATE_TTF, I think you have generated new tga with font. So I guess the endianness is fixed. Do some git status to see if some tga have changed.

Yeah you are right. I didn't compare files through, i just rebuild gorynlich with disabled generation of ttf (but keep those font tgas which was generated), and then it runs fine and font there. So, it mean that tga files can be of different endian type ?

That probabaly mean, that i need somehow to convert other tga files to big-endian ones (like background in the intro , that characters at the left-bottom screen, etc). Strange through, that logo, and chest , and some other thigs draws as it , while all the data files are .tga..

ptitSeb commented 4 years ago

It would be better to fix the reading. The function is ttf_read_tga from src/ttf.c I haven't seen what could go wrong in a quick look, but there must be something there.

ptitSeb commented 4 years ago

Mmmm, in fact, I think line 686, the memcpy(f->glyphs, glyph_data, sizeof(f->glyphs)); : that f->glyphs needs to be byteswapped !

kas1e commented 4 years ago

What i also noticed, is that in the every message in the "intro" , the last letter always missing. Maybe that cause of some memory issues (and as usuall visibly on amigaos4 better), and that the reassons why there is no background in intro, and in menu i didn't have those characters at left-bottom.

Interestingly, is that if i choice "play game", and start move up/down keys, i actually can see how characters appears to be visibly there when they scrolls to the right side, and then should shown on the left side with small scroll : but that didn't happens. I.e. i press let's say there "down", and can see how character scrolls to the right side, then, it should scrolls a bit from the left side and stop : but that didn't happens. I can't see scroll from the left side.

I also found that i can see last character "wizzard" be visibly. But that one appears like this: scrolls to the right side as should, and then i see no scrolling from the left, and then bum, character shows.

I probabaly vaguely explain it all, can made a video, but it all looks like that reading is fine of those "characters" tgas, just by some reassons they not visibly when should.

kas1e commented 4 years ago

Mmmm, in fact, I think line 686, the memcpy(f->glyphs, glyph_data, sizeof(f->glyphs)); : that f->glyphs needs to be byteswapped !

Do you mean something like:

   memcpy(f->glyphs, glyph_data, sizeof(f->glyphs));

#ifdef __BIG_ENDIAN__
   int r;
   for (r = 0; r < sizeof(f->glyphs) / 2; r++)
   {
            f->glyphs[r] = SDL_SwapLE16(f->glyphs[r]);
   }                        
#endif

?

ptitSeb commented 4 years ago

Yes, but no. glyph is a large stucture, full of double... So it will be more like:

#ifdef __BIG_ENDIAN__
   int r;
   for (r = 0; r <= TTF_GLYPH_MAX; r++)
   {
            f->glyphs[r].width = SwapDouble(f->glyphs[r].width);
            f->glyphs[r].height = SwapDouble(f->glyphs[r].height);
            f->glyphs[r].minx = SwapDouble(f->glyphs[r].minx);
            f->glyphs[r].maxx = SwapDouble(f->glyphs[r].maxx);
            f->glyphs[r].miny = SwapDouble(f->glyphs[r].miny);
            f->glyphs[r].maxy = SwapDouble(f->glyphs[r].maxy);
            f->glyphs[r].advance = SwapDouble(f->glyphs[r].advance);
            f->glyphs[r].texMinX = SwapDouble(f->glyphs[r].texMinX);
            f->glyphs[r].texMaxX = SwapDouble(f->glyphs[r].texMaxX);
            f->glyphs[r].texMinY = SwapDouble(f->glyphs[r].texMinY);
            f->glyphs[r].texMaxY = SwapDouble(f->glyphs[r].texMaxY);
   }                        
#endif

And before, you need to define SwapDouble, with:

static double SwapDouble(double a)
{
    Uint64 r = SDL_SwapLE64(*(Uint64*)&a);
    return *(double*)&r;
}
kas1e commented 4 years ago

Oh, you mean to byteswap whole strucutre, yeah, that did the trick ! now text renders with fonts coming by default in data archive from repo.

Through last letter still missing in all the test in the intro, same as if i use auto-generated big-endian fonts.

I.e. on win32 firt phrase in intro:

"For millenia, the dwarfes of old"

on my build it

"For millenia, the dwarfes of ol" (last "d" missing). And the same for all other phrases in intro.

Is on pandora you have first phrase in intro with last "d" at end, or it missing as well ? It can be very well some buffers-issues in the game itself

kas1e commented 4 years ago

Also at right-bottom we should have goblinhack@gmail.com, -- version 0.0.6, and i found that string in the wid_intro.c :

static void wid_version_make_visible (void *context)
{
        widp w = wid_popup(
                  "%%fg=green$goblinhack@gmail.com, -- version 0.0.6",
                  "",               /* title */
                  0.8f, 0.95f,      /* x,y postition in percent */
                  0,                /* title font */
                  vsmall_font,      /* body font */
                  0,                /* button font */
                  0);               /* number args */
        wid_set_no_shape(w);
        wid_destroy_in(w, 60000);
}

But that "6" at end also didn't visibly. And for me it looks like goblinhack@gmail.com, -- version 0.0. on title screen (i.e. no 6). Is on Pandora it visibly ?

ptitSeb commented 4 years ago

I don't remember. I'll have to check on the Pandora tonight if I have the same issue. Also, I'll try to build vanilla version of Gorynlich on linux to see how it behave (just in case my numerous changes broke something)

kas1e commented 4 years ago

Yeah, thanks a bunch ! I also found that my cursor is "blue" instead of "yellow", but that easy probabaly to remove somewhere same SDL_ENDIAN check as it was for main titles before.

kas1e commented 4 years ago

Yeah, removing all #if SDL_BYTEORDER == SDL_BIG_ENDIAN code in the src/tex.c , make not only colors be fine in title screen, but also make cursor be yellow instead of blue, as should be.

Btw, is levels always generated even if there is levels directory ? What i mean, is that once i do for example "Quick Start" it's in 90% of times saying:

00:00:33.851: Client: Level 1.1[0x200b9008] (client): created
00:00:33.955: Server: Level 1.1[0x1fb49008] (server): created
00:00:33.957: Server: Level 1.1[0x1fb49008] (server): Level generating
00:00:35.627: DYING: Died at map_jigsaw.c:dieat():278
00:00:35.628: FATAL ERROR: Died at line 1982, col 0: expecting start of line
00:00:35.630: ERROR: FATAL ERROR: Died at line 1982, col 0: expecting start of line
00:00:35.630: ERROR: FATAL ERROR: Died at line 1982, col 0: expecting start of line
00:00:35.729: Client: Level 1.1[0x200b9008] (client): destroy
00:00:35.730: Client: Level 1.1[0x200b9008] (client): destroyed
exit(1) error
LIBGL: OGLES2 Library and Interface closed
LIBGL: Shuting down

While "data/levels" have all of them already there.

Strange .. Maybe its the same effect of bug with missing characters at end ..

ptitSeb commented 4 years ago

Yes, levels re always generated. If I remember correctly, the data/levels folder contain "blocks" of level, that are then used by the level generator to build actual levels. On the Pandora, it doesn't die (not that I remember of), but I do need a quite large swapfile (like 1,3 GB of RAM used during level generation, or something like that).

kas1e commented 4 years ago

On amigaos4 we have some sort of "extendent memory" , kind of it was in old DOS when they used chunky memory . I.e. by default i have free about 1.8gb (because of 31 bit addressing) , but can use some specific code to have more (probabaly need to write own malloc(), etc, but it will be fits pretty well in the game where he already have myalloc() ).. So in worse scenario, i can use that.

Just this error didn't looks like memory error, when its can't allocate, it usually says something like can't allocate and die in myalloc(). But once i replace in map_jigsaw.h JIGPIECE_MAX to 10000 (as it done for Pandora), i almost never meet with that malloc error, but instead with that one. And line 1982 in that map_jigsaw.c are:

dg->frag_alt[dir][c].c[JIGPIECE_WIDTH - 1 - y][x] = dg->frag_alt[dir-1][c].c[x][y];

Which didnt' looks like problem with malloc , but more like it can't find something which should find.. And comment at top of block from where that line, saying that it just for "Rotate 90 degrees".

ptitSeb commented 4 years ago

There is, maybe, some bigendian issue with level "basic block" loading, leading to this error...

kas1e commented 4 years ago

Yeah, i rechecked, and yes, when i have no memory, i just have something like this:

00:00:40.207: Client: Level 9.9[0x17c760c8] (client): level loaded
00:00:46.496: DYING: Died at util.c:myzalloc_():21
00:00:46.498: FATAL ERROR: No memory(121900776), wid_editor.c:wid_editor():4051
00:00:46.499: ERROR: FATAL ERROR: No memory(121900776), wid_editor.c:wid_editor():4051 

So its probably indeed something with endianes there, as lots of [] [] and stuff used. Through, when it level loads (that happens sometime still), all other parts looks correct : enemies, move, main character, fonts, textures, etc ,etc.

kas1e commented 4 years ago

And i just tried to comment out that block about "Rotate 90 degres" , and now it start bring again not-enough-memory errors :)

So probabaly in terms of that bug i need firstly implement extendent memory support then..

ptitSeb commented 4 years ago

stuff like that: https://github.com/ptitSeb/gorynlich/blob/master/src/map_jigsaw.c#L3118 probably need some byte reordering... To be checked later.

kas1e commented 4 years ago

Interesting why he (author) choice that unusuall way to do things, i mean, i never ever thinking about malloc 1.6gb, or 2gb at one push. And, what is more funny, is not the kind of game which need that much. Visually it dind't looks that impressive, mostly like some oldshcool game from amiga era. Strange why and for what all those resourses wastes..

edit: it seems that "Read jigpiece header" may have issue. At least, "expecting start of line" words i found right at top of part about reading jigpiece header. Or maybe memory can't allocated, and so he fail only there .. But from another side i can see that memory checked, and if can't be allocated there should be error about.

kas1e commented 4 years ago

Oh, and actually what is interesting : is not always generate levels ! It seems it use generated ones, just dunno why sometime are, sometime not.

For example, now was succefull running, and it didn't eat much memory, and that what i have in output:

00:00:20.322:  
00:00:20.324:           Welcome to the Gorynlich console!
00:00:20.326:  
00:00:20.328: Press <tab> to complete commands.
00:00:20.329: Press ? to show command options.
00:00:31.642: Client: Level 1.3[0x4b1ca008] (client): created
00:00:31.985: Server: Level 1.3[0x4ac49008] (server): created
00:00:31.988: Server: Level 1.3[0x4ac49008] (server): Level Work:games/gorynlich/data/levels/1.3: loading
00:00:32.447: Server: Level 1.3[0x4ac49008] (server): Reset players at start of level
00:00:32.449: Server: Level 1.3[0x4ac49008] (server): level loaded
00:00:32.451: Server: Level 1.3[0x4ac49008] (server): Allocate trigger, white
00:00:32.453: Server: Level 1.3[0x4ac49008] (server): No action trigger exists, activate trigger, white
00:00:32.456: Server: Level 1.3[0x4ac49008] (server): Activate trigger, white
00:01:08.025: Client: Level 1.3[0x4b1ca008] (client): destroy
00:01:08.027: Client: Level 1.3[0x4b1ca008] (client): destroyed
00:01:09.831: Server: Level 1.3[0x4ac49008] (server): destroy things and players
00:01:09.860: Server: Level 1.3[0x4ac49008] (server): destroy
00:01:09.861: Server: Level 1.3[0x4ac49008] (server): destroyed
Exited
LIBGL: OGLES2 Library and Interface closed
LIBGL: Shuting down

See, it load the stuff, not generate !

Probabaly it possible somehow hardcore setup to only load levels, and never generate (that will be more than enough imho). Also it looks like they already generated, just by some reassons regeneration starts again ..

At least that how i see it now

kas1e commented 4 years ago

..

ptitSeb commented 4 years ago

Gorynlich use fixed pipeline only, no shaders.

I'll try to check all this generation / level loading stuff.

kas1e commented 4 years ago

Thanks !

Yeah, i just rechecked : there is just few shaders created (very simple ones) by gl4es, so to have just 2d working. Also i made a profile of it and at least in the intro and menu, it use only glDrawArrays() for drawing

ptitSeb commented 4 years ago

So. I'm back home and done a quick test on the Pandora.

  1. I also have the missing last letter issue ?! gorynlich01 I'll investigate on what is happening !

  2. On the Pandora, I can use GLES 1.1 or GLES 2.0 backend. Gorynlich seems significantly faster with GLES 1.1 backend. I have to investigate also to see if it's normal or not.

ptitSeb commented 4 years ago

I built my version of gorynlich on a linux and ran it without gl4es: same missing last character... So at least it's not gl4es. I'll now try with original version of Gorynlich.

ptitSeb commented 4 years ago

And I built the original, and the error is there too! So it's not my port either!

ptitSeb commented 4 years ago

And I found the issue of the last character missing and just pushed a fix

ptitSeb commented 4 years ago

And I pushed all the AmigaOS4 changes also.

kas1e commented 4 years ago

Yeah, it is !

Now, there is video how it looks like on my side: https://youtu.be/DC50C_sXsxY

There you can see those issues :

  1. no background images in intro
  2. no character at left-bottom in the main menu
  3. when press "play game" and do switch between menus, the only visibly right-scroll of characters, without left one, and in end no characters shown, except only wizzard one.

Can you check how it all on Pandora in that terms ?

kas1e commented 4 years ago

I built my version of gorynlich on a linux and ran it without gl4es

Btw, how in terms of fps when you build it over linux with and without gl4es on the same machine ?

Gorynlich seems significantly faster with GLES 1.1 backend.

How it in terms of fps ? I.e. for example in menu, and in any level. Like GLES2 give 15 fps, and GLES1 50 or something ?

ptitSeb commented 4 years ago

I built my version of gorynlich on a linux and ran it without gl4es

Btw, how in terms of fps when you build it over linux with and without gl4es on the same machine ?

Gorynlich seems significantly faster with GLES 1.1 backend.

How it in terms of fps ? I.e. for example in menu, and in any level. Like GLES2 give 15 fps, and GLES1 50 or something ?

I haven't done any measurement of speed yet. Let's have something that work first, and I woul dlike to try reduce the memory needed also before.

ptitSeb commented 4 years ago

Yeah, it is !

Now, there is video how it looks like on my side: https://youtu.be/DC50C_sXsxY

There you can see those issues :

  1. no background images in intro
  2. no character at left-bottom in the main menu
  3. when press "play game" and do switch between menus, the only visibly right-scroll of characters, without left one, and in end no characters shown, except only wizzard one.

Can you check how it all on Pandora in that terms ?

Everything works as it should. No problem on the Pandora.

kas1e commented 4 years ago

Everything works as it should. No problem on the Pandora.

Interesting that for all of them used the same texture loading function.. With missing background in intro it can be probably something with transparency, but strange effect of those "no left-scroll visibly"

kas1e commented 4 years ago

I watch closer in intro, and i can see, that for a second, image appears to be visibly, and then black. Every new portion of intro (with new intro's background) always show a image for a second, and then black screen.

ptitSeb commented 4 years ago

So imgae is loaded and then a black something is put on top? Maybe an issue with some fade-out effect? I'll check later.

kas1e commented 4 years ago

It looks like it even didn't reach full alpha of 1 , its like fade in effect starts, and reach maybe half of it (or , it may reach till final, just disappear fast), but what i can notice, is that around 50% of fade in effect happens for half of second, and then all black. Will check maybe fade in effect have something in terms of alpha change

kas1e commented 4 years ago

Btw, found in meantime, that game do not free resources correctly even if you just run it (till menu) and then exit from menu without actuall running of game. I checked sdl.c , and it did have :

        SDL_GL_DeleteContext(context);
        SDL_DestroyWindow(window);

So all fine (And i checked via printf that this part is working) and its not that usuall missing part because of which we have non-freed resources, but something else in the code of game itself.

It didn't free big part of the memory (about 130 mb!) , and didn't free about 6 mb of gfx data. Its just when you only run it , and exit from menu right away. I assume, that this non-freed memory can be also issue when we start actual game (like, those 130 mb which can't be freed , can't be used for allocation for the levels).

ptitSeb commented 4 years ago

Can you open a new ticket about the Texture not appearing on amigaos4 port? I'll have some test for you to make to try figuring out what's wrong, but this issue is already long, I would prefer to do that on a new fresh thread.

kas1e commented 4 years ago

Yeah, created, thanks !

kas1e commented 4 years ago

Now .. what next , reducing memory usage ? But probabaly its will be not very possible to reduce it 2-3 times ?

From my side i found another bug yesterday, when implemt amigaos4-restart code : when restarting, game didn't close ourself, don't free resources, etc ,etc , it just like rerun another copy, with eating the same gygabytes. Probabaly there need to add cleaning of resources before: like, just full exit from game, and then only call the execute of binary.

Also its still unclear, why sometime levels generated, but sometime just loaded.

kas1e commented 4 years ago

Btw, Daniel fix both issues with glScissor(), but if you doesn't mind keep that workaround in gl4es till that fixed version released to public

ptitSeb commented 4 years ago

Yeah no problem, it can stay there, it's behind a ifdef anyway.

goblinhack commented 4 years ago

Hey folks, thanks for breathing life into this project! you might want to look at zorbash - I switched to working on that this year, it's a very work in progress - but is based on the same code - though I'm trying to move more to c++. I only mention this, if you are looking at bugs, you might want to look there and for comparison. The code is mostly quite different - but some of the common functions will look familiar. I also changed the widget code completely, to be more of a ascii like grid interface, for more of a retro console feel. Anyway, thanks for working on this!