hedgewars/uFLRunQueue.pas
author unc0rr
Sun, 20 Dec 2015 12:45:49 +0300
branchqmlfrontend
changeset 11465 9f2fb0031ef0
parent 11464 30397f91571c
child 12863 0c6fb706f747
permissions -rw-r--r--
Fix two bugs, and yay, spectating works now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     1
unit uFLRunQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     2
interface
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     3
uses uFLTypes;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     4
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     5
procedure queueExecution(var config: TGameConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     6
procedure passFlibEvent(p: pointer); cdecl;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     7
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     8
implementation
11461
ab77e2ea2f82 uFLData was renamed, update "uses"
sheepluva
parents: 11457
diff changeset
     9
uses uFLGameConfig, hwengine, uFLThemes, uFLUICallback, uFLIPC;
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    10
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    11
var runQueue: PGameConfig = nil;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    12
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    13
procedure nextRun;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    14
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    15
    if runQueue <> nil then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    16
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    17
        if runQueue^.gameType = gtPreview then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    18
            sendUI(mtRenderingPreview, nil, 0);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    19
11457
78860824b5a5 Introduce barriers between messages to different engine instances
unc0rr
parents: 11456
diff changeset
    20
        ipcRemoveBarrierFromEngineQueue();
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    21
        RunEngine(runQueue^.argumentsNumber, @runQueue^.argv);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    22
    end
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    23
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    24
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    25
procedure cleanupConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    26
var t: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    27
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    28
    t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    29
    runQueue:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    30
    dispose(t)
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    31
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    32
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    33
procedure queueExecution(var config: TGameConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    34
var pConfig, t, tt: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    35
    i: Longword;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    36
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    37
    new(pConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    38
    pConfig^:= config;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    39
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    40
    with pConfig^ do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    41
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    42
        nextConfig:= nil;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    43
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    44
        for i:= 0 to Pred(MAXARGS) do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    45
        begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    46
            if arguments[i][0] = #255 then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    47
                arguments[i][255]:= #0
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    48
            else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    49
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    50
            argv[i]:= @arguments[i][1]
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    51
        end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    52
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    53
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    54
    if runQueue = nil then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    55
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    56
        runQueue:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    57
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    58
        ipcSetEngineBarrier();
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    59
        sendConfig(pConfig);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    60
        nextRun
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    61
    end else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    62
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    63
        t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    64
        while t^.nextConfig <> nil do 
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    65
        begin
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    66
            if false and (pConfig^.gameType = gtPreview) and (t^.nextConfig^.gameType = gtPreview) and (t <> runQueue) then
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    67
            begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    68
                tt:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    69
                pConfig^.nextConfig:= tt^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    70
                t^.nextConfig:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    71
                dispose(tt);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    72
                exit // boo
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    73
            end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    74
            t:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    75
        end;
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    76
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    77
        ipcSetEngineBarrier();
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    78
        sendConfig(pConfig);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    79
        t^.nextConfig:= pConfig
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    80
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    81
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    82
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    83
procedure passFlibEvent(p: pointer); cdecl;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    84
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    85
    case TFLIBEvent(p^) of
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    86
        flibGameFinished: begin
11465
9f2fb0031ef0 Fix two bugs, and yay, spectating works now
unc0rr
parents: 11464
diff changeset
    87
            cleanupConfig;
9f2fb0031ef0 Fix two bugs, and yay, spectating works now
unc0rr
parents: 11464
diff changeset
    88
            nextRun
9f2fb0031ef0 Fix two bugs, and yay, spectating works now
unc0rr
parents: 11464
diff changeset
    89
        end;
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    90
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    91
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    92
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    93
end.