Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Jul 2007
Offline Last Active Jun 01 2014 12:30 PM

Topics I've Started

Mediator Pattern Help!

27 May 2014 - 09:47 PM

Hey all,


I'm writing a Mediator class in C++ and am having trouble with a part of it.  I've done this before in C# (which was really easy) and trying to do the same thing in C++ is kicking my butt.  I have a std::map that contains a std::string for the key and a std::vector<> for the value.  The idea being any number of functions/methods can be registered under any number of keys and all said functions/methods can be invoked with one call.


I'm having two primary problems:  1, I can't figure out how to get both functions AND class methods into the std::map.  Currently I'm using:

typedef std::function<void(void* Object)> FunctionDef;

I have a Register method in my Mediator class that takes a std::string for the key and a FunctionDef for the value.  So far this works fine for functions but I can't get it to work with class methods.


And 2;  I have an Unregister method in my Mediator class that takes the same inputs and removes the appropriate function from the appropriate key.  Or, at least, it's supposed too. 

template<class T>
static void Unregister(std::string Key, T Function)
		if (MediatorMap.count(Key) != 0)
			FunctionDef Func = Function;
			for (std::vector<FunctionDef>::iterator It = MediatorMap[Key].begin();
				It != MediatorMap[Key].end();
				 if ((*It).target_type().name() == Func.target_type().name())
					std::cout << "1" << std::endl;

					std::cout << (*It).target<T>() << " == " << Func.target<T>() << " ?? \n";
					if ((*It).target<T>() == Func.target<T>())
						std::cout << "2" << std::endl;

			if (MediatorMap[Key].size() == 0)

This is basicaly just testing code ATM.  The problem seems to be, and mind you I can only test this with functions, that whatever info is provided by .target<T>() (I'm guessing the pointer) never matches, even when sending the same function.


I admit to not really being sure of what I'm doing.  This is new territory for me and my C++ is a little rusty.  Any help would be appreciated.

A few questions on binding VBOs...

24 December 2012 - 10:11 PM

Hey all,


The question isn't so much how to do it, I've figured that out, it's how you unbind a VBO and why having a bound VBO seems to block the usage of Vertex Arrays?


I have the following code in my rendering function:


if (VBO_Support)
					glVertexPointer(	3,	GL_FLOAT,	sizeof(MyVertex),	(GLvoid*) (*RenderListIT)->RenderMesh->VBO_Offset					);
					glNormalPointer(		GL_FLOAT,	sizeof(MyVertex),	(GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*3)	);
					glTexCoordPointer(	2,	GL_FLOAT,	sizeof(MyVertex),	(GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*6)	);
					glColorPointer(		3,	GL_FLOAT,	sizeof(MyVertex),	(GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*8)	);
					glVertexPointer(	3,	GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->x		);
					glNormalPointer(		GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->nx	);
					glTexCoordPointer(	2,	GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->u		);
					glColorPointer(		3,	GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->a		);

And I have a toggle that changes VBO_Support back and forth.  When I have a VBO bound (glBindBufferARB()) and VBO_Support = true everything runs fine but none of my objects display.  Why is that?


Thanks in advance.

Best method for a top down, side scrolling camera.

18 October 2012 - 09:15 PM

Ive seen examples using gluLookAt(), glOrtho(), gluOrtho2d(), etc. One example I saw said all you need is to just use glTranslate(). So what is presently the best, easiest method to achieve this effect?

Thanks in advance.

VBO help...

18 September 2012 - 11:43 AM

Having trouble getting my VBOs to work. No compiler errors. No run time errors. Just nothing showing up on the screen. VA's work though. I'm wondering if my implementation is the issue. I'll try to explain as best I can...

All the model information gets stored in the following:

struct MyVertex
float x, y, z;  // Vertex
float nx, ny, nz; // Normal
float u, v;   // Texcoords
float a, r, g, b; // Color
float padding[4];

This is how I load the VBO:

for (Itter = Mesh_Multimap.begin(); Itter != Mesh_Multimap.end(); ++Itter)
  VBO_Size += (*Itter).second->NumVerticies*sizeof(MyVertex);
glGenBuffersARB( 1, &VBO_ID );
for (VBO_Vector_IT = VBO_Vector.begin(); VBO_Vector_IT != VBO_Vector.end(); ++VBO_Vector_IT)
   glBufferSubDataARB( GL_ARRAY_BUFFER_ARB, VBO_Offset, (*VBO_Vector_IT)->NumVerticies*sizeof(MyVertex), (*VBO_Vector_IT)->VertexData );
   (*VBO_Vector_IT)->VBO_Offset = VBO_Offset;
   VBO_Offset += (*VBO_Vector_IT)->NumVerticies*sizeof(MyVertex);


glVertexPointer( 3, GL_FLOAT, 0, &(*RenderListIT)->RenderMesh->VBO_Offset );
glNormalPointer(  GL_FLOAT, 0, &(*RenderListIT)->RenderMesh->VBO_Offset );
glTexCoordPointer( 2, GL_FLOAT, 0, &(*RenderListIT)->RenderMesh->VBO_Offset );

That's the point that's giving me pause. When just rendering with VAs I need to do the following:

glVertexPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->x  );
glNormalPointer(  GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->nx  );
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->u  );
glColorPointer(  3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->a  );

I had to specify what part of the struct to pull the appropriate data from. Am I supposed to be doing this with the VBOs somehow? What am I missing?

unique hashed pointers and statistical probability?

30 August 2012 - 04:39 PM

I'm trying to generate a unique key from the pointers of various objects for the sake of sorting by catagory, sub catagory, etc. They key itself will be 32bit.

For the sake of this question let's say I have a Car object made up of various Make, Model, Color, Package objects. That Car object is put into a Vector and sorted so that all the given catagories are lumped together appropriately.

If I only have a total of 8 Makes, and the Make is our most important catagory to sort by, then I use the 4 most significant bits of our key. If I have 100 models per make thats the next 7 bits. 20 colors per model is the next 5 bits. So on.

Where my question comes in is this. If I'm using a 32 pointer for my Make, Model, Color, Package objects, I need to somehow reduce that size down to the size of associated bits in the key. So for my Make bits I need to reduce the size of my Make pointer down to 4 bits and still maintain some level of integrity in regards to it's uniqueness. For obvious reseaons I can't have my Ford and Chevy come out the same at 4 bits.

The method I've been playing with so far has looked something like this:

I take bottom 16 bits of my pointer and AND them together with my top 16 bits. So:

TempID = MakeID & 0x000fff
TempID <<= 16
MakeId &= TempID

At this point it seems to me (and please correct me if I'm wrong) that there is only one other pointer that would give me the same result and the statistical probability of getting that pointer would be incredible minute. But I need it to be 4 bits and not 16. So I can do that two more times. What I'm worried about is the ability to maintain the unique-ness and how important that unique-ness is in terms of the statistical possibility of getting identicle results from another pointer.

I hope this all makes sense. It's giving me a headache just thinking about it. lol.