Articles

Foreword:

I've never been a consistent blogger, but even so, this section is for articles separate to the scrapbook, that, perhaps, are written to a slightly better quality than the entries in the scrapbook.

PHP Setup Script

Posted: 2009-11-22

To help deploy several mid-sized projects I've developed a previously half-baked script into a useful, fully resuable, PHP class for writing setup variables from a webform and executing instructions. Its best explained by the code snippets seen below-

Sample setup script:

Php:

<?php 
include('setup.class.php');

/* Variables for the application */
$setup = new SetupScript('constants.php''pe5ches4''Setup and configuration');
// Note: If a value is required, set the default value to false to force validation on the variable
// Note: $setup->AddVariable('name', max_length, default_value, 'helpful_description', 'helpful_example');
// Note: $setup->AddInstruction('MethodName', 'Description of function');

$setup->AddVariable('MYSQL_SERVER'0falsefalse'MySQL server''localhost:/tmp/mysql5.sock');
$setup->AddVariable('MYSQL_DATABASE'0falsefalse'- Database''database');
$setup->AddVariable('MYSQL_USERNAME'0falsefalse'- User''user');
$setup->AddVariable('MYSQL_PASSWORD'0truefalse' - Password''password');
$setup->AddLinebreak();

$setup->AddVariable('COMMENTS_TABLE'0falsefalse' Table name to store entries''oc_comments');
$setup->AddVariable('SERVICE_DIRECTORY'0falsefalse' URL of OpenComments Service''http://mkv25.net/opencomments/v2/');
$setup->AddLinebreak();

$setup->AddVariable('BBCODE_SITE_ROOT'0falsefalse' Default for bbcode links''http://mkv25.net/info/');
$setup->AddLinebreak();

$setup->AddVariable('TRUSTED_USER_1'0falsefalse'''http://mkv25.net/openid/Markavian');
$setup->AddVariable('TRUSTED_USER_2'0falsefalse'''http://localhost/openid/Markavian');

/* End variables */
/* Post setup instructions */
$setup->AddInstruction('CreateTables''Create tables in the database needed for the application'true);
$setup->AddInstruction('AnnounceSuccess''Annouce successful installation');
/* End instructions */

function CreateTables()
{
    echo '<h2>SQL Tables</h2>';
    echo '<p>Creating tables...</p>';
    
    require_once('constants.php');
    require_once('../config/sql_class.php');
    $sql = new sql($MYSQL_SERVER$MYSQL_DATABASE$MYSQL_USERNAME$MYSQL_PASSWORD);

    $instructions = array();
    
    $instructions[] = sprintf("
CREATE TABLE IF NOT EXISTS `%s` (
  `comment_id` int(11) NOT NULL auto_increment,
  `url` varchar(255) NOT NULL,
  `comment` text NOT NULL,
  `openid` tinytext NOT NULL,
  `username` varchar(32) NOT NULL,
  `website` varchar(128) NOT NULL,
  `postdate` datetime NOT NULL,
  `comment_type` enum('comment','feedback','todo','bug','suggestion') NOT NULL,
  PRIMARY KEY  (`comment_id`,`url`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    "$COMMENTS_TABLE);
    
    foreach($instructions as $name=>$query)
    {
        $sql->query($query$name);
    }
    
    echo '<p>Sparing error messages listed above; tables created.</p>';
}

function AnnounceSuccess()
{
    echo "<h2>Success</h2>";
    echo "<p>Installation was a success.</p>";
}

/* Create, process, and display page */
$setup->DisplayPage();
?>

This produces a HTML form like so:

The above file would be written by the project developer responsible for packaging and deploying a project. They would usually identify common variables likely to change on deployment and define them in a file, say constants.php ("Constant" in the context of unchanging through the application); using the format above these variables could instead be defined in a setup file with appropriate descriptions. In turn, a html based setup form can be created and basic validation can be applied, allowing constants.php to be created on the fly through a web interface. This eases and speeds up deployment and provides documentation for the next developer to work from.

From the web interface, when the form is submitted, constants.php is created and the selected instructions are executed:

Sample output file:

Php:

<?php 
// WARNING: This is a dynamically created file; edit only as a last resort
// Generated by SetupScript class on Monday 23rd of November 2009 01:08:51 AM 
// - Local path:  C:/Documents and Settings/John/My Documents/Websites/opencomments/trunk/services/setup.php
// - Remote path: http://localhost/opencomments/services/setup.php
// Dependencies: setup.class.php

// Title:                Setup and configuration
// Description:    This installation script will create the file constants.php.
// Configuration variables:

$MYSQL_SERVER "localhost:/tmp/mysql5.sock"// MySQL server
$MYSQL_DATABASE "db"// - Database
$MYSQL_USERNAME "un"// - User
$MYSQL_PASSWORD "pw"//  - Password

$COMMENTS_TABLE "oc_comments"//  Table name to store entries
$SERVICE_DIRECTORY "http://localhost/opencomments/services/"//  URL of OpenComments Service

$BBCODE_SITE_ROOT "http://mkv25.net/info/"//  Default for bbcode links

$TRUSTED_USER_1 "http://mkv25.net/openid/Markavian";
$TRUSTED_USER_2 "http://localhost/openid/Markavian";

// Additionally, the following instructions were executed: 
// 1.    Create tables in the database needed for the application (optional)
// 2.    Annouce successful installation
?>

Once successful the output of the setup script then contains information about how the file was generated, what each of the variables corresponds to, and information about any instructions executed afterwards- doubling up as a usable part of an application and a log file.

If the rest of the application is written correctly it can detect the presence of the configuration file, or a variable inside, and react / redirect appropriately to prompt the user for action.

Feel free to download and try the script out; setup.class.php is self contained and the sample above is included in the top of its comments.

Downloads

[zip] SetupScript v1.02
Read more »

OpenID and OpenComments

Posted: 2009-11-19

OpenID is an authentication system that uses a single point of login to authorise a user across a range of websites. Users trust an OpenID provider to store and protect their details.

To login to a compatable OpenID website the user supplies the provider's authentication URL and the website they're on requests access. Users are usually redirected to a login page with their provider where they authenticate themselves, and this authentication is communicated back to the 3rd party website.

Advantages

The big advantage is that OpenID provides a single point of login- the user authenticates once with their trusted provider and that's it. Subsequent "logins" to other sites are handled automatically because the user has already authenticated with their provider, and for the duration of their session the provider will support the login.

From a developer perspective; having an OpenID compatable login means that I no longer have to store login details for each individual visiting my site. Chances are they've already registered with an OpenId provider, and I've always been uncomfortable with forcing people to register to participate in online discussion. By providing an OpenID login instead- users can identify themselves and gain full access to manage their own posts after submitting content to the site

OpenComments

OpenComments is a project I'm working on to produce an OpenID enabled comments system that uses JQuery remote $.get and $.post calls to bring comments onto static HTML pages using javascript. Quite often comments are superfluous to the contents of an article, but do provide useful feedback. The main drawback of comments as I see it, which may also arguably be an advantage, is their draw for comments to rank in SEO- for good and for bad. On the whole people have little control over what people post and the target of most spam is to promote search result rankings on other sites. By bringing comments in using javascript requests there's a chance search engines will ignore them, and the focus of the page load is on the main content not the comments.

For now you can see the OpenComments system in action across articles and scrapbook entries on this site, but in future hopefully there will be a project page where you can find out more information and try it out on your own site- prebuilt, just three lines of code. Stay tuned.

Read more »

Asteroids

Posted: 2009-10-20

What you see below is a tech test to visually check the new asteroid animations for the space shooter game. The interactive animation below is a test of collisions to see if spawning new asteroids work well together.

Each asteroid was rendered using Blobs coated with procedural textures- blobs being a useful proximity based building block for a 3D mesh, creating a soft outline appropriate for organic shapes. Each rendered frame of animation was then imported into flash into a looping sequence. The procedural textures are mathematically generated surfaces using fractal algorithms to create a harsh and varied surface. Procedural textures can be used for diffuse, normals, and displacement, making the micro-details easy to generate and improving the realism of the asteroids.

Initial tests suggested that there weren't enough frames in each animation giving the impression that the rocks were spinning too fast. Slower movement suggests larger, heavier, while faster suggests smaller, lighter- Like battleships and speedboats. A large, fast, spinning rock has a worrying amount of momentum- and that looks wrong apparently. Running at 30 frames per second, the large rocks have 36 frames, the mid-sized ones have 24, and the small ones have 16.

So, now the spinning asteroid test is successful, and I have a new interactive toy to play with.

Read more »

Spaceshooter - Sprite Maker

Posted: 2009-10-13

To highlight one of the many innovations in my new game, I'm posting here to preview a technical mockup of the Solar Collector level; a cavernous construct harvesting energy from a close orbit to the sun.

What you see in the preview is a static render of the scene made from a handful of sprites (bitmaps) that have been positioned, flipped, rotated, blurred and recoloured to fit.

What's special about this preview is the SpriteMaker class which processes embedded assets, in the game, by applying filters and effects, before flattening the information back to bitmap data.

Alternatively I could have used the AS3 cacheAsBitmap flag, but if I used that I would lose some control over when elements are drawn to screen, which could in turn impact the performance of the game. With the sprite maker I can control when images get flattened (rendered).

Also, by centralising and containing the creation of assets, I'm able to apply a series of consistent effects, such as BackgroundTint, ForegroundTint, without having to manually regenerate images. Methods such as HueShift, TintToColor and BlendToColor also allow me to "set the mood" of different assets to create different landscapes- as in the example above each layer has a yellowish tint to heat up the scene.

Code:
/* Background */
CreateGraphic(SolarCollector.Pillar02, [Rotate180, BackgroundTint], ImageAlign.LEFT, -20, 0);
CreateGraphic(SolarCollector.Pillar01, [FlipVertical, BackgroundTint], ImageAlign.LEFT, 100, 0);
CreateGraphic(SolarCollector.Pillar01, BackgroundTint, ImageAlign.RIGHT, 20, 0);
CreateGraphic(SolarCollector.Pillar02, [FlipVertical, BackgroundTint], ImageAlign.RIGHT, -200, 0);
CreateGraphic(SolarCollector.Energyblock03, [Rotate180, BackgroundTint], ImageAlign.MIDDLE, 240, -10);
CreateGraphic(SolarCollector.Strata01, BackgroundTint, ImageAlign.TOP, 180, -5);
CreateGraphic(SolarCollector.Strata01, [FlipHorizontal, BackgroundTint], ImageAlign.TOP, -180, -5);
/* Midground */
CreateGraphic(SolarCollector.Energyblock01, Rotate90CCW, ImageAlign.MIDDLE, -170, -80);
CreateGraphic(SolarCollector.Energyblock02, Rotate180, ImageAlign.MIDDLE, 0, 70);
CreateGraphic(SolarCollector.Energyblock03, null, ImageAlign.MIDDLE, 220, -100);
CreateGraphic(SolarCollector.Solarcollector, FlipVertical, ImageAlign.TOP);
/* Foreground */
CreateGraphic(SolarCollector.Pillar01, ForegroundTint, ImageAlign.LEFT, 40, 0);
CreateGraphic(SolarCollector.Pillar02, [FlipHorizontal, ForegroundTint], ImageAlign.RIGHT, 40, 0);
CreateGraphic(SolarCollector.Solarcollector, ForegroundTint, ImageAlign.BOTTOM, -180, 20);
CreateGraphic(SolarCollector.Energypillar, [ForegroundTint], ImageAlign.BOTTOM, 150, 0);
CreateGraphic(SolarCollector.Strata02, [FlipVertical, ForegroundTint], ImageAlign.BOTTOM_RIGHT);
Read more »

History of mkv25.net

Posted: 2009-09-30

Launched in 2002 on the back of Universal Shipyards- mkv25.net has grown and warped into a blossoming network of sites featuring all the things I've held as hobbies over the years. Here is a history of the site featuring its key moments up til now.

2009

Neuro design created and site relaunch. The scrapbook was moved from the front page and archived to its own section. Articles, Gallery, Portfolio, and Games added. The strength of my the new gallery software and the cleanliness of the new design have got me quite exicted about the prospects of the new site.

Also, in a landmark decision for me, I've shunned IE6 to focus on CSS2 compatable browsers. Years of supporting IE6 have taken their toll on thousands of web-developers world wide; I think its time to put that browser to sleep.

2008

DFMA - Dwarf Fortress Map Archive took off in a big way. Thousands of visits a day and hundreds of maps and movies uploaded every month as the stats pages reveal.

2007 May

The Dwarf Fortress Map Archive (DFMA) was launched in support of the #bay12game classic Dwarf Fortress. Its launch heralded a new era in map-sharing and epic fortress building that would allow players to share unbelievable constructions of immense size with relative ease. Made possible by my FDF-Map Viewer software (written using Flash AS3), in partnership with ShadowLord's Map Compressor software, the site is truely innovative - if I may say so myself <Smile>.

2006

2006 was a quiet time, where I was very happy with the website, and so posted content and articles while restraining myself from making any changes to the design, or the layout. There were also side projects going on behind the scenes unrelated to web-development.

2005 December

The unify template was launched on both the main site and USy site. A design for The Fake Clan website was also made but never implemented. The new layout was much crisper and colourful and presented the existing content for both sites fantasticly.

2004 May

The main site went through a radical overhaul, removing the forum, and focusing plainly on the scrapbook articles with a visual splattering of icons gridded across the front page. This layout would stick right up until late 2009.

2004 March

In an attempt to make the forum more used it was moved to the front page with popular items listed along the top. Having a separate forum for a disparate set of content is the wrong way to handle comments and feedback, as demonstrated by the suprising popularity of the USy comments system; note- this would soon become the staple format for blogging across the internet (and soon to be expanded by google wave). I really can't stand forums and the words "never again" spring to mind~ when you compare forums to social networking sites you can see there are now much better ways to link content and comments together.

2003 October

The focus of the site was moved towards a scrapbook, with a supporting forum. The design looked awful and the forum was under-used, so was quickly scrapped.

2003 August

The I-Bead subsite - an support forum for an mp3 player made in Korea was launched. Being the only English language support forum for the device the site gained rapid popularity which would continue until the forum dwindled in usefulness in May 2005.

2003 July

A sophisicated content management system that cached (rendered) all its pages as HTML was implemented along with a new crayola-blue design. Friends were invited to write more articles, but only a handful of useful entries were published.

2003 January

The site was redesigned to cater for a 800x fixed width layout, with a cleaner cut white and grey design. mkv25.net's logo themed in red and navy.

2002 October

The website The Fake Clan - a Worms Armageddon (pc game) fansite for maps and team members was launched. The map archived featured a shopping cart and PHP Zipping system for downloading batches of maps from the site in a convenient download. All of the maps were designed by me and gained popularity amongst pro-ropers around the net- some of them I consider works of art <Smile>

2002 June

Site launch... 640x fixed with 3 column layout focusing on short articles and images from my friends.

News on the site: mkv25.net was registered on the 23rd of May 2002, and it worked, and I was excitied. I thought "This site needs a design! A cool, new design: something neat and tidy, original and useable. This webspace is my gift for people to come visit, to browse at their hearts content, I best make it look good"..."

2002 April

The website Universal Shipyards, built around Space Empires IV graphics and modding, which was previously hosted on Tripod and other places for the previous 3 years, was finally moved to my new server. The site was already handling thousands of visits a day which eventually dwindled as the game aged. USy was my first site, and a major hobby, leading me to learn programming, webdesign, and 3D graphics.

Epilogue

You can read more about the history of mkv25.net by searching for mkv25.net on google, or by looking at mkv25.net on the wayback when machine. mkv25.net has always been a showcase of sorts, its my way of collecting ideas and memes together and passing them onwards to my friends. May that continue for many years to come...

Read more »

No Adverts?

Posted: 2009-09-30

Put simply: I don't like adverts. Especially not on my website; and afterall, this is my website. As such, I've forged on with designs and layouts that focus on content. With any luck, they're easy to navigate, and you can immerse yourself in the depth of articles and images available throughout the site.

-

I hope you enjoy your time here- I'll try and keep things tidy for you. And browse to your hearts content, advertless, around my site <Smile>

Read more »

empty

mkv25.net home