Advertisement
Guest User

concurrency problem paste

a guest
Jul 19th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.08 KB | None | 0 0
  1. import std.string : toStringz;
  2. import std.stdio;
  3. import std.concurrency;
  4.  
  5. import derelict.glfw3.glfw3;
  6. import derelict.opengl3.gl3;
  7.  
  8. enum REQ_WIDTH = 600;
  9. enum REQ_HEIGHT = 300;
  10. enum APP_TITLE = "window";
  11.  
  12. struct Data {
  13.     int x;
  14. }
  15.  
  16. struct Window {
  17.     this(ref Data data) {
  18.         DerelictGLFW3.load();
  19.         DerelictGL3.load();
  20.         glfwInit();
  21.     }
  22.  
  23.     void create() {
  24.         _wnd = glfwCreateWindow(REQ_WIDTH, REQ_HEIGHT, APP_TITLE.toStringz(), null, null);
  25.         glfwShowWindow(_wnd);
  26.         glfwMakeContextCurrent(_wnd);
  27.         DerelictGL3.reload();
  28.  
  29.         auto tid = spawn(&runNewView);
  30.         send(tid, _wnd );
  31.        
  32.         while ( !glfwWindowShouldClose(_wnd) ) {
  33.             glfwWaitEvents();      
  34.             glfwSwapBuffers(_wnd);
  35.         }
  36.     }
  37.  
  38.     GLFWwindow* _wnd;
  39. }
  40.  
  41. void runNewView() {
  42.     while ( true ) {
  43.      receive (
  44.         (string msg) { writeln(msg); },
  45.         (const(GLFWwindow*) window) { glfwMakeContextCurrent(window); }
  46.      );
  47.  
  48.      glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  49.      // draw stuff
  50.  
  51.     }
  52. }
  53.  
  54. void main(string[] args) {
  55.     Data mydata = { 0 };
  56.     auto window = Window(mydata);
  57.     // runs main loop
  58.     window.create();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement