August 28, 2009 by Knut Erik
I’m experimenting with network programming in Java, and writing a server/client application. The basic socket handling in Java is pretty simple. Just create a ServerSocket and instruct it to listen. It will return a Socket object whenever it receives an incoming connection.
try{
Socket socket = new ServerSocket(10000);
} catch (IOException ioe) {
throw new IOException("Could not open server socket 10000", ioe);
}
On the client it’s even easier.
try {
Socket socket = new Socket("127.0.0.1", 10000);
} catch (IOException ioe) {
throw new IOException("Could not open connection to 127.0.0.1", ioe);
}
This will open a socket using port 10000 on the server and client side. However, a server written like this can only handle one client. This is fine for many applications, but I wanted to create a server capable of handling several clients at the same time. Therefore I created a class in the server project that represents the clients. A new instance of these will be created for each client that connects to the server.
private LinkedList<Client> clients = new LinkedList<Client>();
...
private void HandleNewClient(Socket newSocket) {
clients.addLast(new Client(newSocket)); //Add a new client to the list
}
Each instance of the Client class spawns a thread listening for messages from the client program, and handles them by itself.
Tags: Java, programming
Posted in Network programming | Leave a Comment »
June 26, 2009 by Knut Erik
I have implemented a random terrain generator, and after some tweaking it, it produces pretty good results.

Randomly generated terrain
I can seed the generator as I wish, and get the same result every time, or use some other value like the system time to get a new terrain every time.

Another view

Another view of the terrain
Also, the artifacts from the previous post have been eliminated.:) The light is working as I want it now.

Light model working
The lighting is nice, but it doesn’t do shadows. At least not yet. That will be the next focus for me.
-Knut
Tags: c++, graphics, OpenGL, programming, Terrain
Posted in Terrain engine | Leave a Comment »
June 20, 2009 by Knut Erik
I’ve changed the way the program calculates the light level on the textures, so it should be more realistic. The sun’s position is configurable, and is used to shade one side of a hill, while the other one will be bright.

Better light model
The sun would on the left side of this picture, you can see a small valley in the middle with a hill behind it. Notice the difference in light levels between the right and left sides of the valley and hill. This is actually looking very nice.

From above
Same valley, seen from above. The walls are about the same steepness. However, there are a few problems and limitations. Firstly, the sun’s position can only be specified in the east-west range. This is not much of a problem, and is easily corrected if necessary. Secondly, there are no shadows yet, but I plan to add support for this. And thirdly, there are these artifacts here on the textures:

Artifacts on the terrain
See those lines there. They are everywhere. Actually, they appeared when I implemented the texture splatting as well, but then I managed to work around them, for the most part. But now, I have a plan to get rid of them. The problem is, the height map has integer values. So on many slopes the steepness map will be like a stair instead of a smooth slope. To counter this, I think I need to create a random terrain generator.
I’ve been searching around a bit, and I want too implement a fractal generator for the terrain, preferably in a way that allow me to feed it a number to generate a terrain from(seed), or use an random one. Hopefully this will get me smooth slopes as well as interesting terrain, and i hope to complete this as soon as possible.
-Knut
Tags: c++, graphics, OpenGL, programming, Terrain, texture
Posted in Terrain engine | Leave a Comment »