hedgewars/uFLUICallback.pas
author unc0rr
Tue, 02 Aug 2016 23:08:17 +0300
branchqmlfrontend
changeset 11842 93e6c401cc3d
parent 11827 8c71c5a1172f
child 11843 01f88c3b7b66
permissions -rw-r--r--
Preparation to sending engine messages to net.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     1
unit uFLUICallback;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     2
interface
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     3
uses uFLTypes;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     4
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     5
procedure registerUIMessagesCallback(p: pointer; f: TUICallback); cdecl;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     6
procedure sendUI(msgType: TMessageType; msg: PChar; len: Longword);
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     7
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     8
implementation
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
     9
uses uFLIPC;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    10
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    11
var uiCallbackPointer: pointer;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    12
    uiCallbackFunction: TUICallback;
11827
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    13
    isGame: boolean;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    14
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    15
procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    16
begin
11827
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    17
    if msg^ = 'T' then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    18
    begin
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    19
        inc(msg);
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    20
        isGame:= msg^ = 'G';
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    21
        exit;
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    22
    end;
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    23
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    24
    if isGame then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    25
    begin
11842
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
    26
        uiCallbackFunction(uiCallbackPointer, mtToNet, msg, len)
11827
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    27
    end
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    28
    else begin
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    29
        if len = 128 * 256 then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    30
            uiCallbackFunction(uiCallbackPointer, mtPreview, msg, len)
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    31
        else if len = 1 then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    32
            uiCallbackFunction(uiCallbackPointer, mtPreviewHogCount, msg, len)
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    33
    end;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    34
end;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    35
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    36
procedure registerUIMessagesCallback(p: pointer; f: TUICallback); cdecl;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    37
begin
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    38
    uiCallbackPointer:= p;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    39
    uiCallbackFunction:= f;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    40
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    41
    registerIPCCallback(nil, @engineMessageCallback)
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    42
end;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    43
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    44
procedure sendUI(msgType: TMessageType; msg: PChar; len: Longword);
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    45
begin
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    46
    uiCallbackFunction(uiCallbackPointer, msgType, msg, len)
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    47
end;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    48
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    49
end.