author | unc0rr |
Sun, 28 Sep 2014 00:49:04 +0400 | |
branch | qmlfrontend |
changeset 10428 | 7c25297720f1 |
parent 10426 | 727a154cf784 |
child 10430 | 899a30018ede |
permissions | -rw-r--r-- |
10406 | 1 |
unit uFLGameConfig; |
2 |
interface |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
3 |
uses uFLTypes; |
10406 | 4 |
|
10426 | 5 |
procedure resetGameConfig; cdecl; export; |
6 |
procedure runQuickGame; cdecl; export; |
|
7 |
procedure getPreview; cdecl; export; |
|
10406 | 8 |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
9 |
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; export; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
10 |
|
10406 | 11 |
implementation |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
12 |
uses uFLIPC, hwengine; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
13 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
14 |
var guiCallbackPointer: pointer; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
15 |
guiCallbackFunction: TGUICallback; |
10406 | 16 |
|
10426 | 17 |
const |
18 |
MAXCONFIGS = 5; |
|
19 |
MAXARGS = 32; |
|
20 |
||
21 |
type |
|
22 |
TGameType = (gtPreview, gtLocal); |
|
23 |
THedgehog = record |
|
24 |
name: shortstring; |
|
25 |
hat: shortstring; |
|
26 |
end; |
|
27 |
TTeam = record |
|
28 |
teamName: shortstring; |
|
29 |
flag: shortstring; |
|
30 |
graveName: shortstring; |
|
31 |
fortName: shortstring; |
|
32 |
owner: shortstring; |
|
33 |
extDriven: boolean; |
|
34 |
botLevel: Longword; |
|
35 |
hedgehogs: array[0..7] of THedgehog; |
|
36 |
hogsNumber: Longword; |
|
37 |
end; |
|
38 |
TGameConfig = record |
|
39 |
seed: shortstring; |
|
40 |
theme: shortstring; |
|
41 |
script: shortstring; |
|
42 |
gameType: TGameType; |
|
43 |
teams: array[0..7] of TTeam; |
|
44 |
arguments: array[0..Pred(MAXARGS)] of shortstring; |
|
45 |
argv: array[0..Pred(MAXARGS)] of PChar; |
|
46 |
argumentsNumber: Longword; |
|
47 |
end; |
|
48 |
PGameConfig = ^TGameConfig; |
|
49 |
||
50 |
var currentConfig: TGameConfig; |
|
51 |
||
52 |
procedure queueExecution; |
|
53 |
var pConfig: PGameConfig; |
|
54 |
i: Longword; |
|
55 |
begin |
|
56 |
new(pConfig); |
|
57 |
pConfig^:= currentConfig; |
|
58 |
||
59 |
with pConfig^ do |
|
60 |
for i:= 0 to Pred(MAXARGS) do |
|
61 |
begin |
|
62 |
if arguments[i][0] = #255 then |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
63 |
arguments[i][255]:= #0 |
10426 | 64 |
else |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
65 |
arguments[i][byte(arguments[i][0]) + 1]:= #0; |
10426 | 66 |
argv[i]:= @arguments[i][1] |
67 |
end; |
|
68 |
||
69 |
RunEngine(pConfig^.argumentsNumber, @pConfig^.argv); |
|
70 |
end; |
|
71 |
||
72 |
procedure resetGameConfig; cdecl; |
|
10406 | 73 |
begin |
74 |
end; |
|
75 |
||
10426 | 76 |
procedure runQuickGame; cdecl; export; |
77 |
begin |
|
78 |
||
79 |
end; |
|
80 |
||
81 |
procedure getPreview; cdecl; export; |
|
82 |
begin |
|
83 |
with currentConfig do |
|
84 |
begin |
|
85 |
gameType:= gtPreview; |
|
86 |
arguments[0]:= ''; |
|
87 |
arguments[1]:= '--internal'; |
|
88 |
arguments[2]:= '--landpreview'; |
|
89 |
argumentsNumber:= 3; |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
90 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
91 |
queueExecution; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
92 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
93 |
ipcToEngine('eseed ' + seed); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
94 |
ipcToEngine('e$mapgen 0'); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
95 |
ipcToEngine('!'); |
10426 | 96 |
end; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
97 |
end; |
10426 | 98 |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
99 |
procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
100 |
begin |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
101 |
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
|
102 |
end; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
103 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
104 |
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; export; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
105 |
begin |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
106 |
guiCallbackPointer:= p; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
107 |
guiCallbackFunction:= f; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
108 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
109 |
registerIPCCallback(nil, @engineMessageCallback) |
10426 | 110 |
end; |
111 |
||
10406 | 112 |
end. |