Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#11571) What is the target_type for?
Home

[Freeciv-Dev] Re: (PR#11571) What is the target_type for?

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#11571) What is the target_type for?
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Fri, 1 Apr 2005 10:47:20 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11571 >

On Wed, 30 Mar 2005, Jason Short wrote:

> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=11571 >
>
> Here's an updated patch.  Vasco, I don't see why this should be
> particularly slower.

I did it for several reasons. One was speed, but the main reason was
clarity. Originally the code was like your patch is doing now. But then I
noticed it made no sense to a casual read, hence it was harder to debug.
Later I even considered doing the argument passing with a struct to make
the concept more clear. Perhaps I should have.

The idea is that you have to pass the target object to that function. The
target class is a superclass of several different target types.

Elaborating;

* For TARGET_PLAYER the target object must have a player pointer.
* For TARGET_CITY the target object must have a player and city pointer.
  I could have just passed the city pointer and got the player pointer
  from that when it was necessary, but I didn't because it made the code
  shorter. This was probably a mistake.
* For TARGET_BUILDING the target object must have the player, city
  pointers and a building id.

* For TARGET_WORLD the target object must have a pointer to the world
  state. Most of it is stored in the 'game' struct, so the pointer is
  known implicitly and I optimize it away by not passing it to begin with.

If the code was done in a nice and clean high level design, the class
hierarchy would be thus:

targetClass
 |
 |- worldClass
 |- playerClass
 |- cityClass
 |- buildingClass

The world object would contain player objects, a player object would be a
container for city objects, and a city object would be a container for
building objects. Each object would have a way of finding out which
container he was in, if he was in one.

But our code is not structured like this. It is structured differently for
several reasons, one of which is memory use. So we have to hack around
it.

This problem is intrinsically well fit for the OO programming paradigm, so
I tried to make that more or less explicit in the code. It seems I failed.

---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa








[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#11571) What is the target_type for?, Vasco Alexandre da Silva Costa <=