Mucking About with Voxel.js

voxel_forest

Installing Voxel.js

I just discovered voxel.js, which is a web-based voxel engine that can be used to build block-based games like Minecraft. It’s written in node.js, so lets get that set up. Voxel.js requires node.js 0.8.0 or better, and Ubuntu’s repositories supply 0.6.19, so we need to set up a PPA to get the latest version.

Under Ubuntu 12.10 the node.js executable is name ‘nodejs’, I believe its ‘node’ on some other systems.

Grab the voxel hello world repo from github:

Now you should be able to check out voxel at localhost:8080. You will have be inside a crater with a couple of minecrafty types in front of you. They would be Maxogden and Substack, the voxel.js devs.

“npm install” downloads all the dependencies for voxel-hello-world. ‘npm start’ makes npm run a node js webserver, and rebuild index.js on each request using browservefy.

Note: I can only get this working in Firefox – according to Google Chrome doesn’t support WebGL with my laptop’s Nvidia FX Go5200 🙁

Switch to Perlin Noise Terrain Generation

Instead of using the predefined ‘Valley’ terrain, we can switch out to a module, such as the Perlin Noise Terrain Generator.

Add the following at the top of index.js as below:

Then update createGame:

You can muck around with the value of scaleFactor to make mountains, hills or relatively flat terrain.

Plant Some Trees

In order to generate some trees we need to include voxel-forest then add a few lines of code..

From here..

That’s probably enough for one post but jeez there’s a lot more here to play with so watch out for a followup.

Dependency Injection and Drupal 8

Drupal is changing a lot in 8.x, and one of those major changes is adding the Drupal Dependency Container. What is that exactly?

Explain Yourself

  • Dependency injection is a design pattern used to dynamically load service objects, such as a mail delivery service.
  • Normally an object decides what service classes it will use – it will instantiate an object of a given class, then use it. In dependency injection the object will call the injection container which will provide it suitable classes depending on runtime configuration.
  • Sometimes called ‘Inversion of control’
  • The injector is often called a container.

Why all the fuss?

  • Allows selection from multiple potential interfaces at runtime
  • Creates highly pluggable systems – easily switch out caching backends for example.
  • Great for testing – no need to bootstrap or live connections to external services, just give the subsystem a stub implementation. Components can be tested in isolation.

How does it work?

  • Specify the interface for the dependency
  • Let the container object select the implementation

Types of Injection

  • Constructor injection – most common, pass in service object via constructor.
  • Setter injection – good for optional dependencies
  • Property injection – set public attributes directly.

Drupal’s DIC Implementation

One of the first things drupal_handle_request() does is instantiate an object of class DrupalKernel, which is extended from Symfony’s HttpKernel class Kernel.

Getting a service from the container:

To create a new service we implement the Bundle class:

You can see the core implementation of this in lib/Drupal/Core/CoreBundle.php. Some of the services registered include:

  • Configuration system
  • Database connection
  • Queue system
  • Path alias manager
  • Entity manager
  • HTTP Kernel
  • Language manager
  • Twig

Thats a pretty basic overview of Dependency Injection and how it is implemented in Drupal. Lots more information can be found in the links below.

References

BumbleBee drivers on Ubuntu 12.10

My ASUS laptop has 2 graphics cards, one Nvidia and the other Intel. Ubuntu uses the Intel one by default, but that leads to poor performance for gaming. So I need to install the Bumblebee drivers.

  1. sudo add-apt-repository ppa:bumblebee/stable
  2. sudo add-apt-repository ppa:ubuntu-x-swat/x-updates
  3. sudo apt-get update
  4. sudo apt-get install linux-headers-generic
  5. sudo apt-get install bumblebee bumblebee-nvidia bbswitch-dkms
  6. Reboot or re-login

Swat PPA has the latest Nvidia drivers.

Except that I log back in and ‘optirun glxspheres’ returns:

Luckily this can be fixed by editing /etc/bumblebee/bumblebee.conf. Look for the line that says ‘Driver=’ and add ‘nvidia’ at the end. Then reboot, and test with ‘optirun glxspheres’. The graphics card light should switch from blue to white, and the output should look something like the following:

The fix comes from here.

If its still not working try reinstalling using the advice at http://www.ivegotavirus.com/how-to-fix-bumblebee-on-ubuntu-12-10/

Hopefully this is a bit cleaner in 13.04.

 

Features Information Architecture for Drupal 7 Site Builders

Features is a great module that lets Drupal developers export configuration normally stored in the database out to PHP code, which can then be committed to version control and deployed. It’s pretty much a required module these days, but what is the best way to use it when building a site? When should a developer create a new feature for their site? This post outlines a two approaches to Features information architecture.

Continue reading Features Information Architecture for Drupal 7 Site Builders

Clean URLs for WordPress

Clean URLs are great for getting up in the search results, and they give more meaningful links for users too.

Here’s how to set them up in WordPress 3.5.

1. Settings->Permalinks

2. Choose ‘post name’.

3. Update .htaccess using the code at the bottom of the page. WordPress can do that automatically if it has permission to write to .htaccess.

More documentation here if you want to use custom clean URLs.