summaryrefslogtreecommitdiffstats
path: root/src/cells.h
blob: c8c739c7a228e3ac7fa22ab5e383fcdae26ccd63 (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
/***************************************************************************
 *   Copyright (C) 2003-2004 by David Saxton                               *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef CELLS_H
#define CELLS_H

#include <map>

class Point
{
public:
	Point();
	
	short x;
	short y;
	short prevX;
	short prevY;
};

// Key = cell, data = previous cell, compare = score
typedef std::multimap< unsigned short, Point > TempLabelMap;

// Used for mapping out connections
const int cellSize = 8;
class Cell
{
public:
	Cell();
	/**
	 * Resets bestScore, prevX, prevY, addedToLabels, it, permanent for each cell
	 */
	void reset();
	
	unsigned short CIpenalty; // 'Penalty' of using the cell from CNItem
	unsigned short Cpenalty; // 'Penalty' of using the cell from Connector
	unsigned short bestScore; // Best (lowest) score so far, _the_ best if it is permanent
	short prevX, prevY; // Which cell this came from, (-1,-1) if originating cell
	bool permanent:1; // Whether the score can be improved on
	bool addedToLabels:1; // Whether the cell has already been added to the list of cells to check
	Point *point; // Pointer to the point in the TempLabelMap
	unsigned short numCon; // Number of connectors through that point
};


/**
@author David Saxton
*/

typedef unsigned int uint;

class Cells
{
public:
        Cells( const uint w, const uint h );
	~Cells();
	/**
	 * Resets bestScore, prevX, prevY, addedToLabels, it, permanent for each cell
	 */
	void reset();

	inline Cell* operator[] ( const uint x ) const
	{
		if ( x<m_w ) return m_cells[x];
		return 0l;
	}
	
	const uint width() const { return m_w; }
	const uint height() const { return m_h; }
	
	const Cell &cell( const uint x, const uint y ) const { return m_cells[x][y]; }
	
private:
	Cells( const Cells & );
	Cells & operator= ( const Cells & );
	void init( const uint w, const uint h );
	
	uint m_w;
	uint m_h;
	
	Cell **m_cells;
};

#endif