Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Member Since 18 Nov 2009
Offline Last Active Nov 05 2013 01:00 AM

Topics I've Started

Complicated visibility determination?

03 November 2011 - 09:19 PM

So I'm making a turn based game, it's in a 3D engine but it's really a 2D game I guess.

I need to be able to tell what characters are visible to other characters, but I calculate all the AI decisions for the turn before the enemy takes its turn.

The game has interrupts so it's important that the AI is smart enough to be aware of terrain. What I mean by this is imagine that they are running down a corridor. At each branching they need to be careful because if an enemy is there their turn might get interrupted. They also could choose to guard that spot for a turn before proceeding, just to see if someone is coming.

So if they just blindly run around it kind of kills the ability to have good AI, but I am not sure how I should do this. I guess I could precalculate the walkable areas into convex polygons. The problem here is on some maps there could be open levels. Imagine two walkways across from each other. The terrain and walkable areas are not contiguous but the areas are still visible. Also it's kind of a lot of work (though this will help with pathfinding as well).

Is there some other way to go about this? I have read a little here and there but mainly for FPSs or RTS not so much for a turn based tactical game.

Make Visual C++ do something on break?

11 September 2011 - 04:05 PM

I have an error logger but I am currently forced to flush it constantly which is kind of annoying. The same basic idea comes up for other things as well all the time, though, so it's not this one issue.

Is this something that can be done in a reasonably easy manner or not?

Reverse mouse picking

22 April 2011 - 04:27 AM

I'm making a 3D game with an overhead freeranging camera. I have a method to mouse pick that works correctly, creating a ray for the mouse point then projecting it til it collides with something. I know it works properly because any markers I create show up at the right places.

Several times I've tried to go the other direction, though, and always had problems. Using the rays and camera focus and all that crap is very error prone. I don't even know for sure all of it works correctly in the engine. Most likely it does but there's a chance I am using something wrong or whatever. At any rate, i've given up on the recommended method it just doesn't seem to work.

Instead I want to just compute it using geometry. However, that seems to be failing too, but hopefully it's failing in a way that someone else can point out.

So using that method to project into the game world, I am projecting out from each of the corner mouse positions into the plane where z = 0. That is projecting from 3D perspective to a 2D plane.

From there I take the x and y axes, and call a method to find the closest point on each axis to the reverse pick point. Then I find the distance from the origin and use this to calculate the mouse cursor location for that point. Seems like it should work, but somehow it fails. Does this approach have something wrong with it? If not I guess there can be a bug somewhere else. Now the dummy case should be to project the cursor out to the plane, then project it back but it always fails and I can't see what's wrong. In practice there's a reason for doing this that can't be ignored, though, that's just the test case.

If I print out everything it seems if I project every mouse point to the plane the distances between them are regular and describe lines as I'd expect them to. So it seems like my method should be workable but it completely fails. I know the plane can be skewed but (or so I think) it should not matter.

Here is the code. Maybe something obvious is there? Been screwing with this 14 hours today so at this point a fresh pair of eyes would be helpful.

//first, I have this method which I know works
Point3 CollisionUtil::projectCursorPointToGround(Point screenPoint)

//this method fails
Point CollisionUtil::screenPointForWorldPoint(Point3 worldPoint)
	Point cursorPoint;

	float screenWidth = getDisplayWidth();
	float screenHeight = getDisplayHeight();

	Point3 last = projectCursorPointToGround(Point(0, 0));

	Point3 ul = projectCursorPointToGround(Point(0, 0));
	Point3 ur = projectCursorPointToGround(Point(screenWidth, 0));
	Point3 ll = projectCursorPointToGround(Point(0, screenHeight));
	Point3 lr = projectCursorPointToGround(Point(screenWidth, screenHeight));

	Point3 xAxis = ur-ul;
	Point3 yAxis = ll-ul;

	Point3 pointOnXAxis = closestPointOnLine(worldPoint, ul, ur);
	Point3 pointOnYAxis = closestPointOnLine(worldPoint, ul, ll);

	Point3 xProjection = pointOnXAxis-ul;
	Point3 yProjection = pointOnYAxis-ul;

	float xAxisMagnitude = magnitude(xAxis);
	float yAxisMagnitude = magnitude(yAxis);

	float xRatio = screenWidth/xAxisMagnitude;
	float yRatio = screenHeight/yAxisMagnitude;

	float xMagnitude = magnitude(xProjection);
	float yMagnitude = magnitude(yProjection);

	long pointX = round(xMagnitude*xRatio);
	long pointY = round(yMagnitude*yRatio);


	return cursorPoint;

POD detection in C++?

19 April 2011 - 05:05 PM

I have a resizable array class. Works great but I sometimes have a case where I want to make a large array and initialize it, use it once for an algorithm, then ditch it. Unfortunately there's no way to get around this without incurring even worse costs in another area.

The algorithm runs very fast, but the init time is creeping up as I go to larger and larger arrays. In debug mode it takes about 40ms to initialize an array of about 2 million. The array is a template, and 90% of the init time seems to be calling placement new on preallocated memory to construct the objects. This is the case even when it's just an array of longs. Most of the time array is much smaller but I want to be able to handle that case without slowdowns.

I know I can declare a special case for each and every POD type I want to just skip the constructor business with, but that is a real pain. I think I looked into the idea of determining if something is a POD or not before and eventually gave up but I thought I'd throw it out there and see if anyone had some magic solution. (and please don't give usual annoying comments of "use STL!" or "don't optimize!").

My other thought is to make an object of the type then memset the object into the array memory for initialization. That is not really a proper way to initialize anything but it should be safe for my purposes because any time a value is set to the array it's guaranteed to be initialized though technically some objects with weird copy behavior will probably fail to work with the class (but when if it happens, it should be obvious). But of course it's the hackiest of hacks and kind of a pain so hopefully there is something better.

Smoothing a path into line segments of certain size

07 April 2011 - 06:55 PM

I already have pathfinding working but the path points are jagged at times.

The movement goes in discreet step sizes but it's not intended to be tile based in any way even though the underlying structure I use is.

What I have is a list of somewhat jagged steps on a 2D plane. What I need is to come up with a set points that have an exact length between them to the target. The very last point will effectively just be ignored because the movement must be in certain multiples because there is a time unit cost associated with each step (this is for a turn based game).

Not sure how to even start, really. I know that some people use hermitic curves for smoothing but I don't really want a curve but straight lines.