hedgewars/uFLUICallback.pas
author unc0rr
Fri, 22 Dec 2017 23:59:03 +0100
branchqmlfrontend
changeset 12857 90f927b4b9e1
parent 11843 01f88c3b7b66
permissions -rw-r--r--
Start hacking new frontend
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
11843
01f88c3b7b66 Make in-game chat work
unc0rr
parents: 11842
diff changeset
    17
    if (len >= 3) and (msg[1] = 'T') then
11827
8c71c5a1172f - Add state to engine callback for it to know what engine is sending
unc0rr
parents: 10951
diff changeset
    18
    begin
11843
01f88c3b7b66 Make in-game chat work
unc0rr
parents: 11842
diff changeset
    19
        isGame:= msg[2] = 'G';
11827
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
11842
93e6c401cc3d Preparation to sending engine messages to net.
unc0rr
parents: 11827
diff changeset
    25
        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
    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.