remove concept of settings object from library
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'./main.cpp',
|
||||
'./settings.cpp',
|
||||
'./settings.hpp',
|
||||
'../common/settings_json.cpp',
|
||||
'../common/settings_json.hpp',
|
||||
'../common/glfw_view.hpp',
|
||||
'../common/glfw_view.cpp',
|
||||
'../common/curl_request.cpp',
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
#include <signal.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "settings.hpp"
|
||||
#include "../common/settings_json.hpp"
|
||||
#include "../common/glfw_view.hpp"
|
||||
|
||||
MapView *mapView = nullptr;
|
||||
GLFWView *view = nullptr;
|
||||
|
||||
void quit_handler(int) {
|
||||
if (mapView) {
|
||||
if (view) {
|
||||
fprintf(stderr, "waiting for quit...\n");
|
||||
glfwSetWindowShouldClose(mapView->window, true);
|
||||
glfwSetWindowShouldClose(view->window, true);
|
||||
glfwPostEmptyEvent();
|
||||
} else {
|
||||
exit(0);
|
||||
@@ -40,13 +40,22 @@ int main(int argc, char *argv[]) {
|
||||
sigIntHandler.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
|
||||
// main loop
|
||||
view = new GLFWView();
|
||||
llmr::Map map(*view);
|
||||
|
||||
// Load settings
|
||||
llmr::Settings_JSON settings;
|
||||
mapView = new MapView(settings, fullscreen_flag);
|
||||
mapView->init();
|
||||
int ret = mapView->run();
|
||||
mapView->settings.sync();
|
||||
delete mapView;
|
||||
map.setLonLatZoom(settings.longitude, settings.latitude, settings.zoom);
|
||||
map.setAngle(settings.angle);
|
||||
map.setDebug(settings.debug);
|
||||
|
||||
int ret = view->run();
|
||||
|
||||
// Save settings
|
||||
map.getLonLatZoom(settings.longitude, settings.latitude, settings.zoom);
|
||||
settings.angle = map.getAngle();
|
||||
settings.debug = map.getDebug();
|
||||
settings.save();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#include "settings.hpp"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "rapidjson/filestream.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
Settings_JSON::Settings_JSON()
|
||||
{
|
||||
}
|
||||
|
||||
void Settings_JSON::load()
|
||||
{
|
||||
FILE *settingsFile = fopen("/tmp/llmr-native.json", "r");
|
||||
if (settingsFile != NULL) {
|
||||
rapidjson::FileStream is(settingsFile);
|
||||
rapidjson::Document document;
|
||||
document.ParseStream<0>(is);
|
||||
if (document.IsArray()) {
|
||||
longitude = document[rapidjson::SizeType(0)].GetDouble();
|
||||
latitude = document[1].GetDouble();
|
||||
scale = document[2].GetDouble();
|
||||
angle = document[3].GetDouble();
|
||||
debug = document[4].GetBool();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Settings_JSON::persist()
|
||||
{
|
||||
}
|
||||
|
||||
void Settings_JSON::sync()
|
||||
{
|
||||
|
||||
rapidjson::FileStream s(fopen("/tmp/llmr-native.json", "w"));
|
||||
rapidjson::PrettyWriter<rapidjson::FileStream> writer(s);
|
||||
writer.StartArray();
|
||||
writer.Double(longitude);
|
||||
writer.Double(latitude);
|
||||
writer.Double(scale);
|
||||
writer.Double(angle);
|
||||
writer.Bool(debug);
|
||||
writer.EndArray();
|
||||
}
|
||||
|
||||
void Settings_JSON::clear()
|
||||
{
|
||||
longitude = 0;
|
||||
latitude = 0;
|
||||
scale = 0;
|
||||
angle = 0;
|
||||
debug = false;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef LLMR_JSON_SETTINGS
|
||||
#define LLMR_JSON_SETTINGS
|
||||
|
||||
#include <llmr/map/settings.hpp>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class Settings_JSON : public Settings {
|
||||
public:
|
||||
Settings_JSON();
|
||||
virtual void load();
|
||||
virtual void persist();
|
||||
virtual void sync();
|
||||
virtual void clear();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user