forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Environment.cpp
160 lines (150 loc) · 6.11 KB
/
Environment.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "Environment.h"
#include "ParserX.h"
#include "FileBuffer.h"
#include "ReadFile.h"
#include "Game.h"
#include <QDebug>
#include <QFile>
#include "GLUU.h"
Environment::Environment(QString path) {
loaded = false;
texturePath = Game::root + "/routes/" + Game::route + "/envfiles/textures/";
qDebug() << "Wczytywanie pliku env: " << path;
QString sh;
path.replace("//", "/");
qDebug() << path;
QFile file(path);
if (!file.open(QIODevice::ReadOnly))
return;
FileBuffer* data = ReadFile::read(&file);
data->toUtf16();
data->skipBOM();
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "simisa@@@@@@@@@@jinx0w0t______") {
continue;
}
if (sh == "include") {
QString incPath = ParserX::GetStringInside(data);
ParserX::SkipToken(data);
data->insertFile(path + "/" + incPath);
continue;
}
if (sh == "world") {
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "include") {
QString incPath = ParserX::GetStringInside(data);
ParserX::SkipToken(data);
data->insertFile(path + "/" + incPath);
continue;
}
if (sh == "world_water") {
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "world_water_layers") {
waterCount = ParserX::GetNumber(data);
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "world_water_layer") {
water.push_back(WaterLayer());
loadWaterLayer(data);
//traffic->service.emplace_back();
//traffic->service.back().load(data);
ParserX::SkipToken(data);
continue;
}
ParserX::SkipToken(data);
continue;
}
ParserX::SkipToken(data);
continue;
}
qDebug() << "#world_water_layers - undefined token: " << sh;
ParserX::SkipToken(data);
}
ParserX::SkipToken(data);
continue;
}
qDebug() << "#world - undefined token: " << sh;
ParserX::SkipToken(data);
}
ParserX::SkipToken(data);
continue;
}
qDebug() << "#ENV - undefined token: " << sh;
ParserX::SkipToken(data);
}
delete data;
loaded = 1;
qDebug() << water.size();
for(int i = 0; i < water.size(); i++){
qDebug() << water[i].height;
qDebug() << water[i].tex;
}
return;
}
void Environment::loadWaterLayer(FileBuffer* data){
QString sh;
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "world_water_layer_height") {
water.back().height = ParserX::GetNumber(data);
ParserX::SkipToken(data);
continue;
}
if (sh == "world_anim_shader") {
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "world_shader") {
ParserX::GetString(data);
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "terrain_texslots") {
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "terrain_texslot") {
water.back().tex = texturePath + ParserX::GetString(data).toLower();
ParserX::SkipToken(data);
continue;
}
qDebug() << "#terrain_texslots - undefined token: " << sh;
ParserX::SkipToken(data);
}
ParserX::SkipToken(data);
continue;
}
if (sh == "terrain_uvcalc") {
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == "terrain_uvcalc") {
ParserX::SkipToken(data);
continue;
}
qDebug() << "#terrain_uvcalc - undefined token: " << sh;
ParserX::SkipToken(data);
}
ParserX::SkipToken(data);
continue;
}
qDebug() << "#world_anim_shader - undefined token: " << sh;
ParserX::SkipToken(data);
}
ParserX::SkipToken(data);
continue;
}
qDebug() << "#world_anim_shader - undefined token: " << sh;
ParserX::SkipToken(data);
}
ParserX::SkipToken(data);
continue;
}
qDebug() << "#world_water_layer - undefined token: " << sh;
ParserX::SkipToken(data);
continue;
}
}
Environment::~Environment() {
}
void Environment::renderWater(){
}