Author Topic: [Request] Possibility to stop PHP_EACH loop (edit: not needed)  (Read 1658 times)

Offline K4thos

  • Planewalker
  • *****
  • Posts: 110
As per title I'd like to have an option to stop PHP_EACH loop when it's not longer needed. This is mainly for performance and installation time sake. I'd like to use PHP_EACH loops with hundreds of arguments inside tables (with tons of offsets checked in hundreds of files), so letting the loop go on up to the end is wasteful considering the match could be found in one of first entries.

Hopefully my intuition that PHP_EACH is more performance friendly than calling hundreds of variables one by one to compare their values is correct, as that what I'm planning to change in my mods.

Thanks in advance.
« Last Edit: October 25, 2015, 10:25:06 AM by K4thos »

Offline The Imp

  • Planewalker
  • *****
  • Posts: 288
  • Gender: Male
Re: [Request] Possibility to stop PHP_EACH loop
« Reply #1 on: October 25, 2015, 03:15:59 AM »
As per title I'd like to have an option to stop PHP_EACH loop 
Is there a specific reason you can't use say, game_is and other things to determine the action to be taken(more specifically) and then just do it with those files ?

Offline K4thos

  • Planewalker
  • *****
  • Posts: 110
Re: [Request] Possibility to stop PHP_EACH loop
« Reply #2 on: October 25, 2015, 06:36:18 AM »
not sure how that would help. What I need it for (among other things) is EET on the fly resource conversion code. For example 484 area names need to be checked in BG:EE resources. Currently I'm using rather awkward way to check these references:

1. First variables are set like this:
Code: [Select]
OUTER_SPRINT resref_are_source1 "AR0002"
//same for all other areas with following index numbers
OUTER_SPRINT resref_are_dest1 "BG0002"
//same for all other areas with following index numbers
OUTER_SET resref_are_total = 484

2. Than macros loops through all resources in BG:EE to update offsets (or modify scripts and dialogues) on the fly, for example like this (another patch macro called by the one that checks resource resref offsets):
Code: [Select]
READ_ASCII off "resref"
PATCH_IF (NOT ~%resref%~ STR_EQ ~~) BEGIN
SPRINT resref_total ~resref_%res%_total~
SPRINT index_total EVAL ~%%resref_total%%~
FOR (i=1; i<="%index_total%"; i=i+1) BEGIN
SPRINT name_source ~resref_%res%_source%i%~
SPRINT name_dest ~resref_%res%_dest%i%~
SPRINT resref_index_source EVAL ~%%name_source%%~
SPRINT resref_index_dest EVAL ~%%name_dest%%~
PATCH_IF ("%resref%" STR_EQ "%resref_index_source%") BEGIN
SET updated = 1
WRITE_ASCIIE off "%resref_index_dest%" #8
SPRINT str ~Patching %SOURCE_FILESPEC%: %resref_index_source% => %resref_index_dest% -~
SPRINTF str ~%s %x~ ("%str%" off)
PATCH_PRINT ~%str%~
SET i = index_total
END
END
END

When you need to check hundreds of offsets, add to this checks for many types of files, do similar loops also though dialogues and scripts via REPLACE_EVALUATE and so forth than it takes a lot of time. I'm thinking about converting existing code to use PHP_EACH loops to find matches, which I think will be faster than calling and evaluating variables one by one. But to make it even faster it would be great if I could stop that PHP_EACH loop once match is found (like I'm doing in above example code with SET i = index_total)
« Last Edit: October 25, 2015, 06:45:08 AM by K4thos »

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: [Request] Possibility to stop PHP_EACH loop
« Reply #3 on: October 25, 2015, 09:49:41 AM »
What you're really looking for is an efficient way to fetch the remapped resource name for a given resource.  I'd recommend using an associative array.

1. Create your array.
Code: [Select]
ACTION_DEFINE_ASSOCIATIVE_ARRAY remapped_areas BEGIN
  AR0002 => BG0002
  AR0003 => BG0003
  // etc.
END

2. Lookup the value in the array.
Code: [Select]
READ_ASCII off "resref"
TO_UPPER resref
PATCH_IF (VARIABLE_IS_SET $remapped_areas(~%resref%~)) BEGIN
  TEXT_SPRINT new_resref $remapped_areas(~%resref%~)
  WRITE_ASCIIE off ~%new_resref%~ #8

  SET updated = 1
  TEXT_SPRINT str ~Patching %SOURCE_FILESPEC%: %resref% => %new_resref% -~
  SPRINTF str ~%s %x~ ("%str%" off)
  PATCH_PRINT ~%str%~
END

Offline K4thos

  • Planewalker
  • *****
  • Posts: 110
Re: [Request] Possibility to stop PHP_EACH loop
« Reply #4 on: October 25, 2015, 10:23:27 AM »
Code: [Select]
What you're really looking for is an efficient way to fetch the remapped resource name for a given resource.
true

Code: [Select]
PATCH_IF (VARIABLE_IS_SET $remapped_areas(~%resref%~)) BEGIN
  TEXT_SPRINT new_resref $remapped_areas(~%resref%~)
simple and brilliant. This change should optimize the installation time significantly. Thanks for the example code. The PHP_EACH suggestion can be ignored as this implementation sounds much better.
« Last Edit: October 25, 2015, 01:14:03 PM by K4thos »

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: