File: map2.cc

package info (click to toggle)
enemylines7 0.6-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,640 kB
  • sloc: cpp: 21,756; makefile: 24
file content (198 lines) | stat: -rw-r--r-- 4,208 bytes parent folder | download | duplicates (5)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "SDL.h"
#include "SDL_opengl.h"

#include "map2.h"
#include "cube.h"
#include <time.h>

#include "painter3.h"
#include "painter6.h"
#include "debugger.h"
#include "collider.h"
#include "selector2.h"
#include "destructor.h"
#include "merger.h"
#include "cacher.h"
#include "random.h"

#include "tweak/tweak.h"

#include <sstream>
namespace block {


void Map2::init(std::string name) {
	load(name);
}

std::string path="";
void Map2::set_path(std::string s) {
	path=s;
	std::cout << "setpath " << s << "  " << path << std::endl;
}

void Map2::select(unsigned int x,unsigned int y,int button) {
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	float scale=Tweak::blockscale_f();
	glScalef(scale,scale,scale);

	Selector2 selector;
	selector.select(&block,x,y);

	glPopMatrix();

	selected=selector.get_result();

	if (button==3) {
		int level=Tweak::debug_select_level_i();
		while (selected.top().level_>level&&selected.empty()==false) {
			selected.pop();
		}
	}
	if (!selected.empty()) {
		C3f p=selected.top().get_pos();
		std::cout << "selected: " << p << "  level " << selected.top().level_ << "  " << selected.get_current() << "    " << (int)selected.get_current()->get_material() << std::endl;
	}
}




void Map2::debug() {
	std::cout << std::endl;
	std::cout << "debug " << &block << "  " << selected.top().get_current() << std::endl;
	Debugger::debug(&block,selected.top().get_current(),Tweak::draw_all_i()==1);
}

void Map2::draw() {
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_NORMALIZE);

	glPushMatrix();
	float scale=Tweak::blockscale_f();
	glScalef(scale,scale,scale);

	if (Tweak::debugdraw_i()) {
		Painter3::paint(&block,selected.top().get_current(),Tweak::draw_all_i()==1);
	} else {
		Painter6::paint(&block);
	}

	glPopMatrix();
	glDisable(GL_COLOR_MATERIAL);
}


bool Map2::does_collide(C3f p,float size) {
	return Collider::collide(&block,p,size);
}

unsigned int Map2::destroy(C3f p,float radius) {
	Destructor d;
	d.destruct(&block,p,radius);
	return d.result();
}

void Map2::set_material() {
	if (Tweak::editmode_i()!=1) return;
	int m;
	m=Tweak::material_current_i();

	Block *sel;
	sel=selected.get_current();
	if (!sel) return;
	sel->set_material(static_cast<E_Material>(m));
}

void Map2::cycle_material() {
	if (Tweak::editmode_i()!=1) return;
	E_Material mat;
	Block *sel;
	sel=selected.get_current();
	if (!sel) return;
	sel->toggle();

	mat=sel->get_material();

	unsigned int i=static_cast<unsigned int>(mat);
	i++;
	if (i<static_cast<unsigned int>(M_DEFAULT)) { 
		i=static_cast<unsigned int>(M_DEFAULT);
	}
	if (i>=static_cast<unsigned int>(M_LASTNORMAL)) { 
		i=static_cast<unsigned int>(M_DEFAULT);
	}
	std::cout << "cycle: " << (int)mat << "  " << i << std::endl;
	sel->set_material(static_cast<E_Material>(i));
}

void Map2::toggle_selected() {
	if (Tweak::editmode_i()!=1) return;
	Block *sel;
	sel=selected.get_current();
	if (!sel) return;
	sel->toggle();
}
void Map2::split_selected() {
	if (Tweak::editmode_i()!=1) return;
	Block *sel;
	sel=selected.get_current();
	if (!sel) return;
	sel->split();
}
void Map2::merge_selected() {
	if (Tweak::editmode_i()!=1) return;
	selected.pop();
	Block *sel;
	sel=selected.get_current();
	if (!sel) return;
	sel->merge();
}

void Map2::select_parent() {
	if (Tweak::editmode_i()!=1) return;
	selected.pop();
}




void Map2::check() {
	Merger::merge(&block);
}



void Map2::load(std::string name) {
	if (!block.top_load(path+name)) {
		std::cout << "error " << path <<" " << name << std::endl;
	}
	std::cout << " loaded " << name << std::endl;
	Cacher c;
	c.cache(&block,3);
}
void Map2::save() {
	std::ostringstream str;
	str << "backup/save_" << time(NULL);
	if (!block.top_save("save")) { std::cout << "error " << std::endl; }
	if (!block.top_save(str.str())) { std::cout << "error " << std::endl; }
	std::cout << " saved " << std::endl;
}


void Map2::copy() {
	std::ostringstream sstr;
	selected.top().get_current()->save(sstr);
	copystring=sstr.str();
	std::cout << "copy: " << copystring << std::endl;
}

void Map2::paste() {
	std::istringstream sstr;
	sstr.str(copystring);
	selected.top().get_current()->load(sstr);
	std::cout << "paste: " << copystring << std::endl;
}
} //namespace