File: marker.cc

package info (click to toggle)
simutrans 100.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,776 kB
  • ctags: 9,485
  • sloc: cpp: 72,459; ansic: 5,646; makefile: 450
file content (86 lines) | stat: -rw-r--r-- 1,828 bytes parent folder | download
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
/*
 * Copyright (c) 1997 - 2001 Hansjrg Malthaner
 *
 * This file is part of the Simutrans project under the artistic licence.
 * (see licence.txt)
 *
 * Author: V. Meyer
 */

#include <string.h>
#include "../simtypes.h"
#include "../simdebug.h"
#include "../boden/grund.h"
#include "marker.h"

void marker_t::init(int welt_groesse_x,int welt_groesse_y)
{
	cached_groesse = welt_groesse_x;
	bits_groesse = (welt_groesse_x*welt_groesse_y + bit_mask) / (bit_unit);
	if(bits) {
		delete [] bits;
	}
	if(bits_groesse) {
		bits = new unsigned char[bits_groesse];
	}
	else {
		bits = NULL;
	}
	unmarkiere_alle();
}

marker_t::~marker_t()
{
	delete [] bits;
}

void marker_t::unmarkiere_alle()
{
	if(bits) {
		memset(bits, 0, bits_groesse);
	}
	more.clear();
}

void marker_t::markiere(const grund_t *gr)
{
	if(gr != NULL) {
		if(gr->gib_typ()<=grund_t::fundament) {
			// these types (boden, wasser, fundament) are always at ground level
			const int bit = gr->gib_pos().y*cached_groesse+gr->gib_pos().x;
			bits[bit/bit_unit] |= 1 << (bit & bit_mask);
		}
		else if(!more.contains(gr)) {
			more.insert(gr);
		}
	}
}

void marker_t::unmarkiere(const grund_t *gr)
{
	if(gr != NULL) {
		if(gr->gib_typ()<=grund_t::fundament) {
			// these types (boden, wasser, fundament) are always at ground level
			const int bit = gr->gib_pos().y*cached_groesse+gr->gib_pos().x;
			bits[bit/bit_unit] &= ~(1 << (bit & bit_mask));
		}
		else {
			more.remove(gr);
		}
	}
}

bool marker_t::ist_markiert(const grund_t *gr) const
{
	if(gr==NULL) {
		return false;
	}
	if(gr->gib_typ()<=grund_t::fundament) {
		// these types (boden, wasser, fundament) are always at ground level
		const int bit = gr->gib_pos().y*cached_groesse+gr->gib_pos().x;
		return (bits[bit/bit_unit] & (1 << (bit & bit_mask))) != 0;
	}
	else {
		return more.contains(gr);
	}
}