-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClayworks.pas
288 lines (224 loc) · 6.76 KB
/
Clayworks.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
program Clayworks;
{$mode ObjFPC}{$H+}
{$i clay.inc}
uses
{FPC}
{$IFDEF UNIX}cthreads, {$ENDIF}
SysUtils, Classes,
{Clayworks}
ClayTypes, ClayGlobal, ClayLog,
ClayWindow,
{$IFDEF Windows} ClayWindowWin32, ClayRenderGDI, {$ENDIF}
{Original Units}
tmaths, diskop, Sincos, colour, stdpal, pcx256, PITtimer,
msmouse, chardef, strings, vectfont,
gbasics, ggraph, Basic3d,
tdb, tdeditb,
views, twinb, tdwin, twindraw,
gadgets, cdialog, tmenust,
{Main Clayworks application class}
claycp;
type
{ TClayworks }
TClayworks = class
Window : TClayWindow;
constructor Create(); virtual;
destructor Destroy(); override;
procedure Execute(); virtual;
private
FProgramPath : String;
FTimeStamp : UInt32;
FFPS : Float32;
procedure DoKeyDown(AWindow : TClayWindow; AKey : UInt32);
procedure DoKeyUp(AWindow : TClayWindow; AKey : UInt32);
procedure DoMouseDown(AWindow : TClayWindow; X, Y : SInt32; AButton : SInt32);
procedure DoMouseMove(AWindow : TClayWindow; X, Y : SInt32);
procedure DoMouseUp(AWindow : TClayWindow; X, Y : SInt32; AButton : SInt32);
procedure DoWindowClear(AWindow : TClayWindow);
end;
var
Clay : TClayworks;
{ TClayworks }
constructor TClayworks.Create();
begin
LogStatus('TClayWorks','V'+VersionStr+', (C) T.lewis 1995.$'+chr(13));
{Create Window}
LogStatus('ClayWorks','Creating Window');
{$IFDEF Windows}
Window := TClayWindowWin32.Create('Clayworks', 1024, 768);
{Assign Input Callbacks}
Window.OnMouseMove := @DoMouseMove;
Window.OnMouseDown := @DoMouseDown;
Window.OnMouseUp := @DoMouseUp;
Window.OnKeyDown := @DoKeyDown;
Window.OnKeyUp := @DoKeyUp;
{Assign General Callbacks}
Window.OnClear := @DoWindowClear;
{Temp hack - store pointer to canvas in old style ClayRenderGDI.pas driver}
ClayRenderGDI.GDICanvas := TClayCanvasGDI(Window.Canvas);
{Set Global Message Pump Pointer}
PumpOSMessages := @TClayWindowWin32(Window).PumpOSMessages;
{$ENDIF}
Window.SetCaption('Clayworks '+VersionStr);
{Reset Host Input Vars}
HostMessageLock := false;
HostMouseX := 0;
HostMouseY := 0;
HostMouseZ := 0;
{Reset msmouse.pas vars}
xm := 0;
ym := 0;
zm := 0;
ms_pressed := false;
ms_released := false;
ms_doubleclicked := false;
ms_gridmoved := false;
{Setup Perspective Var}
PerspectiveINT:=PersStart;
{Extract Program Path}
FProgramPath := IncludeTrailingBackslash(ExtractFileDir(ParamStr(0)));
{Setup Global Clayworks Paths}
clay_dir := FProgramPath;
font_path := clay_dir+'SANSF16B.FNT';
{Initialize Graphics}
LogStatus('ClayWorks','Initializing Graphics');
initgraph(VideoModeGDI1024x768);
//AResult := initgraph(VideoModeLazarusFullscreen);
{Setup Palette}
usecolours(0,16);
{Load Font List}
if fexist(font_path) then loadfontlist(font_path, tcharset) else
begin
{TODO : Debug log}
//writeln('Font file not found, please place the file sans16b.fnt in the program file''s directory');
exit;
end;
{Setup Character Set}
//move(altletters,mem[seg(tcharset):ofs(tcharset)+(254 shl 4)],32);
//move(ctrlletters,mem[seg(tcharset):ofs(tcharset)+(252 shl 4)],32);
{Manual Width Tweaks?}
tcharset.widths[252]:=8;
tcharset.widths[253]:=9;
tcharset.widths[254]:=8;
tcharset.widths[255]:=9;
tcharset.attrib:=1;
{Load Font}
LogStatus('ClayWorks','Loading Font');
if fexist(clay_dir+defaultfont) then
Vfontin := vfont.load(defaultfont)
else
Vfontin := false;
{Load Info}
if fexist(clay_dir+'info.txt') then
textfile := loadtext(clay_dir+'info.txt');
getmem(objectinfo,512);
gridpic:=nil;
{Setup Draw Object}
new(draw_object,create(4900,4200,4200));
{Initialize Graphics Mode}
setpal(@pal16,0,16);
{Initialize 3D renderer}
init3d();
{Setup Light}
lightvec.setlight(0,0,0,500,50,10,SC.ColourDepth shr 1);
{Create Clayworks Application}
LogStatus('ClayWorks','Creating Application');
with SC.screenport do
application := new(claycp.clay,create(0,0,x2,y2));
InitTWIN(application);
{Load warning PCX}
if fexist(clay_dir+'warn.pcx') then
warningsign:=readpcx(clay_dir+'warn.pcx',PAcolcheck)
else
warningsign:=nil;
mouseon;
root:=application;
{
{Show register file}
registerfile:=loadtext(clay_dir+'register.txt');
desktop^.add_and_draw(new(infodialog,create(90,80,590,470,registerfile,true)),VPcentre,PIDundefined);
}
{Set Root UI Object to initially be the application}
Views.root := application;
application^.draw;
end;
destructor TClayworks.Destroy();
begin
LogStatus('ClayWorks','Shutting Down');
{Clayworks Flag}
fin := True;
mouseoff;
if vfontin then
vfont.done;
{Destroy Draw}
dispose(draw_object, done);
close3d;
{Destroy ClayWorks Application}
dispose(application, done);
freemem(textfile,strlen(textfile));
{freemem(objectinfo,512);}
{if warningsign<>nil then
destroybitmap(warningsign);}
closegraph;
{Free Objects Memory}
Window.Free;
LogStatus('TClayWorks','That was ClayWorks V'+VersionStr+', (C) T.lewis 1995.$'+chr(13));
end;
procedure TClayworks.Execute();
begin
while (not ClayFlagQuit) do
begin
{Poll the Window for OS Messages}
//Window.PumpOSMessages();
{NOTE : MPos also calls Window.PumpOSMessages() due to the UI locking in
loops that only call MPos() + EventMPos() it's the best place to put it
while the DOS methodology is in place}
{Poll Clayworks Mouse Events}
MPos();
EventMPos();
{Poll Clayworks Keyboard Events}
eventkey();
{Force Render of UI Application}
//application^.draw();
{Ffree up the CPU - mouse drag draw won't sleep as they are loop locked}
Sleep(1);
end;
end;
procedure TClayworks.DoMouseMove(AWindow : TClayWindow; X, Y : SInt32);
begin
HostMouseX := X;
HostMouseY := Y;
end;
procedure TClayworks.DoMouseDown(AWindow : TClayWindow; X, Y : SInt32; AButton : SInt32);
begin
//HostMessageLock := true;
//HostMouseX := X;
//HostMouseY := Y;
HostMouseZ := 1;
end;
procedure TClayworks.DoMouseUp(AWindow : TClayWindow; X, Y : SInt32; AButton : SInt32);
begin
//HostMouseX := X;
//HostMouseY := Y;
HostMouseZ := 0;
end;
procedure TClayworks.DoWindowClear(AWindow : TClayWindow);
begin
{Just re-render the entire application for now}
application^.draw();
end;
procedure TClayworks.DoKeyDown(AWindow : TClayWindow; AKey : UInt32);
begin
HostKey := AKey;
//HostScan := AScan;
end;
procedure TClayworks.DoKeyUp(AWindow : TClayWindow; AKey : UInt32);
begin
end;
{Include Resource Files - IE Application Icon}
{$R *.res}
begin
Clay := TClayworks.Create();
Clay.Execute();
Clay.Free();
end.