mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 09:34:35 -05:00
Hint to the compiler that all vector methods should be inlined
This commit is contained in:
parent
055e564acc
commit
ddbf199301
5 changed files with 40 additions and 38 deletions
|
@ -5,7 +5,7 @@
|
|||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
#define INLINE inline
|
||||
#define HINT_INLINE inline
|
||||
|
||||
/* The following ifdef block is the standard way of creating macros which make exporting
|
||||
from a DLL simpler. All files within this DLL are compiled with the CLIENT_EXPORTS
|
||||
|
|
|
@ -102,7 +102,7 @@ void MapRenderer_RenderTranslucent(Real64 deltaTime) {
|
|||
void MapRenderer_CheckWeather(Real64 deltaTime) {
|
||||
Vector3 pos = Game_CurrentCameraPos;
|
||||
Vector3I coords;
|
||||
Vector3I_Floor(&pos, &coords);
|
||||
Vector3I_Floor(&coords, &pos);
|
||||
|
||||
BlockID block = World_SafeGetBlock_3I(coords);
|
||||
bool outside = !World_IsValidPos_3I(coords);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CS_VECTOR3I_H
|
||||
#include "Typedefs.h"
|
||||
#include "Vectors.h"
|
||||
#include "Compiler.h"
|
||||
/* Represents 3 dimensional integer vector.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
@ -9,10 +10,10 @@
|
|||
typedef struct Vector3I { Int32 X, Y, Z; } Vector3I;
|
||||
|
||||
/* Constructs a 3D vector with X, Y and Z set to given value. */
|
||||
Vector3I Vector3I_Create1(Int32 value);
|
||||
HINT_INLINE Vector3I Vector3I_Create1(Int32 value);
|
||||
|
||||
/* Constructs a 3D vector from the given coordinates. */
|
||||
Vector3I Vector3I_Create3(Int32 x, Int32 y, Int32 z);
|
||||
HINT_INLINE Vector3I Vector3I_Create3(Int32 x, Int32 y, Int32 z);
|
||||
|
||||
|
||||
#define Vector3I_UnitX Vector3I_Create3(1, 0, 0)
|
||||
|
@ -24,30 +25,30 @@ Vector3I Vector3I_Create3(Int32 x, Int32 y, Int32 z);
|
|||
|
||||
|
||||
/* Adds a and b. */
|
||||
void Vector3I_Add(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
HINT_INLINE void Vector3I_Add(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
|
||||
/* Subtracts b from a. */
|
||||
void Vector3I_Subtract(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
HINT_INLINE void Vector3I_Subtract(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
|
||||
/* Multiplies all components of a by scale. */
|
||||
void Vector3I_Multiply1(Vector3I* result, Vector3I* a, Int32 scale);
|
||||
HINT_INLINE void Vector3I_Multiply1(Vector3I* result, Vector3I* a, Int32 scale);
|
||||
|
||||
/* Negates components of a. */
|
||||
void Vector3I_Negate(Vector3I* result, Vector3I* a);
|
||||
HINT_INLINE void Vector3I_Negate(Vector3I* result, Vector3I* a);
|
||||
|
||||
|
||||
/* Returns whether the two vectors are exact same on all axes. */
|
||||
bool Vector3I_Equals(Vector3I* a, Vector3I* b);
|
||||
HINT_INLINE bool Vector3I_Equals(Vector3I* a, Vector3I* b);
|
||||
|
||||
/* Returns a vector such that each component is floor of input floating-point component.*/
|
||||
void Vector3I_Floor(Vector3I* result, Vector3* a);
|
||||
HINT_INLINE void Vector3I_Floor(Vector3I* result, Vector3* a);
|
||||
|
||||
/* Returns a vector with the integer components converted to floating-point components.*/
|
||||
void Vector3I_ToVector3(Vector3* result, Vector3I* a);
|
||||
HINT_INLINE void Vector3I_ToVector3(Vector3* result, Vector3I* a);
|
||||
|
||||
/* Returns a vector such that each component is minimum of corresponding a and b component.*/
|
||||
void Vector3I_Min(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
HINT_INLINE void Vector3I_Min(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
|
||||
/* Returns a vector such that each component is maximum of corresponding a and b component.*/
|
||||
void Vector3I_Max(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
HINT_INLINE void Vector3I_Max(Vector3I* result, Vector3I* a, Vector3I* b);
|
||||
#endif
|
|
@ -2,6 +2,7 @@
|
|||
#define CS_VECTORS_H
|
||||
#include "Typedefs.h"
|
||||
#include "Matrix.h"
|
||||
#include "Compiler.h"
|
||||
/* Represents 2, 3 dimensional vectors.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
@ -12,20 +13,20 @@ typedef struct Vector3_ { Real32 X, Y, Z; } Vector3;
|
|||
|
||||
|
||||
/* Constructs a 2D vector from the given coordinates. */
|
||||
Vector2 Vector2_Create2(Real32 x, Real32 y);
|
||||
HINT_INLINE Vector2 Vector2_Create2(Real32 x, Real32 y);
|
||||
|
||||
/* Constructs a 3D vector with X, Y and Z set to given value. */
|
||||
Vector3 Vector3_Create1(Real32 value);
|
||||
HINT_INLINE Vector3 Vector3_Create1(Real32 value);
|
||||
|
||||
/* Constructs a 3D vector from the given coordinates. */
|
||||
Vector3 Vector3_Create3(Real32 x, Real32 y, Real32 z);
|
||||
HINT_INLINE Vector3 Vector3_Create3(Real32 x, Real32 y, Real32 z);
|
||||
|
||||
|
||||
/* Returns the length of the given vector. */
|
||||
Real32 Vector3_Length(Vector3* v);
|
||||
HINT_INLINE Real32 Vector3_Length(Vector3* v);
|
||||
|
||||
/* Returns the squared length of the given vector. */
|
||||
Real32 Vector3_LengthSquared(Vector3* v);
|
||||
HINT_INLINE Real32 Vector3_LengthSquared(Vector3* v);
|
||||
|
||||
|
||||
#define Vector2_UnitX Vector2_Create2(1.0f, 0.0f)
|
||||
|
@ -41,62 +42,62 @@ Real32 Vector3_LengthSquared(Vector3* v);
|
|||
|
||||
|
||||
/* Adds a and b. */
|
||||
void Vector3_Add(Vector3* result, Vector3* a, Vector3* b);
|
||||
HINT_INLINE void Vector3_Add(Vector3* result, Vector3* a, Vector3* b);
|
||||
|
||||
/* Adds b to all components of a. */
|
||||
void Vector3_Add1(Vector3* result, Vector3* a, Real32 b);
|
||||
HINT_INLINE void Vector3_Add1(Vector3* result, Vector3* a, Real32 b);
|
||||
|
||||
/* Subtracts b from a. */
|
||||
void Vector3_Subtract(Vector3* result, Vector3* a, Vector3* b);
|
||||
HINT_INLINE void Vector3_Subtract(Vector3* result, Vector3* a, Vector3* b);
|
||||
|
||||
/* Multiplies all components of a by scale. */
|
||||
void Vector3_Multiply1(Vector3* result, Vector3* a, Real32 scale);
|
||||
HINT_INLINE void Vector3_Multiply1(Vector3* result, Vector3* a, Real32 scale);
|
||||
|
||||
/* Multiplies components of a by scale. */
|
||||
void Vector3_Multiply3(Vector3* result, Vector3* a, Vector3* scale);
|
||||
HINT_INLINE void Vector3_Multiply3(Vector3* result, Vector3* a, Vector3* scale);
|
||||
|
||||
/* Divides all components of a by scale. */
|
||||
void Vector3_Divide1(Vector3* result, Vector3* a, Real32 scale);
|
||||
HINT_INLINE void Vector3_Divide1(Vector3* result, Vector3* a, Real32 scale);
|
||||
|
||||
/* Divides components of a by scale. */
|
||||
void Vector3_Divide3(Vector3* result, Vector3* a, Vector3* scale);
|
||||
HINT_INLINE void Vector3_Divide3(Vector3* result, Vector3* a, Vector3* scale);
|
||||
|
||||
|
||||
/* Linearly interpolates between two vectors. */
|
||||
void Vector3_Lerp(Vector3* result, Vector3* a, Vector3* b, Real32 blend);
|
||||
HINT_INLINE void Vector3_Lerp(Vector3* result, Vector3* a, Vector3* b, Real32 blend);
|
||||
|
||||
/* Calculates the dot product of two vectors. */
|
||||
Real32 Vector3_Dot(Vector3* left, Vector3* right);
|
||||
HINT_INLINE Real32 Vector3_Dot(Vector3* left, Vector3* right);
|
||||
|
||||
/* Calculates the cross product of two vectors. */
|
||||
void Vector3_Cross(Vector3* result, Vector3* a, Vector3* b);
|
||||
HINT_INLINE void Vector3_Cross(Vector3* result, Vector3* a, Vector3* b);
|
||||
|
||||
/* Calculates the normal of a vector. */
|
||||
void Vector3_Normalize(Vector3* result, Vector3* a);
|
||||
HINT_INLINE void Vector3_Normalize(Vector3* result, Vector3* a);
|
||||
|
||||
|
||||
/* Transforms a vector by the given matrix. */
|
||||
void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat);
|
||||
HINT_INLINE void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat);
|
||||
|
||||
/* Transforms the Y component of a vector by the given matrix. */
|
||||
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat);
|
||||
HINT_INLINE void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat);
|
||||
|
||||
/* Rotates the given 3D coordinates around the x axis. */
|
||||
Vector3 Vector3_RotateX(Vector3 v, Real32 angle);
|
||||
HINT_INLINE Vector3 Vector3_RotateX(Vector3 v, Real32 angle);
|
||||
|
||||
/* Rotates the given 3D coordinates around the y axis. */
|
||||
Vector3 Vector3_RotateY(Vector3 v, Real32 angle);
|
||||
HINT_INLINE Vector3 Vector3_RotateY(Vector3 v, Real32 angle);
|
||||
|
||||
/* Rotates the given 3D coordinates around the y axis. */
|
||||
Vector3 Vector3_RotateY3(Real32 x, Real32 y, Real32 z, Real32 angle);
|
||||
HINT_INLINE Vector3 Vector3_RotateY3(Real32 x, Real32 y, Real32 z, Real32 angle);
|
||||
|
||||
/* Rotates the given 3D coordinates around the z axis. */
|
||||
Vector3 Vector3_RotateZ(Vector3 v, Real32 angle);
|
||||
HINT_INLINE Vector3 Vector3_RotateZ(Vector3 v, Real32 angle);
|
||||
|
||||
|
||||
/* Returns whether the two vectors are exact same on all axes. */
|
||||
bool Vector3_Equals(Vector3* a, Vector3* b);
|
||||
HINT_INLINE bool Vector3_Equals(Vector3* a, Vector3* b);
|
||||
|
||||
/* Returns whether the two vectors are different on any axis. */
|
||||
bool Vector3_NotEquals(Vector3* a, Vector3* b);
|
||||
HINT_INLINE bool Vector3_NotEquals(Vector3* a, Vector3* b);
|
||||
#endif
|
|
@ -46,7 +46,7 @@ void WeatherRenderer_Render(Real64 deltaTime) {
|
|||
Gfx_BindTexture(weather == Weather_Rainy ? weather_rainTex : weather_snowTex);
|
||||
Vector3 camPos = Game_CurrentCameraPos;
|
||||
Vector3I pos;
|
||||
Vector3I_Floor(&camPos, &pos);
|
||||
Vector3I_Floor(&pos, &camPos);
|
||||
bool moved = !Vector3I_Equals(&pos, &weather_lastPos);
|
||||
weather_lastPos = pos;
|
||||
|
||||
|
|
Loading…
Reference in a new issue