Mittwoch, 14. März 2012

Windows: Shutdown via command line

You can shutdown a computer running Windows using the command line. Use the shutdown command to force a shutdown, reboot or hibernate.

Shutdown computer
shutdown /s

Restart computer
shutdown /r

Hibernate computer
shutdown /h

The shutdown command is available since Windows XP. On older versions of Windows use this command:

Restarting the computer
RUNDLL.EXE user.exe,exitwindowsexec

Shut down the computer
RUNDLL32.EXE user,exitwindows

Freitag, 2. März 2012

Java: Creating an undecorated window with LWJGL

This system property removes the window decorations (title bar, icons, border) from LWJGL applications in window mode.

org.lwjgl.opengl.Window.undecorated=<true|false>

You can specify the property on the command line, when you start the application

java -Dorg.lwjgl.opengl.Window.undecorated=true -jar application.jar

or in your code by setting it manually.

System.setProperty(" org.lwjgl.opengl.Window.undecorated", "true");

See the LWJGL wiki for more hidden property switches.

Donnerstag, 23. Februar 2012

C++: string tokenzier

This function splits a string into substrings. It uses a list of delimiter characters to find the boundaries of the substrings.

void tokenize(const std::string &str, 
              std::vector<std::string> &tokens, 
              const std::string &delimiters = " ") {
  string::size_type lastPos = str.find_first_not_of(delimiters, 0);
  string::size_type pos = str.find_first_of(delimiters, lastPos);

  while (std::string::npos != pos || std::string::npos != lastPos) {
    tokens.push_back(str.substr(lastPos, pos - lastPos));
    lastPos = str.find_first_not_of(delimiters, pos);
    pos = str.find_first_of(delimiters, lastPos);
  }
}

Usage:
vector<std::string> tokens;
tokenize("I want to tokenize this!", tokens);

tokenize("2012-02-20", tokens, "-");

Mittwoch, 22. Februar 2012

Tools: Installing WebDAV support in TotalCommander 64 bit

After I switched to the 64 bit beta version of Total Commander, I noticed that I could no longer connect to my WebDAV server. The problem was the WebDAV plugin for Total Commander. It was a 32 bit version and could not be loaded into the 64 bit Commander.
The plugins page still has the 32 bit plugin for download. I think this is ok, because the 64 bit version of Total Commander is still in beta. A 64 bit plugin has already been written. You have to go to the forums and dig around a little bit to find the link.
After installling the beta plugin everything worked fine again.

Download WebDAV 64 bit plugin for Total Commander

Sonntag, 12. Februar 2012

Java Slick game development - 64 bit problems

When setting up my project and writing the simple basic application Slick crashed on me with an error:

java.lang.UnsatisfiedLinkError: Drones\lib\lwjgl.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform

I'm running Windows 7 on a 64 bit system and I have the 64 bit Java VM installed. You will not see this error if you are running the 32 bit version of Java on your 64 bit system.

To solve this problem I had to download the current version of LWJGL from their site and copy the windows DLLs and the lwjgl.jar that is included in the download into my project lib directory. This will replace the lwjgl.jar that came with the Slick distribution.

So now my project looks like this in the project explorer:

Samstag, 11. Februar 2012

Java: Slick game development - Part #2 The first program

After setting up the project in my last post, we now create a very simple sample application that we will extent in the future.

The following code creates a new Slick game. It is not much yet - just a black window. But this window is already an OpenGL frame.

package codebrocken.drones;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

public class Drones extends BasicGame {

 public Drones(String title) {
  super(title);
 }

 @Override
 public void render(GameContainer arg0, Graphics arg1) throws SlickException {
  // TODO Auto-generated method stub

 }

 @Override
 public void init(GameContainer arg0) throws SlickException {
  // TODO Auto-generated method stub

 }

 @Override
 public void update(GameContainer arg0, int arg1) throws SlickException {
  // TODO Auto-generated method stub

 }

 public static void main(String[] args) {
  try {
   AppGameContainer appContainer = new AppGameContainer(new Drones("Drones"));
   appContainer.start();
  } catch (SlickException e) {
   e.printStackTrace();
  }
 }
}

The class itself is derived from BasicGame, which does a lot of work for us. We just have to implement a few methods that will do our actual work later. The main method creates a new AppGameContainer and initializes it with our game.

Freitag, 10. Februar 2012

Java: Slick game development - Part #1 Setting up Eclipse

Slick is a 2D game library for Java. It uses OpenGL for rendering. It also contains a lot of utility functions. I want to do a little bit of game programming so instead of writing my own engine (as I would do normally), this time I'm testing Slick.

Step #1: Download Slick libraries

You can get the Slick libraries here. Just download the complete package. It includes the LWJGL libraries that provide the OpenGL layer.

Step #2: Create a new Eclipse project

Create a new Java project in Eclipse and amed it Drones.Nothing fancy at this point.


Step #3: Import the libraries

I created a new lib folder, that will contain all my libraries. I copied the slick.jar and lwjgl.jar from the Slick archive into that folder. To add them to the build you have to open the properties of the project and select "Build Path". Then click "Add JARs..." and select the two JAR archives from the lib folder.


Step #4: Import the native libraries

The LWJGL library needs a native runtime library. On windows systems this is the lwjgl.dll you can find in the root folder of the Slick archive. I copied the DLL into the lib folder too. You can choose a "native" subfolder as you like.
You now have to open the "Referenced Libraries" branch in the package explorer and right click the lwjgl.jar to open its properties. In the properties dialog select "Native Library". Here you can select the "Location path" where Eclipse will look for native libraries, when it starts the application. Just select our lib directory here.
Under the hood this step sets the java.library.path property to point to the lib directory. This property defines where Java searches for native libraries.


Now you are done with setting up Eclipse. You should have a structure that looks something like this: