Jump to content

  • Log In with Google      Sign In   
  • Create Account


l0k0

Member Since 17 Aug 2009
Offline Last Active Jan 26 2014 12:29 PM

Topics I've Started

One Camera With Multiple Targets

20 March 2012 - 03:55 PM

I'm currently working on a 3D multiplayer game with a singular camera that tracks multiple targets. Right now it translates its position relative to the centroid. This causes issues when, for example, 3 players are in one corner and one player is in the other. Anyone have a relatively simple algorithm that properly weights how these targets contribute to the lookat/position of the camera and ensures no target ever goes off screen?

Forcing Alignment of SSE Intrinsics Types onto the Heap with Class Hierachies

21 January 2012 - 07:56 PM

I'm currently developing a Component-Entity Model, and am getting rather annoyed by my intrinsic __m128 based matrices and vectors breaking when they are aligned onto the heap. I know they must be aligned on 16 byte bounds and everything works fine when things are done statically. Here is the basic hierachy currently in place:

class Object {
	string name;
	uint32 instanceId;
};

class Component : public Object {
	GameObject *gameObject;
	uint32 typeId;
}; // 44 bytes total in size

class Transform : public Component {
	Vector2 localPosition; // 52 bytes
	Vector2 localScale;  // 60 bytes
	Transform *parent;  // 64 bytes
	// Are we not aligned on a 16 bytes boundary here?
	Matrix4 worldMatrix; // holds 4 vector 4s (which wrap __m128)
	std::unordered_map<tbdString, tbdTransform*> children;
	tbdVector2 worldPosition;
	tbdVector2 worldScale;
	float32 localRotation;
	float32 worldRotation;
	bool isDirty;
	uint8 __pad[15] // -- total of 256 bytes
};

Unfortunately, despite trying to ensure the worldMatrix was aligned on a proper boundary, it still breaks. I tried overriding new/delete and using an Aligned version of malloc/free, but that would break in Object's constructor. Do I need to just implement object and component as an interface or an abstract class so I can reorder the structure of the concrete class the way I want/need to? Also, why is this failing in its current form? Thanks in advance for the help. Intrinsics are still new to me.

Component Entity Model Message Passing in C++

15 January 2012 - 11:37 PM

I'm implementing the generic string based message passing functionality seen in other component entity models. My idea is to do the following: keep a hash table in each component of string names and member function addresses. When sending a message from a game object, it looks for a function with the given name in each component/behavoir. If found it is called and the args are passed to it.

Here are my concerns with this approach:
1) My current idea is to pass a void ** array as the arguments so the function prototypes are consistent. I don't think the template ju jitsu would be worth it here, if even doable for "all" or "most" function prototypes.
2) How might you handle returns from sendMessage complicit functions? Put them at the end of the array? This doesn't seem very intuitive but is there another option?
3) Right now if two components have the same string name message handler, when sendMessage is invoked, only one of them will be called. This is a bit concerning. Anyway to get around this besides using descriptive names. Consider this example:

class Armor : public Component {

DECLARE_COMPONENT(Armor, ARMOR_ID, Component)
public:
void setHealth(void **args) {
	// set the armor health
}

Armor() : Component() {
REGISTER_FUNC(Armor, "setHealth", &setHealth);
}

};

class Health: public Component {

DECLARE_COMPONENT(Health, HEALTH_ID, Component)
public:
void setHealth(void **args) {
	// set the health
}

Health() : Component() {
REGISTER_FUNC(Health, "setHealth", &setHealth);
}

};



GameObject.sendMessage() will only call one. broadcastMessage() will call both despite this being undesirable. Is the only way to avoid this to use more descriptive message names, e.g. "Health_SetHealth" and "Armor_SetArmor". I realize that in some cases this is prefferred. For example, one component can be aware of a "health changed" event without any dependencies on the actual health component. For things like A.I. scripts this can keep things decoupled and encapsulated.

Also, I'm aware that member function pointers are a PITA when inheritance is concerned. My DECLARE macro already handles this somewhat messy process by generating a unique typedef and table name from the classname and calling the base class's implementation of handleMessage if nothing is found. I'm more interested with alternatives/solutions to the ambiguous name issue and the rather clunky practice of passing void pointer arrays for everything.

Thanks in advance!

Component Entity Model Without RTTI

20 December 2011 - 02:08 PM

I'm writing my own component entity model in C++. At the moment, it is somewhat similar to the framework used for Unity Scripting (particularly in C# with templates). Since I'm still in the early phases of the project, I just used type info to handle the type based retrieval of components like so:

template<class T> T * getComponent() {
	for (int i = 0; i < componentList.size(); ++i) {
    	if (typeid(*componentList[i]) == typeid(T)) {
        	return componentList[i];
		}
	}
	return NULL;
}


However, RTTI (along with exceptions) is typically best left disabled in frameworks and engines if possible. What would you recommend for a minimalist way to get this functionality for components only? I'm willing (and hoping) to use the preprocessor to declare classes and assign them a "type id" kept inside the components themselves. The tricky issue is that this must also support subclasses. So if I call getComponent on a base class it must also return a subclass if it is found.

Is a 32 bit type id determined at compile time my best option here? Any tips from people who have implemented the thing themselves?

Spatial Partioning Schemes For Path Graphs

20 July 2011 - 03:59 PM

First, if this topic would be better placed in the Artificial Intelligence section I apologize. I figured since it would focus on spatial partitioning it would be more appropriately placed in this sub forum.

Anyways, I recently wrote a simple path graph that used A* to provide efficient navigation through my world. It is currently a bit unoptimized for a few reasons, the biggest being a lack of spatial partitioning. There are some support functions which are vital in determining new paths based on game events/behaviors. At the moment, these functions basically just determine the closest node, or most appropriate path given a position in world coordinates, such as the following.

Node FindClosestNode(Vector3 pt);
NodePath FindPath(Vector3 pt, Node goal);
NodePath FindPath(Vector3 start, Vector3 end);

Now obviously, calculating the squared distance in a brute force loop isn't an economical way to do this. Unfortunately, when thinking of schemes I've used in the past, nothing really jumped out at me.
There are two major concerns that differentiate path nodes from typical objects thrown into a broad phase. One is that path nodes don't have any volume, they are merely points in space. In addition, they are more or less static, and there is never any need to determine collisions between the path nodes themselves.

We can rule out a Sort and Sweep, since the path nodes are basically static and we aren't concerned with intersections between them.
A bounding volume hierarchy would be an interesting experiment, since the arcs could form a merged AABB that is recursively split. However, this seems like it might result in very deep traversals for large paths.

Currently I'm leaning towards a finite sized grid, using fat objects or forcibly checking all the surrounding cells. The idea is to cast sphere with a sufficient radius at the passed in position into the grid. If no overlaps are found, search the neighboring cells until an occupied cell is met.

So...to anyone who has written a broadphase for a path graph before, what spatial partitioning scheme would you recommend?

PARTNERS