eirikhm

A few days ago I saw that Unreal Tournament 3 was added to Steam, and that they also offered some new downloadable content. I decided to give it a spin, and activated my copy of UT3 in Steam. I had to download the whole 8gb game to play it, but on a 20mbps line that’s wasn’t a problem. When I came back from work today I decided to give it a spin. To my amazement it crashed on startup, only giving me “UT3.exe has stopped working”. I figured it was the ATI drivers, so I went over and grabbed the latest and greatest Catalyst package. Upon starting the installation that failed as well. I tried in safe mode, tried uninstalling (which failed) and googled my eyes out. After a while I found this post from SuperWasp which explains how to run the ATI driver installer from command line. Basically, go to C:ATISupportXX-driver-versionDriverBin64 and run the command “atisetup.exe -Install -Output screen“. I did it from the Driver folder, where the Setup.exe is located by calling “setup.exe -Install -Output screen” which also worked fine. The process took a few minutes, but once I rebooted the driver was updated.

PS: Windows was stuck in “Windows is now rebooting” until I unplugged my iPhone :)

Now, this shows how to update the driver, but it does not explain the problem with both Unreal Tournament 3 and the driver setup software failing. I’ve looked around a bit, and based on what I’ve read it seems like the .NET Framework 2.0 files might have been damaged in some way. I tried running the “sfc /scannow” command (some info on that tool here) to let Windows search for corrupt or damaged system files, but no luck. Since .NET Framework 2.0 is an integrated part of Windows Vista I’m basically unable to uninstall it as well. If anyone has any suggestions on how to fix this I’d be really glad to hear from you.

Lars Olav Torvik has just posted a neat weather widget for Vista, using the norwegian weather service yr.no. Give it a spin!

Related posts:

Handy online regex tool for PHP, Perl, JS and Python

[tags]Windows Vista, Widget[/tags]

As I mentioned in this previous post I’ve started to play around with C# and XNA Game Studio, and it’s very entertaining. I started out using The Platformer Starter Kit , which is a basic platformer game that you can customize and base your game on. I followed the tutorials mentioned in the previous link, and everything just works pretty smooth. Very satisfying to see immediate results reflected in a working game. After finishing them I decided to add a new feature by myself, a falling apple which would kill the player (I’ve been playing I Wanna Be The Guy lately). Hence, this post: XNA Platformer Starter Kit – Falling Apples. Now, this is a very basic feature. I just based my Apple on a copy of the Gem class, and did some minor modifications to allow them to fall down once the player walks under them, and if the player is hit he’ll die. A picture to show the final result:

Falling Apples

Falling Apples

Please bear in mind that this post is just a note of the changes I did to make this work, and should not be considered a full tutorial. I might end up doing more proper posts on XNA as I progress in my work with it.

So, here it goes!

First, create a new C# class. Just copy all the contents from the Gem class, and rename Gem to Apple (and gems to apples). Also, add the following line to the Apple constructor so that we can see the difference between apples and gems: Color = Color.Red;

Now, remove the following lines, since we do not need them:

private SoundEffect collectedSound;
 
public readonly int PointValue;

And add these:

private const float GravityAcceleration = 6500.0f;
private const float MaxFallSpeed = 600.0f;
private bool isFalling;
 
public Vector2 Velocity
{
    get { return velocity; }
    set { velocity = value; }
}
Vector2 velocity;

Now, since we want to be able to trigger the apples to fall when the player passes under them, we’ll need to create a bounding rectangle, which is taller than the actual apple. This will be the rectangle the player will collide with once he passes under the apple, and hence the apple will start falling.

public Rectangle TriggerRectangle
{
    get
    {
        int left = (int)basePosition.X;
        int width = 32;
        int top = (int)basePosition.Y;
        int height = 200;
        return new Rectangle(left, top, width, height);
    }
}

We need to implement some kind of basic physics to calculate how fast the apple should be falling. This is done by adding a new method called ApplyPhysics, which checks if the apple is falling, and if it is, it updates the velocity and position based on some simple calculations:

private void ApplyPhysics(GameTime gameTime)
{
    float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
    if (isFalling)
    {
        velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed);
        Position += velocity * elapsed;
    }
}

To make sure it actually falls when triggered we need to update public void Update(GameTime gameTime) and add a call to the ApplyPhysics method we just created. The call can be added right after bounce, at the end of the method:

    bounce = (float)Math.Sin(t) * BounceHeight * texture.Height;
    ApplyPhysics(gameTime);
}

The last thing we need to do in the Apple class is to add a method for actually starting the fall:

public void OnRockFalling()
{
    isFalling = true;
}

Next up are some changes to the Level class. Find the line which creates the Gem array:

private List<Gem> gems = new List<Gem>();

And add a new array for the Apples:

private List<Apple> apples = new List<Apple>();

Next up is the loading of the Apples. In the LoadTile method, add a new case statement as follows:

    case 'R':
        return LoadAppleTile(x, y);

This will load R’s in the level code as apples. We now need to create the LoadAppleTile method:

private Tile LoadApppleTile(int x, int y)
{
    Point position = GetBounds(x, y).Center;
    apples.Add(new Apple(this, new Vector2(position.X, position.Y)));
    return new Tile(null, TileCollision.Passable);
}

Almost there! We need to create a few news method for getting the apples to work. The first is called UpdateApples, which checks the collisions with the player:

private void UpdateApples(GameTime gameTime)
{
    for (int i = 0; i < apples.Count; ++i)
    {
        Apple apple = apples[i];
        apple.Update(gameTime);
        if (apple.BoundingCircle.Intersects(Player.BoundingRectangle))
        {
            OnPlayerKilled(null);
        }
        else if (apple.TriggerRectangle.Intersects(Player.BoundingRectangle))
        {
            OnAppleFalling(apple);
        }
    }
}

Next up is the OnAppleFalling method, which in turn calls OnAppleFalling in the Apple class.

private void OnAppleFalling(Apple apple)
{
    apple.OnAppleFalling();
}

Now we just need to insert calls for these methods in the correct places. First up is the UpdateApples method. This is called from the Update method. Just find the following line:

    UpdateGems(gameTime);

and insert the UpdateApples call under it:

    UpdateApples(gameTime);

The last change is to the Draw method. You’ll see there is two lines used to draw the gems, and that’s what we need to do for our apples. Insert the two following lines after the code for the gems:

foreach (Apple apple in apples)
    apple.Draw(gameTime, spriteBatch);

Now, to give this a spin, open the 0.txt level file and place some R’s here and there. When you start up the game you should see some red gems which falls down when you pass under them.

PS: A more clever approach here would be to create a base class for these classes, which would hold all the shared logic and methods, but the goal for this tutorial is to show how to implement the new feature as easily as possible.

[tags]C#,XNA,Game Development[/tags]

At no time is freedom of speech more precious than when a man hits his thumb with a hammer.

~Marshall Lumsden

This is an experiment in designing an internationalization feature which I’ve been thinking about for a while. The idea is for people to come up with designs and implementations for the described requirements, and get a healthy discussion going on how to get a feature like this implemented in the best way. I’ve came up with some features and requirements which should make the design somewhat interesting.

Wanna play? If so, continue reading.

Now, let’s consider a website, which is to be deployed for several markets (in several countries), and serve both residential and corporate customers.

Requirements

A “tag” is an identifier for any given text that may be translated. The “tag” can be the text itself in the source language, or an identifier such as LABEL_CLICK_HERE, all depending on the implementation.

A tag’s content can be translated to any given language

This is the most basic feature, and does not need any explanation.

Any given market should be able to use the application in any given language

Customers in the French market should be able to view the application in German and so on. Does not sound tricky, but see next point.

A tag’s content *may* have different meaning in different markets

For example, in the US a zipCode validation error will differ from the zipCode validation error used in Spain, but surname validation errors will be the same. This also goes for descriptive texts for features and services which might differ. However, for 90%+ of the translated texts, the English translation in Spain would be the same as the english translation in the US.

A tag’s content *may* differ based on the context of the user

Imagine the front-page when a used is logged in. A text is presented here with information about available features, instructions on how to use them etc. Now, some of these features are not available for residential customers, while some are exclusive to residential customers. The usage/instructions of the features may be different for corporate customers. In addition, both residential and corporate customers have roles in the application (admin users and regular users), and the content may differ based on the role. Most of the tags will just have one content, but some may have several. The available contexts could be visualized as a tree structure, with ‘ALL’ at the top, which forks out to corporate and residential, which in turn forks out to admin / user:

Contexts

Contexts

When retrieving content for a tag the system should first look for the user’s context, for example “Residential Admin”, and if no content is present it shall select the parent etc.

Any changes to a tags’s content should be kept in a history log

Every time a tag’s content is changed, the old version should be kept for historical purposes. A nice bonus would be to be able to change a tag’s content ahead of time , that is, setting an effective date.

These are the basic requirements I’ve made up for this experiment. Now, I’d like to hear how you tackle internationalization in your application, and how you would design a implementation which would sastisfy the requriements described here. I’m working on my own implementation for this which I’d like to share after I’ve seen what other people come up with. If you have suggestions for more requirements which would make this even more interesting, please send a comment!

[tags]PHP,Internationalization[/tags]

So, I finally got around to upgrading WordPress and setting up a proper theme. I still want to customize it a bit, but it’s fine for now.

I’ve recently started playing with XNA Game Studio, and I’m really impressed with what Microsoft has pulled off with this framework. I found a starter-kit for a platformer, and I was up and running, making new content and features in less than 45 mins. It’s been a long time since I last worked with C#, and I found it refreshing to get back to it.  I’ll try to do some posts on it later on.

I’ve been dormant for quite some time, mainly due to a major project going on at work. This week I’m starting my vacation, and its time to get back to all things fun. Today I got offered a spot on the Prado Developer Team, which I hope will prove to be both a challenge and a great opportunity to improve my knowledge on both the framework and PHP.

As a part-time project I’ve started building a multi-touch display surface inspired by Microsoft Surface. I’ve completed a *very* basic edition (tutorial here, and I’ve just started planning a more complicated setup along the lines of this project.

I’ll do some posts on the process as soon as I get some pictures.

[tags]PHP, Prado, Multi-touch[/tags]   

Some time ago a friend of mine tipped me about this article series called “What every programmer should know about memory” written by Ulrich Drepper (lead contributor and maintainer of glib). I just recently came around to start reading it. This is a 100 page long text which covers computer memory in detail, with focus on how software interacts with memory. From RAM to CPU caches the text moves on to tips on how we as programmers can improve our code when it comes to memory management and performance. A really good read which I suggest every programmer should check out.

[tags]Hardware, Memory, Unix/Linux[/tags]

Aug 262008


After receiving quite some feedback on my post “Why Delphi for PHP should have used Prado instead of VCL” I decided to do a follow up to that post. Some of the feedback was quite interesting, hence this post was born.

First and foremost I’d like to address the feedback I got regarding the class name prefixing in VCL/PHP. I argued that the lack of class prefixes could create problems in the future, and used Prado’s T notation as as sample of something that would at least be a bit better. Let’s take a look at two VCL/PHP classes named Collection and Object. These two names are often reserved in programming langues (atleast object oriented ones). If PHP decides to introduce these two classes the VCL/PHP guys would be pretty screwed. It would involve refactoring the framework as well as applications which uses those classes. Prado on the other hand has a prefix (TCollection etc. minor, but it’s a world of difference). I assume that the VCL/PHP authors will introduce namespace support with PHP 5.3, so this issue will hopefully be a thing of the past when 5.3 ships. That said, I’m a bit curious to see how the migration / backwards compability would turn out if VCL/PHP adopt namespaces.

What I miss in the feedback I got from my previous post was people acually using VCL/PHP for enterprise applications and how that is working. From what I can tell the usage of Exceptions is still limited to the 3rd party libs such as Zend Framework which are included with VCL/PHP. That’s a bit interesting.

I’d like to touch on the comment made by Pieter Viljoen for my original post. I agree that Codegear pushed quite a toolset for the PHP community in a short time, but the underlying code is not enterprise quality. One can argue that PHP is ugly and flawed (not sure I agree on that part), but that does not mean that one should not strive for good architecture and methodology when developing frameworks on top of PHP. I see the point that VCL/PJP offers features that are interesting for starting PHP developers, but for large scale applications I just don’t see it. I’d be pretty cautious pulling in a framework without exception support if I was to create an application.

Again, I’m really interested in some feedback from someone that actually has built applications with VCL/PHP.

I’ve also noticed that there is not much activity in the VCL/PHP SVN repository. Anyone know what’s going on there?

[tags]PHP, Prado, VCL4PHP[/tags]  

If some of you recently got email saying you just made a comment here, it’s most likely due to that I moved some comments over from my old blog (http://eirikhoem.wordpress.com/). I’ll get around to answering any questions later today. Thanks for commenting!

When doing complex applications it’s often nice to have some sort of system for handling settings. PHP has a nice function called parse_ini_file which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a given key is all that’s needed. The example I’m providing is pretty basic, but it’s still very usable and can be added to almost any application.

First, we need to create a file to hold the settings. It’s ordinary plaintext and follows the INI format.

Here is a quick sample of some key / value pairs:

[general]
locale = no_NO
company.name = MyCompany

datasource.host = localhost
datasource.database = mydb
datasource.username = user
datasource.password = 1234

The class for accessing the file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class MyConfigClass{
  protected $config;
 
    public function __construct()
    {
      $this->config = parse_ini_file('../conf/myapp.ini');
 
    }
 
    public function getConfig($key = null)
    {
      if($key !== null)
      {
        if(isset($this->config[$key]))
        {
          return $this->config[$key];
        }
        else
        {
          throw new Exception("Unknown key '$key' in configuration");
        }
      }
      else
      {
        return $this->config;
      }
    }
 
    public function setConfig($config)
    {
 
      $this->config = $config;
    }
}
 
?>

Usage:

1
2
3
$configManager = new MyConfigClass();
 
$value = $configManager->getConfig['datasource.host'];

Now, when working on larger application one usually have a application like class, and that’s a nice place to put this code. When using Prado I usually place the config code in the TApplication class.

[tags]PHP[/tags]