aboutsummaryrefslogtreecommitdiff
path: root/src/util/pointedthing.cpp
blob: cd13000b5302c71b40c1b3a5137cc5b320f28cf2 (plain)
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
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser 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 "pointedthing.h"

#include "serialize.h"
#include "../exceptions.h"
#include <sstream>

PointedThing::PointedThing():
	type(POINTEDTHING_NOTHING),
	node_undersurface(0,0,0),
	node_abovesurface(0,0,0),
	object_id(-1)
{}

std::string PointedThing::dump() const
{
	std::ostringstream os(std::ios::binary);
	if(type == POINTEDTHING_NOTHING)
	{
		os<<"[nothing]";
	}
	else if(type == POINTEDTHING_NODE)
	{
		const v3s16 &u = node_undersurface;
		const v3s16 &a = node_abovesurface;
		os<<"[node under="<<u.X<<","<<u.Y<<","<<u.Z
			<< " above="<<a.X<<","<<a.Y<<","<<a.Z<<"]";
	}
	else if(type == POINTEDTHING_OBJECT)
	{
		os<<"[object "<<object_id<<"]";
	}
	else
	{
		os<<"[unknown PointedThing]";
	}
	return os.str();
}

void PointedThing::serialize(std::ostream &os) const
{
	writeU8(os, 0); // version
	writeU8(os, (u8)type);
	if(type == POINTEDTHING_NOTHING)
	{
		// nothing
	}
	else if(type == POINTEDTHING_NODE)
	{
		writeV3S16(os, node_undersurface);
		writeV3S16(os, node_abovesurface);
	}
	else if(type == POINTEDTHING_OBJECT)
	{
		writeS16(os, object_id);
	}
}

void PointedThing::deSerialize(std::istream &is)
{
	int version = readU8(is);
	if(version != 0) throw SerializationError(
			"unsupported PointedThing version");
	type = (PointedThingType) readU8(is);
	if(type == POINTEDTHING_NOTHING)
	{
		// nothing
	}
	else if(type == POINTEDTHING_NODE)
	{
		node_undersurface = readV3S16(is);
		node_abovesurface = readV3S16(is);
	}
	else if(type == POINTEDTHING_OBJECT)
	{
		object_id = readS16(is);
	}
	else
	{
		throw SerializationError(
			"unsupported PointedThingType");
	}
}

bool PointedThing::operator==(const PointedThing &pt2) const
{
	if(type != pt2.type)
		return false;
	if(type == POINTEDTHING_NODE)
	{
		if(node_undersurface != pt2.node_undersurface)
			return false;
		if(node_abovesurface != pt2.node_abovesurface)
			return false;
	}
	else if(type == POINTEDTHING_OBJECT)
	{
		if(object_id != pt2.object_id)
			return false;
	}
	return true;
}

bool PointedThing::operator!=(const PointedThing &pt2) const
{
	return !(*this == pt2);
}

9730 vt 0.4833 0.9730 vt 0.5219 0.9855 vt 0.6097 0.9229 vt 0.6097 0.2971 vt 0.4678 0.2470 vt 0.4291 0.2345 vt 0.5219 0.2345 vt 0.4833 0.2470 vt 0.4833 0.2783 vt 0.4678 0.2783 vt 0.4132 0.2971 vt 0.4132 0.9229 vt 0.4678 0.9417 vt 0.4833 0.9417 vt 0.5182 0.9229 vt 0.5182 0.2971 vt 0.4328 0.2971 vt 0.4328 0.9229 vt 0.5026 0.9229 vt 0.5026 0.2971 vt 0.4485 0.2971 vt 0.4485 0.9229 vt 0.5026 0.2814 vt 0.4485 0.2814 vt 0.4485 0.9386 vt 0.5026 0.9386 vt 0.9588 0.9625 vt 0.8837 0.9625 vt 0.8837 0.0348 vt 0.9588 0.0348 vt 0.9901 0.9625 vt 0.9901 0.0348 vt 0.9588 0.0035 vt 0.8837 0.0035 vt 0.8524 0.0348 vt 0.8524 0.9625 vt 0.9588 0.9938 vt 0.8837 0.9938 vt 0.9588 0.9625 vt 0.8837 0.9625 vt 0.8837 0.0348 vt 0.9588 0.0348 vt 0.9901 0.9625 vt 0.9901 0.0348 vt 0.9588 0.0035 vt 0.8837 0.0035 vt 0.8524 0.0348 vt 0.8524 0.9625 vt 0.9588 0.9938 vt 0.8837 0.9938 vt 0.9588 0.9625 vt 0.8837 0.9625 vt 0.8837 0.0348 vt 0.9588 0.0348 vt 0.9901 0.9625 vt 0.9901 0.0348 vt 0.9588 0.0035 vt 0.8837 0.0035 vt 0.8524 0.0348 vt 0.8524 0.9625 vt 0.9588 0.9938 vt 0.8837 0.9938 vt 0.7427 0.1169 vt 0.6400 0.1169 vt 0.6400 0.3317 vt 0.7427 0.3317 vt 0.7427 0.4343 vt 0.8260 0.4343 vt 0.8260 0.3317 vt 0.8260 0.1169 vt 0.8260 0.0142 vt 0.7427 0.0142 vt 1.2064 -0.1190 vt -0.2978 -0.1190 vt -0.2978 -0.6179 vt 1.2064 -0.6179 vt -0.2924 0.9963 vt -0.2924 -0.0015 vt 1.2117 -0.0015 vt 1.2117 0.9963 vt 1.2064 0.9965 vt 1.6526 0.1041 vt -0.2978 0.9965 vt -0.7440 0.1041 vn -1.0000 0.0000 -0.0000 vn 0.0000 0.0000 -1.0000 vn -0.0000 0.0000 1.0000 vn 0.0000 0.8944 -0.4472 vn 1.0000 0.0000 0.0000 vn -0.2782 0.8591 -0.4296 vn 0.2782 0.8591 -0.4296 vn 0.1433 -0.8852 0.4426 vn -0.1433 -0.8852 0.4426 vn 0.0000 -0.8944 0.4472 vn 0.0000 -1.0000 0.0000 g dtrack_vst1_Cube.031_SlopeRailMaterial s off f 8/1/1 10/2/1 9/3/1 7/4/1 f 10/2/2 14/5/2 13/6/2 9/7/2 f 12/8/3 8/1/3 7/9/3 11/10/3 f 12/8/4 14/5/4 10/2/4 8/1/4 f 22/11/5 21/12/5 25/13/5 26/14/5 f 15/15/6 19/16/6 20/17/6 16/18/6 f 16/19/2 20/20/2 21/21/2 17/22/2 f 17/23/7 21/12/7 22/11/7 18/24/7 f 19/25/3 15/26/3 18/27/3 22/28/3 f 26/29/3 23/30/3 19/25/3 22/28/3 f 19/16/1 23/31/1 24/32/1 20/17/1 f 21/21/2 20/20/2 24/33/2 25/34/2 f 26/14/8 25/13/8 27/35/8 28/36/8 f 24/32/9 23/31/9 29/37/9 30/38/9 f 28/36/5 27/35/5 31/39/5 32/40/5 f 30/38/1 29/37/1 33/41/1 34/42/1 f 31/39/4 34/42/4 33/41/4 32/40/4 f 23/30/3 26/29/3 28/43/3 32/40/3 33/41/3 29/44/3 f 24/33/2 30/45/2 34/42/2 31/39/2 27/46/2 25/34/2 f 39/47/4 42/48/4 41/49/4 40/50/4 f 35/51/3 39/47/3 40/50/3 36/52/3 f 36/53/1 40/50/1 41/49/1 37/54/1 f 37/55/2 41/49/2 42/48/2 38/56/2 f 39/47/5 35/57/5 38/58/5 42/48/5 f 43/59/1 45/60/1 46/61/1 44/62/1 f 47/63/5 49/64/5 50/65/5 48/66/5 f 43/67/10 44/68/10 47/63/10 48/66/10 f 45/60/4 50/65/4 49/64/4 46/61/4 f 58/69/1 57/70/1 61/71/1 62/72/1 f 51/73/7 55/74/7 56/75/7 52/76/7 f 52/77/3 56/78/3 57/79/3 53/80/3 f 53/81/6 57/70/6 58/69/6 54/82/6 f 55/83/2 51/84/2 54/85/2 58/86/2 f 62/87/2 59/88/2 55/83/2 58/86/2 f 55/74/5 59/89/5 60/90/5 56/75/5 f 57/79/3 56/78/3 60/91/3 61/92/3 f 62/72/9 61/71/9 63/93/9 64/94/9 f 60/90/8 59/89/8 65/95/8 66/96/8 f 64/94/1 63/93/1 67/97/1 68/98/1 f 66/96/5 65/95/5 69/99/5 70/100/5 f 67/97/4 70/100/4 69/99/4 68/98/4 f 59/88/2 62/87/2 64/101/2 68/98/2 69/99/2 65/102/2 f 60/91/3 66/103/3 70/100/3 67/97/3 63/104/3 61/92/3 f 75/105/4 78/106/4 77/107/4 76/108/4 f 71/109/2 75/105/2 76/108/2 72/110/2 f 72/111/5 76/108/5 77/107/5 73/112/5 f 73/113/3 77/107/3 78/106/3 74/114/3 f 75/105/1 71/115/1 74/116/1 78/106/1 f 83/117/4 86/118/4 85/119/4 84/120/4 f 79/121/3 83/117/3 84/120/3 80/122/3 f 80/123/1 84/120/1 85/119/1 81/124/1 f 81/125/2 85/119/2 86/118/2 82/126/2 f 83/117/5 79/127/5 82/128/5 86/118/5 f 91/129/4 94/130/4 93/131/4 92/132/4 f 87/133/2 91/129/2 92/132/2 88/134/2 f 88/135/5 92/132/5 93/131/5 89/136/5 f 89/137/3 93/131/3 94/130/3 90/138/3 f 91/129/1 87/139/1 90/140/1 94/130/1 f 96/141/5 95/142/5 97/143/5 98/144/5 f 98/144/2 97/145/2 101/146/2 102/147/2 f 100/148/3 99/149/3 95/150/3 96/141/3 f 100/148/4 96/141/4 98/144/4 102/147/4 g dtrack_vst1_Cube.031_SlopeGravelMaterial f 3/151/3 6/152/3 5/153/3 2/154/3 f 1/155/11 2/156/11 5/157/11 4/158/11 f 1/159/5 3/151/5 2/160/5 f 6/152/1 4/161/1 5/162/1 f 4/161/4 6/152/4 3/151/4 1/159/4