Re: Journeywar
Posted: 21 Jul 2014, 13:41
				
				nice soap pad you've got there
			Wait, do you mean you're actually replacing the sky? Oh god the horror!skybox widget
The OpenGL scene is sized to about a large map size. Or something like that, ask a dev. So if the Lua skybox is too big, part of it gets out of the volume where things are rendered. If the lua skybox is too small, then it goes through the terrain.PicassoCT wrote:Can somebody tell me how to keep the org sky from popping back into existance, when i zoom in ?
I use zwzsg skybox widget to draw the sky, and the holotable below..
I'd say it's more about z-fighting, and that a judicious of either gl.DepthMask/gl.DepthTest, or gl.PolygonOffset, would fix it.PicassoCT wrote:Teamplatter and MapGrid VR interact in a rather poor fashion with each other. Meaning Teamplatter makes the VR-Grid flicker. I think it something with the DrawWorldPreUnit() calls beating each other..
I dont understand, both sides are depth testing as far as i can tell.zwzsg wrote:I'd say it's more about z-fighting, and that a judicious of either gl.DepthMask/gl.DepthTest, or gl.PolygonOffset, would fix it.PicassoCT wrote:Teamplatter and MapGrid VR interact in a rather poor fashion with each other. Meaning Teamplatter makes the VR-Grid flicker. I think it something with the DrawWorldPreUnit() calls beating each other..
Code: Select all
--related thread: http://springrts.com/phpbb/viewtopic.php?f=13&t=26732&start=22
function widget:GetInfo()
  return {
    name      = "External VR Grid",
    desc      = "VR grid around map",
    author    = "knorke, tweaked by KR",
    date      = "Sep 2011",
    license   = "PD",
    layer     = -3,
    enabled   = false,
    --detailsDefault = 3,
  }
end
if VFS.FileExists("nomapedgewidget.txt") then
	return
end
local DspLst = nil
--local updateFrequency = 120	-- unused
local gridTex = "LuaUI/images/vr_grid.png"
--local height = 0	-- how far above ground to draw
---magical speedups---
local math = math
local random = math.random
local spGetGroundHeight = Spring.GetGroundHeight
local glVertex = gl.Vertex
local glTexCoord = gl.TexCoord
local glColor = gl.Color
local glCreateList = gl.CreateList
local glTexRect = gl.TexRect
local spTraceScreenRay = Spring.TraceScreenRay
----------------------
local heights = {}
local island = false
local mapSizeX = Game.mapSizeX
local mapSizeZ = Game.mapSizeZ
--[[
local maxHillSize = 800/res
local maxPlateauSize = math.floor(maxHillSize*0.6)
local maxHeight = 300
local featureChance = 0.01
local noFeatureRange = 0
]]--
options_path = 'Settings/Graphics/Map/VR Grid'
options_order = {"mirrorHeightMap","drawForIslands","res","range","northSouthText"}
options = {
	mirrorHeightMap = {
		name = "Mirror heightmap",
		type = 'bool',
		value = true,
		desc = 'Mirrors heightmap on the grid',
		OnChange = function(self)
			gl.DeleteList(DspLst)
			widget:Initialize()
		end, 		
	},
	drawForIslands = {
		name = "Draw for islands",
		type = 'bool',
		value = Spring.GetConfigInt("ReflectiveWater", 0) ~= 4,
		desc = "Draws mirror grid when map is an island",		
	},	
	res = {
		name = "Tile size (64-512)",
		advanced = true,
		type = 'number',
		min = 64, 
		max = 512, 
		step = 64,
		value = 512,
		desc = 'Sets tile size (lower = more detail)\nStepsize is 64; recommend powers of 2',
		OnChange = function(self)
			gl.DeleteList(DspLst)
			widget:Initialize()
		end, 
	},
	range = {
		name = "Range (1024-8192)",
		advanced = true,
		type = 'number',
		min = 1024, 
		max = 8192, 
		step = 256,
		value = 3072,
		desc = 'How far outside the map to draw',
		OnChange = function(self)
			gl.DeleteList(DspLst)
			widget:Initialize()
		end, 
	},	
	northSouthText = {
		name = "North, East, South, & West text",
		type = 'bool',
		value = false,
		desc = 'Help you identify map direction under rotation by placing a "North/South/East/West" text on the map edges',
		OnChange = function(self)
			gl.DeleteList(DspLst)
			widget:Initialize()
		end, 		
	},	
}
-- for terrain randomization - kind of primitive
--[[
local terrainFuncs = {
	ridge = function(x, z, args)
			if args.height == 0 then return end
			for a=x-args.sizeX*res, x+args.sizeX*res,res do
				for b=z-args.sizeZ*res, z+args.sizeZ*res,res do
					local distFromCenterX = math.abs(a - x)/res
					local distFromCenterZ = math.abs(b - z)/res
					local heightMod = 0
					local excessDistX, excessDistZ = 0, 0
					if distFromCenterX > args.plateauSizeX then
						excessDistX = distFromCenterX - args.plateauSizeX
					end
					if distFromCenterZ > args.plateauSizeZ then
						excessDistZ = distFromCenterZ - args.plateauSizeZ
					end
					if excessDistX == 0 and excessDistZ == 0 then
						-- do nothing
					elseif excessDistX >= excessDistZ then
						heightMod = excessDistX/(args.sizeX - args.plateauSizeX)
					elseif excessDistX < excessDistZ then
						heightMod = excessDistZ/(args.sizeZ - args.plateauSizeZ)
					end
					
					if heights[a] and heights[a][b] then
						heights[a][b] = heights[a][b] + args.height * (1-heightMod)
					end
				end
			end
			--Spring.Echo(count)
		end,
	diamondHill = function(x, z, args) end,
	mesa = function(x, z, args) end,
}
]]--
local function GetGroundHeight(x, z)
	return heights[x] and heights[x][z] or spGetGroundHeight(x,z)
end
local function IsIsland()
	local sampleDist = 512
	for i=1,mapSizeX,sampleDist do
		-- top edge
		if GetGroundHeight(i, 0) > 0 then
			return false
		end
		-- bottom edge
		if GetGroundHeight(i, mapSizeZ) > 0 then
			return false
		end
	end
	for i=1,mapSizeZ,sampleDist do
		-- left edge
		if GetGroundHeight(0, i) > 0 then
			return false
		end
		-- right edge
		if GetGroundHeight(mapSizeX, i) > 0 then
			return false
		end	
	end
	return true
end
local function InitGroundHeights()
	local res = options.res.value or 128
	local range = (options.range.value or 8192)/res
	local TileMaxX = mapSizeX/res +1
	local TileMaxZ = mapSizeZ/res +1
	
	for x = (-range)*res,mapSizeX+range*res, res do
		heights[x] = {}
		for z = (-range)*res,mapSizeZ+range*res, res do
			local px, pz
			if options.mirrorHeightMap.value then
				if (x < 0 or x > mapSizeX) then	-- outside X map bounds; mirror true heightmap
					local xAbs = math.abs(x)
					local xFrac = (mapSizeX ~= xAbs) and x%(mapSizeX) or mapSizeX
					local xFlip = -1^math.floor(x/mapSizeX)
					if xFlip == -1 then
						px = mapSizeX - xFrac
					else
						px = xFrac
					end
				end
				if (z < 0 or z > mapSizeZ) then	-- outside Z map bounds; mirror true heightmap
					local zAbs = math.abs(z)
					local zFrac = (mapSizeZ ~= zAbs) and z%(mapSizeZ) or mapSizeZ
					local zFlip = -1^math.floor(z/mapSizeZ)
					if zFlip == -1 then
						pz = mapSizeZ - zFrac
					else
						pz = zFrac
					end				
				end
			end
			heights[x][z] = GetGroundHeight(px or x, pz or z)	-- 20, 0
		end
	end
	
	--apply noise
	--[[
	for x=-range*res, (TileMaxX+range)*res,res do
		for z=-range*res, (TileMaxZ+range)*res,res do
			if (x > 0 and z > 0) then Spring.Echo(x, z) end
			if not (x + noFeatureRange > 0 and z + noFeatureRange > 0 and x - noFeatureRange < TileMaxX and z - noFeatureRange < TileMaxZ) and featureChance>math.random() then
				local args = {
					sizeX = math.random(1, maxHillSize),
					sizeZ = math.random(1, maxHillSize),
					plateauSizeX = math.random(1, maxPlateauSize),
					plateauSizeZ = math.random(1, maxPlateauSize),
					height = math.random(-maxHeight, maxHeight),
				}
				terrainFuncs.ridge(x,z,args)
			end
		end
	end	
	
	-- for testing
	local args = {
		sizeX = maxHillSize,
		sizeZ = maxHillSize,
		plateauSizeX = maxPlateauSize,
		plateauSizeZ = maxPlateauSize,
		height = maxHeight,
	}
	terrainFuncs.ridge(-600,-600,args)	
	]]--
end
--[[
function widget:GameFrame(n)
	if n % updateFrequency == 0 then
		DspList = nil
	end
end
]]--
local function TextOutside()
	if (options.northSouthText.value) then
		local mapSizeX = mapSizeX
		local mapSizeZ = mapSizeZ
		local average = (GetGroundHeight(mapSizeX/2,0) + GetGroundHeight(0,mapSizeZ/2) + GetGroundHeight(mapSizeX/2,mapSizeZ) +GetGroundHeight(mapSizeX,mapSizeZ/2))/4
		gl.Rotate(-90,1,0,0)
		gl.Translate (0,0,average)		
		gl.Text("North", mapSizeX/2, 200, 200, "co")
		
		gl.Rotate(-90,0,0,1)
		gl.Text("East", mapSizeZ/2, mapSizeX+200, 200, "co")
		
		gl.Rotate(-90,0,0,1)	
		gl.Text("South", -mapSizeX/2, mapSizeZ +200, 200, "co")
		
		gl.Rotate(-90,0,0,1)
		gl.Text("West", -mapSizeZ/2,200, 200, "co")
		
		-- gl.Text("North", mapSizeX/2, 100, 200, "on")
		-- gl.Text("South", mapSizeX/2,-mapSizeZ, 200, "on")
		-- gl.Text("East", mapSizeX,-(mapSizeZ/2), 200, "on")
		-- gl.Text("West", 0,-(mapSizeZ/2), 200, "on")
	end
end
local function TilesVerticesOutside()
	local res = options.res.value or 128
	local range = (options.range.value or 8192)/res
	local TileMaxX = mapSizeX/res +1
	local TileMaxZ = mapSizeZ/res +1	
	for x=-range,TileMaxX+range,1 do
		for z=-range,TileMaxZ+range,1 do
			if (x > 0 and z > 0 and x < TileMaxX and z < TileMaxZ) then 
			else
				glTexCoord(0,0)
				glVertex(res*(x-1), GetGroundHeight(res*(x-1),res*z), res*z)
				glTexCoord(0,1)
				glVertex(res*x, GetGroundHeight(res*x,res*z), res*z)
				glTexCoord(1,1)				
				glVertex(res*x, GetGroundHeight(res*x,res*(z-1)), res*(z-1))
				glTexCoord(1,0)
				glVertex(res*(x-1), GetGroundHeight(res*(x-1),res*(z-1)), res*(z-1))
			end
		end
	end
	
end
local function DrawTiles()
	gl.PushAttrib(GL.ALL_ATTRIB_BITS)
	gl.DepthTest(true)
	gl.DepthMask(true)
	gl.Texture(gridTex)
	gl.BeginEnd(GL.QUADS,TilesVerticesOutside)
	gl.Texture(false)
	gl.DepthMask(false)
	gl.DepthTest(false)
	TextOutside()
	glColor(0.5,0.5,0.5,0.01)
	gl.PopAttrib()
	
end
function widget:DrawWorldPreUnit()
	if (not island) or options.drawForIslands.value then
		gl.CallList(DspLst)-- Or maybe you want to keep it cached but not draw it everytime.
		-- Maybe you want Spring.SetDrawGround(false) somewhere
	end	
end
function widget:MousePress(x, y, button)
	local _, mpos = spTraceScreenRay(x, y, true) --//convert UI coordinate into ground coordinate.
	if mpos==nil then --//activate epic menu if mouse position is outside the map
		local _, _, meta, _ = Spring.GetModKeyState()
		if meta then  --//show epicMenu when user also press the Spacebar
			WG.crude.OpenPath(options_path) --click + space will shortcut to option-menu
			WG.crude.ShowMenu() --make epic Chili menu appear.
			return false
		end
	end
end
function widget:Initialize()
	Spring.SendCommands("luaui disablewidget Map Edge Extension")
	island = IsIsland()
	InitGroundHeights()
	DspLst = glCreateList(DrawTiles)
end
function widget:Shutdown()
	gl.DeleteList(DspList)
endCode: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    gui_team_platter.lua
--  brief:   team colored platter for all visible units
--  author:  Dave Rodgers
--
--  Copyright (C) 2007.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
  return {
    name      = "TeamPlatter",
    desc      = "Shows a team color platter above all visible units",
    author    = "trepan",
    date      = "Apr 16, 2007",
    license   = "GNU GPL, v2 or later",
    layer     = 5,
    enabled   = true  --  loaded by default?
  }
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Automatically generated local definitions
local GL_LINE_LOOP           = GL.LINE_LOOP
local GL_TRIANGLE_FAN        = GL.TRIANGLE_FAN
local glBeginEnd             = gl.BeginEnd
local glColor                = gl.Color
local glCreateList           = gl.CreateList
local glDeleteList           = gl.DeleteList
local glDepthTest            = gl.DepthTest
local glDrawListAtUnit       = gl.DrawListAtUnit
local glLineWidth            = gl.LineWidth
local glPolygonOffset        = gl.PolygonOffset
local glVertex               = gl.Vertex
local spDiffTimers           = Spring.DiffTimers
local spGetAllUnits          = Spring.GetAllUnits
local spGetGroundNormal      = Spring.GetGroundNormal
local spGetSelectedUnits     = Spring.GetSelectedUnits
local spGetTeamColor         = Spring.GetTeamColor
local spGetTimer             = Spring.GetTimer
local spGetUnitBasePosition  = Spring.GetUnitBasePosition
local spGetUnitDefDimensions = Spring.GetUnitDefDimensions
local spGetUnitDefID         = Spring.GetUnitDefID
local spGetUnitRadius        = Spring.GetUnitRadius
local spGetUnitTeam          = Spring.GetUnitTeam
local spGetUnitViewPosition  = Spring.GetUnitViewPosition
local spIsUnitSelected       = Spring.IsUnitSelected
local spIsUnitVisible        = Spring.IsUnitVisible
local spSendCommands         = Spring.SendCommands
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local function SetupCommandColors(state)
  local alpha = state and 1 or 0
  local f = io.open('cmdcolors.tmp', 'w+')
  if (f) then
    f:write('unitBox  0 1 0 ' .. alpha)
    f:close()
    spSendCommands({'cmdcolors cmdcolors.tmp'})
  end
  os.remove('cmdcolors.tmp')
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local teamColors = {}
local trackSlope = true
local circleLines  = 0
local circlePolys  = 0
local circleDivs   = 32
local circleOffset = 0
local startTimer = spGetTimer()
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Initialize()
  circleLines = glCreateList(function()
    glBeginEnd(GL_LINE_LOOP, function()
      local radstep = (2.0 * math.pi) / circleDivs
      for i = 1, circleDivs do
        local a = (i * radstep)
        glVertex(math.sin(a), circleOffset, math.cos(a))
      end
    end)
  end)
  circlePolys = glCreateList(function()
    glBeginEnd(GL_TRIANGLE_FAN, function()
      local radstep = (2.0 * math.pi) / circleDivs
      for i = 1, circleDivs do
        local a = (i * radstep)
        glVertex(math.sin(a), circleOffset, math.cos(a))
      end
    end)
  end)
  SetupCommandColors(false)
end
function widget:Shutdown()
  glDeleteList(circleLines)
  glDeleteList(circlePolys)
  SetupCommandColors(true)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local realRadii = {}
local function GetUnitDefRealRadius(udid)
  local radius = realRadii[udid]
  if (radius) then
    return radius
  end
  local ud = UnitDefs[udid]
  if (ud == nil) then return nil end
  local dims = spGetUnitDefDimensions(udid)
  if (dims == nil) then return nil end
  local scale = ud.hitSphereScale -- missing in 0.76b1+
  scale = ((scale == nil) or (scale == 0.0)) and 1.0 or scale
  radius = dims.radius / scale
  realRadii[udid] = radius
  return radius
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local teamColors = {}
local function GetTeamColorSet(teamID)
  local colors = teamColors[teamID]
  if (colors) then
    return colors
  end
  local r,g,b = spGetTeamColor(teamID)
 
  colors = {{ r, g, b, 0.4 },
            { r, g, b, 0.7 }}
  teamColors[teamID] = colors
  return colors
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local triggerzoneDefID=		UnitDefNames["triggerzone"].id
local actionzoneDefID=		UnitDefNames["actionzone"].id
local reservoirzoneDefID=	UnitDefNames["reservoirzone"].id
-- and   udid ~=reservoirzoneDefID and udid ~=triggerzoneDefID and udid ~= actionzoneDefID
function widget:DrawWorldPreUnit()
  glLineWidth(3.0)
  glDepthTest(true)
 
  glPolygonOffset(-50, -2)
  local lastColorSet = nil
  for _,unitID in ipairs(spGetAllUnits()) do
    if (spIsUnitVisible(unitID)) then
      local teamID = spGetUnitTeam(unitID)
      if (teamID) then
        local udid = spGetUnitDefID(unitID)
        local radius = GetUnitDefRealRadius(udid)
        if (radius) then
          local colorSet  = GetTeamColorSet(teamID)
          if (trackSlope and (not UnitDefs[udid].canFly)) then
            local x, y, z = spGetUnitBasePosition(unitID)
            local gx, gy, gz = spGetGroundNormal(x, z)
            local degrot = math.acos(gy) * 180 / math.pi
            glColor(colorSet[1])
            glDrawListAtUnit(unitID, circlePolys, false,
                             radius, 1.0, radius,
                             degrot, gz, 0, -gx)
            glColor(colorSet[2])
            glDrawListAtUnit(unitID, circleLines, false,
                             radius, 1.0, radius,
                             degrot, gz, 0, -gx)
          else
            glColor(colorSet[1])
            glDrawListAtUnit(unitID, circlePolys, false,
                             radius, 1.0, radius)
            glColor(colorSet[2])
            glDrawListAtUnit(unitID, circleLines, false,
                             radius, 1.0, radius)
          end
        end
      end
    end
  end
  glPolygonOffset(false)
  --
  -- Blink the selected units
  --
  glDepthTest(false)
  local diffTime = spDiffTimers(spGetTimer(), startTimer)
  local alpha = 1.8 * math.abs(0.5 - (diffTime * 3.0 % 1.0))
  glColor(1, 1, 1, alpha)
  for _,unitID in ipairs(spGetSelectedUnits()) do
    local udid = spGetUnitDefID(unitID)
    local radius = GetUnitDefRealRadius(udid)
    if (radius) then
      if (trackSlope   and (not UnitDefs[udid].canFly)) then
        local x, y, z = spGetUnitBasePosition(unitID)
        local gx, gy, gz = spGetGroundNormal(x, z)
        local degrot = math.acos(gy) * 180 / math.pi
        glDrawListAtUnit(unitID, circleLines, false,
                         radius, 1.0, radius,
                          degrot, gz, 0, -gx)
      else
        glDrawListAtUnit(unitID, circleLines, false,
                         radius, 1.0, radius)
      end
    end
  end
  glLineWidth(1.0)
end
             
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Exactly, if they are both depth testing, and are both at the same depth, then you get flicker.PicassoCT wrote:I dont understand, both sides are depth testing as far as i can tell.
[f=0000910] Fatal: LuaRules: cannot allocate more memory! (805306399 bytes already used, 0 bytes maximum)
[f=0000910] Error: LuaRules::RunCallIn: error = 4, GameFrame, [Internal Lua error: Call failure] not enough memory
[f=0000910] Fatal: LuaUI: cannot allocate more memory! (805306399 bytes already used, 0 bytes maximum)
[f=0000910] Error: LuaUI::RunCallIn: error = 4, GameFrame, [Internal Lua error: Call failure] not enough memory
[f=0000910] Fatal: LuaRules: cannot allocate more memory! (805306399 bytes already used, 0 bytes maximum)
[f=0000910] [UnitScript] Error: LuaRules::RunCallIn: error = 1, CLuaUnitScript::StartMoving, [Internal Lua error: Call failure] not enough memory
[f=0000910] Fatal: LuaUI: cannot allocate more memory! (805306399 bytes already used, 0 bytes maximum)