• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nicholas Kong

How to read/adapt coding style that look like this

22 posts in this topic

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:

 

http://www.youtube.com/watch?v=BES9EKK4Aw4

Edited by warnexus
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites


Thanks DragonSoulj! It makes a lot of sense now!

 

wink.png  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.

0

Share this post


Link to post
Share on other sites

Thanks DragonSoulj! It makes a lot of sense now!

 
wink.png  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".
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites

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...

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites


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.

0

Share this post


Link to post
Share on other sites


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'.

0

Share this post


Link to post
Share on other sites
[edit]
This post was completely wrong and helped no one. Just not my day today.
[/edit] Edited by MarkS
-1

Share this post


Link to post
Share on other sites

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.
1

Share this post


Link to post
Share on other sites

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++.
0

Share this post


Link to post
Share on other sites

 

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites


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?

0

Share this post


Link to post
Share on other sites
Yeah, ignore me today. I don't know why, but I'm not at my best today. I was off am nearly every count.
0

Share this post


Link to post
Share on other sites

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;
 
private static final ThreadLocal<Vec3> temp = new ThreadLocal<Vec3>() {
    @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;
}
}
 
0

Share this post


Link to post
Share on other sites

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

your initial post was good. I appreciate everyone's feedback!

0

Share this post


Link to post
Share on other sites


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.

 

It's common practice among Java game developers to keep an internal temporary vector in some classes to avoid newing them all over the place. Given the number of them often needed in a single frame, it can put a bit too much pressure on the GC in some cases. I've seen different approaches to how they're implemented. Most commonly its as a normal class member in the class that needs it. I assume that Marcus has implemented one in this case as a static member of his Vec3 class. Of course it isn't thread-safe, but I seriously doubt that's an issue in for him. Static members and methods that mutate state are common in Java, so any Java programmer worth his salt knows when to use them and when not to. If he needed multi-threaded access, he would have chosen a different approach.

0

Share this post


Link to post
Share on other sites

 

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;
 
private static final ThreadLocal<Vec3> temp = new ThreadLocal<Vec3>() {
    @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;
}
}
 

 

I never knew such thing existed (its no surprise since I never delved beyond the "extend Thread or implement Runnable" in Java). Looking at the Javadocs, it looks like a pretty nice feature.

 

 

It's common practice among Java game developers to keep an internal temporary vector in some classes to avoid newing them all over the place. Given the number of them often needed in a single frame, it can put a bit too much pressure on the GC in some cases. I've seen different approaches to how they're implemented. Most commonly its as a normal class member in the class that needs it. I assume that Marcus has implemented one in this case as a static member of his Vec3 class. Of course it isn't thread-safe, but I seriously doubt that's an issue in for him. Static members and methods that mutate state are common in Java, so any Java programmer worth his salt knows when to use them and when not to. If he needed multi-threaded access, he would have chosen a different approach.

I know, probably the most used static around is a Random instance. But it sounds weird to place it directly on the Vec3 class instead of, as you said, the class that needs it.

 

I mentioned threading because from what i've read around, in voxel engines its pretty common to do multi threaded stuff (ie, generating chunks in a secondary thread), I have no idea if Minecraft follows such practices though.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0