Keeping low profile

March 5th, 2010 by ofer
Posted in Other blogs

Hello everyone reading my blog,

I just wanted to say that I am not sure how often I will update my blog. I have started to work on a new job which I enjoy a lot.
I am going to keep a low profile on game development. I believe I will be back to it sooner or later.

Thank you for reading. :)

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Crossstiches

February 22nd, 2010 by ofer
Posted in Other blogs

Someone showed me her cross stitches today. She said there are millions of website where you can buy cross stitches images and samples.
Some of them are a representation of a photo or a realistic artwork. But some are also more schematic.
I am not sure about the legal issues here, but I would think that the cross stitches samples may be a really good source for pixel art.

What do you think?

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Ground Truth

February 12th, 2010 by ofer
Posted in Other blogs

When you are in a position that you don’t know if your code is the faulty one or the bug is somewhere else. Sometimes you can just use another program that you know is working and use it to verify where the bug is at.

An example. Say you have written code to load a BMP file format. You use your program, but the image has some weird artifacts. Is it a bug in your code? Or is it a corrupted BMP file?
You can simply load the same BMP file with another program such as window’s paint, and see if it loads properly or if paint is having problems with this file as well. If paint loads the BMP file properly, the bug might be in your code.

I have given the BMP file format as an example, but this is true to many other fields where you have some tool you know is working right. It is kind of similar to the Bug negative verification.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Don’t make sense

February 3rd, 2010 by ofer
Posted in Other blogs

Making sense isn’t always good. I was debugging some code and printed some number on the screen. The number had weird initialized values, so I rationalized why these values are not 0 at the beginning.
Bottom line, I just forgot to initialize the debug variable so I had garbage values.

I think it’s a common trait of humans to try rationalize everything. Sometimes they are so convinced at something and the logic behind it, even though it has no basis or it is even something that can’t make sense.

Does it happen to you too?

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Fun with dynamic casting

January 29th, 2010 by ofer
Posted in Coding

Polymorphism allows for different function implementations to be called, depending on values only known at run time. For instance:

class BaseA {
	public:
		virtual void foo(){cout<<"Base";};
};

class A: public BaseA {
	public:
		void foo(){cout<<"Child";};
};

A a;
BaseA & base = a;
base.foo();

Will print “Child”.

“Pair polymorphism” is when you want a specific function implementation to be called based on the run time value of two different instances of a class. For instance in the case of:

class BaseA {
};

class BaseB {
	public:
		virtual void foo (BaseA & a) = 0;
};

class A: public BaseA {
};

class B: public BaseB {
	public:
		void foo (A & a);
};

You would want that somehow “void B::foo (A & a)” will be called. The code I posted does not do this.
There is a way to do this, but it requires for a class to know about the implementation classes. It is not a problem in some cases. However, sometimes you want to have an abstraction layer.
An abstraction layer is a set of classes or interfaces, that have no methods or “don’t know” anything about the classes that implement them. For instance you can have a graphics abstraction layer.
You could implement this layer with DirectX. However, this layer will make it easier to afterwards add an implementation with OpenGL without having to make a lot of changes, even if the game is already completed.

How are we going to have a “pair polymorphism” in this case? One solution is using dynamic casting. You can cast a pointer of a parent class to it’s child class(in case the run time value really points to an instance of that class).
Some code:

class BaseA {
};

class BaseB {
	public:
		virtual void foo (BaseA & a) = 0;
};

class A: public BaseA {
};

class B: public BaseB {
	public:
		void foo (BaseA & a)
		{
			foo2 (dynamic_cast<A &>(a));
		}
		void foo2 (A & a);
};

I was asked by someone how this can be done without dynamic casting, because he doesn’t like dynamic casting. I found a way, but it ain’t pretty, and I honestly can’t find any advantage of using this code instead of just using dynamic casting. But here it is:

class BaseA {
	public:
		virtual void DynamicCast() = 0;
};

class BaseB {
	public:
		virtual void foo (BaseA & base) = 0;
};

class A;

class Caster {
	public:
		A * a;
};

class A: public BaseA {
	public:
		Caster * c;
		void DynamicCast()
		{
			c->a = this;
		}
};

class B: public BaseB {
	public:
		Caster * c;
		void foo (BaseA & base)
		{
			base.DynamicCast();
			foo2 (c->a);
		}
		void foo2 (A & a);
};
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks