Rewrite of the terrain initialization:

*Replaced spawn/sleep with a PFH
This commit is contained in:
ulteq 2015-04-11 18:18:38 +02:00
parent 23733263ea
commit 44198b18d7
2 changed files with 41 additions and 26 deletions

View File

@ -34,6 +34,7 @@ GVAR(AtmosphericDensitySimulationEnabled) = true;
GVAR(BarrelLengthInfluenceEnabled) = true;
GVAR(VehicleGunnerEnabled) = true;
GVAR(currentGrid) = 0;
GVAR(INIT_MESSAGE_ENABLED) = false;
[] call FUNC(initializeTerrainExtension);

View File

@ -12,32 +12,46 @@
*/
#include "script_component.hpp"
[] spawn {
private ["_initStartTime", "_mapSize", "_mapGrids", "_gridCenter", "_gridHeight", "_gridNumObjects", "_gridSurfaceIsWater"];
_initStartTime = time;
_mapSize = getNumber (configFile >> "CfgWorlds" >> worldName >> "MapSize");
if (("ace_advanced_ballistics" callExtension format["init:%1:%2", worldName, _mapSize]) == "Terrain already initialized") exitWith {
if (GVAR(INIT_MESSAGE_ENABLED)) then {
systemChat "AdvancedBallistics: Terrain already initialized";
};
};
_mapGrids = ceil(_mapSize / 50);
for "_x" from 0 to _mapGrids * 50 step 50 do {
for "_y" from 0 to _mapGrids * 50 step 50 do {
_gridCenter = [_x + 25, _y + 25];
_gridHeight = round(getTerrainHeightASL _gridCenter);
_gridNumObjects = count (_gridCenter nearObjects ["Building", 50]);
_gridSurfaceIsWater = if (surfaceIsWater _gridCenter) then {1} else {0};
"ace_advanced_ballistics" callExtension format["set:%1:%2:%3", _gridHeight, _gridNumObjects, _gridSurfaceIsWater];
};
sleep 0.001;
};
private ["_initStartTime", "_mapSize", "_mapGrids", "_gridCells", "_x", "_y", "_gridCenter", "_gridHeight", "_gridNumObjects", "_gridSurfaceIsWater"];
_initStartTime = time;
_mapSize = getNumber (configFile >> "CfgWorlds" >> worldName >> "MapSize");
if (("ace_advanced_ballistics" callExtension format["init:%1:%2", worldName, _mapSize]) == "Terrain already initialized") exitWith {
if (GVAR(INIT_MESSAGE_ENABLED)) then {
systemChat format["AdvancedBallistics: Finished terrain initialization in %1 seconds", ceil(time - _initStartTime)];
systemChat "AdvancedBallistics: Terrain already initialized";
};
};
_mapGrids = ceil(_mapSize / 50) + 1;
_gridCells = _mapGrids * _mapGrids;
GVAR(currentGrid) = 0;
[{
private ["_args", "_mapGrids", "_gridCells", "_initStartTime"];
_args = _this select 0;
_mapGrids = _args select 0;
_gridCells = _args select 1;
_initStartTime = _args select 2;
if (GVAR(currentGrid) >= _gridCells) exitWith {
if (GVAR(INIT_MESSAGE_ENABLED)) then {
systemChat format["AdvancedBallistics: Finished terrain initialization in %1 seconds", ceil(time - _initStartTime)];
};
[_this select 1] call cba_fnc_removePerFrameHandler;
};
for "_i" from 1 to 50 do {
_x = floor(GVAR(currentGrid) / _mapGrids) * 50;
_y = (GVAR(currentGrid) - floor(GVAR(currentGrid) / _mapGrids) * _mapGrids) * 50;
_gridCenter = [_x + 25, _y + 25];
_gridHeight = round(getTerrainHeightASL _gridCenter);
_gridNumObjects = count (_gridCenter nearObjects ["Building", 50]);
_gridSurfaceIsWater = if (surfaceIsWater _gridCenter) then {1} else {0};
"ace_advanced_ballistics" callExtension format["set:%1:%2:%3", _gridHeight, _gridNumObjects, _gridSurfaceIsWater];
GVAR(currentGrid) = GVAR(currentGrid) + 1;
if (GVAR(currentGrid) >= _gridCells) exitWith {};
};
}, 0, [_mapGrids, _gridCells, _initStartTime]] call CBA_fnc_addPerFrameHandler