Jump to content

  • Log In with Google      Sign In   
  • Create Account


PolyVox

Member Since 24 Nov 2002
Offline Last Active Feb 02 2014 01:53 AM

Topics I've Started

We've just released a new version of PolyVox, our open source voxel terrain engine

20 November 2012 - 03:32 PM

Hi all,

We've just made a new release of our PolyVox voxel terrain engine. You can read about PolyVox here and see a list of projects using it here.

Some key points:
  • Written in C++ and available under the zlib license.
  • Independent of graphics API or rendering engine.
  • Can create both smooth and cubic-style terrain.
  • Raycasting support for picking and ambient occlusion.
  • Support for large volumes with compression and paging.
  • Provides image processing operations (resampling, blurring, etc).
  • Has an A* implementation for pathfinding through volume data.
The new release contains a number of improvements to both the library and also to the surrounding development process. You can read the release announcement here: http://www.volumesoffun.com/polyvox-version-0-2-released/

Hope someone finds it useful :-)

Template syntax question

30 July 2011 - 02:30 PM

Hi guys,

I know there are some template wizards around here so hopefully someone can help :-) I have a simple code example which I can't get to compile on both VS2010 and GCC. I can make simple changes to allow it to compile on either platform, but I haven't found the one correct solution which works on both. See the two commented lines in the code below:

template <typename Type>
class Base
{
public:
	template <typename NestedType>
	class Nested
	{
	};
};

template <typename Type>
class Derived : public Base<Type>
{
public:
	class Nested : public Base<Type>::Nested< int > //This line works on VS2010
	class Nested : public Base<Type>::template Nested< int > //This line works on GCC
	{
	};
};

int main(int argc, char** argv)
{
	Derived<int>::Nested nested;
	return 0;
}

In both cases, the line which works on one platform does not work on the other. If I get it the wrong way round the VS2010 error is:

error C2955: 'Base<Type>::Nested' : use of class template requires template argument list

And the GCC error is:

main.cpp:17: error: non-template ‘Nested’ used as template
main.cpp:17: note: use ‘Base<Type>::template Nested’ to indicate that it is a template

Any ideas what the correct syntax is?!

Thanks!

C++ Template Inheritance (accessing base member)

24 July 2011 - 02:07 AM

Hi Guys,

I just need a quick C++ template sanity check. The following code compiles successfully on GCC:

#include <iostream>

using namespace std;

template <typename Type>
class Base
{
protected:
  Type value;
};

template <typename Type>
class Derived : public Base<Type>
{
public:
  Type getValue()
  {
	return Base<Type>::value;
  }
};

int main(int argc, char** argv)
{
  Derived<int> derived;
  cout << "Hello " << derived.getValue() << endl;
  return 0;
}

However, if I remove the 'Base<Type>::' part from inside getValue() then it no longer compiles. That is, the code:

#include <iostream>

using namespace std;

template <typename Type>
class Base
{
protected:
  Type value;
};

template <typename Type>
class Derived : public Base<Type>
{
public:
  Type getValue()
  {
	return value;
  }
};

int main(int argc, char** argv)
{
  Derived<int> derived
  cout << "Hello " << derived.getValue() << endl;
  return 0;
}

Gives the error:

main.cpp: In member function ‘Type Derived<Type>::getValue()’:
main.cpp:18: error: ‘value’ was not declared in this scope

This surprises me, as I didn't think you needed to clarify the variable in that way as it is a member of the base class.

If I modify the classes to not be templatised then I don't need the 'Base<Type>::' prefix, so why do I need it in the templated case? Is the mistake elsewhere - maybe I'm doing template inheritance wrong?

Thanks!

C++ Template Question

29 April 2011 - 02:40 PM

Hi Guys, the following is not valid C++:

#include <list>

template <typename ContainerType, typename ElementType>
class MyClass
{
public:
	ElementType mSingleElement;
	ContainerType<ElementType> mContainerOfElements;
};

int main(int argc, char* argv[])
{
	MyClass<std::list, int> myClass;
	return 0;
}

In particular, it complains about the line:

ContainerType<ElementType> mContainerOfElements;

With the error message:

error C3203: 'list' : unspecialized class template can't be used as a template argument for template parameter 'ContainerType', expected a real type


I can get around this by writing it as follows:

#include <list>

template <typename ContainerType, typename ElementType>
class MyClass
{
public:
	ElementType mSingleElement;
	ContainerType mContainerOfElements;
};

int main(int argc, char* argv[])
{
	MyClass<std::list<int>, int> myClass;
	return 0;
}

This works, but it feels ugly to me that I have to specify 'int' twice in the following line:

MyClass<std::list<int>, int> myClass;

Is there are better way to write this?

Accessing C++ containers from multiple threads

12 February 2010 - 11:49 PM

Hi Guys, Sorry for the slightly noobish question but I'm not that experienced with threading. In my engine I have a thread pool and am able to send it tasks derived from a 'Runnable' base class. I would like to have my main thread retrieve the results from these tasks, and so my idea was to have the tasks write their results into a global(ish) queue. The main thread would then retrieve results from this queue at it's convenience. This means I need a queue which I can read and write safely from multiple threads, and my plan is initially to write a class which wraps the std::queue and a mutex. My wrapper will expose the push_back(), pop(), front(),etc methods, but will make sure the mutex is obtained before calling through to the std::queue implementations. So firstly I would like to know if this is a sensible and conventional approach, or whether there is a better way of doing things (given that I'm trying to keep it relatively simple). Secondly, I would like to know for which std::queue functions I actually need to lock the mutex before calling through. For example, can I safely call size() without locking the mutex? What about front()? Obviously push() and pop() are out. More generally, where can I find this information for all the containers? Is it specified in the C++ standard? Thanks for any input.

PARTNERS