Skip to content

TraceScreenRay fails to hit map on areas that are flattened by buildings being built on them.  #42

@Beherith

Description

@Beherith

Quite a few things are now known about this issue:

  1. The oldest engine I tested this also had the bug, it was in engine 1486.
  2. When a building is built by a constructor, the edges of the flattened area randomly miss on TraceScreenRay
  3. If the buildings are /give-en, then the bug is not present
  4. If the terrain is restored underneath /given buildings, the bug becomes visible.
  5. Explosions and craters do not show this behaviour
  6. The issue can relatively easily be checked by this widget that traces the screen along a regular grid, and draws a red rectangle if the trace fails.
function widget:GetInfo()
    return {
        name      = "ScreenTrace",
        desc      = "Trace the screen along a regular grid, drawing a red rectangle on any ray that does not hit the ground",
        author    = "beheriht",
        date      = "2021 summer heat",
        license   = "Bacon",
        layer     = 10000,
        enabled   = true  --  loaded by default?
    }
end

local resolution = 10

local vsx, vsy
function widget:ViewResize(newX,newY)
	vsx, vsy = Spring.GetViewGeometry()
end

function widget:Initialize()
	widget:ViewResize()
end

function widget:DrawScreen()
	gl.Color(1.0, 0.0, 0.0, 0.75)  --red
	for x = 1, vsx, resolution do
		for y = 1, vsy, resolution do
			local _ , coords = Spring.TraceScreenRay(x, y, true) 
			if coords and coords[2] and coords[2] > -1000 then
				--gl.Color(0.0, 1.0, 0.0, 0.5) -- green
				--gl.Rect(x, y, x+ resolution/2, y+resolution/2) -- x y w h
			else
				--gl.Color(1.0, 0.0, 0.0, 0.75)  --red
				gl.Rect(x, y, x+ resolution, y+ resolution) -- x y w h
			end
		end
	end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions