Last Ray of Hope Home of Kaluriel Hargrove

28Mar/08Off

Website Design

Despite being nearly four to six years since I did any website designed, I'm still surprised how quickly I adapt to new or changing languages.

My knowledge of PHP and MySQL seems to exponentially increasing with the more I do, and just by glancing at my housemates source code for the professional website he is developing for someone, I pick up so much more.

These two week Easter break have been a much wanted break from programming, learning someone new is quite fun, though would I ever want to get into the web design business again? hell no, I find making applications so much easier to make secure with techniques such as memory mirroring and xor'ing important variables.

But still, it is a nice escape, and good to work on my portfolio website.

Tagged as: , No Comments
27Mar/08Off

Legend of Bob: Snow

agt_9I decided to change the grass texture to a snow texture, and make the town a snowy scene. However it didn't look right. So I decided to add a snow particle effect.

The snowflakes are additive and alpha blended, and so give a glow, and stop at ground level, this is ruining slightly with the river since it is just slightly less than ground level.

agt_13Also the fact that a vertex shader is being for the water to make it look like it is moving, the snow shouldn't settle on it, but it does.

Unfortunately that is not much I can do about it, at some point I may go through and setup multiple emitters that bypass the areas that the snow has a problem with, or adjust it so that it stops at a different ground level.

24Mar/08Off

Constructors, Avatars and Codecs

Redesigned the avatar which my friend Joey made for me a few years back. Cleaned up the edged, and changed the font.

While editing some videos last night, that I made of World of Warcraft last year (a 3-man Onyxia fight), I got thinking about designing a development codec. Since the files I recorded were at a stupidly high resolution of 1680x1050 at 30fps (about 30GB each), it was taking forever to do anything with them.

So I thought, how about a codec with the high quality bitstream data, but with a low quality editing stream to go with it. Big emphasis on random access and bidirectional seeking would be key to this my friend Gavin pointed out to me on IRC. Then when you've done editing using the low quality stream, it can be applied to the high quality when converting.

Would be nice if the C++ standard included constructors like PHP5 is introducing ( __construct() ), so whenever you change a class name, you don't have to renamed the constructor(s) and destructor.

22Mar/08Off

New Website Design

Implemented a new website design thanks to my housemate Brian who is great at implementing CSS and strict HTML.

Starting to get the functionality up and running so I don't have to do everything through the database manager.

Tagged as: , No Comments
22Mar/08Off

Legend of Bob: Playing Sound with FMOD

FMOD LogoA few month ago I gave up on the idea on using OpenAL for playing sound effect since trying to get MP3s to play with it was getting annoying. A friend recommended whilst in the Student Union to use FMOD, so I switched over and found it did everything I needed, plus there was plenty of documentation and examples.

So here is some basic code for getting audio playing using FMOD, as well as a few additional functions. I've only allocated blocks for playing 10 sounds (if more than 10 sounds are attempted to be loaded, LoadSoundByFile() returns -1).

Here is the header for my sound manager.

#ifndef SOUNDMANAGER_H_INCLUDED
#define SOUNDMANAGER_H_INCLUDED
 
// --- [ libraries ] ------------------------------------------
#pragma comment(lib, "fmodex_vc.lib")
 
// --- [ includes ] -------------------------------------------
#include <fmod.hpp>
 
// --- [ definitions ] ----------------------------------------
#define SOUND_LOOP_INFINITE -1
#define MAX_NUM_SOUNDS 10
 
// --- [ class ] ----------------------------------------------
class SoundManager
{
// Attributes
private
	FMOD::System * m_pSystem;
	FMOD::Sound * m_pSound[MAX_NUM_SOUNDS];
 
// Functions
public:
	// Constructor
	SoundManager();
 
	// Destructor
	~SoundManager();
 
	// Load Sound from File
	int LoadSoundFromFile( const char * inFilename );
 
	// Free Sound
	void FreeSound( const int inSoundId );
 
	// Play Sound
	void PlaySound( const int inSoundId );
 
	// Set Position
	void SetSoundPosition( const int inSoundId, const int inPositionInMilliseconds );
 
	// Set Loop Count
	void SetSoundLoopCount( const int inSoundId, const int inCount );
 
	// Set Loop Points
	void SetSoundLoopPoints( const int inSoundId, const int inStartInMilliseconds, const int inEndInMilliseconds );
};
 
#endif

 

For background music, I've also included code so that the sound can be looped forever, and since not all sounds will be looping from the beginning, I've added a function to set where the loop repeats from and begins again. When a sound is not being used anymore, FreeSound() should be called for the id returned by LoadSoundFromFile().

// --- [ includes ] -------------------------------------------
#include "SoundManager.h"
 
// --- [ constructor / destructor ] ---------------------------
SoundManager::SoundManager()
{
	for( unsigned int i = 0; i < MAX_NUM_EFFECTS; ++i )
	{
	m_pSound[i] = 0;
	}
 
	// Create FMOD SoundSystem
	FMOD::System_Create( &m_pSystem );
 
	// Check FMOD Version
	unsigned int fmodVersion;
	m_pSystem->getVersion( &fmodVersion );
	assert( fmodVersion >= FMOD_VERSION )
 
	// Initialize FMOD SoundSystem
	m_pSystem->init(32, FMOD_INIT_NORMAL, 0);
}
 
SoundManager::~SoundManager()
{
	// Free FMOD Sounds
	for( unsigned int i = 0; i < MAX_NUM_SOUNDS; ++i )
	{
		if( m_pSound[i] )
		{
			m_pSound[i]->release();
		}
	}
 
	// Free FMOD SoundSystem
	if( m_pSystem )
	{
		m_pSystem->close();
		m_pSystem->release();
		m_pSystem = 0;
	}
}
 
// --- [ functions ] ------------------------------------------
int SoundManager::LoadSoundFromFile( const char * inFilename )
{
	for( int i = 0; i < MAX_NUM_SOUNDS; ++i )
	{
		if( !m_pSound[i] )
		{
			m_pSystem->createSound( inFilename, FMOD_SOFTWARE, 0, &m_pSound[i] );
			return i;
		}
	}
 
	return -1;
}
 
void SoundManager::FreeSound( const int inSoundId )
{
	assert( inSoundId >= 0 && inSoundId < MAX_NUM_SOUNDS );
 
	if( m_pSound[inSoundId] )
	{
		m_pSound[inSoundId]->release();
		m_pSound[inSoundId] = 0;
	}
}
 
void SoundManager::PlaySound( const int inSoundId )
{
	assert( inSoundId >= 0 && inSoundId < MAX_NUM_SOUNDS );
 
	if( m_pSound[inSoundId] )
	{
		FMOD::Channel * channel;
		m_pSystem->playSound( FMOD_CHANNEL_FREE, m_pSound[inSoundId], false, &channel );
	}
}
 
void SetSoundPosition( const int inSoundId, const int inPositionInMilliseconds )
{
	assert( inSoundId >= 0 && inSoundId < MAX_NUM_SOUNDS );
 
	if( m_pSound[inSoundId] )
	{
		m_pSound[inSoundId]->setPosition( inPositionInMilliseconds, FMOD_TIMEUNIT_MS );
	}
}
 
void SoundManager::SetSoundLoopCount( const int inSoundId, const int inCount )
{
	assert( inSoundId >= 0 && inSoundId < MAX_NUM_SOUNDS );
 
	if( m_pSound[inSoundId] )
	{
		m_pSound[inSoundId]->setLoopCount( inCount );
	}
}
 
void SoundManager::SetSoundLoopPoints( const int inSoundId, const int inStartInMilliseconds, const int inEndInMilliseconds )
{
	assert( inSoundId >= 0 && inSoundId < MAX_NUM_SOUNDS );
 
	if( m_pSound[inSoundId] )
	{
		m_pSound[inSoundId]->setLoopPoints( inStartInMilliseconds, FMOD_TIMEUNIT_MS, inEndInMilliseconds, FMOD_TIMEUNIT_MS );
	}
}

 

All timing in my code is in milliseconds, but it can be changed to another supported FMOD time unit.

Tagged as: , , , No Comments
19Mar/08Off

The Most Evil Code Ever

I have just created quite possibly the most evil code to mankind, its an abomination. However it did double my FPS.

Basically, I thought to myself "a class is basically just a structure, and its functions are basically the same function but with a pointer to the class at the beginning, so why can't I just have a pointer to a function within the class, and the class pointer and combine the to for function callbacks, but on a generic level, only have the base class structure known". And so thats what I set out to do, to test if it would work.

Now instead of calling an OnEvent function that is pure virtual in the base class, I can call the functions directly, skipping the middleman. It compiles on g++ and visual studio 9.

//
//
#include <iostream>
 
//
//
class IBase
{
	public:
		IBase()
		{
		}
 
		virtual ~IBase()
		{
		}
 
		int testno( const int j )
		{
			return 3;
		}
};
 
//
//
class clsDerived : public IBase
{
	public:
		clsDerived()
			:
			IBase()
		{
		}
 
		int test( const int i )
		{
			return i;
		}
};
 
//
//
class clsMyDerive : public IBase
{
	public:
		clsMyDerive()
			:
			IBase()
		{
		}
 
		virtual ~clsMyDerive()
		{
		}
 
		virtual int tested( const int i )
		{
			return -i;
		}
};
 
//
//
class clsMyD : public clsMyDerive
{
	public:
		clsMyD()
			:
			clsMyDerive()
		{
		}
 
		int testy( const int i )
		{
			return ~i;
		}
 
		int tested( const int i )
		{
			return -1 + 1;
		}
};
 
//
//
typedef int (IBase::*_FN_CLSGAME)( const int );
 
//
//
int main()
{
	IBase * test = new clsDerived();
	IBase * test2 = new clsMyDerive();
	IBase * test3 = new clsMyD();
	_FN_CLSGAME q;
 
	q = reinterpret_cast<_FN_CLSGAME>( &clsDerived::test );
	std::cout << "Test 1: %d" << (test->*q)(12) << std::endl;
 
	q = reinterpret_cast<_FN_CLSGAME>( &clsMyDerive::tested );
	std::cout << "Test 2: %d" << (test2->*q)(12) << std::endl;
 
	q = reinterpret_cast<_FN_CLSGAME>( &clsMyDerive::tested );
	std::cout << "Test 3: %d" << (test3->*q)(12) << std::endl;
 
	return 0;
}

 

Tagged as: , No Comments