• 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!

Abandoned Optimalization

Levis

Find(Rum) = false;
Staff member
Administrator
Creative Support
Programmer
Storm Modder
it seems to me the dailycrewupdate has become very sluggish.
Maybe we should take a look at it and see if things are happening which should happen or optimize some stuff.

While taking a quick look I saw for example at one point the food usage was calculated but a while later this happens again but in a if statement this time. I haven't had time to look at this good but maybe the other part should be in the else instead of also in there.
Also I noticed things like this:
Code:
for(i=0; i<4; i++){cn = GetCompanionIndex(&pchar,i);if(cn!=-1) ft[i] = makeint(makefloat(foodQ)*foodRatio[i]);} ....

for(i=0; i<4; i++)
{
cn = GetCompanionIndex(&pchar,i);
if(cn!=-1) SetCharacterGoods(&Characters[cn],GOOD_WHEAT, ft[i]);
}

so you see the same foreloop is done here twice but they do other things.
this could be made like this:
Code:
for(i=0; i<4; i++)
{
cn = GetCompanionIndex(&pchar,i);
if(cn!=-1)
{
ft[i] = makeint(makefloat(foodQ)*foodRatio[i]);
SetCharacterGoods(&Characters[cn],GOOD_WHEAT, ft[i]);
}
}
this would reduce the time it takes to run this script a bit and probally makes the code more clear.
I dont have time for this yet, but if someone wants feel free to begin on this, all small bit help. so if you find improvements on the script please submit them here.
if you need a place to start, then start with this
Code:
//if food doesn't divide evenly:
while(ft[0]+ft[1]+ft[2]+ft[3] != foodQ)
{
for(i=0; i<4; i++)
{
if(ft[i] > 0) 
//Ship had food
{
if(ft[0]+ft[1]+ft[2]+ft[3] > foodQ) //too much food alocated, so remove some
{
ft[i]--;
}
if(ft[0]+ft[1]+ft[2]+ft[3] < foodQ)
//not enough food alocated, so add some
{
ft[i]++;
}
}
}
}
haven't had time to look at it well but I think what happens here could be done WAY better and actually takes up quite some time like this.
 
Would be nice to smooth this out indeed.
But I won't be doing anything on this any time soon. Too many other things still to do.

It wasn't until recently that I began to understand code optimization at all.
Comes with the new job....
 
Checked it a bit more and you chould take a look at calender.c there the dailyupdates are called and also some other functions are called to fill the shops etc. My guess is they actually cause more of the lag. Also if we want to improve this we should get rid of some of the trace messages and log messages.
 
Changed to "Feature Request" since this is not technically a bug.
 
From what I can see both on land and sea things are called by events which are repeatedly called. With the game getting more and more complex some of these functions will cause lag on slower machines. Maybe it would be an idea to try to organise most of these calls and have a toggle for them on how often they are called. For example i did this a bit already in the landinterface when fixing the corpse looting at locators. I think we could increase the performance of the game significantly by this.
 
I've been looking at several function over the last weeks already and there is a lot to gain everywhere. I must warn this would mean fixing and rewriting a lot. But actually this is the kind of programming I like so I'm willing to do it. But I say sorry already for all bugs I'm going to introduce because a lot of mod added features add theire exceptions just somewhere in the code where they found it worked so I might increase performance on a function but by doing that a certain function might be called less often and break a mod added feature untill I fix it.
 
Big question is which Build version this should then go in. Ideally Build 14 should run as efficiently as possible, but huge amount of rewrites sound risky at best.
Perhaps we should put that in the Build 15 base indeed, just to avoid breaking things that are currently working even if they don't work perfectly.
 
I will try to make a start with this then but only where not much rewriting is required so we can increase the performance. And the parts where I'm afraid to break stuff I will keep for now.
 
A simple gain we can get it to have a attribute to store the time since a last load and move some of the daily updates to update on load and then check how much time has past (things like shops and towns etc) the daily update should only do things which actually affect you at sea like crew payment etc.
 
@Levis has been doing some work on this again. :woot

Just to be sure: Did you change anything in the initialization orders and such?
Last time I played around with that, I broke some stuff that we only found out MONTHS later because it affected the ending of the Standard Storyline.
Specifically, because the order between item and location initialization changed, placing the statue on the pedestal no longer activated the next quest case. :facepalm
 
@Levis has been doing some work on this again. :woot

Just to be sure: Did you change anything in the initialization orders and such?
Last time I played around with that, I broke some stuff that we only found out MONTHS later because it affected the ending of the Standard Storyline.
Specifically, because the order between item and location initialization changed, placing the statue on the pedestal no longer activated the next quest case. :facepalm
For now the only things I moved are before the start of a game.
I will try not to move the order in which things are initialized.
 
We'll probably need to keep an eye out for unintended side-effects.
It is good that you're doing this, but the game can be touchy about all sorts of things. :facepalm
 
It seems to me that something in this section of code is decidedly slower in the 4 October version compared to the 27 September one:
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));
Not quite sure why....

EDIT: It is CreateOfficer_Cheat! Just executing GiveShip2Character on the player is very quick:
Code:
GiveShip2Character(pchar,SHIP_CURSED,"Black Pearl",-1,PIRATE,true,true);
 
Back
Top