Skip to content

Commit

Permalink
optimize core splitter simulation logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkc0d3r committed Nov 9, 2024
1 parent b4d5398 commit a6ae0e3
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions BeltBalancer/BeltEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,45 +709,23 @@ int updateOnCPUSorted(BeltEntity* entities, size_t size, unsigned int iterations
float supply = lsupply + rsupply;
if (demand >= supply)
{
float halfSupply = supply / 2;
b->subtractFromBuffer = lsupply;
r->subtractFromBuffer = rsupply;
if (ldemand < halfSupply)
{
lnext->addToBuffer = ldemand;
rnext->addToBuffer = supply - ldemand;
}
else if (rdemand < halfSupply)
{
rnext->addToBuffer = rdemand;
lnext->addToBuffer = supply - rdemand;
}
else
{
lnext->addToBuffer = halfSupply;
rnext->addToBuffer = halfSupply;
}
float pushLeft = minss(ldemand, supply / 2);
float pushRight = minss(rdemand, supply - pushLeft);
pushLeft = supply - pushRight;
lnext->addToBuffer = pushLeft;
rnext->addToBuffer = pushRight;
}
else
{
float halfDemand = demand / 2;
lnext->addToBuffer = ldemand;
rnext->addToBuffer = rdemand;
if (lsupply < halfDemand)
{
b->subtractFromBuffer = lsupply;
r->subtractFromBuffer = demand - lsupply;
}
else if (rsupply < halfDemand)
{
r->subtractFromBuffer = rsupply;
b->subtractFromBuffer = demand - rsupply;
}
else
{
r->subtractFromBuffer = halfDemand;
b->subtractFromBuffer = halfDemand;
}
float subLeft = minss(lsupply, demand / 2);
float subRight = minss(rsupply, demand - subLeft);
subLeft = demand - subRight;
b->subtractFromBuffer = subLeft;
r->subtractFromBuffer = subRight;
}
}

Expand Down

0 comments on commit a6ae0e3

Please sign in to comment.