File: sfm.c

package info (click to toggle)
searchandrescue 0.8.2-10
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,656 kB
  • ctags: 6,111
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 80
file content (133 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download | duplicates (6)
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
127
128
129
130
131
132
133
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

#include "sfm.h"


SFMRealmStruct *SFMInit(int argc, char **argv);
void SFMShutdown(SFMRealmStruct *realm);

void SFMSetTiming(SFMRealmStruct *realm, SFMTime lapsed_ms);
void SFMSetTimeCompression(SFMRealmStruct *realm, double compression);
void SFMUpdateRealm(SFMRealmStruct *realm, SFMTime lapsed_ms);


/*
 *	Creates a new FDM Realm.
 */
SFMRealmStruct *SFMInit(int argc, char **argv)
{
	SFMRealmStruct *realm = SFM_REALM(calloc(
	    1, sizeof(SFMRealmStruct)
	));
	if(realm == NULL)
	    return(NULL);

	/* Reset values */
	realm->lapsed_time = 0l;
	realm->time_compensation = 1.0;
	realm->time_compression = 1.0;

	realm->gravity = SFMDefaultGravity;

	realm->airborne_cb_client_data = NULL;
	realm->airborne_cb = NULL;

	realm->touch_down_cb_client_data = NULL;
	realm->touch_down_cb = NULL;

	realm->collision_cb_client_data = NULL;
	realm->collision_cb = NULL;

	realm->model = NULL;
	realm->total_models = 0;

	return(realm);
}

/*
 *	Deletes the FDM Realm.
 */
void SFMShutdown(SFMRealmStruct *realm)
{
	if(realm == NULL)
	    return;

	/* Delete all FDMs */
	while(realm->total_models > 0)
	{
	    if(realm->model[0] == NULL)
		break;

	    /* Delete this SFMModel, this will also call the
	     * destroy_model_cb on the Realm if it is set.
	     *
	     * Note that each call to this function will
	     * deincrement realm->total_models by one
	     */
	    SFMModelDelete(realm, realm->model[0]);
	}

	free(realm);
}

/*
 *	Sets the FDM Realm's timing.
 *
 *	Future calls to SFM*() functions will use the timing values
 *	set here.
 */
void SFMSetTiming(SFMRealmStruct *realm, SFMTime lapsed_ms)
{
	if(realm == NULL)
	    return;

	if(lapsed_ms < 0l)
	    lapsed_ms = 0l;

	/* Update timings */
	realm->lapsed_time = lapsed_ms;
	realm->time_compensation = (double)(
	    (double)lapsed_ms / (double)SFMCycleUnitsMS
	);
}

/*
 *	Sets the FDM Realm's time compression.
 */
void SFMSetTimeCompression(SFMRealmStruct *realm, double compression)
{
	if(realm == NULL)
	    return;

	if(compression < 0.0)
	    compression = 0.0;

	realm->time_compression = compression;
}

/*
 *	Updates the FDM Realm's FDMs and timing.
 */
void SFMUpdateRealm(SFMRealmStruct *realm, SFMTime lapsed_ms)
{
	int m_num;
	SFMModelStruct *m;

	if(realm == NULL)
	    return;

	SFMSetTiming(realm, lapsed_ms);

	/* Update each FDM */
	for(m_num = 0; m_num < realm->total_models; m_num++)
	{
	    m = realm->model[m_num];
	    if(m == NULL)
		continue;

/* TODO */

	}
}