2 days ago we had a long talk how we should introduce a pathfinder in an 'extra' package, as I described in a few posts earlier. After some debating we came to the conclusion that there is absolutely no fair way to do that in C++. Although a pathfinder would operate faster in C++, the difference isn't big enough. So we decided to make a library framework in Squirrel, where people can put their general libraries, and an easy way to access them. I just committed exactly that. In the coming days / weeks / months, we will be adding some things we think is useful, under which some queues, but also a basic pathfinder, and more of such tools all AIs will want to use.
Some positive things about this library system: it doesn't force you to use any of them. You can always write your own. It allows multiple implementations of the same thing, like more than one pathfinder. It is portable. It is secure.
Now how does it work? I will write a wiki page about it soon. Basically:
in bin/ai/library there are dirs, 'categories'. In a category there is a dir, the library itself. In that dir is a file called 'library.nut', similar to 'info.nut'. It gives some basic information about the library, and is loaded on OpenTTD startup. The idea is equal to 'info.nut' in all ways, but you don't do: RegisterAI, you do: RegisterLibrary. Easy as pie
Now from your AI you can run:
Code: Select all
import("categorie.name", "LocalName", version);
The LocalName is how you want to class to be called in your script. This is useful, as there will be multiple implementation of the same thing. By changing one line, you can switch between those implementations, without changing everything in your AI. Also, it avoids a lot of name collision, and other problems of that order.
The version part makes sure you talk to library you expect. Say you made your AI for sets.priority_queue version 1, but in the library-dir of a user is version 2. Your AI will now fail to load on his machine, as there might be a mismatch in operations. This is an early problem detection, which hopefully avoids a lot of problems. So, make sure to fill in the right version
I think that sums it up pretty well.. any questions, feel free to ask. Sorry that I had to post this in this topic again, as it is becoming unreadable, but we are trying to get our own NoAI subforum, which hopefully makes this easier on all of us (http://www.tt-forums.net/viewtopic.php?f=21&t=37891)
Ps: if any of you have a library you think should be included as official library (in SVN), please send it to me. Sending in any library for inclusion means you give up the rights of the library, and it becomes GPL copyrighted to OpenTTD.