Posts Tagged ‘JavaScript’

Wii Opera SDK Raycasting Class Updated

Wednesday, June 25th, 2008

The following features have been added to the Raycasting class:

  • Left and right strafing
  • Ducking
  • Variable camera altitude
  • Teleporting
  • Background images for sky and ground

With these added features, the possibility exists to create games in the genres of on-rails shooter and 3D sidescroller.

Wii Opera SDK 3.0 on the Horizon

Tuesday, June 24th, 2008

Much of the Wii Opera SDK is being overhauled or rewritten from scratch for the upcoming version 3.0 release.  Unfortunately, some of the new features have to wait until the Opera 9.5 build of the Internet Channel becomes available for the Wii.  The new Wii Remote class is available now, as is the Raycasting class, in the preview release.  The new Drawing class makes use of the Canvas::transform function, which is available in Opera 9.5 but not the 9.27 build of the Internet Channel.  You can see it in action on a computer, but the demo does not work on the Wii yet.  Also coming with the 3.0 release will be a dungeon editor for the raycaster so that developers can create their own games.  The raycaster is versatile enough that it can even be used to create on-rails flight sims and 3D side scrollers.

Wii Opera SDK: New Wii Remote Class

Tuesday, June 24th, 2008

A new Wii Remote class for the Wii Opera SDK has just been released, superceding the previously existing one.  A demonstration can be found at http://wiioperasdk.com/remote.html.

This new class contains the following features:

  • Read button presses from all 4 Wii Remotes
  • Read distance from Sensor Bar of all 4 Wii Remotes
  • Read cursor position of all 4 Wii Remotes
  • Read angle of roll for all 4 Wii Remotes
  • Read button presses from 3 Nunchuks
  • Read button presses from a keyboard acting as a Wii Remote
  • Autodetect active keyboard or Wii Remote NEW!
  • Autoswap between remote and controller orientation based on Wii Remote direction NEW!
  • Autorotate D-pad orientation based on Wii Remote orientation NEW!
  • Read additional keypresses when using BOTH a Wii Remote and a USB keyboard NEW!
  • Toggle disabling of default key/button actions NEW!

Wii Opera SDK Texture-Mapping Greatly Accelerated

Tuesday, May 27th, 2008

I’ve made modifications to the triangle texture mapping functionality of the Wii Opera SDK, incorporating the rotation and scaling calculations by Tangent128 for his 3D globe widget at MyOpera. This eliminated the need for scanline-based rendering and replaced it with single-pass rendering. As one can imagine, this greatly increased the speed of the triangle filling.  Based on trials I’ve done, the speed increase is probably about 20 fold, but it really depends on how big the average triangle is for each mesh. Basically, the boost probably comes down pretty close to scaling linearly with the number of scalines that would’ve been in the triangle with the old rendering method. A demo of the Super Smash Bros. logo is at http://wiioperasdk.com/texturemap.html and a ripple puddle is at http://wiioperasdk.com/ripple3.html.

(more…)

Javascript Optimization for Games on the Nintendo Wii

Saturday, May 3rd, 2008

Did you know that games with advanced graphics and controls are possible on the Wii’s Internet Channel (Opera 9.x) using nothing but HTML and efficiently-coded Javascript? I’m not talking about Pong, either. I’m referring to games with graphics that rival those of Starfox for the SuperNES or the original Wolfenstein 3D for the PC. This article focuses on thinking in the mindset of optimizing your Javascript code as much as possible for both speed and memory in areas specific to the Wii. Articles already exist on the Wii Remote and the canvas object, so I will not spent a great deal of time on the specifics of those but will dive right into the meat of the topic.

Integer Math

Whenever time-critical calculations must be made, it is a good idea to work in integer-only math. (Plus, pixels are integer coordinates, anyways.) Since javascript variables are all of one type, there is no specific integer variable, so tricks must be employed to pull the extra speed boost from integer calculations over floating-point ones. There are a few ways to do this:

 scale = Math.floor((x2-x1)/img.width);
scale = ((x2-x1)/img.width)>>0;
scale = ((x2-x1)/img.width)|0;

For calculations of our needs, always avoid the first example. Javascript’s built-in Math class is very slow compared to bit shifts or bit comparisons. If all values are integers already, then conversions are only needed on divides. For rounding numbers, add half of the denominator to the numerator before dividing. The second example leads us into bit shifting over division and multiplications. Divides (and to a lesser extant: multiplies) can be processor-intensive when used repeatedly, so always use bit-shifts when an integer is going to be multiplied or divided by a power of two, like so:

 centerx = (x1+x2)/2; centerx = (x1+x2)>>1;  

(more…)