Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Copying a struct #402848
06/11/12 00:33
06/11/12 00:33
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
I think I may not understand fully how memcpy works.

So I have a struct which has several panels in it which You can see on screen. I loaded one up and wanted to simply copy that struct to a new one. I used memcpy the way it shows in the manual but I still only have one visible panel on screen. Which now behaves the way I set the second one two. I made several of these, 70, and still one panel and all behave the way one of them should. i can tell all of the functions are working but they are not moving the panel at 70 times the rate of speed as I would expect.

Any helpful advice that my point me in the right direction?


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Copying a struct [Re: FoxHound] #402849
06/11/12 02:52
06/11/12 02:52
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
We need some code dude... Or at least post the struct you are trying to copy.

There are several reasons it could be failing...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Copying a struct [Re: EvilSOB] #402851
06/11/12 03:09
06/11/12 03:09
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
Code:
//declared outside of function
FSA_panel* girlscout_fsa;	
FSA_panel* fsa_yo[150];



function setup_fsa_001()
{
	girlscout_fsa = malloc(sizeof(FSA_panel));
	
	if(!FSA_create("girlscout001.fsa",vector(700,random(500),0),girlscout_fsa))
	{
		printf("file not found");
		sys_exit("");
		return;
	}

}


function copy_fsa()
{
		fsa_yo[0] = malloc(sizeof(FSA_panel));
               memcpy(fsa_yo[0],girlscout_fsa,sizeof(FSA_panel));  

	
}




FSA_create works fine I can add as many of theses as I want with it, all the other FSA_ functions work fine. I want something a bit faster than the FSA_create function. I was hoping for a better understanding of making a copy of one struct to another and working with them independently of each other.

Last edited by FoxHound; 06/11/12 03:19.

---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Copying a struct [Re: FoxHound] #402852
06/11/12 03:24
06/11/12 03:24
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I NEED to see the FSA_panel struct itself, and the 'FSA_create' would be helpful.


BTW, in 'copy_fsa', the memset is just plain wrong, it will just fill the fsa_yo
with junk data.


And the memcpy MIGHT need to be
"memcpy([b]&[/bfsa_yo[0], [b]&[/bgirlscout_fsa, sizeof(FSA_panel));"
or
"memcpy([b]&[/bfsa_yo[0], girlscout_fsa, sizeof(FSA_panel));"

I always have trouble myself determining if the '&' is necessary and need
to "trial and error" test it every time I use it...
Because sometimes it is, and sometimes not, depending on the pointers declaration.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Copying a struct [Re: EvilSOB] #402853
06/11/12 03:30
06/11/12 03:30
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
Some of the code I put up at first was a bit off as I do a lot of trail and error, basically I try break it when it doesn't do what I want.

Neither way I use the "&" symbol works, as in the game crashes bad both ways.

The struct and FSA_create works just fine. I want a quick and easy way to copy the struct.

I'm making this.
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=402345#Post402345
The struct itself is huge.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Copying a struct [Re: FoxHound] #402854
06/11/12 04:07
06/11/12 04:07
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
It doesnt matter that the struct is huge, I will only be skimming through it.
AND it doesnt matter (to me) that fsa_create works fine as is either.

I need to see them because SOME types of data will memcpy fine, and others dont.
Im looking for types that dont copy, and need re-creating...


You can PM the info to me if you want to keep it confidential, I dont mind.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Copying a struct [Re: EvilSOB] #402857
06/11/12 05:16
06/11/12 05:16
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
i assume you use engine panels
so copying one of your structs with the PANEL* pointer does NOT copy the panel but the reference to it. so you are currently really using only one panel. to copy a PANEL* you need to create a new panel and set all parameters in your code, memcpy would fail here because of the internal engine layout


Visit my site: www.masterq32.de
Re: Copying a struct [Re: MasterQ32] #402859
06/11/12 07:39
06/11/12 07:39
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Master32 has hit ONE of the types of data Im looking for, but there are others.

But even then, its unlikelt to cause problems, you just need to handle
those 'special' elements properly.

Like the PANEL that Master has brought up.
It CAN be 'memcpy'ed, BUT you need to do a pan_create first, and then
memcpy from the old panel ... always SKIPPING the first FOUR bytes, and maybe the last 24...
This way youve done a 'quick' copy of its contents, without disturbing the
internal engine values.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Copying a struct [Re: EvilSOB] #402887
06/11/12 15:41
06/11/12 15:41
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
That answers my question then. The reason fsa_create takes so long is that it has to create up to 32 panels. In the example I'm doing there are only 17 panels. It either freezes the game for a second or with several waits put into key places to prevent a freeze it takes 3 seconds to create a new FSA. I'll play around with some new ideas today and see if i can fix it.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: Copying a struct [Re: FoxHound] #402909
06/11/12 19:25
06/11/12 19:25
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
Still never found an answer to my problem but I solved my problem another way. Apparently I decided to create a panel 256 times instead of just the one I needed. Multiply that across 17 panels and it was quite a mess. So all the waits remove and this thing loads fast.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1