Archived

This topic is now archived and is closed to further replies.

NoNseNse

Memory, pointers and similarities

Recommended Posts

OK, here''s my current problem: I programmed an engine which can load a .md2 (Q2) model, and drawit. nothing special so far. Unfortunately this takes a lot of memory to store, so I stored it in two different ways: at first I got a structure called ''model'' in which is all the (polygon) data of the .md2 file, with all animation frames. it is defined like this: s_model *model; //s_model is a custom structure Now when I load a model, enough memory is allocated with malloc. Because normally only one frame is active, and the data is not usable for me in this state (I need D3D-Vertices), I have a seccond variable, called mesh. It is defined very similar, but not a ''s_model'' but a D3DVERTEX. IN it I write the current active frame. So far so good, not the best approach, but it works. Now I wanted to load 15 times the same model and put it on different positions of my map. Of course it would be a waste of memory to load the first structure 15 times, so I just load it one time, and then I have 15 times the seccond structure, with the individual frame and position. the question now is: Have I to allocate memory for all the 15 structures if I define the idividual structs as followed: mesh = /* the correct frames of */ model; My first thought was yes, but when I tried it, all the 15 models did exactly the same animations, all showed the last frame I loaded. I believe I have somewhere done something wrong with the memory, or all the pointers, so if you did understand all the crap I wrote above and know an answer, I''d be grateful. NoNseNse

Share this post


Link to post
Share on other sites
I''m not sure i have totally understood your problem...
So i''ll be sorry if my answer is totally useless :D

But do you use DrawPrimitive() as below :

LPMESH is a pointer to the start of your second structure

lpD3DDevice -> DrawPrimitive(primitivetype,vertextype,LPMESH+startofframe,sizeofframe,0);


I hope it will help you



BugKiller
www.bugkiller.net

Share this post


Link to post
Share on other sites
Hi

If you wan''t just a copy of your Model on an other Position, you just need to adjust your Transformation Matrix each time before rendering one of the Models.
And even if you change the Modeldata, you can do that between rendering your Models, and that without any large speed penaltys.

But you only need 1/15 of the Memory !


Lars

Share this post


Link to post
Share on other sites
Man, I''m not exactly sure what you''re trying to do, but here goes anyway. I think you need an array of pointers, if you want pointers that is. You need one to point to each of your 15 (or however many) structures. I think you are trying to use one pointer to point to 15 different places, but aren''t storing their addresses. Therefore the pointer always points to the most recent struct. Damn, now you have me sounding crazy

Let me know if you need me to clarify, that wasn''t the clearest explanation I''ve ever given.

-BacksideSnap-

Share this post


Link to post
Share on other sites
Ok, first I want to thank you all for the ideas. They helped me a lot in solving the problem. My error: I sed pointers to point onto a structure, but I did not extract the data itself. So when I altered the source data, all the pointers pointed onto the same chunk of data. Now I copy the data directly into an array instead of pointing to it. SO that problem''s solved, but it surely wasn''t the last!

Share this post


Link to post
Share on other sites