On original Morrowind scripts revision

Posted 18 April 2010 - 02:33 PM

Compiled bytecode should be identical between commented and uncommented script: try compiling a commented/uncommented script, load the different .esp with MWEdit compare scripts option).
There may be a difference in memory used if source code is loaded in memory during playing, (I don't think so, it would serve no purpose but hey, this is Morrowind after all), this has not been thoroughly tested so far to my knowledge.
My 2 cents...
Comment stripping: keep at least valuable infos, you can nuke the joke comments.
Indentation: remove it if you like, THEN use MWEdit, better with "initial indent level" unchecked, to reapply a consistent, standard indentation.

You can discuss about using/not using returns, procedural vs object oriented, C# vs PHP, Linux vs Windows, Morrowind vs Oblivion, Cathedral vs Parlor...
Indentation is the only universally good programming habit. Period.

 

Posted 18 April 2010 - 10:58 AM

Jac, on 18 April 2010 - 02:43 AM, said:

Indentation and proper commenting, Abot.

You are right, of course.

 

And, with english not as my mother language I should avoid posting at 2 a.m. I will try to clarify my thoughts.
I was not trying to say proper comments are not good, just that IMHO they are not as essential as indentation. I think deciding what is proper may still be in the eye of the beholder, that's why a wrote:

Comment stripping: keep at least valuable infos, you can nuke the joke comments
Some examples:

if ( MenuMode == 1 )
	return
	;don't run time in Menu Mode. Very bad.
endif
if ( timer > 29 )
	set start to 0
	set timer to 0
	;after 9 more seconds, the doors are back to their original position
	;reset timer and start
endif

set timer to ( timer + GetSecondsPassed )
;above line increments the timer... should be last here outside if
;statements
;otherwise bad things can happen

Are these comments useful for someone that never opened MSFD? Probably yes. Are they useful for more experienced coders? probably not.
I think these comments could be stripped with no great problems in a script tidy work

Begin arethanMandasScript

;can't be insane if you have LORE
short noLore

End

This comment I would keep: it tells about the special purpose of the script.

 


Posted 22 April 2010 - 11:00 PM

huskobar, on 19 April 2010 - 06:11 AM, said:
I do find it funny, though, that even with proper indentation and comments, over 200 original scripts turned out wrong and stayed that way for 10 years.

Agreed, probably this is due to a sort of "stand in awe of Bethesda" effect, mixed with "if they (seem to) work don't change them", and the fact that some things that seem wrong or at least incongruent (= equivalent to == in comparisons, some extra endifs that seems to be just happily skipped...) probably produce the same bytecode as the "correct" version.

There are probably Bethesda scripts that were not written by programmers, and scripts that may be written in a theoretically more efficient way ( I say theoretically because I an not so sure that would be a noticeable difference in game).

Take the signrotate and the float scripts for example: they are widely used by lights and other activators, and even in the Bloodmoon revision, they are still calling a "slow" getdistance function each frame and using an unneeded swingTime variable instead of a constant value.

I'm using a personal version of signrotate on street lanterns, that replaces the variable with a constant, calls getdistance only every couple of seconds (using getsecondspassed and a slighty randomized time interval so not every instance repeats the slow getdistance call the same frame), and even replaces the light with activator at daytime.

With all this optimization, what is the huge FPS gain in Balmora? Probably less than 1 FPS.