Ejemplo n.º 1
0
bool EntityClassDoom3_parseEntityDef( Tokeniser& tokeniser ){
	EntityClass* entityClass = Eclass_Alloc();
	entityClass->free = &Eclass_Free;

	if ( !EntityClass_parse( *entityClass, tokeniser ) ) {
		eclass_capture_state( entityClass ); // finish constructing the entity so that it can be destroyed cleanly.
		entityClass->free( entityClass );
		return false;
	}

	EntityClass* inserted = EntityClassDoom3_insertUnique( entityClass );
	if ( inserted != entityClass ) {
		globalErrorStream() << "entityDef " << entityClass->name() << " is already defined, second definition ignored\n";
		eclass_capture_state( entityClass ); // finish constructing the entity so that it can be destroyed cleanly.
		entityClass->free( entityClass );
	}
	return true;
}
Ejemplo n.º 2
0
void realise(){
	if ( --m_unrealised == 0 ) {
		globalOutputStream() << "searching vfs directory " << makeQuoted( "def" ) << " for *.def\n";
		GlobalFileSystem().forEachFile( "def/", "def", makeCallbackF(EntityClassDoom3_loadFile) );

		{
			for ( Models::iterator i = g_models.begin(); i != g_models.end(); ++i )
			{
				Model_resolveInheritance( ( *i ).first.c_str(), ( *i ).second );
			}
		}
		{
			for ( EntityClasses::iterator i = g_EntityClassDoom3_classes.begin(); i != g_EntityClassDoom3_classes.end(); ++i )
			{
				EntityClass_resolveInheritance( ( *i ).second );
				if ( !string_empty( ( *i ).second->m_modelpath.c_str() ) ) {
					Models::iterator j = g_models.find( ( *i ).second->m_modelpath );
					if ( j != g_models.end() ) {
						( *i ).second->m_modelpath = ( *j ).second.m_mesh;
						( *i ).second->m_skin = ( *j ).second.m_skin;
					}
				}
				eclass_capture_state( ( *i ).second );

				StringOutputStream usage( 256 );

				usage << "-------- NOTES --------\n";

				if ( !string_empty( ( *i ).second->m_comments.c_str() ) ) {
					usage << ( *i ).second->m_comments.c_str() << "\n";
				}

				usage << "\n-------- KEYS --------\n";

				for ( EntityClassAttributes::iterator j = ( *i ).second->m_attributes.begin(); j != ( *i ).second->m_attributes.end(); ++j )
				{
					const char* name = EntityClassAttributePair_getName( *j );
					const char* description = EntityClassAttributePair_getDescription( *j );
					if ( !string_equal( name, description ) ) {
						usage << EntityClassAttributePair_getName( *j ) << " : " << EntityClassAttributePair_getDescription( *j ) << "\n";
					}
				}

				( *i ).second->m_comments = usage.c_str();
			}
		}

		m_observers.realise();
	}
}
Ejemplo n.º 3
0
/**
 * Creates a new entityclass for given parsed definition
 * @param entityDef parsed definition information to use
 * @return a new entity class or 0 if something was wrong with definition
 */
EntityClass *EntityClassScannerUFO::initFromDefinition (const entityDef_t* definition)
{
	g_debug("Creating entity class for entity definition '%s'\n", definition->classname);

	EntityClass* e = Eclass_Alloc();
	e->free = &Eclass_Free;
	e->m_name = definition->classname;

	for (int idx = 0; idx < definition->numKeyDefs; idx++) {
		const entityKeyDef_t* keydef = &definition->keyDefs[idx];
		const std::string keyName = keydef->name;

		if (keyName == "color") {
			//not using _color as this is a valid attribute flag
			// grab the color, reformat as texture name
			const int r = sscanf(keydef->desc, "%f %f %f", &e->color[0], &e->color[1], &e->color[2]);
			if (r != 3) {
				g_message("Invalid color token given\n");
				return 0;
			}
		} else if (keyName == "size") {
			e->fixedsize = true;
			const int r = sscanf(keydef->desc, "%f %f %f %f %f %f", &e->mins[0], &e->mins[1], &e->mins[2], &e->maxs[0],
					&e->maxs[1], &e->maxs[2]);
			if (r != 6) {
				g_message("Invalid size token given\n");
				return 0;
			}
		} else if (keyName == "description") {
			e->m_comments = keydef->desc;
		} else if (keyName == "spawnflags") {
			if (keydef->flags & ED_ABSTRACT) {
				/* there are two keydefs, abstract holds the valid levelflags, the other one default value and type */
				const char* flags = keydef->desc;
				parseFlags(e, &flags);
			} else {
				parseAttribute(e, keydef);
			}
		} else if (keyName == "classname") {
			/* ignore, read from head */
			continue;
		} else if (keyName == "model") {
			/** @todo what does that modelpath stuff do? it does not read anything from keydef */
			e->m_modelpath = os::standardPath(e->m_modelpath);
			const bool mandatory = (keydef->flags & ED_MANDATORY);
			EntityClass_insertAttribute(*e, "model", EntityClassAttribute("model", "model", mandatory));
		} else {
			/* all other keys are valid attribute keys */
			parseAttribute(e, keydef);
		}
	}

#if 0
	/**
	 * @todo direction and angle are 2 types used for different display
	 * (see entityinspector DirectionAttribute and AngleAttribute)
	 * the problem is that different entities have "angle" property, but different defines what values are valid
	 * which is actually not reflected by this code. Perhaps we should introduce different types for these representations.
	 */
	EntityClassAttribute *angle = e->getAttribute("angle");
	if (angle) {
		if (e->fixedsize) {
			angle->name = _("Yaw Angle");
		} else {
			angle->name = _("Direction");
		}
	}
#endif
	eclass_capture_state(e);

	return e;
}