Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12706) Events framework
Home

[Freeciv-Dev] (PR#12706) Events framework

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#12706) Events framework
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Thu, 7 Apr 2005 08:48:16 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This is all about finding a way to get scenario events to work.
Civilization II : Test of Time had it, modpack authors requested it, I
think it is a useful feature.

Rationale:
Using the registry format for this makes little sense. I proposed we use
a pre-existing language (so we do not reinvent the language wheel,
again) and use an interface similar to how the GTK+ event system works.

There is more info on this subject here:
http://freeciv.org/index.php/Events

In my view the language must have the following traits:
1) Forgiving
2) Readable
3) Embeddable inside Freeciv, runs modpack code in source code form.

This is so as many people as possible can make a modpack.

These traits are good to have, but not essential:
5) Byte-compiled at ruleset load
6) Garbage Collected
7) Large user base
8) Fast
9) Small

Lua meets all these requirements. Python has a similar score, but is
more bloated, squeaks on binary link with a GCC warning, is slower for
numeric calculations. On the other hand it has a richer API and is more
suited for writing complex apps. It comes preinstalled on most Linux
distros. But most will not install libpython dev files by default, which
we require. Lua only needs an ANSI C compiler. LISP based languages are
not as readable as either of these two, despite what its proponents
might say.

Both Lua and Python use the MIT License, which is GPL compatible.

I prefer Lua for several reasons, one being that since its standard API
is so limited, no one will try to convert large chunks of mainline code
into Lua. Why is that bad? Because it splits the codebase in islands of
developers, because Freeciv was written precisely because a pre-existing
clone of Civilization was slow precisely because it was all written in
Python, etc. :)

References:
http://www.lua.org/manual/5.0/
http://www.python.org/doc/2.4.1/


Short term plan:

* Commit lua to the freeciv tree, commit the event.diff.gz patch.
  (all the necessary work for this is done, all which remains is commit)

Medium term plan:

* Design and implement custom Freeciv lib for Lua, loosely based on the
Civilization ToT event system info we got from that mod community, plus
considering suggestions and comments from them for which actions they
want to be able to do (there should be a dozen possible actions, tops).
* Commit that.
* Add event support. At first it could be as lame as this:

The places where the events are triggered get to call this little C
function:
emit_event(E_HUT);

This function executes all the Lua callbacks for that event type on the
spot.

On the Lua side, your code would be something like this:

function hutCallback()
-- do some stuff.
end

eventConnect(EHut, hutCallback)


Notes:
GUI editors do not solve the problem alone, you still need a
representation format. GUI editors like the one in Warcraft III are
mostly a kludge to make the programming of events easier which have
their negatives and positives. Most games use code in a simple language,
for understandable reasons.

In case you are interested, I did try Python first. In case someone can
dispel my concerns over it and make a patch of their own, fire away.

If you have other language proposals, preferably with a patch of your
own, fire away.




[Prev in Thread] Current Thread [Next in Thread]