-
Notifications
You must be signed in to change notification settings - Fork 2
/
mdl_script.pas
165 lines (140 loc) · 5.72 KB
/
mdl_script.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
//------------------------------------------------------------------------------
//
// DD_MODEL: DelphiDOOM Procedural Model Editor
// Copyright (C) 2017-2021 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// Script main execute function
//
//------------------------------------------------------------------------------
// E-Mail: jimmyvalavanis@yahoo.gr
// Site : https://sourceforge.net/projects/delphidoom-procedural-modeler/
//------------------------------------------------------------------------------
unit mdl_script;
interface
uses
SysUtils,
Classes;
function MDL_ExecuteScript(const Script: string): boolean;
implementation
uses
mdl_script_proclist,
mdl_script_functions,
uPSCompiler,
uPSRuntime;
function ScriptOnUses(Sender: TPSPascalCompiler; const Name: string): Boolean;
var
uT_integer: TPSType;
uT_longword: TPSType;
uT_extended: TPSType;
begin
if Name = 'SYSTEM' then
begin
Sender.AddTypeS('TIntegerArray', 'array of integer');
Sender.AddTypeS('TInt64Array', 'array of int64');
Sender.AddTypeS('TLongWordArray', 'array of LongWord');
Sender.AddTypeS('TSingleArray', 'array of single');
Sender.AddTypeS('TFloatArray', 'array of single');
Sender.AddTypeS('TDoubleArray', 'array of double');
Sender.AddTypeS('TExtendedArray', 'array of extended');
Sender.AddTypeS('float', 'single');
Sender.AddTypeS('real', 'double');
Sender.AddTypeS('GLenum', 'longword');
Sender.AddTypeS('GLboolean', 'boolean');
Sender.AddTypeS('GLbitfield', 'longword');
Sender.AddTypeS('GLbyte', 'Shortint');
Sender.AddTypeS('GLshort', 'SmallInt');
Sender.AddTypeS('GLint', 'Integer');
Sender.AddTypeS('GLsizei', 'Integer');
Sender.AddTypeS('GLubyte', 'Byte');
Sender.AddTypeS('GLushort', 'Word');
Sender.AddTypeS('GLuint', 'longword');
Sender.AddTypeS('GLfloat', 'Single');
Sender.AddTypeS('GLclampf', 'Single');
Sender.AddTypeS('GLdouble', 'Double');
Sender.AddTypeS('GLclampd', 'Double');
Sender.AddTypeS('GLint64', 'int64');
uT_extended := Sender.FindType('extended');
uT_integer := Sender.FindType('integer');
uT_longword := Sender.FindType('longword');
Sender.AddConstant('NaN', uT_extended).Value.textended := 0.0 / 0.0;
Sender.AddConstant('Infinity', uT_extended).Value.textended := 1.0 / 0.0;
Sender.AddConstant('NegInfinity', uT_extended).Value.textended := - 1.0 / 0.0;
Sender.AddConstant('MAXINT', uT_integer).Value.ts32 := MAXINT;
Sender.AddConstant('GL_LINES', uT_longword).Value.tu32 := $0001;
Sender.AddConstant('GL_LINE_LOOP', uT_longword).Value.tu32 := $0002;
Sender.AddConstant('GL_LINE_STRIP', uT_longword).Value.tu32 := $0003;
Sender.AddConstant('GL_TRIANGLES', uT_longword).Value.tu32 := $0004;
Sender.AddConstant('GL_TRIANGLE_STRIP', uT_longword).Value.tu32 := $0005;
Sender.AddConstant('GL_TRIANGLE_FAN', uT_longword).Value.tu32 := $0006;
Sender.AddConstant('GL_QUADS', uT_longword).Value.tu32 := $0007;
Sender.AddConstant('GL_QUAD_STRIP', uT_longword).Value.tu32 := $0008;
Sender.AddConstant('GL_POLYGON', uT_longword).Value.tu32 := $0009;
Sender.AddConstant('GL_MODELVIEW', uT_longword).Value.tu32 := $1700;
Sender.AddConstant('GL_PROJECTION', uT_longword).Value.tu32 := $1701;
Sender.AddConstant('GL_TEXTURE', uT_longword).Value.tu32 := $1702;
Sender.AddConstant('GL_COLOR', uT_longword).Value.tu32 := $1800;
MDL_RegisterProcsCompiler(Sender);
Result := True;
end
else
Result := False;
end;
function MDL_ExecuteScript(const Script: string): boolean;
var
i: integer;
Compiler: TPSPascalCompiler;
Exec: TPSExec;
{$IFDEF UNICODE}Data: AnsiString;{$ELSE}Data: string;{$ENDIF}
begin
MDL_InitProcList;
Compiler := TPSPascalCompiler.Create; // create an instance of the compiler.
Compiler.OnUses := ScriptOnUses; // assign the OnUses event.
if not Compiler.Compile(Script) then // Compile the Pascal script into bytecode.
begin
for i := 0 to Compiler.MsgCount - 1 do
printf(Format('Pos: %.*d, "%s"', [6, compiler.Msg[i].Pos, compiler.Msg[i].MessageToString]));
Compiler.Free;
MDL_ShutDownProcList;
Result := False;
Exit;
end;
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data.
Compiler.Free; // After compiling the script, there is no need for the compiler anymore.
printf('Compile successful'#13#10);
Exec := TPSExec.Create; // Create an instance of the executer.
MDL_RegisterProcsExec(Exec);
if not Exec.LoadData(Data) then // Load the data from the Data string.
begin
printf('Can not run script, internal error!');
{ For some reason the script could not be loaded. This is usually the case when a
library that has been used at compile time isn't registered at runtime. }
Exec.Free;
// You could raise an exception here.
MDL_ShutDownProcList;
Result := False;
Exit;
end;
printf('Running...'#13#10);
Exec.RunScript; // Run the script.
Exec.Free; // Free the executer.
MDL_ShutDownProcList;
Result := True;
printf('Done'#13#10);
end;
end.