footballjds
2013-12-16 01:25:40
title is weird, huh?
But seriously, we can "almost" multithread.
by using global variables and checks at the beginning of every procedure/function the exits if it was called within so many milliseconds;
I'll outline a quick example below, NOTE this will not compile and is pseudocode/example text.
Please note, you can always write a regular procedure that has no check at the top.
I plan to write an entire script incorporating some of this style throughout(evil chicken lair black dragon + fam sup(terror, tort, yak)):
But seriously, we can "almost" multithread.
by using global variables and checks at the beginning of every procedure/function the exits if it was called within so many milliseconds;
I'll outline a quick example below, NOTE this will not compile and is pseudocode/example text.
Please note, you can always write a regular procedure that has no check at the top.
I plan to write an entire script incorporating some of this style throughout(evil chicken lair black dragon + fam sup(terror, tort, yak)):
var
ore_TPA: TPointArray;
_findOre, _setLocation, _walkToBank: integer;
procedure setLocation;
const
threadSleep = 350;
begin
{if the last time this function was called plus the sleep time in milliseconds
is greater than the current time it will exit. Forcing this function to sleep
for the period of time in the const}
if (_setLocation + threadSleep) > getSystemTime then exit;
players[currentPlayer].location := externalFindFunction;
_setLocation := getSystemTime;
end;
procedure updateOreTPA:;
const
threadSleep = 750;
begin
{if the last time this function was called plus the sleep time in milliseconds
is greater than the current time it will exit. Forcing this function to sleep
for the period of time in the const. it will also exit if we're not at the mine,
obviously we wouldn't want to search for ore unles we are at the mine.}
if ((_findOre + threadSleep) > getSystemTime) or
(players[currentPlayer].location <> 'mine')then exit;
ore_TPA := FindOrePoints;
_findOre := getSystemTime;
end;
procedure walkToBank;
const
threadSleep = 150;//low number is fine because it will BARELY use resources if it doesn't execute
begin
{unless the procedure hasn't been called in 150 millisceonds, we're not already
at the bank AND the inventory is full we're going to exit out of this}
if ((_walkToBank + threadSleep) > getSystemTime) or (players[currentPlayer].location = 'bank') or (tabBackpack.count < 28) then exit;
if walkPath('bank') then writeln('we walked to the bank');
end;
begin
while true do
begin
walkToBank
updateOreTPA;
setLocation;
wait(10);
end;
end.