hedgewars/uFLRunQueue.pas
author unc0rr
Sun, 24 Dec 2017 00:44:16 +0100
branchqmlfrontend
changeset 12863 0c6fb706f747
parent 11465 9f2fb0031ef0
permissions -rw-r--r--
More refactoring in attempt to move away from frontlib
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
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     7
implementation
12863
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 11465
diff changeset
     8
uses hwengine, uFLUICallback, uFLIPC;
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
     9
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    10
var runQueue: PGameConfig = nil;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    11
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    12
procedure nextRun;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    13
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    14
    if runQueue <> nil then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    15
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    16
        if runQueue^.gameType = gtPreview then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    17
            sendUI(mtRenderingPreview, nil, 0);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    18
11457
78860824b5a5 Introduce barriers between messages to different engine instances
unc0rr
parents: 11456
diff changeset
    19
        ipcRemoveBarrierFromEngineQueue();
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    20
        RunEngine(runQueue^.argumentsNumber, @runQueue^.argv);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    21
    end
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    22
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    23
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    24
procedure cleanupConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    25
var t: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    26
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    27
    t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    28
    runQueue:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    29
    dispose(t)
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    30
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    31
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    32
procedure queueExecution(var config: TGameConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    33
var pConfig, t, tt: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    34
    i: Longword;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    35
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    36
    new(pConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    37
    pConfig^:= config;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    38
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    39
    with pConfig^ do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    40
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    41
        nextConfig:= nil;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    42
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    43
        for i:= 0 to Pred(MAXARGS) do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    44
        begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    45
            if arguments[i][0] = #255 then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    46
                arguments[i][255]:= #0
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    47
            else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    48
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    49
            argv[i]:= @arguments[i][1]
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    50
        end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    51
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    52
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    53
    if runQueue = nil then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    54
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    55
        runQueue:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    56
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    57
        ipcSetEngineBarrier();
12863
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 11465
diff changeset
    58
        //sendConfig(pConfig);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    59
        nextRun
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    60
    end else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    61
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    62
        t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    63
        while t^.nextConfig <> nil do 
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    64
        begin
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    65
            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
    66
            begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    67
                tt:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    68
                pConfig^.nextConfig:= tt^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    69
                t^.nextConfig:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    70
                dispose(tt);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    71
                exit // boo
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    72
            end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    73
            t:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    74
        end;
11464
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    75
30397f91571c Fix a ton of bugs in engine instances queue and ipc
unc0rr
parents: 11461
diff changeset
    76
        ipcSetEngineBarrier();
12863
0c6fb706f747 More refactoring in attempt to move away from frontlib
unc0rr
parents: 11465
diff changeset
    77
        //sendConfig(pConfig);
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    78
        t^.nextConfig:= pConfig
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    79
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    80
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    81
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    82
end.