ZealousEngine

Members
  • Content count

    433
  • Joined

  • Last visited

Community Reputation

100 Neutral

About ZealousEngine

  • Rank
    Member
  1. Destructors and Vectors...

    Quote: And where are the results? Im guessing you are not very familiar with boost::object_pool. There are many situations (in games especially) where you will be constantly allocating/deallocating very small objects. In these situations, you will save time AND memory by using a pool. I have used boost::object_pool before, but tonight I decided to create my own little pool (just using a simple vector), and thats how I ran into this little problem. Using a shared pointer to store the new object created by the constructor seems to be the easiest solution. And youre right, dynamically allocating new objects like that defeats the purpose of the pool, I was just using it as an example for the problem I was having (ie forgetting that the compiler created a copy constructor behind my back).
  2. Destructors and Vectors...

    Quote:Have you profiled it? Yes I have. Besides, were just talking about a pool. Not exactly a extreme concept. Premature optimization isnt even a factor for discussion here. So back to my problem - the onlything I can think of would be to have seperate init/uninit functions and call them manually. That would avoid all this copy/destructor craziness.
  3. Destructors and Vectors...

    Quote:Original post by Zahlman Quote:Original post by ZealousEngine Well I am trying to use the vector as a sort of reusable pool What do you think you will gain from doing this? Quote:in order to keep all my objects grouped together in memory. What do you think you will gain from that? Quote:in order to avoid havoc when the vector copies things around? What havoc? What will I gain from grouping thousands of classes together? Lots. Especially when I iterate over the whole vector. And the havoc seems to be, the Constructor is called once (creating a new object), but then the copy constructors dont allocate any new objects (which is fine, their job is just to copy the pointer). Now we have only ONE actual new object, and THREE destructors being called (each of which will try to destroy the object).
  4. Destructors and Vectors...

    Well I am trying to use the vector as a sort of reusable pool, in order to keep all my objects grouped together in memory. Thus I cant really just store pointers. So how should I implement the following class... class foo { public: foo() { mObj = new Obj; assert(!"foo constructor"); } ~foo() { delete mObj; assert(!"foo destructor"); } foo(const foo& p) { assert(!"foo copy constructor"); } }; ..in order to avoid havoc when the vector copies things around?
  5. Destructors and Vectors...

    Ok I think I see now, so I am seeing one constructor, then TWO copy constructors (I assume two since the vector always allocates twice the space needed right?), then followed by 3 destructors (one for the temporary, and two for the vector). I wonder though, is there anyway to have a list/vector of objects, and grow things WITHOUT having to create a temporary object? *I think the bug I was noticing was because I was creating a new unrelated object in the constructor, and then deleting it in the destructor. I guess this caused problems when the vector tried to copy stuff around?
  6. Destructors and Vectors...

    Just tested again, still getting ONE constructor and THREE destructores... The only code is what I posted above... are you sure you only get two destructors? Why wouldnt it be a 1 to 1 ratio of constructors to destructors though? I have a lot going on in the constructors (they allocate new objects for example), and the fact that things ARE NOT 1 to 1 is causing all kinds of bugs :(
  7. So I noticed that when I add objects to a vector, their destructors are being called more than they should be... see the following... class foo { public: foo() { assert(!"foo constructor"); } ~foo() { assert(!"foo destructor"); } }; ... std::vector<foo> fooVec; fooVec.push_back(foo()); The above code generates one cunstructor assert, followed by THREE destructors! Zuh?
  8. I am trying to implement a spherical terrain system where a single geo clipmap sits ontop of a sphere, in its own arbitrary coordinate space. The basics are pretty simple... http://www.math.uni-bremen.de/~justen/Mich/planetrendering_gallery_e.html?lang=0&stylefile=Layout/default.css Ok, so I have my square clipmap sitting ontop of my sphere. For simplicity I start by placing the clipmap at the top of the sphere, so it has a identity matrix to begin with. My question is, now how should I move/update the clipmap? My clipmap class works on the assumption that everything is 2d. Shifts take place when the camera position goes beyond a certain point on the x/z axis. How should I adapt this to a 'Lutz style' spherical terrain? Should I be using the dot product of the camera position and the vectors of the 'clipmap coordinate space', which will give me a relative distance from the center of the clipmap. Or should I try and transform the camera position from world space into another space (one more relative to the clipmap?). I have been using the dotproduct approach, but what am I supposed to do when root level of the clipmap needs to shift? How do I tell where to rotate/position the clipmap based on this shifting? Thanks for any help!
  9. One question about quaternions...

    So what is the logic/math used when determing how to scale your axis/rotation? If I want a 45degree rotation around the (1,1,0) axis, how do I convert all that to a quaternion?
  10. One question about quaternions...

    There is just one thing about quaternions that bugs me... I can visualize the xyz values forming the axis, and the w representing the rotation. What DOESNT make any sense to me is why the xyz axis is not ALWAYS a unit vector. Shouldnt it ALWAYS be a unit vector? For example, when you want to rotate around the x axis 90 degrees, WHY do you need to set the x axis to sqrt(0.5)? If you want to rotate around (1,0,0), why in the crap cant that part stay constant, and only the rotation portion change? Whats the logic here? Rotating 180 degrees around the root axes is so simple and intuitive... why cant all rotations work the same way... sigh.. Thanks for any info!
  11. Is it possible to render to a 3d texture (using directx9)? Or perhaps some way to render each slice to a traditional 2d render target, then somehow combine those slices (efficiently) into a 3d texture? Thanks for any info!
  12. [Solved] C++ Macro question...

    Quote:You are going to want a fair few elements in the sequence though to make it worth your while And why would having a large list of names be a problem with Hodgman's method? I define the list ONCE, then I can use it with ANY macro. Keep in mind the onlything I need is the NAME of the component (upper and lower case versions are nice to have too). Although with Hodgman's method it seems like it would be trivial to pass additional information to the macros if I ever needed too.
  13. [Solved] C++ Macro question...

    Haha! Hodgman you are my hero! That works great! And seems way more elegant than using boost. Works perfect with vs2005 express. Thanks again bud!
  14. [Solved] C++ Macro question...

    I dont think the problem is joining things together, but rather - How can you create a list/vector that can be read at the preprocessor stage.
  15. [Solved] C++ Macro question...

    Quote: #define LIST (w, (x, (y, (z, BOOST_PP_NIL)))) #define MACRO(r, data, elem) BOOST_PP_CAT(elem, data) BOOST_PP_LIST_FOR_EACH(MACRO, _, LIST) // expands to w_ x_ y_ z_ I dont quite see how this macro would allow me to insert JUST the names into an existing loop or a block of code. Can somebody please post a little demonstration if it is possible? It seems like BOOST_PP_REPEAT would work IF I could figure out how to use the index counter to iterate through some kind of 'name list' as well..