File: signpost.cpp

package info (click to toggle)
powder 117-2
  • links: PTS
  • area: non-free
  • in suites: stretch
  • size: 10,576 kB
  • ctags: 3,545
  • sloc: cpp: 55,002; makefile: 541; sh: 258; objc: 245; ansic: 107; csh: 54
file content (126 lines) | stat: -rw-r--r-- 1,996 bytes parent folder | download | duplicates (7)
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
/*
 * PROPRIETARY INFORMATION.  This software is proprietary to POWDER
 * Development, and is not to be reproduced, transmitted, or disclosed
 * in any way without written permission.
 *
 * Produced by:	Jeff Lait
 *
 *      	POWDER Development
 *
 * NAME:        signpost.cpp ( POWDER Library, C++ )
 *
 * COMMENTS:
 *	Tracks signposts and their values.  Creates a heap of signposts
 *	which can be queried to get a sign at a position.  O(N) to
 *	access so be wary!
 */

#include "signpost.h"
#include "sramstream.h"

void
SIGNPOSTDATA::init(SIGNPOST_NAMES sign, int x, int y)
{
    myPos = y & 31;
    myPos <<= 5;
    myPos |= x & 31;
    mySign = sign;
}

bool
SIGNPOSTDATA::isPos(int x, int y) const
{
    int		x1, y1;
    getPos(x1, y1);
    return (x1 == x) && (y1 == y);
}

void
SIGNPOSTDATA::getPos(int &x, int &y) const
{
    x = myPos & 31;
    y = myPos >> 5;
}

SIGNPOST_NAMES
SIGNPOSTDATA::getSign() const
{
    return (SIGNPOST_NAMES) mySign;
}

void
SIGNPOSTDATA::save(SRAMSTREAM &os) const
{
    int		collapse;

    collapse = mySign << 10 | myPos;
    os.write(collapse, 16);
}

void
SIGNPOSTDATA::load(SRAMSTREAM &is)
{
    int		val;

    is.uread(val, 16);
    myPos= val & 1023;
    mySign= val >> 10;
}

SIGNLIST::SIGNLIST()
{
}

SIGNLIST::~SIGNLIST()
{
}

SIGNPOST_NAMES
SIGNLIST::find(int x, int y) const
{
    int		i;

    for (i = 0; i < myPosts.entries(); i++)
    {
	if (myPosts(i).isPos(x, y))
	    return myPosts(i).getSign();
    }
    return SIGNPOST_NONE;
}

void
SIGNLIST::append(SIGNPOST_NAMES sign, int x, int y)
{
    SIGNPOSTDATA post;

    post.init(sign, x, y);
    myPosts.append(post);
}

void
SIGNLIST::save(SRAMSTREAM &os) const
{
    int		i;

    os.write(myPosts.entries(), 8);
    for (i = 0; i < myPosts.entries(); i++)
    {
	myPosts(i).save(os);
    }
}

void
SIGNLIST::load(SRAMSTREAM &is)
{
    int		i;
    int		val;

    is.uread(val, 8);
    for (i = 0; i < val; i++)
    {
	SIGNPOSTDATA	post;
	post.load(is);

	myPosts.append(post);
    }
}