-
whats the easiest way to make a structure in java, i.e. for making a 3 component floating point vector for a maths library
-
can you overload operators to make a 3d maths library?
-
is there some kind of function pointer like there is in c? (in java it would be more like a class reference) cause they are handy for mode switching
1.) Class (or Enum should be possible in Java 1.5+)
2.) No operator overloading available in Java, use function-calls like add, sub, cross and so on and return self for chaining
3.) In Java you have no Pointer, all Object-Parameters are submitted “by ref”
Yep, I got that, class, or enum.
But how the hell do you swap from intro screen to game play mode without a function pointer?!?!?!?
You can overload methods. References are equiv to pointers.
One possibility would be to have a base class to handle drawing and the game logic, then derive new classes for intro screen and game play. You have a reference to the current active “game screen” object and call the drawing and logic methods on that in your game loop. When the state changes, you just change the active “game screen”.
Roquen- references are equiv to class pointers?
I know I can go write a switch statement and contain all possible modes with different variables, but im talking about having one variable that can swap between classes.
Wildern- So I make the intro and the game screen come out of the same class? nah… Isnt that virtual functions in c++? god im confused.
From a C-like point-of-view:
an object reference is a pointer to a data chunk which contains the object’s (well) data. This data contains a hidden pointer to its defining class. Which in turn has a method table.
So you can have two classes which are derived from a common base class which each implement different desire behavior:
public abstract class ActiveMode
{
public abstract ActiveMode exec();
}
public class TitleScreen extends ActiveMode
{
@Override
public ActiveMode exec()
{
// Do some stuff, if we're changing to a new mode, then return a reference to the handler of that mode.
// Still in the title screen.
return this;
}
}
Is one of many possible examples.
extends! so I inherit both screens out of the same class, i dig. thanks.
You know itll probably make my code neater not using c for a change. 
I still swear if I had basic with “goto x” id have the most powerful spaghetti of all time.