monkyyy wrote:impossible? isnt there a way to draw a 2D image as a "quad" and then from there make a table of all objects needed, sorting by distance?
When I say impossible, I'm referring to making maps that aren't an easy-on-the-CPU grid. DOOM had maps that could contain any shape room, each room was made up of sectors, and each sector was made up of linedefs. Each map could have thousands of linedefs. Hundreds of sectors. The map creation utilities of the time had to
use BSP to generate node maps which, to put it in laymans terms, split the map into smaller pieces that the game engine could then work with. i.e., each sector could tell the engine which other sectors it could "see" so the engine would only have to iterate over sectors and linedefs that were actually in view, but in order to do it, it took a lot of calculating beforehand.
In other words, you can't just loop through every single wall in the map to see if it's in view, that would cause so much slowdown, so you need to devise a method to tell which lines are within view quickly by creating a tree that lists what lines are visible from where and account for every sector.
Here's an example to make it easier...
Code: Select all
+---+
| |
| C |
| |
+---+---+---+
| | | |
| B | A | D |
| | | |
+---+---+---+
| |
| E |
| |
+---+
In this example, room A can see B, D and E. D can see A. E can see A. B can see A and C. C can see B. I guess if you were to create an engine that used rooms, you'd first check the sector (room) you're in, which might be A. Check its list of rooms it can see, figure out which of those rooms are in view and iterate over them. Say you can see B and E from A but not D. You check B and E. E can only see A so it stops. B can see C. But can YOU see C? So it checks if C is in view too by using the power of MATHS to check the angle of each corner of the sector to see if it's within your view. If so, it iterates over the rooms C can see. Which in this case is only B, which is already drawn. In the case of you standing in A, the game should now have a list of rooms you the player can see. A, B, C and E. It then iterates over the lines in each of these rooms and once again checks to see if you can see them. It also has to make sure to only iterate over walls that are shared (for instance the wall between A and B which in DOOM terms would be a passable linedef that has no texture) or ones that have no texture that can be seen (Remember that in DOOM, linedefs had three textures for each side. Upper, Lower and Middle. Middle would be the one you walk through if the wall is passable) Oh, and it also has to add every enemy and "thing" that the sector contains to another list that will later need to be looped through. This list is recreated every frame.
Now imagine that on a much larger map. With many many connected sectors. You're talking about a sector tree the size of a giant redwood. If you were to have a hundred sectors all in view, you'd be waiting for the engine to check every single one every frame.
Not to mention calculating all the enemies AI for all the enemies in the level, even ones that aren't on screen.
NOW, after the rendering is done, you ALSO have to have some good hit detection. If you ask me, this would actually be harder to figure out. Grid collision is as easy as
if map[math.floor(player.x)][math.floor(player.y)].hit == true then which is why so many Indie 3D FPS games are Wolfenstein-style these days. (Google: "Gun Godz") But collision with arbitrary shapes is a bit harder. I guess if you incorporated the collision detection from Box2D it might help, but how slow are you going to get at this point?
Then when all is said and done, you still have to draw everything. Which includes every line for each wall (The amount would be equivalent or greater than the horizontal resolution you use) and every visible thing and enemy.
I'm not saying it's not possible. I mean, someone created a viable DOOM engine in JavaScript that ran pretty fast, it'll just be hard. Plus those people always seem to obfuscate their code and good luck converting such a large amount of JS to Lua.
And then remember that the floors and ceilings would be impossible in Löve as it is, and using my method would slow the game down even more.
I'll just stick to Wolfenstein engines for now. It's a good start. And it's retro.