Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualepicpunnum

Posted 09 February 2013 - 10:58 PM

Feel free to correct me if I'm wrong (still learning C++, having learned Java, and some C#), but I believe this is what it is...

In C-based languages, void is simply nothingness, as I'm sure you know. Commonly (thought not seen in Java much - at least I don't to use it) void is an unnecessary parameter in functions if used as above. This is merely just a matter of taste from what I know.
Therefore, this:

void run (void){
  //Filler code
}

should compile the same as this:

void run (){
  //Filler code
}

 

Really the only thing that the extra void does is fill in the parameter parenthesis, and make it a bit clearer to the programmer that the function has no intent to take arguments. However, depending on your level of comments & documentation, it may be completely unnecessary. tldr: Don't worry about it.

There may be some subtleties between them, but nothing very significant.


EDIT: Looking at your loop, I'd recommend doing what slicer4ever suggested. That could very likely be the root of your problem. Granted I can't see all of your custom methods (eg: your update() and all that jazz), but looking at it, it doesn't seem like you're doing all too much with your milliseconds variable, rather than using it in one method. Instead of invoking Thread.sleep(), you might be better enclosing your drawing code within an if statement that checks the time.
To give you an idea, take this basic structure:

public void run(){
  //basic game loop
  while (isRunning){
    //calculate time since last loop
    long milliseconds = System.currentTimeMillis() - lastTick;
    
    //This would be the change here
    //replace (1000/framesPersecond) if you prefer ticks in ms
    if (framesPerSecond> 0 && milliseconds > (1000/framesPerSecond)){
      //GAME LOGIC & DRAWING

      lastTick = System.currentTimeMillis(); //moved into the if statement
    }
  }
}

I believe that a structure more like this would save yourself the time of your interpreter having to call a method outside of your class. It also should be a bit more accurate and constant for your game, as the sleep() and wait() methods can be a bit off at times, or have occasionally failed.
An article here could explain the inaccuracy a bit more than I could.


#1epicpunnum

Posted 09 February 2013 - 10:31 PM

Feel free to correct me if I'm wrong (still learning C++, having learned Java, and some C#), but I believe this is what it is...

In C-based languages, void is simply nothingness, as I'm sure you know. Commonly (thought not seen in Java much - at least I don't to use it) void is an unnecessary parameter in functions if used as above. This is merely just a matter of taste from what I know.
Therefore, this:

void run (void){
  //Filler code
}

should compile the same as this:

void run (){
  //Filler code
}

 

Really the only thing that the extra void does is fill in the parameter parenthesis, and make it a bit clearer to the programmer that the function has no intent to take arguments. However, depending on your level of comments & documentation, it may be completely unnecessary. tldr: Don't worry about it.

There may be some subtleties between them, but nothing very significant.


PARTNERS