v0.5: fixed-point logic fixes
This commit is contained in:
+12
-11
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
package require Tk
|
package require Tk
|
||||||
|
|
||||||
set appversion 0.4
|
set appversion 0.5
|
||||||
set scriptpath [file normalize [info script]]
|
set scriptpath [file normalize [info script]]
|
||||||
set appdir [file dirname $scriptpath]
|
set appdir [file dirname $scriptpath]
|
||||||
# check if we're running from a starpack
|
# check if we're running from a starpack
|
||||||
@@ -293,21 +293,22 @@ proc wa_roundtime_write {num} {
|
|||||||
|
|
||||||
# fixedpoint helpers
|
# fixedpoint helpers
|
||||||
proc fixed2float {fpint} {
|
proc fixed2float {fpint} {
|
||||||
set whole [expr {int($fpint) >> 16}]
|
set fpint [expr {int($fpint)}]
|
||||||
set frac [expr {int($fpint) & 65535}]
|
set whole [expr {$fpint >> 16}]
|
||||||
return [expr {$whole + ($frac / 65536)}]
|
set frac [expr {$fpint % 65536}]
|
||||||
|
return [expr {$whole + ($frac / 65536.)}]
|
||||||
}
|
}
|
||||||
|
|
||||||
proc float2fixed {flt} {
|
proc float2fixed {flt} {
|
||||||
set whole [expr {int(double($flt))}]
|
set whole [expr {int($flt)}]
|
||||||
set frac [expr {double($flt) - $whole}]
|
set frac [expr {$flt - $whole}]
|
||||||
return [expr {($whole << 16) | int($frac * 65536)}]
|
return [expr {($whole << 16) | int($frac * 65536.)}]
|
||||||
}
|
}
|
||||||
|
|
||||||
# v3-only spec functions
|
# v3-only spec functions
|
||||||
|
|
||||||
proc wa_petrolturndecay_read {raw} {return [fixed2float $raw]}
|
proc wa_petrolturndecay_read {raw} {return [fixed2float $raw]}
|
||||||
proc wa_petrolturndecay_write {num} {return [expr int($num * 65536)]}
|
proc wa_petrolturndecay_write {num} {return [expr int($num * 65536.)]}
|
||||||
|
|
||||||
# general logic
|
# general logic
|
||||||
|
|
||||||
@@ -341,7 +342,7 @@ proc fullscanscheme {version} {
|
|||||||
set delay 0
|
set delay 0
|
||||||
set prob 0
|
set prob 0
|
||||||
catch {
|
catch {
|
||||||
binary scan [string range $rawschemedata $offs [expr {$offs + 4}]] cucucucu ammo power delay prob
|
binary scan [string range $rawschemedata $offs [expr {$offs + 3}]] cucucucu ammo power delay prob
|
||||||
}
|
}
|
||||||
set wsc_data($offs) $ammo
|
set wsc_data($offs) $ammo
|
||||||
set wsc_data($poweroffs) $power
|
set wsc_data($poweroffs) $power
|
||||||
@@ -360,7 +361,7 @@ proc fullscanscheme {version} {
|
|||||||
if {$size eq 2} {set fmt s}
|
if {$size eq 2} {set fmt s}
|
||||||
if {$size eq 4} {set fmt i}
|
if {$size eq 4} {set fmt i}
|
||||||
set newval ""
|
set newval ""
|
||||||
binary scan [string range $rawschemedata $offs [expr {$offs + $size}]] $fmt newval
|
binary scan [string range $rawschemedata $offs [expr {$offs + $size - 1}]] $fmt newval
|
||||||
if {$newval ne ""} {set wscval $newval}
|
if {$newval ne ""} {set wscval $newval}
|
||||||
if {([llength $valopt] > 1) && ([lindex $valopt 0] eq "spec")} {
|
if {([llength $valopt] > 1) && ([lindex $valopt 0] eq "spec")} {
|
||||||
set readfunc "[lindex $valopt 1]_read"
|
set readfunc "[lindex $valopt 1]_read"
|
||||||
@@ -474,7 +475,7 @@ proc savescheme {fname} {
|
|||||||
if {$size eq 2} {set fmt s}
|
if {$size eq 2} {set fmt s}
|
||||||
if {$size eq 4} {set fmt i}
|
if {$size eq 4} {set fmt i}
|
||||||
if {([llength $valopt] > 1) && ([lindex $valopt 0] eq "spec")} {
|
if {([llength $valopt] > 1) && ([lindex $valopt 0] eq "spec")} {
|
||||||
set writefunc "[lindex $valopt 1]_read"
|
set writefunc "[lindex $valopt 1]_write"
|
||||||
set val [$writefunc $val]
|
set val [$writefunc $val]
|
||||||
} elseif {$valopt eq "fixp"} {
|
} elseif {$valopt eq "fixp"} {
|
||||||
set val [float2fixed $val]
|
set val [float2fixed $val]
|
||||||
|
|||||||
Reference in New Issue
Block a user