2 * Copyright (c) 2017 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 stage. 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 )
97 Dali::Window winHandle = application.GetWindow();
98 winHandle.ShowIndicator( Dali::Window::INVISIBLE );
100 // Get a handle to the stage
101 mStage = Stage::GetCurrent();
103 mStage.SetBackgroundColor( Color::BLACK );
106 mStage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
109 mScene.Load( SCENE_URL );
112 mTutorialController.DisplayTutorial();
114 // Connect OnKeyEvent signal
115 mStage.KeyEventSignal().Connect( this, &GameController::OnKeyEvent );
118 // Handle a quit key event
119 void OnKeyEvent(const KeyEvent& event)
121 if(event.state == KeyEvent::Down)
123 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
132 Application& mApplication;
135 FppGameTutorialController mTutorialController;
138 int DALI_EXPORT_API main( int argc, char **argv )
140 Application application = Application::New( &argc, &argv );
141 GameController test( application );
142 application.MainLoop();