Beispiel #1
0
bool AI::doActions()
{
  unsigned int r,l,f;
  space sp;
  do
  {
    if(que.empty())return true;
    //get the next best
    sp = que.top();
    //pop it off
    que.pop();
  }while( !plants[sp.acting].canAct() || !canDo(sp.acting,sp.action) || notActing[sp.acting]);
  cout<<plants[sp.acting].objectID()<<" ("<<plants[sp.acting].x()<<","<<plants[sp.acting].y()<<") ";sp.display();
  switch (sp.action)
  {
    case LEAF:
      plants[sp.acting].growLeaf();
      break;
    case ROOT:
      plants[sp.acting].growRoot();
      break;
    case FLOWER:
      getFlowerUp(sp.acting,r,l,f);
      plants[sp.acting].growFlower(r,l,f);
      break;
    case SPREAD:
      if(canSpreadHere[sp.x+1][sp.y+1])
      {
        plants[sp.acting].spread(sp.x,sp.y);
        if(!canSpawnHere[sp.x+1][sp.y+1])
        {
          cout<<"\n\n\tAttack!";
          sp.display();
          cout<<"\n\n"<<endl;
        }
        canSpreadHere[sp.x+1][sp.y+1]=false;
      }
      break;
    case SPAWN:
      if(canSpawnHere[sp.x+1][sp.y+1])
      {
        plants[sp.acting].spawn(sp.x,sp.y);
        canSpawnHere[sp.x+1][sp.y+1]=false;
      }
      break;            
    case NOOP:
      notActing[sp.acting]=true;
      break;
  }
  return que.empty();
}
        bool SplitEdgesCommand::performDo() {
            if (!canDo())
                return false;
            
            m_vertices.clear();
            makeSnapshots(m_brushes);
            document().brushesWillChange(m_brushes);

            BrushEdgeMap::const_iterator it, end;
            for (it = m_brushEdges.begin(), end = m_brushEdges.end(); it != end; ++it) {
                Model::Brush* brush = it->first;
                const Model::EdgeInfo& edgeInfo = it->second;
                Vec3f newVertexPosition = brush->splitEdge(edgeInfo, m_delta);
                m_vertices.insert(newVertexPosition);
            }

            document().brushesDidChange(m_brushes);
            return true;
        }
        bool MoveEdgesCommand::performDo() {
            if (!canDo())
                return false;
            
            m_edges.clear();
            makeSnapshots(m_brushes);
            document().brushesWillChange(m_brushes);
            
            BrushEdgesMap::const_iterator it, end;
            for (it = m_brushEdges.begin(), end = m_brushEdges.end(); it != end; ++it) {
                Model::Brush* brush = it->first;
                const Model::EdgeList& edges = it->second;
                const Model::EdgeList newEdges = brush->moveEdges(edges, m_delta);
                m_edges.insert(m_edges.end(), newEdges.begin(), newEdges.end());
            }

            document().brushesDidChange(m_brushes);
            return true;
        }
        bool SplitEdgesCommand::performDo() {
            if (!canDo())
                return false;
            
            m_vertices.clear();
            makeSnapshots(m_brushes);
            document().brushesWillChange(m_brushes);

            Model::EdgeList::const_iterator eIt, eEnd;
            for (eIt = m_edges.begin(), eEnd = m_edges.end(); eIt != eEnd; ++eIt) {
                Model::Edge* edge = *eIt;
                Model::Brush* brush = edge->left->face->brush();
                Vec3f newVertexPosition = brush->splitEdge(edge, m_delta);
                m_vertices.insert(newVertexPosition);
            }

            document().brushesDidChange(m_brushes);
            return true;
        }
        bool MoveVerticesCommand::performDo() {
            if (!canDo())
                return false;
            
            m_vertices.clear();
            makeSnapshots(m_brushes);
            document().brushesWillChange(m_brushes);

            BrushVerticesMap::const_iterator it, end;
            for (it = m_brushVertices.begin(), end = m_brushVertices.end(); it != end; ++it) {
                Model::Brush* brush = it->first;
                const Vec3f::List& oldVertexPositions = it->second;
                Vec3f::List newVertexPositions = brush->moveVertices(oldVertexPositions, m_delta);
                m_vertices.insert(newVertexPositions.begin(), newVertexPositions.end());
            }
            
            document().brushesDidChange(m_brushes);
            return true;
        }
        bool MoveFacesCommand::performDo() {
            if (!canDo())
                return false;

            m_handleManager.remove(m_brushes);
            makeSnapshots(m_brushes);
            document().brushesWillChange(m_brushes);
            m_facesAfter.clear();

            Model::BrushFacesMap::const_iterator it, end;
            for (it = m_brushFaces.begin(), end = m_brushFaces.end(); it != end; ++it) {
                Model::Brush* brush = it->first;
                const Model::FaceInfoList& faceInfos = it->second;
                const Model::FaceInfoList newFaces = brush->moveFaces(faceInfos, m_delta);
                m_facesAfter.insert(m_facesAfter.end(), newFaces.begin(), newFaces.end());
            }

            document().brushesDidChange(m_brushes);
            m_handleManager.add(m_brushes);
            m_handleManager.selectFaceHandles(m_facesAfter);

            return true;
        }
Beispiel #7
0
//-------------------------------------------------------------------------------------------------------
long AudioEffectX::dispatcher (long opCode, long index, long value, void *ptr, float opt)
{
	long v = 0;
	switch(opCode)
	{
		// VstEvents
		case effProcessEvents:
			v = processEvents ((VstEvents*)ptr);
			break;

		// parameters and programs
		case effCanBeAutomated:
			v = canParameterBeAutomated (index) ? 1 : 0;
			break;
		case effString2Parameter:
			v = string2parameter (index, (char*)ptr) ? 1 : 0;
			break;

		case effGetNumProgramCategories:
			v = getNumCategories ();
			break;
		case effGetProgramNameIndexed:
			v = getProgramNameIndexed (value, index, (char*)ptr) ? 1 : 0;
			break;
		case effCopyProgram:
			v = copyProgram (index) ? 1 : 0;
			break;

		// connections, configuration
		case effConnectInput:
			inputConnected (index, value ? true : false);
			v = 1;
			break;	
		case effConnectOutput:
			outputConnected (index, value ? true : false);
			v = 1;
			break;	
		case effGetInputProperties:
			v = getInputProperties (index, (VstPinProperties*)ptr) ? 1 : 0;
			break;
		case effGetOutputProperties:
			v = getOutputProperties (index, (VstPinProperties*)ptr) ? 1 : 0;
			break;
		case effGetPlugCategory:
			v = (long)getPlugCategory ();
			break;

		// realtime
		case effGetCurrentPosition:
			v = reportCurrentPosition ();
			break;
			
		case effGetDestinationBuffer:
			v = (long)reportDestinationBuffer ();
			break;

		// offline
		case effOfflineNotify:
			v = offlineNotify ((VstAudioFile*)ptr, value, index != 0);
			break;
		case effOfflinePrepare:
			v = offlinePrepare ((VstOfflineTask*)ptr, value);
			break;
		case effOfflineRun:
			v = offlineRun ((VstOfflineTask*)ptr, value);
			break;

		// other
		case effSetSpeakerArrangement:
			v = setSpeakerArrangement ((VstSpeakerArrangement*)value, (VstSpeakerArrangement*)ptr) ? 1 : 0;
			break;
		case effProcessVarIo:
			v = processVariableIo ((VstVariableIo*)ptr) ? 1 : 0;
			break;
		case effSetBlockSizeAndSampleRate:
			setBlockSizeAndSampleRate (value, opt);
			v = 1;
			break;
		case effSetBypass:
			v = setBypass (value ? true : false) ? 1 : 0;
			break;
		case effGetEffectName:
			v = getEffectName ((char *)ptr) ? 1 : 0;
			break;
		case effGetErrorText:
			v = getErrorText ((char *)ptr) ? 1 : 0;
			break;
		case effGetVendorString:
			v = getVendorString ((char *)ptr) ? 1 : 0;
			break;
		case effGetProductString:
			v = getProductString ((char *)ptr) ? 1 : 0;
			break;
		case effGetVendorVersion:
			v = getVendorVersion ();
			break;
		case effVendorSpecific:
			v = vendorSpecific (index, value, ptr, opt);
			break;
		case effCanDo:
			v = canDo ((char*)ptr);
			break;
		case effGetIcon:
			v = (long)getIcon ();
			break;
		case effSetViewPosition:
			v = setViewPosition (index, value) ? 1 : 0;
			break;		
		case effGetTailSize:
			v = getGetTailSize ();
			break;
		case effIdle:
			v = fxIdle ();
			break;

		case effGetParameterProperties:
			v = getParameterProperties (index, (VstParameterProperties*)ptr) ? 1 : 0;
			break;

		case effKeysRequired:
			v = (keysRequired () ? 0 : 1);	// reversed to keep v1 compatibility
			break;
		case effGetVstVersion:
			v = getVstVersion ();
			break;

		// version 1.0 or unknown
		default:
			v = AudioEffect::dispatcher (opCode, index, value, ptr, opt);
	}
	return v;
}
// File loader.
bool qtractor_vst_scan::open ( const QString& sFilename, unsigned long iIndex )
{
	close();

	if (!QLibrary::isLibrary(sFilename))
		return false;

#ifdef CONFIG_DEBUG_0
	qDebug("qtractor_vst_scan[%p]::open(\"%s\", %lu)", this,
		sFilename.toUtf8().constData(), iIndex);
#endif

	m_pLibrary = new QLibrary(sFilename);

	VST_GetPluginInstance pfnGetPluginInstance
		= (VST_GetPluginInstance) m_pLibrary->resolve("VSTPluginMain");
	if (pfnGetPluginInstance == NULL)
		pfnGetPluginInstance = (VST_GetPluginInstance) m_pLibrary->resolve("main");
	if (pfnGetPluginInstance == NULL) {
	#ifdef CONFIG_DEBUG
		qDebug("qtractor_vst_scan[%p]: plugin does not have a main entry point.", this);
	#endif
		return false;
	}

	m_pEffect = (*pfnGetPluginInstance)(qtractor_vst_scan_callback);
	if (m_pEffect == NULL) {
	#ifdef CONFIG_DEBUG
		qDebug("qtractor_vst_scan[%p]: plugin instance could not be created.", this);
	#endif
		return false;
	}

	// Did VST plugin instantiated OK?
	if (m_pEffect->magic != kEffectMagic) {
	#ifdef CONFIG_DEBUG
		qDebug("qtractor_vst_scan[%p]: plugin is not a valid VST.", this);
	#endif
		m_pEffect = NULL;
		return false;
	}

	// Check whether it's a VST Shell...
	const int categ = vst_dispatch(effGetPlugCategory, 0, 0, NULL, 0.0f);
	if (categ == kPlugCategShell) {
		int id = 0;
		char buf[40];
		unsigned long i = 0;
		for ( ; iIndex >= i; ++i) {
			buf[0] = (char) 0;
			id = vst_dispatch(effShellGetNextPlugin, 0, 0, (void *) buf, 0.0f);
			if (id == 0 || !buf[0])
				break;
		}
		// Check if we're actually the intended plugin...
		if (i < iIndex || id == 0 || !buf[0]) {
		#ifdef CONFIG_DEBUG
			qDebug("qtractor_vst_scan[%p]: "
				"vst_shell(%lu) plugin is not a valid VST.", this, iIndex);
		#endif
			m_pEffect = NULL;
			return false;
		}
		// Make it known...
		g_iVstShellCurrentId = id;
		// Re-allocate the thing all over again...
		pfnGetPluginInstance
			= (VST_GetPluginInstance) m_pLibrary->resolve("VSTPluginMain");
		if (pfnGetPluginInstance == NULL)
			pfnGetPluginInstance = (VST_GetPluginInstance) m_pLibrary->resolve("main");
		if (pfnGetPluginInstance == NULL) {
		#ifdef CONFIG_DEBUG
			qDebug("qtractor_vst_scan[%p]: "
				"vst_shell(%lu) plugin does not have a main entry point.", this, iIndex);
		#endif
			m_pEffect = NULL;
			return false;
		}
		// Does the VST plugin instantiate OK?
		m_pEffect = (*pfnGetPluginInstance)(qtractor_vst_scan_callback);
		// Not needed anymore, hopefully...
		g_iVstShellCurrentId = 0;
		// Don't go further if failed...
		if (m_pEffect == NULL) {
		#ifdef CONFIG_DEBUG
			qDebug("qtractor_vst_scan[%p]: "
				"vst_shell(%lu) plugin instance could not be created.", this, iIndex);
		#endif
			return false;
		}
		if (m_pEffect->magic != kEffectMagic) {
		#ifdef CONFIG_DEBUG
			qDebug("qtractor_vst_scan[%p]: "
				"vst_shell(%lu) plugin is not a valid VST.", this, iIndex);
		#endif
			m_pEffect = NULL;
			return false;
		}
	#ifdef CONFIG_DEBUG
		qDebug("qtractor_vst_scan[%p]: "
			"vst_shell(%lu) id=0x%x name=\"%s\"", this, i, id, buf);
	#endif
	}
	else
	// Not a VST Shell plugin...
	if (iIndex > 0) {
		m_pEffect = NULL;
		return false;
	}

//	vst_dispatch(effIdentify, 0, 0, NULL, 0.0f);
	vst_dispatch(effOpen,     0, 0, NULL, 0.0f);

	// Get label name...
	char szName[256]; ::memset(szName, 0, sizeof(szName));
	if (vst_dispatch(effGetEffectName, 0, 0, (void *) szName, 0.0f))
		m_sName = szName;
	else
		m_sName = QFileInfo(sFilename).baseName();

	// Specific inquiries...
	m_iFlagsEx = 0;

	if (canDo("sendVstEvents"))       m_iFlagsEx |= effFlagsExCanSendVstEvents;
	if (canDo("sendVstMidiEvent"))    m_iFlagsEx |= effFlagsExCanSendVstMidiEvents;
	if (canDo("sendVstTimeInfo"))     m_iFlagsEx |= effFlagsExCanSendVstTimeInfo;
	if (canDo("receiveVstEvents"))    m_iFlagsEx |= effFlagsExCanReceiveVstEvents;
	if (canDo("receiveVstMidiEvent")) m_iFlagsEx |= effFlagsExCanReceiveVstMidiEvents;
	if (canDo("receiveVstTimeInfo"))  m_iFlagsEx |= effFlagsExCanReceiveVstTimeInfo;
	if (canDo("offline"))             m_iFlagsEx |= effFlagsExCanProcessOffline;
	if (canDo("plugAsChannelInsert")) m_iFlagsEx |= effFlagsExCanUseAsInsert;
	if (canDo("plugAsSend"))          m_iFlagsEx |= effFlagsExCanUseAsSend;
	if (canDo("mixDryWet"))           m_iFlagsEx |= effFlagsExCanMixDryWet;
	if (canDo("midiProgramNames"))    m_iFlagsEx |= effFlagsExCanMidiProgramNames;

	return true;
}
Beispiel #9
0
//-------------------------------------------------------------------------------------------------------
long AudioEffectX::dispatcher (long opCode, long index, long value, void *ptr, float opt)
{
    long v = 0;
    switch(opCode)
    {
    // VstEvents
    case effProcessEvents:
        v = processEvents ((VstEvents*)ptr);
        break;

    // parameters and programs
    case effCanBeAutomated:
        v = canParameterBeAutomated (index) ? 1 : 0;
        break;
    case effString2Parameter:
        v = string2parameter (index, (char*)ptr) ? 1 : 0;
        break;

    case effGetNumProgramCategories:
        v = getNumCategories ();
        break;
    case effGetProgramNameIndexed:
        v = getProgramNameIndexed (value, index, (char*)ptr) ? 1 : 0;
        break;
    case effCopyProgram:
        v = copyProgram (index) ? 1 : 0;
        break;

    // connections, configuration
    case effConnectInput:
        inputConnected (index, value ? true : false);
        v = 1;
        break;
    case effConnectOutput:
        outputConnected (index, value ? true : false);
        v = 1;
        break;
    case effGetInputProperties:
        v = getInputProperties (index, (VstPinProperties*)ptr) ? 1 : 0;
        break;
    case effGetOutputProperties:
        v = getOutputProperties (index, (VstPinProperties*)ptr) ? 1 : 0;
        break;
    case effGetPlugCategory:
        v = (long)getPlugCategory ();
        break;

    // realtime
    case effGetCurrentPosition:
        v = reportCurrentPosition ();
        break;

    case effGetDestinationBuffer:
        v = (long)reportDestinationBuffer ();
        break;

    // offline
    case effOfflineNotify:
        v = offlineNotify ((VstAudioFile*)ptr, value, index != 0);
        break;
    case effOfflinePrepare:
        v = offlinePrepare ((VstOfflineTask*)ptr, value);
        break;
    case effOfflineRun:
        v = offlineRun ((VstOfflineTask*)ptr, value);
        break;

    // other
    case effSetSpeakerArrangement:
        v = setSpeakerArrangement ((VstSpeakerArrangement*)value, (VstSpeakerArrangement*)ptr) ? 1 : 0;
        break;
    case effProcessVarIo:
        v = processVariableIo ((VstVariableIo*)ptr) ? 1 : 0;
        break;
    case effSetBlockSizeAndSampleRate:
        setBlockSizeAndSampleRate (value, opt);
        v = 1;
        break;
    case effSetBypass:
        v = setBypass (value ? true : false) ? 1 : 0;
        break;
    case effGetEffectName:
        v = getEffectName ((char *)ptr) ? 1 : 0;
        break;
    case effGetErrorText:
        v = getErrorText ((char *)ptr) ? 1 : 0;
        break;
    case effGetVendorString:
        v = getVendorString ((char *)ptr) ? 1 : 0;
        break;
    case effGetProductString:
        v = getProductString ((char *)ptr) ? 1 : 0;
        break;
    case effGetVendorVersion:
        v = getVendorVersion ();
        break;
    case effVendorSpecific:
        v = vendorSpecific (index, value, ptr, opt);
        break;
    case effCanDo:
        v = canDo ((char*)ptr);
        break;
    case effGetIcon:
        v = (long)getIcon ();
        break;
    case effSetViewPosition:
        v = setViewPosition (index, value) ? 1 : 0;
        break;
    case effGetTailSize:
        v = getGetTailSize ();
        break;
    case effIdle:
        v = fxIdle ();
        break;

    case effGetParameterProperties:
        v = getParameterProperties (index, (VstParameterProperties*)ptr) ? 1 : 0;
        break;

    case effKeysRequired:
        v = (keysRequired () ? 0 : 1);	// reversed to keep v1 compatibility
        break;
    case effGetVstVersion:
        v = getVstVersion ();
        break;

#if VST_2_1_EXTENSIONS
    case effEditKeyDown:
        if (editor)
        {
            VstKeyCode keyCode = {index, (unsigned char)value, (unsigned char)opt};
            v = editor->onKeyDown (keyCode);
        }
        break;

    case effEditKeyUp:
        if (editor)
        {
            VstKeyCode keyCode = {index, (unsigned char)value, (unsigned char)opt};
            v = editor->onKeyUp (keyCode);
        }
        break;

    case effSetEditKnobMode:
        if (editor)
            v = editor->setKnobMode (value);
        break;

    case effGetMidiProgramName:
        v = getMidiProgramName (index, (MidiProgramName*)ptr);
        break;
    case effGetCurrentMidiProgram:
        v = getCurrentMidiProgram (index, (MidiProgramName*)ptr);
        break;
    case effGetMidiProgramCategory:
        v = getMidiProgramCategory (index, (MidiProgramCategory*)ptr);
        break;
    case effHasMidiProgramsChanged:
        v = hasMidiProgramsChanged (index) ? 1 : 0;
        break;
    case effGetMidiKeyName:
        v = getMidiKeyName (index, (MidiKeyName*)ptr) ? 1 : 0;
        break;

    case effBeginSetProgram:
        v = beginSetProgram () ? 1 : 0;
        break;
    case effEndSetProgram:
        v = endSetProgram () ? 1 : 0;
        break;

#endif // VST_2_1_EXTENSIONS

#if VST_2_3_EXTENSIONS
    case effGetSpeakerArrangement:
        v = getSpeakerArrangement ((VstSpeakerArrangement**)value, (VstSpeakerArrangement**)ptr) ? 1 : 0;
        break;

    case effSetTotalSampleToProcess:
        v = setTotalSampleToProcess (value);
        break;

    case effShellGetNextPlugin:
        v = getNextShellPlugin ((char*)ptr);
        break;

    case effStartProcess:
        v = startProcess ();
        break;
    case effStopProcess:
        v = stopProcess ();
        break;

    case effSetPanLaw:
        v = setPanLaw (value, opt) ? 1 : 0;
        break;

    case effBeginLoadBank:
        v = beginLoadBank ((VstPatchChunkInfo*)ptr);
        break;
    case effBeginLoadProgram:
        v = beginLoadProgram ((VstPatchChunkInfo*)ptr);
        break;
#endif // VST_2_3_EXTENSIONS

    // version 1.0 or unknown
    default:
        v = AudioEffect::dispatcher (opCode, index, value, ptr, opt);
    }
    return v;
}
Beispiel #10
0
//TODO Test if you can build something and act on it in one turn
void AI::buildQueue()
{
  for(unsigned int i=0;i<plants.size();i++)
  {
    //cout<<"Working on plant: "<<i<<endl;
    //cout<<"HP: "<<plants[i].health()<<endl;
    //if its my plant and it can do something
    if(plants[i].ownerID() == playerID() && plants[i].canAct())
    {
      //Spam talk
      string message="This is plant[" + plants[i].objectID();
      message+="] owned by Player: "+plants[i].ownerID();
      message+=" on turn "+turnNumber();
      //char * temp = message.c_str();
      plants[i].talk((char*)(message.c_str()));
      if(i==0)
      {
        plants[i].talk((char*)("Did calling talk twice append or replace the usual string?"));
      }
      //if you don't have a leaf
      if(!plants[i].leaf())
      {
        if(canDo(i,LEAF))
        {
          //a place to try growing a leaf
          space sp(plants[i].x(), plants[i].y(),i,LEAF);
          sp.rating=evalTree(leafTree,sp);
          que.push(sp);
        }
        /*
        else
        {
          space sp(plants[i].x(), plants[i].y(),i,LEAF);
          cout<<"CANT DO: ";
          sp.display();
        }
        */
      }
      //if you want to generate light
      else
      {
        //cout<<"Pushing NOOP"<<endl;
        space sp(plants[i].x(), plants[i].y(),i,NOOP);
        sp.rating=evalTree(noopTree,sp);
        //que.push(sp);
      }
      //if it doesn't have a root
      if(!plants[i].root())
      {
        //I can do a root
        if(canDo(i,ROOT))
        {
          //a place to try growing a root
          space sp(plants[i].x(), plants[i].y(),i,ROOT);
          sp.rating=evalTree(rootTree,sp);
          que.push(sp);
        }
        /*
        else
        {
          space sp(plants[i].x(), plants[i].y(),i,ROOT);
          cout<<"CANT DO: ";
          sp.display();        
        }
        */
      }
      //for expansion
      else
      {
        if(canDo(i,SPREAD))
        {
          for(unsigned int r=0;r<4;r++)
          {
            space sp(plants[i].x()+xoff[r], plants[i].y()+yoff[r],i,SPREAD);
            if(canSpawnHere[sp.x+1][sp.y+1])
            {
              sp.rating=evalTree(rootTree,sp);
              que.push(sp);
            }
          }
        }
      }
      //if it doesn't have a flower and can make one
      if(!plants[i].flower())
      {
        if(canDo(i,FLOWER))
        {
          //a place to try growing a flower
          space sp(plants[i].x(), plants[i].y(),i,FLOWER);
          sp.rating=evalTree(flowerTree,sp);
          que.push(sp);
        }
      }
      //if you have a flower and can spawn
      else
      {
        if(canDo(i,SPAWN))
        {
          for(unsigned int r=0;r<4;r++)
          {
            space sp(plants[i].x()+xoff[r], plants[i].y()+yoff[r],i,SPAWN);
            if(canSpawnHere[sp.x+1][sp.y+1])
            {
              sp.rating=evalTree(spawnTree,sp);
              que.push(sp);
            }
          }
        }
      }
    }
  }
 // //cout<<"Bot of Build QUE"<<endl;
}