Review emmisiveLights script
Closed, ResolvedPublic

Description

While debugging scripts running on my server I noticed this script is pretty much always running.

"ca\structures_c\Misc_Powerlines\emmisiveLights.sqf"

Taking a quick glance it seems the script is to handle turning street lights on or off based on lighting levels.

After reviewing the script it appears to be designed so that if the CUP_lampState changes (due to lighting) or if you are 100m away from the last checked position it will run a nearObjects for "Land_PowLines_WoodL" in 400m and update their object material if it does not match the expected value for the current CUP_lampState.

Problem is the logic that is supposed to make this script run only every 100m of movement is flawed and never sets _prevPos to the current position so this script will just run every .5 seconds.

It also seems odd that this script would be running on machines that don't have an interface as this is just a visual effect? (unless this affects AI??)

Full script:

0 spawn {
	sleep .1;
	
	_prevPos = [0,0,0];
	
	CUP_stopLampCheck = false;
	
	0 spawn {
		#define cfg(a) getNumber (configFile >> "CfgWorlds" >> worldName >> a)
		_lat = -cfg("latitude");
		_long = cfg("longitude");
		_gmt = round(_long/360 * 24);
		_a = 4*(_long - 15 * _gmt);

		#define sun floor sunOrMoon
		#define dec (23.45 * sin _b)

		_pre = -1;
		_pre_1 = 0;
		
		waitUntil {
			if ((sun == 1) || {sun != _pre}) then {
				_pre = sun;
				
				_b = 360/365 * (round(((date select 1)-1)*30.4375) + (date select 2) - 81);
				_st = asin(sin dec * sin _lat + cos dec * cos _lat * cos (15 * ((daytime + (_a + (9.87*sin(2*_b) - 7.53*cos _b - 1.5*sin _b))/60)-12))) < 3.97;
				if !(_st isEqualTo _pre_1) then {
					_pre_1 = _st;
					CUP_lampState = _st;
				};
				
				sleep .75;
			};
			
			sleep .25;
			
			CUP_stopLampCheck
		};
	};
	waitUntil {!isNil "CUP_lampState"};
	_pre_st = -1;
	waitUntil {
		_pos = positionCameraToWorld [0,0,0];
		
		if ((_pos distance _prevPos > 100) || !(CUP_lampState isEqualTo _pre_st)) then {
			_pre_st = CUP_lampState;
			_m = format ['ca\Structures\Misc_Powerlines\Data\powlines_%1.rvmat',['multi1','light1'] select CUP_lampState];

			{
				if (getObjectMaterials _x select 0 != _m) then {
					_x setObjectMaterial [0,_m];
				};
				
				nil
			} count (_pos nearObjects ["Land_PowLines_WoodL",400]);
		};
		
		sleep .5;
		
		CUP_stopLampCheck
	};
};

/*_d = round(((date select 1)-1)*30.4375) + (date select 2);
_b = 360/365 * (_d-81);
_eot = 9.87*sin(2*_b) - 7.53*cos _b - 1.5*sin _b;
_lstm = 15 * _gmt;
_tc = 4*(_long - _lstm) + _eot;

_lst = dayTime + _tc/60;
_hra = 15 * (_lst-12);
_dec = 23.45 * sin _b;
_elv = asin(sin _dec * sin _lat + cos _dec * cos _lat * cos _hra);*/

Details

Commits
Restricted Diffusion Commit
JonBons created this task.Nov 11 2017, 1:49 AM
JonBons updated the task description. (Show Details)
JonBons updated the task description. (Show Details)Nov 11 2017, 1:51 AM
JonBons updated the task description. (Show Details)
JonBons updated the task description. (Show Details)
torndeco claimed this task.Mon, Dec 4, 1:21 AM
torndeco closed this task as Resolved by committing Restricted Diffusion Commit.Mon, Dec 4, 7:40 AM
torndeco added a commit: Restricted Diffusion Commit.