-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathunit1.pas
More file actions
290 lines (259 loc) · 9.78 KB
/
Copy pathunit1.pas
File metadata and controls
290 lines (259 loc) · 9.78 KB
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
289
(******************************************************************************)
(* Gorilla ??.??.???? *)
(* *)
(* Version : see ugorilla.pas *)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* Support : www.Corpsman.de *)
(* *)
(* Description : reimplementation of the orig gorilla.bas from DOS *)
(* *)
(* License : See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(* Warranty : There is no warranty, neither in correctness of the *)
(* implementation, nor anything other that could happen *)
(* or go wrong, use at your own risk. *)
(* *)
(* Known Issues: none *)
(* *)
(* History : 0.01 - 0.03: uncknown *)
(* 0.04: Einfügen richtiger LineEnding's *)
(* Sperren des 3. Players beim Netzwerkspiel, da sonst *)
(* das gesamte Spiel kaputt geht *)
(* 0.05: refactor for publish *)
(* 0.06: port to shader rendering *)
(* *)
(******************************************************************************)
(*
Todo:
- Schwierigkeitsgrad Editierbar(Auswirkungen auf Wind, Rundenweise, Turn Weise) -> Was macht dann die Ki ?
- Highscore Engine ( Wohl eher nicht .. )
Offene Bugs:
- Der Client kommt eigentlich nicht mehr aus einem Verbundenen Netzwerkspiel raus ( Außer durch ESC = Beenden )
- Verbinden sich mehr als ein Netzwerkspieler, dann geht das nicht ...
// *)
Unit Unit1;
{$MODE objfpc}{$H+}
{.$DEFINE DebuggMode}// Zeigt evtl aufgetretene OpenGL Fehler an.
Interface
Uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls,
OpenGlcontext,
uopengl_graphikengine,
uOpenGL_ASCII_Font, // http://corpsman.de/index.php?doc=opengl/simple_font
ugorilla,
math,
dglOpenGL, // http://wiki.delphigl.com/index.php/dglOpenGL.pas
lNetComponents, lNet; // http://lnet.wordpress.com/
Type
{ TForm1 }
TForm1 = Class(TForm)
LTCPComponent1: TLTCPComponent;
OpenGLControl1: TOpenGLControl;
Timer1: TTimer;
Procedure FormCloseQuery(Sender: TObject; Var CanClose: boolean);
Procedure FormCreate(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
Procedure LTCPComponent1Accept(aSocket: TLSocket);
Procedure LTCPComponent1CanSend(aSocket: TLSocket);
Procedure LTCPComponent1Connect(aSocket: TLSocket);
Procedure LTCPComponent1Disconnect(aSocket: TLSocket);
Procedure LTCPComponent1Error(Const msg: String; aSocket: TLSocket);
Procedure LTCPComponent1Receive(aSocket: TLSocket);
Procedure OpenGLControl1KeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Procedure OpenGLControl1MakeCurrent(Sender: TObject; Var Allow: boolean);
Procedure OpenGLControl1Paint(Sender: TObject);
Procedure OpenGLControl1Resize(Sender: TObject);
Procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
End;
Var
Form1: TForm1;
Initialized: Boolean = false; // Wenn True dann ist OpenGL initialisiert
Gorilla: TGorillaGame; // Die Spiel Instanz
Implementation
{$R *.lfm}
Uses
uopengl_shaderprimitives
, uopengl_legacychecker
;
{ TForm1 }
Var
allowcnt: Integer = 0;
Procedure OnOpenGLLegacyCall(Severity: GLuint; aMessage: String);
Begin
Initialized := false;
showmessage(
format('Error, unallowed OpenGL legacy call: %d = %s', [Severity, aMessage])
);
halt;
End;
Procedure TForm1.OpenGLControl1MakeCurrent(Sender: TObject; Var Allow: boolean);
Begin
If allowcnt > 2 Then Begin
exit;
End;
inc(allowcnt);
// Sollen Dialoge beim Starten ausgeführt werden ist hier der Richtige Zeitpunkt
If allowcnt = 1 Then Begin
// Init dglOpenGL.pas , Teil 2
ReadExtensions; // Anstatt der Extentions kann auch nur der Core geladen werden. ReadOpenGLCore;
ReadImplementationProperties;
RegisterLegacyCheckerCallback(@OnOpenGLLegacyCall);
End;
If allowcnt = 2 Then Begin
// glenable(GL_POINT_SMOOTH); //das würde die Punkte Glätten führt aber nicht zu den Pixelfehlern, welche wohl nur auf nicht Nvidia Graphikkarten auftreten
If Not Assigned(glCreateShader) Then Begin
// On Windows it seems that you need to "reload" the core functions for proper function
ReadExtensions;
ReadImplementationProperties;
RegisterLegacyCheckerCallback(@OnOpenGLLegacyCall);
// if still not available, then halt
If Not Assigned(glCreateShader) Then Begin
showmessage('glCreateShader not available, use legacy mode..');
halt;
End;
End;
OpenGL_GraphikEngine_InitializeShaderSystem;
OpenGL_ShaderPrimitives_InitializeShaderSystem;
Create_ASCII_Font();
Gorilla := TGorillaGame.create;
// Der Anwendung erlauben zu Rendern.
Initialized := True;
ReActivateKHRDebug; // Reenable KHRDebug
OpenGLControl1Resize(Nil);
End;
Form1.Invalidate;
End;
Procedure TForm1.OpenGLControl1Paint(Sender: TObject);
Begin
If Not Initialized Then Exit;
// Render Szene
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);
go2d(640, 480);
Gorilla.Render;
exit2d;
OpenGLControl1.SwapBuffers;
End;
Procedure TForm1.OpenGLControl1Resize(Sender: TObject);
Begin
If Initialized Then Begin
If OpenGLControl1.MakeCurrent Then
glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);
OpenGLControl1.Invalidate;
End;
End;
Procedure TForm1.FormCreate(Sender: TObject);
Begin
caption := 'Gorilla ver. ' + floattostrf(GorillaVersion / 100, fffixed, 7, 2) + ' support : www.Corpsman.de';
Randomize;
// Init dglOpenGL.pas , Teil 1
If Not InitOpenGl Then Begin
showmessage('Error, could not init dglOpenGL.pas');
Halt;
End;
OpenGLControl1.AutoResizeViewport := True; // This is crucial for GTK3, don't know why, but without it the demo does not work
OpenGLControl1.DebugContext := True; // Required so the GL driver actually generates KHR_debug messages
ClientWidth := 640;
ClientHeight := 480;
OpenGLControl1.Align := alClient;
(*
60 - FPS entsprechen
0.01666666 ms
Ist Interval auf 16 hängt das gesamte system, bei 17 nicht.
Generell sollte die Interval Zahl also dynamisch zum Rechenaufwand, mindestens aber immer 17 sein.
*)
Timer1.Interval := 17;
Network := LTCPComponent1;
End;
Procedure TForm1.FormDestroy(Sender: TObject);
Begin
If OpenGLControl1.MakeCurrent Then Begin
OpenGL_GraphikEngine_FinalizeShaderSystem;
OpenGL_ShaderPrimitives_FinalizeShaderSystem;
End;
End;
Procedure TForm1.LTCPComponent1Accept(aSocket: TLSocket);
Begin
Gorilla.OnAccept(aSocket);
End;
Procedure TForm1.LTCPComponent1CanSend(aSocket: TLSocket);
Begin
// On Can Send ist nur bei der Übertragung Großer Datenmengen notwendig, in Gorilla wird dies nicht benötigt.
End;
Procedure TForm1.LTCPComponent1Connect(aSocket: TLSocket);
Begin
// On Connect, ist wenn der Client erfolgreich beim Server eingeloggt wurde, dies wird in Gorilla anders erkannt..
End;
Procedure TForm1.LTCPComponent1Disconnect(aSocket: TLSocket);
Begin
Gorilla.OnDisconnect(aSocket);
End;
Procedure TForm1.LTCPComponent1Error(Const msg: String; aSocket: TLSocket);
Begin
showmessage(msg);
Gorilla.OnDisconnect(aSocket)
End;
Procedure TForm1.LTCPComponent1Receive(aSocket: TLSocket);
Var
b: Byte;
len: integer;
Begin
len := aSocket.Get(b, 1);
If len = 0 Then exit; // Es wurde nichts empfangen
Gorilla.OnReceive(b, aSocket);
End;
Procedure TForm1.OpenGLControl1KeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Begin
Gorilla.OnKeyDown(Key, Shift);
End;
Procedure TForm1.FormCloseQuery(Sender: TObject; Var CanClose: boolean);
Begin
If LTCPComponent1.Connected Then Begin
LTCPComponent1.Disconnect(true);
End;
timer1.Enabled := false;
Initialized := false;
Gorilla.Free;
Gorilla := Nil;
End;
Procedure TForm1.Timer1Timer(Sender: TObject);
{$IFDEF DebuggMode}
Var
i: Cardinal;
p: Pchar;
{$ENDIF}
Begin
If Initialized Then Begin
{$IFDEF LCLGTK3}
OpenGLControl1.Invalidate;
{$ELSE}
OpenGLControl1.OnPaint(Nil);
{$ENDIF}
{$IFDEF DebuggMode}
i := glGetError();
If i <> 0 Then Begin
Timer1.Enabled := false;
p := gluErrorString(i);
showmessage('OpenGL Error (' + inttostr(i) + ') occured.' + #13#13 +
'OpenGL Message : "' + p + '"'#13#13 +
'Applikation will be terminated.');
close;
End;
{$ENDIF}
End;
End;
End.