Ejemplo n.º 1
0
int main(int argc,const char * argv[]) {
	 std::string track="oval.lvl"; //default level

	 if(argc>1) {
		track=std::string(argv[1]);
	 }

	 Config config=Config();
	if(!config.open(track)) {
		printf("Open error\n");
		exit(1);
	}

    Graphics::init(800, 600);

    // Create the thread for the decision module.
    DecisionModule * dm = new GeneticAlgorithm(config);
    glfwCreateThread(DMFunction, dm);

    Graphics::drawLoop();

    glfwTerminate();

    return 0;
}
Ejemplo n.º 2
0
/* Sphinx_Thread::loadAndStart: load models and start thread */
void Sphinx_Thread::loadAndStart(MMDAgent *mmdagent, const char *languageModel, const char *dictionary, const char *acousticModel, const char *configFile, const char *logFolder)
{
   /* reset */
   clear();

   m_mmdagent = mmdagent;

   m_languageModel = MMDAgent_strdup(languageModel);
   m_dictionary = MMDAgent_strdup(dictionary);
   m_acousticModel = MMDAgent_strdup(acousticModel);
   m_configFile = MMDAgent_strdup(configFile);
   m_logFolder = MMDAgent_strdup(logFolder);

   if(m_mmdagent == NULL || m_languageModel == NULL || m_dictionary == NULL || m_acousticModel == NULL || m_configFile == NULL || m_logFolder == NULL) {
      clear();
      return;
   }

   /* create recognition thread */
   glfwInit();
   m_thread = glfwCreateThread(mainThread, this);
   if(m_thread < 0) {
      clear();
      return;
   }
}
Ejemplo n.º 3
0
int start_process(void (*func)())
{
	if(!kiss_init())
		return 0;

	return glfwCreateThread(kiss_run_process, (void *)func);
}
/* Julius_Thread::loadAndStart: load models and start thread */
void Julius_Thread::loadAndStart(MMDAgent *mmdagent, const char *languageModel, const char *dictionary, const char *acousticModel, const char *triphoneList, const char *configFile, const char *userDictionary)
{
   /* reset */
   clear();

   m_mmdagent = mmdagent;

   m_languageModel = MMDAgent_strdup(languageModel);
   m_dictionary = MMDAgent_strdup(dictionary);
   m_acousticModel = MMDAgent_strdup(acousticModel);
   m_triphoneList = MMDAgent_strdup(triphoneList);
   m_configFile = MMDAgent_strdup(configFile);
   m_userDictionary = MMDAgent_strdup(userDictionary);

   if(m_mmdagent == NULL || m_languageModel == NULL || m_dictionary == NULL || m_acousticModel == NULL || m_triphoneList == NULL || m_configFile == NULL) {
      clear();
      return;
   }

   /* create recognition thread */
   glfwInit();
   m_thread = glfwCreateThread(mainThread, this);
   if(m_thread < 0) {
      clear();
      return;
   }
}
Ejemplo n.º 5
0
/* Audio_Thread::setupAndStart: setup and start thread */
void Audio_Thread::setupAndStart(MMDAgent *mmdagent)
{
   m_mmdagent = mmdagent;

   glfwInit();
   m_mutex = glfwCreateMutex();
   m_cond = glfwCreateCond();
   m_thread = glfwCreateThread(mainThread, this);
   if(m_mutex == NULL || m_cond == NULL || m_thread < 0) {
      clear();
      return;
   }
}
Ejemplo n.º 6
0
Thread::Thread(GLFWthreadfun pFunction, void * pArgument, std::string sName)
	: m_bCanStart(false),
	  m_bShouldBeRunning(true),
	  m_bThreadEnded(false),
	  m_sName(sName),
	  ///m_pFpsCounter(FpsCounter::CreateCounter(sName))
	  m_pArguments(),
	  m_oThread(-1)
{
	m_pArguments[0] = this;
	m_pArguments[1] = pArgument;
	m_oThread = glfwCreateThread(pFunction, m_pArguments);
	if (IsAlive())
		printf("%s thread (tid = %d) created.\n", m_sName.c_str(), m_oThread);
	else {
		printf("Couldn't create %s thread.\n", m_sName.c_str());
		throw 0;
	}

	//m_bCanStart = true;		// Allow the thread to start
}
Ejemplo n.º 7
0
/* Flite_Manager::loadAndStart: load and start thread */
void Flite_Manager::loadAndStart(MMDAgent *mmdagent, const char *config)
{
   clear();

   m_mmdagent = mmdagent;
   m_config = MMDAgent_strdup(config);

   if(m_mmdagent == NULL || m_config == NULL) {
      clear();
      return;
   }

   glfwInit();
   m_mutex = glfwCreateMutex();
   m_cond = glfwCreateCond();
   m_thread = glfwCreateThread(mainThread, this);
   if(m_mutex == NULL || m_cond == NULL || m_thread < 0) {
      clear();
      return;
   }
}
Ejemplo n.º 8
0
ThreadID Thread_Manager::Create(ThreadFunction* funcptr, void* param) {
	ThreadID th = glfwCreateThread(funcptr,param);
	logWrite("Spawned thread [%p] (ThreadID[0x%x])",funcptr,th);
	return th;
}
Ejemplo n.º 9
0
int main( int argc, char **argv )
{
    int        i, frames, benchmark;
    double     t0, t;
    GLFWthread physics_thread = 0;

    // Use multithreading by default, but don't benchmark
    multithreading = 1;
    benchmark = 0;

    // Check command line arguments
    for( i = 1; i < argc; i ++ )
    {
        // Use benchmarking?
        if( strcmp( argv[i], "-b" ) == 0 )
        {
            benchmark = 1;
        }

        // Force multithreading off?
        else if( strcmp( argv[i], "-s" ) == 0 )
        {
            multithreading = 0;
        }

        // With a Finder launch on Mac OS X we get a bogus -psn_0_46268417
        // kind of argument (actual numbers vary). Ignore it.
        else if( strncmp( argv[i], "-psn_", 5) == 0 );

        // Usage
        else
        {
            if( strcmp( argv[i], "-?" ) != 0 )
            {
                printf( "Unknonwn option %s\n\n", argv[ i ] );
            }
            printf( "Usage: %s [options]\n", argv[ 0 ] );
            printf( "\n");
            printf( "Options:\n" );
            printf( " -b   Benchmark (run program for 60 s)\n" );
            printf( " -s   Run program as single thread (default is to use two threads)\n" );
            printf( " -?   Display this text\n" );
            printf( "\n");
            printf( "Program runtime controls:\n" );
            printf( " w    Toggle wireframe mode\n" );
            printf( " ESC  Exit program\n" );
            exit( 0 );
        }
    }

    // Initialize GLFW
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        exit( EXIT_FAILURE );
    }

    // Open OpenGL fullscreen window
    if( !glfwOpenWindow( WIDTH, HEIGHT, 5,6,5,0, 16,0, GLFW_FULLSCREEN ) )
    {
        fprintf( stderr, "Failed to open GLFW window\n" );
        glfwTerminate();
        exit( EXIT_FAILURE );
    }

    // Set window title
    glfwSetWindowTitle( "Particle engine" );

    // Disable VSync (we want to get as high FPS as possible!)
    glfwSwapInterval( 0 );

    // Window resize callback function
    glfwSetWindowSizeCallback( Resize );

    // Set keyboard input callback function
    glfwSetKeyCallback( KeyFun );

    // Upload particle texture
    glGenTextures( 1, &particle_tex_id );
    glBindTexture( GL_TEXTURE_2D, particle_tex_id );
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, P_TEX_WIDTH, P_TEX_HEIGHT,
                  0, GL_LUMINANCE, GL_UNSIGNED_BYTE, particle_texture );

    // Upload floor texture
    glGenTextures( 1, &floor_tex_id );
    glBindTexture( GL_TEXTURE_2D, floor_tex_id );
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, F_TEX_WIDTH, F_TEX_HEIGHT,
                  0, GL_LUMINANCE, GL_UNSIGNED_BYTE, floor_texture );

    // Check if we have GL_EXT_separate_specular_color, and if so use it
    if( glfwExtensionSupported( "GL_EXT_separate_specular_color" ) )
    {
        glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL_EXT,
                       GL_SEPARATE_SPECULAR_COLOR_EXT );
    }

    // Set filled polygon mode as default (not wireframe)
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
    wireframe = 0;

    // Clear particle system
    for( i = 0; i < MAX_PARTICLES; i ++ )
    {
        particles[ i ].active = 0;
    }
    min_age = 0.0f;

    // Set "running" flag
    running = 1;

    // Set initial times
    thread_sync.t  = 0.0;
    thread_sync.dt = 0.001f;

    // Init threading
    if( multithreading )
    {
        thread_sync.p_frame = 0;
        thread_sync.d_frame = 0;
        thread_sync.particles_lock = glfwCreateMutex();
        thread_sync.p_done = glfwCreateCond();
        thread_sync.d_done = glfwCreateCond();
        physics_thread = glfwCreateThread( PhysicsThreadFun, NULL );
    }

    // Main loop
    t0 = glfwGetTime();
    frames = 0;
    while( running )
    {
        // Get frame time
        t = glfwGetTime() - t0;

        // Draw...
        Draw( t );

        // Swap buffers
        glfwSwapBuffers();

        // Check if window was closed
        running = running && glfwGetWindowParam( GLFW_OPENED );

        // Increase frame count
        frames ++;

        // End of benchmark?
        if( benchmark && t >= 60.0 )
        {
            running = 0;
        }
    }
    t = glfwGetTime() - t0;

    // Wait for particle physics thread to die
    if( multithreading )
    {
        glfwWaitThread( physics_thread, GLFW_WAIT );
    }

    // Display profiling information
    printf( "%d frames in %.2f seconds = %.1f FPS", frames, t,
            (double)frames / t );
    printf( " (multithreading %s)\n", multithreading ? "on" : "off" );

    // Terminate OpenGL
    glfwTerminate();

    exit( EXIT_SUCCESS );
}