Пример #1
0
void Entity_setColour(){
	if ( GlobalSelectionSystem().countSelected() != 0 ) {
		const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path();
		Entity* entity = Node_getEntity( path.top() );

		if( entity == 0 && path.size() == 3 ){
			entity = Node_getEntity( path.parent() );
		}

		if ( entity != 0 ) {
			const char* strColor = entity->getKeyValue( "_color" );
			if ( !string_empty( strColor ) ) {
				Vector3 rgb;
				if ( string_parse_vector3( strColor, rgb ) ) {
					g_entity_globals.color_entity = rgb;
				}
			}
			if ( color_dialog( GTK_WIDGET( MainFrame_getWindow() ), g_entity_globals.color_entity ) ) {
				char buffer[128];
				sprintf( buffer, "%g %g %g", g_entity_globals.color_entity[0],
						 g_entity_globals.color_entity[1],
						 g_entity_globals.color_entity[2] );

				StringOutputStream command( 256 );
				command << "entitySetColour " << buffer;
				UndoableCommand undo( command.c_str() );
				Scene_EntitySetKeyValue_Selected( "_color", buffer );
			}
		}
	}
}
Пример #2
0
inline Entity* ScenePath_getEntity (const scene::Path& path)
{
	Entity* entity = Node_getEntity(path.top());
	if (entity == 0) {
		entity = Node_getEntity(path.parent());
	}
	return entity;
}
Пример #3
0
	virtual void visit(const scene::INodePtr& node) const {
		Entity* entity = Node_getEntity(node);

		if (entity != NULL) {
			_classnames.push_back(entity->getKeyValue("classname"));
		}
	}
Пример #4
0
	bool pre(const scene::INodePtr& node) {
		// Don't traverse hidden nodes
		if (!node->visible()) {
			return false;
		}
		
		SelectablePtr selectable = Node_getSelectable(node);

		// ignore worldspawn
		Entity* entity = Node_getEntity(node);
		if (entity != NULL) {
			if (entity->getKeyValue("classname") == "worldspawn") {
				return true;
			}
		}
    
    	bool selected = false;
    
		if (selectable != NULL && node->getParent() != NULL && !node->isRoot()) {
			for (std::size_t i = 0; i < _count; ++i) {
				// Check if the selectable passes the AABB test
				if (policy.evaluate(_aabbs[i], node)) {
					selectable->setSelected(true);
					selected = true;
					break;
				}
			}
		}
	
		// Only traverse the children of this node, if the node itself couldn't be selected
		return !selected;
	}
Пример #5
0
void DEntity::BuildInRadiant( bool allowDestruction ){
	bool makeEntity = strcmp( m_Classname, "worldspawn" ) ? true : false;

	if ( makeEntity ) {
		NodeSmartReference node( GlobalEntityCreator().createEntity( GlobalEntityClassManager().findOrInsert( m_Classname.GetBuffer(), !brushList.empty() || !patchList.empty() ) ) );

		for ( std::list<DEPair* >::const_iterator buildEPair = epairList.begin(); buildEPair != epairList.end(); buildEPair++ )
		{
			Node_getEntity( node )->setKeyValue( ( *buildEPair )->key, ( *buildEPair )->value );
		}

		Node_getTraversable( GlobalSceneGraph().root() )->insert( node );

		for ( std::list<DBrush *>::const_iterator buildBrush = brushList.begin(); buildBrush != brushList.end(); buildBrush++ )
			( *buildBrush )->BuildInRadiant( allowDestruction, NULL, node.get_pointer() );

		for ( std::list<DPatch *>::const_iterator buildPatch = patchList.begin(); buildPatch != patchList.end(); buildPatch++ )
			( *buildPatch )->BuildInRadiant( node.get_pointer() );

		QER_Entity = node.get_pointer();
	}
	else
	{
		for ( std::list<DBrush *>::const_iterator buildBrush = brushList.begin(); buildBrush != brushList.end(); buildBrush++ )
			( *buildBrush )->BuildInRadiant( allowDestruction, NULL );

		for ( std::list<DPatch *>::const_iterator buildPatch = patchList.begin(); buildPatch != patchList.end(); buildPatch++ )
			( *buildPatch )->BuildInRadiant();
	}
}
Пример #6
0
scene::INodePtr Doom3EntityCreator::createEntity(const IEntityClassPtr& eclass) {
    scene::INodePtr node = getEntityForEClass(eclass);
    Entity* entity = Node_getEntity(node);
    assert(entity != NULL);

    entity->setKeyValue("classname", eclass->getName());

    // If this is not a worldspawn or unrecognised entity, generate a unique
    // name for it
    const std::string& eclassName = eclass->getName();

    if (!eclassName.empty() &&
            eclassName != "worldspawn" &&
            eclassName != "UNKNOWN_CLASS")
    {
        /* Clean up the name of the entity that is about the created
         * so that nothing bad can happen (for example, the colon character
         * seems to be causing problems in Doom 3 Scripting)
         */
        std::string entityName =
            boost::algorithm::replace_all_copy(eclassName, ":", "_") + "_1";

        entity->setKeyValue("name", entityName);
    }

    return node;
}
Пример #7
0
void ScriptEntityNode::forEachKeyValue(Entity::Visitor& visitor) {
	Entity* entity = Node_getEntity(*this);

	if (entity != NULL) {
		entity->forEachKeyValue(visitor);
	}
}
Пример #8
0
bool MapImporter::addPrimitiveToEntity(const scene::INodePtr& primitive, const scene::INodePtr& entity)
{
	_nodes.insert(NodeMap::value_type(
		NodeIndexPair(_entityCount, _primitiveCount), primitive));

	_primitiveCount++;

	if (_dialog && _dialogEventLimiter.readyForEvent())
    {
		_dialog->setTextAndFraction(
            _dlgEntityText + "Primitive " + string::to_string(_primitiveCount),
			getProgressFraction()
        );
    }

	if (Node_getEntity(entity)->isContainer())
	{
		entity->addChildNode(primitive);
		return true;
	}
	else
	{
		return false;
	}
}
Пример #9
0
void Entity_setColour()
{
  if(GlobalSelectionSystem().countSelected() != 0)
  {
    const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path();
    Entity* entity = Node_getEntity(path.top());
    if(entity != 0)
    {
      const char* strColor = entity->getKeyValue("_color");
      if(!string_empty(strColor))
      {
        Vector3 rgb;
        if (string_parse_vector3(strColor, rgb))
        {
          g_entity_globals.color_entity = rgb;
        }
      }

      if(g_pGameDescription->mGameType == "doom3"
        ? color_dialog(GTK_WIDGET(MainFrame_getWindow()), g_entity_globals.color_entity)
        : DoNormalisedColor(g_entity_globals.color_entity))
      {
        char buffer[128];
        sprintf(buffer, "%g %g %g", g_entity_globals.color_entity[0],
                g_entity_globals.color_entity[1],
                g_entity_globals.color_entity[2]);

        Scene_EntitySetKeyValue_Selected("_color", buffer);
      }
    }
  }
}
Пример #10
0
void post( const scene::Path& path, scene::Instance& instance ) const {
	Selectable *selectable = Instance_getSelectable( instance );
	if ( selectable && selectable->isSelected() ) {
		Entity* entity = Node_getEntity( path.top() );
		if ( entity == 0 && Node_isPrimitive( path.top() ) ) {
			NodeSmartReference child( path.top().get() );
			NodeSmartReference parent( path.parent().get() );

			if ( path.size() >= 3 && parent != worldspawn ) {
				NodeSmartReference parentparent( path[path.size() - 3].get() );

				Node_getTraversable( parent )->erase( child );
				Node_getTraversable( group )->insert( child );

				if ( Node_getTraversable( parent )->empty() ) {
					//deleteme.push(DeletionPair(parentparent, parent));
					Node_getTraversable( parentparent )->erase( parent );
				}
			}
			else
			{
				Node_getTraversable( parent )->erase( child );
				Node_getTraversable( group )->insert( child );
			}
		}
	}
}
Пример #11
0
void post( const scene::Path& path, scene::Instance& instance ) const {
	Entity* entity = Node_getEntity( path.top() );
	if ( entity != 0
		 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) {
		entity->setKeyValue( m_key, m_value );
	}
}
Пример #12
0
void Entity_ungroupSelected(){
	if ( GlobalSelectionSystem().countSelected() < 1 ) {
		return;
	}

	UndoableCommand undo( "ungroupSelectedEntities" );

	scene::Path world_path( makeReference( GlobalSceneGraph().root() ) );
	world_path.push( makeReference( Map_FindOrInsertWorldspawn( g_map ) ) );

	scene::Instance &instance = GlobalSelectionSystem().ultimateSelected();
	scene::Path path = instance.path();

	if ( !Node_isEntity( path.top() ) ) {
		path.pop();
	}

	if ( Node_getEntity( path.top() ) != 0
		 && node_is_group( path.top() ) ) {
		if ( world_path.top().get_pointer() != path.top().get_pointer() ) {
			parentBrushes( path.top(), world_path.top() );
			Path_deleteTop( path );
		}
	}
}
Пример #13
0
void StimResponseEditor::rescanSelection()
{
	const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

	_entity = NULL;
	_srEntity = SREntityPtr();
	_stimEditor->setEntity(_srEntity);
	_responseEditor->setEntity(_srEntity);
	_customStimEditor->setEntity(_srEntity);

	if (info.entityCount == 1 && info.totalCount == 1)
	{
		// Get the entity instance
		const scene::INodePtr& node = GlobalSelectionSystem().ultimateSelected();

		_entity = Node_getEntity(node);

		_srEntity = SREntityPtr(new SREntity(_entity, _stimTypes));
		_stimEditor->setEntity(_srEntity);
		_responseEditor->setEntity(_srEntity);
		_customStimEditor->setEntity(_srEntity);
	}

	if (_entity != NULL)
	{
		std::string title = _(WINDOW_TITLE);
		title += " (" + _entity->getKeyValue("name") + ")";
		SetTitle(title);
	}
	else
	{
		SetTitle(_(WINDOW_TITLE));
	}
}
Пример #14
0
void MapExporter::post(const scene::INodePtr& node)
{
	try
	{
		Entity* entity = Node_getEntity(node);

		if (entity != NULL)
		{
			_writer.endWriteEntity(*entity, _mapStream);
			return;
		}

		IBrush* brush = Node_getIBrush(node);

		if (brush != NULL && brush->hasContributingFaces())
		{
			_writer.endWriteBrush(*brush, _mapStream);
			return;
		}

		IPatch* patch = Node_getIPatch(node);

		if (patch != NULL)
		{
			_writer.endWritePatch(*patch, _mapStream);
			return;
		}
	}
	catch (IMapWriter::FailureException& ex)
	{
		rError() << "Failure exporting a node (post): " << ex.what() << std::endl;
	}
}
Пример #15
0
void ScriptEntityNode::setKeyValue(const std::string& key, const std::string& value) {
	Entity* entity = Node_getEntity(*this);

	if (entity != NULL) {
		entity->setKeyValue(key, value);
	}
}
Пример #16
0
// Test for targeting
bool ObjectiveEntity::isOnTargetList(const TargetList& list) const {
	// Try to convert the weak_ptr reference to a shared_ptr
	Entity* entity = Node_getEntity(_entityNode.lock());
	assert(entity != NULL);

	return list.isTargeted(entity);
}
// Write out conversations to entity keyvals
void ConversationEntity::writeToEntity() {
	// Try to convert the weak_ptr reference to a shared_ptr
	Entity* entity = Node_getEntity(_entityNode.lock());
	assert(entity != NULL);

	// greebo: Remove all conversation-related spawnargs first
	clearEntity(entity);

	for (ConversationMap::const_iterator i = _conversations.begin();
		 i != _conversations.end();
		 ++i)
	{
		// Obtain the conversation and construct the key prefix from the index
		const Conversation& conv = i->second;
		std::string prefix = "conv_" + string::to_string(i->first) + "_";

		// Set the entity keyvalues
		entity->setKeyValue(prefix + "name", conv.name);
		entity->setKeyValue(prefix + "actors_must_be_within_talkdistance",
			conv.actorsMustBeWithinTalkdistance ? "1" : "0");
		entity->setKeyValue(prefix + "talk_distance", string::to_string(conv.talkDistance));
		entity->setKeyValue(prefix + "actors_always_face_each_other_while_talking",
			conv.actorsAlwaysFaceEachOther ? "1" : "0");
		entity->setKeyValue(prefix + "max_play_count", string::to_string(conv.maxPlayCount));

		// Write the actor list
		for (Conversation::ActorMap::const_iterator a = conv.actors.begin();
			 a != conv.actors.end(); ++a)
		{
			std::string actorKey = prefix + "actor_" + string::to_string(a->first);
			entity->setKeyValue(actorKey, a->second);
		}

		// Write all the commands
		for (Conversation::CommandMap::const_iterator c = conv.commands.begin();
			 c != conv.commands.end(); ++c)
		{
			std::string cmdPrefix = prefix + "cmd_" + string::to_string(c->first) + "_";

			try {
				const ConversationCommandInfo& cmdInfo =
					ConversationCommandLibrary::Instance().findCommandInfo(c->second->type);

				entity->setKeyValue(cmdPrefix + "type", cmdInfo.name);
				entity->setKeyValue(cmdPrefix + "actor", string::to_string(c->second->actor));
				entity->setKeyValue(cmdPrefix + "wait_until_finished", c->second->waitUntilFinished ? "1" : "0");

				for (ConversationCommand::ArgumentMap::const_iterator a = c->second->arguments.begin();
					a != c->second->arguments.end(); ++a)
				{
					entity->setKeyValue(cmdPrefix + "arg_" + string::to_string(a->first), a->second);
				}
			}
			catch (std::runtime_error e) {
				rError() << "Unrecognised conversation command ID: " << c->second->type << std::endl;
			}
		}
	}
}
Пример #18
0
static NodeSmartReference Entity_create (EntityCreator& entityTable, EntityClass* entityClass, const KeyValues& keyValues)
{
	scene::Node& entity(entityTable.createEntity(entityClass));
	for (KeyValues::const_iterator i = keyValues.begin(); i != keyValues.end(); ++i) {
		Node_getEntity(entity)->setKeyValue((*i).first, (*i).second);
	}
	return NodeSmartReference(entity);
}
Пример #19
0
static NodeSmartReference Entity_parseTokens (Tokeniser& tokeniser, EntityCreator& entityTable, const PrimitiveParser& parser,
		int index)
{
	NodeSmartReference entity(g_nullNode);
	KeyValues keyValues;
	std::string classname = "";

	int count_primitives = 0;
	while (1) {
		std::string token = tokeniser.getToken();
		if (token.empty()) {
			Tokeniser_unexpectedError(tokeniser, token, "#entity-token");
			return g_nullNode;
		}
		if (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 (token == "{") { // begin primitive
			if (entity == g_nullNode) {
				// entity has brushes
				entity
						= Entity_create(entityTable, GlobalEntityClassManager().findOrInsert(classname, true),
								keyValues);
			}

			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
			const std::string key = token;
			token = tokeniser.getToken();
			if (token.empty()) {
				Tokeniser_unexpectedError(tokeniser, token, "#epair-value");
				return g_nullNode;
			}
			keyValues.push_back(KeyValues::value_type(key, token));
			if (key == "classname")
				classname = keyValues.back().second;
		}
	}
	// unreachable code
	return g_nullNode;
}
Пример #20
0
bool pre( const scene::Path& path, scene::Instance& instance ) const {
	if ( m_entity == 0 ) {
		Entity* entity = Node_getEntity( path.top() );
		if ( entity != 0 && string_equal( m_name, entity->getKeyValue( "classname" ) ) ) {
			m_entity = entity;
		}
	}
	return true;
}
Пример #21
0
bool DEntity::LoadFromEntity( scene::Node& ent, bool bLoadPatches ) {
	ClearPatches();
	ClearBrushes();
	ClearEPairs();

	QER_Entity = &ent;

	LoadEPairList( Node_getEntity( ent ) );

	bool keep = false;
	int i;
	for ( i = 0; brushEntityList[i]; i++ )
	{
		if ( string_equal_nocase( brushEntityList[i], m_Classname ) ) {
			keep = true;
			break;
		}
	}

	if ( !keep ) {
		return false;
	}

	if ( Node_getTraversable( ent ) ) {
		class load_brushes_t : public scene::Traversable::Walker
		{
		DEntity* m_entity;
		mutable int m_count;
public:
		load_brushes_t( DEntity* entity )
			: m_entity( entity ), m_count( 0 ){
		}

		bool pre( scene::Node& node ) const {
			scene::Path path( NodeReference( GlobalSceneGraph().root() ) );
			path.push( NodeReference( *m_entity->QER_Entity ) );
			path.push( NodeReference( node ) );
			scene::Instance* instance = GlobalSceneGraph().find( path );
			ASSERT_MESSAGE( instance != 0, "" );

			if ( Node_isPatch( node ) ) {
				DPatch* loadPatch = m_entity->NewPatch();
				loadPatch->LoadFromPatch( *instance );
			}
			else if ( Node_isBrush( node ) ) {
				DBrush* loadBrush = m_entity->NewBrush( m_count++ );
				loadBrush->LoadFromBrush( *instance, true );
			}
			return false;
		}
		} load_brushes( this );

		Node_getTraversable( ent )->traverse( load_brushes );
	}

	return true;
}
Пример #22
0
  void operator()(scene::Instance& instance) const
  {
		const char* classname = Node_getEntity(instance.path().top())->getKeyValue("classname");

		if(!strcmp(classname, "worldspawn"))
		{
			world.LoadFromEntity(instance.path().top(), false);
			world.RemoveNonCheckBrushes(exclusionList, true);
			world.SaveToFile(pFile);
		}
		else if(strstr(classname, "info_"))
		{
			world.ClearBrushes();
			world.ClearEPairs();
			world.LoadEPairList(Node_getEntity(instance.path().top()));
			world.SaveToFile(pFile);
		}
  }
Пример #23
0
 // Required visit method
 void visit(const scene::INodePtr& node) const
 {
     Entity* ent = Node_getEntity(node);
     if (ent && ent->getEntityClass()->isLight())
     {
         // Add light to list
         _entityList.push_back(ent);
     }
 }
Пример #24
0
void popElement( const char* name ){
	ASSERT_MESSAGE( string_equal( name, "entity" ), PARSE_ERROR );
	NodeSmartReference entity( m_entityTable.createEntity( GlobalEntityClassManager().findOrInsert( Node_getEntity( node() )->getKeyValue( "classname" ), node_is_group( node() ) ) ) );

	{
		EntityCopyingVisitor visitor( *Node_getEntity( entity ) );
		Node_getEntity( node() )->forEachKeyValue( visitor );
	}

	if ( Node_getTraversable( entity ) != 0 && !Node_getEntity( entity )->getEntityClass().fixedsize ) {
		parentBrushes( node(), entity );
	}

	Node_getTraversable( m_parent )->insert( entity );

	destructor( primitive() );
	destructor( node() );
}
Пример #25
0
void post( const scene::Path& path, scene::Instance& instance ) const {
	Entity* entity = Node_getEntity( path.top() );
	if ( entity != 0
		 && Instance_getSelectable( instance )->isSelected()
		 && node_is_group( path.top() )
		 && !groupPath ) {
		groupPath = &path;
		groupInstance = &instance;
	}
}
// Constructor
ConversationEntity::ConversationEntity(scene::INodePtr node) :
	_entityNode(node)
{
	Entity* entity = Node_getEntity(node);
	assert(entity != NULL);

	// Use an conversationKeyExtractor to populate the ConversationMap from the keys
	// on the entity
	ConversationKeyExtractor extractor(_conversations);
	entity->forEachKeyValue(extractor);
}
Пример #27
0
bool pre( const scene::Path& path, scene::Instance& instance ) const {
	const char *str;
	Entity* entity = Node_getEntity( path.top() );
	if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) {
		str = entity->getKeyValue( m_flag );
		if ( string_empty( str ) ) {
			( *m_count )++;
		}
	}
	return true;
}
Пример #28
0
 bool addPrimitiveToEntity(const scene::INodePtr& primitive, const scene::INodePtr& entity)
 {
     if (Node_getEntity(entity)->isContainer())
     {
         entity->addChildNode(primitive);
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #29
0
 void visit(scene::Instance& instance) const
 {
   if(Node_getEntity(instance.path().top()) != 0
     && node_is_group(instance.path().top()))
   {
     if(m_parent.top().get_pointer() != instance.path().top().get_pointer())
     {
       parentBrushes(instance.path().top(), m_parent.top());
       Path_deleteTop(instance.path());
     }
   }
 }
Пример #30
0
inline scene::Node& node_for_eclass (EntityClass* eclass)
{
	scene::Node& node = entity_for_eclass(eclass);
	Node_getEntity(node)->setKeyValue("classname", eclass->name());

	Namespaced* namespaced = Node_getNamespaced(node);
	if (namespaced != 0) {
		namespaced->setNamespace(GlobalNamespace());
	}

	return node;
}