FreeOrion
http://www.freeorion.org/forum/

Revising FOCS Include directive
http://www.freeorion.org/forum/viewtopic.php?f=6&t=10011
Page 1 of 1

Author:  dbenage-cx [ Mon Mar 21, 2016 9:08 pm ]
Post subject:  Revising FOCS Include directive

Currently a lot of unused macros are included when parsing certain script files.
These files should include any macros they need, without concern of what those files might also include.

e.g.
An entry uses macros A_1 and B_1. It includes files A.macros and B.macros
A.macros has a couple of macros that use macro B_2, and should include B.macros
Other entries also use A_1 or B_1, but not always both.

For more concrete examples:
species.macros is a good example of macros that rely on each other.
Most of the tech entries are examples of loading a much larger list of macros for a single macro (TECH_COST_MULTIPLIER).

I've created a PR that initially does the following:
* Limit the #include statement to only include a file once.
* Replace any base path (a leading '/') with default/ (specifically, GetResourceDir() ).
* Allow a leading asterisk wildcard in the filename

I omitted adding a separate #include_once and limited the other options to keep from a need to parse the files multiple times.
If there is a method to have both #include and #include_once, without needing to pre-process, the logic escaped me.

The base path was redirected since absolute paths should never be used, and any traversal beyond default/ would potentially fail if the resource directory is changed.

The wildcard is probably the most controversial bit. I wanted to give a method for including a specific batch of files, but a separate directive leads me to need multiple passes.
Full wildcard support would add more complexity for what I felt would be seldom used. e.g. How many times would #include "asteroid??_small.txt" be needed, a sub-directory could just as easily be created for those files and use #include "asteroids/*_small.txt" if a batch inclusion was desired.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/