Script Tidy(is there any benefit in openmw)

General discussion regarding the OpenMW project.
For technical support, please use the Support subforum.
User avatar
Pop000100
Posts: 82
Joined: 18 Aug 2014, 21:17
Location: Loitering around Gnisis.

Script Tidy(is there any benefit in openmw)

Post by Pop000100 »

So script tidy is a plugin by Huskobar that fixes syntax, removes comments, removes spaces, and others.
but is it faster in OpenMW's implemention of morrowind's bytecode

example script in script tidy

Code: Select all

Begin barAssScript

Float timer
Short creepstate
Short DtncCk
Short doorcheck
Short door2check
Short doOnce
Short dayCheck

If ( MenuMode == 1 )
Return
EndIf

If ( doOnce == 1 )
If ( GetJournalIndex "TR_Assassins" >= 100 )
light_bar1_OUT_unique->Disable
light_bar2_OUT_unique->Disable
light_bar3_OUT_unique->Disable
light_bar4_OUT_unique->Disable
light_bar5_OUT_unique->Disable
light_bar6_OUT_unique->Disable
light_bar7_OUT_unique->Disable
light_bar8_OUT_unique->Disable
light_bar1_unique->Enable
light_bar2_unique->Enable
light_bar3_unique->Enable
light_bar4_unique->Enable
light_bar5_unique->Enable
light_bar6_unique->Enable
light_bar7_unique->Enable
light_bar8_unique->Enable
Set doOnce To 2
EndIf
EndIf

If ( creepstate == 0 )
If ( doOnce == 0 )
light_bar1_OUT_unique->Disable
light_bar2_OUT_unique->Disable
light_bar3_OUT_unique->Disable
light_bar4_OUT_unique->Disable
light_bar5_OUT_unique->Disable
light_bar6_OUT_unique->Disable
light_bar7_OUT_unique->Disable
light_bar8_OUT_unique->Disable
Set doOnce To 1
EndIf
EndIf

If ( GetJournalIndex "TR_Assassins" < 80 )
Return
EndIf

If ( GetJournalIndex "TR_Assassins" >= 100 )
Return
EndIf

If ( DtncCk == 0 )
If ( GetDistance Player > 192 )
Return
EndIf
EndIf

If ( doorcheck == 1 )
If ( GetJournalIndex "TR_Assassins" < 85 )
Return
EndIf
EndIf

If ( door2check == 1 )
If ( GetJournalIndex "TR_Assassins" < 85 )
Return
EndIf
EndIf

If ( dayCheck == 0 )
If ( DaysPassed > "helsethScript".FightDay )
Set dayCheck To 1
EndIf
EndIf

If ( creepstate >= 1 )
If ( GetDistance Player >= 400 )
hels_assassin1->ClearForceSneak
hels_assassin2->ClearForceSneak
hels_assassin3->ClearForceSneak
hels_assassin1->ClearForceSneak
hels_assassin1->StartCombat Player
hels_assassin2->StartCombat Player
hels_assassin3->StartCombat Player
hels_assassin1->StartCombat Player
Set creepstate To 17
EndIf
EndIf

If ( dayCheck == 0 )
Return
EndIf

If ( creepstate == 0 )
If ( GameHour < 20 )
If ( GameHour > 4 )
Return
EndIf
EndIf

Set DtncCk To 1
Set creepstate To 1
Journal "TR_Assassins" 85

ElseIf ( creepstate == 1 )
hels_assassin1->ForceSneak
hels_assassin2->ForceSneak
hels_assassin3->ForceSneak
hels_assassin1->AiTravel 738 -228 -128
Set creepstate To 2

ElseIf ( creepstate == 2 )
If ( hels_assassin1->GetAiPackageDone == 1 )
PlaySound3D "Torch Out"
light_bar1_unique->Disable
light_bar2_unique->Disable
light_bar3_unique->Disable
light_bar4_unique->Disable
light_bar5_unique->Disable
light_bar6_unique->Disable
light_bar7_unique->Disable
light_bar8_unique->Disable
light_bar1_OUT_unique->Enable
light_bar2_OUT_unique->Enable
light_bar3_OUT_unique->Enable
light_bar4_OUT_unique->Enable
light_bar5_OUT_unique->Enable
light_bar6_OUT_unique->Enable
light_bar7_OUT_unique->Enable
light_bar8_OUT_unique->Enable
Set creepstate To 3
EndIf

ElseIf ( creepstate == 3 )
Set timer To ( timer + GetSecondsPassed )
If ( timer > 5 )
hels_assassin1->Say "Vo\Misc\helsass1.wav" "...supposed to be here somewhere..."
hels_assassin1->AiTravel 516 -100 -128
Set timer To 0
Set creepstate To 4
EndIf

ElseIf ( creepstate == 4 )
If ( hels_assassin1->GetAiPackageDone == 1 )
Set creepstate To 5
EndIf

ElseIf ( creepstate == 5 )
Set timer To ( timer + GetSecondsPassed )
If ( timer > 5 )
hels_assassin1->Say "Vo\Misc\helsass2.wav" "...he told us in the Queen Mother's chambers..."
hels_assassin1->AiTravel 816 -2 -128
Set timer To 0
Set creepstate To 6
EndIf

ElseIf ( creepstate == 6 )
If ( hels_assassin1->GetAiPackageDone == 1 )
Set creepstate To 7
EndIf

ElseIf ( creepstate == 7 )
hels_assassin1->Say "Vo\Misc\helsass3.wav" "...behind the screen..."
hels_assassin1->AiTravel 786 128 -128
Set creepstate To 8

ElseIf ( creepstate == 8 )
If ( hels_assassin1->GetAiPackageDone == 1 )
Set creepstate To 9
EndIf

ElseIf ( creepstate == 9 )
hels_assassin1->AiTravel 748 292 -128
Set creepstate To 10

ElseIf ( creepstate == 10 )
If ( hels_assassin1->GetAiPackageDone == 1 )
Set creepstate To 11
EndIf

ElseIf ( creepstate == 11 )
hels_assassin1->AiTravel 553 282 -128
Set creepstate To 12

ElseIf ( creepstate == 12 )
If ( hels_assassin1->GetAiPackageDone == 1 )
Set creepstate To 13
EndIf

ElseIf ( creepstate == 13 )
hels_assassin1->AiTravel 371 268 -128
Set creepstate To 14

ElseIf ( creepstate == 14 )
If ( hels_assassin1->GetAiPackageDone == 1 )
Set creepstate To 15
EndIf

ElseIf ( creepstate == 15 )
hels_assassin1->AiTravel 243 164 -128
Set creepstate To 16

ElseIf ( creepstate == 16 )
hels_assassin1->ClearForceSneak
hels_assassin2->ClearForceSneak
hels_assassin3->ClearForceSneak
hels_assassin1->StartCombat Player
hels_assassin2->StartCombat Player
hels_assassin3->StartCombat Player
Set creepstate To 17
EndIf

End
same script in vanilla

Code: Select all

Begin barAssScript

;this script is on the active_assassin_unique activator in Bs chambers. will need lots o' tweaking. - Mark
 
float timer
short creepstate
short distancecheck
short doorcheck
short door2check
short doOnce
short dayCheck

if ( MenuMode == 1 )
	return
endif

if ( doOnce == 1 )
	if ( GetJournalIndex TR_Assassins >= 100 )
		light_bar1_OUT_unique->Disable
		light_bar2_OUT_unique->Disable
		light_bar3_OUT_unique->Disable
		light_bar4_OUT_unique->Disable
		light_bar5_OUT_unique->Disable
		light_bar6_OUT_unique->Disable
		light_bar7_OUT_unique->Disable
		light_bar8_OUT_unique->Disable
		light_bar1_unique->Enable
		light_bar2_unique->Enable
		light_bar3_unique->Enable
		light_bar4_unique->Enable
		light_bar5_unique->Enable
		light_bar6_unique->Enable
		light_bar7_unique->Enable
		light_bar8_unique->Enable
		set doOnce to 2
	endif
endif		

if ( creepstate == 0 )
	if ( doOnce == 0 )
		light_bar1_OUT_unique->Disable
		light_bar2_OUT_unique->Disable
		light_bar3_OUT_unique->Disable
		light_bar4_OUT_unique->Disable
		light_bar5_OUT_unique->Disable
		light_bar6_OUT_unique->Disable
		light_bar7_OUT_unique->Disable
		light_bar8_OUT_unique->Disable
		set doOnce to 1
	endif
endif

if ( GetJournalIndex TR_Assassins < 80 )
	;MessageBox "RETURNING FOR JOURNAL < 80"
	return
endif

if ( GetJournalIndex TR_Assassins >= 100 )
	;MessageBox "RETURNING FOR JOURNAL >= 100"
	return
endif

if ( distancecheck == 0 )
	if ( GetDistance Player > 192 )
		;MessageBox "RETURNING FOR DISTANCE > 192"
		return
	endif
endif

if ( doorcheck == 1 )
	if ( GetJournalIndex TR_Assassins < 85 )
		;MessageBox "RETURNING FOR DOORCHECK=1 AND JOURNAL < 85"
		return
	endif
endif

if ( door2check == 1 )
	if ( GetJournalIndex TR_Assassins < 85 )
		;MessageBox "RETURNING FOR DOORCHECK=1 AND JOURNAL < 85"
		return
	endif
endif

if ( dayCheck == 0 )
	if ( DaysPassed > "King Hlaalu Helseth".FightDay )
		set dayCheck to 1
	endif
endif

;this part clears sneak and starts combat if player moves from behind screens. avoids silly dialogue from assassins

if ( creepstate >= 1 )
	if ( GetDistance Player >= 400 )
		hels_assassin1->ClearForceSneak
		hels_assassin2->ClearForceSneak
		hels_assassin3->ClearForceSneak
		hels_assassin1->ClearForceSneak		
		hels_assassin1->StartCombat Player
		hels_assassin2->StartCombat Player
		hels_assassin3->StartCombat Player
		hels_assassin1->StartCombat Player
		set creepstate to 17
	endif
endif

if ( dayCheck == 0 )
	return
endif

if ( creepstate == 0 )
	if ( GameHour < 20 )
		if ( GameHour > 4 )
			;MessageBox "RETURNING FOR CREEPSTATE=0, GAMEHOUR <20 GAMEHOUR > 4"
			return
		endif
	endif

	set distancecheck to 1
	set creepstate to 1
	;set doorcheck to 0
	Journal TR_Assassins 85

elseif ( creepstate == 1 )
	hels_assassin1->ForceSneak
	hels_assassin2->ForceSneak
	hels_assassin3->ForceSneak
	hels_assassin1->AiTravel 738 -228 -128
	set creepstate to 2

elseif ( creepstate == 2 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		PlaySound3D, "Torch Out"
		light_bar1_unique->Disable
		light_bar2_unique->Disable
		light_bar3_unique->Disable
		light_bar4_unique->Disable
		light_bar5_unique->Disable
		light_bar6_unique->Disable
		light_bar7_unique->Disable
		light_bar8_unique->Disable
		light_bar1_OUT_unique->Enable
		light_bar2_OUT_unique->Enable
		light_bar3_OUT_unique->Enable
		light_bar4_OUT_unique->Enable
		light_bar5_OUT_unique->Enable
		light_bar6_OUT_unique->Enable
		light_bar7_OUT_unique->Enable
		light_bar8_OUT_unique->Enable
		set creepstate to 3
	endif

elseif ( creepstate == 3 )
	set timer to ( timer + GetSecondsPassed )
	if ( timer > 5 )
		hels_assassin1->Say "Vo\Misc\helsass1.wav", "...supposed to be here somewhere..."
		hels_assassin1->AiTravel 516 -100 -128
		set timer to 0		
		set creepstate to 4
	endif		

elseif ( creepstate == 4 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		set creepstate to 5
	endif

elseif ( creepstate == 5 )
	set timer to ( timer + GetSecondsPassed )
	if ( timer > 5 )
		hels_assassin1->Say "Vo\Misc\helsass2.wav", "...he told us in the Queen Mother's chambers..."
		hels_assassin1->AiTravel 816 -2 -128
		set timer to 0
		set creepstate to 6
	endif

elseif ( creepstate == 6 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		set creepstate to 7
	endif

elseif ( creepstate == 7 )
	hels_assassin1->Say "Vo\Misc\helsass3.wav", "...behind the screen..."
	hels_assassin1->AiTravel 786 128 -128
	set creepstate to 8
		
elseif ( creepstate == 8 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		set creepstate to 9
	endif

elseif ( creepstate == 9 )
	hels_assassin1->AiTravel 748 292 -128
	set creepstate to 10		

elseif ( creepstate == 10 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		set creepstate to 11
	endif

elseif ( creepstate == 11 )
	hels_assassin1->AiTravel 553 282 -128
	set creepstate to 12

elseif ( creepstate == 12 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		set creepstate to 13
	endif

elseif ( creepstate == 13 )
	hels_assassin1->AiTravel 371 268 -128
	set creepstate to 14

elseif ( creepstate == 14 )
	if ( hels_assassin1->GetAiPackageDone == 1 )
		set creepstate to 15
	endif

elseif ( creepstate == 15 )
	hels_assassin1->AiTravel 243 164 -128
	set creepstate to 16

elseif ( creepstate == 16 )
	hels_assassin1->ClearForceSneak
	hels_assassin2->ClearForceSneak
	hels_assassin3->ClearForceSneak
	hels_assassin1->StartCombat Player
	hels_assassin2->StartCombat Player
	hels_assassin3->StartCombat Player
	set creepstate to 17
endif



endif
End barAssScript


So anyone familiar with OpenMW script VM is there a advantage to script tidy outside of the actually fixed errors
User avatar
DestinedToDie
Posts: 1181
Joined: 29 Jun 2015, 09:08

Re: Script Tidy(is there any benefit in openmw)

Post by DestinedToDie »

I was under the impression that comments do not get converted into bitcode in the first place, so deleting them has no effect in vanilla Morrowind engine. I suppose fixed syntax makes the script more likely to work as intended in OpenMW, although I think we have pretty much all vanilla Morrowind scripts working already. Removing tabs is not recommended because it makes the script harder to read and is considered bad syntax. In bitcode, do these tabs even exist? Probably not. I'd say that the effort put into this may have been somewhat misguided.

In OpenMW on the other hand the script is converted into bitcode ingame instead of in the CS. So maybe removing tabs does slightly influence the conversion, but it's still madness imo.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Script Tidy(is there any benefit in openmw)

Post by Zini »

I was under the impression that comments do not get converted into bitcode in the first place
Correct.
In bitcode, do these tabs even exist?
No.
In OpenMW on the other hand the script is converted into bitcode ingame instead of in the CS. So maybe removing tabs does slightly influence the conversion, but it's still madness imo.
Our compiler is lightning fast. It is true that there would be a marginal improvement once per script per gaming session. But it would be way too small to be even noticeable.

Its bytecode btw., not bitcode.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Script Tidy(is there any benefit in openmw)

Post by sirherrbatka »

It amazes me how the original engine works. Seriously.
User avatar
Pop000100
Posts: 82
Joined: 18 Aug 2014, 21:17
Location: Loitering around Gnisis.

Re: Script Tidy(is there any benefit in openmw)

Post by Pop000100 »

Thank you guys, also is there a chance for like a script optimizer for OpenMW in the future like -o3 in GCC(i understand this is not a pressing matter)
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Script Tidy(is there any benefit in openmw)

Post by Zini »

Don't see a need for faster script execution right now. At least I haven't seen any case reported where the script engine was a performance bottleneck (other than BS scripts). If that changes there is at least one simple tweak I can do to improve performance and since we are also controlling the VR/the bytecode there are few options too.

Classical optimisation before or during code generation is currently not on the table. I don't rule it out, but that would require some major changes.
Chris
Posts: 1625
Joined: 04 Sep 2011, 08:33

Re: Script Tidy(is there any benefit in openmw)

Post by Chris »

I'd like to see proper event-driven scripting, personally. The biggest timesink with scripts right now is that most of them are just constantly running, doing nothing while looking for a particular change in game state, then do something, then go back to doing nothing until some other change. Every frame it's being executed to check for something that more often than not doesn't happen. Not only is this wasteful (the script has to check 30 to 60 times a second for something that only happens once a minute, or a few times throughout the whole play session), it also burdens script writers with making state machines in every such script. it'd be much easier, and much more efficient, to be able to say 'run this bit of script when XYZ happens', and the script is otherwise completely ignored when XYZ doesn't happen.
kuyondo
Posts: 243
Joined: 29 Mar 2016, 17:45

Re: Script Tidy(is there any benefit in openmw)

Post by kuyondo »

Based on Chris' explanation..
We could make something like this:

Event:
Condition:
Action:

When an event happens, ie activating items, npc dying, disposition change etc..
Check the condition(s) (if any), ie player has item, player skill/attribute, is npc dead?, variable, player in interior? etc..
And execute action if condition(s) is satisfied, ie sethealth, disable/enable, set/create a variable, unlock a door, startscript/stopscript etc..
Last edited by kuyondo on 23 Oct 2017, 19:19, edited 1 time in total.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Script Tidy(is there any benefit in openmw)

Post by Zini »

We could. But what for? We already found that there is no performance problem with the current script system. And even if we find us in a situation eventually where we do have performance problems, these changes won't help with existing scripts.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Script Tidy(is there any benefit in openmw)

Post by sirherrbatka »

That would make scripting *slightly* easier. But post 1.0 I guess.
Post Reply