hedgewars/uFLGameConfig.pas
author unc0rr
Sun, 28 Sep 2014 01:17:55 +0400
branchqmlfrontend
changeset 10430 899a30018ede
parent 10428 7c25297720f1
child 10432 b0abef0ee78c
permissions -rw-r--r--
Getter and setter for seed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     1
unit uFLGameConfig;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     2
interface
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
     3
uses uFLTypes;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     4
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     5
procedure resetGameConfig; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     6
procedure runQuickGame; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     7
procedure getPreview; cdecl;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     8
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     9
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    10
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    11
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    12
function  getSeed: PChar; cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    13
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    14
implementation
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    15
uses uFLIPC, hwengine;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    16
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    17
var guiCallbackPointer: pointer;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    18
    guiCallbackFunction: TGUICallback;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    19
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    20
const
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    21
    MAXCONFIGS = 5;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    22
    MAXARGS = 32;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    23
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    24
type
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    25
    TGameType = (gtPreview, gtLocal);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    26
    THedgehog = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    27
            name: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    28
            hat: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    29
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    30
    TTeam = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    31
            teamName: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    32
            flag: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    33
            graveName: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    34
            fortName: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    35
            owner: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    36
            extDriven: boolean;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    37
            botLevel: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    38
            hedgehogs: array[0..7] of THedgehog;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    39
            hogsNumber: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    40
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    41
    TGameConfig = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    42
            seed: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    43
            theme: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    44
            script: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    45
            gameType: TGameType;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    46
            teams: array[0..7] of TTeam;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    47
            arguments: array[0..Pred(MAXARGS)] of shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    48
            argv: array[0..Pred(MAXARGS)] of PChar;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    49
            argumentsNumber: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    50
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    51
    PGameConfig = ^TGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    52
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    53
var currentConfig: TGameConfig;
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    54
    str2PCharBuffer: array[0..255] of char;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    55
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    56
function str2PChar(const s: shortstring): PChar;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    57
var i: Integer;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    58
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    59
   for i:= 1 to Length(s) do
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    60
      begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    61
      str2PCharBuffer[i - 1] := s[i];
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    62
      end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    63
   str2PCharBuffer[Length(s)]:= #0;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    64
   str2PChar:= @(str2PCharBuffer[0]);
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    65
end;    
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    66
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    67
procedure queueExecution;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    68
var pConfig: PGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    69
    i: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    70
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    71
    new(pConfig);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    72
    pConfig^:= currentConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    73
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    74
    with pConfig^ do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    75
        for i:= 0 to Pred(MAXARGS) do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    76
        begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    77
            if arguments[i][0] = #255 then 
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    78
                arguments[i][255]:= #0
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    79
            else
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    80
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    81
            argv[i]:= @arguments[i][1]
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    82
        end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    83
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    84
    RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    85
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    86
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    87
procedure resetGameConfig; cdecl;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    88
begin
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    89
end;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    90
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    91
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    92
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    93
    currentConfig.seed:= seed
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    94
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    95
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    96
function getSeed: PChar; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    97
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    98
    getSeed:= str2PChar(currentConfig.seed)
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    99
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   100
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   101
procedure runQuickGame; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   102
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   103
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   104
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   105
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   106
procedure getPreview; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   107
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   108
    with currentConfig do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   109
    begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   110
        gameType:= gtPreview;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   111
        arguments[0]:= '';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   112
        arguments[1]:= '--internal';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   113
        arguments[2]:= '--landpreview';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   114
        argumentsNumber:= 3;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   115
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   116
        queueExecution;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   117
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   118
        ipcToEngine('eseed ' + seed);
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   119
        ipcToEngine('e$mapgen 0');
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   120
        ipcToEngine('!');
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   121
    end;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   122
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   123
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   124
procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   125
begin
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   126
    if len = 128 * 256 then guiCallbackFunction(guiCallbackPointer, mtPreview, msg, len)
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   127
end;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   128
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   129
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   130
begin
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   131
    guiCallbackPointer:= p;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   132
    guiCallbackFunction:= f;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   133
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   134
    registerIPCCallback(nil, @engineMessageCallback)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   135
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   136
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   137
end.