Hocoslamfy MorphOS port

7 posts / 0 new
Last post
beworld
Hocoslamfy MorphOS port

Bonjour,
Voila j'ai réussi à compiler Hocoslamfy sur MorphOS :-)
Je suis novice mais j'apprends.
du coup j'aimerais bien faire un Scale 2x, car la réolution 320x240 est un peu.... comment dire...
J'ai cherché un peu partout, testé quelques trucs mais c'est pas top top....
Peux-tu m'aider ? car j'ai vu que dans le portage AmigaOS 4 tu l'a fais... cela m'aiderais bien.
 
Merci
BeWorld

hunoppc
hunoppc's picture

Salut,
Bien sur que je peux t'aider ;-)
Voici un exemple de code que tu peux utiliser SCALE2X
 
void scale2xSDL(SDL_Surface *src, SDL_Surface *dst)
{
     if(SDL_LockSurface(src) < 0)
        printf("scale2x:Was not able to lock work surface");

   if(SDL_LockSurface(dst) < 0)
        printf("scale2x:Was not able to lock screen surface");

    int looph, loopw;

    Uint8* srcpix = (Uint8*)src->pixels;
    Uint8* dstpix = (Uint8*)dst->pixels;

    const int srcpitch = src->pitch;
    const int dstpitch = dst->pitch;
    const int width = src->w;
    const int height = src->h;

    switch(src->format->BytesPerPixel)
    {
    case 1: {
            Uint8 E0, E1, E2, E3, B, D, E, F, H;
        for(looph = 0; looph < height; ++looph)
        {
            for(loopw = 0; loopw < width; ++ loopw)
            {
                    B = *(Uint8*)(srcpix + (MAX(0,looph-1)*srcpitch) + (1*loopw));
                    D = *(Uint8*)(srcpix + (looph*srcpitch) + (1*MAX(0,loopw-1)));
                    E = *(Uint8*)(srcpix + (looph*srcpitch) + (1*loopw));
                    F = *(Uint8*)(srcpix + (looph*srcpitch) + (1*MIN(width-1,loopw+1)));
                    H = *(Uint8*)(srcpix + (MIN(height-1,looph+1)*srcpitch) + (1*loopw));

                E0 = D == B && B != F && D != H ? D : E;
                                E1 = B == F && B != D && F != H ? F : E;
                E2 = D == H && D != B && H != F ? D : E;
                E3 = H == F && D != H && B != F ? F : E;

                *(Uint8*)(dstpix + looph*2*dstpitch + loopw*2*1) = E0;
                *(Uint8*)(dstpix + looph*2*dstpitch + (loopw*2+1)*1) = E1;
                *(Uint8*)(dstpix + (looph*2+1)*dstpitch + loopw*2*1) = E2;
                *(Uint8*)(dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*1) = E3;
            }
        }break;}
    case 2: {
            Uint16 E0, E1, E2, E3, B, D, E, F, H;
        for(looph = 0; looph < height; ++looph)
        {
            for(loopw = 0; loopw < width; ++ loopw)
            {
                    B = *(Uint16*)(srcpix + (MAX(0,looph-1)*srcpitch) + (2*loopw));
                    D = *(Uint16*)(srcpix + (looph*srcpitch) + (2*MAX(0,loopw-1)));
                    E = *(Uint16*)(srcpix + (looph*srcpitch) + (2*loopw));
                    F = *(Uint16*)(srcpix + (looph*srcpitch) + (2*MIN(width-1,loopw+1)));
                    H = *(Uint16*)(srcpix + (MIN(height-1,looph+1)*srcpitch) + (2*loopw));

                E0 = D == B && B != F && D != H ? D : E;
                                E1 = B == F && B != D && F != H ? F : E;
                E2 = D == H && D != B && H != F ? D : E;
                E3 = H == F && D != H && B != F ? F : E;

                *(Uint16*)(dstpix + looph*2*dstpitch + loopw*2*2) = E0;
                *(Uint16*)(dstpix + looph*2*dstpitch + (loopw*2+1)*2) = E1;
                *(Uint16*)(dstpix + (looph*2+1)*dstpitch + loopw*2*2) = E2;
                *(Uint16*)(dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*2) = E3;
            }
        }break;}
    case 3: {
            int E0, E1, E2, E3, B, D, E, F, H;
        for(looph = 0; looph < height; ++looph)
        {
            for(loopw = 0; loopw < width; ++ loopw)
            {
                    B = READINT24(srcpix + (MAX(0,looph-1)*srcpitch) + (3*loopw));
                    D = READINT24(srcpix + (looph*srcpitch) + (3*MAX(0,loopw-1)));
                    E = READINT24(srcpix + (looph*srcpitch) + (3*loopw));
                    F = READINT24(srcpix + (looph*srcpitch) + (3*MIN(width-1,loopw+1)));
                    H = READINT24(srcpix + (MIN(height-1,looph+1)*srcpitch) + (3*loopw));

                E0 = D == B && B != F && D != H ? D : E;
                                E1 = B == F && B != D && F != H ? F : E;
                E2 = D == H && D != B && H != F ? D : E;
                E3 = H == F && D != H && B != F ? F : E;

                WRITEINT24((dstpix + looph*2*dstpitch + loopw*2*3), E0);
                WRITEINT24((dstpix + looph*2*dstpitch + (loopw*2+1)*3), E1);
                WRITEINT24((dstpix + (looph*2+1)*dstpitch + loopw*2*3), E2);
                WRITEINT24((dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*3), E3);
            }
        }break;}
    default: { /*case 4:*/
            Uint32 E0, E1, E2, E3, B, D, E, F, H;
        for(looph = 0; looph < height; ++looph)
        {
            for(loopw = 0; loopw < width; ++ loopw)
            {
                    B = *(Uint32*)(srcpix + (MAX(0,looph-1)*srcpitch) + (4*loopw));
                    D = *(Uint32*)(srcpix + (looph*srcpitch) + (4*MAX(0,loopw-1)));
                    E = *(Uint32*)(srcpix + (looph*srcpitch) + (4*loopw));
                    F = *(Uint32*)(srcpix + (looph*srcpitch) + (4*MIN(width-1,loopw+1)));
                    H = *(Uint32*)(srcpix + (MIN(height-1,looph+1)*srcpitch) + (4*loopw));

                E0 = D == B && B != F && D != H ? D : E;
                                E1 = B == F && B != D && F != H ? F : E;
                E2 = D == H && D != B && H != F ? D : E;
                E3 = H == F && D != H && B != F ? F : E;

                *(Uint32*)(dstpix + looph*2*dstpitch + loopw*2*4) = E0;
                *(Uint32*)(dstpix + looph*2*dstpitch + (loopw*2+1)*4) = E1;
                *(Uint32*)(dstpix + (looph*2+1)*dstpitch + loopw*2*4) = E2;
                *(Uint32*)(dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*4) = E3;
            }
        }break;}
    }
   SDL_UnlockSurface(src);
   SDL_UnlockSurface(dst);
}
 
ensuite tu le déclares comme ci-dessous:
tu prends ta surface de 320x240 en source (src) et tu mets ta surface scaled en destination (dst)
scale2xSDL(screen, screenScaled);
        SDL_UpdateRect(screenScaled, 0, 0, 0, 0);
ensuite tu utiliseras ta surface scaled
le SDL_flip prends plus de temps que le SDL_UpdateRect
donc maintenant à toi de jouer
HunoPPC

beworld

Yeahhh !!! :-)
 
Vais tester tout ca :-)
Merci encore !
 
J'ai deja reussi à porter et bidouille XGalaga :-) compilé avec GCC4 direct via mon G5, j'apprends.
 
a bientôt

hunoppc
hunoppc's picture

Salut,
je suis très content de t'avoir aidé ;-).
je vois que tu avance bien.
bonne programmation et reviens poster de temps en temps pour nous donner ton évolution ainsi que tes portages 
A+
HunoPPC

beworld

re soir....
bon je sèche encore un peu :-)
Dans le code source d'origine, j'ai bien trouvé 2 SDL_Flip(Screen), un dans le game.c et l'autre dans le title.C
Déja si je remplace par le SDL_UpdateRect, ca marche :-), je vois pas de changement mais si tu dis que c'est plus rapide, ca me va.
Après j'arrive pas à placer le : scale2xSDL(screen, screenScaled);
Si je le mets dans la function juste au dessus du SDL_UpdateRect... cela me pète à la tronche :-) freeze... et reboot
Il y a encore un truc qui m'echappe.
Tu aurais la possibilité de m'envoyer ton code source de ton portage AmigaOS4 ? si cela est pas trop abusé ?
Merci
 
beworld at sfr.fr
 

beworld

je viens de porter Rocks'n'Diamonds sur MorphOS :
http://www.morphos-storage.net/index.php?page=Games%2FThink&file=RocksND...
J'ai pas d'AmigaOS 4.1 pour le porté... si tu veux pas grand chose à faire pour le faire marcher :-)

hunoppc
hunoppc's picture

@Beworld
Excuse moi de ne pas avoir répondu mais je n'ai pas eu beaucoup d'activité et je n'ai pas été très productif ces derniers temps
Je te donne la méthode pour initialiser le filtre
#define SCALE2X
SDL_Surface *screen = NULL;
    SDL_Surface *screenScaled = NULL;
 
Dans ton main()
 
int  main(int argc, char **argv) {
 
    /* Center the window */
    putenv("SDL_VIDEO_CENTERED=1");

    /* Init SDLVideo */
        if (SDL_Init(SDL_INIT_VIDEO)<0) {
            printf("Error starting SDL: %s\n",SDL_GetError());
            exit(1);
        }
        atexit(SDL_Quit);
        
    /* Init SDL_TTF */
      if (TTF_Init() < 0) {
            printf("Error starting SDL_ttf: %s\n",SDL_GetError());
            exit(1);
        }
        atexit(TTF_Quit);

    /* Name of the window */
       SDL_WM_SetCaption("Hydorah AmigaOS4", "Hydorah AmigaOS4");

    /* Disable cursor */
      SDL_ShowCursor(SDL_DISABLE);

    /* Disable repeat keys */
      SDL_EnableKeyRepeat(0, 0);
    #ifdef SCALE2X
        screenScaled = SDL_SetVideoMode(320*2, 240*2, 32, SDL_HWSURFACE
    #else
        screen = SDL_SetVideoMode(320, 240, 32, SDL_HWSURFACE
    #endif
    #ifdef TARGET_AMIGAOS4
    | SDL_FULLSCREEN
    #endif
    );
    #ifdef SCALE2X
        if (screenScaled == NULL)
        {
         //   cerr << "Error creating surface: " << SDL_GetError() << endl;
            exit(1);
        }
        screen = SDL_CreateRGBSurface(SDL_HWSURFACE, 320, 240, 32,
        screenScaled->format->Rmask, screenScaled->format->Gmask, screenScaled->format->Bmask, screenScaled->format->Amask);
        if (screen == NULL)
        {
         //   cerr << "Error creating surface: " << SDL_GetError() << endl;
            exit(1);
        }
    #else
    if (screen == NULL)
    {
       // cerr << "Error creating surface: " << SDL_GetError() << endl;
        exit(1);
    }
    #endif
 
//suite du code
  }
 
 
et ensuite à la place de tes SDL_Flip()
 
       #ifdef SCALE2X
        filter_tv2xNES32(screen,screenScaled);
        SDL_Flip(screenScaled);
        #else
        SDL_Flip(screen);
        #endif
 
J'espère que j'aurai été assez explicite
Bon courage et encore toutes mes excuses
HunoPPC