// stack.inc // by Rainer Mager - Copyright 1998 // // Feel free to use, mangle, and modify this to your hearts content. // I'd like credit if it seems appropriate when using this. // // A stack - as in the programming logical structure. // /* Usage: // first include the file #include "stack.inc" // then initialize your stacks Stack( "any_name" ) Stack( "any_other_name" ) // then push data Push( "any_name", colPoint ) Push( "any_other_name", (<1,0.5,0.5> + BallsColor[id]) / 2 ) // then pop data #local my1 = 0; #local my2 = <0,0,0>; #while( Pop( "any_name", my1 ) ) // note: you DO need these tmp variable or POV complains #local tmp = Pop( "any_other_name", my2 ); #end */ #declare STACK_DEBUG = 0; #declare StacksNames = array[1] #declare StacksPos = array[1] #declare StacksMax = array[1] #declare StacksValue = array[1] #declare StacksNum = 0; #macro Push( stack, value ) #local i = 0; #while( i < StacksNum ) // if this is the stack in question #if( strcmp( stack, StacksNames[i] ) = 0 ) #if( StacksPos[i] = StacksMax[i] ) #local temp = array[StacksMax[i] + 1] #local temp = StacksValue[i] // #undef StacksValue[i] #declare StacksValue[i] = array[StacksMax[i] + 10] #local j = 0; #while( j < StacksMax[i] ) #declare StacksValue[i][j] = temp[j]; #local j = j + 1; #end #declare StacksMax[i] = StacksMax[i] + 10; #end #if( STACK_DEBUG > 0 ) #render concat( "Pushed a value onto stack \"", stack, "\" at position ", str(StacksPos[i],0,0), "\n" ) #end #declare StacksValue[i][StacksPos[i]] = value; #declare StacksPos[i] = StacksPos[i] + 1; #local i = StacksNum; #end #local i = i + 1; #end #end #macro Pop( stack, value ) #if( STACK_DEBUG > 0 ) #render concat( "Popped a value from stack \"", stack, "\" " ) #end #local returnVal = true; #local i = 0; #while( i < StacksNum ) // if this is the stack in question #if( strcmp( stack, StacksNames[i] ) = 0 ) #if( StacksPos[i] = 0 ) #local returnVal = false; #local i = StacksNum; #else #render concat( "from position ", str(StacksPos[i],0,0), "\n" ) #declare StacksPos[i] = StacksPos[i] - 1; #local value = StacksValue[i][StacksPos[i]]; #local i = StacksNum; #end #end #local i = i + 1; #end (returnVal) #end #macro Stack( stack ) #if( STACK_DEBUG > 0 ) #render concat( "Initialized stack ", stack, ", stack# ", str(StacksNum, 0, 0), "\n" ) #end // if we can add another stack #if( mod(StacksNum, 10) != 0 ) #declare StacksNames[StacksNum] = stack #declare StacksPos[StacksNum] = 0; #declare StacksMax[StacksNum] = 0; #declare StacksValue[StacksNum] = array[1] #else // else we need to increase the total stacks #local temp1 = array[StacksNum + 1] #local temp1 = StacksNames #local temp2 = array[StacksNum + 1] #local temp2 = StacksPos #local temp3 = array[StacksNum + 1] #local temp3 = StacksMax #local temp4 = array[StacksNum + 1] #local temp4 = StacksValue #undef StacksNames #declare StacksNames = array[StacksNum + 10] #undef StacksPos #declare StacksPos = array[StacksNum + 10] #undef StacksMax #declare StacksMax = array[StacksNum + 10] #undef StacksValue #declare StacksValue = array[StacksNum + 10] #local i = 0; #while( i < StacksNum ) #declare StacksNames[i] = temp1[i]; #declare StacksPos[i] = temp2[i]; #declare StacksMax[i] = temp3[i]; #declare StacksValue[i] = temp4[i]; #local i = i + 1; #end // and then init the stack #declare StacksNames[StacksNum] = stack #declare StacksPos[StacksNum] = 0; #declare StacksMax[StacksNum] = 0; #declare StacksValue[StacksNum] = array[1] #end #declare StacksNum = StacksNum + 1; #end