Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

Declaring LargeVolume<uint8_t> inside a struct
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=499
Page 1 of 1

Author:  Clonkex [ Tue Apr 16, 2013 3:33 am ]
Post subject:  Declaring LargeVolume<uint8_t> inside a struct

Hi,

I want to be able to create a "vector" of volumes, in this case using LargeVolume<uint8_t>, but I see no way of doing this because you went and overloaded and protected the "=" operator. I first tried this:

Code:
struct volumeInfo
{
   LargeVolume<uint8_t> volume;
};

vector<volumeInfo> volume;


But that can't compile because there's no default constructor for LargeVolume. Then I tried this:

Code:
vector<LargeVolume<uint8_t>> volume;


That does compile but then I have no way using volume.push_back() because the vector code itself tries to use the "=" operator.

How would you achieve this? Do you use the 'template' keyword in the declaration or something?

EDIT: So then I thought, ah, stuff this, for the time being I'll just use a single terrain in a global variable. Well turns out that won't work either, because I can't just declare a global variable in my header because LargeVolume has no default constructor. Why'd you have to make this so difficult?? ;)

EDIT2: I wondered whether it might be possible achieve this via pointers, so I tried, but of course you can't assign just the memory address or the data will evaporate the moment you leave the function and you can't assign the data because it uses the "=" operator.

Clonkex

Author:  David Williams [ Tue Apr 16, 2013 9:07 am ]
Post subject:  Re: Declaring LargeVolume<uint8_t> inside a struct

Hi, it is possible to do what you want but I would be curious to know why you want to do this. In particular you should make sure you have read the first entry in the FAQ: http://www.volumesoffun.com/polyvox/doc ... aller-ones

If you do want multiple volumes stored in a vector then your vector should actually just store pointers (as you suggest). The volumes should then be allocated on the heap (using 'new') in which case they won't disappear until you explicitly call 'delete'.

operator=() is hidden basically for performance rasons - copying a volume is very expensive due to the large amount of data, and generally it's not an operation which you need to perform.

Author:  Clonkex [ Tue Apr 16, 2013 9:49 am ]
Post subject:  Re: Declaring LargeVolume<uint8_t> inside a struct

Thank you so much for explaining that! :D

I considered using 'new' and 'delete' but not at the same time as considering pointers so the two never clicked.

Quote:
Hi, it is possible to do what you want but I would be curious to know why you want to do this. In particular you should make sure you have read the first entry in the FAQ: http://www.volumesoffun.com/polyvox/doc ... aller-ones


Lol, I actually found the FAQ and read the entire thing because I was trying to pass the time until you woke up and answered my post (I'd tried everything I could think of to make it work). I live in Australia so it's 7.45pm here at the moment :) It's bizarre thinking that I was waiting around for you to finish sleeping :P

The reason I want to be able to create lots of different volumes is not to create a single large terrain made of lots of volumes (I know you were thinking that ;)) but to allow the creation of separated volumes, such as different planets (which is a really cool use for voxel terrains). I'm creating a game (sort of a 3D Clonk, but for legal reasons it won't be using any Clonk IP), and I'm creating it in DBPro. Since DBPro is a proprietary BASIC language (trust me; it's waaaay more powerful than it sounds), I have to create a wrapper for PolyVox in the form of a plugin DLL (the fact that DBPro is extensible via plugins is the main reason it's so powerful...just look at all the plugins available!). Since I have to make this plugin anyway for my game project, I'll do it properly and sell it as another plugin on TGC's website.

I've been using DBPro since May 2010 (which is pretty much when I started learning to program) and I absolutely love it. There's only two drawbacks that I've come across so far: It's Windows-only and no one has yet created a plugin to allow batching ;)

Thanks a lot (that phrase always comes across as sarcastic) for your help :D I'll go restart the fire for mum (I'm 18...I'm allowed to still live at home ;)) and then try using dynamically-allocated memory.

Clonkex

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/