hedgewars/uFLRunQueue.pas
author unc0rr
Thu, 17 Dec 2015 00:51:20 +0300
branchqmlfrontend
changeset 11464 30397f91571c
parent 11461 ab77e2ea2f82
child 11465 9f2fb0031ef0
permissions -rw-r--r--
Fix a ton of bugs in engine instances queue and ipc
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
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    17
    writeln('RUNNING ', runQueue^.gameType);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    18
        if runQueue^.gameType = gtPreview then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    19
            sendUI(mtRenderingPreview, nil, 0);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    20
11457
78860824b5a5 Introduce barriers between messages to different engine instances
unc0rr
parents: 11456
diff changeset
    21
        ipcRemoveBarrierFromEngineQueue();
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    22
        RunEngine(runQueue^.argumentsNumber, @runQueue^.argv);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    23
    end
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    24
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    25
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    26
procedure cleanupConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    27
var t: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    28
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    29
    t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    30
    runQueue:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    31
    dispose(t)
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    32
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    33
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    34
procedure queueExecution(var config: TGameConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    35
var pConfig, t, tt: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    36
    i: Longword;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    37
begin
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    38
    writeln('QUEUE EXECUTION ', config.gameType);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    39
    new(pConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    40
    pConfig^:= config;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    41
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    42
    with pConfig^ do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    43
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    44
        nextConfig:= nil;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    45
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    46
        for i:= 0 to Pred(MAXARGS) do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    47
        begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    48
            if arguments[i][0] = #255 then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    49
                arguments[i][255]:= #0
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    50
            else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    51
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    52
            argv[i]:= @arguments[i][1]
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    53
        end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    54
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    55
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    56
    if runQueue = nil then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    57
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    58
        runQueue:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    59
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    60
        ipcSetEngineBarrier();
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    61
        sendConfig(pConfig);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    62
        nextRun
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    63
    end else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    64
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    65
        t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    66
        while t^.nextConfig <> nil do 
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    67
        begin
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    68
            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
    69
            begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    70
                tt:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    71
                pConfig^.nextConfig:= tt^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    72
                t^.nextConfig:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    73
                dispose(tt);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    74
                exit // boo
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    75
            end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    76
            t:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    77
        end;
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    78
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    79
        ipcSetEngineBarrier();
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    80
        sendConfig(pConfig);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    81
        t^.nextConfig:= pConfig
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    82
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    83
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    84
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    85
procedure passFlibEvent(p: pointer); cdecl;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    86
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    87
    case TFLIBEvent(p^) of
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    88
        flibGameFinished: begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    89
                cleanupConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    90
                nextRun
11456
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    91
            end;
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    92
        flibRunNetGame: begin
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    93
                runNetGame
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    94
            end;
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    95
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    96
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    97
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    98
end.