Quick actions

cmd+k|ctrl+k

Navigation

Languages

Append types to vectors

Snippet info

Language

C

Visibility

public

Author

evine

Created

2015-12-30T11:24:34Z

Updated

2015-12-30T15:00:10Z

#include <stdio.h>
#include <stdlib.h>

typedef __uint128_t u128;
typedef __uint64_t u64;
typedef __uint32_t u32;
typedef __uint16_t u16;
typedef __uint8_t u8;

typedef __int128_t s128;
typedef __int64_t s64;
typedef __int32_t s32;
typedef __int16_t s16;
typedef __int8_t s8;

typedef __uint32_t b32;

typedef float f32;
typedef double f64;


// Switches
#define DEBUG 1

// Dissapearing functions
#if DEBUG
#define Dlog(...)           \
    printf(__VA_ARGS__) 
#else
#define Assert(Expression,...)
#define Dlog(...)
#endif


// 36 Types.
// 144 Functions.
// 1464 lines of code written manually.
// 66 lines of code here.

// Struct Define
#define v2ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,AppendName,syntax)  \
    v2##Type v2##Type##AppendName(v2##Type First, v2##Type Second)                  \
    {                                                                               \
        v2##Type Result;                                                            \
        Result.x = First.x syntax Second.x;                                         \
        Result.y = First.y syntax Second.y;                                         \
        return Result;                                                              \
    }
#define v3ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,AppendName,syntax)  \
    v3##Type v3##Type##AppendName(v3##Type First, v3##Type Second)                  \
    {                                                                               \
        v3##Type Result;                                                            \
        Result.x = First.x syntax Second.x;                                         \
        Result.y = First.y syntax Second.y;                                         \
        Result.z = First.z syntax Second.z;                                         \
        return Result;                                                              \
    }
#define v4ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,AppendName,syntax)  \
    v4##Type v4##Type##AppendName(v4##Type First, v4##Type Second)                  \
    {                                                                               \
        v4##Type Result;                                                            \
        Result.x = First.x syntax Second.x;                                         \
        Result.y = First.y syntax Second.y;                                         \
        Result.z = First.z syntax Second.z;                                         \
        Result.w = First.w syntax Second.w;                                         \
        return Result;                                                              \
    }  
    
#define VectorStructDefine(Type)    \
    struct v2##Type {               \
        Type x;                     \
        Type y;                     \
    }typedef v2##Type;              \
    struct v3##Type {               \
        Type x;                     \
        Type y;                     \
        Type z;                     \
    }typedef v3##Type;              \
    struct v4##Type {               \
        Type x;                     \
        Type y;                     \
        Type z;                     \
        Type w;                     \
    }typedef v4##Type;              \
                                    \
    v2ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Add,+)  \
    v3ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Add,+)  \
    v4ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Add,+)  \
                                                                    \
    v2ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Sub,-)  \
    v3ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Sub,-)  \
    v4ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Sub,-)  \
                                                                    \
    v2ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Mul,*)  \
    v3ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Mul,*)  \
    v4ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Mul,*)  \
                                                                    \
    v2ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Div,/)  \
    v3ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Div,/)  \
    v4ElementsOfOneStructPlusElementsOfAnotherStruct__(Type,Div,/)  

// NOTE:Daniel: Defines to v2s128,v3s128,v4f32 ...etc 
VectorStructDefine(s128)
VectorStructDefine(s64)
VectorStructDefine(s32)
VectorStructDefine(s16)
VectorStructDefine(s8)

VectorStructDefine(u128)
VectorStructDefine(u64)
VectorStructDefine(u32)
VectorStructDefine(u16)
VectorStructDefine(u8)

VectorStructDefine(f64)
VectorStructDefine(f32)

int main() {
    
    v4s32 g = {-5,1,21,4};
    v4s32 h = {9,4,1,5};
    
    v4s32 r = v4s32Add(g,h);
    
    Dlog("%i : %i : %i : %i\n",r.x,r.y,r.z,r.w);
    
    
    return 0;
}

INFO