新年快乐
我写了这篇开发日志,就不能不告诉你“新年快乐”bug。简单地说,我们在一个相当大的星系上玩开发版MP,并达到了相当晚的时间。并且由于我们都在远程工作,以各种不同的电脑和互联网连接速度运行,性能可能有点慢,但大部分还是可以接受的。然后,突然间,我们注意到了巨大的延时尖峰——大约20 s或者更多——在1月1日。这些尖峰如此引人注目,以至于每次我们的游戏都冻结了,于是我们就开始祝福其他人新年快乐!
这种延时的爆发恰好与几个大帝国决定机飞,并开始同化他们的帝国相吻合。现在,同化属于应该在脚本中完成的事情,事后看来或许不应该那么做……甚至通过在每个1月1日为每个同化国家触发一个事件来工作。这个事件反过来为他们的每个行星都触发了一个事件,而这一被触发的事件有选择了行星上的每个pop,并至少对每个pop使用了一次modify_species,有时能多达四次。这加起来是十分重要的性能开销。
在尝试了各种解决方案后,我们发现最好的修复办法是,首先检查在这一国家作用域内的every_owned_species,检查这一物种是否应该被同化。如果应该,那么用modify_species来创造将被同化的物种,设置一个物种标志,用以指向正在被同化的物种。然后,不是为每一个被同化的pop创建一个新物种,脚本被重写为:查找已经被创造的pop应该被同化的物种,并简单地对其使用change_species。这一结果仍然是不可读的脚本(我会节省你们的眼神,不把它放在这里),但是在我的测试中,这样做减少了超过50%的每年的tick数。因为我们尽可能少地运行了复杂的效果(modify_species)。
Happy New Year
I can’t write this dev diary without telling you about the “Happy New Year” bug. Basically, we were playing dev MP on a reasonably large galaxy and reached reasonably late into the game, and since we were all working remotely on wildly varying computers and internet connection speeds, the performance was perhaps a tad sluggish, but still acceptable for the most part. Then, suddenly, we noticed huge lag spikes - 20 seconds and more - on the 1st of January. So noticeable were these spikes that we began wishing each other a Happy New Year each time the game froze!
It just so happened that the onset of this lag coincided with several large empires deciding to become synthetic and starting to assimilating their empires. Now, assimilation falls into the category of things that are done in script that maybe, in hindsight, should probably not have been done that way… and works by firing an event for each assimilating country every 1st of January. This event in turn fired an event for each of their planets that selected a bunch of pops on the planet and used modify_species on each of them at least once, but sometimes up to four times. This added up to a fairly significant performance hog!
After trying various solutions, it turned out the best way to fix this was to first go through every_owned_species from the country scope, check whether this species should be assimilated, and if so use modify_species to create the species it would assimilate to, setting a species flag that pointed to the species it was being assimilated from. Then, instead of creating a new species for every pop that was assimilated, the scripts were rewritten to find the already-created species that the pop should become, and simply use change_species on it. The result is still unreadable script (I will spare your eyes and not post it here), but in my tests it reduced the yearly tick by over 50%, thanks to the complicated effect (modify_species) being run as seldom as possible.
我写了这篇开发日志,就不能不告诉你“新年快乐”bug。简单地说,我们在一个相当大的星系上玩开发版MP,并达到了相当晚的时间。并且由于我们都在远程工作,以各种不同的电脑和互联网连接速度运行,性能可能有点慢,但大部分还是可以接受的。然后,突然间,我们注意到了巨大的延时尖峰——大约20 s或者更多——在1月1日。这些尖峰如此引人注目,以至于每次我们的游戏都冻结了,于是我们就开始祝福其他人新年快乐!
这种延时的爆发恰好与几个大帝国决定机飞,并开始同化他们的帝国相吻合。现在,同化属于应该在脚本中完成的事情,事后看来或许不应该那么做……甚至通过在每个1月1日为每个同化国家触发一个事件来工作。这个事件反过来为他们的每个行星都触发了一个事件,而这一被触发的事件有选择了行星上的每个pop,并至少对每个pop使用了一次modify_species,有时能多达四次。这加起来是十分重要的性能开销。
在尝试了各种解决方案后,我们发现最好的修复办法是,首先检查在这一国家作用域内的every_owned_species,检查这一物种是否应该被同化。如果应该,那么用modify_species来创造将被同化的物种,设置一个物种标志,用以指向正在被同化的物种。然后,不是为每一个被同化的pop创建一个新物种,脚本被重写为:查找已经被创造的pop应该被同化的物种,并简单地对其使用change_species。这一结果仍然是不可读的脚本(我会节省你们的眼神,不把它放在这里),但是在我的测试中,这样做减少了超过50%的每年的tick数。因为我们尽可能少地运行了复杂的效果(modify_species)。
Happy New Year
I can’t write this dev diary without telling you about the “Happy New Year” bug. Basically, we were playing dev MP on a reasonably large galaxy and reached reasonably late into the game, and since we were all working remotely on wildly varying computers and internet connection speeds, the performance was perhaps a tad sluggish, but still acceptable for the most part. Then, suddenly, we noticed huge lag spikes - 20 seconds and more - on the 1st of January. So noticeable were these spikes that we began wishing each other a Happy New Year each time the game froze!
It just so happened that the onset of this lag coincided with several large empires deciding to become synthetic and starting to assimilating their empires. Now, assimilation falls into the category of things that are done in script that maybe, in hindsight, should probably not have been done that way… and works by firing an event for each assimilating country every 1st of January. This event in turn fired an event for each of their planets that selected a bunch of pops on the planet and used modify_species on each of them at least once, but sometimes up to four times. This added up to a fairly significant performance hog!
After trying various solutions, it turned out the best way to fix this was to first go through every_owned_species from the country scope, check whether this species should be assimilated, and if so use modify_species to create the species it would assimilate to, setting a species flag that pointed to the species it was being assimilated from. Then, instead of creating a new species for every pop that was assimilated, the scripts were rewritten to find the already-created species that the pop should become, and simply use change_species on it. The result is still unreadable script (I will spare your eyes and not post it here), but in my tests it reduced the yearly tick by over 50%, thanks to the complicated effect (modify_species) being run as seldom as possible.





多多良小傘








