Exemplo n.º 1
0
int GetVoxel(vec3 voxel)
{
	ivec3 arrayIndex;
	if(GetArrayIndex(voxel, arrayIndex))
	{
		return int(floor(texelFetch(data, arrayIndex, 0).g * 255));
	}

	return 255; // Return vacuum if block is invalid
}
Exemplo n.º 2
0
// Adds events to the event list from a file
void AddEventsFromFile( const char *fileName )
{
  char buffer[256];

  FILE *fp = fopen( fileName, "r" );

  Event *e;

  // Read first token
  fscanf( fp, "%s%*c", buffer );

  if(fp)
    while(!feof( fp ))
    {
      // Start a new event
      if(StringsMatch( buffer, "Conditions" ))
      {
        // Malloc a new event
        e = (Event *)malloc( sizeof( Event ) );
        e->actions = NULL;
        e->conditions = NULL;

        // Read in conditions
        for(;;)
        {
          int index;
          Condition *c;
          fscanf( fp, "%s%*c", buffer );

          // Should never hit end of file while reading conditions
          if(feof( fp ))
            assert( NULL );

          index = GetArrayIndex( ConditionArray, buffer );

          // String in buffer did not match any conditions
          if(index == NOT_FOUND)
            break;

          c = (Condition *)malloc( sizeof( Condition ) );

          // Insert condition into event
          c->next = e->conditions;
          e->conditions = c;
          c->cb = ConditionPtrs[index];

          // Read parameters for condition
          ReadCParamPtrs[index]( fp, c );

          // Set cleanup function
          c->clean = ConditionCleanups[index];
        }
      }

      if(StringsMatch( buffer, "Actions" ))
      {
        // Read in actions
        for(;;)
        {
          int index;
          Action *a;
          fscanf( fp, "%s%*c", buffer );

          // Break if we are at end of file
          if(feof( fp ))
            break;

          index = GetArrayIndex( ActionArray, buffer );

          // String in buffer did not match any actions
          if(index == NOT_FOUND)
            break;

          a = (Action *)malloc( sizeof( Action ) );

          // Insert action into event
          a->next = e->actions;
          e->actions = a;
          a->cb = ActionPtrs[index];
          
          // Read parameters for action
          ReadAParamPtrs[index]( fp, a );

          // Set cleanup function
          a->clean = ActionCleanups[index];
        }

        // Insert event into event list
        EventListAdd( e );
      }
    }
}