 |
 |
 |
 |
|
 |
 |
| Author |
Message |
OldnGrey
Joined: 04 Feb 2006 Posts: 517
|
Posted: Sat Jan 13, 2007 1:04 am Post subject: |
|
|
Here are the changes I made to the distro decay system. Notes below show why:
| Code: | CONST RECT_SIZE := 32;
program DecayCycle(realm)
// Make sure there isn't already a decay cycler running for this realm.
Set_Critical(1);
if ( GetProcess(CInt(GetGlobalProperty("#DecayPid-"+realm.name))) )
return 0;
else
SetGlobalProperty("#DecayPid-"+realm.name, GetPid());
endif
Set_Critical(0);
var data_file := DFOpenDataFile("DecayInfo", DF_CREATE);
var data_elem := DFFindElement(data_file, "Status-"+realm.name, DF_CREATE);
Set_Priority(1);
Sleep(3);
/* Start from the last place the decayer was at.
* This is to ensure that if there are a lot of crashes,
* it doesn't decay the start of the realm over and over.
*/
var cur_x := CInt(data_elem.GetProp("X"));
var cur_y := CInt(data_elem.GetProp("Y"));
// Report the starting position of the decay cycle for this realm.
DECAY_ReportText("Starting "+realm.name+" decayer at X:"+cur_x+" Y:"+cur_y + " Width: " + realm.width + " Height: " + realm.height, DECAY_REPORT_CONSOLE+DECAY_REPORT_SYSLOG);
while ( 1 )
//check to see if the server is shutting down. If so, quit
if ( GetGlobalProperty("#restartingserver") )
DECAY_ReportText("Closing down decay system in " + realm.name + " as server is shutting down.", DECAY_REPORT_CONSOLE+DECAY_REPORT_SYSLOG);
return 0;
endif
var starttimer := ReadGameClock();
for ( cur_x; cur_x <= realm.width; cur_x := cur_x + RECT_SIZE )
for ( cur_y; cur_y <= realm.height; cur_y := cur_y + RECT_SIZE )
/*
* Note:
* Print("Decayer: sweeping "+cur_x+" "+cur_y+" "+(cur_x+RECT_SIZE)+" "+(cur_y+RECT_SIZE));
* ListObjectsInBox() is ruthless and will list everything that is in that rect.
*/
foreach object in ( ListObjectsInBox(cur_x, cur_y, -130, cur_x+RECT_SIZE, cur_y+RECT_SIZE, 130, realm.name) )
if ( CanRemove(object) )
RemoveObject(object);
endif
endforeach
data_elem.SetProp("Y", cur_y);
if ( realm.name == "britannia" )
// realm not used. do it slowly
SleepMS(400);
else
SleepMS(10);
endif
endfor
cur_y := 0;
data_elem.SetProp("X", cur_x);
endfor
// A full realm sweep has been done.
cur_x := 0;
cur_y := 0;
data_elem.SetProp("X", 0);
data_elem.SetProp("Y", 0);
var elapsedtime := ReadGameClock() - starttimer;
DECAY_ReportText("Decay sweep of " + realm.name + " took " + elapsedtime + " seconds", DECAY_REPORT_CONSOLE+DECAY_REPORT_SYSLOG);
//Ensure decayer run 15 minutes after last time.
var nextloop := starttimer + 900;
while ( ReadGameClock() < nextloop )
Sleep(60);
endwhile
endwhile
return 1;
endprogram |
A couple of notes:
* yeah made 096 compatible.. cos that's what I use!
* I play in britannia_alt, that's why the decay for britannia is slow.
* the while loop at the end of the program is there just to ensure decay only happens every 15 minutes, not 15 minutes after you last ran it.
* the sleeps seem to work ok for a realm with about 60,000 top level items.
* the RECT+SIZE is 32 to make it fit map boundaries better
* cur_y is reset to 0 otherwise the inner for/enfor loop doesn't run more than once.
* I have a cprop set by shutdown timers to signal impending shutdown, it's tested here to close down the decay system early
Extenal changes:
* I also don't log every item decayed, I only log if it can't decay something.
* The decayCycle is started 10 minute after shard startup so players can at least attempt to get to things after restart. |
|
 |
|
|
 |
 |
|