HaHAA

haHAA

Attached: unknown.png (502x317, 40K)

Thinking about it for 3 seconds this seems like a good option, Whats wrong with it?

>O(n^3)
How is this a good option?

>if (y< layers.size()-1)

Why put that there when you can just remove the last iteration of the y loop and kill off a fuckton of pointless checks.

>iterating over n^3 data is n^3 time

no duh

I wrote comments so it is okay

>I write code in C++ because is fast

Can't you just combine those if statements into
if (layers[y][x][z] != 0 && y < layers.size () - 1 && layers[y + 1][x][z] == 0)

i don' think it matters, the compiler will probably combine them anyway, it might even combine to y >= layers.size() too

Probably, but I was saying for legibility purposes. That's two unnecessary indents within those if statements. Also, is right. You could just put y < layers.size() - 1 at the top for loop and save time with unnecessary checks.

I'm no good at programming. what would be a better approach for looping through all that stuff?

> writing lazy code and assuming the compiler will fix it.

This is a bad attitude.

I laughed.

Recursion.

nothing
if you need to loop it you need to loop it
retards just through an autism fit when they see real code that has real nesting that isn't hidden away in functions

its not O(n^3), it's iterating through a 3D structure, it's O(n)

I think its the layers.size() calling every loop that's doing it.

When I think of big O, I think of the anime.

Attached: 240px-Big_o.jpg (240x350, 27K)

and unless layers.size() is repeated as another loop, it's O(size*x*y), which is O(n)

running in an 11-D universe it's really O(root(n))

there's an unknown of what layers actually is (is it a linked list? is it a custom function?). It would probably be prudent to cache the size anyway so you're not making an ynnecessary call.

In addition the size function is called twice, first in the upper loop, then again in the middle.

>OP

Attached: 1517860406479.jpg (800x450, 37K)

>lazy code
In this case it does fundamentally the same exact operations.

You have to meet all three conditions to move forward. Putting them as one if with && or putting them in consecutive ifs by themselves isn't going to change that.

The only real argument to be made is a style one.

Also an option to cache the result as well and put it in a hash map so that when the function is called again with the same data, it would skip the recalculation.

Horrible code, end your life right now.

Looks normal up until whatever is in the x loop, then IDK I'd have to see more.

Please go back to Jow Forums with your strong opinions over shit you know nothing about.
>Can't you slam all your conditionals into one big line
No, you can't. You only know the very top of those conditionals. You don't know if all the code from one is going to be in the other, because they could have shit under the conditionals.
It's not O(n^3), it's O(m * n^2) and O(n^3) isn't automatically bad either. For a 3d struct, that's perfectly fucking fine.
No, it isn't. You don't know what you're talking about.

His point was that the code is horrible, and the code is fine. You're retarded.

>O(n^3) its fine

It's O(n)
O(n^2) if you want to be disingenuous and count layers.size() as part of the algorithm

>the main loop conditional its y < layers.size()
>do an if(y< layers.size()) inside

The programmer clearly doesnt know what he is doing

>b-but the compiler will fix it
Lame

for all you know it just returns a value

It's O(m * n^2). The third line (first for loop) doesn't depend on the CHUNK_SIZE variable.
Additionally, yes, it's fine. Big-O notation is not a measurement of real world speed. People who don't even know Big-O notation (you) shouldn't be allowed to post about it.

The line isn't just y < layers.size(). It's y < layers.size() - 1. You're a retard who can't even fucking read. You don't need to post here. You should take a break from Jow Forums, try to learn more about this subject, then come back.

>doing an if for every y except the last one instead of just covering that case at the end out of the for loop like an unrolled loop which its what actually happens

Its cubic anyway you sperg. Considering that its something 3d that probably needs to be on 60 fps and lot of objects, yes you have a big n and it will matter

video games iterate over 3D data all the time
how the fuck do you think they do it if not like the OP?

>>doing an if for every y except the last one instead of just covering that case at the end out of the for loop like an unrolled
for (int x = 0; x < 10; x++) {
if (x < 4) {
print("foo");
}
print("bar");
}

Is different than
for (int x = 0; x < 4; x++) {
print("foo");
print("bar");
}

You are a braindead code monkey who can only type code and can't read the code of others. Just stop posting.
>"Its cubic anyway you sperg. Considering that its something 3d that probably needs to be on 60 fps and lot of objects, yes you have a big n and it will matter"
>Any use of O(n^3) are going to make the frame rate low for someone's voxel mesh generator
>O(n^3) and O(m * n^2) are the same
You've clearly never dealt with any game development in your entire life. Lets see that github, dumb dumb.

How would that have a better time complexity

Attached: 1517149177840.png (200x300, 28K)

>He needs recursion for a voxel based mesh generator
>He actively wants to make the code slower to "fix" it

Attached: 44140290_1400425620089497_272973136192864256_n.jpg (668x669, 19K)

t. literal retard

sums it up

> for y...
> for z...
> for x...
> layers[y][x][z]
what's DoD?

Attached: 1540284227802.jpg (456x810, 27K)

hf blowing up your stack

>It's not O(n^3), it's O(m * n^2) and O(n^3) isn't automatically bad either. For a 3d struct, that's perfectly fucking fine.
What about octotrees?

You should really just use math to map 3D to 1D and have a flat array, it's much easier to work with.

Also layers[x][y][z] != 0 ? that should be an enum

l < 30 ? why 30? no magic numbers.

Iterating through the world is not n^3 it's n, the three for loops are still aren't doing n^3 work

It would eliminate your need to have three nested for loops, isntead you could just loop over each element in the array, and then use math if you need to figure out which x / y / z the i'th chunk represents.

Here, I wiped your ass for you:
int convert3Dto1D(int x, int y, int z) {
if (x < 0 || y < 0 || z < 0) {
return -1;
}

return (y * xWidth * zDepth) + (z * xWidth) + x;
}


This assumes that the x axis is horizontal (+x to the right)
Y is vertical (+Y going up and away from the origin)
and Z is depth (-Z) shooting out of your chest and into your computer monitor, going away from the origin 'forwards'

jesus christ i would literally kill anyone who use recursion on 9 deep nested for loops

for the purposes of readability, why not? ofc, you might find huge conditional statements OK.

>not rolling your own iterator

that's how you know the code is written by a smelly pajeet

>layers[x][y][z] != 0
>enum
how?

you can't iterate over all your data in less than all your data steps

I don't get it why do you people use a new line just for {

more linezzz

Because when nested code longer than my screen height, bracket in the same line as condition is nightmare to read.

>using recursion in a language with shitty TCO
enjoy your stack overflows

don't you have enclosing brackets highlight in your ide/editor? isn't that enough?

>why do these lines of code have white space in front of them?