Skip to content

Commit cae4def

Browse files
committed
lib: add const qualifiers to vecmat function parameters
1 parent 770ea15 commit cae4def

File tree

6 files changed

+105
-105
lines changed

6 files changed

+105
-105
lines changed

lib/vecmat.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ extern void vm_MakeZero(vector *v);
174174
extern void vm_MakeZero(angvec *a);
175175

176176
// Rotates a vector thru a matrix
177-
extern void vm_MatrixMulVector(vector *, vector *, matrix *);
177+
extern void vm_MatrixMulVector(vector *, const vector *, const matrix *);
178178

179179
// Multiply a vector times the transpose of a matrix
180-
void vm_VectorMulTMatrix(vector *result, vector *v, matrix *m);
180+
void vm_VectorMulTMatrix(vector *result, const vector *v, const matrix *m);
181181

182182
// Multiplies 2 3x3 matrixes, returning the result in first argument
183-
extern void vm_MatrixMul(matrix *, matrix *, matrix *);
183+
extern void vm_MatrixMul(matrix *, const matrix *, const matrix *);
184184

185185
// Multiply a matrix times the transpose of a matrix
186-
void vm_MatrixMulTMatrix(matrix *dest, matrix *src0, matrix *src1);
186+
void vm_MatrixMulTMatrix(matrix *dest, const matrix *src0, const matrix *src1);
187187

188188
// Given a vector, returns the magnitude. Uses sqrt so it's slow
189189
extern scalar vm_GetMagnitude(const vector *);
@@ -201,7 +201,7 @@ extern void vm_CrossProduct(vector *, const vector *, const vector *);
201201
extern void vm_SubVectors(vector *, const vector *, const vector *);
202202

203203
// Returns adds two vectors, returns result in first arg
204-
extern void vm_AddVectors(vector *, vector *, vector *);
204+
extern void vm_AddVectors(vector *, const vector *, const vector *);
205205

206206
// Inits vector to 0,0,0
207207
extern void vm_CenterVector(vector *);
@@ -214,13 +214,13 @@ extern void vm_AverageVector(vector *, int);
214214
extern scalar vm_NormalizeVector(vector *);
215215

216216
// Scales second arg vector by 3rd arg, placing result in first arg
217-
extern void vm_ScaleVector(vector *, vector *, scalar);
217+
extern void vm_ScaleVector(vector *, const vector *, scalar);
218218

219219
// Scales all components of vector v by value s adds the result to p and stores result in vector d
220-
extern void vm_ScaleAddVector(vector *d, vector *p, vector *v, scalar s);
220+
extern void vm_ScaleAddVector(vector *d, const vector *p, const vector *v, scalar s);
221221

222222
// Divides second vector components by 3rd arg, placing result in first arg. Useful for parametric lines
223-
extern void vm_DivVector(vector *, vector *, scalar);
223+
extern void vm_DivVector(vector *, const vector *, scalar);
224224

225225
// Same as NormalizeVector, but uses approximation
226226
extern scalar vm_NormalizeVectorFast(vector *);
@@ -277,49 +277,49 @@ extern scalar vm_VectorDistanceQuick(const vector *a, const vector *b);
277277
// Parameters: dest - filled in with the normalized direction vector
278278
// start,end - the start and end points used to calculate the vector
279279
// Returns: the distance between the two input points
280-
scalar vm_GetNormalizedDir(vector *dest, vector *end, vector *start);
280+
scalar vm_GetNormalizedDir(vector *dest, const vector *end, const vector *start);
281281

282282
// Returns a normalized direction vector between two points
283283
// Uses sloppier magnitude, less precise
284-
scalar vm_GetNormalizedDirFast(vector *dest, vector *end, vector *start);
284+
scalar vm_GetNormalizedDirFast(vector *dest, const vector *end, const vector *start);
285285

286286
// extract angles from a matrix
287-
angvec *vm_ExtractAnglesFromMatrix(angvec *a, matrix *m);
287+
angvec *vm_ExtractAnglesFromMatrix(angvec *a, const matrix *m);
288288

289289
// returns the angle between two vectors and a forward vector
290-
angle vm_DeltaAngVec(vector *v0, vector *v1, vector *fvec);
290+
angle vm_DeltaAngVec(const vector *v0, const vector *v1, const vector *fvec);
291291

292292
// returns the angle between two normalized vectors and a forward vector
293-
angle vm_DeltaAngVecNorm(vector *v0, vector *v1, vector *fvec);
293+
angle vm_DeltaAngVecNorm(const vector *v0, const vector *v1, const vector *fvec);
294294

295295
// Computes the distance from a point to a plane.
296296
// Parms: checkp - the point to check
297297
// Parms: norm - the (normalized) surface normal of the plane
298298
// planep - a point on the plane
299299
// Returns: The signed distance from the plane; negative dist is on the back of the plane
300-
scalar vm_DistToPlane(vector *checkp, vector *norm, vector *planep);
300+
scalar vm_DistToPlane(const vector *checkp, const vector *norm, const vector *planep);
301301

302302
// returns the value of a determinant
303-
scalar calc_det_value(matrix *det);
303+
scalar calc_det_value(const matrix *det);
304304

305305
void vm_MakeInverseMatrix(matrix *dest);
306306
void vm_SinCosToMatrix(matrix *m, scalar sinp, scalar cosp, scalar sinb, scalar cosb, scalar sinh, scalar cosh);
307307

308308
// Gets the real center of a polygon
309-
scalar vm_GetCentroid(vector *centroid, vector *src, int nv);
309+
scalar vm_GetCentroid(vector *centroid, const vector *src, int nv);
310310

311311
// retrieves a random vector in values -RAND_MAX/2 to RAND_MAX/2
312312
void vm_MakeRandomVector(vector *vec);
313313

314314
// Given a set of points, computes the minimum bounding sphere of those points
315-
scalar vm_ComputeBoundingSphere(vector *center, vector *vecs, int num_verts);
315+
scalar vm_ComputeBoundingSphere(vector *center, const vector *vecs, int num_verts);
316316

317317
// Gets the real center of a polygon, but uses fast magnitude calculation
318318
// Returns the size of the passed in stuff
319-
scalar vm_GetCentroidFast(vector *centroid, vector *src, int nv);
319+
scalar vm_GetCentroidFast(vector *centroid, const vector *src, int nv);
320320

321321
// Here are the C++ operator overloads -- they do as expected
322-
extern matrix operator*(matrix src0, matrix src1);
323-
extern matrix operator*=(matrix &src0, matrix src1);
322+
extern matrix operator*(const matrix &src0, const matrix &src1);
323+
extern matrix operator*=(matrix &src0, const matrix &src1);
324324

325325
#endif

netgames/dmfc/dmfcfunctions.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool (*DLLUnattachChildren)(object *parent);
334334
bool (*DLLUnattachChild)(object *parent, char parent_ap);
335335
bool (*DLLUnattachFromParent)(object *child);
336336
float (*DLLvm_GetMagnitude)(vector *);
337-
void (*DLLvm_MatrixMulVector)(vector *, vector *, matrix *);
337+
void (*DLLvm_MatrixMulVector)(vector *, const vector *, const matrix *);
338338
void (*DLLphys_apply_force)(object *obj, vector *force_vec, int16_t weapon_index);
339339
void (*DLLphys_apply_rot)(object *obj, vector *force_vec);
340340
void (*DLLvm_TransposeMatrix)(matrix *);
@@ -346,16 +346,16 @@ float (*DLLvm_GetMagnitudeFast)(vector *);
346346
void (*DLLvm_MakeIdentity)(matrix *);
347347
void (*DLLvm_MakeVectorZero)(vector *v);
348348
void (*DLLvm_MakeAngleZero)(angvec *a);
349-
void (*DLLvm_VectorMulTMatrix)(vector *result, vector *v, matrix *m);
350-
void (*DLLvm_MatrixMul)(matrix *, matrix *, matrix *);
351-
void (*DLLvm_MatrixMulTMatrix)(matrix *dest, matrix *src0, matrix *src1);
349+
void (*DLLvm_VectorMulTMatrix)(vector *result, const vector *v, const matrix *m);
350+
void (*DLLvm_MatrixMul)(matrix *, const matrix *, const matrix *);
351+
void (*DLLvm_MatrixMulTMatrix)(matrix *dest, const matrix *src0, const matrix *src1);
352352
float (*DLLvm_DotProduct)(vector *, vector *);
353353
void (*DLLvm_SubVectors)(vector *, const vector *, const vector *);
354-
void (*DLLvm_AddVectors)(vector *, vector *, vector *);
354+
void (*DLLvm_AddVectors)(vector *, const vector *, const vector *);
355355
void (*DLLvm_AverageVector)(vector *, int);
356-
void (*DLLvm_ScaleVector)(vector *, vector *, float);
357-
void (*DLLvm_ScaleAddVector)(vector *d, vector *p, vector *v, float s);
358-
void (*DLLvm_DivVector)(vector *, vector *, float);
356+
void (*DLLvm_ScaleVector)(vector *, const vector *, float);
357+
void (*DLLvm_ScaleAddVector)(vector *d, const vector *p, const vector *v, float s);
358+
void (*DLLvm_DivVector)(vector *, const vector *, float);
359359
float (*DLLvm_NormalizeVectorFast)(vector *);
360360
void (*DLLvm_ClearMatrix)(matrix *);
361361
void (*DLLvm_AnglesToMatrix)(matrix *, angle p, angle h, angle b);
@@ -368,20 +368,20 @@ void (*DLLvm_GetPerp)(vector *n, vector *a, vector *b, vector *c);
368368
float (*DLLvm_GetNormal)(vector *n, vector *v0, vector *v1, vector *v2);
369369
float (*DLLvm_VectorDistance)(const vector *a, const vector *b);
370370
float (*DLLvm_VectorDistanceQuick)(vector *a, vector *b);
371-
float (*DLLvm_GetNormalizedDir)(vector *dest, vector *end, vector *start);
372-
float (*DLLvm_GetNormalizedDirFast)(vector *dest, vector *end, vector *start);
373-
angvec *(*DLLvm_ExtractAnglesFromMatrix)(angvec *a, matrix *m);
374-
angle (*DLLvm_DeltaAngVec)(vector *v0, vector *v1, vector *fvec);
375-
angle (*DLLvm_DeltaAngVecNorm)(vector *v0, vector *v1, vector *fvec);
376-
float (*DLLvm_DistToPlane)(vector *checkp, vector *norm, vector *planep);
377-
float (*DLLvm_CalcDetValue)(matrix *det);
371+
float (*DLLvm_GetNormalizedDir)(vector *dest, const vector *end, const vector *start);
372+
float (*DLLvm_GetNormalizedDirFast)(vector *dest, const vector *end, const vector *start);
373+
angvec *(*DLLvm_ExtractAnglesFromMatrix)(angvec *a, const matrix *m);
374+
angle (*DLLvm_DeltaAngVec)(const vector *v0, const vector *v1, const vector *fvec);
375+
angle (*DLLvm_DeltaAngVecNorm)(const vector *v0, const vector *v1, const vector *fvec);
376+
float (*DLLvm_DistToPlane)(const vector *checkp, const vector *norm, const vector *planep);
377+
float (*DLLvm_CalcDetValue)(const matrix *det);
378378
void (*DLLvm_MakeInverseMatrix)(matrix *dest);
379379
void (*DLLvm_SinCosToMatrix)(matrix *m, float sinp, float cosp, float sinb, float cosb, float sinh,
380380
float cosh);
381-
float (*DLLvm_GetCentroid)(vector *centroid, vector *src, int nv);
381+
float (*DLLvm_GetCentroid)(vector *centroid, const vector *src, int nv);
382382
void (*DLLvm_MakeRandomVector)(vector *vec);
383-
float (*DLLvm_ComputeBoundingSphere)(vector *center, vector *vecs, int num_verts);
384-
float (*DLLvm_GetCentroidFast)(vector *centroid, vector *src, int nv);
383+
float (*DLLvm_ComputeBoundingSphere)(vector *center, const vector *vecs, int num_verts);
384+
float (*DLLvm_GetCentroidFast)(vector *centroid, const vector *src, int nv);
385385
int (*DLLRenderHUDGetTextLineWidth)(const char *string);
386386
int (*DLLRenderHUDGetTextHeight)(const char *string);
387387
void (*DLLStartFrame)(int x, int y, int x2, int y2, bool clear);

netgames/includes/gamedll_header.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ typedef float (*vm_GetMagnitude_fp)(vector *vec);
965965
DMFCDLLOUT(vm_GetMagnitude_fp DLLvm_GetMagnitude;)
966966

967967
// Rotates a vector thru a matrix
968-
typedef void (*vm_MatrixMulVector_fp)(vector *, vector *, matrix *);
968+
typedef void (*vm_MatrixMulVector_fp)(vector *, const vector *, const matrix *);
969969
DMFCDLLOUT(vm_MatrixMulVector_fp DLLvm_MatrixMulVector;)
970970

971971
// Applies an instantaneous force on an object, resulting in an instantaneous
@@ -1013,15 +1013,15 @@ typedef void (*vm_MakeAngleZero_fp)(angvec *a);
10131013
DMFCDLLOUT(vm_MakeAngleZero_fp DLLvm_MakeAngleZero;)
10141014

10151015
// Multiply a vector times the transpose of a matrix
1016-
typedef void (*vm_VectorMulTMatrix_fp)(vector *result, vector *v, matrix *m);
1016+
typedef void (*vm_VectorMulTMatrix_fp)(vector *result, const vector *v, const matrix *m);
10171017
DMFCDLLOUT(vm_VectorMulTMatrix_fp DLLvm_VectorMulTMatrix;)
10181018

10191019
// Multiplies 2 3x3 matrixes, returning the result in first argument
1020-
typedef void (*vm_MatrixMul_fp)(matrix *, matrix *, matrix *);
1020+
typedef void (*vm_MatrixMul_fp)(matrix *, const matrix *, const matrix *);
10211021
DMFCDLLOUT(vm_MatrixMul_fp DLLvm_MatrixMul;)
10221022

10231023
// Multiply a matrix times the transpose of a matrix
1024-
typedef void (*vm_MatrixMulTMatrix_fp)(matrix *dest, matrix *src0, matrix *src1);
1024+
typedef void (*vm_MatrixMulTMatrix_fp)(matrix *dest, const matrix *src0, const matrix *src1);
10251025
DMFCDLLOUT(vm_MatrixMulTMatrix_fp DLLvm_MatrixMulTMatrix;)
10261026

10271027
// Returns the dot product of the two given vectors
@@ -1033,23 +1033,23 @@ typedef void (*vm_SubVectors_fp)(vector *, const vector *, const vector *);
10331033
DMFCDLLOUT(vm_SubVectors_fp DLLvm_SubVectors;)
10341034

10351035
// Returns adds two vectors, returns result in first arg
1036-
typedef void (*vm_AddVectors_fp)(vector *, vector *, vector *);
1036+
typedef void (*vm_AddVectors_fp)(vector *, const vector *, const vector *);
10371037
DMFCDLLOUT(vm_AddVectors_fp DLLvm_AddVectors;)
10381038

10391039
// Given a vector, divides second arg by vector components
10401040
typedef void (*vm_AverageVector_fp)(vector *, int);
10411041
DMFCDLLOUT(vm_AverageVector_fp DLLvm_AverageVector;)
10421042

10431043
// Scales second arg vector by 3rd arg, placing result in first arg
1044-
typedef void (*vm_ScaleVector_fp)(vector *, vector *, float);
1044+
typedef void (*vm_ScaleVector_fp)(vector *, const vector *, float);
10451045
DMFCDLLOUT(vm_ScaleVector_fp DLLvm_ScaleVector;)
10461046

10471047
// Scales all components of vector v by value s adds the result to p and stores result in vector d
1048-
typedef void (*vm_ScaleAddVector_fp)(vector *d, vector *p, vector *v, float s);
1048+
typedef void (*vm_ScaleAddVector_fp)(vector *d, const vector *p, const vector *v, float s);
10491049
DMFCDLLOUT(vm_ScaleAddVector_fp DLLvm_ScaleAddVector;)
10501050

10511051
// Divides second vector components by 3rd arg, placing result in first arg. Useful for parametric lines
1052-
typedef void (*vm_DivVector_fp)(vector *, vector *, float);
1052+
typedef void (*vm_DivVector_fp)(vector *, const vector *, float);
10531053
DMFCDLLOUT(vm_DivVector_fp DLLvm_DivVector;)
10541054

10551055
// Same as NormalizeVector, but uses approximation
@@ -1116,36 +1116,36 @@ DMFCDLLOUT(vm_VectorDistanceQuick_fp DLLvm_VectorDistanceQuick;)
11161116
// Parameters: dest - filled in with the normalized direction vector
11171117
// start,end - the start and end points used to calculate the vector
11181118
// Returns: the distance between the two input points
1119-
typedef float (*vm_GetNormalizedDir_fp)(vector *dest, vector *end, vector *start);
1119+
typedef float (*vm_GetNormalizedDir_fp)(vector *dest, const vector *end, const vector *start);
11201120
DMFCDLLOUT(vm_GetNormalizedDir_fp DLLvm_GetNormalizedDir;)
11211121

11221122
// Returns a normalized direction vector between two points
11231123
// Uses sloppier magnitude, less precise
1124-
typedef float (*vm_GetNormalizedDirFast_fp)(vector *dest, vector *end, vector *start);
1124+
typedef float (*vm_GetNormalizedDirFast_fp)(vector *dest, const vector *end, const vector *start);
11251125
DMFCDLLOUT(vm_GetNormalizedDirFast_fp DLLvm_GetNormalizedDirFast;)
11261126

11271127
// extract angles from a matrix
1128-
typedef angvec *(*vm_ExtractAnglesFromMatrix_fp)(angvec *a, matrix *m);
1128+
typedef angvec *(*vm_ExtractAnglesFromMatrix_fp)(angvec *a, const matrix *m);
11291129
DMFCDLLOUT(vm_ExtractAnglesFromMatrix_fp DLLvm_ExtractAnglesFromMatrix;)
11301130

11311131
// returns the angle between two vectors and a forward vector
1132-
typedef angle (*vm_DeltaAngVec_fp)(vector *v0, vector *v1, vector *fvec);
1132+
typedef angle (*vm_DeltaAngVec_fp)(const vector *v0, const vector *v1, const vector *fvec);
11331133
DMFCDLLOUT(vm_DeltaAngVec_fp DLLvm_DeltaAngVec;)
11341134

11351135
// returns the angle between two normalized vectors and a forward vector
1136-
typedef angle (*vm_DeltaAngVecNorm_fp)(vector *v0, vector *v1, vector *fvec);
1136+
typedef angle (*vm_DeltaAngVecNorm_fp)(const vector *v0, const vector *v1, const vector *fvec);
11371137
DMFCDLLOUT(vm_DeltaAngVecNorm_fp DLLvm_DeltaAngVecNorm;)
11381138

11391139
// Computes the distance from a point to a plane.
11401140
// Parms: checkp - the point to check
11411141
// Parms: norm - the (normalized) surface normal of the plane
11421142
// planep - a point on the plane
11431143
// Returns: The signed distance from the plane; negative dist is on the back of the plane
1144-
typedef float (*vm_DistToPlane_fp)(vector *checkp, vector *norm, vector *planep);
1144+
typedef float (*vm_DistToPlane_fp)(const vector *checkp, const vector *norm, const vector *planep);
11451145
DMFCDLLOUT(vm_DistToPlane_fp DLLvm_DistToPlane;)
11461146

11471147
// returns the value of a determinant
1148-
typedef float (*vm_CalcDetValue_fp)(matrix *det);
1148+
typedef float (*vm_CalcDetValue_fp)(const matrix *det);
11491149
DMFCDLLOUT(vm_CalcDetValue_fp DLLvm_CalcDetValue;)
11501150

11511151
typedef void (*vm_MakeInverseMatrix_fp)(matrix *dest);
@@ -1155,20 +1155,20 @@ typedef void (*vm_SinCosToMatrix_fp)(matrix *m, float sinp, float cosp, float si
11551155
DMFCDLLOUT(vm_SinCosToMatrix_fp DLLvm_SinCosToMatrix;)
11561156

11571157
// Gets the real center of a polygon
1158-
typedef float (*vm_GetCentroid_fp)(vector *centroid, vector *src, int nv);
1158+
typedef float (*vm_GetCentroid_fp)(vector *centroid, const vector *src, int nv);
11591159
DMFCDLLOUT(vm_GetCentroid_fp DLLvm_GetCentroid;)
11601160

11611161
// retrieves a random vector in values -RAND_MAX/2 to RAND_MAX/2
11621162
typedef void (*vm_MakeRandomVector_fp)(vector *vec);
11631163
DMFCDLLOUT(vm_MakeRandomVector_fp DLLvm_MakeRandomVector;)
11641164

11651165
// Given a set of points, computes the minimum bounding sphere of those points
1166-
typedef float (*vm_ComputeBoundingSphere_fp)(vector *center, vector *vecs, int num_verts);
1166+
typedef float (*vm_ComputeBoundingSphere_fp)(vector *center, const vector *vecs, int num_verts);
11671167
DMFCDLLOUT(vm_ComputeBoundingSphere_fp DLLvm_ComputeBoundingSphere;)
11681168

11691169
// Gets the real center of a polygon, but uses fast magnitude calculation
11701170
// Returns the size of the passed in stuff
1171-
typedef float (*vm_GetCentroidFast_fp)(vector *centroid, vector *src, int nv);
1171+
typedef float (*vm_GetCentroidFast_fp)(vector *centroid, const vector *src, int nv);
11721172
DMFCDLLOUT(vm_GetCentroidFast_fp DLLvm_GetCentroidFast;)
11731173

11741174
// returns scaled line width

0 commit comments

Comments
 (0)