hedgewars/uFLUICallback.pas
author unc0rr
Tue, 17 May 2016 23:18:08 +0300
branchqmlfrontend
changeset 11827 8c71c5a1172f
parent 10951 89a7f617e091
child 11842 93e6c401cc3d
permissions -rw-r--r--
- Add state to engine callback for it to know what engine is sending - Display suggested hogs number in preview
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
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.