Blog about (Web-) Programming, Graphics and Games.

22.05.2010

Java Physics Demo: Boxes

This demo uses parts of the the JBullet and the Vecmath library. I extracted essential classes and put them all into 1 java source file. Thus this demo dont needs external libraries.

On Objectstacks
I also changed the used JBullet parts, so that they dont use Objectstacks. Objectstacks were introduced to manage temporary objects in a threadsafe way. There are 3 possibilities to deal with temporary objects:
  • 1) Just instantiate a temporary object as you need it. Problem: this can result in a lot instantiated objects, garbage collector has alot todo, runtime performance might drop. Though, intelligent jit-compilers could possibly handle multiply temporary instantiations and could in a way inline them..
  • 2) Add (private) auxiliary objectvariables to the class. You can use this objects in computation and dont need to instantiate new ones. Problem: if different threads invoke the same method at the same time, an object could be used twice, with unexpected results. This approach is not thread-safe.
  • 3) Use objectstacks. Retrieve auxiliary objects from a pool and return them to the pool, when computation is over. This way in most cases only limited number of instantitions is needed (opposed to possibly unlimited instantiations in approach 1) and this method is threadsafe (opposed to approach 2).
The original JBullet library uses objectstacks. In this demo I omitted them, because the original approach requires an instrumentation step in the build process. During this step auxiliary classes are generated using an ant-build-file. A simple compile doesnt work. For sake of simplicity I thus dont use objectstacks here, but above second technique. Thus this demo is not thread-safe, but its usecase is only single threaded, so it doesnt matter.

How to build
  • Make sure, that a JDK is installed.
  • Put the source file into a directory 'net/plsw/bullet'.
  • Compile it with 'javac net/plsw/bullet/BoxDemo.java'.
  • Run it with 'java net.plsw.bullet.BoxDemo'.

10.05.2010

Canvas Game Demo: 4Rumble

As a small project besides a more complex 3d-project (soon more infos here) i wrote this game demo for canvas and javascript. Its a remake of a flash game demo, named 4Rumble (click, click), i made a while back. In this Javascript demo there is currently only one character, Cursor-Left/Right make him run around. Cursor-Up/Down zooms in and out. A formerly flash demo ported to javascript, might be seen as statement in the current html5-instead-of-flash debate. Which leads to:

Others stuff ramblings
My opinion about the Apple/Html5 vs. Flash debate (click, click): I dont have much to do with apple and i dont have much todo with flash. So im not directly affected. Obviously, Html5 is more open and accessible, than flash, so I love to see it gain ground. On the other side I strongly dislike vendor-lockin on Iphone (and elsewhere, e.g. linux-ban on ps3). It kills creativity, the user should have the choice between different technologies. If native apps are better than those (compiled) with intermediate code, they will supersede naturally other apps. There is no need for prohibition. If apple would allow flash (or more importantly imo: java) on its devices, I maybe also wanted to have one. :)
And now for sth. completely different: Google makes O3d a WebGl-Javascript-library, the plugin-development is stopped. This is imo a good step since with WebGl there wont be a need for a browser-3D-plugin. Though, WebGl doesnt currently run everywhere (i.e. on i.e.), but according to google the plugin will still be available for at least a year.

31.03.2010

Work in progress: Twaja, Doom3 experiments

Experimenting with trees and fog and the doom3 engine. The aim is to create a spooky single player level. The created content might be reused for other projects.
A second work in progress is Twaja, the Java Twitter Client. I updated the layout and introduced the top control area. Friend feed clustering is improved, so that successive tweets from the same source are displayed together. Thus the profile icon is only displayed once, and messages are shown more compact. More updates on these projects soon!

Btw, congratulations @cern for the first 7TeV collisions and the beginning of the experiments. Now I must read more on particle physics to understand upcoming, hopefully interesting, results. There are nice live data animation websites on the current lhc-status: click, click.

17.03.2010

Does bytecode become obsolete?

Or, more provocative: Will Javascript substitute Java? Java has a certain technical infrastructure, it utilizes bytecode. This exists for following reasons: In the history of programming languages at first there where interpreted languages, e.g. Lisp or Basic. They where slow but portable. Then there came languages like c and c++, where source is compiled to systemspecifc binary. They were fast, but unportable. With Java and bytecode a quite fast AND portable solution emerged. Java source is compiled to system-independent bytecode, which then is executed by the java virtual machine. With later versions of Java, to increase execution speed, just-in-time (jit) compilers were introduced. They compile the bytecode on the fly to systemspecific binary, which than runs faster. Besides the ecosystems of compiled languages, interpreted languages persisted. Script languages like Javascript are there to e.g. control compiled programms or bytecode.

Recently jit-compilers for javascript appeared (Google V8, Mozilla Tracemonkey). Thus Javascript becomes fast and portable, like java, but without bytecode. Bytecode now seems to be an unnessary intermediate step during programm execution. Bytecode means more complexity in IDEs and in language execution. If a jit-compiler works with sourcecode directly, not with bytecode, possibly more optimizations can be done (without the additional abstraction step bytecode). If you get the same results with a less complex solution, you should apply it. With faster script languages, also there will be no need to separate programm logic into scripts and compiled functions. One advantage of bytecode might be that you can have different programming language compiled to it and than be executed on the same virtual machine. Like with JRuby, Jython, Scala than run on the java virtual machine. If you ommit bytecode and want to have the same flexibilty, the execution engine (with the jit-compiler), must be able to read different types of languages. Future will show if that is feasible.

Aside from the technical aspect, lets look at usage fields of Java and Javascript. At first Java was meant to be for the desktop. This didnt fully work out, e.g. Java applets in general couldnt compete with alternative approaches like flash. Java though became very strong on the server. Javascript was also originally there for the desktop, with its improving performance and the new <canvas> html-tag it can increasingly compete with flash and java applets. As of lateley Javascript spread also to the server (e.g. node.js). Thus, also from this point of view, it seems, that Javascript pushes into Java territory.

Two final notes: First, you may replace the term 'java' with 'c#/.net' (or other bytecode/intermediate language platforms) in this text. Second, this considerations only apply to the far future, currently java cannot be replaced by javascript, because of its superior stability, performance, distribution and api. Also, different languages/platforms will stay (in niches). In my perception java/c# (also called managed code) superseded c++ (unmanaged code), yet c++ still exists. In a comparable manner Javascript will displace Java/C#, but all will stay (for now).

11.03.2010

Towards a Web-RTS-Game

Here is a demo for a real-time-strategy (RTS) game using WebGL. Currently there is only very basic gameplay: you can select units using left mouse button and let them move around with the right mouse button. Following is planned for future releases:
  • Map and gameplay enhancements. Add strategy to the real-time
  • Use of other html5 techniques, e.g. audio-tag for audio, websockets for multiplayer gameplay
  • Custom content creation and modification. Users will be able to upload own units and maps to a central repository. Also AI of units might be controlled by editable user-scripts...

27.02.2010

Back from Cebu, Html5 game Sungka

I'm back from vacation. It was a very nice trip, here are three recommendations: Alta Cebu Resort - very nice place with internet and pool, Qatar Airways - tasty food, free beer and whiskey , Warped Passages - interesting book on particle physics, maybe a good read to understand coming LHC-experiments.

Working on new content: Games for Html5 (Canvas and/or WebGL). A first start is a implementation of the game Sungka using Javascript and Canvas (overall size 3.5kB). You can play it directly in the right field above. Currently it wont run on IE, only with e.g. firefox and chrome.

10.02.2010

Html5-Canvas with variable size

I tried to make a Html-page with a Canvas-element, which fills the whole page or browser window. Following line
<canvas width="100%" height="100%">
didnt work. It produced a canvas with a dimension of 100x100 pixels. Following
<canvas style="width:100%;height:100%" width="100%" height="100%">
worked a bit better: the canvas filled the browser window. Though the canvas still had a size of 100x100 pixels, but it was scaled up to fit the page. To have a canvas that dynamically changes its size according to the browser window, I had to set canvas.width and .height manually, like in this code snippet:
var cont=canvas.parentNode;
if ((canvas.width!=cont.clientWidth)||(canvas.height!=cont.clientHeight)) {
canvas.width=cont.clientWidth;
canvas.height=cont.clientHeight;}
Note: by setting e.g. canvas.width the canvas will be cleared, so the resize must take place before the repaint.

Update: If the canvas is used with WebGL, the gl-viewport must be set to the new size.
gl.viewport(0,0,canvas.width,canvas.height);