# HG changeset patch
# User CrimsonDusk
# Date 1360540349 -7200
#      Mon Feb 11 01:52:29 2013 +0200
# Node ID 8b190259f89ce2c313b006e335eba16fb369dc3a
# Parent  460a4505ef46193f2d5080d29a62c94b0a0cb21e
Restructured this a bit..

diff -r 460a4505ef46 -r 8b190259f89c src/g_game.cpp
--- a/src/g_game.cpp	Mon Feb 11 01:19:31 2013 +0200
+++ b/src/g_game.cpp	Mon Feb 11 01:52:29 2013 +0200
@@ -3190,6 +3190,20 @@
 		players[ulIdx].secretcount = 0;
 	}
 
+	// [Dusk] Reset all X/Y offsets on the map.
+	for ( ULONG i = 0; i < (ULONG)numsides; i++ )
+	for ( ULONG j = 0; j < 3; j++ )
+	{
+		const struct {fixed_t* ofs, *savedofs;} offsetInfo[2] = 
+		{
+			{&sides[i].textures[j].xoffset, &sides[i].textures[j].SavedXOffset},
+			{&sides[i].textures[j].yoffset, &sides[i].textures[j].SavedYOffset},
+		};
+
+		for ( ULONG k = 0; k < 3; k++ )
+			*( offsetInfo[k].ofs ) = *( offsetInfo[k].savedofs );
+	}
+
 	// This is all we do in client mode.
 	if (( NETWORK_GetState( ) == NETSTATE_CLIENT ) ||
 		( CLIENTDEMO_IsPlaying( )))
@@ -3305,26 +3319,6 @@
 
 				bSendTextureUpdate = true;
 			}
-
-			// [Dusk] Reset the X/Y offsets
-			for ( ULONG j = 0; j < 3; j++ )
-			{
-				const struct {fixed_t* ofs, *savedofs;} offsetInfo[2] = 
-				{
-					{&side->textures[j].xoffset, &side->textures[j].SavedXOffset},
-					{&side->textures[j].yoffset, &side->textures[j].SavedYOffset},
-				};
-
-				for ( ULONG k = 0; k < 2; k++ )
-				{
-					if ( *( offsetInfo[k].ofs ) != *( offsetInfo[k].savedofs ))
-					{
-						Printf ("Reset %lu.%lu.%lu\n", i, j, k);
-						*( offsetInfo[k].ofs ) = *( offsetInfo[k].savedofs );
-						SERVERCOMMANDS_SetTextureOffset( side - sides, j, k );
-					}
-				}
-			}
 		}
 
 		// If we're the server, tell clients about this texture change.
diff -r 460a4505ef46 -r 8b190259f89c src/p_lnspec.cpp
--- a/src/p_lnspec.cpp	Mon Feb 11 01:19:31 2013 +0200
+++ b/src/p_lnspec.cpp	Mon Feb 11 01:52:29 2013 +0200
@@ -2654,6 +2654,9 @@
 	if (arg0 == 0 || arg3 < 0 || arg3 > 1)
 		return false;
 
+	// [Dusk] We wish to sync any texture offsets here to clients
+	g_bSyncTexOffsetChange = true;
+
 	for(int line = -1; (line = P_FindLineFromID (arg0, line)) >= 0; )
 	{
 		if (lines[line].sidenum[arg3] != NO_SIDE)
@@ -2694,6 +2697,10 @@
 			}
 		}
 	}
+
+	// [Dusk]
+	g_bSyncTexOffsetChange = false;
+
 	return true;
 }
 
diff -r 460a4505ef46 -r 8b190259f89c src/p_local.h
--- a/src/p_local.h	Mon Feb 11 01:19:31 2013 +0200
+++ b/src/p_local.h	Mon Feb 11 01:52:29 2013 +0200
@@ -430,6 +430,8 @@
 // [RH] 
 const secplane_t * P_CheckSlopeWalk (AActor *actor, fixed_t &xmove, fixed_t &ymove);
 
+extern bool g_bSyncTexOffsetChange;
+
 //----------------------------------------------------------------------------------
 //
 // Added so that in the source there's a clear distinction between
diff -r 460a4505ef46 -r 8b190259f89c src/p_map.cpp
--- a/src/p_map.cpp	Mon Feb 11 01:19:31 2013 +0200
+++ b/src/p_map.cpp	Mon Feb 11 01:52:29 2013 +0200
@@ -107,6 +107,9 @@
 // Temporary holder for thing_sectorlist threads
 msecnode_t* sector_list = NULL;		// phares 3/16/98
 
+// [Dusk] When updating texture offsets, should we sync them to the client?
+bool g_bSyncTexOffsetChange = false;
+
 //==========================================================================
 //
 // PIT_FindFloorCeiling
@@ -6549,7 +6552,7 @@
 //
 // P_NetworkTexOffsetChange
 //
-// [Dusk] Network + map reset savvy texture offset changing callback.
+// [Dusk] Network savvy texture offset changing callback.
 // NOTE: This is declared in r_defs.h, since side_t calls this function.
 //
 //=============================================================================
@@ -6560,9 +6563,8 @@
 	side_t::part* tex = &side->textures[ulWhich];
 	fixed_t ofs = ( bY ? tex->yoffset : tex->xoffset );
 
-	// If the offset was changed mid-game, we'll have to tell clients that it was.
-	// If it was set by the map, we may not call this or we'll needlessly waste bandwidth.
-	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( g_bLoadingMap == false ))
+	// Sync the change to clients if so desired
+	if (( g_bSyncTexOffsetChange == true ) && ( NETWORK_GetState( ) == NETSTATE_SERVER ))
 		SERVERCOMMANDS_SetTextureOffset( side - sides, ulWhich, bY );
 }
 
diff -r 460a4505ef46 -r 8b190259f89c src/p_setup.cpp
--- a/src/p_setup.cpp	Mon Feb 11 01:19:31 2013 +0200
+++ b/src/p_setup.cpp	Mon Feb 11 01:52:29 2013 +0200
@@ -228,9 +228,6 @@
 static void P_AllocateSideDefs (int count);
 static void P_SetSideNum (DWORD *sidenum_p, WORD sidenum);
 
-// [Dusk] Is a map being currently loaded?
-bool g_bLoadingMap = false;
-
 
 
 
@@ -3769,9 +3766,6 @@
 	int i;
 	bool buildmap;
 
-	// [Dusk] We are now loading a map
-	g_bLoadingMap = true;
-
 	for (i = 0; i < (int)countof(times); ++i)
 	{
 		times[i].Reset();
@@ -4380,9 +4374,6 @@
 
 	// Call Init function to set sector colors if in Domination
 	DOMINATION_Init();
-
-	// [Dusk] Done loading the map
-	g_bLoadingMap = false;
 }
 
 
diff -r 460a4505ef46 -r 8b190259f89c src/p_setup.h
--- a/src/p_setup.h	Mon Feb 11 01:19:31 2013 +0200
+++ b/src/p_setup.h	Mon Feb 11 01:52:29 2013 +0200
@@ -112,7 +112,4 @@
 int GetUDMFInt(int type, int index, const char *key);
 fixed_t GetUDMFFixed(int type, int index, const char *key);
 
-// [Dusk]
-extern bool g_bLoadingMap;
-
 #endif
