5 * Copyright (c) 2016 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>
37 * Container based types owning heap allocated data of specifed types
39 typedef GameContainer< GameEntity* > EntityArray;
40 typedef GameContainer< GameTexture* > TextureArray;
41 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] filename Path to the scene file
61 * @return true if suceess
63 bool Load( const char* filename );
66 * Loads resource ( model or texture ) or gets if from cache if already loaded
67 * @param[in] filename Path to the resource file
68 * @param[in] cache Reference to the cache array to be used
69 * @return Pointer to the resource or NULL otherwise
72 T* GetResource( const char* filename, GameContainer<T*>& cache );
75 * Returns scene root actor
76 * @return Parent actor of the whole game scene
78 Dali::Actor& GetRootActor();
82 EntityArray mEntities;
85 // internal scene cache
86 ModelArray mModelCache;
87 TextureArray mTextureCache;
89 Dali::Actor mRootActor;
94 T* GameScene::GetResource( const char* filename, GameContainer<T*>& cache )
96 std::string path( DEMO_GAME_DIR );
100 uint32_t hash( GameUtils::HashString( path.c_str() ) );
102 for( typename GameContainer<T*>::Iterator iter = cache.Begin(); iter != cache.End(); ++iter )
104 if( (*iter)->GetUniqueId() == hash )
111 T* resource = new T( path.c_str() );
112 if( !resource->IsReady() )
117 cache.PushBack( resource );