Skip to content

Commit 2faab9b

Browse files
committed
Updated tests and samples to latest version
1 parent c06a19e commit 2faab9b

21 files changed

+305
-178
lines changed

CHANGES.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ March 2015
1313

1414
All Destructors -> Replaced with Release() method (in preparation for Oxygene support)
1515
FreeAndNil() -> Replaced with ReleaseObject()
16-
Added PhysicsManager class, which works as generic front end to physics engines (basic Newton physics engine support)
16+
Added PhysicsManager class, which works as generic front end to physics engines (basic Newton physics engine support)
17+
18+
Added InputManager class, all input now goes through this class
19+
20+
Changed NetClient and NetServer, now they use message handlers with a different signature

Samples/Source/2D/Fonts/text_localization.dpr

+15-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Uses
55
{$IFDEF DEBUG_LEAKS}MemCheck,{$ELSE} TERRA_MemoryManager,{$ENDIF}
66
TERRA_Utils, TERRA_Application, TERRA_Scene, TERRA_Client, TERRA_UI, TERRA_GraphicsManager,
77
TERRA_ResourceManager, TERRA_Color, TERRA_Font, TERRA_OS, TERRA_FileManager, TERRA_Texture,
8-
TERRA_PNG, TERRA_TTF, TERRA_Viewport, TERRA_SpriteManager, TERRA_Localization;
8+
TERRA_PNG, TERRA_TTF, TERRA_Viewport, TERRA_SpriteManager, TERRA_InputManager,
9+
TERRA_FontRenderer, TERRA_Localization;
910

1011
Type
1112
// A client is used to process application events
@@ -29,6 +30,7 @@ Const
2930

3031
Var
3132
_Font:Font = Nil;
33+
_FontRenderer:FontRenderer;
3234
_SelectedLanguage:Integer;
3335

3436
{ Game }
@@ -42,6 +44,9 @@ Begin
4244
// Load a font
4345
_Font := FontManager.Instance.GetFont('droid');
4446

47+
_FontRenderer := FontRenderer.Create();
48+
_FontRenderer.SetFont(_Font);
49+
4550
// Create a scene and set it as the current scene
4651
_Scene := MyScene.Create;
4752
GraphicsManager.Instance.SetScene(_Scene);
@@ -52,21 +57,22 @@ End;
5257
// OnIdle is called once per frame, put your game logic here
5358
Procedure MyGame.OnDestroy;
5459
Begin
60+
ReleaseObject(_FontRenderer);
5561
ReleaseObject(_Scene);
5662
End;
5763

5864
Procedure MyGame.OnIdle;
5965
Begin
60-
If (Application.Instance.Input.Keys.WasPressed(keyEscape)) Then
66+
If (InputManager.Instance.Keys.WasPressed(keyEscape)) Then
6167
Application.Instance.Terminate;
6268

63-
If (Application.Instance.Input.Keys.WasPressed(keyLeft)) And (_SelectedLanguage>1) Then
69+
If (InputManager.Instance.Keys.WasPressed(keyLeft)) And (_SelectedLanguage>1) Then
6470
Begin
6571
Dec(_SelectedLanguage);
6672
LocalizationManager.Instance.SetLanguage(LanguageList[_SelectedLanguage]);
6773
End;
6874

69-
If (Application.Instance.Input.Keys.WasPressed(keyright)) And (_SelectedLanguage<LanguageCount) Then
75+
If (InputManager.Instance.Keys.WasPressed(keyright)) And (_SelectedLanguage<LanguageCount) Then
7076
Begin
7177
Inc(_SelectedLanguage);
7278
LocalizationManager.Instance.SetLanguage(LanguageList[_SelectedLanguage]);
@@ -85,17 +91,17 @@ Begin
8591
Saturation := 1.0
8692
Else
8793
Saturation := 0.0;
88-
94+
8995
SpriteManager.Instance.DrawSprite(10 + I * 70, 10, 10, TextureManager.Instance.GetTexture('flag_'+LanguageList[I]), Nil, blendBlend, Saturation);
9096
End;
9197

9298
// render some text
9399
If Assigned(_Font) Then
94100
Begin
95-
_Font.DrawText(50, 90, 10, ' Language: ' + GetLanguageDescription(LanguageList[_SelectedLanguage]), ColorWhite, 1.0, True);
96-
_Font.DrawText(100, 160, 10, LocalizationManager.Instance['score'] + ': 1000', ColorYellow, 1.0, True);
97-
_Font.DrawText(100, 190, 10, LocalizationManager.Instance['totaltime'] + ': 1:23', ColorYellow, 1.0, True);
98-
_Font.DrawText(100, 230, 10, LocalizationManager.Instance['coinscollected'] + ': 56', ColorYellow, 1.0, True);
101+
_FontRenderer.DrawText(50, 90, 10, ' Language: ' + GetLanguageDescription(LanguageList[_SelectedLanguage]));
102+
_FontRenderer.DrawText(100, 160, 10, LocalizationManager.Instance['score'] + ': 1000');
103+
_FontRenderer.DrawText(100, 190, 10, LocalizationManager.Instance['totaltime'] + ': 1:23');
104+
_FontRenderer.DrawText(100, 230, 10, LocalizationManager.Instance['coinscollected'] + ': 56');
99105

100106
End;
101107
End;

Samples/Source/2D/Fonts/text_render.dpr

+22-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
Uses
55
{$IFDEF DEBUG_LEAKS}MemCheck,{$ELSE} TERRA_MemoryManager,{$ENDIF}
66
TERRA_String, TERRA_Utils, TERRA_Application, TERRA_Scene, TERRA_Client, TERRA_UI, TERRA_GraphicsManager,
7-
TERRA_ResourceManager, TERRA_Color, TERRA_Font, TERRA_OS, TERRA_FileManager,
8-
TERRA_PNG, TERRA_TTF, TERRA_Viewport, TERRA_SpriteManager, TERRA_Localization;
7+
TERRA_ResourceManager, TERRA_Color, TERRA_Font, TERRA_FontRenderer, TERRA_OS, TERRA_FileManager,
8+
TERRA_PNG, TERRA_TTF, TERRA_Viewport, TERRA_SpriteManager, TERRA_Localization,
9+
TERRA_InputManager;
910

1011
Type
1112
// A client is used to process application events
@@ -24,7 +25,7 @@ Type
2425
End;
2526

2627
Var
27-
_Font:Font = Nil;
28+
_FontRenderer:FontRenderer = Nil;
2829

2930
{ Game }
3031
Procedure MyGame.OnCreate;
@@ -35,7 +36,8 @@ Begin
3536
GraphicsManager.Instance.ActiveViewport.BackgroundColor := ColorRed;
3637

3738
// Load a font
38-
_Font := FontManager.Instance.GetFont('droid');
39+
_FontRenderer := FontRenderer.Create();
40+
_FontRenderer.SetFont(FontManager.Instance.GetFont('droid'));
3941

4042
// Create a scene and set it as the current scene
4143
_Scene := MyScene.Create;
@@ -45,12 +47,13 @@ End;
4547
// OnIdle is called once per frame, put your game logic here
4648
Procedure MyGame.OnDestroy;
4749
Begin
50+
ReleaseObject(_FontRenderer);
4851
ReleaseObject(_Scene);
4952
End;
5053

5154
Procedure MyGame.OnIdle;
5255
Begin
53-
If Keys.WasReleased(keyEscape) Then
56+
If InputManager.Instance.Keys.WasReleased(keyEscape) Then
5457
Application.Instance.Terminate;
5558
End;
5659

@@ -72,20 +75,25 @@ End;
7275
Procedure MyScene.RenderSprites(V:Viewport);
7376
Begin
7477
// render some text
75-
If Assigned(_Font) Then
78+
If Assigned(_FontRenderer.Font) Then
7679
Begin
77-
_Font.DrawText(50, 70, 10, ' Hello World!', ColorWhite, 1.0, True);
78-
_Font.DrawText(200, 160, 10, 'This is a'+StringFromChar(fontControlNewLine)+'line break!', ColorYellow, 1.0, True);
80+
_FontRenderer.DrawText(50, 70, 10, ' Hello World!');
7981

80-
_Font.DrawText(200, 100, 10, StringFromChar(fontControlWave)+'Wavy text!', ColorBlue, 1.0, True);
82+
_FontRenderer.SetColor(ColorYellow);
83+
_FontRenderer.DrawText(200, 160, 10, 'This is a'+StringFromChar(fontControlNewLine)+'line break!');
8184

82-
_Font.DrawText(400, 100, 10, StringFromChar(fontControlItalics)+' Italic text!', ColorGreen, 1.0, True);
85+
_FontRenderer.SetColor(ColorBlue);
86+
_FontRenderer.DrawText(200, 100, 10, StringFromChar(fontControlWave)+'Wavy text!');
87+
88+
_FontRenderer.SetColor(ColorGreen);
89+
_FontRenderer.DrawText(400, 100, 10, StringFromChar(fontControlItalics)+' Italic text!');
8390

8491
// unicode rendering
85-
_Font.DrawText(50, 200, 10, GetLanguageDescription(language_Russian), ColorWhite, 1.0, True);
86-
_Font.DrawText(50, 230, 10, GetLanguageDescription(language_Chinese), ColorWhite, 1.0, True);
87-
_Font.DrawText(50, 260, 10, GetLanguageDescription(language_Korean), ColorWhite, 1.0, True);
88-
_Font.DrawText(50, 290, 10, GetLanguageDescription(language_Japanese), ColorWhite, 1.0, True);
92+
_FontRenderer.SetColor(ColorWhite);
93+
_FontRenderer.DrawText(50, 200, 10, GetLanguageDescription(language_Russian));
94+
_FontRenderer.DrawText(50, 230, 10, GetLanguageDescription(language_Chinese));
95+
_FontRenderer.DrawText(50, 260, 10, GetLanguageDescription(language_Korean));
96+
_FontRenderer.DrawText(50, 290, 10, GetLanguageDescription(language_Japanese));
8997
End;
9098
End;
9199

Samples/Source/2D/GUI/gui_clipping.dpr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Uses
55
{$IFDEF DEBUG_LEAKS}MemCheck,{$ELSE} TERRA_MemoryManager,{$ENDIF}
66
TERRA_Application, TERRA_Client, TERRA_Utils, TERRA_ResourceManager, TERRA_GraphicsManager,
77
TERRA_OS, TERRA_Vector2D, TERRA_Font, TERRA_Texture,
8-
TERRA_UI, TERRA_FileManager, TERRA_TTF,
9-
TERRA_Widgets, TERRA_PNG, TERRA_Scene, TERRA_SpriteManager, TERRA_Color, TERRA_Matrix4x4;
8+
TERRA_UI, TERRA_FileManager, TERRA_InputManager, TERRA_TTF,
9+
TERRA_Widgets, TERRA_PNG, TERRA_Scene, TERRA_SpriteManager, TERRA_ClipRect, TERRA_Color, TERRA_Matrix4x4;
1010

1111
Type
1212
Game = Class(AppClient)
@@ -84,10 +84,10 @@ End;
8484

8585
Procedure Game.OnIdle;
8686
Begin
87-
If Keys.WasPressed(keyEscape) Then
87+
If InputManager.Instance.Keys.WasPressed(keyEscape) Then
8888
Application.Instance.Terminate;
8989

90-
Clip := ClipRectCreate(Application.Instance.Input.Mouse.X - 150, Application.Instance.Input.Mouse.Y - 150, 300, 300);
90+
Clip := ClipRectCreate(InputManager.Instance.Mouse.X - 150, InputManager.Instance.Mouse.Y - 150, 300, 300);
9191

9292
//MyWnd.ClipRect := Clip;
9393
MyUI.ClipRect := Clip;

Samples/Source/2D/GUI/gui_simple.dpr

+23-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Uses
55
{$IFDEF DEBUG_LEAKS}MemCheck,{$ELSE} TERRA_MemoryManager,{$ENDIF}
66
TERRA_Application, TERRA_Client, TERRA_Utils, TERRA_ResourceManager, TERRA_GraphicsManager,
77
TERRA_OS, TERRA_Vector2D, TERRA_Font, TERRA_Texture,
8-
TERRA_UI, TERRA_FileManager, TERRA_TTF,
8+
TERRA_UI, TERRA_FileManager, TERRA_InputManager, TERRA_TTF,
99
TERRA_Widgets, TERRA_PNG, TERRA_Scene, TERRA_Color, TERRA_Matrix4x4;
1010

1111
Type
@@ -37,8 +37,6 @@ Var
3737

3838
{ Game }
3939
Procedure Game.OnCreate;
40-
Var
41-
MyTex:Texture;
4240
Begin
4341
FileManager.Instance.AddPath('Assets');
4442

@@ -54,24 +52,6 @@ Begin
5452
// Load a custom mouse cursor
5553
MyUI.LoadCursor('cursor.png');
5654

57-
// Get background texture
58-
MyTex := TextureManager.Instance.GetTexture('background');
59-
60-
// Create a UI background
61-
If Assigned(MyTex) Then
62-
Begin
63-
Background := UISprite.Create('mybg', MyUI, Nil, 0, 0, 0);
64-
65-
Background.SetTexture(MyTex);
66-
Background.Rect.Width := UIManager.Instance.Width;
67-
Background.Rect.Height := UIManager.Instance.Height;
68-
69-
70-
Background.Rect.U2 := 2;
71-
Background.Rect.V2 := 2;
72-
//VectorCreate2D(1,0.5), 0.1, VectorCreate2D(2.0, 2.0)
73-
End;
74-
7555
// Create a empty scene
7656
_Scene := MyScene.Create;
7757
GraphicsManager.Instance.Scene := _Scene;
@@ -84,7 +64,7 @@ End;
8464

8565
Procedure Game.OnIdle;
8666
Begin
87-
If Keys.WasPressed(keyEscape) Then
67+
If InputManager.Instance.Keys.WasPressed(keyEscape) Then
8868
Application.Instance.Terminate;
8969
End;
9070

@@ -168,7 +148,28 @@ Var
168148
Btn:UIButton;
169149
RB:UIRadioButton;
170150
CB:UICheckbox;
151+
152+
MyTex:Texture;
171153
Begin
154+
// Get background texture
155+
MyTex := TextureManager.Instance.GetTexture('background');
156+
157+
// Create a UI background
158+
If Assigned(MyTex) Then
159+
Begin
160+
Background := UISprite.Create('mybg', MyUI, Nil, 0, 0, 1);
161+
162+
Background.SetTexture(MyTex);
163+
Background.Rect.Width := UIManager.Instance.Width;
164+
Background.Rect.Height := UIManager.Instance.Height;
165+
166+
Background.Rect.U2 := 2;
167+
Background.Rect.V2 := 2;
168+
169+
//Background.Visible := False;
170+
End;
171+
172+
172173
MyWnd := UIWindow.Create('mywnd', MyUI, 10, 10, 10, 6, 4);
173174
MyWnd.AllowDragging := True;
174175
MyWnd.Align := waCenter;

Samples/Source/2D/Isometric/isomap.dpr

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Program Tutorial10;
77

88
Uses TERRA_MemoryManager, TERRA_Application, TERRA_Client, TERRA_Utils, TERRA_ResourceManager, TERRA_GraphicsManager,
9-
TERRA_OS, TERRA_Vector2D, TERRA_Font, TERRA_Texture,
9+
TERRA_OS, TERRA_Vector2D, TERRA_Font, TERRA_Texture, TERRA_InputManager,
1010
TERRA_UI, TERRA_FileManager, TERRA_SpriteManager, TERRA_Viewport,
1111
TERRA_Widgets, TERRA_PNG, TERRA_Scene, TERRA_Color, TERRA_Matrix4x4;
1212

@@ -127,7 +127,7 @@ Procedure Game.OnIdle;
127127
Var
128128
Delta:Single;
129129
Begin
130-
If Application.Instance.Input.Keys.WasPressed(keyEscape) Then
130+
If InputManager.Instance.Keys.WasPressed(keyEscape) Then
131131
Application.Instance.Terminate();
132132

133133
Delta := Application.Instance.GetElapsedTime() - LastUpdate;
@@ -137,14 +137,14 @@ Begin
137137
LastUpdate := Application.Instance.GetElapsedTime();
138138
//Delta := 1.5;
139139

140-
If Application.Instance.Input.Keys.IsDown(keyUp) Then
140+
If InputManager.Instance.Keys.IsDown(keyUp) Then
141141
MapY := MapY - Delta;
142-
If Application.Instance.Input.Keys.IsDown(keyDown) Then
142+
If InputManager.Instance.Keys.IsDown(keyDown) Then
143143
MapY := MapY + Delta;
144144

145-
If Application.Instance.Input.Keys.IsDown(keyLeft) Then
145+
If InputManager.Instance.Keys.IsDown(keyLeft) Then
146146
MapX := MapX - Delta;
147-
If Application.Instance.Input.Keys.IsDown(keyRight) Then
147+
If InputManager.Instance.Keys.IsDown(keyRight) Then
148148
MapX := MapX + Delta;
149149
End;
150150
End;

Samples/Source/2D/Lines/linetest.dpr

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{$IFDEF MOBILE}Library{$ELSE}Program{$ENDIF} BasicSample;
33

44
Uses TERRA_Utils, TERRA_Application, TERRA_Scene, TERRA_Client, TERRA_GraphicsManager, TERRA_Viewport,
5-
TERRA_ResourceManager, TERRA_Color, TERRA_Texture, TERRA_OS, TERRA_PNG, TERRA_Vector2D,
6-
TERRA_DebugDraw, TERRA_FileManager, TERRA_Math, TERRA_Vector3D, TERRA_Font, TERRA_Tween;
5+
TERRA_ResourceManager, TERRA_Color, TERRA_Texture, TERRA_OS, TERRA_PNG, TERRA_Vector2D, TERRA_InputManager,
6+
TERRA_DebugDraw, TERRA_FileManager, TERRA_Math, TERRA_Vector3D, TERRA_Font, TERRA_Tween, TERRA_UI;
77

88
Type
99
// A client is used to process application events
@@ -78,13 +78,13 @@ End;
7878
// OnIdle is called once per frame, put your game logic here
7979
Procedure MyGame.OnIdle;
8080
Begin
81-
If Keys.WasPressed(keyEscape) Then
81+
If InputManager.Instance.Keys.WasPressed(keyEscape) Then
8282
Application.Instance.Terminate;
8383

84-
If Keys.WasPressed(keyLeft) Then
84+
If InputManager.Instance.Keys.WasPressed(keyLeft) Then
8585
Dec(EaseType);
8686

87-
If Keys.WasPressed(keyRight) Then
87+
If InputManager.Instance.Keys.WasPressed(keyRight) Then
8888
Inc(EaseType);
8989
End;
9090

@@ -104,8 +104,8 @@ Begin
104104
EaseType := 0;
105105
If (EaseType>37) Then
106106
EaseType := 37;
107-
108-
FontManager.Instance.DefaultFont.DrawText(10, 10, 10, 'Ease :'+EaseNames[EaseType], ColorWhite);
107+
108+
UIManager.Instance.FontRenderer.DrawText(10, 10, 10, 'Ease :'+EaseNames[EaseType]);
109109
Last := -1;
110110
For I:=0 To 100 Do
111111
Begin

0 commit comments

Comments
 (0)