예제 #1
0
파일: kiss.c 프로젝트: kipr/libkiss
DWORD WINAPI kiss_main_thread( LPVOID lpParam )
#endif
{
	glfwInit();

	kiss_g_glfw_mutex = glfwCreateMutex();
	kiss_g_key_mutex = glfwCreateMutex();
	kiss_g_mouse_mutex = glfwCreateMutex();

	if(!kiss_g_glfw_mutex) {
		kiss_g_glfw_initting = 0;
		glfwTerminate();
		return 0;
	}

	glfwDisable(GLFW_AUTO_POLL_EVENTS);

	kiss_g_glfw_enabled = 1;
	kiss_g_glfw_initting = 0;

	while(!kiss_g_glfw_quit) {
		if(kiss_g_op) {
			switch(kiss_g_op) {
				case KISS_OPEN_WINDOW:
					kiss_graphics_open_window(kiss_g_op_arg1, kiss_g_op_arg2);
					glfwSetKeyCallback(kiss_input_callback);
					kiss_g_graphics_enabled=1;
					break;
				case KISS_CLOSE_WINDOW:
					kiss_graphics_close_window();
					kiss_g_graphics_enabled=0;
					break;
				case KISS_COPY:
					if(!kiss_g_graphics_enabled)
						break;
					kiss_graphics_update();
					glfwSwapBuffers();
					break;
			}
			kiss_g_op = 0;
		}
		if(kiss_g_graphics_enabled)
			glfwPollEvents();
	}

	if(kiss_g_graphics_enabled)
		kiss_graphics_close_window();

	glfwTerminate();

	kiss_g_glfw_enabled = 0;
	kiss_g_glfw_quit = 0;

	return 0;
}
예제 #2
0
파일: Message.cpp 프로젝트: KTaskn/MMDAgent
/* Message::setup: setup message queue */
bool Message::setup()
{
   clear();

   m_messageMutex = glfwCreateMutex();
   m_logStringMutex = glfwCreateMutex();

   if(m_messageMutex == NULL || m_logStringMutex == NULL) {
      clear();
      return false;
   }

   return true;
}
예제 #3
0
파일: Message.cpp 프로젝트: ljmljz/MMDAgent
/* Message::setup: setup message queue */
bool Message::setup()
{
   clear();

   m_mutexCommand = glfwCreateMutex();
   m_mutexEvent = glfwCreateMutex();
   m_mutexLog = glfwCreateMutex();

   if(m_mutexCommand == NULL || m_mutexEvent == NULL || m_mutexLog == NULL) {
      clear();
      return false;
   }

   return true;
}
예제 #4
0
void InputSystem::Initialize() {
	lock = glfwCreateMutex();
	wantsQuit = false;
	seconds = glfwGetTime();
	mousePosition = Vec2(0,0);
    glfwSetMousePosCallback(OnMouseMoved);
}
예제 #5
0
kiss_mutex create_mutex()
{
	if(!kiss_init())
		return 0;

	return glfwCreateMutex();
}
예제 #6
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;
   }
}
예제 #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;
   }
}
예제 #8
0
void debugTestThreading() {
	logWrite("Testing thread creation and access to log file (and mutex locks)");
	ThreadID Thread1 = Thread.Create(debugThread_Loop,(void*)0);
	ThreadID Thread2 = Thread.Create(debugThread_Loop,(void*)1);

	Thread.WaitForThread(Thread1);
	Thread.WaitForThread(Thread2);
	logWrite("Threads completed, killing remains...");
	Thread.Kill(Thread1);
	Thread.Kill(Thread2);

	ThreadID randomThread[TEST_MAX_THREAD_NUMBER];
	logWrite("Creating and destroying %d random threads...",TEST_MAX_THREAD_NUMBER);
	for (int i = 0; i < TEST_MAX_THREAD_NUMBER; i++) {
		randomThread[i] = Thread.Create(debugThread_InfLoop,(void*)i);		
	}
	logWrite("Waiting...");
	Thread.Sleep(3.0f);
	logWrite("Killing threads...");
	for (int i = 0; i < TEST_MAX_THREAD_NUMBER; i++) {
		Thread.Kill(randomThread[i]);
	}
	logWrite("Waiting for remaining threads...");
	for (int i = 0; i < TEST_MAX_THREAD_NUMBER; i++) {
		Thread.WaitForThread(randomThread[i]);
	}

	logWrite("Found %d processors/cores",glfwGetNumberOfProcessors());

	logWrite("Creating mutex...");
	GLFWmutex mutex = glfwCreateMutex();
	logWrite("Mutex object pointer: 0x%.8X. Trying to lock and unlock",mutex);
	glfwLockMutex(mutex);
	glfwUnlockMutex(mutex);

	logWrite("Thread test passed!\n");
}
예제 #9
0
파일: thread.cpp 프로젝트: basecq/OpenGTA2
void Thread_Manager::Initialize() {
	for (uint i=0; i < MUTEX_COUNT; i++) {
		mutexLocks[i] = glfwCreateMutex();
	}
}
예제 #10
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 );
}