Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Supporting #Include (And Other C Preprocessor Directives)
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#1
Supporting #Include (And Other C Preprocessor Directives)

Introduction
Somebody mentioned a few weeks ago about how it would be useful to be able to split a single script file into many reusable parts, and then just link them together using something like #includes. I had been wanting something that could do this too for my own projects.

I had initially considered use of the import statement, however I couldn't get this to work. The C Pre-processor happens to provide the support that was being looked for, however the were still the issue of making it usable.

Setting up
In the below ZIP-File a copy of MCPP is included as the pre-processor. I have also written a batch script which will call the pre-processor with the appropriate arguments as well as a display error messages & log them into a text file. Zip File Download:

http://dl.dropbox.com/u/64805489/HpsPreProcessFixed.zip

The next thing to do is set up notepad++ to use the batch file and MCPP. Extract the contents of the zip file to a safe place (For example in a new folder in the amnesia directory). Open up notepad++ and go into the "run" menu and click "run" (or press F5). Into this dialogue box put the following:
[FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps
Replace [FOLDER] with the folder the batch file is in. For example:
C:\Program Files (x86)\Amnesia\HPS_PREPROCESSOR\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps

it is recommended that you then click save and bind the command to something like F6 - otherwise you will have to enter this every time you start notepad++.

Warning: Do not press "run" (or F6 if you bound it) on a script file which ends in ".hps"! This will wipe the script file!!! Give your script files which use the pre-processor a different extension (E.g .phps or .lhps).

Usage
The files that exist before pre-processing will have to have a different extension to the one after pre-processing. The simplest way to do this is to call your script files something like "level.phps" so that the pre-processor writes "level.hps". Consider the following test code:
//level.phps//
#include "inclusion_test.phps"

void OnEnter()
{
   AddDebugMessage("File 1",false);
}

//inclusion_test.phps//
void OnStart()
{
  AddDebugMessage("File 2",false);
}

Running the script from test.phps (F6 if you followed the instructions above) should create "test.hps":
void OnStart()
{
AddDebugMessage("File 2",false);
}  

void OnEnter()
{
AddDebugMessage("File 1",false);
}
Which is what the game will see from test.map and run. When you distribute your custom stories only this exported file is required. Obviously, since we are now using a C pre-processor there is a whole host of other things you can do too.

Recommended Extra Installation Step
You may notice that stuff like #include isn't color coded - and that your new script files ".phps" aren't automatically recognised as HPS files! I Have updated the notepad++ files to fix this (Note that these are updated versions of the overhauled notepad++ files, which provide a fixed function list, folding regions and a new color scheme).

Download: http://www.mediafire.com/?yx2nb2zdgdswg4e

Installation (Steps 1->4 are optional but recommended):
  1. Close notepad++
  2. Go to where you installed notepad (Probably C:\Program Files\Notepad++ or C:\Program Files (X86)\Notepad++\)
  3. Go to the folder "Plugins" Then to the folder "APIs"
  4. Copy across the downloaded version of "hps.xml" into this folder. If you a prompted to overwrite, say yes.
  5. Start notepad++
  6. Go into view-> User-Defined Dialogue
  7. On the drop-down box, if there is the option to select "HPS", select it and and click "Remove"
  8. Click import, and import "UserDefinedDialogue.xml"

You will now a fixed functions list for amnesia (Adds missing functions & keywords, removes non-existing ones), as well as a new color scheme, folding regions (//+ //- /** **/ //Begin //End) etc. ".hps, .phps, .lhps" are now detected, and "#..." are coloured correctly.
(This post was last modified: 05-07-2012, 02:45 AM by Apjjm.)
12-22-2011, 11:59 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Supporting #Include (And Other C Preprocessor Directives)

Hmm, i think i can get this to work for Geany too. I'll post back later after i've messed around with this.

Tutorials: From Noob to Pro
12-23-2011, 12:22 AM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#3
RE: Supporting #Include (And Other C Preprocessor Directives)

Ooooh this will be fun Smile

Nice work figuring this out. Can't wait to put it to use!

(This post was last modified: 12-24-2011, 04:09 PM by palistov.)
12-24-2011, 04:04 PM
Find
Cranky Old Man Offline
Posting Freak

Posts: 986
Threads: 20
Joined: Apr 2012
Reputation: 38
#4
RE: Supporting #Include (And Other C Preprocessor Directives)

(12-23-2011, 12:22 AM)Your Computer Wrote: Hmm, i think i can get this to work for Geany too. I'll post back later after i've messed around with this.
I'm looking to run even ONE .map through a .hps file in Geany. This looks close to what I want, but the whole "wiping your hps file" is discouraging me.
It would be nice to just be able to click a button to test my hps.
(Having Amnesia running all the time during the day, for the occational re-building of scripts in-game, is probably distracting.)

Edit: I'm thinking something like this for an Execute:
"C:\Programs\Amnesia - The Dark Descent\redist\Amnesia.exe" "%p\%e.map"
Would that work?


Noob scripting tutorial: From Noob to Pro

(This post was last modified: 05-03-2012, 02:50 AM by Cranky Old Man.)
05-03-2012, 02:36 AM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#5
RE: Supporting #Include (And Other C Preprocessor Directives)

The "wiping" of the .hps file was just a an issue with the primitive batch file I was using to perform the pre-processing with the MCPP tool. This tool isn't necessary if you already have a C/C++ compiler setup. E.g. In geany i can just use the following in Build->Set Build commands:
cpp -P "%f" "%e.hps"
To pre-process my HPS files and I just make sure I use a different extension for those I wish to pre-process - but you could easily get around this issue by appending something to the output file name so that the writing-to-the-currently-open-file issue doesn't occur.
(This post was last modified: 05-03-2012, 02:50 AM by Apjjm.)
05-03-2012, 02:49 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Supporting #Include (And Other C Preprocessor Directives)

(05-03-2012, 02:36 AM)Cranky Old Man Wrote: I'm looking to run even ONE .map through a .hps file in Geany. This looks close to what I want, but the whole "wiping your hps file" is discouraging me.
It would be nice to just be able to click a button to test my hps.
(Having Amnesia running all the time during the day, for the occational re-building of scripts in-game, is probably distracting.)

Edit: I'm thinking something like this for an Execute:
"C:\Programs\Amnesia - The Dark Descent\redist\Amnesia.exe" "%p\%e.map"
Would that work?

You'd be better off writing a PHP or Python script that takes in the path of the map file and edits the user_settings.cfg file and then launches Amnesia. Then in Geany you can set the execute command under the build commands to launch the script. http://www.geany.org/manual/current/#sub...irectories

Tutorials: From Noob to Pro
05-03-2012, 02:55 AM
Website Find
Cranky Old Man Offline
Posting Freak

Posts: 986
Threads: 20
Joined: Apr 2012
Reputation: 38
#7
RE: Supporting #Include (And Other C Preprocessor Directives)

(05-03-2012, 02:55 AM)Your Computer Wrote: You'd be better off writing a PHP or Python script that takes in the path of the map file and edits the user_settings.cfg file and then launches Amnesia. Then in Geany you can set the execute command under the build commands to launch the script. http://www.geany.org/manual/current/#sub...irectories
I considered going so far as to write my own main_init.cfg in the hps directory, but if it's going to take learning Python or PHP to get it to work, I'm just going to remove the build icons from the Geany toolbar and forget about it.


Noob scripting tutorial: From Noob to Pro

(This post was last modified: 05-03-2012, 03:05 AM by Cranky Old Man.)
05-03-2012, 03:05 AM
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#8
RE: Supporting #Include (And Other C Preprocessor Directives)

Oh mother of god this is amazing. Is this not part of the wiki or something? Because I've never seen this before, and I've made sure to do some snooping around on the wiki just so I didn't miss things like this. D:

EDIT: Is there a way to separate the input directory from the output directory? (ie I want to output my hps files in a folder named "postprocess" rather than just filling my current folder with a bunch of hps and phps files)

Neither changing the filepath in the %MCPP% "%2" "%3" -C -P -W0 2> %ERRF% command ( "\postprocess\%3" ) or the changing input argument for the bat file ( \postprocess\$(NAME_PART).hps ) work. (though if one doesn't work I don't really see why the other would, but I tried them both anyways >_< )

(This post was last modified: 05-04-2012, 10:00 AM by Homicide13.)
05-04-2012, 07:59 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#9
RE: Supporting #Include (And Other C Preprocessor Directives)

(05-04-2012, 07:59 AM)Homicide13 Wrote: EDIT: Is there a way to separate the input directory from the output directory? (ie I want to output my hps files in a folder named "postprocess" rather than just filling my current folder with a bunch of hps and phps files)

Have you tried? (the dot tends to be important):
[FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) .\postprocess\$(NAME_PART).hps

Tutorials: From Noob to Pro
(This post was last modified: 05-04-2012, 10:51 AM by Your Computer.)
05-04-2012, 10:46 AM
Website Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#10
RE: Supporting #Include (And Other C Preprocessor Directives)

(05-04-2012, 10:46 AM)Your Computer Wrote: Have you tried? (the dot tends to be important):
[FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) .\postprocess\$(NAME_PART).hps
Nope, same problem. Sad

05-04-2012, 11:37 AM
Find




Users browsing this thread: 1 Guest(s)