English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 26 September 2017, 00:40   #1
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
Question 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....
milikabdp is offline  
Old 26 September 2017, 00:54   #2
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
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.
emufan is offline  
Old 26 September 2017, 00:56   #3
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
Its on the first line
Sprite->x = 0;
Or if i comment that than on the next line
milikabdp is offline  
Old 26 September 2017, 01:11   #4
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
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; 
};

Last edited by emufan; 26 September 2017 at 01:18.
emufan is offline  
Old 26 September 2017, 01:17   #5
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
struct SimpleSprite
{
UWORD *posctldata;
UWORD height;
UWORD x,y; /* current position */
UWORD num;
};
In sprite.h which comes with amidevcpp.
milikabdp is offline  
Old 26 September 2017, 01:26   #6
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
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));
emufan is offline  
Old 26 September 2017, 01:29   #7
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
Tried it allready but the getsprite acctually changes the pointer. So alloc is the leak then. Anyhow already tried and no help
milikabdp is offline  
Old 26 September 2017, 01:36   #8
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
Quote:
Originally Posted by milikabdp View Post
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

#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) {

Last edited by emufan; 26 September 2017 at 01:56.
emufan is offline  
Old 26 September 2017, 01:49   #9
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
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
milikabdp is offline  
Old 26 September 2017, 01:57   #10
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
Quote:
Originally Posted by milikabdp View Post
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
emufan is offline  
Old 26 September 2017, 01:59   #11
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
Same error... tricky isnt it cant write to it, cant read from it.
milikabdp is offline  
Old 26 September 2017, 02:07   #12
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
Quote:
Originally Posted by milikabdp View Post
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
emufan is offline  
Old 26 September 2017, 02:12   #13
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
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.
milikabdp is offline  
Old 26 September 2017, 02:17   #14
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
Quote:
Originally Posted by milikabdp View Post
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
emufan is offline  
Old 26 September 2017, 02:29   #15
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
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 is offline  
Old 26 September 2017, 02:34   #16
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
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!!!
milikabdp is offline  
Old 26 September 2017, 02:43   #17
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
Quote:
Originally Posted by milikabdp View Post
Great help!!!
*wow* cool stuff - some h3x07ing did it

#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

Last edited by emufan; 26 September 2017 at 02:51.
emufan is offline  
Old 26 September 2017, 05:56   #18
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
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
milikabdp is offline  
Old 26 September 2017, 15:55   #19
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
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.
emufan is offline  
Old 26 September 2017, 18:31   #20
milikabdp
Registered User
 
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
Did bunch of printf debuging this morning.
All is in order! Memory, pointers, sprite num etc. but no sprite on screen
milikabdp is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amidevcpp c++ link errors tolkien Coders. C/C++ 8 08 November 2019 01:18
AmiDevCpp $(GLOBALDEPS) mritter0 Coders. C/C++ 1 29 June 2015 01:30
AmiDevCpp AF2013 Coders. C/C++ 0 14 March 2014 00:23
Problem compiling with AmiDevCpp Franchute13 Coders. C/C++ 2 26 September 2013 15:01
AmiDevCpp and Floats AmigaEd Coders. General 0 18 January 2006 03:16

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:49.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.18986 seconds with 16 queries