mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 15:29:26 -05:00
Merge branch 'master' of github.com:OpenSpace/OpenSpace into feature/stereo
This commit is contained in:
@@ -81,14 +81,17 @@ int addLayer(lua_State* L) {
|
||||
}
|
||||
catch (const ghoul::lua::LuaFormatException& e) {
|
||||
LERRORC("addLayerFromDictionary", e.what());
|
||||
lua_settop(L, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
|
||||
std::shared_ptr<Layer> layer = globe->layerManager()->addLayer(groupID, d);
|
||||
if (layer) {
|
||||
layer->initialize();
|
||||
}
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -113,6 +116,8 @@ int deleteLayer(lua_State* L) {
|
||||
const std::string LayerGroupName = luaL_checkstring(L, LayerGroupLocation);
|
||||
const std::string LayerName = luaL_checkstring(L, NameLocation);
|
||||
|
||||
lua_settop(L, 0);
|
||||
|
||||
// Get the node and make sure it exists
|
||||
SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(GlobeName);
|
||||
if (!node) {
|
||||
@@ -133,6 +138,7 @@ int deleteLayer(lua_State* L) {
|
||||
|
||||
globe->layerManager()->deleteLayer(groupID, LayerName);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -148,10 +154,12 @@ int goToChunk(lua_State* L) {
|
||||
int x = static_cast<int>(lua_tonumber(L, 1));
|
||||
int y = static_cast<int>(lua_tonumber(L, 2));
|
||||
int level = static_cast<int>(lua_tonumber(L, 3));
|
||||
lua_settop(L, 0);
|
||||
|
||||
OsEng.moduleEngine().module<GlobeBrowsingModule>()->goToChunk(x, y, level);
|
||||
|
||||
return 0;
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int goToGeo(lua_State* L) {
|
||||
@@ -174,6 +182,8 @@ int goToGeo(lua_State* L) {
|
||||
altitude);
|
||||
}
|
||||
|
||||
lua_settop(L, 0);
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -202,10 +212,13 @@ int getGeoPosition(lua_State* L) {
|
||||
double altitude = glm::length(cameraPositionModelSpace -
|
||||
posHandle.centerToReferenceSurface);
|
||||
|
||||
lua_settop(L, 0);
|
||||
|
||||
lua_pushnumber(L, Angle<double>::fromRadians(geo2.lat).asDegrees());
|
||||
lua_pushnumber(L, Angle<double>::fromRadians(geo2.lon).asDegrees());
|
||||
lua_pushnumber(L, altitude);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 3, "Incorrect number of items left on stack");
|
||||
return 3;
|
||||
}
|
||||
|
||||
@@ -220,6 +233,7 @@ int loadWMSCapabilities(lua_State* L) {
|
||||
std::string name = lua_tostring(L, -3);
|
||||
std::string globe = lua_tostring(L, -2);
|
||||
std::string url = lua_tostring(L, -1);
|
||||
lua_settop(L, 0);
|
||||
|
||||
OsEng.moduleEngine().module<GlobeBrowsingModule>()->loadWMSCapabilities(
|
||||
std::move(name),
|
||||
@@ -227,6 +241,7 @@ int loadWMSCapabilities(lua_State* L) {
|
||||
std::move(url)
|
||||
);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -238,7 +253,11 @@ int removeWMSServer(lua_State* L) {
|
||||
}
|
||||
|
||||
std::string name = lua_tostring(L, -1);
|
||||
|
||||
lua_settop(L, 0);
|
||||
OsEng.moduleEngine().module<GlobeBrowsingModule>()->removeWMSServer(name);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -253,6 +272,7 @@ int capabilities(lua_State* L) {
|
||||
GlobeBrowsingModule::Capabilities cap =
|
||||
OsEng.moduleEngine().module<GlobeBrowsingModule>()->capabilities(name);
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_newtable(L);
|
||||
for (unsigned long i = 0; i < cap.size(); ++i) {
|
||||
const GlobeBrowsingModule::Layer& l = cap[i];
|
||||
@@ -270,6 +290,7 @@ int capabilities(lua_State* L) {
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
|
||||
return 1;
|
||||
}
|
||||
#endif // GLOBEBROWSING_USE_GDAL
|
||||
|
||||
@@ -52,7 +52,7 @@ void main() {
|
||||
vec4 position = pscTransform(tmp, mat4(1.0));
|
||||
|
||||
// G-Buffer
|
||||
vs_gPosition = position;
|
||||
vs_gPosition = view * (vec4(1E19, 1E19, 1E19, 1.0) * position);
|
||||
|
||||
position = view * position;
|
||||
|
||||
|
||||
@@ -106,6 +106,11 @@ void SyncModule::internalInitialize(const ghoul::Dictionary& configuration) {
|
||||
fTask->registerClass<SyncAssetTask>("SyncAssetTask");
|
||||
|
||||
_torrentClient.initialize();
|
||||
|
||||
// Deinitialize
|
||||
OsEng.registerModuleCallback(OpenSpaceEngine::CallbackOption::Deinitialize, [&] {
|
||||
_torrentClient.deinitialize();
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> SyncModule::documentations() const {
|
||||
|
||||
@@ -68,7 +68,7 @@ void SyncAssetTask::perform(const Task::ProgressCallback & progressCallback) {
|
||||
scripting::ScriptEngine scriptEngine;
|
||||
|
||||
registerCoreClasses(scriptEngine);
|
||||
;
|
||||
|
||||
for (OpenSpaceModule* m : OsEng.moduleEngine().modules()) {
|
||||
scriptEngine.addLibrary(m->luaLibrary());
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "TorrentClient";
|
||||
std::chrono::milliseconds PollInterval(200);
|
||||
std::chrono::milliseconds PollInterval(1000);
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -53,14 +53,11 @@ TorrentError::TorrentError(std::string component)
|
||||
namespace openspace {
|
||||
|
||||
TorrentClient::TorrentClient()
|
||||
: _keepRunning(true)
|
||||
: _active(false)
|
||||
{}
|
||||
|
||||
TorrentClient::~TorrentClient() {
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
_keepRunning = false;
|
||||
_torrentThread.join();
|
||||
_session = nullptr;
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
void TorrentClient::initialize() {
|
||||
@@ -92,40 +89,65 @@ void TorrentClient::initialize() {
|
||||
_session->listen_on(std::make_pair(20280, 20290), ec);
|
||||
_session->start_upnp();
|
||||
|
||||
_active = true;
|
||||
|
||||
_torrentThread = std::thread([this]() {
|
||||
while (_keepRunning) {
|
||||
while (_active) {
|
||||
pollAlerts();
|
||||
std::this_thread::sleep_for(PollInterval);
|
||||
std::unique_lock<std::mutex> lock(_abortMutex);
|
||||
_abortNotifier.wait_for(lock, PollInterval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void TorrentClient::deinitialize() {
|
||||
if (!_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
_active = false;
|
||||
_abortNotifier.notify_all();
|
||||
if (_torrentThread.joinable()) {
|
||||
_torrentThread.join();
|
||||
}
|
||||
|
||||
std::vector<lt::torrent_handle> handles = _session->get_torrents();
|
||||
for (lt::torrent_handle h : handles) {
|
||||
_session->remove_torrent(h);
|
||||
}
|
||||
_torrents.clear();
|
||||
|
||||
_session->abort();
|
||||
_session = nullptr;
|
||||
}
|
||||
|
||||
void TorrentClient::pollAlerts() {
|
||||
// Libtorrent does not seem to reliably generate alerts for all added torrents.
|
||||
// To make sure that the program does not keep waiting for already finished
|
||||
// downsloads, we go through the whole list of torrents when polling.
|
||||
// However, in theory, the commented code below should be more efficient:
|
||||
/*
|
||||
std::vector<libtorrent::alert*> alerts;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
_session->pop_alerts(&alerts);
|
||||
}
|
||||
|
||||
for (lt::alert const* a : alerts) {
|
||||
//LINFO(a->message());
|
||||
// if we receive the finished alert or an error, we're done
|
||||
if (const lt::torrent_finished_alert* alert =
|
||||
lt::alert_cast<lt::torrent_finished_alert>(a))
|
||||
{
|
||||
notify(alert->handle.id());
|
||||
}
|
||||
if (const lt::piece_finished_alert* alert =
|
||||
lt::alert_cast<lt::piece_finished_alert>(a))
|
||||
{
|
||||
notify(alert->handle.id());
|
||||
}
|
||||
if (const lt::torrent_error_alert* alert =
|
||||
lt::alert_cast<lt::torrent_error_alert>(a))
|
||||
for (lt::alert* a : alerts) {
|
||||
if (const lt::torrent_alert* alert =
|
||||
dynamic_cast<lt::torrent_alert*>(a))
|
||||
{
|
||||
notify(alert->handle.id());
|
||||
}
|
||||
}
|
||||
*/
|
||||
std::vector<lt::torrent_handle> handles;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
handles = _session->get_torrents();
|
||||
}
|
||||
for (lt::torrent_handle h : handles) {
|
||||
notify(h.id());
|
||||
}
|
||||
}
|
||||
|
||||
TorrentClient::TorrentId TorrentClient::addTorrentFile(std::string torrentFile,
|
||||
@@ -167,6 +189,11 @@ TorrentClient::TorrentId TorrentClient::addMagnetLink(std::string magnetLink,
|
||||
}
|
||||
libtorrent::error_code ec;
|
||||
libtorrent::add_torrent_params p = libtorrent::parse_magnet_uri(magnetLink, ec);
|
||||
|
||||
if (ec) {
|
||||
LERROR(magnetLink << ": " << ec.message());
|
||||
}
|
||||
|
||||
p.save_path = destination;
|
||||
p.storage_mode = libtorrent::storage_mode_allocate;
|
||||
|
||||
@@ -195,24 +222,29 @@ void TorrentClient::removeTorrent(TorrentId id) {
|
||||
}
|
||||
|
||||
void TorrentClient::notify(TorrentId id) {
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
|
||||
auto torrent = _torrents.find(id);
|
||||
if (torrent == _torrents.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
libtorrent::torrent_handle h = torrent->second.handle;
|
||||
libtorrent::torrent_status status = h.status();
|
||||
|
||||
TorrentProgressCallback callback;
|
||||
TorrentProgress progress;
|
||||
|
||||
progress.finished = status.is_finished;
|
||||
progress.nTotalBytesKnown = status.total_wanted > 0;
|
||||
progress.nTotalBytes = status.total_wanted;
|
||||
progress.nDownloadedBytes = status.total_wanted_done;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
|
||||
torrent->second.callback(progress);
|
||||
auto torrent = _torrents.find(id);
|
||||
if (torrent == _torrents.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
libtorrent::torrent_handle h = torrent->second.handle;
|
||||
libtorrent::torrent_status status = h.status();
|
||||
|
||||
progress.finished = status.is_finished;
|
||||
progress.nTotalBytesKnown = status.total_wanted > 0;
|
||||
progress.nTotalBytes = status.total_wanted;
|
||||
progress.nDownloadedBytes = status.total_wanted_done;
|
||||
|
||||
callback = torrent->second.callback;
|
||||
}
|
||||
|
||||
callback(progress);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -227,6 +259,8 @@ TorrentClient::~TorrentClient() {}
|
||||
|
||||
void TorrentClient::initialize() {}
|
||||
|
||||
void TorrentClient::deinitialize() {}
|
||||
|
||||
void TorrentClient::pollAlerts() {}
|
||||
|
||||
TorrentClient::TorrentId TorrentClient::addTorrentFile(std::string, std::string,
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
using TorrentId = int32_t;
|
||||
|
||||
virtual void initialize() = 0;
|
||||
virtual void deinitialize() = 0;
|
||||
virtual TorrentId addTorrentFile(std::string torrentFile,
|
||||
std::string destination,
|
||||
TorrentProgressCallback cb) = 0;
|
||||
@@ -78,6 +79,7 @@ public:
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "libtorrent/torrent_handle.hpp"
|
||||
@@ -92,6 +94,7 @@ public:
|
||||
virtual ~TorrentClient();
|
||||
|
||||
void initialize() override;
|
||||
void deinitialize() override;
|
||||
TorrentId addTorrentFile(std::string torrentFile,
|
||||
std::string destination,
|
||||
TorrentProgressCallback cb) override;
|
||||
@@ -116,7 +119,9 @@ private:
|
||||
std::unique_ptr<libtorrent::session> _session;
|
||||
std::thread _torrentThread;
|
||||
std::mutex _mutex;
|
||||
std::atomic_bool _keepRunning;
|
||||
std::atomic_bool _active;
|
||||
std::mutex _abortMutex;
|
||||
std::condition_variable _abortNotifier;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
@@ -131,6 +136,7 @@ public:
|
||||
virtual ~TorrentClient();
|
||||
|
||||
void initialize() override;
|
||||
void deinitialize() override;
|
||||
TorrentId addTorrentFile(std::string torrentFile,
|
||||
std::string destination,
|
||||
TorrentProgressCallback cb) override;
|
||||
|
||||
Reference in New Issue
Block a user