Multi_Slot_Example Code
20 posts
• Page 2 of 2 • 1, 2
Re: Multi_Slot_Example Code
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:
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:
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};
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Multi_Slot_Example Code
Thanks so much
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
or both
or is there another location to define the preset?
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?
-
monty34 - Command Sergeant Major
- Posts: 165
- Joined: Wed Jun 28, 2017 7:25 pm
Re: Multi_Slot_Example Code
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 :
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:
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);
}
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Multi_Slot_Example Code
Thanks for your great help, i'll give this a try
-
monty34 - Command Sergeant Major
- Posts: 165
- Joined: Wed Jun 28, 2017 7:25 pm
Re: Multi_Slot_Example Code
Good progress so far, what is the max byte offset which i can use? 127 for the slot?
-
monty34 - Command Sergeant Major
- Posts: 165
- Joined: Wed Jun 28, 2017 7:25 pm
Re: Multi_Slot_Example Code
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+
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
Last edited by Scachi on Thu Aug 02, 2018 4:02 pm, edited 1 time in total.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Multi_Slot_Example Code
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+
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
This would be the answer when the app comes out for quick settings!
- bonefisher
- Lieutenant General
- Posts: 5413
- Joined: Thu Jan 29, 2015 10:49 am
Re: Multi_Slot_Example Code
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?
-
monty34 - Command Sergeant Major
- Posts: 165
- Joined: Wed Jun 28, 2017 7:25 pm
Re: Multi_Slot_Example Code
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
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
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Multi_Slot_Example Code
Great example. Thank you for taking the time to share this.
-
UK_Wildcats - Brigadier General
- Posts: 2243
- Joined: Thu Jan 08, 2015 6:53 pm
20 posts
• Page 2 of 2 • 1, 2
Return to User's Script Documentation
Who is online
Users browsing this forum: No registered users and 58 guests