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-model.h"
19 #include "game-renderer.h"
20 #include "game-scene.h"
21 #include "game-texture.h"
23 #include "fpp-game-tutorial-controller.h"
25 #include <dali-toolkit/dali-toolkit.h>
31 const char* SCENE_URL =
33 DEMO_GAME_DIR "/scene.json"};
36 /* This example creates 3D environment with first person camera control
37 It contains following modules:
39 GameScene - responsible for loading and managing the scene data,
40 it wraps around window. Owns list of entities. Scene can be deserialised
41 from json file ( see scene.json )
42 GameEntity - the renderable object that has also a transformation. It wraps DALi actors.
44 GameModel - loads models ( '.mod' file format ) and wraps DALi Geometry object. 'mod' format
47 GameTexture - manages textures. Loads them, creates samplers and wraps DALi TextureSet
49 GameRenderer - binds texture and model. It's created per entity. While renderer is always unique
50 for entity, the texture and model may be reused
52 GameCamera - Wraps the CameraActor. It provides not only that but also handles user input and
53 implements first-person-perspective camera behavior.
54 GameCamera uses Dali::Timer to provide per-frame ( or rather every 16ms ) update tick.
58 .---------------| GameScene |---------------.
62 .------------. .------------.|.------------. .------------.
63 | GameEntity | | GameEntity |v| ... | | GameEntity |
64 '------------' '------------' '------------' '------------'
72 .--------------. .--------------.
73 | GameTexture | | GameModel |
74 '--------------' '--------------'
76 class GameController : public ConnectionTracker
79 GameController(Application& application)
80 : mApplication(application)
82 // Connect to the Application's Init signal
83 mApplication.InitSignal().Connect(this, &GameController::Create);
90 // The Init signal is received once (only) during the Application lifetime
91 void Create(Application& application)
93 // Get a handle to the window
94 mWindow = application.GetWindow();
96 mWindow.SetBackgroundColor(Color::BLACK);
99 mWindow.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
102 mScene.Load(mWindow, SCENE_URL);
105 mTutorialController.DisplayTutorial(mWindow);
107 // Connect OnKeyEvent signal
108 mWindow.KeyEventSignal().Connect(this, &GameController::OnKeyEvent);
111 // Handle a quit key event
112 void OnKeyEvent(const KeyEvent& event)
114 if(event.GetState() == KeyEvent::DOWN)
116 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
124 Application& mApplication;
127 FppGameTutorialController mTutorialController;
130 int DALI_EXPORT_API main(int argc, char** argv)
132 Application application = Application::New(&argc, &argv);
133 GameController test(application);
134 application.MainLoop();