Revision 1958
Added more functionality to database for mapping things.
intersectData.c | ||
---|---|---|
3 | 3 |
|
4 | 4 |
/* |
5 | 5 |
* This function serves to make the code for the intersection database |
6 |
* as reuseable as possible. This part initializes the data and is the |
|
7 |
* only one that needs to be rewritten for each map. |
|
8 |
* |
|
9 |
*/ |
|
10 |
|
|
11 |
void initializeData(){ |
|
12 |
//insert all intersections that are in the map. |
|
13 |
//THIS DATA FOR THE DEMO MAP |
|
14 |
insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE); |
|
15 |
insertNode(1, ROAD_NODE, ROAD, ROAD_SINGLE); |
|
16 |
insertNode(2, INTERSECTION_NODE, DOUBLE_C, TMIDDLE); |
|
17 |
insertNode(4,ROAD_NODE,ROAD,HIGHWAY); |
|
18 |
insertNode(5,INTERSECTION_NODE,DOUBLE_C,TMIDDLE); |
|
19 |
insertNode(8,ROAD_NODE,ROAD,ROAD_SINGLE); |
|
20 |
insertNode(10,ROAD_NODE,ROAD,ROAD_SINGLE); |
|
21 |
insertNode(16,INTERSECTION_NODE,DOUBLE_C, TMIDDLE); |
|
22 |
return; |
|
23 |
} |
|
24 |
|
|
25 |
/* |
|
26 |
* This function serves to make the code for the intersection database |
|
27 | 6 |
* as reuseable as possible. This part creates the implementation of the |
28 | 7 |
* database that can be copied over for all projects. |
29 | 8 |
* |
30 | 9 |
*/ |
31 | 10 |
|
32 |
|
|
33 | 11 |
// Does nothing if your indmax is out of bounds. |
34 |
void insertNode(int key, int featureid, int node_type, int node_info){ |
|
35 |
// if (key < sizeof(IntersectData)/sizeof(int)) |
|
12 |
void insertNode(int key, int featureid, int intersect_num, int node_type, int node_info){ |
|
36 | 13 |
if(key < NUM_FEATURES) |
37 |
NodeData[key] = (featureid<<12) + (node_type<<2) + node_info; |
|
14 |
NodeData[key] = (featureid<<12) + (intersect_num<<5) + (node_type<<2) + node_info;
|
|
38 | 15 |
return; |
39 | 16 |
} |
40 | 17 |
|
41 |
void insertIntersection(int key, int node_type, int intersection_position){ |
|
18 |
void insertIntersection(int key, int intersect_num, int node_type, int intersection_position){
|
|
42 | 19 |
if(key < NUM_FEATURES) |
43 |
NodeData[key] = (INTERSECTION_NODE<<12) + (node_type<<2) |
|
20 |
NodeData[key] = (INTERSECTION_NODE<<12) + (intersect_num<<5) + (node_type<<2)
|
|
44 | 21 |
+ intersection_position; |
45 | 22 |
return; |
46 | 23 |
} |
47 | 24 |
|
48 |
void insertRoad(int key, int node_type, int road_type){ |
|
25 |
void insertRoad(int key, int intersect_num, int node_type, int road_type){
|
|
49 | 26 |
if(key < NUM_FEATURES) |
50 |
NodeData[key] = (ROAD_NODE<<12) + (node_type<<2) + road_type; |
|
27 |
NodeData[key] = (ROAD_NODE<<12) + (intersect_num<<5) + (node_type<<2) + road_type;
|
|
51 | 28 |
return; |
52 | 29 |
} |
53 | 30 |
|
31 |
/* |
|
32 |
* This function serves to make the code for the intersection database |
|
33 |
* as reuseable as possible. This part initializes the data and is the |
|
34 |
* only one that needs to be rewritten for ech map. |
|
35 |
* |
|
36 |
*/ |
|
37 |
/**********************************************************************NEEDS TO BE FIXED*/ |
|
38 |
void initializeData(){ |
|
39 |
//insert all intersections that are in the map. |
|
40 |
//THIS DATA FOR THE DEMO MAP |
|
41 |
/* insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE); |
|
42 |
insertNode(1, ROAD_NODE, ROAD, ROAD_SINGLE); |
|
43 |
insertNode(2, INTERSECTION_NODE, DOUBLE_C, TMIDDLE); |
|
44 |
insertNode(4,ROAD_NODE,ROAD,HIGHWAY); |
|
45 |
insertNode(5,INTERSECTION_NODE,DOUBLE_C,TMIDDLE); |
|
46 |
insertNode(8,ROAD_NODE,ROAD,ROAD_SINGLE); |
|
47 |
insertNode(10,ROAD_NODE,ROAD,ROAD_SINGLE); |
|
48 |
insertNode(16,INTERSECTION_NODE,DOUBLE_C, TMIDDLE); |
|
49 |
*/ return; |
|
50 |
} |
|
51 |
|
|
54 | 52 |
// Functions to get data from the Database: |
55 |
//@TODO:Add some checks to make sure the key is less than NUM_FEATURES |
|
56 |
// also: figure out what to do when this happens. |
|
57 |
// Add checks to see if we call getIntersect...() on intersections |
|
58 |
// and getRoad...() on roads. |
|
59 | 53 |
|
60 | 54 |
int getFeatureId(int key) |
61 | 55 |
{ |
... | ... | |
66 | 60 |
|
67 | 61 |
int getIntersectType(int key){ |
68 | 62 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE) |
69 |
return (NodeData[key]>>2)&3;
|
|
63 |
return (NodeData[key]>>2)&7;
|
|
70 | 64 |
else return -1; |
71 | 65 |
} |
72 | 66 |
|
73 | 67 |
int getIntersectPos(int key){ |
74 | 68 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE) |
75 |
return (NodeData[key])&3;
|
|
69 |
return (NodeData[key])&3;
|
|
76 | 70 |
else return -1; |
77 | 71 |
} |
78 | 72 |
|
79 | 73 |
int getRoadType(int key){ |
80 | 74 |
if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE) |
81 |
return (NodeData[key]>>2)&3;
|
|
75 |
return (NodeData[key]>>2)&7;
|
|
82 | 76 |
else return -1; |
83 | 77 |
} |
84 | 78 |
|
85 | 79 |
int getRoadInfo(int key){ |
86 | 80 |
if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE) |
87 |
return (NodeData[key])&3;
|
|
81 |
return (NodeData[key])&3;
|
|
88 | 82 |
else return -1; |
89 | 83 |
} |
90 | 84 |
|
85 |
int getIntersectNum(int key){ |
|
86 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE) |
|
87 |
return (NodeData[key]>>5)&127; |
|
88 |
else return -1; |
|
89 |
} |
Also available in: Unified diff