hedgewars/uFLUICallback.pas
author unc0rr
Thu, 11 Aug 2016 23:05:14 +0300
branchqmlfrontend
changeset 11848 01f88c3b7b66
parent 11847 93e6c401cc3d
permissions -rw-r--r--
Make in-game chat work
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;
11832
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
11848
01f88c3b7b66 Make in-game chat work
unc0rr
parents: 11847
diff changeset
    17
    if (len >= 3) and (msg[1] = 'T') then
11832
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    18
    begin
11848
01f88c3b7b66 Make in-game chat work
unc0rr
parents: 11847
diff changeset
    19
        isGame:= msg[2] = 'G';
11832
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    20
        exit;
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    21
    end;
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    22
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    23
    if isGame then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    24
    begin
11847
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11832
diff changeset
    25
        uiCallbackFunction(uiCallbackPointer, mtToNet, msg, len)
11832
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    26
    end
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    27
    else begin
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    28
        if len = 128 * 256 then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    29
            uiCallbackFunction(uiCallbackPointer, mtPreview, msg, len)
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    30
        else if len = 1 then
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    31
            uiCallbackFunction(uiCallbackPointer, mtPreviewHogCount, msg, len)
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    32
    end;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    33
end;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    34
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    35
procedure registerUIMessagesCallback(p: pointer; f: TUICallback); cdecl;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    36
begin
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    37
    uiCallbackPointer:= p;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    38
    uiCallbackFunction:= f;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    39
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    40
    registerIPCCallback(nil, @engineMessageCallback)
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    41
end;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    42
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    43
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
    44
begin
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    45
    uiCallbackFunction(uiCallbackPointer, msgType, msg, len)
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    46
end;
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    47
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
diff changeset
    48
end.