Featured Posts
  • Sandora version 0.1.2 has been released. From the changelog: Fixed a bug where it would sometimes tried to insert particles outside the  boundary, resulting in a crash or palette shift....

    Sandora 0.1.2 released

    Sandora version 0.1.2 has been released. From the changelog: Fixed a bug where it would sometimes tried to insert particles outside the  boundary, resulting in a crash or palette shift....

    Continue Reading...

Latest Posts
0

Extending the CodeIgniter Database Active Record class, the non-hacky way

The past few weeks I’ve been busy working with CodeIgniter. If you don’t know what CodeIgniter is, it’s basically a lightweight and open source PHP web application framework. If you’re working with PHP applications, I suggest you check it out.

One of the best features about CodeIgniter (besides being lightweight and open source) is that you can basically extend all the core classes and substitute them for your own. This makes it a highly customizable framework.

However, one core concept you cannot extend – according to the documentation, are the database classes. I wanted to extend the Active Record database class to include custom functions like insert_delayed() and insert_update() (‘INSERT INTO … ON DUPLICATE KEY UPDATE …’, see MySQL docs here). Previous attempts from other people required altering the system files (aka ‘hacking’), instead of the application files, which is ugly and doesn’t last across framework updates.

However, thanks to the articles I found here and here, I came up with my own solution.

This extension requires 1) a custom Loader class, 2) a custom DB function and 3) a custom DB_active_record class. Using our custom Loader, we load our custom DB function, which in turn is used to load our custom DB_active_record class. Simple, no?

application/core/MY_Loader.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class MY_Loader extends CI_Loader {
	public function database($params = '', $return = FALSE, $active_record = NULL)
	{
		// Grab the super object
		$CI =& get_instance();
 
		// Do we even need to load the database class?
		if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
		{
			return FALSE;
		}
 
		// Check if custom DB file exists, else include core one
		if (file_exists(APPPATH.'core/'.config_item('subclass_prefix').'DB'.EXT))
		{
			require_once(APPPATH.'core/'.config_item('subclass_prefix').'DB'.EXT);
		}
		else
		{
			require_once(BASEPATH.'database/DB'.EXT);
		}
 
		if ($return === TRUE)
		{
			return DB($params, $active_record);
		}
 
		// Initialize the db variable. Needed to prevent
		// reference errors with some configurations
		$CI->db = '';
 
		// Load the DB class
		$CI->db =& DB($params, $active_record);
	}
}
 
/* End of file MY_Loader.php */
/* Location: ./application/core/MY_Loader.php */

Copy the contents from system/database/DB.php to application/core/MY_DB.php and look for the following:

require_once(BASEPATH.'database/DB_driver'.EXT);
 
if ( ! isset($active_record) OR $active_record == TRUE)
{
	require_once(BASEPATH.'database/DB_active_rec'.EXT);
 
	if ( ! class_exists('CI_DB'))
	{
		eval('class CI_DB extends CI_DB_active_record { }');
	}
}

Change it to the following:

require_once(BASEPATH.'database/DB_driver'.EXT);
 
if ( ! isset($active_record) OR $active_record == TRUE)
{
	require_once(BASEPATH.'database/DB_active_rec'.EXT);
 
	// get the CI instance
	$CI = & get_instance();
	$prefix = $CI->config->item('subclass_prefix');
 
	if (file_exists(APPPATH.'core/'.$prefix.'DB_active_rec'.EXT))
	{
		require_once(APPPATH.'core/'.$prefix.'DB_active_rec'.EXT);
		if ( ! class_exists('CI_DB'))
		{
			eval('class CI_DB extends '.$prefix.'DB_active_record { }');
		}
	} 
	else 
	{
		if ( ! class_exists('CI_DB'))
		{
			eval('class CI_DB extends CI_DB_active_record { }');
		}
	} 
}

(Thanks to robotslacker.com for the article on this one.)

Then, create your application/core/MY_DB_active_rec.php file:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
 
class MY_DB_active_record extends CI_DB_active_record
{
	public function foo()
	{
		echo 'foobar';
	}
}
 
/* End of file MY_DB_active_rec.php */
/* Location: ./application/core/MY_DB_active_rec.php */

And there you have it. A custom CodeIgniter active record database class, the non-hacky way. :) Once I come up with some good functions for ‘INSERT DELAYED’ and ‘INSERT INTO … ON DUPLICATE KEY UPDATE …’, I’ll post them.

0

Sandora 0.1.2 released

Sandora version 0.1.2 has been released. From the changelog:

  • Fixed a bug where it would sometimes tried to insert particles outside the  boundary, resulting in a crash or palette shift.
  • Changed key layout (see readme or see here).
  • Changed default particle from Wall to Sand. This is to prevent confusing new  users in thinking this is a paint program or something.
  • Added makefiles and key layout support for N900/N950.
  • Added Linux makefile.

Downloadable from Sandora’s Google Code page or click here to download 0.1.2.

0

Sandora updates, 0.1.2 in the works

I’ve picked up my Sandora project again since a few days and moved the code from SourceForge to Google Code. The new project page can be found here: http://code.google.com/p/sandora/. The official Sandora homepage is still http://mineth.net/projects/sandora/, so do continue to link to that (instead to Google Code directly). The SourceForge project page will close in a few weeks from now on.

Version 0.1.2 will be released next and will include a few bugfixes and will add support for Nokia N900 and N950 compilation (Maemo/MeeGo). If you have a N900 or N950 and want to help me test (I don’t have either device) or if you have any other handheld device capable running Linux with GCC and libSDL, please contact me and we’ll see what I can do to support more platforms. Version 0.1.2-RC2 is currently available in the trunk, so feel free to compile and test. A prepackaged PND will be released hopefully next week.

After this I’m planning to rewrite most of the code for performance and add some new particle types, since currently it uses quite some heavy stuff. Lots and lots of rand() calls each frame, a non-fixed framerate and a weird way of handling moved particles, just to name a few.

Tags:
0

Sandora on Maemo/Meego N9x0!

Someone has ported Sandora to the Nokia N950 phone, which looks really awesome!

YouTube Preview Image

It uses a slightly different key layout than the original Sandora version. See this topic for the announcement on the Maemo boards or this topic on the Meego boards.

Credits to Aapo Rantalainen.

Tags:
0

Current status of things

Here’s a quick post with the current status regarding Mineth Studios the past few months:

I (WaveHack) am still working on Multitroid, amongst some other minor projects. Progress is a bit slow due business with work.

AzMiLion is working on his Crash Viper game, which is (imo) looking really awesome so far. :3

Two people have joined the Mineth Studios team, both friends of both me and Az. These are Luminaflare and Power Metal Hank. Power Metal Hank is about to start working on his RPG projects and will hopefully blog occasionally about them.

0

Crash Viper: Build 5

Hey all,

Just a quick post to let you know that Crash Viper 20XX has been updated to the 5th build.

New in this version
-New enemy wich will actually shoot at you!
-Damage and movement values have been ever so slightly tweaked
-Changed the backend for spawning powerups after a enemy is killed, easier to implement like this.

As always, you can grab it here

0

An introduction of sorts.

I’m Luminaflare or LF for short, you may have seen me credited in the metafraxy project (I’m the original creator of those giant balls of doom among others) and more recently I’ve had some minor creative input on crash viper. I’m currently working on a few projects of my own but they are still in early development.

Also I’m British.

3

A new project: Crash Viper

All yer damn base are belong to us

Crash Viper 20XX
So yeah, I’ve decided to start working on games again, and I’m proud to announce my new pet project, Crash Viper 20XX. a side scrolling Shmup in the style of gradius, r-type and others.

Having recently decided to get back into gaming i thought that maybe making a a side scroller would be a good challenge at get me to think of new and exciting ways to play in this genre. so i came up with the Crash mechanic, a system which allows the user to alter the appearance and function of his ship. there are currently two ships known as the Drill Ship and the Wide Ship, they both have a unique crash with a unique weapon system.

Controls

Arrow keys – Move
X – Shoot
C – Crash

Features(Current)

Seeing as this is a very early test, the game is not yet feature complete so far i’ve implemented

-Basic enemies
-Crash System
-Ship selection
-Dynamic Background
-Custom SFX

Planned Features

-Levels with unique enemies
-Bossfights, 1 boss per level, maybe more.
-More unlockable ships
-upgraded versions of each ship
-Soundtrack? maybe?

Download

Right here

0

Moving servers, small downtime expected

Mineth.net will be moving servers in (hopefully) a few days and some of you might experience a few hours of downtime.

Sorry for the inconvenience.

0

WordPress 3.1.1 and MySQL strict, caution with upgrade!

As you might know, there is a fix which allows WordPress to run on MySQL strict. WordPress version 3.1.1 includes a database upgrade, which will break your WordPress installation if you run MySQL on strict/traditional if you upgrade automatically; I found out the hard way (although luckily on a test environment). The best bet is to upgrade the database manually.

Disclaimer: No server hamsters were (severely) harmed in the process.

Page 1 of 41234