-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojectio.cpp
110 lines (92 loc) · 2.81 KB
/
projectio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Atlas - Volumetric terrain editor
* Copyright (C) 2012-2015 Ondřej Záruba
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "projectio.h"
#include <QOpenGLContext>
ProjectIO::ProjectIO()
{
context=NULL;
surface=NULL;
connect(&io,SIGNAL(loadProgress(QString,int)),this,SIGNAL(loadProgress(QString,int)));
}
ProjectIO::~ProjectIO()
{
// thread.join();
delete context;
delete surface;
}
void ProjectIO::init(QOpenGLContext *shared_context)
{
//must be in main thread for Windows
if(surface==NULL)
{
surface=new QOffscreenSurface;
surface->create();
surface->moveToThread(this);
}
if(context==NULL)
{
context=new QOpenGLContext;
context->setShareContext(shared_context);
context->create();
context->moveToThread(this);
}
}
bool ProjectIO::create(WorldGraphics *world, const QString &path, const QString &name, const QString &author, int width, int height, int depth)
{
bool success=io.create(world, path.toStdString(), name.toStdString(), author.toStdString(), width, height, depth);
emit completed(success);
return success;
}
bool ProjectIO::save(WorldGraphics *world, const QString &file_path)
{
return io.save(world,file_path.toStdString());
}
int ProjectIO::completed()
{
return io.completed();
}
bool ProjectIO::load(WorldGraphics *world, const QString &file_path)
{
bool success = io.load(world,file_path.toStdString());
emit completed(success);
return success;
}
bool ProjectIO::load(WorldBase *world, const QString &file_path)
{
bool success= io.load(world,file_path.toStdString());
//emit onCompleted(succeess);
return success;
}
void ProjectIO::loadThread(WorldGraphics *world, const QString &file_path, QOpenGLContext *shared_context)
{
this->world=world;
this->file_path=file_path;
this->shared_context=shared_context;
init(shared_context);
start();
}
WorldIO *ProjectIO::worldIO()
{
return &io;
}
void ProjectIO::run()
{
context->makeCurrent(surface);
bool success=io.load(world,file_path.toStdString());
context->doneCurrent();
emit completed(success);
}