[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

my biggest fear is performance. I'm coding 2D tile maps

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 1

File: 1437953374835.jpg (38KB, 400x388px) Image search: [Google]
1437953374835.jpg
38KB, 400x388px
my biggest fear is performance.

I'm coding 2D tile maps and everything like nested lists containing objects iterating over other nested lists containing objects.

but I'm afraid looping over every lists (like looping the tilesets with the characters, enemies, bullets, sparks) is the worst possible scenario.

my game is a 2D shit on libgdx, how do I overcome this fear I'm doing shit performance?
>>
>>56009625
If this is a hobby project I wouldn't worry about it until you start to notice slowdown. Sounds like you could use a quad-tree or some variant to do stuff slightly better. But if you don't know what that is it's honestly probably not worth the massive detour to learn it until you need it.
>>
>>56009661

for (Enemy e : enemies)
{
for (Tileset t : tiles)
{
for (Spark s : sparks)
{
// Do the game code
}
}
}

this is my code structure generally.
Imagine being the worst case scenario a 2D rpg maker game with some touhou style of gameplay.
>>
>>56009680
Does everything move every turn? Why not update only "live" tiles?
>>
>>56009680
I'm assuming the game-screen is split up into tiles. In that case, given the position of the enemy (something I assume you can look up given the enemy) you should be able to retrieve the tile (and surrounding tiles) which saves you having to iterate over all tiles. Then, from the tile, look up the sparks attached to that tile.

This pushes time complexity into space complexity, since each tile e.g. has to store its spark.

For a proper solution, look into quad-trees if you like. You'll basically be storing all your enemies and tiles in the same data structure.
>>
>>56009736
>>56009741
So basically I make a 2D array of objects, and some quadtree, right?

how do I retrieve an object from an array or lists if I have the tileset coordinates?
>>
>>56009736
Hi there!

You seem to have made a bit of a mistake in your post. Luckily, the users of 4chan are always willing to help you clear this problem right up! You appear to have used a tripcode when posting, but your identity has nothing at all to do with the conversation! Whoops! You should always remember to stop using your tripcode when the thread it was used for is gone, unless another one is started! Posting with a tripcode when it isn't necessary is poor form. You should always try to post anonymously, unless your identity is absolutely vital to the post that you're making!

Now, there's no need to thank me - I'm just doing my bit to help you get used to the anonymous image-board culture!
>>
>>56009806

Fuck off, falcon is the only person on /g/ allowed to have a trip
>>
do some bigO notation analysis on your code. loops within loops are bad. O^2 time vs two loops in a row which is just N time.

you can have sub sets of tiles "map chunks" and then only load in the chunk that is "visible" to the camera, and work on smaller sets of data.

you can maybe order your data, a longer insert time but faster to read from etc, depending on your need. you coudl use a heap or tree to make it easier to iterate through those new smaller lists.

restructure your data so it's not in nested loops. use a complex data structure rather than an array / list. so that you aren't nesting loops or repeating interations over similar data.
>>
>>56009858
so you mean a tree?
what data structures would be for something like a 2D rpg with some bullet hell stuff, for curiosity?
>>
>>56009625

APPROACH A: Purer

Keep two 2D arrays

1: the render arrary. You loop over it exactly once. Finished for rendering.

2: the real array. A 2D array of stacks. The top of each stack has a copy in the render array.

push(item) {
overwrite_render_array(item, coords);
push(item, stacks[coords]); // many ways to do this bit.
}

APPROACH B: Easier

Have the 2D array of stacks, but iterate thus

for each element in 2D grid {
peek top of stack
}

Done.
>>
>>56009833
>defending tripfags
You have to go back
>>
>>56009625
Granted these books are kinda dated, but the contents are still valid. Pick up
Real-Time Collision Detection by Ericson
and
Real-Time Rendering by Möller and Haines
Thread posts: 13
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.