Author Topic: Tasharen Fog of War  (Read 105820 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #60 on: March 07, 2014, 11:12:06 AM »
1. Yup. FOWSystem GetRevealedBuffer / SetRevealedBuffer:
  1.         /// <summary>
  2.         /// Retrieve the revealed buffer
  3.         /// </summary>
  4.  
  5.         public byte[] GetRevealedBuffer ()
  6.         {
  7.                 int size = textureSize * textureSize;
  8.                 byte[] buff = new byte[size];
  9.                 for (int i = 0; i < size; ++i) buff[i] = mBuffer1[i].g;
  10.                 return buff;
  11.         }
  12.  
  13.         /// <summary>
  14.         /// Reveal the area, given the specified array of bytes.
  15.         /// </summary>
  16.  
  17.         public void SetRevealedBuffer (byte[] arr)
  18.         {
  19.                 int mySize = textureSize * textureSize;
  20.  
  21.                 if (arr.Length != mySize)
  22.                 {
  23.                         Debug.LogError("Buffer size mismatch. Fog is " + mySize + ", but passed array is " + arr.Length);
  24.                 }
  25.                 else
  26.                 {
  27.                         if (mBuffer0 == null)
  28.                         {
  29.                                 mBuffer0 = new Color32[mySize];
  30.                                 mBuffer1 = new Color32[mySize];
  31.                         }
  32.  
  33.                         for (int i = 0; i < mySize; ++i)
  34.                         {
  35.                                 mBuffer0[i].g = arr[i];
  36.                                 mBuffer1[i].g = arr[i];
  37.                         }
  38.                 }
  39.         }
2. FoW revealers can be updated frequently or just once. For static objects like a stationary guard tower you would set the FoW revealer to do its thing only once, while for a moving object like the FoW revealer on the player you will set it to update frequently. Frequent updates mean frequent raycasts, so your door will automatically block the revealer when it's closed.

GrimmGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Tasharen Fog of War
« Reply #61 on: March 07, 2014, 03:43:33 PM »
Thanks for the information Aren.  Unfortunately, I have been unable to make a door that blocks and unblocks the player's revealer based on it being opened or closed.  Can you explain how to set this up?  Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #62 on: March 08, 2014, 01:51:29 PM »
As I mentioned, player's revealer simply performs raycasts from the Revealer's point to each of the points on the FoW map. If the door has a collider that will prevent the ray cast from reaching its target, then the point will be considered to be not visible from FoW's perspective. Just make sure that you've got your door's layer set up correctly to what FOW system will consider to be a blocker.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Tasharen Fog of War
« Reply #63 on: March 19, 2014, 02:53:41 AM »
Hi, for a turn based game can I turn off the FOW update frequency so that it only is updated when I call a manual update (when a character actually moves)? in other words I don't need the FOW to be updating anything during the player's turn, only once they end the turn the FOW needs to be updated to see if their characters can see new things.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #64 on: March 20, 2014, 02:41:14 AM »
Sure, just disable the FOWSystem component and re-enable it when you need it.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Tasharen Fog of War
« Reply #65 on: March 22, 2014, 06:59:35 PM »
Sure, just disable the FOWSystem component and re-enable it when you need it.

Hmm, but that makes the entire Fog disappear if I disable the component. I need it to stay on screen, just not update all the time.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #66 on: March 23, 2014, 03:10:21 AM »
Open FOWImageEffect, line 68:
  1.                 if (mFog == null || !mFog.enabled)
  2.                 {
  3.                         enabled = false;
  4.                         return;
  5.                 }
Change it to:
  1.                 if (mFog == null)
  2.                 {
  3.                         enabled = false;
  4.                         return;
  5.                 }
...and disabling FOWSystem will no longer disable the image effect.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Tasharen Fog of War
« Reply #67 on: March 25, 2014, 02:59:16 PM »
Cool, that works.

Is there an event I can create somewhere or subscribe to that would let me know when the rebuild of the FOW has completed so I can know when to turn off the FOWSystem component?

ie: when my character stops moving I call: myFOWRevealer.Rebuild(); which only works if the FOWSystem is enabled, so I would like to wait for that to happen but not just use a simple timer as that could get messy if another character moves within the timer time or something.

Also, is there a way to force the FOWSystem to update the textures instead of using the Update Frequency? so when I enable the FOWSystem component, I can just ask it to refresh the textures as well and then disable it. I tried making the mNextUpdate public and setting that to 0 but that seems to have unpredictable results and doesn't always work.
« Last Edit: March 25, 2014, 11:43:27 PM by capitalj »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #68 on: March 26, 2014, 03:40:46 AM »
FOW is updated on a separate thread so that it doesn't degrade game performance -- and all the logic happens inside FOWSystem.ThreadUpdate. The actual textures are updated in FOWSystem.UpdateTexture, which happens on the main (game) thread. If you want to be notified of them being updated, I would advise adding your callback logic there.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Tasharen Fog of War
« Reply #69 on: March 26, 2014, 08:09:04 PM »
I see. Ok well the issue with my implementation is that I don't know when the FOW logic is being updated, but it would be great to just call some function on FOWSystem to have everything updated at that time. So I'm just confused as to how to make this work in a turn based system like my game where I don't need any sort of update frequency happening, it's all manually called. Maybe the game flow is not clear, here's what I am looking to do:

There are 2 teams, which should not be able to see each other's characters if they are in the FOW.

1) Game start: each player's character's FOWRevealer is enabled or disabled depending on whether it is that character's team's turn. The FOW system then needs to update to reveal the current team's characters.

2) Player moves a character. The FOW needs to update to reveal the change based on the character's new position.

3) Player ends their turn. Each character's FOWRevealer is enabled or disabled again based on whether it is that character's team's turn. Then the FOW system needs to update to reveal the new team's characters and hide the old team's characters (if they are in the fog).


So what I don't understand is which components to enable/disable and force update when these 3 stages happen. I have the FOWRevealers all changing properly when the turns change, but the whole FOWsystem stuff is not really working, which must be because it's in the middle of some sort of updates or transitions when I have these stages happening. Sometimes it works perfectly but sometimes there is no update to the FOW.. or the FOWSystem.isvisible reports that a character is visible even though they are in the fog.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #70 on: March 26, 2014, 08:29:10 PM »
Sounds like you are overthinking it. Why do you care when the FoW is updated? Its performance hit is minimal. If you truly care about it for some reason, then just enable the FOWSystem when you know it will be updated, and then disable it some time later -- after some delay of a few seconds, for example. FOWSystem is meant to be real-time, not turn-based, so by trying to change it to be updated manually you are only creating headaches for yourself.

zmeinaz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #71 on: March 28, 2014, 08:27:31 AM »
Does this still require Unity Pro if I use the mobile shader implementation? The first page of this thread mentions that Unity Pro is required, but the Asset Store page does not.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tasharen Fog of War
« Reply #72 on: March 28, 2014, 10:20:58 AM »
Unity Pro is needed if you want to use the Image Effect-based approach. If you use the custom shader-based approach you don't need Pro. I just haven't gotten around to updating the info everywhere.

zmeinaz

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Tasharen Fog of War
« Reply #73 on: March 29, 2014, 04:24:41 PM »
How difficult would it be to use FOW on the x-y plane instead of the x-z plane in the example. I have a 2.5D game that I am trying to use this with, the character moves on the x-y plane. I have it partially working, however when the character moves on the y plane, the FOW is not updated. it works fine along the x-axis. I am using the shader implementation and have changed my shaders to use worldPos.xy instead of xz. What else would I need to change?

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Tasharen Fog of War
« Reply #74 on: March 29, 2014, 05:26:11 PM »
Sounds like you are overthinking it. Why do you care when the FoW is updated? Its performance hit is minimal. If you truly care about it for some reason, then just enable the FOWSystem when you know it will be updated, and then disable it some time later -- after some delay of a few seconds, for example. FOWSystem is meant to be real-time, not turn-based, so by trying to change it to be updated manually you are only creating headaches for yourself.

Yeah, maybe. My stuff has to run on mobile so I usually want to try to reduce the cpu use to free up room for other things. I'll keep working away at it. Unfortunately turning the component off and on doesn't really work, the results are not always the same and it doesn't update when it is enabled sometimes.

Unrelated question: what do I have to do to update the FOW system if I have terrain that is loaded at runtime? I've found that if a different terrain is loaded during the game start the FOW still reflects the terrain that was in place before the terrain was changed. Even when my characters move and call Rebuild on their revealers, it still doesn't update to match the new terrain. Is there a way to force it to redraw the FOW from scratch?