Skip to content

Sys Registry

friznit edited this page Feb 12, 2016 · 1 revision

h1. Sys registry

Controls initialisation order and dependancies among modules.

h2. Module with no dependancies

Implement the following structure to register a module with no dependancies. It will be added to the startup queue and run according to its place in the queue. Modules that depend on this module will only be allowed to run once the "startupComplete" flag has been set to true

    // Main process
	case "init": {
		if (isServer) then {
			// if server, initialise module game logic
			_logic setVariable ["super", SUPERCLASS];
			_logic setVariable ["class", MAINCLASS];

			// give the module a type name
			_logic setVariable ["moduleType", "ALIVE_MODULE_A"];

			// set this modules startup flag as false
			_logic setVariable ["startupComplete", false];

			// call the register method
			[_logic,"register"] call MAINCLASS;		
		};
	};
	case "register": {
		
		private["_registration","_moduleType"];

		_moduleType = _logic getVariable "moduleType";

		// registration args
		_registration = [_logic,_moduleType];

		// create the registry if not already created
		if(isNil "ALIVE_registry") then {
			ALIVE_registry = [nil, "create"] call ALIVE_fnc_registry;
			[ALIVE_registry, "init"] call ALIVE_fnc_registry;			
		};

		// register the module
		[ALIVE_registry,"register",_registration] call ALIVE_fnc_registry;
	};
	case "start": {

		// .... the code you want to run before allowing other modules that depend on this module to startup ....
	
		// set module startup flag as true
		[_logic,"startupComplete",true] call ALIVE_fnc_hashSet;
		
		// .... more code ....

	};

h2. Module that depends on another named module

Implement the following structure to register a module with required named dependancies. It will be added to the startup queue and run once the required module has reached startupComplete state

    // Main process
	case "init": {
        if (isServer) then {
			// if server, initialise module game logic
			_logic setVariable ["super", SUPERCLASS];
			_logic setVariable ["class", MAINCLASS];
			
			// give the module a type name
			_logic setVariable ["moduleType", "ALIVE_MODULE_B"];
			
			// set this modules startup flag as false
			_logic setVariable ["startupComplete", false];

			// call the register method
			[_logic,"register"] call MAINCLASS;			
        };
	};
	case "register": {
		
			private["_registration","_moduleType"];
		
			_moduleType = _logic getVariable "moduleType";
			
			// ALIVE_MODULE_B requires ALIVE_MODULE_A to be started
			_registration = [_logic,_moduleType,["ALIVE_MODULE_A"]];
	
			// create the registry if not already created
			if(isNil "ALIVE_registry") then {
				ALIVE_registry = [nil, "create"] call ALIVE_fnc_registry;
				[ALIVE_registry, "init"] call ALIVE_fnc_registry;	
			};

			// register the module
			[ALIVE_registry,"register",_registration] call ALIVE_fnc_registry;
	};
	// Main process
	case "start": {
	
		// .... the code you want to run before allowing other modules that depend on this module to startup ....
	
		// set module startup flag as true
		[_logic,"startupComplete",true] call ALIVE_fnc_hashSet;
		
		// .... more code ....
	
	};

h2. Module that depends on any synced modules

Implement the following structure to register a module with required synced dependancies. It will be added to the startup queue and run once the synced modules have reached startupComplete state

    // Main process
	case "init": {
        if (isServer) then {
			// if server, initialise module game logic
			_logic setVariable ["super", SUPERCLASS];
			_logic setVariable ["class", MAINCLASS];
			
			// give the module a type name
			_logic setVariable ["moduleType", "ALIVE_MODULE_C"];
			
			// set this modules startup flag as false
			_logic setVariable ["startupComplete", false];

			// call the register method
			[_logic,"register"] call MAINCLASS;			
        };
	};
	case "register": {
		
			private["_registration","_moduleType"];
		
			_moduleType = _logic getVariable "moduleType";
			
			// ALIVE_MODULE_B requires any synced modules
			// additionally ignore any ALIVE_MODULE_A that are synced
			_registration = [_logic,_moduleType,["SYNCED"],["ALIVE_MODULE_A"]];
	
			// create the registry if not already created
			if(isNil "ALIVE_registry") then {
				ALIVE_registry = [nil, "create"] call ALIVE_fnc_registry;
				[ALIVE_registry, "init"] call ALIVE_fnc_registry;	
			};

			// register the module
			[ALIVE_registry,"register",_registration] call ALIVE_fnc_registry;
	};
	// Main process
	case "start": {
	
		// .... the code you want to run before allowing other modules that depend on this module to startup ....
	
		// set module startup flag as true
		[_logic,"startupComplete",true] call ALIVE_fnc_hashSet;
		
		// .... more code ....
	
	};