Archive for the ‘C++’ Category

Models and more

Wednesday, March 19th, 2008
acomplia online cialis cost cialis online pharmacy viagra for order cheapest accutane cheap cialis viagra uk purchase viagra online where to order cialis purchase viagra no rx cheap price cialis accutane sale find discount cialis find discount viagra online generic cialis cheap cialis in uk buy cialis from canada acomplia online stores viagra for sale lowest price for cialis buy viagra on line price of viagra drug viagra online purchase 25mg viagra viagra cost viagra cheap price purchase cialis online buy viagra lowest price pharmacy viagra best price for viagra purchase accutane cialis pills tablet viagra cheap acomplia online order viagra overnight delivery buy cialis overnight delivery viagra in bangkok cialis bangkok purchase cialis no rx cheap cialis no rx purchase acomplia online cheap generic cialis cheapest cialis viagra in us cialis in bangkok order viagra online best price viagra viagra malaysia where to buy acomplia cheapest cialis prices cialis cheap buying cialis order generic viagra viagra order buying generic viagra no prescription cialis buy accutane buy viagra no rx buy cheapest viagra buy acomplia cheap order viagra no prescription required buy viagra in us 20mg cialis order viagra in us acomplia cheap buying viagra viagra cheap buy cheap viagra online fda approved viagra cialis information cost of viagra find cheap cialis cialis from canada purchase viagra overnight delivery acomplia discount fda approved cialis viagra rx find no rx cialis viagra discount certified cialis cialis without a prescription accutane acomplia pharmacy cialis overnight shipping viagra australia sale cialis buy sildenafil citrate buy cialis from us online viagra cialis soft acomplia prices buy discount cialis viagra pill viagra prices buy viagra overnight delivery online cialis order cialis cheap online discount viagra overnight delivery viagra online without prescription compare viagra prices online cheapest generic cialis accutane online overnight cialis cheap cialis without prescription buy sildenafil in uk viagra no rx cialis cheap price 50mg viagra buy accutane online erectile dysfunction cheap viagra overnight delivery cheap cialis tablets viagra pharmacy online acomplia without a prescription cheap accutane tablets buy cialis without prescription lowest price acomplia cialis tablet buy generic accutane find cialis without prescription order accutane cheap cialis overnight delivery cialis price cialis from india cialis no rx buy discount cialis online cialis overnight buy acomplia without prescription cialis tablets cheap viagra in usa buy viagra in canada cialis pharmacy online order cialis in us discount cialis 20 mg cialis acomplia online cheap cheapest viagra online cialis prescription order cialis on internet buy sildenafil in spain buy generic cialis cheap cialis in canada viagra tablets accutane without prescription cialis canada buy cheap acomplia online cheap viagra cheap cialis pharmacy find cialis on internet acomplia prescription buy cialis cheap order cheap cialis online find cialis no prescription required viagra overnight delivery buy viagra low price compare cialis prices 25 mg viagra order viagra no rx viagra online buy cialis no rx impotence treatment impotence cure viagra overnight online pharmacy cialis viagra online cheap find cialis online generic cialis online no rx cialis accutane generic cheapest acomplia prices buy viagra online cheap buy viagra internet acomplia no prescription pfizer viagra drug cialis online purchase order discount cialis cialis 10mg best price for cialis cheap viagra from usa find discount viagra cialis pill order viagra without prescription viagra generic purchase viagra without prescription buy acomplia online accutane cheap order viagra from canada cialis online without prescription cheap accutane cialis side effects cialis for sale buy cheap accutane online cialis generic discount cialis without prescription buy viagra from canada buy cialis internet discount viagra no rx viagra without a prescription drug cialis cialis pharmacy buy cialis generic cialis prices discount accutane order cialis no prescription impotence drugs cost viagra acomplia generic buy viagra online impotence medication order cialis from canada buy discount viagra acomplia acomplia pills purchase accutane online pharmacy online buy sildenafil internet buy accutane cheap viagra canada discount cialis online order cialis overnight delivery where to buy viagra cheap accutane online find no rx viagra cheap cialis from uk lowest price for viagra cheap viagra from canada approved cialis pharmacy 10 mg cialis viagra in uk cialis vs viagra cialis internet cheapest viagra prices accutane prescription buy cialis in us low cost cialis cialis buy online pharmacy cialis buying generic cialis purchase cialis overnight delivery buy discount viagra online order no rx viagra acomplia without prescription viagra buy order viagra from us viagra internet find discount cialis online acomplia for sale purchase cialis without prescription cialis drug discount viagra accutane prices buy sildenafil canada viagra in malaysia accutane online stores generic drugs buy viagra generic cialis purchase cialis us viagra medication price of accutane cheap cialis pill viagra no prescription find viagra buy cialis online cheap cheap cialis from canada cheap generic viagra price of cialis sale viagra viagra free sample order viagra order acomplia online where to order viagra viagra approved cialis for order buy sildenafil cheap buy accutane without prescription discount viagra without prescription cheap cialis from usa buy viagra no prescription required cialis discount cheap viagra on internet order generic cialis buying cialis online accutane without a prescription buy cialis lowest price viagra no rx required buy generic viagra online purchase cialis viagra buy drug order cialis without prescription viagra us 10mg cialis cheap acomplia tablets buy sildenafil in canada find viagra without prescription cialis overnight delivery buy viagra cheap cialis cheapest price cialis sale lowest price cialis cheapest generic viagra viagra soft tab no rx viagra cheap cialis no prescription purchase viagra viagra sale viagra india find viagra no prescription required impotence pills cialis 20mg 100 mg viagra buy cheap accutane buy cialis low price compare viagra prices cheapest viagra price impotence cheap viagra tablet tablet cialis order discount viagra viagra overnight shipping order viagra on internet buy cheap cialis online cost cialis buy sildenafil low cost order cialis no rx cheap viagra in uk cialis medication generic viagra cheap buy sildenafil online buy cheapest cialis on line order cialis no prescription required viagra drug buy viagra without prescription buy cialis on internet viagra cheap drug cheap viagra no prescription cheap viagra in canada cheap generic acomplia cheap viagra internet viagra pills cheap cialis in uk order cheap viagra online buy cialis from india cheap viagra no rx cheapest generic viagra online lowest price viagra cheap cialis in usa viagra sales order accutane online buy and purchase sildenafil online online pharmacy viagra viagra in australia certified viagra cialis malaysia viagra cheapest price cialis no rx required buy cheap acomplia buy sildenafil online without a prescription discount viagra online no prescription viagra viagra tablet viagra from india viagra cheap cialis internet order cialis 50 mg viagra buy cialis in canada order discount cialis online cialis no online prescription approved viagra pharmacy cialis soft tab cialis no prescription buy cialis order cheap cialis 100mg viagra order cialis online compare cialis prices online cheap viagra tablets cheap price viagra cialis cheap viagra online find viagra on internet cialis 20 mg viagra side effects cheap acomplia cialis without rx cialis without prescription cialis 10 mg viagra bangkok purchase acomplia cialis free delivery cheapest viagra buy viagra cialis india viagra vendors low cost viagra order viagra cheap online cheap viagra from uk generic accutane cheapest accutane prices viagra vs cialis generic acomplia accutane pills buy generic viagra generic viagra online generic viagra accutane discount find viagra online find cialis accutane pharmacy viagra online stores cialis buy order viagra in canada cialis online cheap viagra soft find cheap cialis online cheap viagra without prescription order viagra no prescription buy cheapest cialis order cialis in canada cheapest sildenafil citrate cialis uk cialis free sample cialis online review buy generic acomplia price of acomplia drug viagra generic cialis viagra no online prescription free viagra viagra information buy viagra from us buy viagra on internet cheapest acomplia order acomplia viagra buy online viagra online review where to buy cialis buy cheapest viagra online viagra without rx cialis approved viagra pharmacy order cheap viagra buy cialis online discount cialis no rx cheap viagra pill buy generic cialis online cialis online buy no rx viagra viagra online pharmacy cialis online stores buy cheap cialis buy cheapest cialis online buy cheap viagra accutane for sale cialis in australia buy cheap cialis internet acomplia sale buy viagra us overnight viagra lowest price accutane online accutane online acomplia find cheap viagra online best price cialis buy cheap viagra internet viagra free delivery cheap cialis on internet buy viagra from india cialis rx buying viagra online cheap generic accutane find cheap viagra where to buy accutane cialis australia cheapest cialis online order no rx cialis viagra purchase cialis vendors discount acomplia cialis cheap drug discount cialis overnight delivery cialis sales cialis buy drug cheapest generic cialis online buy cheapest viagra on line cheap cialis online cheap viagra pharmacy accutane online cheap buy acomplia viagra without prescription cheap cialis tablet cheapest cialis price buy no rx cialis cialis in us buy cialis on line free cialis order cialis from us cialis in malaysia accutane no prescription order discount viagra online cost of cialis buy cialis us cialis order viagra from canada viagra prescription buy cialis no prescription required viagra price

I did a small favor for a fellow indie, and he in turn made some new 3-D models for OVM! OVM now sports a UFO model to serve as the Martians’ base, and a laser rifle for Martian crewmen to hold.

I felt the placeholder art I originally had for those two items really detracted from the game’s look, even as placeholders. What a nice improvement. Thanks Thak!

If you’re interested in more of Thak’s work, check out 3dmatter.com or spellcraft.biz. He works fast - he turned out those two models in no time flat.

Progress

These last few weeks I:

  • finished the A.I. personal-view-of-the-world feature
  • started to separate OVM’s pathfinding code into a stand-alone library
  • added new features to meta-C (my homegrown programming language, which OVM is written in)
  • optimized meta-C for speed

I kind of spread myself too thin these last weeks, trying to do all those things simultaneously, and several of them didn’t go as planned. Still, I got some progress done.

A.I. personal view of the world

This is done! The A.I. now makes all important decisions based on a limited, imperfect view of the world. No cheating anymore!

This is a huge milestone, and it’s been a long time coming. I remember putting this feature on my to-do list well over a year ago. At the time I thought to myself, that’s pretty ambitious, I don’t know if I’ll get that feature in. So, I’m definitely happy that it’s actually in!

I still need to do the follow-up work of increasing the A.I.’s exploration ability; without that, as predicted, the A.I. is behaving dumb as dirt.

Pathfinding library

I started pulling out OVM’s pathfinding code for packaging as a sellable product.

Here’s what the main API currently looks like:

   F32 findPath(
      Point2F          bgnPoint,
      RectF            endRect,
      IMap*            map,
      Vector<Point2F>* path,
      ICoster*         coster = NULL,
      F32              range = 0,
      F32              maxCost = FLT_MAX
      );

It’s simply a global function that outputs a vector of way points. Maybe I’ll describe the parameters in a later post. I’m still figuring out how to make the API as user-friendly and flexible as possible, by using C++ templates, etc. Naturally, it’ll also need a friendly TorqueScript interface, too.

There will also be some utility functions and data structures, for things like iterating over the tiles crossed by a ray (useful for smoothing out the final path).

One good thing is, I’ve taken a look at some other free pathfinding packages, and it looks like OVM’s pathfinding does indeed provide features beyond what’s already out there. Got to provide value, to sell a product.

Next up: Squads

I’ve started working on giving OVM a notion of sqauds, i.e. groupings of units.

The more I think about squads, the more issues I see them impacting in the game. For example:

  • making units march in formation
  • reducing the number of calls to pathfinding (and hence reducing CPU demand), via squad flocking
  • reducing network traffic, via squad flocking
  • allowing the A.I. to temporarily subdivide a force to deal with attacks from multiple directions, via a hierarchy of squads (i.e., squads of squads), and then bring those forces back together to resume the squad’s original mission
  • helping the AI manage multiple units sent to do a single job, e.g. when multiple workers go to build a new base
  • allowing units to auto-explore in two’s or three’s, in addition to individually

I thought that was kind of interesting. Originally, I thought of squads as mainly relating to marching in formation. But they seem to touch quite a few other areas, at least from a programming perspective.

Game results screen

Saturday, August 26th, 2006

I’ve started working on the game results screen, which shows player scores and other statistics.

One idea I had for this screen was to include a chat window.  That way players can discuss game results after the game is over.  I’m surprised so few RTSs have a chat feature here.  After all, nearly every first-person shooter game allows chat when a game/round ends.  Torque, included.  And since Torque already has this feature, including it into my results screen is easy.

One thing I’m finding not-so-easy though is programmatically creating the results screen from C++ code.  Torque’s GUI controls are really designed to be instantiated from TorqueScript - and from TorqueScript only.  I haven’t seen a single GUI control class that has a convenient C++ constructor.  I.e., a constructor that takes traditional arguments like position, text, parent window, etc.  In fact, most control classes don’t even have C++ accessor and mutator methods!  You have to set all control attributes TorqueScript-style.  What a nuisance.

That’s one of the problems in general I’ve found with Torque; some functionality is accessible from TorqueScript only, while other functionality is accessible from C++ only.

In other news: do you recognize these two fugitives?

Out Of This World

Catch them in action in a re-release of this gaming classic.

 

Meta-C r0×0rs like…well, it just r0×0rs

Thursday, May 18th, 2006

I mentioned earlier that I’m writing Orcs vs. Martians in a home-brewed programming language, Meta-C. Meta-C gives me a chance to experiment with the design of a programming language, to try to make programming easier.

To me, “easier programming” means

  1. less code is required to implement a particular feature
  2. the code is easier to maintain and refactor as the app evolves

So I made Meta-C to have the same syntax as C++, but modified it to be less verbose, and to require fewer changes when the architecture of the code evolves. (Excuse me for going a bit off-subject about a programming language probably nobody will ever use but me, but I like this stuff : )

Here’s an example that illustrates some of the improvement possible over C++. Orcs vs. Martians has a function that looks for the nearest enemy base. It’s a small function, and it does three fairly common things; it:

  1. iterates over a container (all the entities in the game map)
  2. tests elements of a certain type (”Bases”)
  3. returns the “best” element by some criteria (the nearest base)

Comparing the C++ and the Meta-C implementations of this function is pretty revealing. First, here’s the C++:

01   Base* Base::getBaseToAttack()
02   {
03      Base* ret = NULL;
04      for (set<Entity*>::iterator ent = gMap->getEnts().begin();
05           ent != gMap->getEnts().end();
06           ent++) {
07         Base* base = dynamic_cast<Base*>(*ent);
08         if (base)
09            if (isEnemy(base) && (!ret || distTo(base) < distTo(ret)))
10               ret = base;
11      }
12      return ret;
13   }

Now, here’s the Meta-C:

01   Base* getBaseToAttack()
02   {
03      for gMap.ents,Base*
04         if isEnemy(base) && (!$ || distTo(base) < distTo($))
05            $ = base;
06   }

With Meta-C, there’s much less code! Mostly, because

  1. Meta-C’s “for” keyword natively understands STL containers. When its argument is an STL container, it automatically generates that ugly STL iteration code
  2. “for” also takes an optional element type (”Base*”), when you only want to iterate over elements of that type
  3. The “$” symbol means the return value of the function. If used, Meta-C automatically generates its declaration and a return statement for it in the function
  4. other minor things you can probably pick out

Not only is there less code, Meta-C requires less re-work as the application evolves. For example, if the following changes happened, here’s what the impact would be on the two implementations of the function.

  1. if the type of the container changed, e.g. from a std::set to a std::list, the C++ implementation would need a change to its “for” loop. The Meta-C wouldn’t need any change.
  2. if the function’s return type changed from Base* to something else, the C++ function would need changes in four places. Meta-C would need changes in two places.
  3. if a dedicated “gMap.bases” container was created that contained only bases, and you wanted to iterate over that instead of the “gMap.ents” container that contains all game entities, the C++ function would require several changes: changing the two instances of “gMap->getEnts()” in the for loop to “gMap->getBases()”; deleting the lines doing the dynamic_cast operation and testing its result; and un-indenting the 2nd if statement. Meta-C would only require one change: from “for gMap.ents,Base*” to “for gMap.bases”.

I like this language :)

We now return you to your regularly scheduled blog.

Code metrics

Friday, March 10th, 2006

Code metrics, before and after the TorqueScript-to-C++ conversion:

TorqueScript:  773 lines / 2661 words
C++:          1219 lines / 3750 words

Wow, very impressive. TorqueScript needs only about 2/3rds the code as C++ to implement the same functionality. Very nice. These stats exclude code lines that are blank, comments, or only contain a single curly bracket.

As a side note, strictly speaking, I am actually not writing this game in C++. I’m writing it in my own home-brewed computer language, Meta-C. Meta-C is very C++-like, but is meant to be more concise and easier to write. Meta-C generates C++ code, which can then be compiled in the normal fashion. Here are Meta-C’s code metrics:

Meta-C:        882 lines / 2858 words

Huh, TorqueScript even beats my Meta-C language. My pride is injured -)

Torque and C++

Thursday, March 9th, 2006

Very cool! Orcs vs. Martians is now creating workers, soldiers, and buildings from C++ code. It was exciting to see this work the first time. And both workers and soldiers are now pathfinding (moved that code to a common base class). I still need to move tree creation into C++, and re-hook up the workers’ harvesting behavior.Unfortunately, converting to C++ has made deletion of SimObjects a bit of a challenge. Back when the game logic was in TorqueScript and my objects were all held in SimSets, deletion was easy. Torque magically removes a deleted object from any SimSets that contain it, thus the game logic rarely needs to worry about stale object references. Not so now: my objects are now contained in STL lists, as C++ pointers. And accessing a deleted pointer will bring down the house in a hurry.

Hmm…there are a number of possible approaches here. It’s still possible to use Torque’s SimSets and/or object IDs in C++ code. Presumably the magical deletion can be made to work in C++ too. Also, one can use the SimObjects’ constructors and destructors to automatically add or remove the SimObjects from STL lists. I’ll probably try a combination of both those approaches, and see how it goes.

Converting to C++

Monday, March 6th, 2006

I’ve taken the plunge and started converting Orcs vs. Martians from TorqueScript, to C++. So far, I have C++ classes for Workers, Soldiers, Bases, Walls, Towers, Trees, Players, Races, the game Map, and some base classes for shared functionality. I should be done converting the server-side code today. It’ll be interesting to compare code size before and after the conversion. I’ll post metrics.I like TorqueScript ok, but when writing it I really miss C++’s class declarations. In fact I found myself writing commented C++ class declarations in TorqueScript, so I could remember my data members. I am very data-centric in the way I think and need a programming language that caters to that. Before I write much code for a new app, I usually draw an entity-relationship diagram which is one of those bubble-and-lines diagrams. An ER diagram shows the main objects and their “has-a” relationships to one another, and whether each relationship is 1:1, or 1:N (one-to-many). I love those, they help me see the big picture and remember it later. Based on the ER diagram, I then write the class declarations with one data member for every “has-a” relation.

I also really like to document my classes’ data members. If I know exactly what a data member represents, then later it’s easier to write new code that works on that data member, without introducing bugs. For example, if a data member is a file path, is it absolute or relative? or can it be both? can it be the empty string? if so, what does the empty string mean? If it’s a pointer, can the pointer be NULL? what does NULL mean? I usually document that kind of stuff next to each data member. I find it considerably more helpful to do that, than to document function bodies. In fact, if you ever look at my code, you’ll see heavily-documented data members and lightly-documented function bodies. Most programmers do the opposite, i.e document their functions, but not their data model.

Anyway, to do all that stuff, I need a language that supports explicit class declarations. Hence my decision to switch from TorqueScript to C++. Not to mention that C++ has easier class inheritance, static type checking, and other things.

The conversion itself hasn’t gone as quicky as I thought it would, despite the similar syntax between TorqueScript and C++. I’ve been working about four days to convert ~800 lines of TorqueScript (when I’m done it’ll probably be five days). I think the biggest problem has been that the syntax for accessing data types is very different between the two languages, despite similarities elsewhere. For examples, TorqueScript uses strings for Points and other “structures”, and ints for object handles. C++ uses explicit structs and classes, and pointers. So most of the code that access that data has to be changed. Also, it wasn’t obvious to me how to use TorqueScript’s schedule() function in C++, so I’ve converted its usage to processTick() everywhere. No complaints though, five days isn’t too bad. Be forewarned though, if you ever contemplate converting a large TorqueScript app to C++, it could take longer than you think.