BGforgeNet/Fallout2_Unofficial_Patch

Optimization

Closed this issue · 3 comments

It'd be great to enable optimization. The only problem is stringification.
(It'd be also great to enable short-circuit evaluation, but I have no idea how to search for places where it might cause problems).

Here's a list of suspicious procedure calls:

$ for proc in $(grep -R 'call .*;' scripts_src/  | grep -v 'call Node' | sed 's|.*call ||' | sed 's|;.*||' | sed 's|(.*||' | sort | uniq); do echo -n "$proc: "; grep -iR "procedure $proc" scripts_src | wc -l; done | grep -v '"):' |  grep ': 0'
cbFunc: 0
check_Num_10: 0
check_Num_4: 0
check_Num_5: 0
check_Num_6: 0
check_Num_8: 0
check_Num_9: 0
def_process: 0
over:: 0
guard: 0
node_string: 0
old_critter_p_proc: 0
old_map_enter_p_proc: 0
PARTY_NODE_X: 0
pop_critter: 0
remove_all_items_pid: 0
return_node: 0
stored_node: 0
the_node: 0
x: 0

And the corresponding files. Need to check these.

scripts_src/DEN/DCVIC.SSL:474:   call PARTY_NODE_X;
scripts_src/GENERIC/ZCCRPDEL.SSL:1558:   call check_Num_4;
scripts_src/GENERIC/ZCCRPDEL.SSL:1559:   call check_Num_5;
scripts_src/GENERIC/ZCCRPDEL.SSL:1560:   call check_Num_6;
scripts_src/GENERIC/ZCCRPDEL.SSL:1561:   call check_Num_8;
scripts_src/GENERIC/ZCCRPDEL.SSL:1562:   call check_Num_9;
scripts_src/GENERIC/ZCCRPDEL.SSL:1563:   call check_Num_10;
scripts_src/HEADERS/COMMAND.H:466:                                                            call x;                                \
scripts_src/HEADERS/COMMAND.H:470:                                                      end else call x
scripts_src/HEADERS/DEFINE.H:974:   call old_map_enter_p_proc;
scripts_src/HEADERS/DEFINE.H:982:   else call old_critter_p_proc;
scripts_src/HEADERS/NEWRENO.H:1220:// call guards
scripts_src/HEADERS/NEWRENO.H:1869:   call stored_node;
scripts_src/HEADERS/NEWRENO.H:1873:   call stored_node;
scripts_src/HEADERS/NEWRENO.H:1877:   call stored_node;
scripts_src/HEADERS/NEWRENO.H:1881:   call stored_node;
scripts_src/HEADERS/NEWRENO.H:1885:   call stored_node;
scripts_src/HEADERS/sfall/lib.inven.h:145:            call remove_all_items_pid(critter, obj_pid(item));
scripts_src/KLAMATH/KCTORR.SSL:179:   //call pop_critter;
scripts_src/MAIN/NHMYRON.SSL:603:            call PARTY_NODE_X;
scripts_src/MAIN/QHPRZRCH.SSL:356:   //call guards
scripts_src/MODOC/MCDAVIN.SSL:300:               call PARTY_NODE_X;
scripts_src/MODOC/MCMIRIA.SSL:339:                  call PARTY_NODE_X;
scripts_src/NAVARRO/CCDRILL.SSL:274:            call the_node;                                                          \
scripts_src/NCR/WAYPNT.SSL:143:            call cbFunc(target_tile);
scripts_src/NEWRENO/NCANGBIS.SSL:286:      debug_msg("sending call guard to bismen");
scripts_src/NEWRENO/NCELDRID.SSL:534:   call return_node;
scripts_src/NEWRENO/NCELDRID.SSL:550:   call return_node;
scripts_src/NEWRENO/NCJIMMYJ.SSL:312:   call return_node;
scripts_src/NEWRENO/NCJULES.SSL:356:   call node_string;
scripts_src/NEWRENO/NCLABISH.SSL:316:      debug_msg("sending call guard to bismen");
scripts_src/NEWRENO/NCRENESC.SSL:317:   call return_node;
scripts_src/NEWRENO/NCTRAY.SSL:169:                                             call x;                                               \
scripts_src/NEWRENO/NCTRAY.SSL:384:   call return_node;
scripts_src/NEWRENO/NIWRIGRV.SSL:50:            call def_process;                                  \
scripts_src/VAULT13/WAYPNT.SSL:143:            call cbFunc(target_tile);

The short-circuit evaluation should only be enabled when the conditional execution in the script is written in its logic. For vanilla/RP scripts it would require even larger scale of rewrites than stringification, so I wouldn't recommend doing that. Also I don't think it has apparent benefit like optimization (smaller script filesize).

Well, one benefit of short-circuit it that logs don't get polluted as much with faulty conditions. Anyway, until there's a systematic way to search for possible errors, no point in trying to do that.

I went about optimization in a more straightforward way - just compiled everything with optimization, decompiled back and searched for missing functions:

dcjoey.ssl: forced_node
mcvegeir.ssl: forced_node
ncangbis.ssl: forced_node
ncbigjes.ssl: stored_node
ncbisgrd.ssl: forced_node
ncbishop.ssl: stored_node
nccorbro.ssl: forced_node
nccorbro.ssl: stored_node
nceldrid.ssl: return_node
ncjimmyj.ssl: return_node
ncjules.ssl: node_string
nclabish.ssl: forced_node
ncorvill.ssl: stored_node
ncrenesc.ssl: return_node
ncsalvat.ssl: stored_node
ncstulit.ssl: forced_node
ncstulit.ssl: stored_node
nctray.ssl: return_node
ocariel.ssl: cbFunc
ocjimmy.ssl: cbFunc
sccarkid.ssl: cbFunc

Other than cbFunc, everything appears to be already fixed. I stringified it as well, I think now we can try optimization.

Probably can enable short-circuit in global scripts...