Advertisement
snake5

basic SGScript threading test

Nov 29th, 2015
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. function draw_ticking_text()
  2. {
  3.     str = "Gradually appearing text...";
  4.     i = 0;
  5.     thread_create( function() use( i ){ for(;;){ i++; yield( 0.2 ); } } );
  6.     for(;;)
  7.     {
  8.         tx = string_part( str, 0, i % str.length );
  9.         SS_DrawTextLine( tx, Font, 20, 20, color(1,1,1) );
  10.         yield();
  11.     }
  12. }
  13.  
  14. function initialize()
  15. {
  16.     global W = 1024, H = 576;
  17.     global Window = SS_CreateWindow( "SGS-SDL Game Framework", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 576, SDL_WINDOW_OPENGLMAYBE );
  18.     Window.initRenderer( SS_RENDERER_DONTCARE, SS_RENDERER_VSYNC );
  19.     global Font = SS_CreateFont( "fonts/lato-regular.ttf", 12 );
  20.    
  21.     thread_create( draw_ticking_text );
  22. }
  23.  
  24. global prevTime = ftime();
  25. function update()
  26. {
  27.     SS_Clear( color(0.25,0.3,0.4) );
  28.     SS_SetCameraUI( 0, W, 0, H );
  29.     curTime = ftime();
  30.     deltaTime = curTime - prevTime;
  31.     global prevTime = curTime;
  32.     if( deltaTime > 1/15 )
  33.         deltaTime = 1/15;
  34.     process_threads( deltaTime );
  35.     SS_Present();
  36. }
  37.  
  38. function on_event( e )
  39. {
  40.     if( e.type == SDL_QUIT )
  41.         global sys_exit = true;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement