Thread: Any types missed?

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735

    Any types missed?

    I'm writing an expression handler so that I can auto-detect symbols in my shaders by processing the #ifdef, #if, #elif and #else statements (and plan to implement a #'include statement so I can generate the needed code instead of passing directly to the shaders which is the current method), here's what I have for defined types etc, any types I missed at all?

    Code:
    typedef enum _ENUM_C_OPERATORS
    {
    	COP_NIL = 0,
    	COP_ONT = '?',
    	COP_ONF = ':',
    	COP_NEL = ',',
    	COP_END = ';',
    	COP_TYPE_VEC2 = 'v' | ('e' << 8) | ('c' << 16) | ('2' << 24),
    	COP_TYPE_VEC3 = 'v' | ('e' << 8) | ('c' << 16) | ('3' << 24),
    	COP_TYPE_VEC4 = 'v' | ('e' << 8) | ('c' << 16) | ('4' << 24),
    	COP_TYPE_MAT2 = 'm' | ('a' << 8) | ('t' << 16) | ('2' << 24),
    	COP_TYPE_MAT3 = 'm' | ('a' << 8) | ('t' << 16) | ('3' << 24),
    	COP_TYPE_MAT4 = 'm' | ('a' << 8) | ('t' << 16) | ('4' << 24),
    	COP_EXPR_OPEN = '(',
    	COP_EXPR_SHUT = ')',
    	COP_CODE_OPEN = '{',
    	COP_CODE_SHUT = '}',
    	/* Bitwise Symbols */
    	COP_BWN = '~',
    	COP_BWA = '&',
    	COP_BAE = '&' | ('=' << 8),
    	COP_BWO = '|',
    	COP_BOE = '|' | ('=' << 8),
    	COP_BWX = '^',
    	COP_BXE = '^' | ('=' << 8),
    	COP_SHL = '<' | ('<' << 8),
    	COP_SLE = '<' | ('<' << 8) | ('=' << 16),
    	COP_SHR = '>' | ('>' << 8),
    	COP_SRE = '>' | ('>' << 8) | ('=' << 16),
    	/* Comparison Symbols */
    	COP_NOT = '!',
    	COP_EQL = '=' | ('=' << 8),
    	COP_NEQ = '!' | ('=' << 8),
    	COP_GTH = '>',
    	COP_GTE = '>' | ('=' << 8),
    	COP_LTH = '<',
    	COP_LTE = '<' | ('=' << 8),
    	/* Math Symbols */
    	COP_ADD = '+',
    	COP_ADE = '+' | ('=' << 8),
    	COP_INC = '+' | ('+' << 8),
    	COP_SUB = '-',
    	COP_SUE = '-' | ('=' << 8),
    	COP_DEC = '-' | ('-' << 8),
    	COP_MUL = '*',
    	COP_MUE = '*' | ('=' << 8),
    	COP_DIV = '/',
    	COP_DIE = '/' | ('=' << 8),
    	COP_MOD = '%',
    	COP_MOE = '%' | ('=' << 8),
    } ENUM_C_OPERATORS;
    
    typedef enum _ENUM_INTEGRALS
    {
    	CIN_INT = 0,
    	/* Floating Point Numbers */
    	CIN_F = 'F',
    	CIN_D = 'D',
    	CIN_LD = 'L' | ('D' << 8),
    	/* Integers */
    	CIN_U = 'U',
    	CIN_L = 'L',
    	CIN_UL = 'U' | ('L' << 8),
    	CIN_LL = 'L' | ('L' << 8),
    	CIN_ULL = 'U' | ('L' << 8) | ('L' << 16),
    	/* Why these aren't already a standard I don't know but might as well lead
    	 * by example */
    	CIN_HH = 'H' | ('H' << 8),
    	CIN_UHH = 'U' | ('H' << 8) | ('H' << 16),
    	CIN_H = 'H',
    	CIN_UH = 'U' | ('H' << 8),
    	CIN_J = 'J',
    	CIN_UJ = 'U' | ('J' << 8),
    	CIN_P = 'P',
    	CIN_UP = 'U' | ('P' << 8),
    	CIN_Z = 'Z',
    	CIN_UZ = 'U' | ('Z' << 8)
    #if 0
    	/* specific with integers */
    	CIN_I = 'I'
    #endif
    } ENUM_INTEGRALS;
    
    typedef union _INTEGRAL
    {
    	long double ld;
    	double d;
    	float f;
    	uintmax_t uj;
    	intmax_t j;
    	uintptr_t up;
    	intptr_t p;
    	size_t uz;
    	ssize_t z;
    	ullong ull;
    	dllong ll;
    	ulong ul;
    	dlong l;
    	uint u;
    	dint i;
    	ushort uh;
    	dshort h;
    	dchar hh;
    	uchar uhh;
    } INTEGRAL;

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    By the lack of replies I'll take it that I haven't missed anything, instead while I figure out how best to add the matrix & vertex support to my math handlers I let others see if they have any suggestions for the main code (attached).
    Attached Files Attached Files

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Unless anyone has a better idea this is what I'm going with for retrieving vectors & matrices:
    Code:
    dint OpGet( GFX *gc, GFXR *This, u32 type, INTEGRAL *list, uint num )
    {
    	uint i;
    
    	for ( i = 0; i < num && This; )
    	{
    		dint n = 1;
    
    		if ( type < This->type )
    				return -1;
    
    		if ( This->type >= IVT_MAT2 )
    		{
    			n = (This->type - IVT_MAT2) + 2;
    			n *= n;
    		}
    		else if ( This->type >= IVT_VEC2 )
    			n =  (This->type - IVT_VEC2) + 2;
    
    		if ( num < (n + i) )
    			return -1;
    
    		if ( This->type < IVT_VEC2 )if ( This->type < IVT_VEC2 )
    			list[i++] = This->Value;
    		else
    		{
    			OpGet( gc, GrabGfxRecipe( gc, This->InitId ), list + i, n );
    			i += n;
    		}
    
    		This = GrabGfxRecipe( This->NextId );
    	}
    
    	return 0;
    }
    I'll use a different function for passing these integerals into a cglm vec4/mat4, I can fob off the math thereafter.

    Edit: Noticed after posting that I forgot to change the "This" pointer each loop, corrected the above code to match the fix

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Turns out cglm doesn't yet have the functions I need so supplementing with my own code for now, is this right for matrix/vector addition? Also if this is right then is this the same way for the other operations (minus, multiply & division)?
    Code:
    	OpGetMat( listA, Arows, Acols, matA );
    	OpGetMat( listB, Brows, Bcols, matB );
    
    	if ( type >= IVT_MAT2 )
    	{
    		if ( B->type == type )
    		{
    			for ( r = 0; r < Arows; ++r )
    			{
    				for ( c = 0; c < Acols; ++c )
    				{
    					uint i = (r * Acols) + c;
    					matA[i] += matB[i];
    				}
    			}
    		}
    		else if ( B->type == type - 3 )
    		{
    			for ( r = 0; r < Arows; ++r )
    			{
    				for ( c = 0; c < Acols; ++c )
    				{
    					uint i = (r * Acols) + c;
    					matA[i] += matB[c];
    				}
    			}
    		}
    		else
    		{
    			for ( r = 0; r < Arows; ++r )
    			{
    				for ( c = 0; c < Acols; ++c )
    				{
    					uint i = (r * Acols) + c;
    					matA[i] += matB[0];
    				}
    			}
    		}
    	}
    	else if ( type >= IVT_VEC2 )
    	{
    		if ( B->type == type )
    		{
    			for ( c = 0; c < Acols; ++c )
    				matA[c] += matB[c];
    		}
    		else
    		{
    			for ( c = 0; c < Acols; ++c )
    				matA[c] += matB[0];
    		}
    	}
    
    	FreeGfxRecipe( gc, A->ResultId );
    	A->ResultId = OpSetMat( gc, Arows, Acols, matC );

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Just finished verifying my code produces the correct results of the expressions I put it, I lack imagination however so I'd like to ask you lot to build it then test it, I only set up the makefile for linux but I don't think I used any linux specific code so feel free to adapt to a windows build if you want, shouldn't take anything more than 5min (accounting for downloading a build of cglm). Once built just run it with "--test-recipe='<your recipe>'" as an argument, for vertex/matrix math I just did a copy paste of the code from addition and then swapped out the + operator for the matching operator, let me know if anything there produces incorrect results (assuming it works at all, didn't test that yet as I haven't though of any tests for it yet).

    (1bed0829) * Commits * Dragonbuilder * GitLab

  6. #6
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Judging by the lack of replies noone was inclined to even provide example recipes with expected outputs for me to try, that's disappointing but not the end of the world, sooner or later I'll try processing the shaders directly to see what breaks before I start using the handler prior to compiling.

    Anyways on the off chance some people are later inclined here's an update that includes a fix to subtraction (I forgot to replace + with - on that one handler):
    Files * d2bcdb2ee5fb897ba2ac2ea24bf2dcf1e2b25d98 * Lee Shallis / Dragonbuilder * GitLab

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1st bit being missed
    By awsdert in forum C Programming
    Replies: 1
    Last Post: 07-12-2019, 05:38 PM
  2. need help on finding what i missed!
    By Masterx in forum C Programming
    Replies: 13
    Last Post: 06-21-2009, 09:23 PM
  3. We missed REALLY big day (by about 17 hours)
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-20-2005, 07:53 PM
  4. ok i think i missed the memo
    By kl3pt0 in forum C Programming
    Replies: 27
    Last Post: 06-12-2004, 06:11 PM
  5. Hello everyone - Bubba has missed all of you
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 01-20-2003, 09:33 AM

Tags for this Thread