• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fixed Shipyard Interface Performance Issues

Levis

Find(Rum) = false;
Staff member
Administrator
Creative Support
Programmer
Storm Modder
So I did some work on optimizing the shipyard interface now.
I found out the getSellprice is called 3 times for each ship or so. So this caused some lags.
Also in the cannons interface there was a function called each milliseccond while it wasn't used.
There is still a lot of debug code in this file but it's all disabled atm so you shouldn't have a problem with it now.
Still need to look more at it but I think this should give a noticeable effect already with the jerkyness in at last the repair and cannons interface.
Please let me know if it helps.

Place in: PROGRAM\INTERFACE
 

Attachments

  • shipyard.c
    175.3 KB · Views: 124
That's awesome! This is definitely a performance issue that I was noticing myself too as the Shipyard Interface took quite a while to load.
With a bit of luck, this will help a lot. Thanks very much! :doff
 
Haven't checked the loading that much yet. I do see there is a lot going on there also. But figuring it all out takes time so I tried to prioritize the using of the interface.
 
@Levis: Performance is definitely better with this one.
But there is an obvious bug: The "Cannot Buy - Too expensive" text is apparently showing for all ships all the time.
Except when it changes to "Tier Too High" or "Navy Ship". Big odd. :facepalm
 
I think that's an easy fix. This:
Code:
if(money < buyPrice) return 1;
Should probably be this:
Code:
if(money < buyPrice - sellPrice) return 1;
 
Oh right, that had to be changed ofc.
I would put the buyprice - sellprice in brackets tough.
 
Got multiple people say its fixed so gonna call this one. Might look at it later but for now there are more pressing matters :).
 
Got multiple people say its fixed so gonna call this one. Might look at it later but for now there are more pressing matters :).
As far as I can tell, the Shipyard Interface is OK on performance.
Not sure if there are any weird unexpected effects though, but that has to be discovered from the testers.
 
For some bizarre reason, I ran into another performance issue with the Shipyard Interface with the latest modpack update I'm working on.
To be sure it isn't something I did, I also checked the Sunday 27 September 2015 version and confirmed the problem.

Start new game and execute this through console:
Code:
  ch = CreateOfficer_Cheat(OFFIC_TYPE_CAPNAVY, "Barbossa", 3, PIRATE, false);
   ch.name = "Hector";
   ch.lastname = "Barbossa";
   GiveShip2Character(ch,SHIP_CURSED,"Black Pearl",-1,PIRATE,true,true);
   SetCompanionIndex(pchar, -1, GetCharacterIndex(ch.id));
   RemovePassenger  (pchar,  CharacterFromID  (ch.id));
Then go to the shipyard to sell the cursed Black Pearl. As soon as I click on the Pearl's icon, it takes a surprising while for the game to respond again.
Must have been a good 10-15 seconds.

EDIT: This was on Realistic Game Mode if that makes any difference.
 
Last edited:
It could be that this affects exclusively SHIP_CURSED . Haven't triggered it with any other ship when I thought to check it on second try.
 
Could you confirm this only happens for cursed ships?
 
It seems to happen for uncursed ones too.
The first time you click on a companion ship, the game takes a while to respond.
It is playable though as at least it should be only once.
 
Just took a look at this again. The problem is because of this:
Code:
int GetGoodPriceByType(ref refStore, ref char, int iGoodType, int quantity, int PriceType)
{
    //if(!TestRef(rStoreTown) || !CheckAttribute(rStoreTown,"size")) rStoreTown = GetCurrentTown();
    int unitSize = sti(Goods[iGoodType].Units);
    int i = iGoodType;
    bool tmpbooltn = false;
    string tname = GetTownIDFromGroup(refStore.group);
    int tsize = GetTownSize(tname);
    //if(CheckAttribute(rStoreTown,"id") && rStoreTown.id == tname) tmpbooltn = true;
    //if(!tmpbooltn)
    //{
        //rStoreTown = GetTownFromID(tname);
        //if(!CheckAttribute(rStoreTown,"size")) { trace("town " +tname + ", " + rStoreTown.name + " has no size!"); tsize = DEFAULT_TOWN_POP; }
        //else { tsize = sti(rStoreTown.size); } // assign the aref up here. NK 05-04-15
    //}
    //temp so it doesn't get so slow.
    // TIH added gunpowder here, as it KILLS the game with high quantitys! Jul20'06
    if( i==GOOD_BALLS || i==GOOD_GRAPES || i==GOOD_KNIPPELS || i==GOOD_BOMBS || i==GOOD_GUNPOWDER )
    {
        return makeint((quantity*GetStoreGoodsPrice(&refStore, iGoodType, PriceType, &char, 0) + unitSize-1) / unitSize);
    }
    //start normal good price find loop
    // sped up 05-04-15 NK
    //int oQty = GetStoreGoodsQuantity(refStore, iGoodType); // find orig qty.
    int price = 0;
    int mult = 1;
    if(PriceType == PRICE_TYPE_BUY) mult = -1;
    // new 05-04-15 -->
    string tmpstr = Goods[iGoodType].name;
    int gqty = refStore.Goods.(tmpstr).Quantity;
    if(gqty > 2 * quantity && gqty > tsize/4 ) // i.e. number is big enough we can do averages
    {
        price =  (GetStoreGoodsPrice(&refStore, iGoodType, PriceType, &char, 0) + GetStoreGoodsPrice(&refStore, iGoodType, PriceType, &char, mult * quantity)) / 2 * quantity;
    }
    else
    {
        for(i = 0; i < quantity; i++)
        {
            price += GetStoreGoodsPrice(&refStore, iGoodType, PriceType, &char, i);   <---------------THIS LINE
        }
    }
    int sumPrice = (price + unitSize-1) / unitSize;
    return sumPrice;
}

All goods are looped which can cause a pretty high delay.
I'm not going to tackle this now because I have planned to rewrite the whole economic system anyways so I will probably tackle it then.
What I could do it change the price calculation in the shipyard to the one used for gunpowder etc in this function. This means it will take an easier way to calculate the price which would be less accurate but way quicker.

Had a quick test and I only see an 2% price difference (approxiamatly) between the 2 ways of calculating the price. I'd say for the shipyard thats no problem.
 
Last edited:
Had a quick test and I only see an 2% price difference (approxiamatly) between the 2 ways of calculating the price. I'd say for the shipyard thats no problem.
Where does that difference come from?
 
Where does that difference come from?
If you loop trough te cargo the prices is adjusted after each sell.
Now you sell it all at the same price (so how you actually would do it in the store unless you are really trying to get the best money for your cargo :p).
 
If you loop trough te cargo the prices is adjusted after each sell.
Now you sell it all at the same price (so how you actually would do it in the store unless you are really trying to get the best money for your cargo :p).
Sounds like something I'd like to see changed at the actual stores too!
Right now, the sell prices seem to change WHILE you're selling. Which doesn't make so much sense to me. :facepalm
 
Back
Top