Build 4.5.110: Bug fixes

FIXED: Error in databases caused by respawning static objects via mist.dynAddStatic. DB updater was adding a new groupName entry for the static object instead of inheriting it from the missing editor. If the groupName didn't match the unitName then the problem occurred.
FIXED: Loading mistSetting value for dbLog
FIXED: Error in segmentIntersect function. Correctly to return vec2 table rather than entries 2 and 3 being the x, y values
FIXED: Typo in getWindBearingAndVel function
FIXED: locality bug in mist.marker.add where the passed coordinates were still referenced and converted to vec3
This commit is contained in:
mrSkortch 2022-04-15 21:26:31 -06:00
parent 3654aa9a88
commit a13abdd0e6
2 changed files with 84 additions and 56 deletions

View File

@ -35,7 +35,7 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 4 mist.majorVersion = 4
mist.minorVersion = 5 mist.minorVersion = 5
mist.build = 109 mist.build = 110
-- forward declaration of log shorthand -- forward declaration of log shorthand
local log local log
@ -858,7 +858,7 @@ do -- the main scope
end end
end end
local function dbUpdate(event, objType) local function dbUpdate(event, objType, origGroupName)
--dbLog:info('dbUpdate') --dbLog:info('dbUpdate')
local newTable = {} local newTable = {}
newTable.startTime = 0 newTable.startTime = 0
@ -873,10 +873,10 @@ do -- the main scope
log:warn('$1 is not a Group or Static Object. This should not be possible. Sent category is: $2', event, objType) log:warn('$1 is not a Group or Static Object. This should not be possible. Sent category is: $2', event, objType)
return false return false
end end
local objName = newObject:getName()
newTable.name = newObject:getName() newTable.name = origGroupName or objName
newTable.groupId = tonumber(newObject:getID()) newTable.groupId = tonumber(newObject:getID())
newTable.groupName = newObject:getName() newTable.groupName = origGroupName or objName
local unitOneRef local unitOneRef
if objType == 'static' then if objType == 'static' then
unitOneRef = newObject unitOneRef = newObject
@ -1061,9 +1061,10 @@ do -- the main scope
--dbLog:info('iterate') --dbLog:info('iterate')
for name, gData in pairs(tempSpawnedGroups) do for name, gData in pairs(tempSpawnedGroups) do
--env.info(name) --env.info(name)
--dbLog:info(gData) --dbLog:warn(gData)
local updated = false local updated = false
local stillExists = false local stillExists = false
local staticGroupName
if not gData.checked then if not gData.checked then
tempSpawnedGroups[name].checked = true -- so if there was an error it will get cleared. tempSpawnedGroups[name].checked = true -- so if there was an error it will get cleared.
local _g = gData.gp or Group.getByName(name) local _g = gData.gp or Group.getByName(name)
@ -1091,7 +1092,8 @@ do -- the main scope
end end
end end
--dbLog:info('Updated: $1', updated) --dbLog:info('Updated: $1', updated)
if updated == false and gData.type ~= 'static' then -- time to check units if updated == false then
if gData.type ~= 'static' then -- time to check units
-- dbLog:info('No Group Mismatch, Check Units') -- dbLog:info('No Group Mismatch, Check Units')
if _g and _g:isExist() == true then if _g and _g:isExist() == true then
stillExists = true stillExists = true
@ -1108,13 +1110,20 @@ do -- the main scope
end end
end end
end end
else -- it is a static object
local ref = mist.DBs.unitsByName[name]
if ref then
staticGroupName = ref.groupName
end
end
else else
stillExists = true stillExists = true
end end
if stillExists == true and (updated == true or not mist.DBs.groupsByName[name]) then if stillExists == true and (updated == true or not mist.DBs.groupsByName[name]) then
--dbLog:info('Get Table') --dbLog:info('Get Table')
local dbData = dbUpdate(name, gData.type) local dbData = dbUpdate(name, gData.type, staticGroupName)
if dbData and type(dbData) == 'table' then if dbData and type(dbData) == 'table' then
writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated} writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated}
end end
@ -1440,7 +1449,7 @@ do -- the main scope
-- create logger -- create logger
mist.log = mist.Logger:new("MIST", mistSettings.logLevel) mist.log = mist.Logger:new("MIST", mistSettings.logLevel)
dbLog = mist.Logger:new('MISTDB', 'warn') dbLog = mist.Logger:new('MISTDB', mistSettings.dbLog)
log = mist.log -- log shorthand log = mist.log -- log shorthand
-- set warning log level, showing only -- set warning log level, showing only
@ -3114,11 +3123,16 @@ function mist.shape.getPointOnSegment(point, seg, isSeg)
end end
function mist.shape.segmentIntersect(segA, segB) function mist.shape.segmentIntersect(seg1, seg2)
local dx1, dy1 = segA[2].x - segA[1].x, segA[2] - segA[1].y local segA = {mist.utils.makeVec2(seg1[1]), mist.utils.makeVec2(seg1[2])}
local dx2, dy2 = segB[2].x - segB[1].x, segB[2] - segB[1].y local segB = {mist.utils.makeVec2(seg2[1]), mist.utils.makeVec2(seg2[2])}
local dx1, dy1 = segA[2].x - segA[1].x, segA[2].y - segA[1].y
local dx2, dy2 = segB[2].x - segB[1].x, segB[2].y - segB[1].y
local dx3, dy3 = segA[1].x - segB[1].x, segA[1].y - segB[1].y local dx3, dy3 = segA[1].x - segB[1].x, segA[1].y - segB[1].y
local d = dx1*dy2 - dy1*dx2 local d = dx1*dy2 - dy1*dx2
if d == 0 then if d == 0 then
return false return false
end end
@ -3131,7 +3145,7 @@ function mist.shape.segmentIntersect(segA, segB)
return false return false
end end
-- point of intersection -- point of intersection
return true, segA[1].x + t1*dx1, segA[1].y + t1*dy1 return true, {x = segA[1].x + t1*dx1, y = segA[1].y + t1*dy1}
end end
@ -7480,7 +7494,7 @@ do
local coa = -1 local coa = -1
local usedId = 0 local usedId = 0
pos = mist.utils.deepCopy(pos)
if id then if id then
if type(id) ~= 'number' then if type(id) ~= 'number' then
@ -8610,7 +8624,7 @@ do -- group tasks scope
end end
function mist.getWindBearingAndVel(p) function mist.getWindBearingAndVel(p)
local point = mist.utils.makeVec3(o) local point = mist.utils.makeVec3(p)
local gLevel = land.getHeight({x = point.x, y = point.z}) local gLevel = land.getHeight({x = point.x, y = point.z})
if point.y <= gLevel then if point.y <= gLevel then
point.y = gLevel + 10 point.y = gLevel + 10

View File

@ -35,7 +35,7 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 4 mist.majorVersion = 4
mist.minorVersion = 5 mist.minorVersion = 5
mist.build = 109 mist.build = 110
-- forward declaration of log shorthand -- forward declaration of log shorthand
local log local log
@ -858,7 +858,7 @@ do -- the main scope
end end
end end
local function dbUpdate(event, objType) local function dbUpdate(event, objType, origGroupName)
--dbLog:info('dbUpdate') --dbLog:info('dbUpdate')
local newTable = {} local newTable = {}
newTable.startTime = 0 newTable.startTime = 0
@ -873,10 +873,10 @@ do -- the main scope
log:warn('$1 is not a Group or Static Object. This should not be possible. Sent category is: $2', event, objType) log:warn('$1 is not a Group or Static Object. This should not be possible. Sent category is: $2', event, objType)
return false return false
end end
local objName = newObject:getName()
newTable.name = newObject:getName() newTable.name = origGroupName or objName
newTable.groupId = tonumber(newObject:getID()) newTable.groupId = tonumber(newObject:getID())
newTable.groupName = newObject:getName() newTable.groupName = origGroupName or objName
local unitOneRef local unitOneRef
if objType == 'static' then if objType == 'static' then
unitOneRef = newObject unitOneRef = newObject
@ -1061,9 +1061,10 @@ do -- the main scope
--dbLog:info('iterate') --dbLog:info('iterate')
for name, gData in pairs(tempSpawnedGroups) do for name, gData in pairs(tempSpawnedGroups) do
--env.info(name) --env.info(name)
--dbLog:info(gData) --dbLog:warn(gData)
local updated = false local updated = false
local stillExists = false local stillExists = false
local staticGroupName
if not gData.checked then if not gData.checked then
tempSpawnedGroups[name].checked = true -- so if there was an error it will get cleared. tempSpawnedGroups[name].checked = true -- so if there was an error it will get cleared.
local _g = gData.gp or Group.getByName(name) local _g = gData.gp or Group.getByName(name)
@ -1091,7 +1092,8 @@ do -- the main scope
end end
end end
--dbLog:info('Updated: $1', updated) --dbLog:info('Updated: $1', updated)
if updated == false and gData.type ~= 'static' then -- time to check units if updated == false then
if gData.type ~= 'static' then -- time to check units
-- dbLog:info('No Group Mismatch, Check Units') -- dbLog:info('No Group Mismatch, Check Units')
if _g and _g:isExist() == true then if _g and _g:isExist() == true then
stillExists = true stillExists = true
@ -1108,13 +1110,20 @@ do -- the main scope
end end
end end
end end
else -- it is a static object
local ref = mist.DBs.unitsByName[name]
if ref then
staticGroupName = ref.groupName
end
end
else else
stillExists = true stillExists = true
end end
if stillExists == true and (updated == true or not mist.DBs.groupsByName[name]) then if stillExists == true and (updated == true or not mist.DBs.groupsByName[name]) then
--dbLog:info('Get Table') --dbLog:info('Get Table')
local dbData = dbUpdate(name, gData.type) local dbData = dbUpdate(name, gData.type, staticGroupName)
if dbData and type(dbData) == 'table' then if dbData and type(dbData) == 'table' then
writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated} writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated}
end end
@ -1440,7 +1449,7 @@ do -- the main scope
-- create logger -- create logger
mist.log = mist.Logger:new("MIST", mistSettings.logLevel) mist.log = mist.Logger:new("MIST", mistSettings.logLevel)
dbLog = mist.Logger:new('MISTDB', 'warn') dbLog = mist.Logger:new('MISTDB', mistSettings.dbLog)
log = mist.log -- log shorthand log = mist.log -- log shorthand
-- set warning log level, showing only -- set warning log level, showing only
@ -3114,11 +3123,16 @@ function mist.shape.getPointOnSegment(point, seg, isSeg)
end end
function mist.shape.segmentIntersect(segA, segB) function mist.shape.segmentIntersect(seg1, seg2)
local dx1, dy1 = segA[2].x - segA[1].x, segA[2] - segA[1].y local segA = {mist.utils.makeVec2(seg1[1]), mist.utils.makeVec2(seg1[2])}
local dx2, dy2 = segB[2].x - segB[1].x, segB[2] - segB[1].y local segB = {mist.utils.makeVec2(seg2[1]), mist.utils.makeVec2(seg2[2])}
local dx1, dy1 = segA[2].x - segA[1].x, segA[2].y - segA[1].y
local dx2, dy2 = segB[2].x - segB[1].x, segB[2].y - segB[1].y
local dx3, dy3 = segA[1].x - segB[1].x, segA[1].y - segB[1].y local dx3, dy3 = segA[1].x - segB[1].x, segA[1].y - segB[1].y
local d = dx1*dy2 - dy1*dx2 local d = dx1*dy2 - dy1*dx2
if d == 0 then if d == 0 then
return false return false
end end
@ -3131,7 +3145,7 @@ function mist.shape.segmentIntersect(segA, segB)
return false return false
end end
-- point of intersection -- point of intersection
return true, segA[1].x + t1*dx1, segA[1].y + t1*dy1 return true, {x = segA[1].x + t1*dx1, y = segA[1].y + t1*dy1}
end end
@ -7480,7 +7494,7 @@ do
local coa = -1 local coa = -1
local usedId = 0 local usedId = 0
pos = mist.utils.deepCopy(pos)
if id then if id then
if type(id) ~= 'number' then if type(id) ~= 'number' then
@ -8610,7 +8624,7 @@ do -- group tasks scope
end end
function mist.getWindBearingAndVel(p) function mist.getWindBearingAndVel(p)
local point = mist.utils.makeVec3(o) local point = mist.utils.makeVec3(p)
local gLevel = land.getHeight({x = point.x, y = point.z}) local gLevel = land.getHeight({x = point.x, y = point.z})
if point.y <= gLevel then if point.y <= gLevel then
point.y = gLevel + 10 point.y = gLevel + 10