View Issue Details

IDProjectCategoryView StatusLast Update
0004514The Dark ModTweakingpublic22.05.2024 15:04
ReporterGoldwell Assigned Tostgatilov  
PrioritynormalSeveritymajorReproducibilityrandom
Status resolvedResolutionfixed 
PlatformPCOSWindowsOS Version10
Product VersionTDM 2.05 
Target VersionTDM 2.08Fixed in VersionTDM 2.08 
Summary0004514: Game runs sluggish randomly
DescriptionSometimes when booting up TDM I find the game runs quite sluggish, in the main menu I will be getting 40-50 fps rather than my normal 60fps and when playing a mission the game runs worse than it normally would.

After restarting TDM and ensuring that the main menu is a solid 60fps after experiencing the bug I find that the same areas that were sluggish are no longer.

This happens on any mission and I've only experienced this bug in 2.05.
Steps To ReproduceJust run the dark mod and see if you get 40-50 fps in the main menu, restart the game until you have 60 fps in the main menu (usually takes me 2-5 restarts)

If the game boots with a sub par frame rate in the main menu then any subsequent missions will run slower than usual, using the restart fix seems to restore performance to full capacity again.
TagsNo tags attached.
Attached Files
4514_sync_game_and_vsync.patch (3,104 bytes)   
Index: framework/Common.cpp
===================================================================
--- framework/Common.cpp	(revision 7565)
+++ framework/Common.cpp	(working copy)
@@ -2519,8 +2519,7 @@
 #define MAX_ASYNC_STATS			1024
 
 asyncStats_t	com_asyncStats[MAX_ASYNC_STATS];		// indexed by com_ticNumber
-int prevAsyncMsec;
-int	lastTicMsec;
+int64_t lastTicUsec;
 
 void idCommonLocal::SingleAsyncTic( void ) {
 	// main thread code can prevent this from happening while modifying
@@ -2571,31 +2570,31 @@
 		return;
 	}
 
-	const int msec = Sys_Milliseconds();
-	if ( !lastTicMsec ) {
-		lastTicMsec = msec - USERCMD_MSEC;
+	const int64_t usec = Sys_GetTimeMicroseconds();
+	if ( !lastTicUsec ) {
+		lastTicUsec = usec - USERCMD_USEC;
 	}
 
-	int ticMsec = USERCMD_MSEC;
+	int64_t ticUsec = USERCMD_USEC;
 	const float timescale = com_timescale.GetFloat();
 
 	// don't skip too many
 	if ( timescale == 1.0f ) {
-		if ( lastTicMsec + (10 * USERCMD_MSEC) < msec ) {
-			lastTicMsec = msec - (10 * USERCMD_MSEC);
+		if ( lastTicUsec + (10 * USERCMD_USEC) < usec ) {
+			lastTicUsec = usec - (10 * USERCMD_USEC);
 		}
 	}
 	// the number of msec per tic can be varies with the timescale cvar
 	else {								// i.e if ( timescale != 1.0f )
-		ticMsec /= timescale;
-		if ( ticMsec < 1 ) {
-			ticMsec = 1;
+		ticUsec /= timescale;
+		if ( ticUsec < 1 ) {
+			ticUsec = 1;
 		}
 	}
 
-	while ( lastTicMsec + ticMsec <= msec ) {
+	while ( lastTicUsec + ticUsec <= usec ) {
 		SingleAsyncTic();
-		lastTicMsec += ticMsec;
+		lastTicUsec += ticUsec;
 	}
 }
 
Index: framework/UsercmdGen.h
===================================================================
--- framework/UsercmdGen.h	(revision 7565)
+++ framework/UsercmdGen.h	(working copy)
@@ -27,6 +27,9 @@
 const int USERCMD_HZ			= 60;			// 60 frames per second
 const int USERCMD_MSEC			= 1000 / USERCMD_HZ;
 
+//stgatilov: this macros is used only for synchronizing main tic with vsync
+const int USERCMD_USEC			= 16650;		// ~60.06 Hz --- a bit higher than vsync
+
 // ButtonState inputs; originally from UsercmdGen.cpp, left out of SDK by accident
 // sourced from http://www.doom3world.org/phpbb2/viewtopic.php?f=26&t=18587&p=170143
 typedef enum {
Index: sys/win32/win_main.cpp
===================================================================
--- sys/win32/win_main.cpp	(revision 7565)
+++ sys/win32/win_main.cpp	(working copy)
@@ -1015,9 +1015,14 @@
 		common->Error( "idPacketServer::Spawn: CreateWaitableTimer failed" );
 	}
 
+	//stgatilov: run idCommonLocal::Async every 3 ms
+	//ideally, game tic should be incremented every 16.66 ms, but we cannot specify interval up to microseconds
+	//incrementing it every 16 ms causes double frames =( so we do it simply more often
+	const int intervalMS = 3;		//USERCMD_MSEC;
+
 	LARGE_INTEGER	t;
 	t.HighPart = t.LowPart = 0;
-	SetWaitableTimer( hTimer, &t, USERCMD_MSEC, NULL, NULL, TRUE );
+	SetWaitableTimer( hTimer, &t, intervalMS, NULL, NULL, TRUE );
 
     Sys_CreateThread( Sys_AsyncThread, NULL, THREAD_ABOVE_NORMAL, threadInfo, "Async", g_threads,  &g_thread_count );
 
4514_sync_game_and_vsync.patch (3,104 bytes)   

Relationships

related to 0004696 resolvedstgatilov At high FPS player footsteps don't always play 
related to 0004865 resolvedcabalistic Improve the way how FPS cap works (uncapped FPS) 
related to 0005855 closedstgatilov Cutscenes sound out of sync without uncapped FPS 
related to 0005575 resolvedstgatilov When Uncapped FPS is Off, Video Cutscene Loses Audio Sync 

Activities

duzenko

duzenko

27.05.2017 11:18

developer   ~0008877

Does com_fixedTic 1 help?
Goldwell

Goldwell

27.05.2017 11:26

developer   ~0008878

I just tried that and here's what I found.

I ran TDM - Got steady 60fps on the main menu
Closed TDM and opened it again - FPS was hovering around 40-50fps on the main menu
I put in the console command you suggested - Main menu shot upto 2000 fps

Ingame turning that command off causes the game to really slow down, but turning it on causes it to become ultra fluid, and feel a little strange in some ways (hard to explain).

I tried using that console command on a version of the game that's running 60fps in the main menu and I had the same result of fluidity. So from that I would conclude that the fixTic command seems to have the same outcome regardless of whether the core game has 40~fps or 60~fps in the menu.
duzenko

duzenko

27.05.2017 13:36

developer   ~0008879

I think this issue was discussed recently in forum: http://forums.thedarkmod.com/topic/18800-micro-stutter-while-moving-solved/
So did you like the fixed-tic generally or rather disliked it?
It's best combined with vsync on - please try that.
Personally I think fixed-tic should be on by default but there are still some minor physics bugs, however rare.

user81

28.03.2018 09:24

  ~0010190

@Goldwell, can this be closed or did you want to keep it open..?
Goldwell

Goldwell

29.03.2018 19:31

developer   ~0010327

Yes it's safe to say that the issue has been fixed now, at least I haven't run into it yet during 2.06 testing and I don't think anyone else has either.

user81

30.03.2018 08:07

  ~0010330

see last note.
stgatilov

stgatilov

14.07.2018 08:41

administrator   ~0010678

Last edited: 14.07.2018 08:48

Bumped into this exact issue.
Here is the forum topic:
  http://forums.thedarkmod.com/topic/19540-sometimes-tdm-is-slow-and-laggy/

The hunt for this issue was not fun, and I even though I guess I have fixed it, I still cannot explain it.

Long story short, the game is modeled in 16 ms tics, but vsync normally has about 16.66 ms. Obviously, this leads to small but noticeable jumps about 1.5 times a second. To see them, look at some close and well-lit surface and slide to the left continuously (while crouched/creeping).
Moreover, the same desynchronization between game tics and vsync seems to make game slow on some runs. Once again: I cannot explain it well, but after my changes the problem seems to be gone.

Attached the patch 4514_sync_game_and_vsync.patch.
Also there are good changes of Sleep(1) in the main loop from Cabalistic (in the forum discussion).

stgatilov

stgatilov

06.03.2019 15:19

administrator   ~0011672

Committed the fixes:

rev 8034: Perform tick every 16.66 ms (synchronize with default vsync):
  4514_sync_game_and_vsync.patch attached
rev 8035: Cabalistic's fix (wait for trigger instead of Sleep(1)):
  http://forums.thedarkmod.com/topic/19540-sometimes-tdm-is-slow-and-laggy/#entry424571
rev 8036: Reenforce com_maxfps limit with busywait loop:
  http://bugs.thedarkmod.com/view.php?id=4865#c10685
stgatilov

stgatilov

08.03.2019 06:47

administrator   ~0011676

The max FPS limit was buggy, leading to infinite loop.
Commits 8039 and 8040 fix this.
stgatilov

stgatilov

12.06.2021 12:46

administrator   ~0014094

Last edited: 27.12.2021 04:07

I think this change broke lengths of ROQ videos.

It you set "com_fixedTic 0" and play some briefing video, the video will come to the end, then restart from scratch for a few seconds then stop.
With "com_fixedTic 1", the same video will stop at its designated end.

I think this is caused by timing discrepancy.
The player increases video time by 16 ms every 16.66 ms of astronomical time, i.e. the video playback is faster by 4%.
That's why the video ends a bit earlier, and then starts from scratch.

UPDATE: Created 0005855
stgatilov

stgatilov

22.05.2024 15:04

administrator   ~0016706

The fix is reverted due to 0005575 and 0005855, and due to the fact that uncapped FPS is the default mode now.

Issue History

Date Modified Username Field Change
29.04.2017 16:58 Goldwell New Issue
27.05.2017 11:18 duzenko Note Added: 0008877
27.05.2017 11:26 Goldwell Note Added: 0008878
27.05.2017 13:36 duzenko Note Added: 0008879
28.03.2018 09:24 user81 Note Added: 0010190
29.03.2018 19:31 Goldwell Note Added: 0010327
29.03.2018 19:47 nbohr1more Status new => resolved
29.03.2018 19:47 nbohr1more Resolution open => unable to reproduce
29.03.2018 19:47 nbohr1more Fixed in Version => TDM 2.06
29.03.2018 19:47 nbohr1more Target Version => TDM 2.06
29.03.2018 20:02 nbohr1more Assigned To => stgatilov
30.03.2018 03:43 stgatilov Assigned To stgatilov =>
30.03.2018 08:07 user81 Note Added: 0010330
30.03.2018 08:07 user81 Status resolved => closed
30.03.2018 08:07 user81 Assigned To => user81
14.07.2018 08:41 stgatilov Note Added: 0010678
14.07.2018 08:41 stgatilov Assigned To user81 => stgatilov
14.07.2018 08:41 stgatilov Status closed => confirmed
14.07.2018 08:47 stgatilov File Added: 4514_sync_game_and_vsync.patch
14.07.2018 08:48 stgatilov Note Edited: 0010678
14.07.2018 08:48 stgatilov Target Version TDM 2.06 => TDM 2.08
04.03.2019 16:33 stgatilov Relationship added related to 0004696
04.03.2019 16:33 stgatilov Relationship added related to 0004865
06.03.2019 15:19 stgatilov Note Added: 0011672
06.03.2019 15:20 stgatilov Status confirmed => resolved
06.03.2019 15:20 stgatilov Fixed in Version TDM 2.06 => TDM 2.08
06.03.2019 15:20 stgatilov Resolution unable to reproduce => fixed
08.03.2019 06:47 stgatilov Note Added: 0011676
12.06.2021 12:46 stgatilov Note Added: 0014094
27.12.2021 04:07 stgatilov Note Edited: 0014094
27.12.2021 04:07 stgatilov Relationship added related to 0005855
22.05.2024 14:27 stgatilov Relationship added related to 0005575
22.05.2024 15:04 stgatilov Note Added: 0016706