author | unc0rr |
Sun, 28 Sep 2014 01:17:55 +0400 | |
branch | qmlfrontend |
changeset 10430 | 899a30018ede |
parent 10428 | 7c25297720f1 |
child 10432 | b0abef0ee78c |
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 |
|
10430 | 5 |
procedure resetGameConfig; cdecl; |
6 |
procedure runQuickGame; cdecl; |
|
7 |
procedure getPreview; cdecl; |
|
10406 | 8 |
|
10430 | 9 |
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; |
10 |
||
11 |
procedure setSeed(seed: PChar); cdecl; |
|
12 |
function getSeed: PChar; cdecl; |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
13 |
|
10406 | 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 | 19 |
|
10426 | 20 |
const |
21 |
MAXCONFIGS = 5; |
|
22 |
MAXARGS = 32; |
|
23 |
||
24 |
type |
|
25 |
TGameType = (gtPreview, gtLocal); |
|
26 |
THedgehog = record |
|
27 |
name: shortstring; |
|
28 |
hat: shortstring; |
|
29 |
end; |
|
30 |
TTeam = record |
|
31 |
teamName: shortstring; |
|
32 |
flag: shortstring; |
|
33 |
graveName: shortstring; |
|
34 |
fortName: shortstring; |
|
35 |
owner: shortstring; |
|
36 |
extDriven: boolean; |
|
37 |
botLevel: Longword; |
|
38 |
hedgehogs: array[0..7] of THedgehog; |
|
39 |
hogsNumber: Longword; |
|
40 |
end; |
|
41 |
TGameConfig = record |
|
42 |
seed: shortstring; |
|
43 |
theme: shortstring; |
|
44 |
script: shortstring; |
|
45 |
gameType: TGameType; |
|
46 |
teams: array[0..7] of TTeam; |
|
47 |
arguments: array[0..Pred(MAXARGS)] of shortstring; |
|
48 |
argv: array[0..Pred(MAXARGS)] of PChar; |
|
49 |
argumentsNumber: Longword; |
|
50 |
end; |
|
51 |
PGameConfig = ^TGameConfig; |
|
52 |
||
53 |
var currentConfig: TGameConfig; |
|
10430 | 54 |
str2PCharBuffer: array[0..255] of char; |
55 |
||
56 |
function str2PChar(const s: shortstring): PChar; |
|
57 |
var i: Integer; |
|
58 |
begin |
|
59 |
for i:= 1 to Length(s) do |
|
60 |
begin |
|
61 |
str2PCharBuffer[i - 1] := s[i]; |
|
62 |
end; |
|
63 |
str2PCharBuffer[Length(s)]:= #0; |
|
64 |
str2PChar:= @(str2PCharBuffer[0]); |
|
65 |
end; |
|
10426 | 66 |
|
67 |
procedure queueExecution; |
|
68 |
var pConfig: PGameConfig; |
|
69 |
i: Longword; |
|
70 |
begin |
|
71 |
new(pConfig); |
|
72 |
pConfig^:= currentConfig; |
|
73 |
||
74 |
with pConfig^ do |
|
75 |
for i:= 0 to Pred(MAXARGS) do |
|
76 |
begin |
|
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 | 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 | 81 |
argv[i]:= @arguments[i][1] |
82 |
end; |
|
83 |
||
84 |
RunEngine(pConfig^.argumentsNumber, @pConfig^.argv); |
|
85 |
end; |
|
86 |
||
87 |
procedure resetGameConfig; cdecl; |
|
10406 | 88 |
begin |
89 |
end; |
|
90 |
||
10430 | 91 |
procedure setSeed(seed: PChar); cdecl; |
92 |
begin |
|
93 |
currentConfig.seed:= seed |
|
94 |
end; |
|
95 |
||
96 |
function getSeed: PChar; cdecl; |
|
97 |
begin |
|
98 |
getSeed:= str2PChar(currentConfig.seed) |
|
99 |
end; |
|
100 |
||
101 |
procedure runQuickGame; cdecl; |
|
10426 | 102 |
begin |
103 |
||
104 |
end; |
|
105 |
||
10430 | 106 |
procedure getPreview; cdecl; |
10426 | 107 |
begin |
108 |
with currentConfig do |
|
109 |
begin |
|
110 |
gameType:= gtPreview; |
|
111 |
arguments[0]:= ''; |
|
112 |
arguments[1]:= '--internal'; |
|
113 |
arguments[2]:= '--landpreview'; |
|
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 | 121 |
end; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
122 |
end; |
10426 | 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 | 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 | 135 |
end; |
136 |
||
10406 | 137 |
end. |