@Gajet The problem I have with this, and why I asked the one who started it for qualification about what he means with "straight line", is something like this: Assuming green is the "movable area" and yellow is the player position here ...
... which of the points A, B and C is reachable in a "straight line" to the player?
B can be ... if the mobs can run diagonally. Can they? We don't know.
C is not valid .. unless the mobs can run diagonally, and prefer diagonal movement to horizontal/vertical one, in which case the mob CAN reach the player regardless.
Wouldn't this algorithm then boil down to: foreach(point in area on the edge and not a wall) mob = spawn_mob_at(point), result = mob.move_to(player.position) if( result = hit ) point.mark_as_spawner()?
Add in a catching of results (if a point is marked as a valid path of another spawner already, we don't need to check further) if you want, and you're done.
And no, you won't get more performance your way. From the edges to the player + catching of results of previous runs will get you more performance, especially if you go around the edge ordered.
But that has a cost: You need to save more data in the map, in particular the information about if a previous spawner who took this point on the way managed to get to the player, or if he failed.
I also have no idea how to implement it on the GPU alone. :D
just think about it this way: to use gpu power to maximum value you need to run same code on many threads without having them depend on each others results
The other problem with the "test from the player to the spawn point" approach is that in a discrete space, A->B can be reachable in a straight line while B->A isn't. See point C in my picture above: If the rule is "try to go diagonally, then go the rest of the way up, down, left or right", C->player is reachable in "straight line", player->C isn't.
C->player can be reachable if you reverse the movement order for checking. and player->C can be reachable too, but it'll create a bad dirty code. by the way that movement order will not create an straight line in my defenition
The entities don't exist when the "LoadContent" method is called, so I thought it would be nice to make the method static, then either manually, or through reflection, call each entity's "LoadContent"
I'm working in XNA, is there an other way I should be doing this?
yeah... I know. But if it's not static, then I need an instance of the entity to call LoadContent on, and that gives the wrong impression, it won't be loading its own resources, it'll be loading resources for all future instances of the entity
That is correct. I am just refactoring some stuff so that I can add a new Sprite Library module in, and the Sprite classes that I am working with want to load at the startup kinda like: code.google.com/p/xnaspritelib/source/browse/trunk/…
(will read the wiki in a sec)
In my code, the LoadContent() gets called right at the start, and only ever once. As you can see, it loads a Sprite from a file (which in turn loads images). This Sprite is stored internally because it will be used for each and every instance of a "SimpleSprite" in the example