I find my life to me quite busy, and there never seems to be enough time in which to complete everything I want to complete. Because of two classes, Computer Graphics 2, and Foundations of 3D, I find I don't have as much free time as I'd like.

I have to work on my ray tracing homework, which I need to rewrite to be multi-threaded, and improve the organization and design of it. I have to work on a project which uses that same ray tracing framework, and add a UI to it. For my 3d project I also need to add a UI. For this other personal project, Upwards, I need to finish the HUD stuff. Also for 3d, I'm working on a multi-threaded server with load-balancing capabilities. I'm also working on my own personal engine Warp, during the process of all of the above. I'm finishing up a Graduate school application for SMU. Also, my gf is staying with me, so I have to take care of her; however, I think she's helping me relieve stress, so I'm really glad she's here.  (Thank youu Becky! :O<3 )

On top of it all, my parents want me to use my free time to apply to jobs and try to get my life figured out before I graduate.   Um yeah, what free time again? I'm at school, and it's consuming my life, I don't have much time for anything else.  Thanks for being loving and considerate though.


 

There's a lot of stuff I want to add to my Warp engine: a build system like Make, CMake, or something; a pre-processor for putting content into faster loading files and possibly putting them into a single format, maybe even a compressed one; finish designing and upgrading my animation systems and put hardware skinning in place; finish abstracting out the effect system so I can use my DX10 rendering components; debug some DX9 code with a custom texure that wasn't rendering correctly; abstract out the Network interfaces, add some Windows networking components, and hook up some tools to take advantage of it; create the UI (to use on the above projects), and setup debugging tools and other creation tools; finish abstracting the threading interfaces, and start taking advantage of them for main systems; port my multi-threaded load balancing server to Warp; add procedural texture generation; setup the game scene manager, and try to hook up my ray tracer to it;   setup scene graphs and other techniques for improving rendering speeds; add a system to handle pre/post processing and saving and indexing buffers, in case effects need to share data so data isn't being rendered twice carelessly; etc.

So, there's a lot of research and development I want to do, as this is an educational endeavor and I love learning new things.  Something I've seen a need for, is a bit buffer for the manipulation of bits; I've already started writing one for my huffman coding exercise, though I think if I put it into my engine I'll want to rewrite some things.  I also want to look into various techniques for compression, though also even writing a float class that's not just 32 bits, perhaps 24 or even 16 bits; I just have to look more into the storage format and see how much precision I lose by doing this.


 

FARSCAPE! Frelll this is an awesome show! ;D

On that note, my girlfriend Beck has mentioned the possibility of us working on a Farscape fan game.  Turns out there has already been a Farscape game, but from what I gather it sucked.  Here's a vid you can check out of the old game: Farscape: The Game gameplay video And here's a page with some reviews: Amazon. Doesn't seem like the game did very well, or was any good at least.  From briefly thinking about it, I'd model the game after Mass Effect or Knights of the Old Republic.  After talking about it a little, I figured the player shouldn't be able to play an existing character; the player would get to follow a new character, an addition to Moya.  I think I want the game to play out like a Shooter RPG, and leveling up a character and customizing them doesn't make much sense to me on an already developed character.

Anyway, making a Farscape fan game is merely an idea at this point, if not one to help drive the development of my engine.  But, if you have comments concerning this "project," please feel free to drop me a line.

[Disclaimer] I'm a fairly new Farscape fan, and still haven't seen all seasons.

[Disclaimer : All benchmarks were done in debug mode on an i7 920 system with no compiler optimizations]

After browsing some cool C++ util functions today on StackOverflow, one of the cool util functions was for trimming strings, so I became intrigued and decided to compare them against my own, as they used some cool C++ std library tricks that I've never seen before. After doing benchmark tests, I was excited to find my own implementation appeared to blow his out of the water. After 1,000,000 tests, his averaged about 27 microseconds, while mine at first averaged less than 5 microseconds. After tweaking mine a bit, my trim_trailingWhitespace function averaged close to 4 microseconds after averaging 1,000,000 samples. Also to note, his function works directly on the original string, while mine returns a new copy; so it's even more impressive.

Here's another benchmark using 1,000,000 samples.
Using the following string: "          "
His: 37.88 microseconds
Mine: 4.03 microseconds

Benchmark 3 using the same # of samples as before.
Using the following string: "  The world ends with you!   "
His: 30.37 microseconds
Mine: 6.26 microseconds

The reason for this post, is because I was excited to find out my implementation is extremely fast, and I felt like sharing it with the world to see if it's possible to do even better! I'm still thinking of ways to improve my functions, but please let me know if you can best me in any way, I'm here to learn!


The only header you should need is the following, with the proper using statements too of course:

#include <iostream>

using std::basic_string;

This is the trim function used by my trim_trailingWhitespace

template<typename CharType>
static basic_string<CharType> trim(const basic_string<CharType>& str, size_t index, size_t len)
{
	size_t length = str.size();
	if(index >= length)
	{
		return basic_string<CharType>();
	}

	length -= index;
	length = length > len ? len : length;

	return str.substr(index, length);
}

And this is my function to trim the whitespace at the end of the string:

template<typename CharType>
static basic_string<CharType> trim_trailingWhitespace(const basic_string<CharType>& str)
{
	size_t length = str.size();
	if(length == 0)
	{
		return str;
	}

	register size_t index = length - 1;

	while(' ' == str[index])
	{
		if(index != 0)
		{
			--index;
		}
		else
		{
			return basic_string<CharType>();
		}
	}

	return trim(str, 0, ++index);
}

You'll notice I'm using some funky template stuff here, and basic_string; this will allow you to use whatever kind of string encoding you want, 1Byte ASCII characters (string), or 2Byte unicode characters (wstring), or whatever. And the beauty of it is, if you pass in the proper string type, like string or wstring, you don't need to define the template parameters; your compiler will automatically fill them in for you so you only just need to call the function name without worrying about the template details!

I haven't gotten a chance to rewrite my trim_leadingWhitespace function, so that will be coming soon; and yes, I will rename these once I decide upon a better name.


After doing some further research I stumbled across this implementation.  I realized my above comparison to the first algorithm wasn't entirely fair as the implementation wasn't even competitive, even though it worked in-place.  So, here's the source for an actually efficient implementation of rear trimming white space:

void rtrim(string& str, const locale& loc)
{
  string::size_type pos = str.size();
  while (pos > 0 && isspace(str[pos - 1], loc)) pos--;
  str.erase(pos);
}

By replacing the isspace with ' ' == you can make this function much faster, though obviously this works with our locale, and may be different across other languages. Another possible reason this isn't as fast as it could be is because of the str[pos - 1], he's doing an extra calculation per loop besides the pos--. His solution gets around the problem of using an unsigned int (size_t) that mine originally had, but lucky for me my rewrite made mine even more efficient because of this trick he had to do.

And here's the details on isspace. I think my check works fine for both string and wstring and the like; if not, please let me know.  [Edit] You could pass the locale space/seperator in as a parameter to the function if that's an issue.

As the above solution works in place, I decided to tweak my original function to work in place on a string, and am excited to say that it beats out this obviously improved implementation.  Here's my new in-place implementation:

template<typename CharType>
static void trim_trailingWhitespace(basic_string<CharType>& str)
{
	size_t length = str.size();
	if(length == 0)
	{
		return;
	}

	register size_t index = length - 1;

	while(' ' == str[index])
	{
		if(index != 0)
		{
			--index;
		}
		else
		{
			str.clear();
			return;
		}
	}
	str.erase(++index);
}

So, my implementation provides shortcuts for an empty string, and for the case the entire string contains spaces (where you see str.clear()). It also provides an interesting way to loop through the string compared to the other implementation, allowing mine to be a bit quicker, probably because I only have to use str[index] (besides the above mentioned shortcuts).

Benchmark 1:
String: "      "
His: 2.97 microseconds
His + my tweak: 2.68 microseconds
Mine:2.54 microseconds

Benchmark 2:
String: "  The world ends with you!   "
His: 3.93 microseconds
His + my tweak: 3.68 microseconds
Mine: 3.65 microseconds

As noted at the header, the above tests were done in debug mode with no optimizations.  If you turn on optimizations you'll notice the two algorithms at the bottom here are neck and neck, it doesn't really matter what you use.  Heck, if you look at the algorithm from StackOverflow that's not nearly as efficient in debug, suddenly becomes nearly comparable.  Though, it's still nice to have a code that runs fast in debug too; but it does raise the question whether it was worth the time to do this research; as they say, don't optimize until you have to.  It's been a nice educational endeavor so far, so I don't really care if it might be considered wasted time, as I've learned more than a thing or two.  Thoughts?

And here's the link to the StackOverflow page of useful C++ utilities: Most Useful C++ Utils.

Here I sit, among fellow Game Design and Development (GDD) students in the GDD Computer Lab, my last quarter at Rochester Institute of Technology. There are so many things I want to do, and only so much time to do it; there's so much research I would love to do, but I'd have to sacrifice too much of my personal life, besides I'm not being paid to do it yet anyway. So, I've come to further realize, I think I would love to be paid to do research in the Video Game programming, related to graphics, user tools, etc. etc. There are A LOT of things I could do with user tools alone, especially when it comes to graphics, and it's something I'll be doing a bit of during this quarter so I can get a platform-independent Gadget System (UI and Application system) working!

I'm actually a little sad I haven't posted to my blog more, as there's much I want to share with the world, and I would love it for people to see I'm bursting with ideas and helpful thoughts.  I have knowledge I want to share with the world, to help make it easier for people like me to get started and break into developing video games!  So, I'll have to start tackling this more.  I have a Matrix Tutorial/post I plan on releasing, it'll be about using them in games, not necessarily implementation; as from a programmers perspective, you don't need to know about the implementation to use it, as long as you understand it.  There is soo much math behind all that goes into video games, and it would take a long time to get a grasp and derive every single thing that goes behind it all.

Right now I'm working on some utility functions, setting up a INI file for loading, saving, and editing INI files.  From there, I plan on setting up a Settings class where you can setup automatic loading from the INI file; I was tossing around the idea of being able to monitor an INI file in realtime so if you make a change to it your settings will load them up, which in response will throw events and re-apply the settings to your current game.  This seemed like a powerful debugging feature, though obviously should be a configurable option.

I think I may make a post on tools ideas, or at least make a post on the gadget system I'll be working on.  One of the tools I thought would be neat would be to use a networked mouse or keyboard, which in reality is more useful for consoles, but I thought still could be a powerful feature.  I know I can't wait to add networking features to my engine, I want to be able to use FTP or something like it for streaming files, either for transferring levels mid-game for user content, distributed processing, or what have you.  I also thought it would be neat to pull in files from the web as well, though I'm not yet sure if it's entirely necessary yet; granted, I haven't thought about this in a while.  I pretty much plan on using gadgets for managing everything that I can in the engine, to make it as easy as possible to work with, so you can tweak things in realtime with the utmost control.

This'll be short for now, as it seems I've come down with a cold, and I need to work on getting some rest and trying to knock this sickness out cold. My first day, I'll be attending the Advanced Visual Affects with DirectX 11 Summit, which runs from 10am to 6pm. The second day, I'll presumably be attending the AI Summit, which also runs from 10am to 6pm. I've never been to GDC before, so I'm not sure if one usually stays at one of these for the whole time or not.

I should also ideally be doing some networking, however, perhaps that's better saved for later in the week when I'm hopefully better from my cold. So if that's what I plan on doing, then maybe I'll work on finishing my inverse kinematics code so I have some cool stuff to show off. XD

Anyway, I'll certainly be excited to meet some new people who are also passionate about game programming; if you're in the area, please feel free to drop me a line! Also, feel free to email be to try to more quickly get in contact at: leetNightshade [at] gmail [dot] com Emails to this account, as long as they're not flagged as spam, should trigger a notification on my phone. Look forward to meeting you guys! :D

So if you're somewhat familiar with C++ you know you can't easily implement a nice generic delegate that works for both static classes and member functions of all classes.  However, with some research and thought, you will realize it's not as hard as you think!

First, I would like to share this article that inspired me and caused me to gain hope in that delegates are possible in a nice flexible way!  Here it is, on: Code Project.

Okay, let's first think about this, we want a delegate to hide away the C++ syntax so we can call any kind of function, pass in certain parameters and get something back.  To make this flexible, it makes sense to have the base delegate class be a template, so you can define what types you want to use.  So here is the base class, which I'll call IDelegate, as in Interface Delegate.

// Interface for a Delegate class, for dispatching a lookup function call.
// R is the return type
// P is the parameter type
template <typename R,typename P>
class IDelegate
{
public:
virtual ~IDelegate(){}

virtual R Invoke(P) = 0;
};

You could also just as easily use an operator overload instead of Invoke:

virtual R operator()(P) = 0;

Now we just need to worry about creating a subclass so we can use these Delegates! So, we'll start with the Static Delegate since it'll be the simplest to create. To create a Static Delegate, we'll need a StaticDelegate class that accepts a static function pointer, and that's all it needs. So we have that below:

// This class is for attaching a Static Function Pointer to an IDelegate
// R is the return type
// P is the parameter type
template <typename R,typename P>
class StaticDelegate<typename R,typename P>
	: public IDelegate<R,P>
{
	typedef R (*funcPtr)(P);

protected:
	funcPtr _funcPtr;

public:
	StaticDelegate(funcPtr functionPointer)
		: _funcPtr( functionPointer )
	{
	}

	R Invoke(P param)
	{
		return _funcPtr(param);
	}
};

For those of you who don't know, this is a Static Function Pointer:

typedef R (*funcPtr)(P);

And also in case you didn't know, you can in fact define functions with parenthesis around the name, it is valid syntax.

Okay, so what we have here is really simple to use:

void PrintInt(int num)
{
	std::cout << num << endl;
}
typdef StaticDelegate<void,int> SDelegate;

IDelegate<void,int> delegate = SDelegate(&PrintInt);

I do encourage you to use typedefs to make your life easier, this becomes more obvious why you might want to do that when you're working with Class Member Function Pointers. In an event system, to be as flexible as possible, I do suggest trying to stick with one type of delegate.

Okay, the above shows you what you need to do to get a Static Function working with an IDelegate, now we need to get something to encapsulate a Member Function Pointer. For lack of a better name, I'll be using Type Delegate, as you do have to specify a class type that the member function belongs to.

// This class is for attaching a Member Function Pointer to an IDelegate
// R is the return type
// T is the Class of this Member Function Pointer
// P is the parameter type
template <typename R,typename T,typename P>
class TypeDelegate
	: public IDelegate<R,P>
{
	typedef R (T::*funcPtr)(P);// this is a function pointer definition
protected:
	funcPtr _funcPtr;
	T& _objPtr;

public:
	TypeDelegate(T& objPtr, funcPtr functionPointer)
		: _objPtr( objPtr )
		, _funcPtr( functionPointer )
	{
	}

	R Invoke(P param)
	{
		return (_objPtr.*_funcPtr)(param);
	}
};

Okay, so to create a TypeDelegate you need to pass in an object of the class you specified, and a function pointer to the class. So you can try this:

class Object1
{
public:
	typedef TypeDelegate<void,PhysicsObject,Object_Event::ENUM> TDelegate;

	Object1(){}

	void CatchEvent(Object_Event::ENUM eventID)
	{
		//...
	}
};
//  Somewhere in your code...
Object1 obj1 = Object1();

IDelegate delegate = TDelegate(&obj1,&Object1::CatchEvent);

//or inside of obj1:
delegate = TDelegate(*this,&Object1::CatchEvent);

Again, please feel free to use typedefs as it'll leave you with less code to type. I also suggest using this one system for all your delegate needs, no matter if you need parameters or not. I think this system is beautiful as it is because it's so simple, flexible, and it's not hard to tell what it does and didn't require a mess to get working like I thought might have to happen. If you want to use this type of delegate with no params, you can define an empty class like this:

// use as a Parameter type instead of void inside of IDelegate, as you'll get a compiler error
class Void
{
public:
	Void(){}
};

Yes, as I indicated in the comment, if you try to use "void" as the parameter type for the IDelegate sub classes, you will get a compiler error. So, as an alternative, use "Void", and pass in Void() as the args for the delegate; or, just use a "void*" and set it to NULL I guess (or a Void* or whatever you want); just make it obvious to functions using the delegate know that it's a void type.

So, as I suggested for keeping the delegate system simple, when you want to use multiple parameters, just use a struct with them defined. One reason I prefer this: if you didn't use a single struct, you'd have to expect every function variable to be properly named to know what it does. In this case, if you're using a struct, the variables names are what you define them to be, so this will help for documentation purposes when someone wants to find out what it does, they just need to look in one place: the struct definition.

 

[UPDATE:]
Source Files: C++ Delegates.

Archive