OSP Kit Optimisation Simplified KeyConfig Presentation

Users who are viewing this thread

Ikaguia

Grandmaster Knight
WBWF&SNW
yeah, that's it, thanks

and you forgot a "_" in the first line, it should be ":upper_limit" instead of ":upperlimit"
 

Caba`drin

Count
M&BWBWF&SNWVC
Dunde, thanks much for this! It's extraordinarily handy and easy to adjust.

Quick question...after spending some time with the code and running a couple of (admittedly brief) tests, I'm wondering why you chose to use a new troop for the key data rather than utilizing one of the three temp_array troops? Is there something I'm missing there? Changing the constant key_config_data to trp_temp_array_a, for instance, only requires one additional call of "script_init_key_config" somewhere in the first few lines of the configuration presentation. (I've tested for possible errors by re-setting the temp array's slots after each visit to the presentation, and nothing appears to be affected. The globals get set appropriately, etc.)
 

Lav

Sergeant Knight at Arms
M&BWB
Caba`drin said:
Quick question...after spending some time with the code and running a couple of (admittedly brief) tests, I'm wondering why you chose to use a new troop for the key data rather than utilizing one of the three temp_array troops? Is there something I'm missing there? Changing the constant key_config_data to trp_temp_array_a, for instance, only requires one additional call of "script_init_key_config".
Those temp arrays are used by the Native code in various places and must never be used for persistent storage.

Unless you like a little unpredictability in your scripts. :smile:

Dunde, fantastic work, I was planning to write something like this myself but now I can lazily drink some beer instead! :smile:
 

Caba`drin

Count
M&BWBWF&SNWVC
Lav said:
Those temp arrays are used by the Native code in various places and must never be used for persistent storage.

Unless you like a little unpredictability in your scripts. :smile:
I'm aware of that...I've used them numerous times myself.
But my point is, from what I can see and from messing with the code, this key_config_data faux-troop is not needed for persistent storage, either. All the persistent storage needed is in the global variables and the scripts that are generated at compile-time.
 

Lav

Sergeant Knight at Arms
M&BWB
Caba`drin said:
Lav said:
Those temp arrays are used by the Native code in various places and must never be used for persistent storage.

Unless you like a little unpredictability in your scripts. :smile:
I'm aware of that...I've used them numerous times myself.
And now suppose someone else did too, taking great care not to screw up with slots used by Native, but having no idea what slots are used by you. And then imagine yet another person trying to use both scripts in his project... :roll:

Caba`drin said:
But my point is, from what I can see and from messing with the code, this key_config_data faux-troop is not needed for persistent storage, either. All the persistent storage needed is in the global variables and the scripts that are generated at compile-time.
Probably. But then I wouldn't be able to understand the code, not with my nearly-zero knowledge of Python. :smile:

Anyway, code performance and memory usage in dunde's code may be slightly worse compared to Python-generated code using globals, but it is considerably more readable and moddable. So I rather like it the way it is. :smile:
 

dunde

Count
WB
Updated OP for more simplified code. Now, the part of code that need to be modified for new keys is only at module_constants.py.
 

Caba`drin

Count
M&BWBWF&SNWVC
Just was updating my use of this system to your current code--thanks for the update, the centralization to module_constants makes sense--and noted two things that need fixing in the OP

First, now that all_keys_list is a list of tuples, rather than hex values, this line needs to specify to take the first item in the tuple for each list entry
Code:
def set_key_config():
   key_config = []
   for i in xrange(len(keys_list)):
      key_config.append((troop_set_slot, key_config_data, slot_default_keys_begin+i, keys_list[i][1]))      
   for i in xrange(len(all_keys_list)):
      key_config.append((troop_set_slot, key_config_data, slot_key_defs_begin+i, all_keys_list[i][0])) ##THIS LINE
   return key_config[:] 

And, second, you refer to pre-defined "str_*" strings throughout the presentation, rather than quick strings as before, but these strings aren't defined in your module_strings bit.

Might also be useful to just add a simple utility "get key name" script to your scripts, so folks don't need to puzzle it out or read the rest of the thread to find it:
Code:
 ("str_store_key_name", 
   [
    (store_script_param_1, ":str_reg"), 
    (store_script_param_2, ":key"),
    (assign, ":end", number_of_all_keys),
    (try_for_range, ":i", 0, ":end"),
      (store_add, ":key_offset", slot_key_defs_begin, ":i"),
      (troop_slot_eq, key_config_data,  ":key_offset", ":key"),
      (store_add, ":strings_offset", key_label_begin, ":i"),          
      (assign, ":end", 0),
    (try_end),
    (try_begin),
      (eq, ":end", 0),
      (neq, ":key", 0xff),
      (str_store_string, ":str_reg", ":strings_offset"),
    (else_try),
      (str_store_string, ":str_reg", "str_blank_string"),
    (try_end),
   ]),
 

shokkueibu

Knight
M&BWB
Hmm. This isn't working for me and I know it did before with the old code.
I even applied it to a clean module system to be sure and the same happens: the keys don't have default values and I can't bind new ones. Pressing default or reset doesn't work either.
 

Caba`drin

Count
M&BWBWF&SNWVC
shokkueibu said:
Hmm. This isn't working for me and I know it did before with the old code.
I even applied it to a clean module system to be sure and the same happens: the keys don't have default values and I can't bind new ones. Pressing default or reset doesn't work either.
Did you make the changes noted in my post above yours? There's a small bit missing in the Python dunde has in the OP.
 

shokkueibu

Knight
M&BWB
Thanks dunde. You forgot about this though:
Caba`drin said:
Code:
def set_key_config():
   key_config = []
   for i in xrange(len(keys_list)):
      key_config.append((troop_set_slot, key_config_data, slot_default_keys_begin+i, keys_list[i][1]))      
   for i in xrange(len(all_keys_list)):
      key_config.append((troop_set_slot, key_config_data, slot_key_defs_begin+i, all_keys_list[i][0])) ##THIS LINE
   return key_config[:] 


Finally figured out my problem. Since my mod is multiplayer the keys weren't getting initialized properly.

Multiplayer changes:​

Move this line:
Code:
(call_script, "script_init_all_keys"),
from script_game_start to script_game_quick_start.

Change the key config presentation header as follows:
Code:
# Key configuration
  ("key_config", prsntf_manual_end_only, 0, [  #Change the header to this
    (ti_on_presentation_load, [
      (presentation_set_duration, 999999),
      (set_fixed_point_multiplier, 1000),
      (create_mesh_overlay, reg0, "mesh_load_window"), #ADD THIS
 
Top Bottom