Multi_Slot_Example Code

Documentation, usage tips and configuration guides for Titan Two scripts and bytecodes published by the community users.

Re: Multi_Slot_Example Code

Postby Scachi » Sat Jul 28, 2018 1:43 pm

I think you would need one byte per character so if you want to store "Hawthornes Field-Forged Shotgun" you need 32 bytes+1 to limit the length, you could use any byteoffset from 0..127 that is not in use already.
The easiest way is to print out the name from within the data_slot.gpc when you writing the data to pmem to not waste so much pmem bytespace just for showing the name as the data_slot has direct access to the names.
Adding those lines to the data_script.gpc in the init section should print the name:

Code: Select all
printf("Data block name:");
    printf(TriWeaponName[triRecoilmode]);



About the TRILIMIT, it is not working like I thought it would, it also messes up the "char *TriWeaponName" when trying to print out the name at position 4
I thought the GPC compiler would spit out a failure if one of the arrays has not the exact matching number of "TRILIMIT".
So if you add something and forget to add a value to every one of the entries in data_slot.gph you will get some random numbers invalid data or reset the T2 with an access outside of the TRILIMIT.

But that is not working at all, probably it is my fault of not knowing how that works.
So remove the TRILIMIT from the data_script.gph for now:
data_slot.gph:
Code: Select all
 
char *TriWeaponName[] = {"Power Weapon 0: AR-Disabled","Power Weapon 1: Hawthornes Field-Forged Shotgun","Power Weapon 2: Gunnoras Axt","Power Weapon 3: Undefined","Power Weapon 4: Undefined","Power Weapon 5: Undefined"};
const fix32 triyRecoilvalue[] = {0.0,45.0,45.0,0.0,0.0};
const fix32 trixRecoilvalue[] = {0.0,0.0,0.0,0.0,0.0};
const bool triRapidfiremodevalue[] = {0,1,0,0,0};
const uint16 triShotHoldTimeValue[] = {0,334,0,0,0};
const uint16 triShotWaitTimeValue[] = {0,334,0,0,0};
const uint16 triWeaponReloadTimeValue[] = {2500,2500,2500,2500,2500};
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Multi_Slot_Example Code

Postby monty34 » Sun Jul 29, 2018 7:14 am

Thanks so much :smile0517:

I`ll adapt this to the three weapon slots for D2.

One more question, if i want to have a starting config (e.g. TriRcoilmode = 1 for Hawthorne`s Shotgun) do i only have to change inside the share.gph

Code: Select all
 
uint8 triRecoilmode=0;


or both
Code: Select all
 
uint8 triRecoilmode=0;
uint8 triRecoilmodeCur=0;
 


or is there another location to define the preset?
User avatar
monty34
Command Sergeant Major
Command Sergeant Major
 
Posts: 165
Joined: Wed Jun 28, 2017 7:25 pm

Re: Multi_Slot_Example Code

Postby Scachi » Sun Jul 29, 2018 8:39 am

At the moment the starting config is the last used config.

Changing triRecoilmode or triRecoilmodeCur isn't changing anything.
It is only used for tracking the L2+dpad inout and check if a different slot got selected than it is already loaded.

This is in main slot scripts init :
Code: Select all
pmem_read(PO_trm,&triRecoilmode); // read the last triRecoilmode used
  triRecoilmodeCur = triRecoilmode;

triRecoilmode gets set to the last data loaded, the same with triRecoilmodeCur.

Setting a "default" is not possible by changing any variable value set by init.
The init gets always executed when changing from main->data->main
The script doesn't know when it is started the first time or when it was commanded just load a user selected data slot it would go into an endless slot cycle.

What we can do is track the T2 systemtime and if the systemtime is less than it was when the script was active the last time, reset the time tracking and load the default.
The T2 systemtime resets after powercylce/t2reset or "after 49 days, 17 hours, 2 minutes, 47 seconds and 295 milli-seconds." according to the documentations.

Or use a specific button combo to load your default data.

This uses the tracking of the T2 system_time for checking if the default slot should be loaded (you can select the default slot via the Interactive Configuration).
Save as main_slot.gpc:
Code: Select all
#pragma METAINFO("main slot", 1, 0, "Scachi")
 
#include "share.gph"
 
/*** IC
<cfgdesc>
[Main Script]
collapsible= 1
shortdesc     = Main Scripts Settings
control   = info
 
[Default Data Block]
shortdesc = Select the default Data Block to load fater a powercycle/start of T2
byteoffset= 126
bitsize        = 8
control        = spinbox
default        = 0
minimum        = 0
maximum        = 255
step            = 1
 
 
[Data Memory Slot]
shortdesc = Select the Memory Slot where the DATA script is stored!
byteoffset= 127
bitsize        = 8
control        = combobox
default        = 0
item            = Select one !
item            = 1
item            = 2
item            = 3
item            = 4
item            = 5
item            = 6
item            = 7
item            = 8
item            = 9
 
[Last Loaded Data]
shortdesc = Shows the last loaded Data or Data to load
byteoffset= 0
bitsize        = 8
control        = spinbox
default        = 0
minimum        = 0
maximum        = 255
step            = 1
 
[Last Systemtime Run]
shortdesc = Shows the last system_time when the script has run to load the default slot after a powercycle
byteoffset= 122
bitsize        = 32
control        = spinbox
default        = 0
minimum        = 0
maximum        = 4294967295
step            = 1
 
 
</cfgdesc>
***/

 
uint32 timeT2 = system_time();
uint32 timeLast;
uint8  defaultData;
 
 
init {
  pmem_load()// current slot
 
  pmem_read(127,&DataSlot); // to now the slot where the data is stored
  if (DataSlot == 0) {
    printf("Main: You have to select the memory slot where the DATA script is at!");
    ColorLEDVM('R',200,200,-1);
  }
 
  // uint8 triRecoilmode; // in share.gph
  pmem_read(PO_trm,&triRecoilmode); // read the last triRecoilmode used
 
  // check for T2 reset/powercycle to load default data block
  pmem_read(122,&timeLast);     // read the last time a slot was loaded
  pmem_read(126,&defaultData); // read the default data block to load
  defaultData=clamp(defaultData,0,TRILIMIT); // limit to valid range
  if ( timeT2 < timeLast ) {
    pmem_write(0,defaultData);
    pmem_write(122,system_time()); // update the last data block load time for tracking T2 reset/powercycle
    pmem_save();
    printf("Main: Scripts last load time %d indicates a powercycle, now commanding Data slot %d to load data block %d",timeLast, DataSlot,defaultData);
    mslot_load(DataSlot);
  }
 
  // load the current data block from pmem
  triRecoilmodeCur = triRecoilmode;
  printf("Main: Reading the data block %d at init",triRecoilmode);
  PowerDataLoad();
  printf("Main: Ready");
}
 
void PowerDataLoad() {
                                          // byteoffset 0   uint8 triRecoilmode
  pmem_read(PO_tyr,&triyRecoil);          // byteoffset +4  fix32 triyRecoil
  pmem_read(PO_txr,&trixRecoil);          // byteoffset +4  fix32 trixRecoil
  pmem_read(PO_trf,&triRapidFireMode);    // byteoffset +1  bool triRapidFireMode;
  pmem_read(PO_tsh,&triShotHoldTime);     // byteoffset +2  uint16 triShotHoldTime,
  pmem_read(PO_tsw,&triShotWaitTime);     // byteoffset +2  uint16 triShotWaitTime
  pmem_read(PO_twr,&triWeaponReloadTime); // byteoffset +2  uint16 triWeaponReloadTime
                                          // byteoffset 127 uint8 DataSlot location
  printf("triyRecoil %f", triyRecoil);
  printf("trixRecoil %f", trixRecoil);
 
  printf("triRapidFireMode %d", triRapidFireMode);
 
  printf("triShotHoldTime %d", triShotHoldTime);
  printf("triShotWaitTime %d", triShotWaitTime);
 
  printf("triWeaponReloadTime %d", triWeaponReloadTime);
 
}
 
main {
  // L2 + DPAD_LEFT decrease / right increase triRecoilmode to load
  if ( get_val(BUTTON_8) && event_active(BUTTON_12) && triRecoilmode>0 ) triRecoilmode--;
  if ( get_val(BUTTON_8) && event_active(BUTTON_13) ) triRecoilmode++;
  if ( event_active(BUTTON_12) || event_active(BUTTON_13) )  {
    triRecoilmode=clamp(triRecoilmode,0,TRILIMIT);
    printf("Slot Nr: %d",triRecoilmode);
  }
 
  // press R3 to load the data
  if ( event_active(BUTTON_6) && triRecoilmode != triRecoilmodeCur && DataSlot != 0 ) {
    pmem_write(0,triRecoilmode);
    pmem_write(122,system_time()); // update the last data block load time for tracking T2 reset/powercycle
    pmem_save();
    printf("Main: Now switching to Data slot %d to load data block %d",DataSlot,triRecoilmode);
    mslot_load(DataSlot);
  }
}
 
 
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Multi_Slot_Example Code

Postby monty34 » Mon Jul 30, 2018 4:00 am

Thanks for your great help, i'll give this a try :joia:
User avatar
monty34
Command Sergeant Major
Command Sergeant Major
 
Posts: 165
Joined: Wed Jun 28, 2017 7:25 pm

Re: Multi_Slot_Example Code

Postby monty34 » Thu Aug 02, 2018 3:34 pm

Good progress so far, what is the max byte offset which i can use? 127 for the slot?
User avatar
monty34
Command Sergeant Major
Command Sergeant Major
 
Posts: 165
Joined: Wed Jun 28, 2017 7:25 pm

Re: Multi_Slot_Example Code

Postby Scachi » Thu Aug 02, 2018 3:43 pm

monty34 wrote:Good progress so far, what is the max byte offset which i can use? 127 for the slot?

Yes, 0..127
but you can't use the last one,127, with anything bigger than 8 bit as you will then use 127+ :wink:

You can use my program to check the pmem usage of interactive configuration of a script.
It does some error checking too. The PMEM-Usage button shows a table with the 0..127 bytes and used bits.
https://github.com/J2Kbr/GtunerIV/issue ... -409021681

Another option would be to use the config control to have buttons in the Interactive Configuration for presets.
Clicking on them would adjust the settings then, but that can't be used without the IC or running GTuner at the moment.
Code: Select all
[Weapon Config]
group     = true
control        = config
item      = Default (primary):#0B:0000000005DC000BB800
item      = Default (secondary):#15:0000000005DC000BB800
item      = House Striker (primary): #0B:0000000F0578190A5A28
item      = House Striker (secondary): #15:0000000F0578190A5A28
 


ic-config-control.png
ic-config-control.png (8.91 KiB) Viewed 2451 times
Last edited by Scachi on Thu Aug 02, 2018 4:02 pm, edited 1 time in total.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Multi_Slot_Example Code

Postby bonefisher » Thu Aug 02, 2018 3:59 pm

Scachi wrote:
monty34 wrote:Good progress so far, what is the max byte offset which i can use? 127 for the slot?

Yes, 0..127
but you can't use the last one,127, with anything bigger than 8 bit as you will then use 127+ :wink:

You can use my program to check the pmem usage of interactive configuration of a script.
It does some error checking too. The PMEM-Usage button shows a table with the 0..127 bytes and used bits.
https://github.com/J2Kbr/GtunerIV/issue ... -409021681

Another option would be to use the config control to have buttons in the Interactive Configuration for presets.
Clicking on them would adjust the settings then, but that can't be used without the IC or running GTuner and the moment.
Code: Select all
[Weapon Config]
group     = true
control        = config
item      = Default (primary):#0B:0000000005DC000BB800
item      = Default (secondary):#15:0000000005DC000BB800
item      = House Striker (primary): #0B:0000000F0578190A5A28
item      = House Striker (secondary): #15:0000000F0578190A5A28
 


ic-config-control.png

This would be the answer when the app comes out for quick settings! :smile0517:
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Multi_Slot_Example Code

Postby monty34 » Fri Aug 03, 2018 5:25 am

Finished my script now, running fine so far. Only point is the high cpu load during the memory slot switches which cause an annoying noise. Any idea how this can be fixed?
User avatar
monty34
Command Sergeant Major
Command Sergeant Major
 
Posts: 165
Joined: Wed Jun 28, 2017 7:25 pm

Re: Multi_Slot_Example Code

Postby Scachi » Fri Aug 03, 2018 5:40 am

If the cpu load doesn't reach 100% or above I wouldn't care about that.. what is "high" for you ? ..
but I never recognized my T2 causing some sort of noise on high cpu load.

Using the code I posted for you (some posts ago) I can't recognized high cpu load, only a small pause of the cpu load value when the code switches the slot forth and back to load the data.

Can you send me your code for testing ? I'll pm you my mail address.

// edit
It looks like the pmem_write and slot change are causing a short very high cpu usage that creates the headset (connected to controller) sound issue.
I also experienced something similar using only pmem_write (without slot change) to often by accident. The whole T2 lagged, I could notice it in-game as the controller input wasn't send to the console fast enough anymore.
I have added an github issue for that already:
https://github.com/J2Kbr/TitanTwo/issues/155
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Multi_Slot_Example Code

Postby UK_Wildcats » Sat Aug 04, 2018 5:13 pm

Great example. Thank you for taking the time to share this.
User avatar
UK_Wildcats
Brigadier General
Brigadier General
 
Posts: 2243
Joined: Thu Jan 08, 2015 6:53 pm

Previous

Return to User's Script Documentation

Who is online

Users browsing this forum: No registered users and 58 guests