Page 9 of 13

Re: SpriteShadow (Duke3D Shadows) v1.85 [more optimization!]

Posted: Wed Jan 16, 2019 10:27 am
by Caligari87
@NightFright: Just open the .pk3 in SLADE or 7zip and delete the MENUDEF file. Everything else will continue working as normal, including the configuration cvars

8-)

Re: SpriteShadow (Duke3D Shadows) v1.85 [more optimization!]

Posted: Thu Jan 17, 2019 12:59 am
by NightFright
Actually the idea was to avoid cvar entries in the ini file, too. My apologies if that wasn't clear before.

Re: SpriteShadow (Duke3D Shadows) v1.85 [more optimization!]

Posted: Thu Jan 17, 2019 6:39 pm
by zrrion the insect
If you want that you'll probably have to DIY it

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Wed Jul 10, 2019 9:06 am
by Nash
Update July 10th 2019 (version 1.9)

- GZDoom version bump to 4.1.3.
- Do not serialize shadows. This means the shadow actors do not get written into saved games. Might help with multiplayer saved game stability.
- Github repository added.

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Mon Jul 29, 2019 10:03 pm
by vsonnier
Hello Nash, thank you for your SpriteShadow code !
I've adapted it with some changes you may found interesting:

- The Z_ShadeMe inventory is still added for all +ISMONSTER like you did, and is never removed afterwards, rather only the Z_Shadow is enebled/disabled.
- Added a CVAR to enable/disable shadows
- Cleanup of Shadows based on age, not distance re-computing.

Z_ShadeMe:

Code: Select all

class Z_ShadeMe : CustomInventory
{
	// reference to the shadow
	Z_SpriteShadow myShadow;
    
    int countFromLastUpdate;
    int maxMonsterShadowAgeInTicks;
    bool shadowCloseEnoughToPlayer;
    
...
    
    void setEnableShadow(bool bEnable) {
    
        countFromLastUpdate = 0;
        
        if (bEnable != self.shadowCloseEnoughToPlayer) {
         
            if (bEnable) {
                
                if (!self.myShadow) {
                
                    let sh = Z_SpriteShadow(Spawn("Z_SpriteShadow", Owner.Pos, NO_REPLACE));
            
                    if (sh)
                    {
                        self.myShadow = sh;
                        self.myShadow.ownerRef = Owner;
                    }
        
                }
                
            } else {
            
                 //destroy the shadow because disabled, or too far from the player.
                if (self.myShadow) {
                    self.myShadow.Destroy();
                    self.myShadow = null;
                }                 
            }
            //update
            self.shadowCloseEnoughToPlayer = bEnable; 
        }
    }
    
    override void PostBeginPlay() {
        //by default is false, and is enabled in Handler WorldTick(): 
        self.shadowCloseEnoughToPlayer = false;
        //if countFromLastUpdate is bigger than 2s (35 * 2 ticks) remove the shadow unconditionally.
        maxMonsterShadowAgeInTicks = 35 * 2; 
        Super.PostBeginPlay();
    }
    
    override void Tick() {
     
        countFromLastUpdate++;

        //Cleanup : shadow is too old, it means it has not been tested
        //for player proximity for a long time, which means it is indeed too far !
        if (countFromLastUpdate > maxMonsterShadowAgeInTicks) {
                self.setEnableShadow(false);
        }
        
        Super.Tick();
    }
    
	...
}
SpriteShadowHandler:

Code: Select all

class SpriteShadowHandler : EventHandler
{
    int countTicks;
    
	// spawn shadows for monsters
	override void WorldThingSpawned(WorldEvent e)
	{
		if (e.Thing.bIsMonster && !e.Thing.CountInv("Z_ShadeMe"))
		{   
                      //Every monster got a Z_ShadeMe inventory token, but your shadow is effectively enabled or not later. 
			e.Thing.A_GiveInventory("Z_ShadeMe", 1);   
		}
	}

    ...

  override void WorldTick(void)
  { 
        //0) Save game : do not serialize shadows.
		if (gameaction == ga_savegame || gameaction == ga_autosave)
		{
			ThinkerIterator it = ThinkerIterator.Create("Z_ShadeMe");
			Z_ShadeMe shadeMe;
			while (shadeMe = Z_ShadeMe(it.Next()))
			{   
                              //VSO: Destroy all shadows, NOT the Z_ShadeMe !
                             // monster Shadows will be re-created at nexts WorldTick().
                            if (shadeMe) {
                              shadeMe.setEnableShadow(false);
                           }
		       }
                       //VSO: Trick so that the next Shadow re-creation will only occur in 35 ticks = 1s.
			countTicks = 0;
                       return;
		}
        
        countTicks++;
       
        // no need to update this too often
        if (countTicks % 35 != 0) return;
               
        PlayerInfo p = players[consoleplayer];
        if (!p) return;

        double shadowDist = Cvar.FindCvar("spriteshadowdistance").GetFloat();
        bool shadows_enabled = Cvar.FindCvar("spriteshadowenabled").GetBool();
        
		//1) update shadows enabling flag to Z_ShadeMe according to distance to player:
        // look for shadow casters around you
        BlockThingsIterator it = BlockThingsIterator.Create(p.mo, shadowDist);
        while (it.Next())
        {
            Actor mo = it.thing;
            //only consider monster-tagged things:
            if (mo.bIsMonster)
            {
                let shadeMe = Z_ShadeMe(mo.FindInventory("Z_ShadeMe"));
                
                         if (shadeMe)
                         {
                                if (shadows_enabled && (mo.Distance2DSquared(p.mo) < shadowDist ** 2)) {
                     
                                        shadeMe.setEnableShadow(true);
                                } else {
                                       shadeMe.setEnableShadow(false);
                                }
                        }
	        } 
            }//end while.
   }
}

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Mon Jul 29, 2019 11:20 pm
by Nash
Can you make a pull request at https://github.com/nashmuhandes/SpriteShadow ? It is more convenient to review code changes that way.

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Tue Jul 30, 2019 10:37 am
by vsonnier
Can you make a pull request at https://github.com/nashmuhandes/SpriteShadow ? It is more convenient to review code changes that way.
Thanks, I'll do it properly in a few days.

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Fri Aug 02, 2019 2:40 am
by vsonnier
Hello Nash, I've submitted a PR you can look at: https://github.com/nashmuhandes/SpriteShadow/pull/1

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Fri Aug 09, 2019 2:54 pm
by NightFright
Did anybody have crashes to console with this? I have had some recently. Levels play fine after reloading the last savegame, though. Next time it happens I'll note down the message to track down the issue.

My impression is this happens since v1.9, can't remember the mod ever causing trouble before.

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Tue Aug 13, 2019 12:08 pm
by ZellSF
1.9 seems to have broken something slightly.

In MAP09 of Valiant archviles teleport around in the starting areas of the map. With 1.9 they leave their shadows when they teleport away, 1.85 works fine.

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Tue Aug 13, 2019 6:07 pm
by Nash
Thanks, I've opened an issue on Github: https://github.com/nashmuhandes/SpriteShadow/issues/2

(Please feel free to leave other bug reports on the Github)

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Thu Aug 15, 2019 5:59 pm
by panzerfaustmna


Hi, ive got this error while playing brutal doom on gz 4.1.3 , its happens when iam using brutality on enemys
sry 4 bad english =)

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Thu Aug 15, 2019 8:17 pm
by Nash
@panzerfaustmna: thank you, added to Github issues. Will fix when I have more spare time. :) https://github.com/nashmuhandes/SpriteShadow/issues/3

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Sat Aug 17, 2019 12:36 am
by vsonnier
@panzerfaustmna: thank you, added to Github issues. Will fix when I have more spare time. :) https://github.com/nashmuhandes/SpriteShadow/issues/3
I've asubmitted a PR fixing this problem that I have encountered as well.

Re: SpriteShadow (Duke3D Shadows) v1.9

Posted: Mon Aug 19, 2019 4:00 am
by Nash
vsonnier wrote:
@panzerfaustmna: thank you, added to Github issues. Will fix when I have more spare time. :) https://github.com/nashmuhandes/SpriteShadow/issues/3
I've asubmitted a PR fixing this problem that I have encountered as well.
Thanks, this is an easy one. :)