Beispiel #1
0
bool EntityClassDoom3_parseUnknown( Tokeniser& tokeniser ){
	//const char* name =
	PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );

	//globalOutputStream() << "parsing unknown block " << makeQuoted(name) << "\n";

	PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, "{" ) );
	tokeniser.nextLine();

	std::size_t depth = 1;
	for (;; )
	{
		const char* token;
		PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) );
		if ( string_equal( token, "}" ) ) {
			if ( --depth == 0 ) {
				tokeniser.nextLine();
				break;
			}
		}
		else if ( string_equal( token, "{" ) ) {
			++depth;
		}
		tokeniser.nextLine();
	}
	return true;
}
Beispiel #2
0
void Map_Read(scene::Node& root, Tokeniser& tokeniser, EntityCreator& entityTable, const PrimitiveParser& parser)
{
  int count_entities = 0;
  for(;;)
  {
    tokeniser.nextLine();
    if (!tokeniser.getToken()) // { or 0
		  break;

    NodeSmartReference entity(Entity_parseTokens(tokeniser, entityTable, parser, count_entities));

    if(entity == g_nullNode)
    {
      globalErrorStream() << "entity " << count_entities << ": parse error\n";
      return;
    }

    Node_getTraversable(root)->insert(entity);

    ++count_entities;
  }
}
Beispiel #3
0
static bool EntityClass_parse( EntityClass& entityClass, Tokeniser& tokeniser ){
	PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, entityClass.m_name ) );

	PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, "{" ) );
	tokeniser.nextLine();

	StringOutputStream usage( 256 );
	StringOutputStream description( 256 );
	CopiedString* currentDescription = 0;
	StringOutputStream* currentString = 0;

	for (;; )
	{
		const char* key;
		PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, key ) );

		const char* last = string_findFirstSpaceOrTab( key );
		CopiedString first( StringRange( key, last ) );

		if ( !string_empty( last ) ) {
			last = string_findFirstNonSpaceOrTab( last );
		}

		if ( currentString != 0 && string_equal( key, "\\" ) ) {
			tokeniser.nextLine();
			*currentString << " ";
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, *currentString ) );
			continue;
		}

		if ( currentDescription != 0 ) {
			*currentDescription = description.c_str();
			description.clear();
			currentDescription = 0;
		}
		currentString = 0;

		if ( string_equal( key, "}" ) ) {
			tokeniser.nextLine();
			break;
		}
		else if ( string_equal( key, "model" ) ) {
			const char* token;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) );
			entityClass.fixedsize = true;
			StringOutputStream buffer( 256 );
			buffer << PathCleaned( token );
			entityClass.m_modelpath = buffer.c_str();
		}
		else if ( string_equal( key, "editor_color" ) ) {
			const char* value;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) );
			if ( !string_empty( value ) ) {
				entityClass.colorSpecified = true;
				bool success = string_parse_vector3( value, entityClass.color );
				ASSERT_MESSAGE( success, "editor_color: parse error" );
			}
		}
		else if ( string_equal( key, "editor_ragdoll" ) ) {
			//bool ragdoll = atoi(tokeniser.getToken()) != 0;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
		}
		else if ( string_equal( key, "editor_mins" ) ) {
			entityClass.sizeSpecified = true;
			const char* value;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) );
			if ( !string_empty( value ) && !string_equal( value, "?" ) ) {
				entityClass.fixedsize = true;
				bool success = string_parse_vector3( value, entityClass.mins );
				ASSERT_MESSAGE( success, "editor_mins: parse error" );
			}
		}
		else if ( string_equal( key, "editor_maxs" ) ) {
			entityClass.sizeSpecified = true;
			const char* value;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) );
			if ( !string_empty( value ) && !string_equal( value, "?" ) ) {
				entityClass.fixedsize = true;
				bool success = string_parse_vector3( value, entityClass.maxs );
				ASSERT_MESSAGE( success, "editor_maxs: parse error" );
			}
		}
		else if ( string_equal( key, "editor_usage" ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, usage ) );
			currentString = &usage;
		}
		else if ( string_equal_n( key, "editor_usage", 12 ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, usage ) );
			currentString = &usage;
		}
		else if ( string_equal( key, "editor_rotatable" )
				  || string_equal( key, "editor_showangle" )
				  || string_equal( key, "editor_showangles" ) // typo? in prey movables.def
				  || string_equal( key, "editor_mover" )
				  || string_equal( key, "editor_model" )
				  || string_equal( key, "editor_material" )
				  || string_equal( key, "editor_combatnode" )
				  || ( !string_empty( last ) && string_equal( first.c_str(), "editor_gui" ) )
				  || string_equal_n( key, "editor_copy", 11 ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
		}
		else if ( !string_empty( last ) && ( string_equal( first.c_str(), "editor_var" ) || string_equal( first.c_str(), "editor_string" ) ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "string";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_float" ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "string";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_snd" ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "sound";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_bool" ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "boolean";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_int" ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "integer";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_model" ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "model";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_color" ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "color";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( !string_empty( last ) && ( string_equal( first.c_str(), "editor_material" ) || string_equal( first.c_str(), "editor_mat" ) ) ) {
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second;
			attribute.m_type = "shader";
			currentDescription = &attribute.m_description;
			currentString = &description;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) );
		}
		else if ( string_equal( key, "inherit" ) ) {
			entityClass.inheritanceResolved = false;
			ASSERT_MESSAGE( entityClass.m_parent.empty(), "only one 'inherit' supported per entityDef" );
			const char* token;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) );
			entityClass.m_parent.push_back( token );
		}
		// begin quake4-specific keys
		else if ( string_equal( key, "editor_targetonsel" ) ) {
			//const char* value =
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
		}
		else if ( string_equal( key, "editor_menu" ) ) {
			//const char* value =
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
		}
		else if ( string_equal( key, "editor_ignore" ) ) {
			//const char* value =
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
		}
		// end quake4-specific keys
		// begin ignore prey (unknown/unused?) entity keys
		else if ( string_equal( key, "editor_light" )
				  || string_equal( key, "editor_def def_debrisspawner" )
				  || string_equal( key, "editor_def def_drop" )
				  || string_equal( key, "editor_def def_guihand" )
				  || string_equal( key, "editor_def def_mine" ) ) {
			//const char* value =
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
		}
		// end ignore prey entity keys
		else
		{
			CopiedString tmp( key );
			if ( string_equal_n( key, "editor_", 7 ) ) {
				globalErrorStream() << "unsupported editor key " << makeQuoted( key ) ;
			}
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, key ).second;
			attribute.m_type = "string";
			const char* value;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) );
			if ( string_equal( value, "}" ) ) { // hack for quake4 powerups.def bug
				globalErrorStream() << "entityDef " << makeQuoted( entityClass.m_name.c_str() ) << " key " << makeQuoted( tmp.c_str() ) << " has no value\n";
				break;
			}
			else
			{
				attribute.m_value = value;
			}
		}
		tokeniser.nextLine();
	}

	entityClass.m_comments = usage.c_str();

	if ( string_equal( entityClass.m_name.c_str(), "light" ) ) {
		{
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "light_radius" ).second;
			attribute.m_type = "vector3";
			attribute.m_value = "300 300 300";
		}
		{
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "light_center" ).second;
			attribute.m_type = "vector3";
		}
		{
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "noshadows" ).second;
			attribute.m_type = "boolean";
			attribute.m_value = "0";
		}
		{
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "nospecular" ).second;
			attribute.m_type = "boolean";
			attribute.m_value = "0";
		}
		{
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "nodiffuse" ).second;
			attribute.m_type = "boolean";
			attribute.m_value = "0";
		}
		{
			EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "falloff" ).second;
			attribute.m_type = "real";
		}
	}

	return true;
}
Beispiel #4
0
bool EntityClassDoom3_parseModel( Tokeniser& tokeniser ){
	const char* name;
	PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, name ) );

	Model& model = g_models[name];

	PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, "{" ) );
	tokeniser.nextLine();

	for (;; )
	{
		const char* parameter;
		PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, parameter ) );
		if ( string_equal( parameter, "}" ) ) {
			tokeniser.nextLine();
			break;
		}
		else if ( string_equal( parameter, "inherit" ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, model.m_parent ) );
			tokeniser.nextLine();
		}
		else if ( string_equal( parameter, "remove" ) ) {
			//const char* remove =
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
			tokeniser.nextLine();
		}
		else if ( string_equal( parameter, "mesh" ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, model.m_mesh ) );
			tokeniser.nextLine();
		}
		else if ( string_equal( parameter, "skin" ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, model.m_skin ) );
			tokeniser.nextLine();
		}
		else if ( string_equal( parameter, "offset" ) ) {
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, "(" ) );
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, ")" ) );
			tokeniser.nextLine();
		}
		else if ( string_equal( parameter, "channel" ) ) {
			//const char* channelName =
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) );
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, "(" ) );
			for (;; )
			{
				const char* end;
				PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, end ) );
				if ( string_equal( end, ")" ) ) {
					tokeniser.nextLine();
					break;
				}
			}
		}
		else if ( string_equal( parameter, "anim" ) ) {
			CopiedString animName;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, animName ) );
			const char* animFile;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, animFile ) );
			model.m_anims.insert( Model::Anims::value_type( animName, animFile ) );

			const char* token;
			PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) );

			while ( string_equal( token, "," ) )
			{
				PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, animFile ) );
				PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) );
			}

			if ( string_equal( token, "{" ) ) {
				for (;; )
				{
					const char* end;
					PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, end ) );
					if ( string_equal( end, "}" ) ) {
						tokeniser.nextLine();
						break;
					}
					tokeniser.nextLine();
				}
			}
			else
			{
				tokeniser.ungetToken();
			}
		}
		else
		{
			globalErrorStream() << "unknown model parameter: " << makeQuoted( parameter ) << "\n";
			return false;
		}
		tokeniser.nextLine();
	}
	return true;
}
Beispiel #5
0
NodeSmartReference Entity_parseTokens(Tokeniser& tokeniser, EntityCreator& entityTable, const PrimitiveParser& parser, int index)
{
  NodeSmartReference entity(g_nullNode);
  KeyValues keyValues;
  const char* classname = "";

  int count_primitives = 0;
  while(1)
  {
    tokeniser.nextLine();
    const char* token = tokeniser.getToken();
    if(token == 0)
    {
      Tokeniser_unexpectedError(tokeniser, token, "#entity-token");
      return g_nullNode;
    }
    if (!strcmp(token, "}")) // end entity
    {
      if(entity == g_nullNode)
      {
        // entity does not have brushes
        entity = Entity_create(entityTable, GlobalEntityClassManager().findOrInsert(classname, false), keyValues);
      }
      return entity;
    }
    else if(!strcmp(token, "{")) // begin primitive
    {
      if(entity == g_nullNode)
      {
        // entity has brushes
        entity = Entity_create(entityTable, GlobalEntityClassManager().findOrInsert(classname, true), keyValues);
      }

      tokeniser.nextLine();

      NodeSmartReference primitive(parser.parsePrimitive(tokeniser));
      if(primitive == g_nullNode || !Node_getMapImporter(primitive)->importTokens(tokeniser))
      {
        globalErrorStream() << "brush " << count_primitives << ": parse error\n";
        return g_nullNode;
      }

      scene::Traversable* traversable = Node_getTraversable(entity);
      if(Node_getEntity(entity)->isContainer() && traversable != 0)
      {
        traversable->insert(primitive);
      }
      else
      {
        globalErrorStream() << "entity " << index << ": type " << classname << ": discarding brush " << count_primitives << "\n";
      }
      ++count_primitives;
    }
    else // epair
    {
      CopiedString key(token);
      token = tokeniser.getToken();
      if(token == 0)
      {
        Tokeniser_unexpectedError(tokeniser, token, "#epair-value");
        return g_nullNode;
      }
      keyValues.push_back(KeyValues::value_type(key, token));
      if(string_equal(key.c_str(), "classname"))
      {
        classname = keyValues.back().second.c_str();
      }
    }
  }
  // unreachable code
  return g_nullNode;
}