English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. C/C++ (https://eab.abime.net/forumdisplay.php?f=118)
-   -   AmiDevCpp - sprites problem (https://eab.abime.net/showthread.php?t=88785)

milikabdp 26 September 2017 00:40

AmiDevCpp - sprites problem
 
Hi, cant get sprites to work in amidevcpp - have been trying for days :)

I open the screen with:
Code:

        genscreen = OpenScreenTags(NULL,
                                  SA_DisplayID, LORES_KEY,
                                  SA_Depth, 4,
                                  // Give me a lot of border
                                  SA_Width, 320,
                                  SA_Height, 256,
                                  SA_Overscan, 0,
                                  // Hold the titlebar, please
                                  SA_Quiet, TRUE,
                                  // Give me sysfont 0 as default rastport font.
                                  SA_SysFont, 1,
                                  SA_Draggable,0,
                                  SA_Exclusive,1,
                                  SA_Colors,ColorSpec,
                                  SA_Type, CUSTOMSCREEN,
                                  TAG_DONE);

and can easily draw with standard RectFill etc, but cant get sprites to work.

My spritedata:
Code:

UWORD sprite_data[]={
        0, 0, /* position control */
        0xffff, 0x0000, /* image data line 1, color 1 */
        0xffff, 0x0000, /* image data line 2, color 1 */
        0x0000, 0xffff, /* image data line 3, color 2 */
        0x0000, 0xffff, /* image data line 4, color 2 */
        0x0000, 0x0000, /* image data line 5, transparent */
        0x0000, 0xffff, /* image data line 6, color 2 */
        0x0000, 0xffff, /* image data line 7, color 2 */
        0xffff, 0xffff, /* image data line 8, color 3 */
        0xffff, 0xffff, /* image data line 9, color 3 */
        0, 0 /* reserved, must init to 0 0 */
};

My sprite show code:
Code:

struct SimpleSprite * sprite;
        int sprite_num = GetSprite(sprite, 1);
        if (sprite_num != -1) {
                // here still is ok, usually get sprite num =1

                // create a emty pointer
                UWORD * spritedata;
                // allocate chipmemory
                spritedata=(UWORD) AllocMem(sizeof(sprite_data),MEMF_CHIP);
                // copy sprite data into chipmemory
                CopyMem(sprite_data,spritedata,sizeof(sprite_data));
                // still all ok - get correct data in spritedata

                ChangeSprite(NULL, sprite, &spritedata); // no error
                // but no sprite!!!
                                       
        }

I have seren examples where you need to set
sprite->x=0;
sprite->y=0;
sprite->height=9;
but cant do that in amidevcpp - get compile error "dereferencing pointer to incomplete type"

Any help is appreciated.

Regards....

emufan 26 September 2017 00:54

i cannot help here, but you should copy the exact error message from the "Compiler Log" tab,
and the source code lines where it find the error you describe.

milikabdp 26 September 2017 00:56

Its on the first line
Sprite->x = 0;
Or if i comment that than on the next line

emufan 26 September 2017 01:11

ah, ok, this is your code:
Code:

...
sprite->x=0;
sprite->y=0;
sprite->height=9;
...

from my basic knowledge, some info about "typedef struct SimpleSprite { ... };" or
"struct SimpleSprite { ... };" is missing.
does it have the "members" x, y, height?

there should be something like that:
Code:

struct SimpleSprite {
int x;
int y;
int height;
};


milikabdp 26 September 2017 01:17

struct SimpleSprite
{
UWORD *posctldata;
UWORD height;
UWORD x,y; /* current position */
UWORD num;
};
In sprite.h which comes with amidevcpp.

emufan 26 September 2017 01:26

hmm, you have #include <sprite.h> in you source file ? :)

on stackoverflow someone suggest to allocate mem for that struct:
Code:

struct SimpleSprite * sprite = malloc(sizeof(SimpleSprite));

milikabdp 26 September 2017 01:29

Tried it allready but the getsprite acctually changes the pointer. So alloc is the leak then. Anyhow already tried and no help :)

emufan 26 September 2017 01:36

Quote:

Originally Posted by milikabdp (Post 1187419)
Tried it allready but the getsprite acctually changes the pointer. So alloc is the leak then. Anyhow already tried and no help :)

hmm. where is alkis?! I'm sure he could fix this in no time :spin

#1) where do you have the "sprite->x =0;" lines?
i think they have to be in the same function and below the "struct SimpleSprite * sprite;" line.
Code:

struct SimpleSprite * sprite;
  sprite->x=0;
  sprite->y=0;
  sprite->height=9;
        int sprite_num = GetSprite(sprite, 1);
        if (sprite_num != -1) {


milikabdp 26 September 2017 01:49

Well not really, it needs to be bellow if, in that place pointer is still empty.
But it makes no difference, cant access any members anywhere

emufan 26 September 2017 01:57

Quote:

Originally Posted by milikabdp (Post 1187425)
Well not really, it needs to be bellow if, in that place pointer is still empty.
But it makes no difference, cant access any members anywhere

*example removed* makes no sense :spin

milikabdp 26 September 2017 01:59

Same error... tricky isnt it :) cant write to it, cant read from it. :)

emufan 26 September 2017 02:07

Quote:

Originally Posted by milikabdp (Post 1187428)
Same error... tricky isnt it :) cant write to it, cant read from it. :)

oh, I removed that example, but u were faster :)

#1) another one from my lightwave plugin stuff.
they do initialze the member before they do the struct, in this case typedef struct:
Code:

int spln,dirn,thickness;
double darken,brighten;

typedef struct VIDIMAGE_TAG{
    int spln;
    int dirn;
    int thickness;
    double darken;
    double brighten;
} VIDIMAGE;
....
// this is a function, LWInstance / LWError are known types
LWInstance create(LWError *error)
{
                VIDIMAGE *lwinst;

        lwinst = malloc(sizeof(struct VIDIMAGE_TAG));
        if (!lwinst)
        {
                *error = "Error allocating memory!";
                return NULL;
        }

                lwinst->thickness = 1;
                lwinst->spln = 4;
                lwinst->darken = 0.75;
                lwinst->brighten = 0.0;
...
};

this does build with sasc and gcc crosscompilers, like the one used with AmiDevCpp

milikabdp 26 September 2017 02:12

Thats perfect for this example.
I use that all the time.
But the pointer within simpleSprite i think is not allowing to access any element. No matter how are they allocated.

emufan 26 September 2017 02:17

Quote:

Originally Posted by milikabdp (Post 1187430)
Thats perfect for this example.
I use that all the time.
But the pointer within simpleSprite i think is not allowing to access any element. No matter how are they allocated.

this "UWORD *posctldata;"?

I thought you have to use all of them, but what you do, is just set some values for a certain member. this is strange.

maybe that pointer has to get initialized prior using the sprite struct?

#1) i would just make a copy of sprite.h, and edit that struct, move the *posctldata to the last position of that struct.
just to see what happens :spin

milikabdp 26 September 2017 02:29

yup, that works, tried it now - no problems.
but that structure needs to be like this - for system calls, cant just move pointer down...

milikabdp 26 September 2017 02:34

Well, thanks a lot!!! you got me thinking in a different direction.

struct SimpleSprite1
{
APTR posctldata;
UWORD height;
UWORD x,y;
UWORD num;

};

Recreating that struck like this works just fine, sprite show and all!!!

Great help!!!

emufan 26 September 2017 02:43

Quote:

Originally Posted by milikabdp (Post 1187437)
Great help!!!

*wow* cool stuff - some h3x07ing did it :D

#1) I cannot find the APTR example i was looking for. I had some issue with such type the other day,
but in this case you replaced UWORD with the APTR type, so it must have been something different :)

milikabdp 26 September 2017 05:56

This is just a gift that keeps giving.
Now everything work in WinUAE, but not on real machine - no sprite is visible...

Code:

        // add sprite
                                sprite_num = GetSprite(&sprite, 2);
                                if (sprite_num != -1) {
                                        sprite.x = 0;
                                        sprite.y = 0;
                                        sprite.height = 32;

                                        // color pallete
                                        SetRGB4(&genscreen->ViewPort, 21,0,0,0);

                                        // allocate chipmemory
                                        spritedata=(UWORD) AllocMem(sizeof(sprite_data),MEMF_CHIP);
                                        if (spritedata > 0) {
                                                // copy sprite data into chipmemory
                                                CopyMem(&sprite_data,spritedata,sizeof(sprite_data));

                                                ChangeSprite(&genscreen->ViewPort, &sprite, spritedata);

                                                MoveSprite(&genscreen->ViewPort, &sprite, 30,10);

                                        } else {
                                                DisplayAlert(RECOVERY_ALERT,"\x00\xF0\x14" "Could not allocate memory for sprite!",64);
                                        }

                                } else {
                                        DisplayAlert(RECOVERY_ALERT,"\x00\xF0\x14" "Could not allocate sprite!",64);
                                }

No alerts sprite is just not visible :crazy

emufan 26 September 2017 15:55

hmm, do you run it from shell/cli? maybe add some printf's in those conditions like:
Code:

if (spritedata > 0) {
    printf("spritedata > 0\n");
    printf("&sprite == %d\n", &sprite);
    ...

or other more usefull values.

milikabdp 26 September 2017 18:31

Did bunch of printf debuging this morning.
All is in order! Memory, pointers, sprite num etc. but no sprite on screen :)


All times are GMT +2. The time now is 13:01.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.05162 seconds with 11 queries