Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / traffic_navigation / intersectData.c @ 1927

History | View | Annotate | Download (2.33 KB)

1
#include "intersectData.h"
2
#include "lineDrive.h"
3

    
4
/*
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
        
15
        insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
16
        insertNode(1, ROAD_NODE, ROAD, ROAD_DOUBLE);
17
        insertNode(2, ROAD_NODE, ROAD, ROAD_DOUBLE);
18
        insertNode(3, ROAD_NODE, ROAD, ROAD_DOUBLE);
19
        insertNode(4, ROAD_NODE, ROAD, ROAD_DOUBLE);
20
        return;
21
}
22

    
23
/*
24
 * This function serves to make the code for the intersection database
25
 * as reuseable as possible. This part creates the implementation of the
26
 * database that can be copied over for all projects.  
27
 *
28
 */
29

    
30

    
31
// Does nothing if your indmax is out of bounds.
32
void insertNode(int key, int featureid, int node_type, int node_info){
33
//        if (key < sizeof(IntersectData)/sizeof(int))
34
        if(key < NUM_FEATURES)
35
          NodeData[key] = (featureid<<12) + (node_type<<2) + node_info;
36
        return;
37
}
38

    
39
void insertIntersection(int key, int node_type, int intersection_position){
40
        if(key < NUM_FEATURES)
41
           NodeData[key] = (INTERSECTION_NODE<<12) + (node_type<<2)
42
               + intersection_position;
43
        return;
44
}
45

    
46
void insertRoad(int key, int node_type, int road_type){
47
        if(key < NUM_FEATURES)
48
           NodeData[key] = (ROAD_NODE<<12) + (node_type<<2) + road_type;
49
        return;
50
}
51

    
52
// Functions to get data from the Database:
53
//@TODO:Add some checks to make sure the key is less than NUM_FEATURES
54
//        also: figure out what to do when this happens.
55
//        Add checks to see if we call getIntersect...() on intersections
56
//        and getRoad...() on roads.
57

    
58
int getFeatureId(int key)
59
{
60
        if(key < NUM_FEATURES)
61
          return (NodeData[key]>>12)&15;
62
        else return -1;
63
}
64

    
65
int getIntersectType(int key){
66
        if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
67
          return (NodeData[key]>>2)&3;
68
        else return -1;
69
}
70

    
71
int getIntersectPos(int key){
72
        if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
73
          return (NodeData[key])&3;
74
        else return -1;
75
}
76

    
77
int getRoadType(int key){
78
        if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
79
          return (NodeData[key]>>2)&3;
80
        else return -1;
81
}
82

    
83
int getRoadInfo(int key){
84
        if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
85
          return (NodeData[key])&3;
86
        else return -1;
87
}
88