Пример #1
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");
}
Пример #2
0
// Main function
int main(int argc, char * argv[])
{
	/*{
		PointerState test;

		test.UpdateButtonState(0) = true;
		test.UpdateButtonState(1) = true;
		test.UpdateButtonState(2) = true;

		PointerState test2(test);

		test2.UpdateButtonState(2) = false;

		std::cout << test.GetButtonState(2) << &std::endl;
		std::cout << test2.GetButtonState(2) << &std::endl;

		return 0;
	}*/
#if 0
	{
		std::function<void()> Test = []() { std::cout << "Hi from anon func.\n"; };
		//std::function<ConceptString(const std::vector<ConceptId> &)> Test = [](const std::vector<ConceptId> & Parameters){ return ConceptString({FindConcept("<"), GetParameterIfExists(Parameters, 0), FindConcept(">")}); };

		// Call Test()
		//Test();

		printf("size of func %ld\n", sizeof(Test));

		return 0;
	}
#endif







	// Set env vars
	std::string GoPath;		// This has to exist even after putenv() call because putenv simply adds a pointer rather than copying the value
	std::string Path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin";
	{
		// Initialize the value of GoPath
		GoPath = "GOPATH=";
		// Get current working directory
		{
			auto cwd = getcwd(nullptr, 0);
			if (nullptr == cwd) {
				printf("Fatal Error: getcwd() failed.");
				exit(1);
			}

			printf("Current-working-dir is '%s' (should be the folder where README.md is).\n", cwd);
			GoPath = GoPath + cwd + "/GoLand";
			GoPath += ":";
			GoPath = GoPath + cwd + "/GoLanding";
			Path = Path + ":" + cwd + "/GoLand/bin";
			free(cwd);
		}

		putenv(const_cast<char *>("DYLD_INSERT_LIBRARIES="));		// HACK: Const cast
		putenv(const_cast<char *>("TERM=xterm"));		// HACK: Const cast
		putenv(const_cast<char *>(GoPath.c_str()));		// HACK: Const cast
		// HACK: Add go/bin to $PATH by hardcoding the whole PATH for OS X
		putenv(const_cast<char *>(Path.c_str()));		// HACK: Const cast
	}

	glfwInit();
	// Verify the GLFW library and header versions match
	{
		int Major, Minor, Revision;
		glfwGetVersion(&Major, &Minor, &Revision);

		bool Match = (GLFW_VERSION_MAJOR == Major && GLFW_VERSION_MINOR == Minor && GLFW_VERSION_REVISION == Revision);

		if (!Match)
		{
			std::cerr << "Error: GLFW library and header versions do not match." << std::endl;

			throw 0;
		}
		else
		{
			std::cout << "Using GLFW " << Major << "." << Minor << "." << Revision << "." << std::endl;
		}
	}

	// Open main window
	{
		GLFWvidmode DesktopMode;
		glfwGetDesktopMode(&DesktopMode);

		glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 32);

		const bool Fullscreen = static_cast<bool>(0);
		const Vector2n WindowDimensons(1536, 960);

		if (!Fullscreen) {
			glfwOpenWindow(WindowDimensons.X(), WindowDimensons.Y(), DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 0, 0, 0, GLFW_WINDOW);
			glfwSetWindowPos((DesktopMode.Width - WindowDimensons.X()) / 2, (DesktopMode.Height - WindowDimensons.Y()) / 2);		// Center the window
		} else {
			glfwOpenWindow(DesktopMode.Width, DesktopMode.Height, DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 0, 0, 0, GLFW_FULLSCREEN);
			glfwEnable(GLFW_MOUSE_CURSOR);
		}

		{
			std::ostringstream x;
			x << "CPU Count: " << glfwGetNumberOfProcessors() << std::endl
			  << "GL Renderer: " << glGetString(GL_VENDOR) << " " << glGetString(GL_RENDERER) << " " << glGetString(GL_VERSION) << std::endl
			  << "GLFW_ACCELERATED: " << glfwGetWindowParam(GLFW_ACCELERATED) << std::endl
			  << "GLFW_RED_BITS: " << glfwGetWindowParam(GLFW_RED_BITS) << std::endl
			  << "GLFW_GREEN_BITS: " << glfwGetWindowParam(GLFW_GREEN_BITS) << std::endl
			  << "GLFW_BLUE_BITS: " << glfwGetWindowParam(GLFW_BLUE_BITS) << std::endl
			  << "GLFW_ALPHA_BITS: " << glfwGetWindowParam(GLFW_ALPHA_BITS) << std::endl
			  << "GLFW_DEPTH_BITS: " << glfwGetWindowParam(GLFW_DEPTH_BITS) << std::endl
			  << "GLFW_STENCIL_BITS: " << glfwGetWindowParam(GLFW_STENCIL_BITS) << std::endl
			  << "GLFW_REFRESH_RATE: " << glfwGetWindowParam(GLFW_REFRESH_RATE) << std::endl
			  << "GLFW_FSAA_SAMPLES: " << glfwGetWindowParam(GLFW_FSAA_SAMPLES) << std::endl;
			std::cout << x.str();
		}

		{
			//glfwSetWindowTitle("Conception");
			glfwSwapInterval(1);					// Set Vsync
			glfwDisable(GLFW_AUTO_POLL_EVENTS);

			glfwEnable(GLFW_KEY_REPEAT);
			glfwDisable(GLFW_SYSTEM_KEYS);
		}
	}

	{
		InputManager InputManager;
		g_InputManager = &InputManager;

		ConceptionApp MainApp(InputManager);
		//LiveEditorApp MainApp(InputManager);
		//ConceptionTestApp MainApp(InputManager);
		//MultitouchTestApp MainApp(InputManager);
		//SentienceApp MainApp(InputManager);

		glfwSetWindowTitle(MainApp.GetTitle().c_str());

		// Perform the layout of UI widgets
		MainApp.Layout();

		// OpenGL settings
		InitializeOpenGL();

		std::cout << std::endl;		// Done loading

		// Main loop
		while (glfwGetWindowParam(GLFW_OPENED))
		{
			auto CurrentTime = glfwGetTime();
			static auto LastTime = CurrentTime;
			auto TimePassed = CurrentTime - LastTime;
			LastTime = CurrentTime;

			// DEBUG: Moved to top of loop to enable debug printing from input handling code
			glClear(GL_COLOR_BUFFER_BIT);		// Clear frame

			// Process input
			{
				// Populate InputEventQueue
				if (MainApp.ShouldRedrawRegardless())
					glfwPollEvents();
				else {
					glfwWaitEvents();
					//if (glfwGetTime() - LastTime >= 1) printf("Slept for %f secs\n", glfwGetTime() - LastTime);
					LastTime = glfwGetTime();
				}
				//InputManager.ProcessTimePassed(TimePassed);

				MainApp.ProcessEventQueue(InputManager.ModifyInputEventQueue());
				MainApp.ProcessTimePassed(TimePassed);
			}

			// Render
			{
				// DEBUG: Moved to top of loop to enable debug printing from input handling code
				///glClear(GL_COLOR_BUFFER_BIT);		// Clear frame

				MainApp.Render();
			}

			// Display new frame
			glfwSwapBuffers();
			//glFinish();

			///printf("%f ms frame\n", TimePassed * 1000);

			// Use less CPU in background
			if (!glfwGetWindowParam(GLFW_ACTIVE))
			{
				glfwSleep(0.100);
			}
		}
	}

	// Clean up
	OglUtilsKillFont();
	glfwTerminate();

	std::cout << "\nReturning 0 from main().\n";
	return 0;
}
Пример #3
0
void PullInfo(){
  printf("================================================================================\n");
  
  int major, minor, rev;
  glfwGetVersion(&major, &minor, &rev);
  printf("GLFW version is %i.%i.%i\n", major, minor, rev);
  
  int width, height;
  glfwGetWindowSize(&width, &height);
  printf("Window size is %i %i\n", width, height);
  
  int status = glfwGetKey(GLFW_KEY_LCTRL);
  if(status == GLFW_PRESS)
    printf("Left control is pressed\n");
  else
    printf("Left control is released\n");
    
  status = glfwGetMouseButton(GLFW_MOUSE_BUTTON_1);
  if(status == GLFW_PRESS)
    printf("Mouse button 1 is pressed\n");
  else
    printf("Mouse button 1 is released\n");
    
  int x, y;
  glfwGetMousePos(&x, &y);
  printf("Mouse position is %i %i\n", x, y);
  
  int wheel = glfwGetMouseWheel();
  printf("Mouse wheel pos is %i\n", wheel);
  
  double time = glfwGetTime();
  printf("Time is %f\n", time);
  
  glfwGetGLVersion(&major, &minor, &rev);
  printf("GL version is %i.%i.%i\n", major, minor, rev);
  
  int proc = glfwGetNumberOfProcessors();
  printf("%i processors are available\n", proc);
  
  unsigned int i;
  for(i = 0; i<nb_params; i++)
    printf(" - %-27s : %i\n", GetParamName(params[i]), glfwGetWindowParam(params[i]));
  
  const char* extension = "MOZ_WEBGL_compressed_texture_s3tc";
  printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported");  
  
  extension = "GL_EXT_framebuffer_object";
  printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported");
  
  extension = "glBindBuffer";
  void* proc_addr = glfwGetProcAddress(extension);
  printf("'%s' extension proc address is %p.\n", extension, proc_addr);
  
  printf("Sleeping 1 sec...\n");
  glfwSleep(1);
  printf("...Done.\n");
  
  printf("================================================================================\n");
  
#ifdef REPORT_RESULT  
  int result = 1;
  REPORT_RESULT();
#endif
}