2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "game-renderer.h"
19 #include "game-model.h"
20 #include "game-texture.h"
21 #include "game-scene.h"
23 #include "fpp-game-tutorial-controller.h"
25 #include <dali-toolkit/dali-toolkit.h>
32 const char* SCENE_URL =
34 DEMO_GAME_DIR "/scene.json"
38 /* This example creates 3D environment with first person camera control
39 It contains following modules:
41 GameScene - responsible for loading and managing the scene data,
42 it wraps around window. Owns list of entities. Scene can be deserialised
43 from json file ( see scene.json )
44 GameEntity - the renderable object that has also a transformation. It wraps DALi actors.
46 GameModel - loads models ( '.mod' file format ) and wraps DALi Geometry object. 'mod' format
49 GameTexture - manages textures. Loads them, creates samplers and wraps DALi TextureSet
51 GameRenderer - binds texture and model. It's created per entity. While renderer is always unique
52 for entity, the texture and model may be reused
54 GameCamera - Wraps the CameraActor. It provides not only that but also handles user input and
55 implements first-person-perspective camera behavior.
56 GameCamera uses Dali::Timer to provide per-frame ( or rather every 16ms ) update tick.
60 .---------------| GameScene |---------------.
64 .------------. .------------.|.------------. .------------.
65 | GameEntity | | GameEntity |v| ... | | GameEntity |
66 '------------' '------------' '------------' '------------'
74 .--------------. .--------------.
75 | GameTexture | | GameModel |
76 '--------------' '--------------'
78 class GameController : public ConnectionTracker
82 GameController( Application& application )
83 : mApplication( application )
85 // Connect to the Application's Init signal
86 mApplication.InitSignal().Connect( this, &GameController::Create );
93 // The Init signal is received once (only) during the Application lifetime
94 void Create( Application& application )
96 // Get a handle to the window
97 mWindow = application.GetWindow();
99 mWindow.SetBackgroundColor( Color::BLACK );
102 mWindow.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
105 mScene.Load( mWindow, SCENE_URL );
108 mTutorialController.DisplayTutorial( mWindow );
110 // Connect OnKeyEvent signal
111 mWindow.KeyEventSignal().Connect( this, &GameController::OnKeyEvent );
114 // Handle a quit key event
115 void OnKeyEvent(const KeyEvent& event)
117 if(event.GetState() == KeyEvent::Down)
119 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
128 Application& mApplication;
131 FppGameTutorialController mTutorialController;
134 int DALI_EXPORT_API main( int argc, char **argv )
136 Application application = Application::New( &argc, &argv );
137 GameController test( application );
138 application.MainLoop();