Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


MarkS

Member Since 09 Jan 2001
Offline Last Active Yesterday, 10:18 PM

Topics I've Started

How to use a unique_ptr as a member variable?

25 April 2015 - 12:52 PM

All of the examples that I can find online shows unique_ptr defined within a function, but never within a class. I want to use this to store the frame image data for a sprite, but doing so is a little unclear. I am aware of make_unique, but I am using VS 2012 and it doesn't offer it, or if it does, it is very well hidden.

This is what I've got so far, cobbled together from bits and pieces around the net:
 

class frame_data{
public:
frame_data(unsigned long width,unsigned long height);
~frame_data();
 
private:
std::unique_ptr<unsigned char> _data;
 
unsigned long _width;
unsigned long _height;
};
 

frame_data::frame_data(unsigned long width,unsigned long height) : _height(height), _width(width)
{
std::unique_ptr<unsigned char> temp(new unsigned char(width * height * 4));
 
_data = std::move(temp);
}
 
frame_data::~frame_data()
{
}

My question is with the construction and assignment of the unique_ptr in the constructor. Is this the best or only method without using make_unique?


Replying to old threads...

05 April 2015 - 06:36 PM

When you open a thread older than 60 days, you get a nice alert, along with a statement that you may not reply to the thread and to start a new topic. Interestingly, the software seems to be ignoring that.
 
The thread in question, although it doesn't seem to be limited to a single thread: http://www.gamedev.net/topic/626072-what-do-i-need-to-learn-for-a-zork-clone-in-c/

Looking for a path finding algorithm, with some caveats...

14 December 2014 - 10:03 PM

There is a game called "Flow Free". I found it to be highly addictive, and thought it would be fun to remake it in 3D. To do so requires the ability to generate the levels automatically and check the generated levels to ensure that it is possible to solve. To start, I want to create a 2D solver. This poses quite a challenge. It appears simple, but the requirements of the game make this quite difficult. All cells must be visited and no two paths can cross.

Here is a 9x9 cell level and its solution:

game.png

 

The solution would break most path finding algorithms, and I'm not sure this really is a problem that a path finding algorithm would be best suited for anyway. While playing the game slowly and consciously thinking out the moves, I came to realize that I was actually solving for each different path while actively working on a single path. This leads me to think it is more of an AI issue than a simple path finding issue.

 

Take the magenta path as an example. The correct solution is not one that would be found via any path finding algorithm. A shorter path would be selected, but any other path would block out the red, brown and green paths. This means that while solving for the magenta, the algorithm must also be solving for the other paths. Even so, it is possibly to solve some levels without visiting all of the cells. This requires some rather highly serpentine routes that wouldn't be obvious from an algorithmic standpoint.

 

I haven't started coding, but I'm not sure how to begin. How would I go about this? The logic to code this escapes me at the moment.


Question about dereferencing syntax in C/C++...

13 August 2013 - 04:31 PM

I have always accepted how C/C++ dreferences structs and pointers to structs until a recent thread on a new language, C-UP. The developer stated that the language doesn't use the '->' operator to dereference pointers.

This makes a lot of sense. I'm curious why the C++ standard still requires the use of '->' and '*'?
 
struct foo{
int i;
int *j;
};
 
foo foo1,*foo2;
int temp;

// These next lines do the exact same thing...
foo1.i = 1;
foo2->i = 1;
temp = foo1.i;
temp = foo2->i;
temp = *foo1.j;
temp = *foo2->j;
The only reason I can see for the disparity is that '->' and '*' informs the reader that a pointer is being dereferenced. Does it truly matter? All that is being done is accessing a member of a class or struct.

List of C++11 compliant compilers?

01 August 2013 - 10:33 AM

I'm getting fed up with Visual Studio Express 2012. There are so many new language features that I can only look at in code samples.

 

Are there any *free* Windows-based C++11 compilers? What are some recommendations?


PARTNERS