Well, we're getting there... I haven't had much time to work on things lately as I'm trying to finish up my workload before going on hols for a bit.
Nothing very exciting here (and framerate/quality decimated by Youtube). Captains recruit their villages and go for a wander. White captain takes a dislike to Red captain, fight ensues [without the sprites, you have to take my word for it...] ;-) White captain wins the battle. Then takes on Yellow while his army has low hitpoints and loses. Then the two remaining armies have their captains removed to show what happens when the armies disband and the soldiers return home. Very basic, but I'm pleased with how clean the state machine runs at the moment.
I don't want to start doing the fancy graphical stuff for quite a while. I'd rather have the actual game mechanics working and the gameplay completed in this rather dull-looking 2D world than start adding fancy stuff just to justify nice screenshots. So you might want to switch off your RSS feed for a while if you want pretty screenies. :)
I'm particularly looking forward to having arrows, cannonballs that actually follow a trajectory. Originally, they flew across hugging the landscape like low-flying cruise missiles.
Very glad I picked up a copy of Effective STL by Scott Meyers. Didn't answer a question I had about STL so I'll throw it out here (and Google isn't helping either, maybe it's my search query).
Q: If your class has a property (bool IsAlive() is a good example), what is the best way to retrieve an item from a container based on a boolean method that the class contains?
At the moment, a very dull:
container<Agent*>::iterator i=ctr.begin();
while(i!=ctr.end()) {
if(*i->IsAlive()) // do something...
++i;
}
does the trick, but I was hoping that I could do this via the <algorithm> functions like find_if() which (from my own testing with large amounts of loops) perform much better than standard loops.
What you're looking for is called mem_fun. It allows you to call a member function from a pointer in an algorithm like for_each() and find_if().
ReplyDeleteIf you're trying to find the first entry in the list that is alive so that you can perform some operation on it, you'd want to do it like this:
vector::iterator iResult = find_if( ctr.begin(), ctr.end(), mem_fun(&Agent::IsAlive) );
Also, you can write your update loop like this using mem_fun:
for_each( ctr.begin(), ctr.end(), mem_fun(&Agent::Update) );
Assuming, of course, that your update function is called Update() :)
Note the lack of parentheses after the function names in the above code; that's what marks these as functors and not actual functions.
Also, awesome video :) More please.
ReplyDeleteAh, brilliant! (I see what the problem was now)
ReplyDeleteI've recently been using for_each to call functions like Update and Draw in the main loop.
i.e.,
// main draw ...
for_each(m_gameAgents.begin(),m_gameAgents.end(),mem_fun_ref(&Agent::Draw));
// main update ...
for_each(m_gameAgents.begin(),m_gameAgents.end(),mem_fun_ref(&Agent::Update));
However, for the find_if, I was getting compiler errors that were hard to decipher.
Turns out, I just needed to change mem_fun_ref to just mem_fun as you've used in your example.
"find_if" works great now, no longer need that loop. (from what I gather, the advantage is that you're not evaluating it!=ctr.end() every cycle of the loop.
I skipped over a section about ptr_fun, mem_fun and mem_fun_ref that I should read again in more detail.
Glad you like the video! Had to merge 4 different videos together in VirtualDub as Fraps only records 30-second snippets. I should probably buy a licence if I'm going to be using it often. :)
There are actually a lot of free alternatives to Fraps.
ReplyDeletehttp://www.anewmorning.com/2009/01/06/5-free-alternatives-to-fraps/
Great project. To read your page made my day. This game is one of my alltime favourites. Looking forward to testing it one day. As we say:
ReplyDelete"Was lange währt, wird endlich gut"
Wolf