[Defconapi] Extensive use of SendChatMessage
Jakub Gemrot
jakub.gemrot at gmail.com
Mon Oct 5 06:37:41 CDT 2009
Hi!
I'm using Defcon-JavaBot.
I've been trying to use SendChatMessage as one of the way to log my
bot's actions.
Unfortunately extensive use of this method causes the update() to be
called less often as it should be called.
At first it is called every 100ms, but after 5 minutes it's every 250ms!
Read the code please at then end of the mail.
Basicly - I'm abusing SendChatMessage a lot! Sending 4 messages in 100ms
and things are even worse - I'm using SendChatMessage outside update() method.
My questions:
1) is it normal? (the lag between update() method calls is getting
worse and worse)
2) is it because I'm sending messages in "unsync way" (not only from
update() method)?
3) or is it because the SendChatMessage should not be used for logging?
4) how the logging should be approached in general in DefCon?
I'm going to investigate this topic further. Just want to report and
ask some basic questions :-)
Jakub
P.S.: I'm investigating these things only from the Java side, not
doing anything to the C++ code...
static boolean first = true;
static long start;
static long lastRun = 0;
// update is called every tick of the game
public static boolean update()
{
if (first) {
start = System.currentTimeMillis();
new Thread(new Runnable() {
@Override
public void run() {
start = System.currentTimeMillis();
while(true) {
SendChatMessage("Unsync message at " +
(System.currentTimeMillis() - start) + " ms", CHATCHANNEL_PUBLIC);
try {
Thread.sleep(31);
} catch (Exception e) {
}
}
}
}).start();
first = false;
} else {
SendChatMessage("Sync message, update called after " +
(System.currentTimeMillis()-lastRun) + " ms", CHATCHANNEL_PUBLIC);
}
lastRun = System.currentTimeMillis();
return true;
}
// this is called when the dll is initialised, usually in the
host/join dialog of the game
public static boolean initialise(String[][] _commandLineOptions)
{
SendChatMessage("Initialised...", CHATCHANNEL_PUBLIC);
return true;
}
public static void addEvent(int _eventType, int _causeObjectId,
int _targetObjectId,
int _unitType, float _longitude, float _latitude)
{
}
More information about the Defconapi
mailing list