Merge branch 'feature/dome' into develop

This commit is contained in:
Joakim Kilby
2015-02-17 14:42:53 +01:00
11 changed files with 712 additions and 595 deletions

View File

@@ -34,6 +34,8 @@
*/
namespace openspace {
class SyncBuffer;
namespace scripting {
class ScriptEngine {
@@ -67,6 +69,16 @@ public:
bool writeDocumentation(const std::string& filename, const std::string& type) const;
void serialize(SyncBuffer* syncBuffer);
void deserialize(SyncBuffer* syncBuffer);
void postSynchronizationPreDraw();
void preSynchronization();
void queueScript(const std::string &script);
std::vector<std::string> allLuaFunctions() const;
private:
@@ -80,6 +92,11 @@ private:
lua_State* _state;
std::set<LuaLibrary> _registeredLibraries;
//sync variables
std::mutex _mutex;
std::vector<std::string> _queuedScripts;
std::string _currentSyncedScript;
};
} // namespace scripting

View File

@@ -99,6 +99,8 @@ public:
void setPosition(psc pos);
const psc& position() const;
const psc& unsynchedPosition() const;
void setModelMatrix(glm::mat4 modelMatrix);
const glm::mat4& modelMatrix() const;
@@ -169,6 +171,11 @@ private:
glm::vec2 _sharedScaling;
psc _sharedPosition;
glm::mat4 _sharedViewRotationMatrix;
//synced copies of local variables
glm::vec2 _syncedScaling;
psc _syncedPosition;
glm::mat4 _syncedViewRotationMatrix;
};

View File

@@ -197,6 +197,11 @@ private:
double _sharedTime;
double _sharedDt;
bool _sharedTimeJumped;
//synced copies
double _syncedTime;
double _syncedDt;
bool _syncedTimeJumped;
std::mutex _syncMutex;

View File

@@ -517,18 +517,23 @@ bool OpenSpaceEngine::initializeGL() {
void OpenSpaceEngine::preSynchronization() {
FileSys.triggerFilesystemEvents();
if (sgct::Engine::instance()->isMaster()) {
const double dt = sgct::Engine::instance()->getDt();
_interactionHandler->update(dt);
//_interactionHandler.lockControls();
//const double dt = sgct::Engine::instance()->getDt();
const double dt = sgct::Engine::instance()->getAvgDt();
Time::ref().advanceTime(dt);
Time::ref().preSynchronization();
_interactionHandler->update(dt);
//_interactionHandler.lockControls();
_scriptEngine->preSynchronization();
_renderEngine->preSynchronization();
}
}
void OpenSpaceEngine::postSynchronizationPreDraw() {
Time::ref().postSynchronizationPreDraw();
_scriptEngine->postSynchronizationPreDraw();
_renderEngine->postSynchronizationPreDraw();
if (sgct::Engine::instance()->isMaster() && _gui->isEnabled()) {
@@ -635,7 +640,10 @@ void OpenSpaceEngine::mouseScrollWheelCallback(int pos) {
void OpenSpaceEngine::encode() {
if (_syncBuffer) {
_renderEngine->serialize(_syncBuffer);
Time::ref().serialize(_syncBuffer);
_scriptEngine->serialize(_syncBuffer);
_renderEngine->serialize(_syncBuffer);
_syncBuffer->write();
}
}
@@ -643,7 +651,11 @@ void OpenSpaceEngine::encode() {
void OpenSpaceEngine::decode() {
if (_syncBuffer) {
_syncBuffer->read();
Time::ref().deserialize(_syncBuffer);
_scriptEngine->deserialize(_syncBuffer);
_renderEngine->deserialize(_syncBuffer);
}
}
@@ -660,7 +672,8 @@ void OpenSpaceEngine::externalControlCallback(const char* receivedChars,
{
std::string script = std::string(receivedChars + 1);
LINFO("Received Lua Script: '" << script << "'");
_scriptEngine->runScript(script);
//_scriptEngine->runScript(script);
_scriptEngine->queueScript(script);
}
}
}

View File

@@ -532,26 +532,39 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
transform = glm::rotate(dy * 10, cameraRight) * transform;
transform = glm::rotate(dz * 10, _camera->viewDirection()) * transform;
// should be changed to something more dynamic =)
//get "old" focus position
psc focus = _camera->focusPosition();
//// get camera position
//psc relative = _camera->position();
// get camera position (UNSYNCHRONIZED)
psc relative = _camera->unsynchedPosition();
//get relative vector
psc relative_focus_coordinate = relative - focus;
//rotate relative vector
relative_focus_coordinate = glm::inverse(transform) * relative_focus_coordinate.vec4();
//get new new position of focus node
psc origin;
if (_focusNode) {
origin = _focusNode->worldPosition();
}
_camera->setFocusPosition(origin);
// the camera position
psc relative = _camera->position();
psc relative_origin_coordinate = relative - origin;
relative_origin_coordinate = glm::inverse(transform) * relative_origin_coordinate.vec4();
relative = origin + relative_origin_coordinate; //relative_origin_coordinate + origin;
//new camera position
relative = origin + relative_focus_coordinate;
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f);
psc target = relative + relative_origin_coordinate * dist;// *fmaxf(bounds, (1.f - d));
psc target = relative + relative_focus_coordinate * dist;
//don't fly into objects
if ((target - origin).length() < bounds){
target = relative;
}
_camera->setFocusPosition(origin);
_camera->setPosition(target);
_camera->rotate(glm::quat_cast(transform));
@@ -846,7 +859,8 @@ void InteractionHandler::keyboardCallback(int key, int action) {
_validKeyLua = true;
auto ret = _keyLua.equal_range(key);
for (auto it = ret.first; it != ret.second; ++it) {
OsEng.scriptEngine()->runScript(it->second);
//OsEng.scriptEngine()->runScript(it->second);
OsEng.scriptEngine()->queueScript(it->second);
if (!_validKeyLua) {
break;
}

View File

@@ -217,7 +217,8 @@ void LuaConsole::keyboardCallback(int key, int action) {
// ENTER == run lua script
else {
if (_commands.at(_activeCommand) != "") {
OsEng.scriptEngine()->runScript(_commands.at(_activeCommand));
//OsEng.scriptEngine()->runScript(_commands.at(_activeCommand));
OsEng.scriptEngine()->queueScript(_commands.at(_activeCommand));
if (!_commandsHistory.empty() &&
_commands.at(_activeCommand) != _commandsHistory.at(_commandsHistory.size() - 1))
_commandsHistory.push_back(_commands.at(_activeCommand));

View File

@@ -223,13 +223,13 @@ void OrbitalMouseController::scrollWheel(int pos) {
void OrbitalMouseController::update(const double& dt){
if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
//if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
_handler->orbit(
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed,
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed,
static_cast<float>(_middleMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonMiddle].x * _rotationSpeed,
static_cast<float>(_rightMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
}
//}
// if (_leftMouseButtonDown){
// _handler->orbit(static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed, static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed, 0.f);

File diff suppressed because it is too large Load Diff

View File

@@ -26,6 +26,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/syncbuffer.h>
#include <ghoul/lua/lua_helper.h>
#include <fstream>
@@ -605,6 +606,45 @@ bool ScriptEngine::writeDocumentation(const std::string& filename, const std::st
}
}
void ScriptEngine::serialize(SyncBuffer* syncBuffer){
syncBuffer->encode(_currentSyncedScript);
}
void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
syncBuffer->decode(_currentSyncedScript);
}
void ScriptEngine::postSynchronizationPreDraw(){
}
void ScriptEngine::preSynchronization(){
if (!_currentSyncedScript.empty()){
runScript(_currentSyncedScript);
_currentSyncedScript.clear();
}
_mutex.lock();
if (!_queuedScripts.empty()){
_currentSyncedScript = _queuedScripts.back();
_queuedScripts.pop_back();
}
_mutex.unlock();
}
void ScriptEngine::queueScript(const std::string &script){
if (script.empty())
return;
_mutex.lock();
_queuedScripts.insert(_queuedScripts.begin(), script);
_mutex.unlock();
}
} // namespace scripting
} // namespace openspace

View File

@@ -51,6 +51,9 @@ Camera::Camera()
, _sharedPosition()
, _sharedScaling(1.f, 0.f)
, _sharedViewRotationMatrix(1.f)
, _syncedPosition()
, _syncedScaling(1.f, 0.f)
, _syncedViewRotationMatrix(1.f)
, _focusPosition()
{
}
@@ -66,6 +69,11 @@ void Camera::setPosition(psc pos)
const psc& Camera::position() const
{
//return _localPosition;
return _syncedPosition;
}
const psc& Camera::unsynchedPosition() const{
return _localPosition;
}
@@ -119,7 +127,8 @@ void Camera::setViewRotationMatrix(glm::mat4 m) {
const glm::mat4& Camera::viewRotationMatrix() const
{
return _localViewRotationMatrix;
//return _localViewRotationMatrix;
return _syncedViewRotationMatrix;
}
void Camera::compileViewRotationMatrix()
@@ -129,6 +138,7 @@ void Camera::compileViewRotationMatrix()
// the camera matrix needs to be rotated inverse to the world
// _viewDirection = glm::rotate(glm::inverse(_viewRotation), _cameraDirection);
//_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz;
_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz;
_viewDirection = glm::normalize(_viewDirection);
}
@@ -194,7 +204,8 @@ void Camera::setScaling(glm::vec2 scaling)
const glm::vec2& Camera::scaling() const
{
return _localScaling;
//return _localScaling;
return _syncedScaling;
}
void Camera::setLookUpVector(glm::vec3 lookUp)
@@ -230,9 +241,9 @@ void Camera::deserialize(SyncBuffer* syncBuffer){
void Camera::postSynchronizationPreDraw(){
_syncMutex.lock();
_localViewRotationMatrix = _sharedViewRotationMatrix;
_localPosition = _sharedPosition;
_localScaling = _sharedScaling;
_syncedViewRotationMatrix = _sharedViewRotationMatrix;
_syncedPosition = _sharedPosition;
_syncedScaling = _sharedScaling;
_syncMutex.unlock();
}

View File

@@ -148,10 +148,13 @@ Time* Time::_instance = nullptr;
Time::Time()
: _time(-1.0)
, _dt(1.0)
, _timeJumped(false)
, _syncedTime(-1.0)
, _syncedDt(1.0)
, _syncedTimeJumped(false)
, _deltaTimePerSecond(1.0)
, _sharedTime(-1.0)
, _sharedDt(1.0)
, _deltaTimePerSecond(1.0)
, _timeJumped(false)
, _sharedTimeJumped(false)
{
}
@@ -184,7 +187,8 @@ void Time::setTime(double value) {
double Time::currentTime() const {
assert(_instance);
return _time;
//return _time;
return _syncedTime;
}
double Time::advanceTime(double tickTime) {
@@ -200,7 +204,8 @@ void Time::setDeltaTime(double deltaT) {
}
double Time::deltaTime() const {
return _dt;
//return _dt;
return _syncedDt;
}
void Time::setTime(std::string time) {
@@ -212,7 +217,8 @@ void Time::setTime(std::string time) {
std::string Time::currentTimeUTC() const {
std::string date;
SpiceManager::ref().getDateFromET(_time, date);
//SpiceManager::ref().getDateFromET(_time, date);
SpiceManager::ref().getDateFromET(_syncedTime, date);
return date;
}
@@ -239,9 +245,9 @@ void Time::deserialize(SyncBuffer* syncBuffer){
void Time::postSynchronizationPreDraw(){
_syncMutex.lock();
_time = _sharedTime;
_dt = _sharedDt;
_timeJumped = _sharedTimeJumped;
_syncedTime = _sharedTime;
_syncedDt = _sharedDt;
_syncedTimeJumped = _sharedTimeJumped;
_syncMutex.unlock();
}
@@ -257,7 +263,8 @@ void Time::preSynchronization(){
}
bool Time::timeJumped(){
return _timeJumped;
//return _timeJumped;
return _syncedTimeJumped;
}
void Time::setTimeJumped(bool jumped){