X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ffpp-game%2Fgame-scene.cpp;h=1b768f4460b75ae2a5c448e3acb883ae69427f72;hb=4f2d9d01598786b08a6f50d86e140d23951be2e0;hp=03b8e0577e4169d12881317d6bd5dca566ca7265;hpb=d9253e5ef3a09dd18b4e0c59eabc8379d0c8138a;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/fpp-game/game-scene.cpp b/examples/fpp-game/game-scene.cpp index 03b8e05..1b768f4 100644 --- a/examples/fpp-game/game-scene.cpp +++ b/examples/fpp-game/game-scene.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,17 @@ * */ -#include #include +#include -#include "game-scene.h" -#include "game-model.h" -#include "game-texture.h" +#include "game-camera.h" #include "game-entity.h" +#include "game-model.h" #include "game-renderer.h" -#include "game-camera.h" +#include "game-scene.h" +#include "game-texture.h" -#include "third-party/picojson.h" +#include "third-party/pico-json.h" #include @@ -44,132 +44,127 @@ GameScene::~GameScene() { } -bool GameScene::Load(const char *filename) +bool GameScene::Load(Window window, const char* filename) { ByteArray bytes; - if( !LoadFile( filename, bytes ) ) + if(!LoadFile(filename, bytes)) { return false; } // add EOL - bytes.push_back( '\0'); + bytes.push_back('\0'); picojson::value root; - picojson::parse( root, bytes.data() ); + picojson::parse(root, bytes.data()); - bool failed( false ); + bool failed(false); - if( root.is() ) + if(root.is()) { object rootObject = root.get(); - for( object::iterator it = rootObject.begin(); it != rootObject.end(); ++it ) + for(object::iterator it = rootObject.begin(); it != rootObject.end(); ++it) { - std::string entityName( (*it).first ); + std::string entityName((*it).first); - GameEntity* entity = new GameEntity( entityName.c_str() ); - mEntities.PushBack( entity ); + GameEntity* entity = new GameEntity(entityName.c_str()); + mEntities.PushBack(entity); - value& val( (*it).second ); - value& vLocation = val.get( "location" ); - value& vRotation = val.get( "rotation" ); - value& vScale = val.get( "scale" ); - value& vSize = val.get( "size" ); - value& vModel = val.get( "model" ); - value& vTexture = val.get( "texture" ); + value& val((*it).second); + value& vLocation = val.get("location"); + value& vRotation = val.get("rotation"); + value& vScale = val.get("scale"); + value& vSize = val.get("size"); + value& vModel = val.get("model"); + value& vTexture = val.get("texture"); - if( !vLocation.is() ) + if(!vLocation.is()) { array& location = vLocation.get(); - entity->SetLocation( Vector3( - location.at(0).get(), - location.at(1).get(), - location.at(2).get() - )); + entity->SetLocation(Vector3( + location.at(0).get(), + location.at(1).get(), + location.at(2).get())); } - if( !vRotation.is() ) + if(!vRotation.is()) { array& rotation = vRotation.get(); - entity->SetRotation( Quaternion( Vector4( - -rotation.at(0).get(), - rotation.at(1).get(), - -rotation.at(2).get(), - rotation.at(3).get() - )) ); + entity->SetRotation(Quaternion(Vector4( + -rotation.at(0).get(), + rotation.at(1).get(), + -rotation.at(2).get(), + rotation.at(3).get()))); } - if( !vScale.is() ) + if(!vScale.is()) { array& scale = vScale.get(); - entity->SetScale( Vector3( - scale.at(0).get(), - scale.at(1).get(), - scale.at(2).get() - )); + entity->SetScale(Vector3( + scale.at(0).get(), + scale.at(1).get(), + scale.at(2).get())); } - if( !vSize.is() ) + if(!vSize.is()) { array& size = vSize.get(); - entity->SetSize( Vector3( - size.at(0).get(), - size.at(1).get(), - size.at(2).get() - )); + entity->SetSize(Vector3( + size.at(0).get(), + size.at(1).get(), + size.at(2).get())); } - GameModel* model( NULL ); - GameTexture* texture( NULL ); + GameModel* model(NULL); + GameTexture* texture(NULL); - if( !vModel.is() ) + if(!vModel.is()) { std::string& strModel = vModel.get(); - model = GetResource( strModel.c_str(), mModelCache ); + model = GetResource(strModel.c_str(), mModelCache); } - if( !vTexture.is() ) + if(!vTexture.is()) { std::string& strTexture = vTexture.get(); - texture = GetResource( strTexture.c_str(), mTextureCache ); + texture = GetResource(strTexture.c_str(), mTextureCache); } - if( !model || !texture ) + if(!model || !texture) { failed = true; break; } - entity->GetGameRenderer().SetModel( model ); - entity->GetGameRenderer().SetMainTexture( texture ); + entity->GetGameRenderer().SetModel(model); + entity->GetGameRenderer().SetMainTexture(texture); } } - if( failed ) + if(failed) { return false; } - // add all to the stage - Stage stage = Stage::GetCurrent(); + // add all to the window mRootActor = Actor::New(); - mRootActor.SetAnchorPoint( AnchorPoint::CENTER ); - mRootActor.SetParentOrigin( ParentOrigin::CENTER ); - stage.GetRootLayer().Add( mRootActor ); - mRootActor.SetScale( -1.0, 1.0, 1.0 ); - mRootActor.SetPosition( 0.0, 0.0, 0.0 ); - mRootActor.SetOrientation( Degree( 90 ), Vector3( 1.0, 0.0, 0.0 )); - for( size_t i = 0; i < mEntities.Size(); ++i ) + mRootActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mRootActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + window.GetRootLayer().Add(mRootActor); + mRootActor.SetProperty(Actor::Property::SCALE, Vector3(-1.0, 1.0, 1.0)); + mRootActor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 0.0)); + mRootActor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Degree(90), Vector3(1.0, 0.0, 0.0))); + for(size_t i = 0; i < mEntities.Size(); ++i) { - Actor actor( mEntities[i]->GetActor() ); - actor.SetAnchorPoint( AnchorPoint::CENTER ); - actor.SetParentOrigin( ParentOrigin::CENTER ); - mRootActor.Add( actor ); + Actor actor(mEntities[i]->GetActor()); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mRootActor.Add(actor); mEntities[i]->UpdateRenderer(); } // update camera - mCamera.Initialise( 60.0f, 0.1f, 100.0f ); + mCamera.Initialise(window.GetRenderTaskList().GetTask(0).GetCameraActor(), 60.0f, 0.1f, 100.0f, window.GetSize()); return true; }