DSS news

I’ve been working hard on my game lately. Lots of new features are in, namely: save game, technology tree, ship ability tree,  galaxy view and freighter transport route. But I also worked on a major graphics revamp as you can see here:


There are new gfx assets like space stations, warp gate and some ships. New gfx feature like alpha support(yeah that one should have been done way long ago),  engine trail and sky box.

Next up are : Ai and combat

Also I finally decided how to name my game but I’m not going to say just yet. From now on I’ll refer to it as DSS.

Todo

I’m very forgetful so I tend to write every little things down for later reference. Over the years I learned to coop with that trait of mine in many ways. I even bought an Ipod touch so i can take notes and pictures of what i should remember. So it’s not surprising that my todo list got quite big and exhaustive over the ~4 months I’ve been working on my new project. But the problem is that I add a new item in the list and just never go back to do it. I just forget about my todo list… I’m that forgetful. So as an incentive to do my todo list items, I did this:

#define JOIN_STR2__(x) #x
#define JOIN_STR1__(x) JOIN_STR2__(x)
#define LOC_TODO __FILE__ "("JOIN_STR1__(__LINE__)") : Warning _TODO: "
#define TODO(x) __pragma(message(LOC_TODO x))

So when I think about something i should remember and actually do later I just write it down at the right place in the code like this:

TODO("Make this real");

So when I compile I get a warning message that look like:
Warning 110 warning _TODO: Make this real c:\p4\test\test.cpp 96

I like getting a warning message, It reminds me that I should fix it while I’m working in the same file.

Early screen shots

It’s been a while now since I’ve started working on my new project. There was a lot of foundation work that needed to be done, mostly in the graphics department. And I’m happy with what I have accomplished so far knowing that I have pretty much started this project from scratch 2 months ago.

Although I still need to do some graphic features, I am willing to share a few early screen shots.




The game concept comes from an idea I had long ago but never had time to develop. Hopefully, things will evolve like I planned.
The game has no name yet. I usually refer to it as “E.W.”. Although I have most of the production pipeline in place, it is still in pre-production.
It involves spaceships, a lot of pew pew and will put the emphasis on strategy.
I wish I could say more, but I’ld rather keep some surprises for later. 🙂

Edge iteration

If you’ve done some computational geometry on polygons you probably have encountered this little problem: iteration on polygon edges.
Common solution is using the modulo operator:

void processPolygon(unsigned int n){
    for(unsigned int i = 0; i < n; ++i){
        precessEdge(i, (i+1)%n);
    }
}

Which yields on VS C++ 2010 with optimization on:

01061027  lea         esi,[ecx+1]  
0106102A  xor         edx,edx  
0106102C  mov         eax,esi  
0106102E  div         eax,edi  
01061030  mov         eax,edx  
01061032  call        precessEdge (1061000h)  
01061037  mov         ecx,esi  
01061039  cmp         ecx,edi  
0106103B  jb          processPolygon+7 (1061027h)  
0106103D  pop         esi  

The div is the result of the modulo, we don’t want it.
There is a better and faster way to do this:

void processPolygon2(unsigned int n){
    for(unsigned int i = n-1,j=0 ; j < n; i=j, ++j){
        precessEdge(i, j);
    }
}

this one yields:

01061050  mov         eax,esi  
01061052  call        precessEdge (1061000h)  
01061057  mov         ecx,esi  
01061059  inc         esi  
0106105A  cmp         esi,edi  
0106105C  jb          processPolygon2+10h (1061050h)  
0106105E  pop         esi  

No div, i.e. faster.

This is known as the Barrett Enumeration

unsigned -1

Are you the kind of programmer that uses unsigned variable index and genuinely needs to set it to FFs or -1 for special purpose?
Stuff like:

class Foo{
	/*snip snip*/
	unsigned int mIndex;
	void bar(){
		mIndex = unsigned int(-1);
	}
	void monkey(){
		if(mIndex == unsigned int(-1)){
			/* snip snip */
		}
	}
};

If you are like me you probably like to make thing generic without warning while involving as less code as possible.
So here is a thing for you.

class CMax{
public:
	template< class T >
	operator T()const{return (std::numeric_limits<T>::max)();}
};

template< class T >
T MaxOf(const T& a){ return CMax(); }

template< class T >
bool IsMax(const T& a){ return a == MaxOf(a); }

Use them like so:

unsigned int ui = CMax();
unsigned short us = CMax();
if( IsMax(ui) ){
	/* snip snip */
}
if( IsMax(us) ){
	/* snip snip */
}

Better see?


class Foo{
	/*snip snip*/
	unsigned int mIndex;
	void bar(){
		mIndex = CMax();
	}
	void monkey(){
		if( IsMax(mIndex)){
			/* snip snip */
		}
	}
};

Changing the type of mIndex will not affect the rest of the code. One less thing to think about.