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-container.h"
26 #include "game-utils.h"
27 #include "game-camera.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;
49 * Creates an instance of the GameScene
54 * Destroys an instance of the GameScene
59 * Loads scene from formatted JSON file, returns true on success
61 * @param[in] window The window to load the scene on
62 * @param[in] filename Path to the scene file
63 * @return true if suceess
65 bool Load( Dali::Window window, const char* filename );
68 * Loads resource ( model or texture ) or gets if from cache if already loaded
69 * @param[in] filename Path to the resource file
70 * @param[in] cache Reference to the cache array to be used
71 * @return Pointer to the resource or NULL otherwise
74 T* GetResource( const char* filename, GameContainer<T*>& cache );
77 * Returns scene root actor
78 * @return Parent actor of the whole game scene
80 Dali::Actor& GetRootActor();
84 EntityArray mEntities;
87 // internal scene cache
88 ModelArray mModelCache;
89 TextureArray mTextureCache;
91 Dali::Actor mRootActor;
96 T* GameScene::GetResource( const char* filename, GameContainer<T*>& cache )
98 std::string path( DEMO_GAME_DIR );
102 uint32_t hash( GameUtils::HashString( path.c_str() ) );
104 for( typename GameContainer<T*>::Iterator iter = cache.Begin(); iter != cache.End(); ++iter )
106 if( (*iter)->GetUniqueId() == hash )
113 T* resource = new T( path.c_str() );
114 if( !resource->IsReady() )
119 cache.PushBack( resource );