-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot5.cpp
116 lines (94 loc) · 3.26 KB
/
robot5.cpp
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
/***************************************************************************
file : robot5.cpp
created : 22 June 2023 10:04:10 AM IST
copyright : (C) 2002 ashish
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <tgf.h>
#include <track.h>
#include <car.h>
#include <raceman.h>
#include <robottools.h>
#include <robot.h>
#include "driver.h"
static Driver *driver;
static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s);
static void newrace(int index, tCarElt* car, tSituation *s);
static void drive(int index, tCarElt* car, tSituation *s);
static void endrace(int index, tCarElt *car, tSituation *s);
static void shutdown(int index);
static int InitFuncPt(int index, void *pt);
/*
* Module entry point
*/
extern "C" int
robot5(tModInfo *modInfo)
{
memset(modInfo, 0, 10*sizeof(tModInfo));
modInfo->name = strdup("robot5"); /* name of the module (short) */
modInfo->desc = strdup(""); /* description of the module (can be long) */
modInfo->fctInit = InitFuncPt; /* init function */
modInfo->gfId = ROB_IDENT; /* supported framework version */
modInfo->index = 1;
return 0;
}
/* Module interface initialization. */
static int
InitFuncPt(int index, void *pt)
{
tRobotItf *itf = (tRobotItf *)pt;
driver = new Driver(index);
itf->rbNewTrack = initTrack; /* Give the robot the track view called */
/* for every track change or new race */
itf->rbNewRace = newrace; /* Start a new race */
itf->rbDrive = drive; /* Drive during race */
itf->rbPitCmd = NULL;
itf->rbEndRace = endrace; /* End of the current race */
itf->rbShutdown = shutdown; /* Called before the module is unloaded */
itf->index = index; /* Index used if multiple interfaces */
return 0;
}
/* Called for every track change or new race. */
static void
initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s)
{
driver->initTrack(track, carHandle, carParmHandle, s);
}
/* Start a new race. */
static void
newrace(int index, tCarElt* car, tSituation *s)
{
driver->newRace(car, s);
}
/* Drive during race. */
static void
drive(int index, tCarElt* car, tSituation *s)
{
driver->drive(car, s);
}
/* End of the current race */
static void
endrace(int index, tCarElt *car, tSituation *s)
{
driver->endRace(car, s);
}
/* Called before the module is unloaded */
static void
shutdown(int index)
{
delete driver;
}