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

unit uFLUICallback;
interface
uses uFLTypes;

procedure registerUIMessagesCallback(p: pointer; f: TUICallback); cdecl;
procedure sendUI(msgType: TMessageType; msg: PChar; len: Longword);

implementation
uses uFLIPC;

var uiCallbackPointer: pointer;
    uiCallbackFunction: TUICallback;
    isGame: boolean;

procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
begin
    if msg^ = 'T' then
    begin
        inc(msg);
        isGame:= msg^ = 'G';
        exit;
    end;

    if isGame then
    begin
    end
    else begin
        if len = 128 * 256 then
            uiCallbackFunction(uiCallbackPointer, mtPreview, msg, len)
        else if len = 1 then
            uiCallbackFunction(uiCallbackPointer, mtPreviewHogCount, msg, len)
    end;
end;

procedure registerUIMessagesCallback(p: pointer; f: TUICallback); cdecl;
begin
    uiCallbackPointer:= p;
    uiCallbackFunction:= f;

    registerIPCCallback(nil, @engineMessageCallback)
end;

procedure sendUI(msgType: TMessageType; msg: PChar; len: Longword);
begin
    uiCallbackFunction(uiCallbackPointer, msgType, msg, len)
end;

end.