Work on asset loader and synchronization module

This commit is contained in:
Emil Axelsson
2017-07-21 15:36:09 +02:00
parent e1874101ce
commit 9491e920ad
8 changed files with 135 additions and 130 deletions
+2 -3
View File
@@ -26,15 +26,14 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/syncs/httpsynchronization.h
${CMAKE_CURRENT_SOURCE_DIR}/syncs/resourcesynchronization.h
# ${CMAKE_CURRENT_SOURCE_DIR}/syncs/resourcesynchronization.h
# ${CMAKE_CURRENT_SOURCE_DIR}/syncs/torrentsynchronization.h
${CMAKE_CURRENT_SOURCE_DIR}/syncs/synchronization.h
)
source_group("Header Files" FILES ${HEADER_FILES})
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/syncs/httpsynchronization.cpp
${CMAKE_CURRENT_SOURCE_DIR}/syncs/resourcesynchronization.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/syncs/resourcesynchronization.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/syncs/torrentsynchronization.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
+15 -19
View File
@@ -22,7 +22,7 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/space/spacemodule.h>
#include <modules/sync/syncmodule.h>
#include <openspace/documentation/documentation.h>
#include <openspace/rendering/renderable.h>
@@ -31,35 +31,31 @@
#include <ghoul/misc/assert.h>
#include <modules/sync/syncs/syncrhonization.h>
#include <modules/sync/syncs/httpsyncrhonization.h>
#include <modules/sync/syncs/resourcesyncrhonization.h>
#include <modules/sync/syncs/torrentsyncrhonization.h>
#include <openspace/util/resourcesynchronization.h>
#include <modules/sync/syncs/httpsynchronization.h>
//#include <modules/sync/syncs/resourcesyncrhonization.h>
//#include <modules/sync/syncs/torrentsyncrhonization.h>
namespace openspace {
SpaceModule::SpaceModule() : OpenSpaceModule(Name) {}
SyncModule::SyncModule() : OpenSpaceModule(Name) {}
void SpaceModule::internalInitialize() {
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Synchronization>>(),
"Synchronization"
);
void SyncModule::internalInitialize() {
auto fSynchronization = FactoryManager::ref().factory<Synchronization>();
auto fSynchronization = FactoryManager::ref().factory<ResourceSynchronization>();
ghoul_assert(fSynchronization, "Synchronization factory was not created");
fSynchronization->registerClass<RenderablePlanet>("HttpSyncrhonization");
fSynchronization->registerClass<RenderableRings>("ResourceSynchronization");
//fSynchronization->registerClass<RenderableConstellationBounds>("TorrentSynchronization");
fSynchronization->registerClass<HttpSynchronization>("HttpSyncrhonization");
}
std::vector<documentation::Documentation> SpaceModule::documentations() const {
std::vector<documentation::Documentation> SyncModule::documentations() const {
return {
HttpSyncrhonization::Documentation(),
ResourceSynchronization::Documentation(),
TorrentSynchronization::Documentation()
HttpSynchronization::Documentation()
//ResourceSynchronization::Documentation(),
//TorrentSynchronization::Documentation()
};
}
@@ -26,6 +26,38 @@
namespace openspace {
HttpSynchronization::HttpSynchronization(const ghoul::Dictionary& dict)
: openspace::ResourceSynchronization()
{
}
bool HttpSynchronization::needsSync() {
return true;
}
std::shared_ptr<SynchronizationJob> HttpSynchronization::createSynchronizationJob() {
return std::make_shared<HttpSynchronizationJob>();
}
documentation::Documentation HttpSynchronization::Documentation() {
return {};
}
HttpSynchronizationJob::HttpSynchronizationJob() {
}
HttpSynchronizationJob::~HttpSynchronizationJob() {
}
void HttpSynchronizationJob::execute() {
}
std::shared_ptr<SynchronizationProduct> HttpSynchronizationJob::product() {
return nullptr;
}
} // namespace openspace
+20
View File
@@ -25,9 +25,29 @@
#ifndef __OPENSPACE_MODULE_SYNC___HTTPSYNCHRONIZATION___H__
#define __OPENSPACE_MODULE_SYNC___HTTPSYNCHRONIZATION___H__
#include <openspace/util/resourcesynchronization.h>
#include <openspace/documentation/documentation.h>
#include <ghoul/misc/dictionary.h>
namespace openspace {
class HttpSynchronization : public ResourceSynchronization {
public:
HttpSynchronization(const ghoul::Dictionary& dict);
bool needsSync() override;
std::shared_ptr<SynchronizationJob> createSynchronizationJob() override;
static documentation::Documentation Documentation();
};
class HttpSynchronizationJob : public SynchronizationJob {
public:
HttpSynchronizationJob();
virtual ~HttpSynchronizationJob();
void execute() override;
std::shared_ptr<SynchronizationProduct> product() override;
};
} // namespace openspace
-34
View File
@@ -1,34 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_SYNC___SYNCHRONIZATION___H__
#define __OPENSPACE_MODULE_SYNC___SYNCHRONIZATION___H__
namespace openspace {
} // namespace openspace
#endif // __OPENSPACE_MODULE_SYNC___SYNCHRONIZATION___H__
+5
View File
@@ -51,6 +51,7 @@
#include <openspace/scene/translation.h>
#include <openspace/scene/sceneloader.h>
#include <openspace/scene/assetloader.h>
#include <openspace/util/resourcesynchronization.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/task.h>
@@ -182,6 +183,10 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
std::make_unique<ghoul::TemplateFactory<Task>>(),
"Task"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<ResourceSynchronization>>(),
"ResourceSynchronization"
);
SpiceManager::initialize();
TransformationManager::initialize();
+3 -3
View File
@@ -81,7 +81,7 @@ int importAsset(lua_State* state) {
try {
return assetLoader->importAssetLua(assetName, false, false);
} catch (const ghoul::RuntimeError& e) {
return luaL_error(state, "Failed to import asset '%s'. %s: %s", assetName.c_str(), e.message, e.component);
return luaL_error(state, "Failed to import asset '%s'. %s: %s", assetName.c_str(), e.message.c_str(), e.component.c_str());
}
}
@@ -99,7 +99,7 @@ int importAssetToggle(lua_State* state) {
try {
return assetLoader->importAssetLua(assetName, true, toggleEnabled);
} catch (const ghoul::RuntimeError& e) {
return luaL_error(state, "Failed to import asset '%s'. %s: %s", assetName.c_str(), e.message, e.component);
return luaL_error(state, "Failed to import asset '%s'. %s: %s", assetName.c_str(), e.message.c_str(), e.component.c_str());
}
}
@@ -274,7 +274,7 @@ void AssetLoader::pushAsset(Asset* asset) {
// Register empty data table on imported asset
lua_newtable(*_luaState);
lua_setfield(*_luaState, assetTableIndex, DataTableName);
lua_setfield(*_luaState, assetTableIndex, SyncTableName);
// Register empty dependant table on imported asset.
// (importer => dependant object)
+58 -71
View File
@@ -24,6 +24,7 @@
#include "gtest/gtest.h"
#include <openspace/scene/assetloader.h>
#include <openspace/scene/sceneloader.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/documentation/documentation.h>
@@ -34,39 +35,44 @@
#include <fstream>
class SceneLoaderTest : public ::testing::Test {
protected:
virtual void SetUp() {
_assetLoader = std::make_unique<openspace::AssetLoader>(&_luaState, "${TESTDIR}/SceneLoaderTest/", "${TEMPORARY}/resources/");
_sceneLoader = std::make_unique<openspace::SceneLoader>(_assetLoader.get());
}
openspace::Scene _scene;
ghoul::lua::LuaState _luaState;
std::unique_ptr<openspace::AssetLoader> _assetLoader;
std::unique_ptr<openspace::SceneLoader> _sceneLoader;
};
//class SceneLoaderTest : public testing::Test {};
TEST(SceneLoaderTest, NonExistingFileTest) {
TEST_F(SceneLoaderTest, NonExistingFileTest) {
const std::string file = absPath("NonExistingFile");
openspace::SceneLoader loader;
EXPECT_THROW(loader.loadScene(file), ghoul::FileNotFoundError);
EXPECT_THROW(_sceneLoader->loadScene(&_scene, file), ghoul::FileNotFoundError);
}
TEST(SceneLoaderTest, IllformedFileTest) {
TEST_F(SceneLoaderTest, IllformedFileTest) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/illformed.scene");
openspace::SceneLoader loader;
EXPECT_THROW(loader.loadScene(file), ghoul::lua::LuaRuntimeException);
EXPECT_THROW(_sceneLoader->loadScene(&_scene, file), ghoul::lua::LuaRuntimeException);
}
TEST(SceneLoaderTest, IllformedFileTestInvalidSceneFolder) {
TEST_F(SceneLoaderTest, IllformedFileTestInvalidSceneFolder) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/illformedInvalidScene.scene");
openspace::SceneLoader loader;
EXPECT_THROW(loader.loadScene(file), openspace::documentation::SpecificationError);
EXPECT_THROW(_sceneLoader->loadScene(&_scene, file), openspace::documentation::SpecificationError);
}
TEST(SceneLoaderTest, IllformedFileTestWrongType) {
TEST_F(SceneLoaderTest, IllformedFileTestWrongType) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/illformedWrongType.scene");
openspace::SceneLoader loader;
EXPECT_THROW(loader.loadScene(file), openspace::documentation::SpecificationError);
EXPECT_THROW(_sceneLoader->loadScene(&_scene, file), openspace::documentation::SpecificationError);
}
TEST(SceneLoaderTest, AbsoluteScenePath) {
TEST_F(SceneLoaderTest, AbsoluteScenePath) {
const std::string scenePath = absPath("${TEMPORARY}/tmp.scene");
std::ofstream sceneFile(scenePath.c_str());
@@ -85,82 +91,70 @@ TEST(SceneLoaderTest, AbsoluteScenePath) {
sceneFile << "return " << formatter.format(sceneFileDictionary);
sceneFile.close();
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(scenePath);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
_sceneLoader->loadScene(&_scene, scenePath);
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 1) << "Expected scene to consist of one root node";
}
TEST(SceneLoaderTest, Test00) {
TEST_F(SceneLoaderTest, Test00) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test00.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 1) << "Expected scene to consist of one root node";
}
TEST(SceneLoaderTest, Test00Location) {
TEST_F(SceneLoaderTest, Test00Location) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test00-location.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 1) << "Expected scene to consist of one root node";
}
TEST(SceneLoaderTest, Test01) {
TEST_F(SceneLoaderTest, Test01) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test01.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 2) << "Expected scene to consist of two nodes";
std::map<std::string, openspace::SceneGraphNode*> nodesByName = scene->nodesByName();
std::map<std::string, openspace::SceneGraphNode*> nodesByName = _scene.nodesByName();
EXPECT_EQ(nodesByName.size(), 2) << "Expected scene to consist of two nodes";
EXPECT_EQ(nodesByName["Root"]->name(), "Root");
EXPECT_EQ(nodesByName["NoDependency"]->name(), "NoDependency");
EXPECT_EQ(nodesByName["NoDependency"]->parent(), nodesByName["Root"]);
}
TEST(SceneLoaderTest, Test01Location) {
TEST_F(SceneLoaderTest, Test01Location) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test01-location.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 2) << "Expected scene to consist of two nodes";
std::map<std::string, openspace::SceneGraphNode*> nodesByName = scene->nodesByName();
std::map<std::string, openspace::SceneGraphNode*> nodesByName = _scene.nodesByName();
EXPECT_EQ(nodesByName.size(), 2) << "Expected scene to consist of two nodes";
EXPECT_EQ(nodesByName["Root"]->name(), "Root");
EXPECT_EQ(nodesByName["NoDependency"]->name(), "NoDependency");
EXPECT_EQ(nodesByName["NoDependency"]->parent(), nodesByName["Root"]);
}
TEST(SceneLoaderTest, Test02) {
TEST_F(SceneLoaderTest, Test02) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test02.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 3) << "Expected scene to consist of two nodes";
std::map<std::string, openspace::SceneGraphNode*> nodesByName = scene->nodesByName();
std::map<std::string, openspace::SceneGraphNode*> nodesByName = _scene.nodesByName();
EXPECT_EQ(nodesByName.size(), 3) << "Expected scene to consist of two nodes";
EXPECT_EQ(nodesByName["Root"]->name(), "Root");
EXPECT_EQ(nodesByName["NoDependency"]->name(), "NoDependency");
@@ -172,17 +166,15 @@ TEST(SceneLoaderTest, Test02) {
EXPECT_EQ(nodesByName["Child"]->dependencies().size(), 0);
}
TEST(SceneLoaderTest, Test02Location) {
TEST_F(SceneLoaderTest, Test02Location) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test02-location.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 3) << "Expected scene to consist of three nodes";
std::map<std::string, openspace::SceneGraphNode*> nodesByName = scene->nodesByName();
std::map<std::string, openspace::SceneGraphNode*> nodesByName = _scene.nodesByName();
EXPECT_EQ(nodesByName.size(), 3) << "Expected scene to consist of three nodes";
EXPECT_EQ(nodesByName["Root"]->name(), "Root");
EXPECT_EQ(nodesByName["NoDependency"]->name(), "NoDependency");
@@ -196,17 +188,15 @@ TEST(SceneLoaderTest, Test02Location) {
EXPECT_EQ(nodesByName["Child"]->dependencies().size(), 0);
}
TEST(SceneLoaderTest, Test03) {
TEST_F(SceneLoaderTest, Test03) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test03.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 3) << "Expected scene to consist of three nodes";
std::map<std::string, openspace::SceneGraphNode*> nodesByName = scene->nodesByName();
std::map<std::string, openspace::SceneGraphNode*> nodesByName = _scene.nodesByName();
EXPECT_EQ(nodesByName.size(), 3) << "Expected scene to consist of three nodes";
EXPECT_EQ(nodesByName["Root"]->name(), "Root");
EXPECT_EQ(nodesByName["NoDependency"]->name(), "NoDependency");
@@ -222,17 +212,15 @@ TEST(SceneLoaderTest, Test03) {
EXPECT_EQ(nodesByName["Dependent"]->dependencies()[0], nodesByName["NoDependency"]);
}
TEST(SceneLoaderTest, Test04) {
TEST_F(SceneLoaderTest, Test04) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test04.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
_sceneLoader->loadScene(&_scene, file);
ASSERT_NE(scene, nullptr) << "loadScene returned nullptr";
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 5) << "Expected scene to consist of five nodes";
std::map<std::string, openspace::SceneGraphNode*> nodesByName = scene->nodesByName();
std::map<std::string, openspace::SceneGraphNode*> nodesByName = _scene.nodesByName();
EXPECT_EQ(nodesByName.size(), 5) << "Expected scene to consist of five nodes";
EXPECT_EQ(nodesByName["Root"]->name(), "Root");
EXPECT_EQ(nodesByName["NoDependency"]->name(), "NoDependency");
@@ -254,12 +242,11 @@ TEST(SceneLoaderTest, Test04) {
EXPECT_EQ(nodesByName["ChildAndDependent"]->dependencies()[0], nodesByName["Dependent"]);
}
TEST(SceneLoaderTest, Test05) {
TEST_F(SceneLoaderTest, Test05) {
const std::string file = absPath("${TESTDIR}/SceneLoaderTest/test05.scene");
openspace::SceneLoader loader;
std::unique_ptr<openspace::Scene> scene = loader.loadScene(file);
std::vector<openspace::SceneGraphNode*> nodes = scene->allSceneGraphNodes();
_sceneLoader->loadScene(&_scene, file);
std::vector<openspace::SceneGraphNode*> nodes = _scene.allSceneGraphNodes();
EXPECT_EQ(nodes.size(), 1);
// TODO: Add more tests regarding circular deps.