Friday, September 15, 2006

THERE AIN'T NO TIMES LIKE THE OLD TIMES

Today I was thinking of posting some comments about some of the engines out there, but then I said "naaa! It's Friday. Let's take it easy and leave that for Monday".

So, what's for today? Doing some search for new posts in a couple forums I found some references to "old" games and I couldn't help remembering the old machines, old games, old sweet days. Snif! Snif! So let's go retro ...

Going back to the mid 80's I remember receiving my first computer ever: a ZX Spectrum Plus ... aahhh! My first love. Responsible for my passion on videogames. Titles like "Pssst", "Atic-Atac" and "Game Over" come very fast to my mind. Those were the days when you had to wait like 5 minutes or so until the game loaded into memory (48k ... wow!) while you prayed not to receive that nasty error message that appeared when the cassette player emmitted a wrong sound. Remember that? I bet you do. Then without loosing your hope, you used to rewind the tape, press "play" so that everything started again.

Then I switched to a "Commodore 128D" with a 5 1/4 drive. A whole new world for me. Just the fact of not having to use a tape was terriffic for me. Games like "Dig Dug" and "Bruce Lee" helped me tolerate those boring afternoons after high school when there was no one to call, no football matches, not even homework.

Then came an "Amiga 2000" (without hardrive I regret -too expensive back in those days) but again with an unknown hardware for me: a 3 1/2 floppy drive (I know what you're thinking: "what a challenge!"). This was a big change regarding visual quality: the graphics, colors, the cut-scenes. And also regarding sounds and music: my favorite? "Shadow of the Beast" (that guitar track that played when the game was over was really enjoyable). Games like "Prince of Persia" (with those impressive movements of the main character), "Lotus Espirit Turbo Challenge" and "The Blues Brothers" (a very funny platform game) caught my attention for hours and hours.

Finally, I bought my first PC computer: a notebook "Presario 1080". After that I realized something "I love notebooks". I have to admit that desktops are in general more powerful and you can get a better desktop for the same price or less than a notebook (especially if you buy the part separately and assemble the machine by your-self), but notebooks are quite more handy. With time I started to value more "handiness and comfort" than "hardware power" (yeah, I know, to some extent, since it has a direct relation to your needs as well as your purchasing power). We all know PC games but the first I played was "Pod" (since it came with my notebook), then "Primal Rage", "Alone in the Dark", the "FIFA" and "Star Wars" series (Rebel Assault, Tie Fighter, etc.), among others.

Now-a-days, I've got a 64-bit-processor desktop with the power to run smoothly each and every newest PC game in the market (like one of my favorites "Prince of Persia: The Sands of Time") but I still enjoy playing classic retro games, every now and then.

Well, that's all guys. Have a nice weekend!

[By the way, which are/were your favorites "retro" games?]

Thursday, September 14, 2006

MANAGED DIRECTX AND WINDOWS XP PRO 64-BITS

As most of you may know, there is no MDX support for x64 platform yet. So, in order to run any MDX program the platform target should be set to "x86" (that is, 32 bit).

For users of WinXP Pro x64 that want to run Managed DirectX code with Visual Sudio 2005 (also applicable to the XNA framework) -any version, take due note that there are two possible ways to avoid the nasty "Bad image format" exception.

As mentioned in Benjamin Nitschke's blog, the first one, is by modifying the "csproj" file with the notepad. Just locate and open the file and then add the following line:

<PlatformTarget>x86</PlatformTarget>

(if the "node" already exists, just replace it with the above-mentioned one).

The second one, is by using VS IDE it-self. Following this link for further instructions.

Stay tuned!

Wednesday, September 13, 2006

FRAMERATE COMPONENT FOR XNA

Just a quick note: I have posted the source code for a simple component that calculates and display the framerate of your XNA-game project.

Considerations:

  • You might change the namespace in line to your game's namespace.
  • Currently, the game window's title will be used to display the framerate (this will change when XNA supports fonts). As a workaround, you can use garykac's bitmap fonts example to modify this behavior.
  • If "Enabled" is set to false, framerates are not calculated (Current is set to 0).
  • If "Visible" is set to false, the current framerate value is not displayed (but yet it can be calculated if enabled).
  • When you want to show the decimal part of the framerate value (that is, "ShowDecimals" is set to true), you can set the display format to the fixed one (like "0.00").
  • You can also set whether the time step must be fixed or not.
  • You are free to modify/optimize the source code as desired. Please share your optimizations with the community.

Enjoy!!!

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Components;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
/// <summary>
/// Simple class to calculate the frame-per-seconds rate of your game.
/// </summary>
public sealed partial class Framerate : GameComponent
{
#region Instance Fields

private float deltaFPSTime;
private double currentFramerate;
private string windowTitle, displayFormat;
private bool enabled, visible, canDraw, showDecimals;

#endregion

#region Instance Properties

/// <summary>
/// Gets the current framerate.
/// </summary>
/// <remarks>
/// The 'Enabled' property must have been set to true to retrieve values greater than zero.
/// </remarks>
public double Current
{
get{ return this.currentFramerate; }

}

/// <summary>
///
Gets or Sets a value to enable framerate calculation.
/// </summary>
public bool
Enabled
{
get { return this.enabled; }
set
{
this.enabled = value;
this
.currentFramerate = 0;

if (this.Game != null && this.windowTitle != null && !this
.enabled)
this.Game.Window.Title = this.windowTitle;
}
}

/// <summary>
///
Gets or Sets a value to display framerate on screen.
/// </summary>
/// <remarks>
///
Currently, the framerate is shown in the window's title of the game.
/// </remarks>
public bool Visible{

get { return this.visible; }
set
{
this.visible = value;

if (this.Game != null && this.windowTitle != null && !this
.visible)
this.Game.Window.Title = this.windowTitle;
}
}

/// <summary>
///
Gets or sets a value indicating whether the time step must be fixed or not.
/// </summary>
/// <remarks>
///
If set to true, the game will target the desired constant framerate set in your main class ('Game1', by default).
/// </remarks>
public bool
IsFixedTimeStep
{
get { return this.Game.IsFixedTimeStep; }
set
{
if(this.Game != null)
this.Game.IsFixedTimeStep = value;
}
}

/// <summary>
///
Gets or sets a value indicating whether the framerate will display decimals on screen or not.
/// </summary>
public bool
ShowDecimals
{
get { return this.showDecimals; }
set { this.showDecimals = value; }
}

/// <summary>
///
Gets or sets a value indicating whether the decimal part of the framerate value must be display as fixed format (or as double format, otherwise).
/// </summary>
/// <remarks>
///
The 'ShowDecimals' property must be set to true in order to set the proper format.
/// </remarks>
public bool
FixedFormatDisplay
{
get { return this.displayFormat == "F"; }
set { this.displayFormat = value == true ? "F" : "R"; }
}

#endregion

#region Constructors

/// <summary>
/// Parameterless constructor for this class.

/// </summary>
public
Framerate()
{
InitializeComponent();
}

#endregion

#region Instance Methods

/// <summary>
/// Called after game initialization but before the first frame of the game.
/// </summary>
public override void Start()
{
this
.canDraw = false
;
this.currentFramerate = 0;

this.windowTitle = this.Game != null ? this.Game.Window.Title : String.Empty;
}

/// <summary>
///
Called when the gamecomponent needs to be updated.
/// </summary>
public override void
Update()
{
if (this.enabled)
{
// The time since Update() method was last called.
float elapsed = (float)this
.Game.ElapsedTime.TotalMilliseconds;

// Ads the elapsed time to the cumulative delta time.
this
.deltaFPSTime += elapsed;

// If delta time is greater than a second: (a) the framerate is calculated, (b) it is marked to be drawn, and (c) the delta time is adjusted, accordingly.
if (this.deltaFPSTime > 1000)
{
this.currentFramerate = 1000 / elapsed;
this.deltaFPSTime -= 1000;
this.canDraw = true;
}
}
}

/// <summary>

///
Called when the gamecomponent needs to be drawn.
/// </summary>
/// <remarks>
///
Currently, the framerate is shown in the window's title of the game.
/// </remarks>
public override void
Draw()
{
// If the framerate can be drawn, it is shown in the window's title of
the game.

if (this.visible && this.canDraw)
{
string currentFramerateString = this.showDecimals ? this.currentFramerate.ToString(this.displayFormat) : ((int)this.currentFramerate).ToString("D");

this.Game.Window.Title = "FPS: " + currentFramerateString;

this.canDraw = false;
}
}

#endregion
}
}

[We will discuss and focus on XNA GSE later.]