![]() |
Supporting #Include (And Other C Preprocessor Directives) - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Articles (https://www.frictionalgames.com/forum/forum-40.html) +---- Thread: Supporting #Include (And Other C Preprocessor Directives) (/thread-12023.html) Pages:
1
2
|
Supporting #Include (And Other C Preprocessor Directives) - Apjjm - 12-22-2011 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: Code: [FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) $(NAME_PART).hps Code: 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: Code: //level.phps// Running the script from test.phps (F6 if you followed the instructions above) should create "test.hps": Code: void OnStart() 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):
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. RE: Supporting #Include (And Other C Preprocessor Directives) - Your Computer - 12-23-2011 Hmm, i think i can get this to work for Geany too. I'll post back later after i've messed around with this. RE: Supporting #Include (And Other C Preprocessor Directives) - palistov - 12-24-2011 Ooooh this will be fun ![]() Nice work figuring this out. Can't wait to put it to use! RE: Supporting #Include (And Other C Preprocessor Directives) - Cranky Old Man - 05-03-2012 (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: Code: "C:\Programs\Amnesia - The Dark Descent\redist\Amnesia.exe" "%p\%e.map" RE: Supporting #Include (And Other C Preprocessor Directives) - Apjjm - 05-03-2012 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: Code: cpp -P "%f" "%e.hps" RE: Supporting #Include (And Other C Preprocessor Directives) - Your Computer - 05-03-2012 (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. 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/#substitutions-in-commands-and-working-directories RE: Supporting #Include (And Other C Preprocessor Directives) - Cranky Old Man - 05-03-2012 (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/#substitutions-in-commands-and-working-directoriesI 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. RE: Supporting #Include (And Other C Preprocessor Directives) - Homicide13 - 05-04-2012 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 >_< ) RE: Supporting #Include (And Other C Preprocessor Directives) - Your Computer - 05-04-2012 (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): Code: [FOLDER]\PreProcess.bat $(CURRENT_DIRECTORY) $(FILE_NAME) .\postprocess\$(NAME_PART).hps RE: Supporting #Include (And Other C Preprocessor Directives) - Homicide13 - 05-04-2012 (05-04-2012, 10:46 AM)Your Computer Wrote: Have you tried? (the dot tends to be important):Nope, same problem. ![]() |