Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

(NEW RELEASE) ChupacabraHUD.oxp

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Thargoid »

The simplest way to avoid things like this is to set the variable thargoidRepairBotChance = 0 in the equipment.plist entry for each equipment item of the HUD. Then the DCN and repair bots will just ignore it completely.

Full details of how to do it are in the readme for repair bots.
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Capt. Murphy »

I'm not sure that will help Thargoid, see the edit to my last post as to where the main time overhead is in the function.

CSOTB - I think the time limit for JS timeout is different between Trunk and Test releases (not 100% sure) so what you are testing on might make a difference as to whether or not the script is terminated due to timeout.

Here are some results from using :time worldScripts["Repair system"].checkSystems() from the debug console. This is on an old old laptop (getting on for 6 years), fully iron-assed cobra, but nothing that adds hidden equipment items.

Original repair bots/DCN this.checkSystems().

1) Without C.HUD installed - 139.24 ms, 137.582 ms, 145.027 ms
2) With C.HUD installed - 1509.84 ms, 1500.66 ms, 1409.42 ms

The version below of this.checkSystems() is a little more efficient ( because var scriptEq = EquipmentInfo.infoForKey(player.ship.equipment[listCounter].equipmentKey); is only run for damaged equipment, not every installed equipment item) and less likely to hit timeout but still suffers from the 10x time increase with C.HUD. Not sure if there is a way around this issue when your HUD technique relies on using lots of hidden equipment items.

1) Without C.HUD - 95.8631 ms, 102.833 ms
2) With C.HUD - 906.564 ms, 901.522 ms

Code: Select all

this.checkSystems = function()	
	{
	this.playerDamagedList = [];
	var listCounter = 0 ; // reset the counter
	for(listCounter = 0;listCounter<player.ship.equipment.length;listCounter++)
		{
		if(	player.ship.equipmentStatus(player.ship.equipment[listCounter].equipmentKey) !== "EQUIPMENT_DAMAGED")
		{continue}
		var scriptEq = EquipmentInfo.infoForKey(player.ship.equipment[listCounter].equipmentKey);
		if((scriptEq.scriptInfo.thargoidRepairBotChance === undefined 
				|| isNaN(scriptEq.scriptInfo.thargoidRepairBotChance))
			|| (!isNaN(scriptEq.scriptInfo.thargoidRepairBotChance)
				&& scriptEq.scriptInfo.thargoidRepairBotChance > 0))
			{
			this.playerDamagedList.push(player.ship.equipment[listCounter].equipmentKey); // if it's broke and fixable, add it to the list.
			}
		}
	}
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by CommonSenseOTB »

Thank you very much Capt. Murphy and Thargoid for your efforts and comments. I don't believe there is much I can do for this issue. First, I want to see sdrubbles log and his particular this.checkSystems function to see what is in it as he has already stated that he has added stuff to it and that could be enough to push the time consumption enough to shut down the script function. As I cannot duplicate his problem, I have to assume this is the problem first. If this is not the problem, then doing what Thargoid suggests is only a short-term/temporary fix because any other script that comes along and does a similar operation to check equipment may also cause the problem. Do I have to change all animated hud equipment every time that someone makes an equipment check like this part of thier script? That is unworkable. Is there a better way to do this function that may prevent future problems stemming from any oxp having lots of equipment?

First things first: sdrubble, please post your log and the this.checkSystems function portion of your script. Thankyou.
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
User avatar
sdrubble
Deadly
Deadly
Posts: 234
Joined: Fri Aug 05, 2011 8:30 am
Location: Belo Horizonte, Brazil

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by sdrubble »

:mrgreen: :mrgreen: Thx a lot everybody for the input... and a special thx to CSOTB. :mrgreen: :mrgreen:

As both files requested are under 10K, I don't think there's an issue in posting them inline (pls correct me if I'm wrong on this). :roll:

Full log file follows (179 lines):

Code: Select all

21:22:39.489 [log.header]: Opening log for Oolite version 1.75.3 (x86-32 test release) under Windows at 2011-11-01 21:22:39 -0200.
2 processors detected.
Build options: spoken messages, mass/fuel pricing, JavaScript console support, OXP verifier, localization tools, debug GraphViz support, JavaScript profiling.

Note that the contents of the log file can be adjusted by editing logcontrol.plist.

21:22:40.224 [display.mode.list.native]: Windows native resolution detected: 1680 x 1050
21:22:40.442 [joystick.init]: Number of joysticks detected: 1
21:22:41.786 [dataCache.rebuild.explicitFlush]: Cache explicitly flushed with always-flush-cache preference. Rebuilding from scratch.
21:22:41.802 [searchPaths.dumpAll]: Unrestricted mode - resource paths:
    Resources
    ../AddOns
    ../AddOns/accessoriesV2.0.oxp
    ../AddOns/Armoury_1.08(heavily_customized).oxp
    ../AddOns/Basic-debug.oxp
    ../AddOns/behemoth 2.6.oxp
    ../AddOns/BountyScannerv2.0.oxp
    ../AddOns/Cargo Shepherd 1.01.oxp
    ../AddOns/ChupacabraHUD_2011.10.26.oxp
    ../AddOns/Dark_Rainbow(remove_RepairBots).oxp
    ../AddOns/Deep Horizons - Systems_2.0.8.oxp
    ../AddOns/display_reputation.oxp
    ../AddOns/Escape_Capsule_Locator 1.1.oxp
    ../AddOns/Escort Contracts 1.4.1.oxp
    ../AddOns/farsun_1.05.oxp
    ../AddOns/Fuel Station 1.33.oxp
    ../AddOns/Fuel Tank v2.2.oxp
    ../AddOns/FuelCollectorV0.07.oxp
    ../AddOns/Galactic_Navy 5.3.0.oxp
    ../AddOns/GalaxyInfo V0.9.1.oxp
    ../AddOns/HyperCargo 1.04(not_with_Vortex).oxp
    ../AddOns/I-Missile_1.06.oxp
    ../AddOns/ionics-1.3.1.oxp
    ../AddOns/IronHide 2.00.oxp
    ../AddOns/Military Fuel Injectors 1.00.oxp
    ../AddOns/milmissile.oxp
    ../AddOns/Missile Analyser 1.2.oxp
    ../AddOns/missile_spoof.oxp
    ../AddOns/Nexus_missile_1.22.oxp
    ../AddOns/Police_Scanner_Upgrade 1.3.oxp
    ../AddOns/PylonBasedEqRemover v0.8.oxp
    ../AddOns/Q-Chargerv1.2.oxp
    ../AddOns/railgun.oxp
    ../AddOns/RandomHits1.4.11.oxp
    ../AddOns/Rock_Hermit_Locator1.3.3.oxp
    ../AddOns/SaveAnywhere3.1.oxp
    ../AddOns/ShieldEqualizer+Capacitors(v1.3).oxp
    ../AddOns/Smivs'Shipset-v3.1-SD.oxp
    ../AddOns/Target Autolock Plus 1.12.oxp
    ../AddOns/Target Reticle 1.2.1(NOT_with_MilHUD).oxp
    ../AddOns/TG2forSmivs' Anarchy-v1.1.oxp
    ../AddOns/UPS-courier v1.7.7.oxp
21:22:41.802 [rendering.opengl.version]: OpenGL renderer version: 1.4.0 ("1.4.0 - Build 7.14.10.4906"). Vendor: "Intel". Renderer: "Intel 945GM".
21:22:41.802 [rendering.opengl.extensions]: OpenGL extensions (49):
GL_ARB_transpose_matrix, GL_EXT_texture_compression_s3tc, GL_ARB_texture_cube_map, GL_ARB_texture_env_dot3, GL_NV_texgen_reflection, GL_EXT_blend_color, GL_EXT_rescale_normal, GL_ARB_texture_env_combine, GL_EXT_separate_specular_color, GL_ARB_texture_border_clamp, GL_EXT_fog_coord, GL_IBM_texture_mirrored_repeat, GL_EXT_draw_range_elements, GL_NV_blend_square, GL_ARB_depth_texture, GL_EXT_texture_env_combine, GL_EXT_multi_draw_arrays, GL_EXT_bgra, GL_ARB_texture_env_add, GL_ARB_shadow, GL_EXT_packed_pixels, GL_EXT_texture3D, GL_EXT_blend_subtract, GL_ARB_window_pos, GL_WIN_swap_hint, GL_EXT_texture_lod_bias, GL_ARB_texture_compression, GL_EXT_secondary_color, GL_ARB_texture_env_crossbar, GL_3DFX_texture_compression_FXT1, GL_EXT_shadow_funcs, GL_EXT_abgr, GL_ARB_fragment_program, GL_SGIS_texture_edge_clamp, GL_SGIS_generate_mipmap, GL_ARB_vertex_program, GL_EXT_texture_env_add, GL_EXT_stencil_two_side, GL_EXT_cull_vertex, GL_EXT_blend_func_separate, GL_EXT_blend_minmax, GL_EXT_texture_filter_anisotropic, GL_EXT_clip_volume_hint, GL_ARB_point_parameters, GL_ARB_multitexture, GL_EXT_stencil_wrap, GL_EXT_compiled_vertex_array, GL_ARB_vertex_buffer_object, GL_SGIS_texture_lod
21:22:41.927 [rendering.opengl.gpuSpecific]: Matched GPU configuration "Intel GMA 900/950 family".
21:22:41.927 [rendering.opengl.shader.support]: Shaders will not be used (OpenGL extension GL_ARB_shading_language_100 is not available).
21:22:43.255 [shipData.load.begin]: Loading ship data.
21:22:52.442 [script.load.world.listAll]: Loaded 50 world scripts:
    ams_system 2.02
    armoury_machineScript.js 1.00
    behemoth 2.6
    Bounty Scanner 2.0 2.00
    Caduceus Damage Control Node 2.0
    Cheyd_JS_Common_Functions_1 0.0.5
    chupacabrahud 1.0
    CT_Script 2.0
    Deep Horizon - Systems 2.0.8
    Deep Horizon - Systems API 2.0.5
    Deep Horizon - Systems Exclusion Lists 1.0.1
    display-reputation-contract 1.1
    display-reputation-passenger 1.1
    ecl_SAR_worldscript.js 1.1
    escapePodLocator.js 1.1
    Escort_Contracts 1.4.1
    Escort_Contracts_Rep 1.4.1
    farsun 1.05
    Fuel Collector 0.07
    FuelStation-Setup 1.33
    galaxy_info 0.9
    GalNavy 5.3.0.upd
    hofd 5.3.0
    HyperCargo 1.04
    ionics_v_rlf 1.3.1
    IronHide Armour Script 2.00
    mil_injectors.js 1.00
    Missile Spoof 1.02 - for Oolite 1.75
    missile_analyser 1.2
    oolite-cloaking-device 1.75.3
    oolite-constrictor-hunt 1.75.3
    oolite-nova 1.75.3
    oolite-thargoid-plans 1.75.3
    oolite-trumbles 1.75.3
    Police_Scanner_Upgrade 1.3
    PylonBasedEqRemover 0.0
    Q-Charger 1.2
    railgun 1.3
    Random_Hits 1.4.11
    reticle_target_sensitive 1.2.1
    rockHermit_Locator 1.3.3
    Save Anywhere OXP 3.1 3.1
    sdrbl_CT_Script 2.0
    shieldequalizercapacitors 1.3
    targetAutolock 1.11
    ups_container 1.7.7
    ups_docs 1.7.7
    ups_parcel 1.7.7
    ups_slaves 1.7.7
    ups_sun 1.7.7
21:23:01.833 [debugTCP.disconnect]: No connection to debug console: "Connection to debug console failed: 'No connection could be made because the target machine actively refused it.

' (outStream status: 7, inStream status: 7)."
21:23:01.833 [debugTCP.disconnect]: No connection to debug console: "Connection to debug console failed: 'unknown error.' (outStream status: 0, inStream status: 0)."
21:23:01.833 [debugTCP.connect.failed]: Failed to connect to debug console at address 127.0.0.1:8563.
21:23:02.833 [Save Anywhere OXP 3.1]: initialising Save Anywhere OXP 3.1
21:23:03.208 [loading.complete]: ========== Loading complete. ==========
21:24:07.146 [script.load.world.listAll]: Loaded 50 world scripts:
    ams_system 2.02
    armoury_machineScript.js 1.00
    behemoth 2.6
    Bounty Scanner 2.0 2.00
    Caduceus Damage Control Node 2.0
    Cheyd_JS_Common_Functions_1 0.0.5
    chupacabrahud 1.0
    CT_Script 2.0
    Deep Horizon - Systems 2.0.8
    Deep Horizon - Systems API 2.0.5
    Deep Horizon - Systems Exclusion Lists 1.0.1
    display-reputation-contract 1.1
    display-reputation-passenger 1.1
    ecl_SAR_worldscript.js 1.1
    escapePodLocator.js 1.1
    Escort_Contracts 1.4.1
    Escort_Contracts_Rep 1.4.1
    farsun 1.05
    Fuel Collector 0.07
    FuelStation-Setup 1.33
    galaxy_info 0.9
    GalNavy 5.3.0.upd
    hofd 5.3.0
    HyperCargo 1.04
    ionics_v_rlf 1.3.1
    IronHide Armour Script 2.00
    mil_injectors.js 1.00
    Missile Spoof 1.02 - for Oolite 1.75
    missile_analyser 1.2
    oolite-cloaking-device 1.75.3
    oolite-constrictor-hunt 1.75.3
    oolite-nova 1.75.3
    oolite-thargoid-plans 1.75.3
    oolite-trumbles 1.75.3
    Police_Scanner_Upgrade 1.3
    PylonBasedEqRemover 0.0
    Q-Charger 1.2
    railgun 1.3
    Random_Hits 1.4.11
    reticle_target_sensitive 1.2.1
    rockHermit_Locator 1.3.3
    Save Anywhere OXP 3.1 3.1
    sdrbl_CT_Script 2.0
    shieldequalizercapacitors 1.3
    targetAutolock 1.11
    ups_container 1.7.7
    ups_docs 1.7.7
    ups_parcel 1.7.7
    ups_slaves 1.7.7
    ups_sun 1.7.7
21:24:09.333 [Save Anywhere OXP 3.1]: initialising Save Anywhere OXP 3.1
21:24:34.911 [script.javaScript.timeLimit]: ***** ERROR: Script "Caduceus Damage Control Node" ran for 1.69931 seconds and has been terminated.
21:24:34.911 [script.javaScript.stackTrace]:  0 (../AddOns/Dark_Rainbow(remove_RepairBots).oxp/Config/script.js:159) <anonymous function>
21:24:34.911 [script.javaScript.stackTrace]:     this: [Script "Caduceus Damage Control Node" version 2.0]
21:24:34.911 [script.javaScript.stackTrace]:     scriptEq: [EquipmentInfo EQ_CHUPACABRA_GREEN_37_AFTSHIELD ""]
21:24:34.911 [script.javaScript.stackTrace]:     listCounter: 95
21:24:34.911 [script.javaScript.stackTrace]:  1 (../AddOns/Dark_Rainbow(remove_RepairBots).oxp/Config/script.js:136) <anonymous function>
21:24:34.911 [script.javaScript.stackTrace]:     this: [Script "Caduceus Damage Control Node" version 2.0]
21:24:34.911 [script.javaScript.stackTrace]:     repairTime: undefined
21:37:56.646 [gameController.exitApp]: .GNUstepDefaults synchronized.

Closing log at 2011-11-01 21:37:56 -0200.
Cheers - script coming next...
User avatar
sdrubble
Deadly
Deadly
Posts: 234
Joined: Fri Aug 05, 2011 8:30 am
Location: Belo Horizonte, Brazil

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by sdrubble »

And here is...

../AddOns/Dark_Rainbow(remove_RepairBots).oxp/Config/script.js (in full, 287 lines):

Code: Select all

this.name = "Caduceus Damage Control Node";
this.author = "Thargoid";
this.copyright = "Creative Commons Attribution - Non-Commercial - Share Alike 3.0 license";
this.description = "Damage Control system based on repair bots";
this.version = "2.0";

this.startUp = function()
	{
	if (oolite.compareVersion('1.74') <= 0) 
		{
		log("1.74 detected - Neo-Caduceus DCN initialised");
		delete this.reset;
		}
	else
		{
		log("1.73.x or below detected - Neo-Caduceus DCN unavailable");
		}
	}
	
this.reset = function()  // as 1.74 doesn't have this function, we can use it to self-destruct in 1.73.x and below.
	{
	if(player.ship.equipmentStatus("EQ_DCN") == "EQUIPMENT_UNAVAILABLE") // if we're not flying a ship with DCN installed
		{
		return;
		}
		
	player.consoleMessage("Neo-Caduceus DCN v2.0 requires Oolite 1.74 - self-repair offline.",6);
	delete this.equipmentDamaged;
	delete this.equipmentDestroyed;
	delete this.selfRepair;
	delete this.stopTimers;
	delete this.shipWillDockWithStation;
	delete this.shipDied;
	delete this.shipWillLaunchFromStation;
	delete this.checkSystems;
	delete this.repairSystems;
	delete this.fixItem;
	delete this.startUp;
	player.ship.removeEquipment("EQ_DCN");
	}	

this.equipmentDamaged = function(equipment)
	{
	if(player.ship.equipmentStatus("EQ_DCN") == "EQUIPMENT_UNAVAILABLE") 
		{
		return;
		}
		
	if (equipment == "EQ_DCN")
		{
		if(this.damageControlTimer && this.damageControlTimer.isRunning)
			{
			this.damageControlTimer.stop();
			delete this.damageControlTimer;
			}
		var repairTime = 60 + Math.ceil(Math.random() * 120);
	//	player.consoleMessage("DCN offline - entering self-repair mode", 6);
		player.commsMessage("DCN offline - entering self-repair mode", 6); 	// sdrbl-comms-twk
		this.selfRepairTimer = new Timer(this, this.selfRepair, repairTime);	
		}
	else
		{
		if(!this.damageControlTimer || !this.damageControlTimer.isRunning)
			{
			var repairTime = 120 + Math.ceil(Math.random() * 180);
		//	player.consoleMessage("DCN activated", 6);
			player.commsMessage("DCN activated", 6); 	// sdrbl-comms-twk
			this.damageControlTimer = new Timer(this, this.repairSystems, repairTime);	
			}
		}
	}	

this.selfRepair = function()
	{
	if(player.ship.equipmentStatus("EQ_DCN") == "EQUIPMENT_UNAVAILABLE")
		{
		return;
		}
	
	if(Math.random() < 0.75) // 75% chance of self-repair
		{
		player.ship.setEquipmentStatus("EQ_DCN","EQUIPMENT_OK");
		this.checkSystems();
		if(this.playerDamagedList.length > 0)
			{
		//	player.consoleMessage("DCN online and activated", 6);
			player.commsMessage("DCN online and activated", 6); 	// sdrbl-comms-twk
			var repairTime = 120 + Math.ceil(Math.random() * 180);
			this.damageControlTimer = new Timer(this, this.repairSystems, repairTime);
			}
		else
			{
		//	player.consoleMessage("DCN online and in standby mode", 6);
			player.commsMessage("DCN online and in standby mode", 6); 	// sdrbl-comms-twk
			}
		}
	else
		{
		if(player.ship.equipmentStatus("EQ_DCN") == "EQUIPMENT_DAMAGED") // just in case it was repaired in the meantime
			{
			var repairTime = 60 + Math.ceil(Math.random() * 120);
		//	player.consoleMessage("DCN offline - self-repair continuing", 6);
			player.commsMessage("DCN offline - self-repair continuing", 6); 	// sdrbl-comms-twk
			this.selfRepairTimer = new Timer(this, this.selfRepair, repairTime);
			}
		}
	}
	
this.equipmentDestroyed  = function(equipment)
	{
	if(equipment == "EQ_DCN")
		{
		this.stopTimers();
		}
	}	
	
this.stopTimers = this.shipWillDockWithStation = this.shipDied = function()
	{
	if(this.damageControlTimer && this.damageControlTimer.isRunning)
		{
		this.damageControlTimer.stop();
		delete this.damageControlTimer;
		}
	if(this.selfRepairTimer && this.selfRepairTimer.isRunning)
		{
		player.ship.setEquipmentStatus("EQ_DCN","EQUIPMENT_OK");
		this.selfRepairTimer.stop();
		delete this.selfRepairTimer;
		}	
	}

this.shipWillLaunchFromStation = function()
	{
	if(player.ship.equipmentStatus("EQ_DCN") == "EQUIPMENT_OK")
		{
		this.checkSystems();
		if(this.playerDamagedList.length > 0)
			{
			var repairTime = 120 + Math.ceil(Math.random() * 180);
		//	player.consoleMessage("Repair system reactivated", 6);
			player.commsMessage("Repair system reactivated", 6); 	// sdrbl-comms-twk
			this.damageControlTimer = new Timer(this, this.repairSystems, repairTime);	
			}
		}
	else
		{
		if(player.ship.equipmentStatus("EQ_DCN") == "EQUIPMENT_DAMAGED")
			{
			this.selfRepair();
			return;
			}
		}
	}

this.checkSystems = function()	
	{
	this.playerDamagedList = [];
	var listCounter = 0 ; // reset the counter
	for(listCounter = 0;listCounter<player.ship.equipment.length;listCounter++)
		{
		var scriptEq = EquipmentInfo.infoForKey(player.ship.equipment[listCounter].equipmentKey);
		if(	player.ship.equipmentStatus(player.ship.equipment[listCounter].equipmentKey) == "EQUIPMENT_DAMAGED"
			&& ((scriptEq.scriptInfo.thargoidRepairBotChance === undefined 
				|| isNaN(scriptEq.scriptInfo.thargoidRepairBotChance))
			|| (!isNaN(scriptEq.scriptInfo.thargoidRepairBotChance)
				&& scriptEq.scriptInfo.thargoidRepairBotChance > 0))
			)
			{
			this.playerDamagedList.push(player.ship.equipment[listCounter].equipmentKey); // if it's broke and fixable, add it to the list.
			}
		}
	}
	
this.repairSystems = function() 
	{
	this.checkSystems();
	if(this.playerDamagedList.length == 0)
		{
	//	player.consoleMessage("All systems nominal - DCN entering standby mode", 5);
		player.commsMessage("All systems nominal - DCN entering standby mode", 5); 	// sdrbl-comms-twk
		return;
		}
	else
		{
		var damagedEquipment = Math.floor(Math.random() * this.playerDamagedList.length); // pick a random element from the list...
		this.fixedItem = this.playerDamagedList[damagedEquipment]; // ...define the item...
		this.damagedItem = this.fixedItem + "_DAMAGED"; //...and it's damaged version
		this.fixedName = EquipmentInfo.infoForKey(this.fixedItem).name; // define it's screen name
		this.fixedTech = EquipmentInfo.infoForKey(this.fixedItem).effectiveTechLevel // tech level of the item
		if(EquipmentInfo.infoForKey(this.fixedItem).scriptInfo.thargoidRepairBotChance !== undefined && !isNaN(EquipmentInfo.infoForKey(this.fixedItem).scriptInfo.thargoidRepairBotChance))
			{
			this.fixChance = EquipmentInfo.infoForKey(this.fixedItem).scriptInfo.thargoidRepairBotChance; 
			}
		else
			{
			this.fixChance = 0.6;
			}
		}	
		
	if(Math.random() < this.fixChance)
		{
		this.fixItem();
		}
	else
		{
		var repairTime = 120 + Math.ceil(Math.random() * 180);
	//	player.consoleMessage(this.fixedName + " is still offline - work continuing.", 5);
		player.commsMessage(this.fixedName + " is still offline - work continuing.", 5); 	// sdrbl-comms-twk
		this.damageControlTimer = new Timer(this, this.repairSystems, repairTime);
		}
	}


this.fixItem = function()
	{
	player.ship.setEquipmentStatus(this.fixedItem,"EQUIPMENT_OK"); // and actually fix the thing!
//	player.consoleMessage(this.fixedName + " regenerated and operational", 5)
	player.commsMessage(this.fixedName + " regenerated and operational", 5) 	// sdrbl-comms-twk
	switch(this.fixedItem) // specific OXP equipment which need rebooting after fixing, or have other issues.
		{
		case "EQ_FRAME_FUEL_COLLECTOR":
			{
			if(worldScripts["Fuel Collector"]) 
				{
				worldScripts["Fuel Collector"].shipLaunchedFromStation(); // restart the timers in it's world script
				break;
				}
			}
		case "EQ_FRAME_BOUNTY_SCANNER":			
			{
			if(worldScripts["Bounty Scanner"])
				{
				worldScripts["Bounty Scanner"].shipLaunchedFromStation(); // restart the timers in it's world script
				break;
				}
			}
		case "EQ_EEU":
			{
			if(worldScripts["Emergency Energy Unit"])
				{
				worldScripts["Emergency Energy Unit"].shipLaunchedFromStation(); // restart the timers in it's world script
				break;
				}
			}
		case "EQ_ROCKHERMIT_SCANNER": 
			{ 
			if(worldScripts["rockHermit_Locator"]) 
				{ 
				if(worldScripts["rockHermit_Locator"].version == "1.2.3")
					{
					worldScripts["rockHermit_Locator"].shipLaunchedFromStation() // use the inbuild scripting of the OXP to restart it.
					}
				else
					{
					this.beacons = system.shipsWithPrimaryRole("rockbeacof"); // list the inactive beacons (no lights or "R" on compass) 
					if(this.beacons.length > 0) 
						{ 
						for (let i=0; i<this.beacons.length;i++) 
							{ 
							if (oolite.compareVersion('1.73') <= 0) 
								{
								this.beacons[i].position = this.beacons[i].position.multiply(100); //throw the rockbeacof into space... 
								}
							else 
								{
								this.beacons[i].setPosition(this.beacons[i].position.multiply(100)); //throw the rockbeacof into space... 
						            }

							this.beacons[i].explode(); //...and blow it up. 
							} 
						} 
					worldScripts["rockHermit_Locator"].buoy = "rockbeacon" 
					worldScripts["rockHermit_Locator"].addBuoys() // no inactive beacons, so use original code to add active beacons. 
					}
				break; 
				} 
			}
		}
	if(this.playerDamagedList.length > 1)	
		{
		var repairTime = 120 + Math.ceil(Math.random() * 180);
	//	player.consoleMessage("Repairs ongoing", 6);
		player.commsMessage("Repairs ongoing", 6); 	// sdrbl-comms-twk
		this.damageControlTimer = new Timer(this, this.repairSystems, repairTime);	
		}
		
	}
Thx again and cheers :D
User avatar
sdrubble
Deadly
Deadly
Posts: 234
Joined: Fri Aug 05, 2011 8:30 am
Location: Belo Horizonte, Brazil

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by sdrubble »

@Capt. Murphy and Thargoid

After reading the comments from you both I'm left wondering if it would be worthwhile, for myself, attempting a personal fix while CSOTB ponders on a possible more general solution.

But if I understood everything right, it's possible that neither Thargoid's 'thargoidRepairBotChance = 0' suggestion neither Capt. Murphy's recoded DCN function might solve the issue...

Would doing BOTH tweaks (i.e., in the equipment.plist entries for the HUD - AND in the this.checkSystems function of DCN) improve the running chances a bit more perhaps? :?

Cheers
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by CommonSenseOTB »

Thanx for the log/script posts. I've copied them and will have a good look. Cheers. :)
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Thargoid »

sdrubble wrote:
@Capt. Murphy and Thargoid

After reading the comments from you both I'm left wondering if it would be worthwhile, for myself, attempting a personal fix while CSOTB ponders on a possible more general solution.

But if I understood everything right, it's possible that neither Thargoid's 'thargoidRepairBotChance = 0' suggestion neither Capt. Murphy's recoded DCN function might solve the issue...

Would doing BOTH tweaks (i.e., in the equipment.plist entries for the HUD - AND in the this.checkSystems function of DCN) improve the running chances a bit more perhaps? :?

Cheers
They're both designed to do similar things, but it won't hurt to try. Murphy's optimisation will be better than mine (I'll review the RB code and probably incorporate it, when I have some time) but fundamentally I think this issue is down to simple number of equipment items involved, as already noted. It may just be that with this number of items involved things are getting overloaded and so timing out.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Eric Walch »

Capt. Murphy wrote:
1) Without C.HUD installed - 139.24 ms, 137.582 ms, 145.027 ms
2) With C.HUD installed - 1509.84 ms, 1500.66 ms, 1409.42 ms
I did also some tests on my system:
1) Without C.HUD installed - 24.1028 ms
2) With C.HUD installed - 64.0109 ms
3) With C.HUD installed and your code: 41.3524 ms
4) With C.HUD installed and the code below: 1.8249 ms

Code: Select all

this.checkSystems = function()	
	{
	this.playerDamagedList = [];
    var equipment = player.ship.equipment
	var listCounter = 0 ; // reset the counter
	for(listCounter = 0;listCounter<equipment.length;listCounter++)
		{
		if(	player.ship.equipmentStatus(equipment[listCounter].equipmentKey) !== "EQUIPMENT_DAMAGED")
		{continue}
		var scriptEqInfo = EquipmentInfo.infoForKey(equipment[listCounter].equipmentKey).scriptInfo;
		if((scriptEqInfo.thargoidRepairBotChance === undefined 
				|| isNaN(scriptEqInfo.thargoidRepairBotChance))
			|| (!isNaN(scriptEqInfo.thargoidRepairBotChance)
				&& scriptEqInfo.thargoidRepairBotChance > 0))
			{
			this.playerDamagedList.push(equipment[listCounter].equipmentKey); // if it's broke and fixable, add it to the list.
			}
		}
	}
The main change was only accessing "player.ship.equipment" once. Apparently takes it quite some time to build the player equipment list on every access. By transferring it to a plain JS array you get quite a speed boost. :wink:
Looking in the internal code, I see that Oolite on each access of the equipment list must browse through all equipment, convert damaged equipment to the proper format etc. until a JS usable array of equipment is created.
When you see something like:Total time: 64.0109 ms, JavaScript: 1.44907 ms, native: 62.5527 ms in the time macro, you already have a clue that the native code is the bottneck and not the js part.

Capt Murpy wrote:
I think the time limit for JS timeout is different between Trunk and Test releases (not 100% sure) so what you are testing on might make a difference as to whether or not the script is terminated due to timeout.
Trunk as in nighty builds are the same as test-releases. Only when building yourself you can choose and will it mostly be in debug mode because this compiles the fastest and has other benefits. In debug mode are the timeout limits much shorter.
User avatar
sdrubble
Deadly
Deadly
Posts: 234
Joined: Fri Aug 05, 2011 8:30 am
Location: Belo Horizonte, Brazil

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by sdrubble »

Eric Walch wrote:
I did also some tests on my system:
1) Without C.HUD installed - 24.1028 ms
2) With C.HUD installed - 64.0109 ms
3) With C.HUD installed and your code: 41.3524 ms
4) With C.HUD installed and the code below: 1.8249 ms

Code: Select all

	[ . . . ]
	var equipment = player.ship.equipment
	[ . . . ]
The main change was only accessing "player.ship.equipment" once. [ . . . ]
Hey Eric, this is great news!!! :D

So, I think I've counted 5 different versions of coding for the same function in this thread... that's what we'd call 'incremental improvements'!!! :lol: Although your last version promises to be more in the 'orders of magnitude' department than a mere 'incremental' one... :shock:

I'll wait a bit more to see what CSOTB might come up with... [2nd doohh moment, see below :oops: ] anyway your stats suggest that your version would be a nice candidate for some home hacking and further tests later on. :wink:

Oh, and if you don't mind clarifying a bit more - how come that [b][i][u]With[/u][/i] C.HUD installed and the code below[/b] can be LESS than [b][i][u]Without[/u][/i] C.HUD installed[/b] ? I'm confused as to what you were really comparing here... :?: Dooohh... brain needs sleep I guess. You're talking about the DCN script of course... :oops: :oops: :oops:

Oh, my... 2nd doohh moment on same post - obviously CSOTB won't need to change a thing - changes are to be done on the DCN script only... :oops: :oops: :oops:


Many thx and cheers :D
EDIT: TWO dooohh moments, in the inverse sequence of text, duly slashed.
Last edited by sdrubble on Wed Nov 02, 2011 9:00 pm, edited 3 times in total.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Thargoid »

Repair Bots has been updated to version 2.03 to include this speed hack.

I'll do the same for the Caddy DCN and send the script to ClymAngus.
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by CommonSenseOTB »

Very nice Thargoid, Eric Walch, Capt. Murphy. That should solve the problem. Try this out sdrubble and let us know how it goes. :D
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Capt. Murphy »

Nice one all - except Eric's speed of operations even prior to optimisation really makes me want to upgrade my PC...*mutters*...pay the mortgage or shiny new laptop...pay the mortgage or shiny new laptop..... :? :wink:

On a related note I don't think the :time macro is documented anywhere as such. It really is a very handy tool, but the results are a bit obscure and difficult to interpret. Any chance of an advanced debug console page on the wiki documenting usage of the macros?.

Edit to add - :shock: - with Eric's optimisation I'm down to 22ms with C.HUD installed. I make that a 50 fold increase in efficiency *bows*.

Thargoid - the repair bots 2.03 you've posted still has var scriptEQ set for each equipment item even if it's not damaged. That still adds about 1/3 to the overhead. I got 30ms with repair bots 2.03 and C.HUD installed, and then 22ms with the function as posted by Eric above.

I feel an period of optimising my existing scripts coming on....
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Eric Walch »

Capt. Murphy wrote:
On a related note I don't think the :time macro is documented anywhere as such. It really is a very handy tool, but the results are a bit obscure and difficult to interpret. Any chance of an advanced debug console page on the wiki documenting usage of the macros?.
You are more experienced with Js than I am, so you only looked to the JS side for optimalisation. But the interface between JS and Oolite can be quite slow. For some oolite properties, it is just a matter of converting a C variable to a JS variable. For other properties, there does not exist a variable inside oolite and that property must be calculated first. Without knowing the internal code a user can't know what is the case. Here the time macro is very useful to detect such properties. And you are right that it probably needs a wiki page of its own as it can be quite helpful in optimising code. Problem might be that you probably need internal oolite knowledge to understand it all.

Take for example the full log of the macro from the original function:

Code: Select all

Total time: 64.0109 ms
JavaScript: 1.44907 ms, native: 62.5527 ms
Counted towards limit: 63.5444 ms, excluded: 0.466483 ms
Profiler overhead: 0.540307 ms
                                                        NAME  T  COUNT    TOTAL     SELF  TOTAL%   SELF%  SELFMAX
                                             ShipGetProperty  N     82    62.01    59.29    96.9    92.6     0.83
                                          JSArrayFromNSArray  N     82     2.47     2.47     3.9     3.9     0.96
                      (repairBots_System.js:108) <anonymous>  J      1    63.87     1.37    99.8     2.1     1.37
                                           JSNewNSArrayValue  N     82     2.66     0.19     4.2     0.3     0.00
    -[NSString(OOJavaScriptExtensions) oo_jsValueInContext:]  N     54     0.09     0.09     0.1     0.1     0.00
                                         ShipEquipmentStatus  N     27     0.19     0.08     0.3     0.1     0.01
                          (<console input>) codeToBeProfiled  J      1    64.00     0.08   100.0     0.1     0.08
                                    EquipmentInfoGetProperty  N     54     0.18     0.07     0.3     0.1     0.01
                                        OOStringFromJSString  N     55     0.07     0.07     0.1     0.1     0.00
                                         JSShipGetShipEntity  N    109     0.07     0.07     0.1     0.1     0.00
                               OOStringFromJSValueEvenIfNull  N     54     0.13     0.06     0.2     0.1     0.00
                                     WorldScriptsGetProperty  N      1     0.05     0.05     0.1     0.1     0.05
                               EquipmentInfoStaticInfoForKey  N     27     0.11     0.03     0.2     0.0     0.00
                                         OOStringFromJSValue  N     54     0.15     0.03     0.2     0.0     0.00
                                      JSValueToEquipmentType  N     27     0.10     0.03     0.2     0.0     0.00
                             JSEquipmentInfoGetEquipmentType  N     54     0.02     0.02     0.0     0.0     0.00

Time consumer nr 1 is the first line with 92.6%. That is the internal function ShipGetProperty that is called 82 times. It doesn't say witch property, but looking in the code it can't only be one.
Than with your optimalisation you get:

Code: Select all

Total time: 41.3524 ms
JavaScript: 1.02051 ms, native: 40.3229 ms
Counted towards limit: 41.0114 ms, excluded: 0.340931 ms
Profiler overhead: 0.416403 ms
                                                        NAME  T  COUNT    TOTAL     SELF  TOTAL%   SELF%  SELFMAX
                                             ShipGetProperty  N     55    39.97    38.73    96.7    93.7     0.91
                                          JSArrayFromNSArray  N     55     1.04     1.04     2.5     2.5     0.04
                      (repairBots_System.js:128) <anonymous>  J      1    41.21     0.94    99.7     2.3     0.94
                                           JSNewNSArrayValue  N     55     1.20     0.16     2.9     0.4     0.02
                                         ShipEquipmentStatus  N     27     0.20     0.08     0.5     0.2     0.01
                          (<console input>) codeToBeProfiled  J      1    41.34     0.08   100.0     0.2     0.08
                                     WorldScriptsGetProperty  N      1     0.05     0.05     0.1     0.1     0.05
                                         JSShipGetShipEntity  N     82     0.05     0.05     0.1     0.1     0.00
    -[NSString(OOJavaScriptExtensions) oo_jsValueInContext:]  N     27     0.04     0.04     0.1     0.1     0.00
                                    EquipmentInfoGetProperty  N     27     0.10     0.04     0.2     0.1     0.01
                                        OOStringFromJSString  N     28     0.04     0.04     0.1     0.1     0.00
                               OOStringFromJSValueEvenIfNull  N     27     0.07     0.03     0.2     0.1     0.00
                                      JSValueToEquipmentType  N     27     0.11     0.03     0.3     0.1     0.00
                                         OOStringFromJSValue  N     27     0.08     0.02     0.2     0.0     0.00
                             JSEquipmentInfoGetEquipmentType  N     27     0.01     0.01     0.0     0.0     0.00
As percentage the first line is just as often called, but now only 55 times because you excluded some code from testing.

As last you get:

Code: Select all

Total time: 1.8249 ms
JavaScript: 0.540241 ms, native: 1.27804 ms
Counted towards limit: 1.69363 ms, excluded: 0.131262 ms
Profiler overhead: 0.205861 ms
                                                        NAME  T  COUNT    TOTAL     SELF  TOTAL%   SELF%  SELFMAX
                                             ShipGetProperty  N      1     0.94     0.89    51.5    48.9     0.89
                      (repairBots_System.js:128) <anonymous>  J      1     1.69     0.47    92.6    25.5     0.47
                                         ShipEquipmentStatus  N     27     0.19     0.07    10.3     4.1     0.01
                          (<console input>) codeToBeProfiled  J      1     1.82     0.07    99.6     4.1     0.07
                                     WorldScriptsGetProperty  N      1     0.05     0.05     2.9     2.9     0.05
                                    EquipmentInfoGetProperty  N     27     0.10     0.05     5.3     2.6     0.01
                                          JSArrayFromNSArray  N      1     0.04     0.04     2.1     2.1     0.04
    -[NSString(OOJavaScriptExtensions) oo_jsValueInContext:]  N     27     0.04     0.04     2.1     2.1     0.00
                                        OOStringFromJSString  N     28     0.03     0.03     1.8     1.8     0.00
                                      JSValueToEquipmentType  N     27     0.10     0.03     5.7     1.5     0.00
                               OOStringFromJSValueEvenIfNull  N     27     0.06     0.03     3.3     1.5     0.00
                                         OOStringFromJSValue  N     27     0.08     0.02     4.1     0.9     0.00
                                         JSShipGetShipEntity  N     28     0.01     0.01     0.7     0.7     0.00
                             JSEquipmentInfoGetEquipmentType  N     27     0.01     0.01     0.6     0.6     0.00
                                           JSNewNSArrayValue  N      1     0.04     0.01     2.4     0.3     0.01
ShipGetProperty is now only called once. But that call still uses half of the total time. But now comes the repairBots_System.js on the second place and the JS code flow itself starts to influence the total speed.

All the names you see in the list are internal function names. I don't know how helpfull it genarally will be when you don't know the internal code, although most names are so descriptive that the name alone might give clues.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: (NEW RELEASE) ChupacabraHUD.oxp

Post by Thargoid »

Capt. Murphy wrote:
Thargoid - the repair bots 2.03 you've posted still has var scriptEQ set for each equipment item even if it's not damaged. That still adds about 1/3 to the overhead. I got 30ms with repair bots 2.03 and C.HUD installed, and then 22ms with the function as posted by Eric above.

I feel an period of optimising my existing scripts coming on....
I completely missed Eric's script up there.

v2.04 coming up!
Post Reply