2 registered members (TipmyPip, AndrewAMD),
1,151
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Fast array copy
#240304
12/10/08 13:20
12/10/08 13:20
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Hi! I have two large arrays to store level data, and I need to copy one to another on every frame cycle. for (k = 0; k < 1350; k++) { for (i = 0; i < 1350; i++) { maparray2[i][k][0] = maparray[i][k][0]; maparray2[i][k][1] = maparray[i][k][1]; maparray2[i][k][2] = maparray[i][k][2]; } }
But this kills a lot of CPU, maybe someone knows of faster/better way to code such array-to-array copying? Regards, Konstantin.
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Fast array copy
[Re: kasimir]
#240314
12/10/08 13:57
12/10/08 13:57
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Eeem... My map is divided into many cells. Every cells holds information which is loaded on level start once (from image using colors), into maparray massive; This array is constant.
(maparray[Xcellposition][Ycellpositon][colorRED]) (maparray[Xcellposition][Ycellpositon][colorBLUE]) (maparray[Xcellposition][Ycellpositon][colorGREEN])
On top of it, every frame some entities are moving. Every entity also has its "map-cell" representation. So, I copy maparray to maparray2, add entity dynamic cell info to maparray2 then, and pass this complete map information for further pathfindings and interactions.
I never used memcpy(), is it safe and easy to play with it?
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Fast array copy
[Re: RyuMaster]
#240317
12/10/08 14:07
12/10/08 14:07
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
1350 is absolute maximum, i think 700-800 will be maximum, but I want to deal with extreme case first
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Fast array copy
[Re: Joey]
#240333
12/10/08 14:59
12/10/08 14:59
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Hi, Joey! I was thinking of that at the start. I created bitmap for leveldata. And bitmap panels for entities. Then I found out, that I can not perform pixel operations on panels. If I render panel to target, this target can not be locked. And I can not use only BMAPs for storing data. I need panels, to move BMAP along with entity when it moves. And there are also many problems. The worst one - all pixel operations are very slow.
But I always consider this idea in my head, it is just too hard for me to find performant solution.
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Fast array copy
[Re: RyuMaster]
#240335
12/10/08 15:00
12/10/08 15:00
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
>>for direct access of the bitmap information<< Or You mean something else by this? Not pixel-read access?
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
|