4 Commits
Author SHA1 Message Date
Luxferre 140a085ebe v0.5: fixed-point logic fixes 2024-10-12 18:14:52 +03:00
Luxferre 27c669f67f v0.4: fixed default value validation for v3 2024-10-12 17:05:16 +03:00
Luxferre b749722945 bumped version 2024-10-12 16:44:43 +03:00
Luxferre ec2c95ca07 Fixed v3 value scanning 2024-10-12 16:41:58 +03:00
+15 -14
View File
@@ -7,7 +7,7 @@
package require Tk package require Tk
set appversion 0.2 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
@@ -359,9 +360,9 @@ proc fullscanscheme {version} {
if {$size eq 1} {set fmt cu} if {$size eq 1} {set fmt cu}
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}
catch { set newval ""
binary scan [string range $rawschemedata [expr {$offs + $size}]] $fmt wscval binary scan [string range $rawschemedata $offs [expr {$offs + $size - 1}]] $fmt 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"
set wscval [$readfunc $wscval] set wscval [$readfunc $wscval]
@@ -427,7 +428,7 @@ proc savescheme {fname} {
if {$diffbytes > 0} { # expand with nulls if {$diffbytes > 0} { # expand with nulls
set rawschemedata [string cat $rawschemedata [binary format x$diffbytes]] set rawschemedata [string cat $rawschemedata [binary format x$diffbytes]]
} else { # truncate } else { # truncate
set rawschemedata [string range $rawschemedata 0 [expr {$datasize - 1}] set rawschemedata [string range $rawschemedata 0 [expr {$datasize - 1}]]
} }
# write the version itself # write the version itself
set binval [binary format cu $wsc_data(version)] set binval [binary format cu $wsc_data(version)]
@@ -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]