Fog of War - Page 4

Fog of War

Requests for features in the spring code.

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Fog of War

Post by Argh »

What's the difference between it and inbuilt los?
It doesn't take terrain into account, it's not a map that's updated slowly to keep it efficient, etc., etc.

To answer the question about updates, btw... the actual LOS is updated when things move > a certain amount, or every so often. Fast-moving objects cause a huge performance hit because of this, and use a faster LOS method to help a bit.

Unlike the metalmap, you *can* get the LOS state of any given point, with Spring.GetPositionLosState(). Try that, with as few squares as you can- you really don't need super-amazing resolution for this, the hard part, as you've already figured out, is how to display it quickly. If I were you, I'd use the data returned to make a display list, and only update it infrequently- every 1/4 second or so. You'd see some ugly pop-in, but you could compensate for that, by updating any time the camera moves more than a short distance, and checking that every frame.
User avatar
Chosker
Posts: 37
Joined: 02 Sep 2008, 09:45

Re: Fog of War

Post by Chosker »

it doesn't take terrain into account because it's a grid of squares and I can't go around to modify each of those squares, as it's already too expensive to draw them being all generic (plus I wouldn't know how to do it :roll: )
but now that I remember (and checked), the squares are actually drawn on top of everything, so even if the squares grid is below the level of a cliff, it still looks on top of it from a mostly vertical view
also forgot to add that since it draws squares based on visible terrain and camera height, a very low camera that looks to the horizon makes it all extremely slow

so yeah I guess I could make updates slower (instead of every frame, like it is now) and would probably get a big performance boost.
however I wouldn't know how to do it because I think it's above my experience :-)

anyway I'm releasing the widget. it was improved abit (now the circles "fade" by having multiple layers at different distances). do know that if you change this "fade" amount (Spheres var) you need to change the alpha value accordingly
it's abit messy as there's probably vars that I don't use anymore, etc
feel free to improve it (and release it again :-) )

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:GetInfo()
  return {
    name      = "Fog of war",
    desc      = "Fog of war",
    author    = "camera Fog:unknown / modified by Chosker for fog of war",
    date      = "when?",
    license   = "GNU GPL, v2 or later",
    layer     = 10,
    enabled   = true
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----edit here:

local FogDefs = {
      Spheres = 2,
      Color = {0.0,0.0,0.0,0.15},
      SphereSpacing = 10.5,
      Density = 1,
      Radius = 15,   
      MaxHeight = 3000,
}      

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----"global" variable list

local mapy                   = Game.mapY
local mapx                   = Game.mapX
local mapSizeX               = Game.mapSizeX
local mapSizeZ               = Game.mapSizeZ
local e = Spring.Echo
local fog
local layers                 = FogDefs.Spheres 
local density                = FogDefs.Density
local distance               = FogDefs.Radius
local lsp                    = FogDefs.SphereSpacing
local fr,fg,fb,fa            = unpack(FogDefs.Color) 
local diff                   = layers/lsp
local mh                     = FogDefs.MaxHeight
local maxres = 800
local minres = 5000
local planeheight = 110
local ringspacing = 30
local templosdistance = 250

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----a simple plane, very complete, would look good with shadows, reflex and stuff.

local DrawPlaneModel = function()
  gl.BeginEnd(GL.QUAD_STRIP,function()
    gl.Vertex(-mapx*1024,0,-mapy*1024)
    gl.TexCoord(0,0)
    gl.Normal(0,mapx*256,0)
    gl.Vertex(mapx*2048,0,-mapy*1024)
    gl.TexCoord(1,0)
    gl.Normal(0,mapx*256,0)
    gl.Vertex(-mapx*1024,0,mapy*2048)
    gl.TexCoord(0,1)
    gl.Normal(0,mapx*256,0)
    gl.Vertex(mapx*2048,0,mapy*2048)
    gl.TexCoord(1,1)
    gl.Normal(0,mapx*256,0)
  end)
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----a simple quad.

local DrawSphereModel = function()
  gl.BeginEnd(GL.TRIANGLES,function()
    gl.Vertex(1.0,-0.0, 1.0) 
    gl.Vertex(-1.0, -0.0, 1.0)
    gl.Vertex(1.0, -0.0, -1.0) 
  end)
  gl.BeginEnd(GL.TRIANGLES,function()
    gl.Vertex(1.0, -0.0, -1.0)
    gl.Vertex(-1.0, -0.0, 1.0)
    gl.Vertex(-1.0, -0.0, -1.0)
  end)
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----special effects down here

local GetLocalPlayerID = Spring.GetLocalPlayerID
local GetTeamUnits = Spring.GetTeamUnits
local GetUnitPosition = Spring.GetUnitPosition
local IsSphereInView = Spring.IsSphereInView
local GetCameraPosition = Spring.GetCameraPosition
local ux = {}
local uz = {}

local Fog = function(r,g,b,a)
  local _,camy,_ = GetCameraPosition()
  if camy < maxres then
    camy = maxres
  elseif camy > minres then
    camy = minres
  else
    camy = camy
  end
  for mx = 0, mapSizeX/1, camy/32 do  
    for mz = 0, mapSizeZ/1, camy/32 do  
      local x = mx
      local y = planeheight
      local y2 = templosdistance
      local y3 = ringspacing
      local z = mz

      if IsSphereInView (x,y,z,120) then

        for i = 0,layers,1 do
          local unit = Spring.GetUnitsInCylinder(x,z,(y2+i*y3))
          if (unit[1])==nil then
            local d1 = distance*((camy-64)/960)
            local d2 = density
            gl.PushMatrix()
            gl.Translate(x,y,z)
            gl.Color(r,g,b,a)
            gl.DepthTest(false)
            gl.Blending(true) 
            gl.Scale(d1+density,d1+density,d1+density)      
            gl.CallList(fog)
            gl.PopMatrix() 
            gl.Smoothing(false,false,false)
          end
        end
      end
    end
  end
end 

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----draw functions, calls all the effect creators.

function widget:DrawWorld()
   Fog(fr,fg,fb,fa)
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----setup the list arrays

function widget:Initialize()
  fog = gl.CreateList(DrawSphereModel)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Fog of War

Post by Gota »

Would be very good to have a widget that shows all the area that you dont have los in in grey like in OTA.
How hard is that?
Last edited by Gota on 13 Aug 2009, 14:54, edited 1 time in total.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Fog of War

Post by Jools »

dizekat wrote:speaking of which, how does original TA do LOS ? Or they just have tiny battles?
They have bigger battles. But OTA is 2D, I guess that's why.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Fog of War

Post by Jools »

Gota wrote:Would be very good to have a widget that shows al the are that you dont have los in in grey like in OTA.
How hard is that?
It shouldn't have to be a widget, it should have been one of the first things added to the engine, like stated in the first post.
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Fog of War

Post by TradeMark »

actually there already is such thing, its called L button, then press "^¨~" button to change the style of it
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Fog of War

Post by Gota »

TradeMark wrote:actually there already is such thing, its called L button, then press "^¨~" button to change the style of it
It's not the same.
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Fog of War

Post by TradeMark »

oh you want it gray... i see

play speedballs so you cant see the difference..? xd or some other gray maps
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Fog of War

Post by Gota »

I want it black and white.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Fog of War

Post by Jools »

TradeMark wrote:actually there already is such thing, its called L button, then press "^¨~" button to change the style of it
Style is one thing, but doesn't the L-button make the game very slow?
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: Fog of War

Post by Gnomre »

Jools wrote:
dizekat wrote:speaking of which, how does original TA do LOS ? Or they just have tiny battles?
They have bigger battles. But OTA is 2D, I guess that's why.
OTA isn't 2D, it just has a fixed camera position.
User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Re: Fog of War

Post by Caydr »

Thank you Gnome I was going to rage.

I think I will anyway: What Gota wants is a way to see the terrain outside his view without it getting fuglied by the bizarre color combinations the Spring developers have chosen. Turning stuff outside of LoS to grayscale would accomplish this, and it's an incredibly basic shader effect, but I don't think anyone here has the will to actually implement something that won't make cheating easier.
Post Reply

Return to “Feature Requests”