hedgewars/uFLRunQueue.pas
author unc0rr
Mon, 14 Dec 2015 00:24:03 +0300
branchqmlfrontend
changeset 11459 3c5d99013baf
parent 11457 78860824b5a5
child 11461 ab77e2ea2f82
permissions -rw-r--r--
- Improve IPC handling in engine - Handle EM protocol command - Some fixes for net game
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
11456
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
     9
uses uFLGameConfig, hwengine, uFLData, 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
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    23
        sendConfig(runQueue)
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    24
    end
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    25
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    26
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    27
procedure cleanupConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    28
var t: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    29
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    30
    t:= runQueue;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    31
    runQueue:= t^.nextConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    32
    dispose(t)
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    33
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    34
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    35
procedure queueExecution(var config: TGameConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    36
var pConfig, t, tt: PGameConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    37
    i: Longword;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    38
begin
11457
78860824b5a5 Introduce barriers between messages to different engine instances
unc0rr
parents: 11456
diff changeset
    39
    ipcSetEngineBarrier();
78860824b5a5 Introduce barriers between messages to different engine instances
unc0rr
parents: 11456
diff changeset
    40
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    41
    new(pConfig);
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    42
    pConfig^:= config;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    43
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    44
    with pConfig^ do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    45
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    46
        nextConfig:= nil;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    47
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    48
        for i:= 0 to Pred(MAXARGS) do
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    49
        begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    50
            if arguments[i][0] = #255 then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    51
                arguments[i][255]:= #0
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    52
            else
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    53
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    54
            argv[i]:= @arguments[i][1]
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    55
        end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    56
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    57
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    58
    if runQueue = nil then
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    59
    begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    60
        runQueue:= pConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    61
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
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    68
            if (pConfig^.gameType = gtPreview) and (t^.nextConfig^.gameType = gtPreview) then
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;
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
procedure passFlibEvent(p: pointer); cdecl;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    83
begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    84
    case TFLIBEvent(p^) of
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    85
        flibGameFinished: begin
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    86
                cleanupConfig;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    87
                nextRun
11456
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    88
            end;
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    89
        flibRunNetGame: begin
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    90
                runNetGame
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11439
diff changeset
    91
            end;
11439
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    92
    end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    93
end;
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    94
23912c93935a - Implement engine runs queue
unc0rr
parents:
diff changeset
    95
end.