1 registered members (AndrewAMD),
1,014
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Copying a struct
#402848
06/11/12 00:33
06/11/12 00:33
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
OP
Expert
|
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
Expert
|
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
OP
Expert
|
OP
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
//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
Expert
|
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
OP
Expert
|
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
Expert
|
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: MasterQ32]
#402859
06/11/12 07:39
06/11/12 07:39
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
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
OP
Expert
|
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
OP
Expert
|
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!
|
|
|
|