Revising FOCS Include directive

For what's not in 'Top Priority Game Design'. Post your ideas, visions, suggestions for the game, rules, modifications, etc.

Moderator: Oberlus

Post Reply
Message
Author
dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Revising FOCS Include directive

#1 Post by dbenage-cx »

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.
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.

Post Reply