Day 42 complete

Found and fixed bugs with gencpp when generating the vector math stuff.
This commit is contained in:
2023-10-22 21:52:41 -04:00
parent fa28d401ef
commit 4ab64e2c17
30 changed files with 1694 additions and 886 deletions

View File

@ -0,0 +1,200 @@
// This was generated by project/codegen/engine_gen.cpp
#pragma once
#if INTELLISENSE_DIRECTIVES
#include "vectors.hpp"
#endif
struct Pos2_f32
{
union
{
struct
{
f32 x;
f32 y;
};
f32 Basis[ 2 ];
};
operator Vec2_f32()
{
return *rcast( Vec2_f32*, this );
}
};
using Dist2_f32 = f32;
inline Dist2_f32 distance( Pos2_f32 a, Pos2_f32 b )
{
f32 x = b.x - a.x;
f32 y = b.y - a.y;
Dist2_f32 result = sqrt( x * x + y * y );
return result;
}
struct Vel2_f32
{
union
{
struct
{
f32 x;
f32 y;
};
f32 Basis[ 2 ];
};
operator Vec2_f32()
{
return *rcast( Vec2_f32*, this );
}
};
inline Vel2_f32 velocity( Pos2_f32 a, Pos2_f32 b )
{
Vec2_f32 result = b - a;
return pcast( Vel2_f32, result );
}
inline Pos2_f32& operator+=( Pos2_f32& pos, Vel2_f32 const& vel )
{
pos.x += vel.x;
pos.y += vel.y;
return pos;
}
inline Vel2_f32& operator*=( Vel2_f32& v, f32 s )
{
v.x *= s;
v.y *= s;
return v;
}
struct Accel2_f32
{
union
{
struct
{
f32 x;
f32 y;
};
f32 Basis[ 2 ];
};
operator Vec2_f32()
{
return *rcast( Vec2_f32*, this );
}
};
inline Accel2_f32 acceleration( Vel2_f32 a, Vel2_f32 b )
{
Vec2_f32 result = b - a;
return pcast( Accel2_f32, result );
}
struct Pos2_s32
{
union
{
struct
{
s32 x;
s32 y;
};
s32 Basis[ 2 ];
};
operator Vec2_s32()
{
return *rcast( Vec2_s32*, this );
}
};
using Dist2_s32 = s32;
inline Dist2_s32 distance( Pos2_s32 a, Pos2_s32 b )
{
s32 x = b.x - a.x;
s32 y = b.y - a.y;
Dist2_s32 result = sqrt( x * x + y * y );
return result;
}
struct Vel2_s32
{
union
{
struct
{
s32 x;
s32 y;
};
s32 Basis[ 2 ];
};
operator Vec2_s32()
{
return *rcast( Vec2_s32*, this );
}
};
inline Vel2_s32 velocity( Pos2_s32 a, Pos2_s32 b )
{
Vec2_s32 result = b - a;
return pcast( Vel2_s32, result );
}
inline Pos2_s32& operator+=( Pos2_s32& pos, Vel2_s32 const& vel )
{
pos.x += vel.x;
pos.y += vel.y;
return pos;
}
inline Vel2_s32& operator*=( Vel2_s32& v, s32 s )
{
v.x *= s;
v.y *= s;
return v;
}
struct Accel2_s32
{
union
{
struct
{
s32 x;
s32 y;
};
s32 Basis[ 2 ];
};
operator Vec2_s32()
{
return *rcast( Vec2_s32*, this );
}
};
inline Accel2_s32 acceleration( Vel2_s32 a, Vel2_s32 b )
{
Vec2_s32 result = b - a;
return pcast( Accel2_s32, result );
}
using Pos2 = Pos2_f32;
using Dist2 = Dist2_f32;
using Vel2 = Vel2_f32;
using Accel2 = Accel2_f32;
using Pos2i = Pos2_s32;
using Dist2i = Dist2_s32;
using Vel2i = Vel2_s32;
using Accel2i = Accel2_s32;

View File

@ -0,0 +1,177 @@
// This was generated by project/codegen/engine_gen.cpp
#pragma once
#if INTELLISENSE_DIRECTIVES
#include "engine_module.hpp"
#include "platform.hpp"
#endif
struct Vec2_f32
{
union
{
struct
{
f32 x;
f32 y;
};
f32 Basis[ 2 ];
};
};
template<>
constexpr Vec2_f32 tmpl_zero< Vec2_f32 >()
{
return { 0, 0 };
}
inline Vec2_f32 abs( Vec2_f32 v )
{
Vec2_f32 result { abs( v.x ), abs( v.y ) };
return result;
}
inline Vec2_f32 operator-( Vec2_f32 v )
{
Vec2_f32 result { -v.x, -v.y };
return result;
}
inline Vec2_f32 operator+( Vec2_f32 a, Vec2_f32 b )
{
Vec2_f32 result { a.x + b.x, a.y + b.y };
return result;
}
inline Vec2_f32 operator-( Vec2_f32 a, Vec2_f32 b )
{
Vec2_f32 result { a.x - b.x, a.y - b.y };
return result;
}
inline Vec2_f32 operator*( Vec2_f32 v, f32 s )
{
Vec2_f32 result { v.x * s, v.y * s };
return result;
}
inline Vec2_f32 operator/( Vec2_f32 v, f32 s )
{
Vec2_f32 result { v.x / s, v.y / s };
return result;
}
inline Vec2_f32& operator+=( Vec2_f32& a, Vec2_f32 b )
{
a.x += b.x;
a.y += b.y;
return a;
}
inline Vec2_f32& operator-=( Vec2_f32& a, Vec2_f32 b )
{
a.x -= b.x;
a.y -= b.y;
return a;
}
inline Vec2_f32& operator*=( Vec2_f32& v, f32 s )
{
v.x *= s;
v.y *= s;
return v;
}
inline Vec2_f32& operator/=( Vec2_f32& v, f32 s )
{
v.x /= s;
v.y /= s;
return v;
}
struct Vec2_s32
{
union
{
struct
{
s32 x;
s32 y;
};
s32 Basis[ 2 ];
};
};
template<>
constexpr Vec2_s32 tmpl_zero< Vec2_s32 >()
{
return { 0, 0 };
}
inline Vec2_s32 abs( Vec2_s32 v )
{
Vec2_s32 result { abs( v.x ), abs( v.y ) };
return result;
}
inline Vec2_s32 operator-( Vec2_s32 v )
{
Vec2_s32 result { -v.x, -v.y };
return result;
}
inline Vec2_s32 operator+( Vec2_s32 a, Vec2_s32 b )
{
Vec2_s32 result { a.x + b.x, a.y + b.y };
return result;
}
inline Vec2_s32 operator-( Vec2_s32 a, Vec2_s32 b )
{
Vec2_s32 result { a.x - b.x, a.y - b.y };
return result;
}
inline Vec2_s32 operator*( Vec2_s32 v, s32 s )
{
Vec2_s32 result { v.x * s, v.y * s };
return result;
}
inline Vec2_s32 operator/( Vec2_s32 v, s32 s )
{
Vec2_s32 result { v.x / s, v.y / s };
return result;
}
inline Vec2_s32& operator+=( Vec2_s32& a, Vec2_s32 b )
{
a.x += b.x;
a.y += b.y;
return a;
}
inline Vec2_s32& operator-=( Vec2_s32& a, Vec2_s32 b )
{
a.x -= b.x;
a.y -= b.y;
return a;
}
inline Vec2_s32& operator*=( Vec2_s32& v, s32 s )
{
v.x *= s;
v.y *= s;
return v;
}
inline Vec2_s32& operator/=( Vec2_s32& v, s32 s )
{
v.x /= s;
v.y /= s;
return v;
}
using Vec2 = Vec2_f32;
using Vec2i = Vec2_s32;