-
Original Question: https://cafe.naver.com/edac/112087 For units whose indexes are from 1 to 1500, epScript codefunction setGroundCooldown() {
const weaponCooldown = EUDArray(py_eval("[1] * 13 + [99] * 215"));
for (var i = 1 ; i <= 1500 ; i++) {
if (MemoryX(0x628298 + 0x150 * (i-1) + 0x54, AtLeast, 256 *
weaponCooldown[dwread(0x628298 + 0x150 * (i-1) + 0x64)], 0xFF00)) {
SetMemoryX(0x628298 + 0x150 * (i-1) + 0x54, SetTo, 256 *
weaponCooldown[dwread(0x628298 + 0x150 * (i-1) + 0x64)], 0xFF00);
}
}
} This is a sample code for asking if there's a lag. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Why sample code are poorly writtenSample code occupies only 41 triggers at the expense of massive runtime lag.
Answer 1.Since weapon cooldown is determined by unit type, we can cache unit type and reuse cooldown value if unit type has not changed. function setGroundCooldown() {
const updateTrigger = function(unitEpd, unitVar, varEpd, triggerEpd) {
// Do not recalculate trigger if unitType stays still
if (MemoryXEPD(unitEpd, Exactly, unitVar, 255)) return;
const unit = bread_epd(unitEpd, 0);
dwwrite_epd(varEpd, unit);
const cooldownArray = EUDArray(py_eval("[1] * 13 + [99] * 215"));
const cooldown = 256 * bread_epd(EPD(cooldownArray) + unit, 0);
dwwrite_epd(triggerEpd + (8 + 8) / 4, cooldown); // set value of 1st condition
dwwrite_epd(triggerEpd + (328 + 20) / 4, cooldown); // set value of 1st action
};
foreach(i : py_range(1500)) {
const ptr = 0x628298 - 0x150 * i;
const setCooldown = Forward();
static var unit = 228;
updateTrigger(EPD(ptr + 0x64), unit, EPD(unit.getValueAddr()), EPD(setCooldown));
setCooldown.__lshift__(RawTrigger(
conditions=MemoryX(ptr + 0x54, AtLeast, 0, 0xFF00),
actions=SetMemoryX(ptr + 0x54, SetTo, 0, 0xFF00)
));
}
} Question 2. More parameterReal code has enchant level at unused space Answer 2. Simple adjustmentUnit type and enchant level are parameters for weapon cooldown. function setGroundCooldown() {
const updateTrigger = function(unitEpd, cache, cacheEpd, triggerEpd) {
// Do not recalculate trigger if unitType and enchantLevel stay still
if (MemoryXEPD(unitEpd + 0x64/4, Exactly, cache, 255)
&& MemoryXEPD(unitEpd + 0x24/4, Exactly, cache, 0xFF0000)) return;
const unit = bread_epd(unitEpd + 0x64/4, 0);
const enchant = maskread_epd(unitEpd + 0x24/4, 0xFF0000);
dwwrite_epd(cacheEpd, unit + enchant);
const cooldownArray = EUDArray(py_eval("[1] * 13 + [99] * 215"));
const cooldown = bread_epd(EPD(cooldownArray) + unit, 0) * (655360 - enchant) / 655360;
dwwrite_epd(triggerEpd + (8 + 8) / 4, cooldown); // set value of 1st condition
dwwrite_epd(triggerEpd + (328 + 20) / 4, cooldown); // set value of 1st action
};
foreach(i : py_range(1500)) {
const ptr = 0x628298 - 0x150 * i;
const setCooldown = Forward();
static var cache = 228;
updateTrigger(EPD(ptr), cache, EPD(cache.getValueAddr()), EPD(setCooldown));
setCooldown.__lshift__(RawTrigger(
conditions=MemoryX(ptr + 0x54, AtLeast, 0, 0xFF00),
actions=SetMemoryX(ptr + 0x54, SetTo, 0, 0xFF00)
));
}
} Similar optimization has done in Buizz/EUD-Editor-3#96 Summary
|
Beta Was this translation helpful? Give feedback.
Why sample code are poorly written
Sample code occupies only 41 triggers at the expense of massive runtime lag.
var i
isEUDVariable
, so address must be calculated during game.Calculating
0x628298 + 0x150 * (i-1) + 0x54
involves following trigger executions:1
in(i-1)
0x150
0x628298
and0x64
EPD = (ptr - 0x58A364) ÷ 4
Simple refactoring quarters trigger executions.