author | koda |
Mon, 25 Feb 2013 10:04:31 +0100 | |
branch | experimental3D |
changeset 4846 | 668602df25a6 |
parent 4731 | edf7d04d3fa9 |
child 4779 | 53f7e964a338 |
child 4900 | 8ad0e23e6d63 |
permissions | -rw-r--r-- |
4457 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2010 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit uLandPainted; |
|
22 |
||
23 |
interface |
|
24 |
||
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
25 |
procedure Draw; |
4490 | 26 |
procedure initModule; |
4457 | 27 |
|
28 |
implementation |
|
4648 | 29 |
uses uLandGraphics, uConsts, uUtils, SDLh, uCommands, uDebug; |
4457 | 30 |
|
31 |
type PointRec = packed record |
|
4458 | 32 |
X, Y: SmallInt; |
4457 | 33 |
flags: byte; |
34 |
end; |
|
35 |
||
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
36 |
type |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
37 |
PPointEntry = ^PointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
38 |
PointEntry = record |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
39 |
point: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
40 |
next: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
41 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
42 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
43 |
var pointsListHead, pointsListLast: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
44 |
|
4458 | 45 |
procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt); |
46 |
var eX, eY, dX, dY: LongInt; |
|
47 |
i, sX, sY, x, y, d: LongInt; |
|
48 |
b: boolean; |
|
49 |
len: LongWord; |
|
50 |
begin |
|
51 |
len:= 0; |
|
52 |
if (X1 = X2) and (Y1 = Y2) then |
|
53 |
begin |
|
54 |
exit |
|
55 |
end; |
|
56 |
eX:= 0; |
|
57 |
eY:= 0; |
|
58 |
dX:= X2 - X1; |
|
59 |
dY:= Y2 - Y1; |
|
60 |
||
61 |
if (dX > 0) then sX:= 1 |
|
62 |
else |
|
63 |
if (dX < 0) then |
|
64 |
begin |
|
65 |
sX:= -1; |
|
66 |
dX:= -dX |
|
67 |
end else sX:= dX; |
|
68 |
||
69 |
if (dY > 0) then sY:= 1 |
|
70 |
else |
|
71 |
if (dY < 0) then |
|
72 |
begin |
|
73 |
sY:= -1; |
|
74 |
dY:= -dY |
|
75 |
end else sY:= dY; |
|
76 |
||
77 |
if (dX > dY) then d:= dX |
|
78 |
else d:= dY; |
|
79 |
||
80 |
x:= X1; |
|
81 |
y:= Y1; |
|
82 |
||
83 |
for i:= 0 to d do |
|
84 |
begin |
|
85 |
inc(eX, dX); |
|
86 |
inc(eY, dY); |
|
87 |
b:= false; |
|
88 |
if (eX > d) then |
|
89 |
begin |
|
90 |
dec(eX, d); |
|
91 |
inc(x, sX); |
|
92 |
b:= true |
|
93 |
end; |
|
94 |
if (eY > d) then |
|
95 |
begin |
|
96 |
dec(eY, d); |
|
97 |
inc(y, sY); |
|
98 |
b:= true |
|
99 |
end; |
|
100 |
if b then |
|
101 |
begin |
|
102 |
inc(len); |
|
103 |
if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic) |
|
104 |
end |
|
105 |
end |
|
106 |
end; |
|
107 |
||
4490 | 108 |
procedure chDraw(var s: shortstring); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
109 |
var rec: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
110 |
prec: ^PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
111 |
pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
112 |
i, l: byte; |
4490 | 113 |
begin |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
114 |
i:= 1; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
115 |
l:= length(s); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
116 |
while i < l do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
117 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
118 |
prec:= @s[i]; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
119 |
rec:= prec^; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
120 |
rec.X:= SDLNet_Read16(@rec.X); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
121 |
rec.Y:= SDLNet_Read16(@rec.Y); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
122 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
123 |
pe:= new(PPointEntry); |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
124 |
if pointsListLast = nil then |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
125 |
pointsListHead:= pe |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
126 |
else |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
127 |
pointsListLast^.next:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
128 |
pointsListLast:= pe; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
129 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
130 |
pe^.point:= rec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
131 |
pe^.next:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
132 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
133 |
inc(i, 5) |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
134 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
135 |
end; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
136 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
137 |
procedure Draw; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
138 |
var pe: PPointEntry; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
139 |
prevPoint: PointRec; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
140 |
begin |
4648 | 141 |
// shutup compiler |
142 |
prevPoint.X:= 0; |
|
143 |
prevPoint.Y:= 0; |
|
144 |
||
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
145 |
pe:= pointsListHead; |
4648 | 146 |
TryDo((pe = nil) or (pe^.point.flags and $80 <> 0), 'Corrupted draw data', true); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
147 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
148 |
while(pe <> nil) do |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
149 |
begin |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
150 |
if (pe^.point.flags and $80 <> 0) then |
4649 | 151 |
begin |
4731 | 152 |
{$IFDEF DEBUGFILE}AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+')');{$ENDIF} |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
153 |
FillRoundInLand(pe^.point.X, pe^.point.Y, 34, lfBasic) |
4649 | 154 |
end |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
155 |
else |
4649 | 156 |
begin |
4728 | 157 |
{$IFDEF DEBUGFILE}AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+')');{$ENDIF} |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
158 |
DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y); |
4649 | 159 |
end; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
160 |
|
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
161 |
prevPoint:= pe^.point; |
4648 | 162 |
pe:= pe^.next; |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
163 |
end; |
4490 | 164 |
end; |
165 |
||
166 |
procedure initModule; |
|
167 |
begin |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
168 |
pointsListHead:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
169 |
pointsListLast:= nil; |
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4490
diff
changeset
|
170 |
|
4490 | 171 |
RegisterVariable('draw', vtCommand, @chDraw, false); |
172 |
end; |
|
173 |
||
4457 | 174 |
end. |