5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include "game-camera.h"
26 #include "game-container.h"
27 #include "game-utils.h"
29 #include <dali/public-api/actors/actor.h>
30 #include <dali/public-api/adaptor-framework/window.h>
38 * Container based types owning heap allocated data of specifed types
40 typedef GameContainer<GameEntity*> EntityArray;
41 typedef GameContainer<GameTexture*> TextureArray;
42 typedef GameContainer<GameModel*> ModelArray;
48 * Creates an instance of the GameScene
53 * Destroys an instance of the GameScene
58 * Loads scene from formatted JSON file, returns true on success
60 * @param[in] window The window to load the scene on
61 * @param[in] filename Path to the scene file
62 * @return true if suceess
64 bool Load(Dali::Window window, const char* filename);
67 * Loads resource ( model or texture ) or gets if from cache if already loaded
68 * @param[in] filename Path to the resource file
69 * @param[in] cache Reference to the cache array to be used
70 * @return Pointer to the resource or NULL otherwise
73 T* GetResource(const char* filename, GameContainer<T*>& cache);
76 * Returns scene root actor
77 * @return Parent actor of the whole game scene
79 Dali::Actor& GetRootActor();
82 EntityArray mEntities;
85 // internal scene cache
86 ModelArray mModelCache;
87 TextureArray mTextureCache;
89 Dali::Actor mRootActor;
93 T* GameScene::GetResource(const char* filename, GameContainer<T*>& cache)
95 std::string path(DEMO_GAME_DIR);
99 uint32_t hash(GameUtils::HashString(path.c_str()));
101 for(typename GameContainer<T*>::Iterator iter = cache.Begin(); iter != cache.End(); ++iter)
103 if((*iter)->GetUniqueId() == hash)
110 T* resource = new T(path.c_str());
111 if(!resource->IsReady())
116 cache.PushBack(resource);