Example #1
0
int CMainDlg::PlayFM(int loop)
{
	WAVEFORMATEX wf;
	wf.wFormatTag = WAVE_FORMAT_PCM;
	wf.nChannels = 1;
    wf.nSamplesPerSec = synthParams.isampleRate;
    wf.nAvgBytesPerSec = wf.nSamplesPerSec * 2;
	wf.nBlockAlign = 2; 
    wf.wBitsPerSample = 16;
	wf.cbSize = 0;

	StopPlaying();

	InitGen();

	DWORD atkSusSamples = (DWORD) (durAtkSus * synthParams.sampleRate);
	DWORD totalSamples = (DWORD) (durTotal * synthParams.sampleRate);
	// add room for silence at end to minimize "click" when player turns off.
	DWORD bufSize = totalSamples + (DWORD) (0.1 * synthParams.sampleRate);
	SampleValue *samples;

#ifdef USE_DIRECTSOUND
	HRESULT hr;
	if (dirSndObj == NULL)
	{
		hr = DirectSoundCreate(NULL, &dirSndObj, NULL);
		if (hr == S_OK)
		{
			hr = dirSndObj->SetCooperativeLevel(m_hWnd, DSSCL_NORMAL);
			if (hr != S_OK)
			{
				dirSndObj->Release();
				dirSndObj = NULL;
				MessageBox("Cannot open direct sound output", "Error", MB_OK|MB_ICONSTOP);
				return -1;
			}
		}
	}
	void *pAudio1 = NULL;
	void *pAudio2 = NULL;
	DWORD dwAudio1 = 0;
	DWORD dwAudio2 = 0;

	DSBUFFERDESC dsbd;
	dsbd.dwSize = sizeof(dsbd);
	dsbd.dwFlags = 0; 
	dsbd.dwBufferBytes = bufSize * 2;
	dsbd.dwReserved = 0; 
	dsbd.lpwfxFormat = &wf;
	
	hr = dirSndObj->CreateSoundBuffer(&dsbd, &dirSndBuf, NULL);
	if (hr != S_OK)
		return -1;
	hr = dirSndBuf->Lock(0, bufSize, &pAudio1, &dwAudio1, NULL, NULL, DSBLOCK_ENTIREBUFFER);
	if (hr != S_OK)
	{
		MessageBox("Cannot create direct sound buffer", "Error", MB_OK|MB_ICONSTOP);
		return -1;
	}
	samples = (SampleValue *) pAudio1;
#else
	MMRESULT res; 
	if (woHandle == NULL)
	{
		res = waveOutOpen(&woHandle, WAVE_MAPPER, &wf, (DWORD) m_hWnd, 0, CALLBACK_WINDOW);
		if (res != MMSYSERR_NOERROR)
		{
			MessageBox("Cannot open wave output", "Error", MB_OK|MB_ICONSTOP);
			return -1;
		}
	}

	memset(&wh, 0, sizeof(wh));
	wh.dwBufferLength = bufSize * sizeof(SampleValue);
	wh.lpData = (LPSTR) malloc(wh.dwBufferLength);
	if (wh.lpData == NULL)
	{
		MessageBox("Cannot create wave out buffer", "Error", MB_OK|MB_ICONSTOP);
		return -1;
	}

	res = waveOutPrepareHeader(woHandle, &wh, sizeof(wh));
	samples = (SampleValue *) wh.lpData;
#endif

	DWORD n = 0; 
	while (n++ < atkSusSamples)
		*samples++ = (SampleValue) (Generate() * synthParams.sampleScale);
	NoteOff();
	while (!gen1EG.IsFinished() && n++ < bufSize)
		*samples++ = (SampleValue) (Generate() * synthParams.sampleScale);
	while (n++ < bufSize)
		*samples++ = 0;

#ifdef USE_DIRECTSOUND
	dirSndBuf->Unlock(pAudio1, dwAudio1, pAudio2, dwAudio2);
	dirSndBuf->Play(0, 0, loop ? DSBPLAY_LOOPING : 0);
	if (!loop)
		idTimer = SetTimer(1, (UINT) (durTotal * 1000.0) + 500);
#else
	if (loop)
	{
		wh.dwFlags |= WHDR_BEGINLOOP | WHDR_ENDLOOP;
		wh.dwLoops = 100;
	}
	waveOutWrite(woHandle, &wh, sizeof(wh));
#endif

	return 0;
}
Example #2
0
//----------------------------------------
void SingleRandom::Reset()
{
	srand((unsigned)time(NULL));
	index_ = range_min_;
	Generate();
}
Example #3
0
void Puzzle::New()
{
    if(PromptYesNo(t_("Start a new game?")))
        Generate();
}
DunGen::DunGen(int xCap,int yCap,int difficulty)
{
    Generate(xCap,yCap,difficulty);
}
Example #5
0
bool Random::GenerateBool()
{
								return (Generate(1) == 1);
}
Example #6
0
	void Texture::LoadFromFile(std::string fileName)
	{
		sf::Image img;
		img.loadFromFile(fileName);
		Generate(img);
	}
Example #7
0
void SEAL::IncrementCounter()
{
	counter++;
	position = 0;
	Generate(counter, buffer);
}
Example #8
0
int gmCodeGenPrivate::Lock(const gmCodeTreeNode * a_codeTree, gmCodeGenHooks * a_hooks, bool a_debug, gmLog * a_log)
{
  if(m_locked == true) return 1;

  // set up members
  m_errors = 0;
  m_locked = true;
  m_log = a_log;
  m_hooks = a_hooks;
  m_debug = a_debug;

  GM_ASSERT(m_hooks != NULL);

  // set up memory and stacks.
  m_currentLoop = -1;
  m_currentFunction = NULL;
  m_loopStack.Reset();
  m_patches.Reset();

  // set up the stacks for the first procedure.
  m_hooks->Begin(m_debug);

  PushFunction();
  GM_ASSERT(m_currentFunction);

  // generate the byte code for the root procedure
  if(!Generate(a_codeTree, &m_currentFunction->m_byteCode))
  {
    ++m_errors;
  }
  else
  {
    m_currentFunction->m_byteCode.Emit(BC_RET);

    // Create a locals table
    const char ** locals = NULL;
    if(m_debug)
    {
      locals = (const char **) alloca(sizeof(const char *) * m_currentFunction->m_numLocals);
      memset(locals, 0, sizeof(const char *) * m_currentFunction->m_numLocals);
      for(gmuint v = 0; v < m_currentFunction->m_variables.Count(); ++v)
      {
        Variable &variable = m_currentFunction->m_variables[v];
        if(variable.m_offset != -1)
        {
          locals[variable.m_offset] = variable.m_symbol;
        }
      }
    }
    
    // Fill out a function info struct and add the function to the code gen hooks.

    gmSortDebugLines(m_currentFunction->m_lineInfo);

    gmFunctionInfo info;
    info.m_id = m_hooks->GetFunctionId();
    info.m_root = true;
    info.m_byteCode = m_currentFunction->m_byteCode.GetData();
    info.m_byteCodeLength = m_currentFunction->m_byteCode.Tell();
    info.m_numParams = 0;
    info.m_numLocals = m_currentFunction->m_numLocals;
    info.m_symbols = locals;
    info.m_maxStackSize = m_currentFunction->m_byteCode.GetMaxTos();
    info.m_lineInfoCount = m_currentFunction->m_lineInfo.Count();
    info.m_lineInfo = m_currentFunction->m_lineInfo.GetData();
    info.m_debugName = "__main";
    m_hooks->AddFunction(info);

    //gmByteCodePrint(stdout, info.m_byteCode, info.m_byteCodeLength);
  }

  PopFunction();

  m_hooks->End(m_errors);

  return m_errors;
}
Example #9
0
bool gmCodeGenPrivate::GenExprFunction(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
  GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_FUNCTION);

  gmptr id = m_hooks->GetFunctionId();
  a_byteCode->EmitPtr(BC_PUSHFN, id);

  // Create the function
  PushFunction();

  // Get a debug function name as the name of the variable the function is assigned to
  if(m_debug && a_node->m_parent && a_node->m_parent->m_type == CTNT_EXPRESSION && a_node->m_parent->m_subType == CTNET_OPERATION &&
     (a_node->m_parent->m_subTypeType == CTNOT_ASSIGN || a_node->m_parent->m_subTypeType == CTNOT_ASSIGN_FIELD) && a_node->m_parent->m_children[1] == a_node)
  {
    const gmCodeTreeNode * debugName = a_node->m_parent->m_children[0];
    if(debugName && debugName->m_type == CTNT_EXPRESSION && debugName->m_subType == CTNET_IDENTIFIER)
    {
    }
    else if(debugName->m_type == CTNT_EXPRESSION && debugName->m_subType == CTNET_OPERATION && 
            debugName->m_subTypeType == CTNOT_DOT)
    {
      debugName = debugName->m_children[1];
    }
    else
    {
      debugName = NULL;
    }

    if(debugName)
    {
      GM_ASSERT(debugName->m_type == CTNT_EXPRESSION && debugName->m_subType == CTNET_IDENTIFIER);
      m_currentFunction->m_debugName = debugName->m_data.m_string;
    }
  }

  // Parameters
  const gmCodeTreeNode * params = a_node->m_children[0];
  int numParams = 0;
  while(params)
  {
    const gmCodeTreeNode * param = params->m_children[0];
    GM_ASSERT(param->m_type == CTNT_EXPRESSION && param->m_subType == CTNET_IDENTIFIER);
    if(m_currentFunction->SetVariableType(param->m_data.m_string, CTVT_LOCAL) != numParams)
    {
      if(m_log) m_log->LogEntry("error (%d) parameter %s already declared", param->m_lineNumber, param->m_data.m_string);
      PopFunction();
      return false;
    }
    ++numParams;
    params = params->m_sibling;
  }

  // Generate the code
  bool res = Generate(a_node->m_children[1], &m_currentFunction->m_byteCode);

  // Generate a return incase the function didnt have one.
  m_currentFunction->m_byteCode.Emit(BC_RET);

  if(res)
  {
    // Create a locals table
    const char ** locals = NULL;
    if(m_debug)
    {
      locals = (const char **) alloca(sizeof(const char *) * m_currentFunction->m_numLocals);
      memset(locals, 0, sizeof(const char *) * m_currentFunction->m_numLocals);

      for(gmuint v = 0; v < m_currentFunction->m_variables.Count(); ++v)
      {
        Variable &variable = m_currentFunction->m_variables[v];
        if(variable.m_offset != -1)
        {
          locals[variable.m_offset] = variable.m_symbol;
        }
      }
    }

    // Add the function to the hooks.

    gmSortDebugLines(m_currentFunction->m_lineInfo);
    
    gmFunctionInfo info;
    info.m_id = id;
    info.m_root = false;
    info.m_byteCode = m_currentFunction->m_byteCode.GetData();
    info.m_byteCodeLength = m_currentFunction->m_byteCode.Tell();
    info.m_numParams = numParams;
    info.m_numLocals = m_currentFunction->m_numLocals - numParams;
    info.m_symbols = locals;
    info.m_maxStackSize = m_currentFunction->m_byteCode.GetMaxTos();
    info.m_lineInfoCount = m_currentFunction->m_lineInfo.Count();
    info.m_lineInfo = m_currentFunction->m_lineInfo.GetData();
    info.m_debugName = m_currentFunction->m_debugName;
    m_hooks->AddFunction(info);

    //gmByteCodePrint(stdout, info.m_byteCode, info.m_byteCodeLength);
  }

  PopFunction();
  
  return res;
}
Example #10
0
bool gmCodeGenPrivate::GenExprOpAssign(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
  GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_OPERATION);

  // value on left hand side must be an l-value... ie, a dot, array or identifier.
  const gmCodeTreeNode * lValue = a_node->m_children[0];
  int type = 0;

  if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_DOT)
  {
    // Generate half l-value
    if(!Generate(lValue->m_children[0], a_byteCode)) return false;
    type = 0;
  }
  else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_ARRAY_INDEX)
  {
    // Generate half l-value
    if(!Generate(lValue->m_children[0], a_byteCode)) return false;
    if(!Generate(lValue->m_children[1], a_byteCode)) return false;
    type = 1;
  }
  else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_IDENTIFIER)
  {
    type = 2;
  }
  else
  {
    if(m_log) m_log->LogEntry("error (%d) illegal l-value for '=' operator", a_node->m_lineNumber);
    return false;
  }

  // Generate r-value
  if(!Generate(a_node->m_children[1], a_byteCode)) return false;

  // complete assignment
  if(type == 0)
  {
    a_byteCode->EmitPtr(BC_SETDOT, m_hooks->GetSymbolId(lValue->m_children[1]->m_data.m_string));
  }
  else if(type == 1)
  {
    a_byteCode->Emit(BC_SETIND);
  }
  else if(type == 2)
  {
    gmCodeTreeVariableType vtype;
    int offset = m_currentFunction->GetVariableOffset(lValue->m_data.m_string, vtype);

    // if local, set local regardless
    // if member set this
    // if global, set global
    // set and add local

    if((lValue->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0)
    {
      return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
    }
    if(offset >= 0 && vtype == CTVT_LOCAL)
    {
      return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
    }
    else if(offset == -1)
    {
      if(vtype == CTVT_MEMBER)
      {
        return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
      }
      else if(vtype == CTVT_GLOBAL)
      {
        return a_byteCode->EmitPtr(BC_SETGLOBAL, m_hooks->GetSymbolId(lValue->m_data.m_string));
      }
      if(m_log) m_log->LogEntry("internal error");
      return false;
    }

    offset = m_currentFunction->SetVariableType(lValue->m_data.m_string, CTVT_LOCAL);
    return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
  }
  else
  {
    // paranoia
    if(m_log) m_log->LogEntry("internal error");
    return false;
  }

  return true;
}
Example #11
0
bool gmCodeGenPrivate::GenExprCall(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
  GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_CALL);

  // mark the stack.
  int stackLevel = a_byteCode->GetTos();

  // if callee is a dot function, push left side of dot as 'this'
  const gmCodeTreeNode * callee = a_node->m_children[0];

  if(callee->m_type == CTNT_EXPRESSION && callee->m_subType == CTNET_OPERATION && callee->m_subTypeType == CTNOT_DOT)
  {
    if(!Generate(callee->m_children[0], a_byteCode)) return false;
    a_byteCode->Emit(BC_DUP);
    a_byteCode->EmitPtr(BC_GETDOT, m_hooks->GetSymbolId(callee->m_children[1]->m_data.m_string));
  }
  else
  {
    if(a_node->m_children[2])
    {
      if(!Generate(a_node->m_children[2], a_byteCode)) return false;
    }
    else
    {
#if GM_COMPILE_PASS_THIS_ALWAYS

      a_byteCode->Emit(BC_PUSHTHIS);

#else // !GM_COMPILE_PASS_THIS_ALWAYS

      // if the lvalue is a member, pass 'this', otherwise pass 'null'
      bool pushed = false;
      if(callee->m_type == CTNT_EXPRESSION && callee->m_subType == CTNET_IDENTIFIER)
      {
        gmCodeTreeVariableType vtype;
        int offset = m_currentFunction->GetVariableOffset(callee->m_data.m_string, vtype);
        if(((callee->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0) || (offset == -1 && vtype == CTVT_MEMBER))
        {
          a_byteCode->Emit(BC_PUSHTHIS);
          pushed = true;
        }
      }
      if(!pushed)
      {
        a_byteCode->Emit(BC_PUSHNULL);
      }

#endif // !GM_COMPILE_PASS_THIS_ALWAYS
    }
    if(!Generate(callee, a_byteCode)) return false;
  }

  // push parameters, count the number of parameters
  gmuint32 numParams = 0;

  const gmCodeTreeNode * params = a_node->m_children[1];

  while(params)
  {
    ++numParams;
    if(!Generate(params, a_byteCode, false)) return false;
    params = params->m_sibling;
  }

  // call
  a_byteCode->Emit(BC_CALL, (gmuint32) numParams);

  // restore the stack level.
  a_byteCode->SetTos(stackLevel + 1);

  return true;
}
Example #12
0
bool gmCodeGenPrivate::GenExprOpPreIncDec(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
  GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_OPERATION);

  // Make sure child 0 is an l-value
  const gmCodeTreeNode * lValue = a_node->m_children[0];
  int type = 0;

  if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_DOT)
  {
    // Generate half l-value
    if(!Generate(lValue->m_children[0], a_byteCode)) return false;
    a_byteCode->Emit(BC_DUP);
    a_byteCode->EmitPtr(BC_GETDOT, m_hooks->GetSymbolId(lValue->m_children[1]->m_data.m_string));
    type = 0;
  }
  else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_ARRAY_INDEX)
  {
    // Generate half l-value
    if(!Generate(lValue->m_children[0], a_byteCode)) return false;
    if(!Generate(lValue->m_children[1], a_byteCode)) return false;
    a_byteCode->Emit(BC_DUP2);
    a_byteCode->Emit(BC_GETIND);
    type = 1;
  }
  else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_IDENTIFIER)
  {
    if(!Generate(lValue, a_byteCode)) return false;
    type = 2;
  }
  else
  {
    if(m_log) m_log->LogEntry("illegal l-value for '++/--' operator, line %d", a_node->m_lineNumber);
    return false;
  }

  // Perform inc/dec
  switch(a_node->m_subTypeType)
  {
    case CTNOT_PRE_INC : a_byteCode->Emit(BC_OP_INC); break;
    case CTNOT_PRE_DEC : a_byteCode->Emit(BC_OP_DEC); break;
    default :
    {
      if(m_log) m_log->LogEntry("unkown operator");
      return false;
    }
  }

  // Write back the value
  if(type == 0)
  {
    int offset = m_currentFunction->SetVariableType(s_tempVarName0, CTVT_LOCAL);
    a_byteCode->Emit(BC_DUP);
    a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
    a_byteCode->EmitPtr(BC_SETDOT, m_hooks->GetSymbolId(lValue->m_children[1]->m_data.m_string));
    a_byteCode->Emit(BC_GETLOCAL, (gmuint32) offset);
  }
  else if(type == 1)
  {
    int offset = m_currentFunction->SetVariableType(s_tempVarName0, CTVT_LOCAL);
    a_byteCode->Emit(BC_DUP);
    a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
    a_byteCode->Emit(BC_SETIND);
    a_byteCode->Emit(BC_GETLOCAL, (gmuint32) offset);
  }
  else if(type == 2)
  {
    a_byteCode->Emit(BC_DUP);
    gmCodeTreeVariableType vtype;
    int offset = m_currentFunction->GetVariableOffset(lValue->m_data.m_string, vtype);

    // if local, set local regardless
    // if member set this
    // if global, set global
    // set and add local

    if((lValue->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0)
    {
      return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
    }

    if(offset >= 0 && vtype == CTVT_LOCAL)
    {
      return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
    }
    else if(offset == -1)
    {
      if(vtype == CTVT_MEMBER)
      {
        return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
      }
      else if(vtype == CTVT_GLOBAL)
      {
        return a_byteCode->EmitPtr(BC_SETGLOBAL, m_hooks->GetSymbolId(lValue->m_data.m_string));
      }
      if(m_log) m_log->LogEntry("internal error");
      return false;
    }

    offset = m_currentFunction->SetVariableType(lValue->m_data.m_string, CTVT_LOCAL);
    return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
  }
  else
  {
    // paranoia
    if(m_log) m_log->LogEntry("internal error");
    return false;
  }

  return true;
}
Example #13
0
bool PlaneGenerator::onInit() {
	Generate();

	return true;
}
TurbulentDispersionScene::TurbulentDispersionScene(dReal left_bor, int rankid,dReal WORLD_SIZE_X,dReal WORLD_SIZE_Z, dReal WORLD_SIZE_Y,DEMDomain_3D *domain): BaseScene(left_bor,rankid,WORLD_SIZE_X,WORLD_SIZE_Z,WORLD_SIZE_Y,domain)
{
    /*dBodyID body=dBodyCreate(domain->getWorld());
    dGeomID geom=dCreateSphere(domain->getSpace(),1);

    Particle *p=new Particle(body,geom);
    p->setMass(2000,1e-1);

    p->setCategoryBits(catBits[PARTICLES]);
    p->setCollideBits(catBits[WALLS]&(~catBits[PARTICLES]));

    p->setPosition(0.5,0.5,0.5);
    p->setLinearVel(0,0,0);
    
    domain->AddDynamicBody(p); 
    */
        
    domain->setGravity(-9.81,0,0);
    
    beforeMakeStepEvent = domain->fireOnAfterStepEvent.connect([&](dReal a) { TurbulentDispersionScene::BeforeMakeStep(a); } );
    afterMakeStepEvent = domain->fireOnAfterStepEvent.connect([&](dReal a) { TurbulentDispersionScene::AfterMakeStep(a); } );        
    
    TKE=0.03;
    epsilon=0.139;
        
    te=0;                               //time in eddy
    cps = 0.3;//0.16432;                      //0.09^0.75
    le=(cps*pow(TKE, 1.5)/epsilon);     //dissipation length scale                
    sigma = sqrt(2.0*TKE/3.0);            
    
    
    //DENSITY=1.2922;                   //density of particles=density of the fluid 
    DENSITY=8900;                     //density of copper particles 
    //DENSITY=2500;                     //density of glass particles 
    //DENSITY=1000;                     //density of corn pollen particles 
    //DENSITY=260;                        //density of hollow glass particles 
                        
    pg=new ParticleGenerator(domain->getDomainID());
    //set radius in microns
    pg->RadiusPDF()->set_params<RANDOM_CONSTANT>(23.25);  //copper
    //pg->RadiusPDF()->set_params<RANDOM_CONSTANT>(43.5);   //glass
    //pg->RadiusPDF()->set_params<RANDOM_CONSTANT>(43.5);   //corn pollen
    //pg->RadiusPDF()->set_params<RANDOM_CONSTANT>(23.25);     //hollow glass
    //pg->RadiusPDF()->set_params<RANDOM_CONSTANT>(1);   //fluid particle
    
    pg->PositionPDF_X()->set_params<RANDOM_CONSTANT>(0.1114);
    pg->PositionPDF_Y()->set_params<RANDOM_CONSTANT>(0);
    //line source of particles
    //pg->PositionPDF_Y()->set_params<RANDOM_UNIFORM>(0.2,0.8);
            
    pg->PositionPDF_Z()->set_params<RANDOM_CONSTANT>(0);
    //line source of particles
    //pg->PositionPDF_Z()->set_params<RANDOM_UNIFORM>(0.2,0.8);

    //particle velocity components are equal fluid mean components
    pg->VelocityPDF_X()->set_params<RANDOM_CONSTANT>(6.55);
    pg->VelocityPDF_Y()->set_params<RANDOM_CONSTANT>(0);
    pg->VelocityPDF_Z()->set_params<RANDOM_CONSTANT>(0);
        
    pg->TurbVelocityPDF()->set_params<RANDOM_GAUSSIAN_NO_LIMIT>(0,sigma);    
                  
    pg->tTurbPDF()->set_params<RANDOM_UNIFORM>(0.001,0.999);
                        
    pg->DisableAfterNParticlesGenerated(1000); 
    
    Generate();
}
Example #15
0
void Board::Reset()
{
	Generate();
	step_count = 0;
	win = false;
}
Example #16
0
bool gmCodeGenPrivate::GenStmtCompound(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
  return Generate(a_node->m_children[0], a_byteCode);
}
Example #17
0
	void Texture::LoadFromMemory(void* buffer,int size)
	{
		sf::Image img;
		img.loadFromMemory(buffer,size);
		Generate(img);
	}
Example #18
0
City::City( btDiscreteDynamicsWorld &dynamicsWorld ) : world(dynamicsWorld) {
    Generate();
}
Example #19
0
void SEAL::Seek(unsigned long seekPosition)
{
	counter = startCount + seekPosition/(L/8);
	position = seekPosition%(L/8);
	Generate(counter, buffer);
}
Example #20
0
PlayerData::PlayerData(PlayerProgram *program) : program(program)
{
    Generate();
}
std::vector<std::string> Function_Expression_Generator::Get_Generations(){
	return Generate(m_parse_tree);
}
//See documentation for explanation on the input parameters
struct ParseTree* Parse(int ** __Grammers, int *__Rows, int __countRows,  int __countTerminals,int __countNonterminals, int *__intInput, int __CountInput){

	int **_parseTable;
	struct stack *_ItemStack = (struct stack*)malloc(sizeof(struct stack));
	int i;
	int *_production;
	struct ParseTree *_ptrHeader;
	int *_adjInput = (int *)malloc(sizeof(int)*(__CountInput+1));
	struct ParseTree *_ptrCurrentNode;
	
	//M[X, a]
	int M_a;
	//the number of items in the production[] array
	int _countProductionOutput;
	_parseTable = Generate(__Grammers, __Rows, __countRows, __countTerminals, __countNonterminals);
	//push $
	Push(&_ItemStack, __countTerminals +__countNonterminals+1);
	_ptrCurrentNode = CreateParseTree();
	_ptrCurrentNode->value =0;
	_ptrHeader = _ptrCurrentNode;
	
	//push First production
	Push(&_ItemStack, 0);
	i =0;
	
	//add the endmarker to the input;
	for (int i = 0; i <__CountInput;i++){
		_adjInput[i] =__intInput[i];
	}
	//$
	_adjInput[__CountInput] = __countNonterminals + __countNonterminals+1;
	
	while (_ItemStack->value != __countTerminals +__countNonterminals+1){
		//if terminals match
		if (_ItemStack->value == _adjInput[i]) {
			_ptrCurrentNode =  GetNextInStack(_ptrCurrentNode);
			Pop(&_ItemStack);
		
			i++;
		}
		//Epsilon character
		else if(_ItemStack->value ==__countNonterminals+__countNonterminals){
			_ptrCurrentNode =  GetNextInStack(_ptrCurrentNode);
			Pop(&_ItemStack);
		}
		else if(_ItemStack->value >=__countNonterminals){
			printf("Error, Terminals don't match\n");
			abort();
		}
		else if(_parseTable[_ItemStack->value][_adjInput[i]-__countNonterminals]==-1){
			printf("Error, Error entry in parse table\n");
			abort();
		}
		else{
			if (_adjInput[i] == __countNonterminals + __countTerminals +1){
				//$ sign
				M_a = _parseTable[_ItemStack->value][_adjInput[i]-__countNonterminals-1];	
			}
			else{
				M_a = _parseTable[_ItemStack->value][_adjInput[i]-__countNonterminals];	
			}
			Pop(&_ItemStack);
			//get items in production
			_production = GetProduction(__Grammers, M_a, __countTerminals+ __countNonterminals+1, &_countProductionOutput);
			//add items to tree
			 Add(_ptrCurrentNode, _production, _countProductionOutput);
			 _ptrCurrentNode = _ptrCurrentNode->FirstChild;
			 for (int j =  _countProductionOutput-1; j >=0; j--){
				 if (_production[j] !=-1){
					Push(&_ItemStack,  _production[j]);
				 }
			 }
		}
	}

	return _ptrHeader;
}
Example #23
0
int
main()
{
  // setup random number generator
  gRandomGenerator = gsl_rng_alloc(gsl_rng_taus);
  gsl_rng_set (gRandomGenerator, 0.0);

  // created a rapidity cut named "eta", which returns true if the passed track has a
  //  pseudo-rapidity greater than 0.1
  Cut c0("eta", new eta_greator(0.1));

  // add some other cuts acting on different ranges
  c0.AddCut("zab>2", new eta_greator(2.0))(new eta_greator(5.0))(new eta_greator(8.0));

  // Create a pt cut
  Cut pt_cut("pt>3", new pt_greator(3.0));

  // Create a pt cut
  Cut pt_cut("pt>3.0", new pt_greator(3.0));

  // add some more cuts to the pt-cut group
  //  (Cut::AddCut returns an inserter with operator() which
  //   continues to insert if given a name + function pair)
  pt_cut.AddCut("pt>4.0", new pt_greator(4.0))
               ("pt>6.0", new pt_greator(6.0))
               ("pt>2.0", new pt_greator(2.0))
               ("pt>1.0", new pt_greator(1.0));

  // create a cutlist
  CutList cuts;
  cuts.AddCut(pt_cut);

//  cuts.AddAction("eta", add_to_histogram_eta_1);
//  cuts.AddAction("pt>3 zab>2", add_to_histogram_1);
//  cuts.AddAction("pt>3 eta", add_to_histogram_4);

  cuts.AddAction("pt>3.0", action_pt_3_0);
  cuts.AddAction("pt>4.0", action_pt_4_0);
  cuts.AddAction("pt>1.0", action_pt_1_0);
  cuts.AddAction("pt>2.0", action_pt_2_0);
  cuts.AddAction("pt>6.0", action_pt_6_0);

  cuts.AddAction("pt>4.0 pt>2.0", action_pt_4_AND_2);

//  cuts.Print();

  // generate a random cut
  Track track = Generate();
  track.print();
  std::cout << "Testing Random : " << cuts.Run(track) << std::endl;
  for (int i = 0; i < 50; i++) {
    Track t = Generate();
//    std::cout << "Mass : " << t.m << std::endl;
    cuts.Run(t);
  }
  // std::cout << c0.Run(1.0f) << ' ' << c0.Run(9.0f) << std::endl;
  puts("");

std::cout << "Pt > 1.0 Count : " << pt_1_count << std::endl
          << "Pt > 2.0 Count : " << pt_2_count << std::endl
          << "Pt > 3.0 Count : " << pt_3_count << std::endl
          << "Pt > 4.0 Count : " << pt_4_count << std::endl
          << "Pt > 6.0 Count : " << pt_6_count << std::endl;



  std::cout << "It works!" << std::endl;
  return 0;
}
Example #24
0
void RayGenerator::Generate(int pw,int ph,int x,int y,Vec3q *out) const {
	Generate(level, pw, ph, x, y, out);
}
Example #25
0
void ColorGenerator::Generate(Vector<RGBColor> &Result)
{
    Generate(Result, Vec3f(1.0f, 1.0f, 1.0f));
}
Example #26
0
/**
* Crea la vista preliminar borrando la previa.
*/
void VisualEditor::Create()
{
#if wxVERSION_NUMBER < 2900 && !defined(__WXGTK__ )
    if ( IsShown() )
    {
        Freeze();   // Prevent flickering on wx 2.8,
        // Causes problems on wx 2.9 in wxGTK (e.g. wxNoteBook objects)
    }
#endif
    // Delete objects which had no parent
    DeleteAbstractObjects();

    // Clear selections, delete objects
    m_back->SetSelectedItem(NULL);
    m_back->SetSelectedSizer(NULL);
    m_back->SetSelectedObject(PObjectBase());

    ClearAui();
    ClearWizard();
    ClearComponents( m_back->GetFrameContentPanel() );

    m_back->GetFrameContentPanel()->DestroyChildren();
    m_back->GetFrameContentPanel()->SetSizer( NULL ); // *!*

    // Clear all associations between ObjectBase and wxObjects
    m_wxobjects.clear();
    m_baseobjects.clear();

    if( IsShown() )
    {
        m_form = AppData()->GetSelectedForm();
        if ( m_form )
        {
            m_back->Show(true);

            // --- [1] Configure the size of the form ---------------------------

            // Get size properties
            wxSize minSize( m_form->GetPropertyAsSize( wxT("minimum_size") ) );
            m_back->SetMinSize( minSize );

            wxSize maxSize( m_form->GetPropertyAsSize( wxT("maximum_size") ) );
            m_back->SetMaxSize( maxSize );

            wxSize size( m_form->GetPropertyAsSize( wxT("size") ) );

            // Determine necessary size for back panel
            wxSize backSize = size;
            if ( backSize.GetWidth() < minSize.GetWidth() && backSize.GetWidth() != wxDefaultCoord )
            {
                backSize.SetWidth( minSize.GetWidth() );
            }
            if ( backSize.GetHeight() < minSize.GetHeight() && backSize.GetHeight() != wxDefaultCoord )
            {
                backSize.SetHeight( minSize.GetHeight() );
            }
            if ( backSize.GetWidth() > maxSize.GetWidth() && maxSize.GetWidth() != wxDefaultCoord )
            {
                backSize.SetWidth( maxSize.GetWidth() );
            }
            if ( backSize.GetHeight() > maxSize.GetHeight() && maxSize.GetHeight() != wxDefaultCoord )
            {
                backSize.SetHeight( maxSize.GetHeight() );
            }

            // Modify size property to match
            if ( size != backSize )
            {
                PProperty psize = m_form->GetProperty( wxT("size") );
                if ( psize )
                {
                    AppData()->ModifyProperty( psize, TypeConv::SizeToString( backSize ) );
                }
            }

            // --- [2] Set the color of the form -------------------------------
            PProperty background( m_form->GetProperty( wxT("bg") ) );
            if ( background && !background->GetValue().empty() )
            {
                m_back->GetFrameContentPanel()->SetBackgroundColour( TypeConv::StringToColour( background->GetValue() ) );
            }
            else
            {
                if ( m_form->GetClassName() == wxT("Frame") )
                {
                    m_back->GetFrameContentPanel()->SetOwnBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE ) );
                }
                else
                {
#ifdef __WXGTK__
                    wxVisualAttributes attribs = wxToolBar::GetClassDefaultAttributes();
                    m_back->GetFrameContentPanel()->SetOwnBackgroundColour( attribs.colBg );
#else
                    m_back->GetFrameContentPanel()->SetOwnBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
#endif
                }
            }

            // --- [3] Title bar Setup
            if (  m_form->GetClassName() == wxT("Frame")  ||
                    m_form->GetClassName() == wxT("Dialog") ||
                    m_form->GetClassName() == wxT("Wizard") )
            {
                m_back->SetTitle( m_form->GetPropertyAsString( wxT("title") ) );
                long style = m_form->GetPropertyAsInteger( wxT("style") );
                m_back->SetTitleStyle( style );
                m_back->ShowTitleBar( (style & wxCAPTION) != 0 );
            }
            else
                m_back->ShowTitleBar(false);

            // --- AUI
            if(  m_form->GetObjectTypeName() == wxT("form") )
            {
                if(  m_form->GetPropertyAsInteger( wxT("aui_managed") ) == 1)
                {
                    m_auipanel = new wxPanel( m_back->GetFrameContentPanel() );
                    m_auimgr = new wxAuiManager( m_auipanel, m_form->GetPropertyAsInteger( wxT("aui_manager_style") ) );
                }
            }

            // --- Wizard
            if ( m_form->GetClassName() == wxT("Wizard") )
            {
                m_wizard = new Wizard( m_back->GetFrameContentPanel() );

                bool showbutton = false;
                PProperty pextra_style = m_form->GetProperty( wxT("extra_style") );
                if ( pextra_style )
                {
                    showbutton = pextra_style->GetValue().Contains( wxT("wxWIZARD_EX_HELPBUTTON") );
                }

                m_wizard->ShowHelpButton( showbutton );

                if ( !m_form->GetProperty( wxT("bitmap") )->IsNull() )
                {
                    wxBitmap bmp = m_form->GetPropertyAsBitmap( wxT("bitmap") );
                    if ( bmp.IsOk() )
                    {
                        m_wizard->SetBitmap( bmp );
                    }
                }
            }

            // --- [4] Create the components of the form -------------------------

            // Used to save frame objects for later display
            PObjectBase menubar;
            wxWindow* statusbar = NULL;
            wxWindow* toolbar = NULL;

            for ( unsigned int i = 0; i < m_form->GetChildCount(); i++ )
            {
                PObjectBase child = m_form->GetChild( i );

                if( !menubar && (m_form->GetObjectTypeName() == wxT("menubar_form")) )
                {
                    // main form acts as a menubar
                    menubar = m_form;
                }
                else if (child->GetObjectTypeName() == wxT("menubar") )
                {
                    // Create the menubar later
                    menubar = child;
                }
                else if( !toolbar && (m_form->GetObjectTypeName() == wxT("toolbar_form")) )
                {
                    Generate( m_form, m_back->GetFrameContentPanel(), m_back->GetFrameContentPanel() );

                    ObjectBaseMap::iterator it = m_baseobjects.find( m_form.get() );
                    toolbar = wxDynamicCast( it->second, wxToolBar );

                    break;
                }
                else
                {
                    // Recursively generate the ObjectTree
                    try
                    {
                        // we have to put the content frame panel as parentObject in order
                        // to SetSizeHints be called.
                        if( m_auipanel )
                        {
                            Generate( child, m_auipanel, m_auipanel );
                        }
                        else if( m_wizard )
                        {
                            Generate( child, m_wizard, m_wizard );
                        }
                        else
                            Generate( child, m_back->GetFrameContentPanel(), m_back->GetFrameContentPanel() );

                    }
                    catch ( wxFBException& ex )
                    {
                        wxLogError ( ex.what() );
                    }
                }

                // Attach the toolbar (if any) to the frame
                if (child->GetClassName() == wxT("wxToolBar") )
                {
                    ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
                    toolbar = wxDynamicCast( it->second, wxToolBar );
                }
                else if (child->GetClassName() == wxT("wxAuiToolBar") )
                {
                    ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
                    toolbar = wxDynamicCast( it->second, wxAuiToolBar );
                }

                // Attach the status bar (if any) to the frame
                if ( child->GetClassName() == wxT("wxStatusBar") )
                {
                    ObjectBaseMap::iterator it = m_baseobjects.find( child.get() );
                    statusbar = wxDynamicCast( it->second, wxStatusBar );
                }

                // Add toolbar(s) to AuiManager and update content
                if( m_auimgr && toolbar )
                {
                    SetupAui( GetObjectBase( toolbar ), toolbar );
                    toolbar = NULL;
                }
            }

            if ( menubar || statusbar || toolbar || m_auipanel || m_wizard )
            {
                if( m_auimgr )
                {
                    m_back->SetFrameWidgets( menubar, NULL, statusbar, m_auipanel );
                }
                else if( m_wizard )
                {
                    m_back->SetFrameWidgets( menubar, NULL, NULL, m_wizard );
                }
                else
                    m_back->SetFrameWidgets( menubar, toolbar, statusbar, m_auipanel );
            }

            m_back->Layout();

            if ( backSize.GetHeight() == wxDefaultCoord || backSize.GetWidth() == wxDefaultCoord )
            {
                m_back->GetSizer()->Fit( m_back );
                m_back->SetSize( m_back->GetBestSize() );
            }

            // Set size after fitting so if only one dimesion is -1, it still fits that dimension
            m_back->SetSize( backSize );

            if( m_auimgr ) m_auimgr->Update();
            else
                m_back->Refresh();

            PProperty enabled( m_form->GetProperty( wxT("enabled") ) );
            if ( enabled )
            {
                m_back->Enable( TypeConv::StringToInt( enabled->GetValue() ) != 0 );
            }

            PProperty hidden( m_form->GetProperty( wxT("hidden") ) );
            if ( hidden )
            {
                m_back->Show( TypeConv::StringToInt( hidden->GetValue() ) == 0 );
            }
        }
        else
        {
            // There is no form to display
            m_back->Show(false);
            Refresh();
        }
#if wxVERSION_NUMBER < 2900 && !defined(__WXGTK__)
        Thaw();
#endif
    }

    UpdateVirtualSize();
}
void DFA_Genrator::init(Graph * NFA , unordered_map<char,int> input_map){
    vector < vector < int > > trans_nfa;
    vector < vector <int > > eClouser;
    vector<bool> finalState;
    vector<string> token_type;

    vector<int> state_clouser;
    vector<int> state_trans;

    int node_name = 0;

    //BFS
    queue <Node*> q;

    // map of key = node name and value index of the node in transition table
    // if there was a value for the givven node name
    unordered_map<int,int> node_holder;

    // Node of old graph
    Node* temp_node;
    // Children of old graph
    vector<Edge> *children;

    temp_node = NFA->get_start_node();
    cout<< temp_node->get_node_name() << "Is Acceptance = " << temp_node->is_acceptance_node()<< "Token Type =" << temp_node->get_token_type() <<endl;
    // New start Node
    finalState.push_back(temp_node->is_acceptance_node());
    token_type.push_back(temp_node->get_token_type());

    //Push first node
    q.push(temp_node);
    node_holder.insert(pair<int,int>(temp_node->get_node_name(), node_name++));

    while(q.size()!=0)
    {
        temp_node = q.front(); // old node
        q.pop();

        children = temp_node->get_children();
        Node * node;

        for(int i=0; i< children->size(); i++)
        {
            node = (*children)[i].get_end_node(); // children #i
            cout<< node->get_node_name() << "Is Acceptance = " << node->is_acceptance_node()<< "Token Type =" << node->get_token_type() <<endl;
            if( node_holder.find(node->get_node_name()) != node_holder.end() ){ // visited add to new graph only
                if( (*children)[i].get_value() == "\\L"){ // if epson add it to epson clousre
                    state_clouser.push_back(node_holder[node->get_node_name()]);
                }else{ // not epson, add it trans_table
                    state_trans.push_back(node_holder[node->get_node_name()]); // state number
                    state_trans.push_back(input_map[(*children)[i].get_value()[0]]); // input for the previous state number
                }
                continue;
            }

            //Not visited

            // New start Node
            finalState.push_back(node->is_acceptance_node());
            token_type.push_back(node->get_token_type());

            //Push first node
            q.push(node);
            node_holder.insert(pair<int,int>(node->get_node_name(), node_name++));

            if( (*children)[i].get_value() == "\\L"){ // if epson add it to epson clousre
                state_clouser.push_back(node_holder[node->get_node_name()]);
            }else{ // not epson, add it trans_table
                state_trans.push_back(node_holder[node->get_node_name()]); // state number
                state_trans.push_back(input_map[(*children)[i].get_value()[0]]); // input for the previous state number
            }
        }
        if (state_trans.size()<2){
            state_trans.push_back(-1);
            state_trans.push_back(-1);
        }

        trans_nfa.push_back(state_trans);
        eClouser.push_back(state_clouser);
        state_clouser.clear();
        state_trans.clear();
    }
    cout<< "*******************************************"<<endl;
    cout<< "Transition Table :" << endl;
    for(int i = 0 ; i < trans_nfa.size() ;i++){
        vector<int> v = trans_nfa[i];
        cout<< "Row " << i << endl;
        cout<< endl;
        for(int j= 0 ; j < v.size() ; j++)
            cout<< " "<<v[j];
        cout<< " |  is final = "  << finalState[i] << " | Token Type = " << token_type[i] << "| Epson Closure ";
        vector<int> e_clo = eClouser[i];
        for(int j = 0 ; j < e_clo.size();j++)
            cout<< " " << e_clo[j];
        cout<< endl;

    }
    cout<< "End **********************************"<<endl;
    Generate(trans_nfa , eClouser , input_map.size() , finalState , token_type);
}
Example #28
0
/**
* Generates wxObjects from ObjectBase
*
* @param obj ObjectBase to generate.
* @param parent wxWindow parent, necessary to instantiate a widget.
* @param parentObject ObjectBase parent - not always the same as the wxparent (e.g. an abstract component).
*/
void VisualEditor::Generate( PObjectBase obj, wxWindow* wxparent, wxObject* parentObject )
{
    // Get Component
    PObjectInfo obj_info = obj->GetObjectInfo();
    IComponent* comp = obj_info->GetComponent();

    if ( NULL == comp )
    {
        THROW_WXFBEX( wxString::Format( wxT("Component for %s not found!"), obj->GetClassName().c_str() ) );
    }

    // Create Object
    wxObject* createdObject = comp->Create( obj.get(), wxparent );
    wxWindow* createdWindow = NULL;
    wxSizer*  createdSizer  = NULL;

    switch ( comp->GetComponentType() )
    {
    case COMPONENT_TYPE_WINDOW:
        createdWindow = wxDynamicCast( createdObject, wxWindow );
        if ( NULL == createdWindow )
        {
            THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a window component, but this is not a wxWindow!"), obj->GetClassName().c_str() ) );
        }
        SetupWindow( obj, createdWindow );

        // Push event handler in order to respond to Paint and Mouse events
        comp->PushEventHandler( createdWindow, new VObjEvtHandler( createdWindow, obj ) );
        break;

    case COMPONENT_TYPE_SIZER:
        createdSizer = wxDynamicCast( createdObject, wxSizer );
        if ( NULL == createdSizer )
        {
            THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a sizer component, but this is not a wxSizer!"), obj->GetClassName().c_str() ) );
        }
        SetupSizer( obj, createdSizer );
        break;

    default:
        break;
    }

    // Associate the wxObject* with the PObjectBase
    m_wxobjects.insert( wxObjectMap::value_type( createdObject, obj ) );
    m_baseobjects.insert( ObjectBaseMap::value_type( obj.get(), createdObject ) );

    // New wxparent for the window's children
    wxWindow* new_wxparent = ( createdWindow ? createdWindow : wxparent );

    // Recursively generate the children
    for ( unsigned int i = 0; i < obj->GetChildCount(); i++ )
    {
        if (obj->GetClassName() == wxT("wxCollapsiblePane"))
            Generate( obj->GetChild( i ), ((wxCollapsiblePane*)new_wxparent)->GetPane(), createdObject );
        else
            Generate( obj->GetChild( i ), new_wxparent, createdObject );
    }

    comp->OnCreated( createdObject, new_wxparent );

    // If the created object is a sizer and the parent object is a window, set the sizer to the window
    if (
        ( createdSizer != NULL && NULL != wxDynamicCast( parentObject, wxWindow ) )
        ||
        ( NULL == parentObject && createdSizer != NULL )
    )
    {
        wxparent->SetSizer( createdSizer );
        if ( parentObject )
            createdSizer->SetSizeHints( wxparent );

        wxparent->SetAutoLayout(true);
        wxparent->Layout();
    }
}
Example #29
0
static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, int flags)
{//========================================================================================
	// Fill the buffer with output sound
	int length;
	int finished = 0;
	int count_buffers = 0;
#ifdef USE_ASYNC
	uint32_t a_write_pos=0;
#endif

#ifdef DEBUG_ENABLED
	ENTER("Synthesize");
	if (text)
	{
	SHOW("Synthesize > uid=%d, flags=%d, >>>text=%s<<<\n", unique_identifier, flags, text);
	}
#endif

	if((outbuf==NULL) || (event_list==NULL))
		return(EE_INTERNAL_ERROR);  // espeak_Initialize()  has not been called

	option_multibyte = flags & 7;
	option_ssml = flags & espeakSSML;
	option_phoneme_input = flags & espeakPHONEMES;
	option_endpause = flags & espeakENDPAUSE;

	count_samples = 0;

#ifdef USE_ASYNC
	if(my_mode == AUDIO_OUTPUT_PLAYBACK)
	{
		a_write_pos = wave_get_write_position(my_audio);
	}
#endif

	if(translator == NULL)
	{
		SetVoiceByName("default");
	}

	SpeakNextClause(NULL,text,0);

	if(my_mode == AUDIO_OUTPUT_SYNCH_PLAYBACK)
	{
		for(;;)
		{
#ifdef PLATFORM_WINDOWS
			// Sleep(300);   // 0.3s
#else
#ifdef USE_NANOSLEEP
			struct timespec period;
			struct timespec remaining;
			period.tv_sec = 0;
			period.tv_nsec = 300000000;  // 0.3 sec
			nanosleep(&period,&remaining);
#else
			sleep(1);
#endif
#endif
			if(SynthOnTimer() != 0)
				break;
		}
		return(EE_OK);
	}

	for(;;)
	{
#ifdef DEBUG_ENABLED
		SHOW("Synthesize > %s\n","for (next)");
#endif
		out_ptr = outbuf;
		out_end = &outbuf[outbuf_size];
		event_list_ix = 0;
		WavegenFill(0);

		length = (out_ptr - outbuf)/2;
		count_samples += length;
		event_list[event_list_ix].type = espeakEVENT_LIST_TERMINATED; // indicates end of event list
		event_list[event_list_ix].unique_identifier = my_unique_identifier;
		event_list[event_list_ix].user_data = my_user_data;

		count_buffers++;
		if (my_mode==AUDIO_OUTPUT_PLAYBACK)
		{
#ifdef USE_ASYNC
			finished = create_events((short *)outbuf, length, event_list, a_write_pos);
			length = 0; // the wave data are played once.
#endif
		}
		else
		{
			finished = synth_callback((short *)outbuf, length, event_list);
		}
		if(finished)
		{
			SpeakNextClause(NULL,0,2);  // stop
			break;
		}

		if(Generate(phoneme_list,&n_phoneme_list,1)==0)
		{
			if(WcmdqUsed() == 0)
			{
				// don't process the next clause until the previous clause has finished generating speech.
				// This ensures that <audio> tag (which causes end-of-clause) is at a sound buffer boundary

				event_list[0].type = espeakEVENT_LIST_TERMINATED;
				event_list[0].unique_identifier = my_unique_identifier;
				event_list[0].user_data = my_user_data;

				if(SpeakNextClause(NULL,NULL,1)==0)
				{
#ifdef USE_ASYNC
					if (my_mode==AUDIO_OUTPUT_PLAYBACK)
					{
						dispatch_audio(NULL, 0, NULL); // TBD: test case
					}
					else
					{
						synth_callback(NULL, 0, event_list);  // NULL buffer ptr indicates end of data
					}
#else
					synth_callback(NULL, 0, event_list);  // NULL buffer ptr indicates end of data
#endif
					break;
				}
			}
		}
    }
  return(EE_OK);
}  //  end of Synthesize
Example #30
0
bool	Field::initializeBuffers(ID3D11Device* device)
{
	Dictionnary*		dico;
	VertexType*			vertices;
	Buffers*			buffer;
	unsigned long*		indices;
	int					index;	
	int					vertexCount;
	int					indexCount;

	float				fMax = fSpacing * (unSize/2);
	float				fMin = -fMax;
	float				fDiff;
	bool				filled;
	filled = true;
	fDiff = fMax - fMin;
	Generate();
	
	vertexCount = (unSize-1) * (unSize-1) * 20;
	indexCount = vertexCount;

	if ((dico = Dictionnary::getInstance()) == nullptr)
		return false;
	vertices = new VertexType[vertexCount];
	if (vertices == false)
		return (false);
	indices = new unsigned long[indexCount];
	if (indices == false)
	{
		delete []vertices;
		return (false);
	}
	buffer = new Buffers();
	if (buffer == nullptr)
	{
		delete []vertices;
		delete []indices;
		return (false);
	}

	index = 0;
	DirectX::XMVECTOR	vec1;
	DirectX::XMVECTOR	vec2;
	DirectX::XMVECTOR	normal;

	for(unsigned int i = 0; i < (unSize - 1); i++)
	{
		float	fZ = fMin + i * fSpacing; 
		for(unsigned int j = 0; j < (unSize - 1); j++)
		{
			float fX = fMin + j * fSpacing;
			if(filled)
			{
				DirectX::XMFLOAT3	A(fX, vectPoints[i][j], fZ);
				DirectX::XMFLOAT3	B(fX, vectPoints[i + 1][j], fZ + fSpacing);
				DirectX::XMFLOAT3	C(fX + fSpacing, vectPoints[i + 1][j + 1], fZ + fSpacing);
				DirectX::XMFLOAT3	D(fX + fSpacing, vectPoints[i][j + 1], fZ);

				vec1 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(B.x - A.x, B.y - A.y, B.z - A.z));
				vec2 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(C.x - A.x, C.y - A.y, C.z - A.z));
				normal = DirectX::XMVector3Cross(vec1, vec2);
			setVertices(fX, vectPoints[i][j], fZ, i, j, vertices, indices, &index, normal, (fX + fMax) / fMax * 2, (fZ + fMax) / fMax * 2);
			setVertices(fX, vectPoints[i + 1][j], fZ + fSpacing, i, j, vertices, indices, &index, normal, (fX + fMax) / fMax * 2, (fZ + fSpacing + fMax) / fMax * 2);
			setVertices(fX + fSpacing, vectPoints[i + 1][j + 1], fZ + fSpacing, i, j, vertices, indices, &index, normal, (fX + fSpacing + fMax) / fMax * 2, (fZ + fSpacing + fMax) / fMax * 2);

				/*vec1 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(C.x - B.x, C.y - B.y, C.z - B.z));
				vec2 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(D.x - B.x, D.y - B.y, D.z - B.z));
				normal = DirectX::XMVector3Cross(vec1, vec2);
			setVertices(fX, vectPoints[i + 1][j], fZ + fSpacing, i, j, vertices, indices, &index, normal, (fX + fMax) / fMax * 2, (fZ + fSpacing + fMax) / fMax * 2);
			setVertices(fX + fSpacing, vectPoints[i + 1][j + 1], fZ + fSpacing, i, j, vertices, indices, &index, normal, (fX + fSpacing + fMax) / fMax * 2, (fZ + fSpacing + fMax) / fMax * 2);
			setVertices(fX + fSpacing, vectPoints[i][j + 1], fZ, i, j, vertices, indices, &index, normal, (fX + fSpacing + fMax) / fMax * 2, (fZ + fMax) / fMax * 2);
*/
				vec1 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(D.x - C.x, D.y - C.y, D.z - C.z));
				vec2 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(A.x - C.x, A.y - C.y, A.z - C.z));
				normal = DirectX::XMVector3Cross(vec1, vec2);
			setVertices(fX + fSpacing, vectPoints[i + 1][j + 1], fZ + fSpacing, i, j, vertices, indices, &index, normal, (fX + fSpacing + fMax) / fMax * 2, (fZ +fSpacing + fMax) / fMax * 2);
			setVertices(fX + fSpacing, vectPoints[i][j + 1], fZ, i, j, vertices, indices, &index, normal, (fX + fSpacing + fMax) / fMax * 2, (fZ + fMax) / fMax * 2);
			setVertices(fX, vectPoints[i][j], fZ, i, j, vertices, indices, &index, normal, (fX + fMax) / fMax * 2, (fZ + fMax) / fMax * 2);

				/*vec1 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(A.x - D.x, A.y - D.y, A.z - D.z));
				vec2 = DirectX::XMLoadFloat3(&DirectX::XMFLOAT3(B.x - D.x, B.y - D.y, B.z - D.z));
				normal = DirectX::XMVector3Cross(vec1, vec2);
			setVertices(fX + fSpacing, vectPoints[i][j + 1], fZ, i, j, vertices, indices, &index, normal, (fX + fSpacing + fMax) / fMax * 2, (fZ + fMax) / fMax * 2);
			setVertices(fX, vectPoints[i][j], fZ, i, j, vertices, indices, &index, normal, (fX + fMax) / fMax * 2, (fZ + fMax) / fMax * 2);
			setVertices(fX, vectPoints[i + 1][j], fZ + fSpacing, i, j, vertices, indices, &index, normal, (fX  + fMax) / fMax * 2, (fZ + fSpacing + fMax) / fMax * 2);
			*/


			
			
			/*setVertices(fX, vectPoints[i + 1][j], fZ + fSpacing, i, j, vertices, indices, &index);
			setVertices(fX, vectPoints[i + 1][j], fZ + fSpacing, i, j, vertices, indices, &index);
			setVertices(fX, vectPoints[i][j + 1], fZ, i, j, vertices, indices, &index);
			setVertices(fX, vectPoints[i + 1][j], fZ + fSpacing, i, j, vertices, indices, &index);*/
			
		
			


			}
		}
	}


	if (!buffer->init(device, D3D11_USAGE_DEFAULT, sizeof(VertexType) * vertexCount,
					  vertices, sizeof(unsigned long) * indexCount, indices))
	{
		delete []vertices;
		delete []indices;
		delete buffer;
		return false;
	}
	if (dico->getBuffer("__field", 0, buffer) == nullptr)
	{
		delete []vertices;
		delete []indices;
		delete buffer;
		return false;
	}
	delete []vertices;
	delete []indices;
	return true;
}