View Single Post
Old 03-25-14, 01:13 PM   #3048
TheDarkWraith
Black Magic
 
Join Date: Jun 2007
Posts: 11,962
Downloads: 147
Uploads: 5


Default

Looked back over the code for the minimum signal strength adjustment and noticed that I wasn't accounting for 0 based numbers I rewrote those two functions to take into account 0 based numbers and also to clean it up (original code was fugly!) and to add some error checking into it also (to account for user errors - entering wrong values for variables)

Now it's linear

Code:
TEST AL,AL                                     ; (Check_Adjust_Nightime_Minimum_Signal_Strength_For_Other_Units_Visual_Sensor) tests whether is daytime (0)
JNE SHSim_act.089431A4                         ; if already nighttime then jump
PUSH EAX                                       ; saves EAX to stack
PUSH ECX                                       ; saves ECX to stack
PUSH ESI                                       ; saves ESI to stack
PUSH 48                                        ; saves offset needed in TDWData to stack (start of nighttime value for other units)
CALL SHSim_act.Load_TDWData_Address_Into_EAX   ; calls Load_TDWData_Address_Into_EAX
FLD DWORD PTR DS:[EAX]                         ; loads start of nighttime value for other units onto top of floating point stack
MOV ECX,DWORD PTR DS:[EBX+48]                  ; loads pointer to table of offsets into ECX
MOV ECX,DWORD PTR DS:[ECX+4]                   ; loads an offset into ECX
FLD DWORD PTR DS:[EBX+ECX+28]                  ; loads current available light onto top of floating point stack
FCOMIP ST,ST(1)                                ; compares current available light to start of nighttime value for player's unit
JNB SHORT SHSim_act.0894319A                   ; if current available light is greater than or equal to start of nighttime value for
PUSH 0                                         ; saves 0 to stack (need start of rdata section)
CALL SHSim_act.Load_rdata_Address_Into_EAX     ; calls Load_rdata_Address_Into_EAX
MOV ESI,EAX                                    ; saves start of rdata section to ESI
ADD EAX,0FB1C                                  ; adds offset needed to EAX (sunlight value - used to determine if nighttime)
FLD DWORD PTR DS:[EAX]                         ; loads sunlight value - used to determine if nighttime onto top of floating point stack
FSUBP ST(1),ST                                 ; subtracts ST0 (sunlight value - used to determine if nighttime) from ST1 (start of nighttime value) and stores result in ST1 and pops top of floating point stack (gets range)
FLDZ                                           ; loads 0.0 onto top of floating point stack
FCOMIP ST,ST(1)                                ; compares ST0 (0.0) to ST1 (range) and pops top of floating point stack
JNB SHORT SHSim_act.0894319A                   ; if negative value for range then jump
FLD1                                           ; loads 1.0 onto top of floating point stack
FXCH ST(1)                                     ; swaps ST0 (1.0) and ST1 (range)
FLD DWORD PTR DS:[EBX+ECX+28]                  ; loads current available light onto top of floating point stack
FSUB DWORD PTR DS:[EAX]                        ; subtracts sunlight value - used to determine if nighttime from ST0 (current available sunlight)
FLDZ                                           ; loads 0.0 onto top of floating point stack
FCOMI ST,ST(1)                                 ; compares ST0 (0.0) to ST1 (result) - have to account for possible floating point error
JBE SHORT SHSim_act.0894315C                   ; if before or equal then jump
FST ST(1)                                      ; saves 0.0 to ST1 (result) - sets new result to 0.0
FSTP ST                                        ; pops top of floating point stack - removes 0.0
FDIVRP ST(1),ST                                ; divides ST0 (result) by ST1 (range) and stores result in ST1 and pops top of floating point stack
FSUBR ST,ST(1)                                 ; subtracts ST0 (result) from ST1 (1.0) and stores result in ST0 - gets % of range
ADD ESI,0FAB4                                  ; add offset needed to ESI (Constant 3.0 - nighttime multiplier)
FLD DWORD PTR DS:[ESI]                         ; loads constant 3.0 onto top of floating point stack (nighttime multiplier)
PUSH 4C                                        ; saves offset needed in TDWData to stack (nightime multiplier addition for other units)
CALL SHSim_act.Load_TDWData_Address_Into_EAX   ; calls calls Load_TDWData_Address_Into_EAX
FADD DWORD PTR DS:[EAX]                        ; adds nighttime multiplier addition for other units to nighttime multiplier
FSUB ST,ST(2)                                  ; subtracts ST2 (1.0) from ST0 (total nighttime multiplier) and stores result in ST0 - this converts to 0 based
FLDZ                                           ; loads 0.0 onto top of floating point stack - is possible that user set multiplier addition to negative value thus adjusted nighttime multiplier could be negative!
FCOMI ST,ST(1)                                 ; compares ST0 (0.0) to ST1 (adjusted nighttime multiplier 0 based)
JBE SHORT SHSim_act.0894317D                   ; if before or equal then jump
FST ST(1)                                      ; saves 0.0 to ST1 (adjusted nighttime multiplier)
FSTP ST                                        ; pops top of floating point stack - removes 0.0
FMULP ST(1),ST                                 ; mutiplies % of range by nighttime multiplier for other units 0 based and stores result in ST1 and pops top of floating point stack
FADDP ST(1),ST                                 ; adds ST0 (result) to ST1 (1.0) and stores result in ST1 and pops top of floating point stack - this converts back to 1 based
FLD DWORD PTR SS:[ESP+20]                      ; loads minimum signal strength onto top of floating point stack
FMULP ST(1),ST                                 ; multiplies ST1 (adjusted nighttime multiplier) by ST0 (minimum signal strength) and stores result in ST1 and pops top of floating point stack
PUSH ECX                                       ; creates temp variable
FST DWORD PTR SS:[ESP]                         ; saves new adjusted minimum signal strength to stack
MOVSS XMM0,DWORD PTR SS:[ESP]                  ; loads new adjusted minimum signal strength into XMM0
ADD ESP,4                                      ; deletes temp variables
ADD DWORD PTR SS:[ESP+0C],10                   ; sets new return value
0894319A:
FSTP ST                                        ; pops top of floating point stack
POP ESI                                        ; restores ESI
POP ECX                                        ; restores ECX
POP EAX                                        ; restores EAX
XORPS XMM2,XMM2                                ; zeroes out XMM2
TEST AL,AL                                     ; tests whether it's daytime (0)
089431A4:
RETN                                           ; returns to caller
TheDarkWraith is offline   Reply With Quote