• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

22 replies to this topic

### #1warnexus  Prime Members

Posted 13 July 2013 - 09:31 PM

So I am watching this video of Notch coding Minecraft.

His coding style is bizarre to me. I seen other open source game projects that have

straightforward code.

I will type a sample code from the video for clarity.

Timecode for the video for this code is 1:05.

Vec3.newTemp(target.x + target.xd * time, target.y + target.yd*time,target.z + target.zd * time);

He does not have comments in his code so I am not sure how the developers would follow the code.

Source:

Edited by warnexus, 13 July 2013 - 09:32 PM.

### #2Dragonsoulj  Members

Posted 13 July 2013 - 09:34 PM

Looks like a change in new 3D position over based on time. Probably called every update or so.

Vec3: 3 valued vector.

Target.*: Target's current coordinates

Target.*d: Delta change for each value

time: elapsed time since last update

Edited by Dragonsoulj, 13 July 2013 - 09:37 PM.

### #3warnexus  Prime Members

Posted 13 July 2013 - 10:35 PM

Looks like a change in new 3D position over based on time. Probably called every update or so.

Vec3: 3 valued vector.

Target.*: Target's current coordinates

Target.*d: Delta change for each value

time: elapsed time since last update

Thanks DragonSoulj! It makes a lot of sense now!

### #4Nypyren  Members

Posted 13 July 2013 - 10:40 PM

It makes sense that the code he's actively working on doesn't have comments yet. He's adding an experimental feature and the code is changing a lot.

From what I saw of the few frames where the code is in focus, his coding style seems fine to me.

Edited by Nypyren, 13 July 2013 - 10:42 PM.

### #5Dragonsoulj  Members

Posted 13 July 2013 - 11:03 PM

Thanks DragonSoulj! It makes a lot of sense now!

Helps to know X, Y, and Z are 3D planes (X and Y for 2D), and a point in the 3D space needs a value of each. A change of something is a delta, hence the D.

### #6Álvaro  Members

Posted 14 July 2013 - 07:09 AM

Thanks DragonSoulj! It makes a lot of sense now!

Helps to know X, Y, and Z are 3D planes (X and Y for 2D), and a point in the 3D space needs a value of each. A change of something is a delta, hence the D.

The word is "coordinates", not "planes".

### #7MarkS  Members

Posted 14 July 2013 - 07:53 AM

I guess it depends on experience? I looked at that line and it made perfect sense to me. "Vec3" tells me to expect x,y and z coordinates. A "d" in the variable name tells me it is a delta variable. He's constructing a new vector from an old vector, while translating it by delta values scaled by time. Without looking at the video, I would say this is part of a 3D animation system.

Edited by MarkS, 14 July 2013 - 07:53 AM.

### #8swiftcoder  Senior Moderators

Posted 14 July 2013 - 09:30 AM

Of course, it strikes me as a bit of a WTF that his vector class doesn't support vector add and multiply operations.

They would make it a lot easier to read...

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

### #9Pink Horror  Members

Posted 14 July 2013 - 10:25 AM

I guess it depends on experience? I looked at that line and it made perfect sense to me. "Vec3" tells me to expect x,y and z coordinates. A "d" in the variable name tells me it is a delta variable. He's constructing a new vector from an old vector, while translating it by delta values scaled by time. Without looking at the video, I would say this is part of a 3D animation system.

Where is the new vector going? It's not assigning a return value to anything. I wonder, is in unfinished code, or does Minecraft have global / thread local temp variables to avoid allocations?

### #10Dragonsoulj  Members

Posted 14 July 2013 - 11:36 AM

The word is "coordinates", not "planes".

Actually, I believe those are coordinate planes as I am referring to the whole. His .x, .y, and .z are coordinates on those planes.

### #11swiftcoder  Senior Moderators

Posted 14 July 2013 - 11:52 AM

Actually, I believe those are coordinate planes as I am referring to the whole. His .x, .y, and .z are coordinates on those planes.

A 'coordinate plane' is the plane formed by each *pair* of axis.

Individually, the components on a vector are referred to as 'coordinates'.

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

### #12MarkS  Members

Posted 14 July 2013 - 12:19 PM

This post was completely wrong and helped no one. Just not my day today.
[/edit]

Edited by MarkS, 14 July 2013 - 06:41 PM.

### #13swiftcoder  Senior Moderators

Posted 14 July 2013 - 12:42 PM

This is a C++ constructor:

Vec3.newTemp(target.x + target.xd * time, target.y + target.yd*time,target.z + target.zd * time);

It is equivalent to:
Vec3 newTemp;
newTemp.x = target.x + target.xd * time;
newTemp.y = target.y + target.yd * time;
newTemp.z = target.z + target.zd * time;


Except that it is Java, and it isn't equivalent.

warnexus appears to be correct, in that the result is never assigned to a variable.

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

### #14MarkS  Members

Posted 14 July 2013 - 12:53 PM

Except that it is Java, and it isn't equivalent.

Ah. I missed that part (probably should watch the video now, huh?). I'm not familiar with Java, other than it is loosely based on C++.

### #15TheChubu  Members

Posted 14 July 2013 - 01:52 PM

Except that it is Java, and it isn't equivalent.

Ah. I missed that part (probably should watch the video now, huh?). I'm not familiar with Java, other than it is loosely based on C++.

I'd say its more based on plain C while trying to come up with the OO aspect on its own rather than basing it on C++ (hence no :: or -> operator, abstract instead of virtual, interfaces and so on).

At first I thought that it was a Vec3 from LWJGL default types but it isnt. I have no idea what that Vec3.nevTemp does (it looks like "nev" instead of "new" to me).

If it returns a new Vec3, then it isn't getting assigned to anything. And if it doesn't returns a new Vec3, it looks like a global static method that does something on other static stuff. Which kinda looks ugly since if other thread dares to touch the same Vec3 static, bad things could happen.

I guess it depends on experience? I looked at that line and it made perfect sense to me. "Vec3" tells me to expect x,y and z coordinates. A "d" in the variable name tells me it is a delta variable. He's constructing a new vector from an old vector, while translating it by delta values scaled by time. Without looking at the video, I would say this is part of a 3D animation system.

Where is the new vector going? It's not assigning a return value to anything. I wonder, is in unfinished code, or does Minecraft have global / thread local temp variables to avoid allocations?

As far as I know, in Java, if something is static, its static to that class in that applicaton, so no "thread globals" (unless I misunderstood what you're saying).

Edited by TheChubu, 14 July 2013 - 02:01 PM.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

### #16Dragonsoulj  Members

Posted 14 July 2013 - 02:02 PM

A 'coordinate plane' is the plane formed by each *pair* of axis.

Individually, the components on a vector are referred to as 'coordinates'.

Coordinate Planes*. My mistake.

Nevermind...

Edited by Dragonsoulj, 14 July 2013 - 02:03 PM.

### #17warnexus  Prime Members

Posted 14 July 2013 - 05:51 PM

I guess it depends on experience? I looked at that line and it made perfect sense to me. "Vec3" tells me to expect x,y and z coordinates. A "d" in the variable name tells me it is a delta variable. He's constructing a new vector from an old vector, while translating it by delta values scaled by time. Without looking at the video, I would say this is part of a 3D animation system.

Yeah it would depend on experience. I'm still a CS undergraduate in my senior year. Never been exposed to the production environment.

### #18warnexus  Prime Members

Posted 14 July 2013 - 05:56 PM

This is a C++ constructor:

But he is coding in Java not C++.

Based on coding convention, newTemp looks more like a static method with 3 parameters of his Vec3 class.

Right?

### #19MarkS  Members

Posted 14 July 2013 - 05:58 PM

Yeah, ignore me today. I don't know why, but I'm not at my best today. I was off am nearly every count.

### #20Pink Horror  Members

Posted 14 July 2013 - 06:56 PM

As far as I know, in Java, if something is static, its static to that class in that applicaton, so no "thread globals" (unless I misunderstood what you're saying).

This what I meant by thread local (not to imply I have any idea how Vec3.newTemp is really implemented):

public class Vec3 {

public Vec3() {
x = y = z = 0.0f;
}

private float x, y, z;

@Override protected Vec3 initialValue() {
return new Vec3();
}
};

public static void newTemp(float x, float y, float z)
{
Vec3 v = temp.get();
v.x = x;
v.y = y;
v.z = z;
}
}



Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.