Jump to content

Joelma's Time Control


Donnovan

Recommended Posts

NEW VERSION OF TIME_CONTROL.SQF (V.3)

//===========================================
// Time share: 50% day, 30% dusk, 20% night.
//===========================================
private ["_multi","_maxFPS","_overcast","_fog"];

// General Settings
_multi = 2; 		// 1 for a 4 hours day, 4/3 for a 3 hours day, 2 a for a 2 hours day.
_maxFPS = true; 	// true = remove clouds and set cycles to minimum for maximum fps.
                        // true require disabled dynamic weather effects.

// increase clouds smoothness and possibily decrease fps
_xtraSmooth = 1.0; 	// Try values from 1.0 to 1.5 - Powerfull value.

// Static weather, if you have disabled dynamic weather effects.
_overcast = 0.25; 	// set overcast, from 0 to 1. If _maxFPS = true, it will be 0.
_fog = 0; 		// set fog, from 0 to 1. 0 - no fog, 1 - full fog.

if (_maxFPS && !isNil "drn_fnc_DynamicWeather_SetWeatherLocal") then {
	drn_fnc_DynamicWeather_SetWeatherLocal = {};
};
if (isNil "drn_fnc_DynamicWeather_SetWeatherLocal" || _maxFPS) then {
	if (_maxFPS) then {0 setOvercast 0;} else {0 setOvercast _overcast;};
	0 setFog _fog;
	setWind [0.3, 0.4, true];
};
donn_skipFix = 0;
donn_multi=_multi;
donn_maxFPS=_maxFPS;
if (_maxFPS) then {donn_xs = 1.0;} else {donn_xs = _xtraSmooth;};
if (!isServer) then {
	"cad_pvar_server_date" addPublicVariableEventHandler {_this call donn_setdate;};
	changeCycles = {
		private ["_col","_cya","_speed"]; _speed = _this select 0;
		_cya = [[5,13],[5,15],[5,18],[5,21],[5,23],[5,30],[5,40],[5,45],[5,50]];
		_col = 1; if (donn_maxFPS) then {_col = 0;};
		switch true do {
			case (_speed <=   4.0): {donn_cycles = (_cya select 0 select _col)+((ceil((_cya select 0 select _col)*(donn_xs-1))) min 10)};
			case (_speed <=   6.7): {donn_cycles = (_cya select 1 select _col)+((ceil((_cya select 1 select _col)*(donn_xs-1))) min 10)};
			case (_speed <=   8.9): {donn_cycles = (_cya select 2 select _col)+((ceil((_cya select 2 select _col)*(donn_xs-1))) min 10)};
			case (_speed <=  13.4): {donn_cycles = (_cya select 3 select _col)+((ceil((_cya select 3 select _col)*(donn_xs-1))) min 10)};
			case (_speed <=  20.0): {donn_cycles = (_cya select 4 select _col)+((ceil((_cya select 4 select _col)*(donn_xs-1))) min 10)};
			case (_speed <=  40.0): {donn_cycles = (_cya select 5 select _col)+((ceil((_cya select 5 select _col)*(donn_xs-1))) min 10)};
			case (_speed <=  80.0): {donn_cycles = (_cya select 6 select _col)+((ceil((_cya select 6 select _col)*(donn_xs-1))) min 10)};
			case (_speed <= 160.0): {donn_cycles = (_cya select 7 select _col)+((ceil((_cya select 7 select _col)*(donn_xs-1))) min 10)};
			case (_speed >  160.0): {donn_cycles = (_cya select 8 select _col)+((ceil((_cya select 8 select _col)*(donn_xs-1))) min 10)};
		};
	};
	donn_setdate = {
		private ["_maxError","_sendTime","_dateSer","_dateCli","_date_diff"];
		
		if (isNil "drn_fnc_DynamicWeather_SetWeatherLocal") then {
			if (_maxFPS) then {15 setOvercast 0;} else {15 setOvercast _overcast;};
			15 setFog _fog;
			setWind [0.3, 0.4, true];
		};
		
		_dateSer = ((_this select 1) select 0);
		_dateCli = date;
		_date_diff = (
			((_dateSer select 0) - (_dateCli select 0))*12*31*24 +
			((_dateSer select 1) - (_dateCli select 1))*31*24 +
			((_dateSer select 2) - (_dateCli select 2))*24 +
			((_dateSer select 3) - (_dateCli select 3)) +
			((_dateSer select 4) - (_dateCli select 4))/60
		);
		diag_log format ["DATE DIFFERENCE: %1", _date_diff*60];
		if (isNil "donn_speed") then {
			donn_speed = ((_this select 1) select 1);
			[donn_speed*donn_multi] call changeCycles;
			donn_skipExit = false;
		} else {
			if (((_this select 1) select 1) != donn_speed) then {
				donn_speed = ((_this select 1) select 1);
				[donn_speed*donn_multi] call changeCycles;
				donn_skipExit = true;
			};
		};
		_sendTime = 30;
		donn_skipFix = (_date_diff*3600)/(donn_cycles*_sendTime);
	};
};
waitUntil {!isNil "donn_speed" && !isNil "donn_skipExit"};
if (isServer) then {donn_cycles = 5;};
[] spawn {
	while {true} do {
		private ["_speed","_cycleTime","_timePixel","_skipTime","_tickTimeLenAvg","_tickTimeInitial","_tickTime","_tickTimeLenLast"];
		_speed = donn_speed*donn_multi;
		_cycleTime = 1/donn_cycles;
		_timePixel = 0;
		_skipTime = 0;
		_tickTimeLenAvg = _cycleTime;
		_tickTimeInitial = diag_tickTime;
		_tickTime = _tickTimeInitial;
		donn_skipExit=false;
		while {!donn_skipExit} do {
			skipTime ((_timePixel+donn_skipFix)/3600);
			_skipTime=_skipTime+_timePixel;
			_tickTimeLenLast=diag_tickTime-_tickTime;
			_tickTimeLenAvg=(_tickTimeLenAvg*3+_tickTimeLenLast)/4;
			sleep (_cycleTime*2-_tickTimeLenAvg);
			_tickTime=_tickTime+_tickTimeLenLast;
			_timePixel=(_speed-1)*(_tickTime-_tickTimeInitial)-_skipTime;
		};
	};
};
Link to comment
Share on other sites

Wow. This latest version is the worst so far... sorry... My time was whizzing forward and backwards. One moment, the time is moving VERY VERY fast forward, then it's going backwards. Some players were seeing it switching back and forth between day and night. Tested it on my test server by myself and it was fine. On my server with 20 players, everyone had problems with it. :(

Link to comment
Share on other sites

I can't make tests now, i'm with my girlfriend, sorry...  :)

 

When i got home, at the night of monday, i will make tests.

 

1 - Until that, you can, may be, check if you have added the server side code.

2 - Check for rpt errors on the client side, and may be server side too.

3 - Since your test server runs it ok, try to have at least 2 players at your test server and see if you two are in sync (spectate the other player and ask hin to put the crosshair in the sun/moon, then see if his crosshair is really at the sun/moon, or just compare watchs, like you did before).

 

I don't believe the code healthy is dependant on player number, so if you run it ok on your test server, i believe it is ok. Just sync tests remains, this is why i askyou to have at least 2 players and check sync.

Link to comment
Share on other sites

Wow. This latest version is the worst so far... sorry... My time was whizzing forward and backwards. One moment, the time is moving VERY VERY fast forward, then it's going backwards. Some players were seeing it switching back and forth between day and night. Tested it on my test server by myself and it was fine. On my server with 20 players, everyone had problems with it. :(

Same here. Should note that of the 30+ people online only half had the problem.

Link to comment
Share on other sites

This fast forward/backward time happens only when the player firstly conect to the server, and it remains from 0 to 30 seconds?

This is the client gaining server sync. If so, it's a matter to make this initial sync instantly and not along 30 seconds.

What do you think?

To make the initial sync instantly you need to change some code in time_control.sqf:

Change that:

		if (isNil "donn_speed") then {
			donn_speed = ((_this select 1) select 1);
			[donn_speed*donn_multi] call changeCycles;
			donn_skipExit = false;
		} else {
			if (((_this select 1) select 1) != donn_speed) then {
				donn_speed = ((_this select 1) select 1);
				[donn_speed*donn_multi] call changeCycles;
				donn_skipExit = true;
			};
		};
to that:

		if (isNil "donn_speed") then {
                        setDate _dateSer; //NEW LINE 1!
                        _date_diff = 0; //NEW LINE 2!
			donn_speed = ((_this select 1) select 1);
			[donn_speed*donn_multi] call changeCycles;
			donn_skipExit = false;
		} else {
			if (((_this select 1) select 1) != donn_speed) then {
				donn_speed = ((_this select 1) select 1);
				[donn_speed*donn_multi] call changeCycles;
				donn_skipExit = true;
			};
		};
Link to comment
Share on other sites

This may be the error correction generating a bigger error in the correction process.

With the new code (post #61), error at connection will be 0 or near zero, so the error correction process will do it well.

The error correction process is intended to fix small sync errors and not the initial error that may be of many hours.

Link to comment
Share on other sites

BetterDeadThanZed,

Have you tried the new code?

About the FPS decrease along time:

I noticed the fps decrease along time even with the server not running Joelma's Time Control. So this decrease over time must be something related to the engine/mod/game.

There is a decrease in fps, yes, but the decrease over time is not Joelma's Time Control fault.

Link to comment
Share on other sites

HellWalker, i found what was causing the out of sync in the player connection.

I'm running a new version that works great, but need to do some work on it for a release.

Thankyou for the feedback, hope this next release comes soon, and hope its final.

 

I hope you've got the bugs taken care of. I'd love to use this!

Link to comment
Share on other sites

Yea, I stopped using this as players were reporting huge spikes in lag/dysync and I had a few ppl report that the time cycle was not working right was not getting dark for them, I stood around for 3 hours the one day and watched it get dark so I was unsure what to do really haha. Hope this gets sorted, have been using random day/night cycles to tied me over until this is working better!

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...