[Release] Market Observer

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

Moderators: winston, another_commander

User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: [Release] marketObserver 1.6.1

Post by spara »

Wildeblood wrote:
I wonder... (ignore what follows, it's just me thinking out loud)... is it because gatherMarketValues (?) is writing the array and printValues is reading the array at the same time...?
I'm suspecting something like this. Could it depend on the OS? Have to windows install somewhere and test. I'm so out of my league here :(.
JeX
Competent
Competent
Posts: 54
Joined: Mon Jan 21, 2013 2:13 pm

Re: [Release] marketObserver 1.6.1

Post by JeX »

I can also confirm that the "stuck HUD" persists on MarketObserver 1.6.1 with the newest AI trading assistant installed (not sure this is what affects it as the stuck HUD has occurred before I played with AI T assistant).

It was reproducable simply by reloading a game, then pressing F8 and then F4.

Also, it takes a long while to actually get to the market screen after pressing F8 (at least 1-2 seconds), while with only AI trading assistant the lag was unnoticeable.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: [Release] marketObserver 1.6.1

Post by spara »

JeX wrote:
I can also confirm that the "stuck HUD" persists on MarketObserver 1.6.1 with the newest AI trading assistant installed (not sure this is what affects it as the stuck HUD has occurred before I played with AI T assistant).

It was reproducable simply by reloading a game, then pressing F8 and then F4.

Also, it takes a long while to actually get to the market screen after pressing F8 (at least 1-2 seconds), while with only AI trading assistant the lag was unnoticeable.
There's something strange going on when switching to market screen. Wierdest thing is that it behaves just ok in my installation, except that 'var j' bug that Wildeblood noted of course (I'm using Linux, that might have something to do with it). Wildeblood's note about array-handling makes sense, I wasn't thinking in objects when I should have, instead procedurally. I have passed a test version (changes in object and array handling) to Solonar, let's see if that solves something.

This seems to be a tough nut to crack. :? Thanks a lot for helping and reporting.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: [Release] marketObserver 1.6.1

Post by Wildeblood »

JeX wrote:
Also, it takes a long while to actually get to the market screen after pressing F8 (at least 1-2 seconds), while with only AI trading assistant the lag was unnoticeable.
I wouldn't go as far as saying a second or two, but there's a definite 1/2 second or so lag here. The lag is longer with marketObserver on its own than with both OXPs together, so I assume it's caused by loading the images for the adverts. Anyway, this one fixes all the problems for me:

Edit: link removed.
Last edited by Wildeblood on Sun Feb 17, 2013 3:17 am, edited 1 time in total.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: [Release] marketObserver 1.6.1

Post by spara »

It seems that the market check for min-max prices, switching to the hud with ads and writing the message overlay is just too much as Solonar reported that it still timeouts despite I corrected reading and writing an array at the same time problem. This probably means that the ads must go as they are there only for athmosphere :(. It's a shame as I really liked them. Maybe I'll release two versions of the oxp. One with the ads and one without. Glad Wildeblood has already done a hud for me to use :wink: .
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: [Release] marketObserver 1.6.1

Post by Wildeblood »

Meanwhile I've implemented multiple display modes in Trading Assistant, and ripped off, um, copy/pasted, err, re-invented in a sealed room the purchase book display. I had to rip your playerSoldCargo function because javascript array manipulation mystifies me. What's the difference between unshift and push? I dunno, so I just copied yours. :mrgreen:
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: [Release] marketObserver 1.6.1

Post by cim »

Wildeblood wrote:
What's the difference between unshift and push?
The end it adds to.

Code: Select all

arr = [1,2,3,4];
arr.push(5); // arr = [1,2,3,4,5];
arr.unshift(0); // arr = [0,1,2,3,4,5];
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: [Release] marketObserver 1.6.1

Post by Wildeblood »

cim wrote:
Wildeblood wrote:
What's the difference between unshift and push?
The end it adds to.

Code: Select all

arr = [1,2,3,4];
arr.push(5); // arr = [1,2,3,4,5];
arr.unshift(0); // arr = [0,1,2,3,4,5];
Okay (?), what's the difference between shift and push then?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: [Release] marketObserver 1.6.1

Post by cim »

Wildeblood wrote:
cim wrote:
Wildeblood wrote:
What's the difference between unshift and push?
The end it adds to.

Code: Select all

arr = [1,2,3,4];
arr.push(5); // arr = [1,2,3,4,5];
arr.unshift(0); // arr = [0,1,2,3,4,5];
Okay (?), what's the difference between shift and push then?

Code: Select all

arr = [1,2,3,4];
arr.push(5); // arr = [1,2,3,4,5];
arr.unshift(0); // arr = [0,1,2,3,4,5];
v = arr.shift(); // arr = [1,2,3,4,5]; v = 0;
v = arr.pop(); // arr = [1,2,3,4]; v = 5;
See https://developer.mozilla.org/en-US/doc ... ects/Array for the full reference: there's also 'splice' for adding or removing entries from the middle of the array.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: [Release] marketObserver 1.6.1

Post by Wildeblood »

Bloody Spara! I've just looked at it again and realized the reason I couldn't understand how it works is because his in-line comments explaining how it works are wrong.

:evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil:
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: [Release] marketObserver 1.6.1

Post by spara »

Wildeblood wrote:
Bloody Spara! I've just looked at it again and realized the reason I couldn't understand how it works is because his in-line comments explaining how it works are wrong.

:evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil:
Sorry? We must be having a communication problem. Are you talking of playerSoldCargo -function?
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: [Release] marketObserver 1.6.1

Post by GGShinobi »

Wildeblood wrote:
Bloody Spara! I've just looked at it again and realized the reason I couldn't understand how it works is because his in-line comments explaining how it works are wrong.

:evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil:
*<shivers>* :? oh oh...
updating obsolete comments is not my strength, either... :roll:

I'll try to do better in the future! (don't wanna be the target of a furious Wildeblood) :mrgreen:
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: [Release] marketObserver 1.6.1

Post by Wildeblood »

That first comment, "enough purchases in one log entry":-

Code: Select all

	while(unitCount > 0 && this.$buyLog[commIndex].length > 0) { //purge buys from log
		currentElement = this.$buyLog[commIndex].shift();
		if (currentElement[0] > unitCount) { //enough purchases in one log entry
			if (this.$traderRankFeat)
				this.$profit = this.$profit + unitCount * (price - currentElement[1]);
			currentElement[0] = currentElement[0] - unitCount;
			this.$buyLog[commIndex].unshift(currentElement);
			unitCount = 0;
		}
		else { //not enough puchases in one log entry
			if (this.$traderRankFeat)
				this.$profit = this.$profit + currentElement[0] * (price - currentElement[1]);
			unitCount = unitCount - currentElement[0];
		}
	}
It should say, "More than enough purchases in one log entry."

And the second one, "not enough puchases in one log entry", should say, "May or may not be enough."

Anyway, on a more useful note, javascxript includes a handy array sorting function you seem to be unaware of:-

Code: Select all

this.$sortPurchaseBook = function()
	{
	function descendingSort(a,b) {return b[1] - a[1]}

	for (var i = 0; i < this.$purchaseBook.length; i++)
		{
		if (this.$purchaseBook[i].length > 1)
			{
			this.$purchaseBook[i].sort(descendingSort);
			}
		}
	}
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: [Release] marketObserver 1.6.1

Post by spara »

Wildeblood wrote:
That first comment, "enough purchases in one log entry":-
...
It should say, "More than enough purchases in one log entry."
:lol: Perfectly clear to me. But I can quite understand someone else has hard time understanding it.
Wildeblood wrote:
Anyway, on a more useful note, javascxript includes a handy array sorting function you seem to be unaware of:-

Code: Select all

this.$sortPurchaseBook = function()
	{
	function descendingSort(a,b) {return b[1] - a[1]}

	for (var i = 0; i < this.$purchaseBook.length; i++)
		{
		if (this.$purchaseBook[i].length > 1)
			{
			this.$purchaseBook[i].sort(descendingSort);
			}
		}
	}
I have used sort function in Trophy Collector, where it was straightforward ordering by the first element of array in array. I seem to have missed the sortfunction parameter. Looks quite handy. It looks so handy, that I'll have to rewrite the ordering function. Thanks for the tip.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: [Release] marketObserver 1.6.1

Post by spara »

Quick update on this one. I have found the problem. It's the plist-file that is used for market hud. In that file I have defined ~130 equipment images that are the ads. In script I toggle the visibility of those equipments to show ads (by adding and removing equipment). The problem is the timeout that kicks in when I read the plist file in fro the first time. I'm now pondering the next solutions:

1. Remove ads. (Ouch. I really like those ads. I find them very athmospheric)
2. Reduce the number of ads. (There are already some ads that are already ruined after resizing. But what would be the amount that would work? Trial and error I guess)
3. Somehow preload the hud when all is quiet. (I've been experimenting with this one and I'm not very optimistic with it. It seems to cause timeout whenever I read it. Solonar is also trying this for me.)
4. Write a different plist hud-file for all ad-pairs. Without reducing the number of ads that would meant ~130 hud-files. Would that be a problem somehow? That would probably also mean that I need to do some compatibility stuff for AI Trading Assistant.

Number 3 seems to be dead end. And number 1 is the last resort. That means its either number 2 or 4. I think I'll go with the 4th solution, it's probably the easiest for me, just coding. If there is some problem with the large number (~130) of hud files, please let me know.

Time to dust off my Bash and Gawk skillz and split the plist-file :lol:.
Post Reply