Advertisement
snake5

basic SGScript threading test v2

Nov 29th, 2015
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. function draw_ticking_text()
  2. {
  3.     str = "Gradually appearing text...";
  4.     i = 0;
  5.     subthread_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 draw_moveline( from, to )
  15. {
  16.     from = clone( from );
  17.     to = clone( to );
  18.    
  19.     yield();
  20.     fade = 1.0;
  21.     subthread_create( function() use( fade ){ for(;;){ fade -= 1/60; yield( 1/60 ); } } );
  22.     while( fade > 0 )
  23.     {
  24.         SS_DrawColorLine( from.x, from.y, to.x, to.y, 1, 0, 0, fade );
  25.         yield();
  26.     }
  27. }
  28.  
  29. function initialize()
  30. {
  31.     global mpos = vec2( 0, 0 );
  32.     global opos = vec2( 0, 0 );
  33.     global W = 1024, H = 576;
  34.     global Window = SS_CreateWindow( "SGS-SDL Game Framework", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 576, SDL_WINDOW_OPENGLMAYBE );
  35.     Window.initRenderer( SS_RENDERER_DONTCARE, 0&SS_RENDERER_VSYNC );
  36.     global Font = SS_CreateFont( "fonts/lato-regular.ttf", 12 );
  37.     SS_InitDrawFunctions();
  38.    
  39.     thread_create( draw_ticking_text );
  40. }
  41.  
  42. global prevTime = ftime();
  43. function update()
  44. {
  45.     SS_Clear( color(0.25,0.3,0.4) );
  46.     SS_SetCameraUI( 0, W, 0, H );
  47.     curTime = ftime();
  48.     deltaTime = curTime - prevTime;
  49.     global prevTime = curTime;
  50.     if( deltaTime > 1/15 )
  51.         deltaTime = 1/15;
  52.     process_threads( deltaTime );
  53.     SS_Present();
  54. }
  55.  
  56. function on_event( e )
  57. {
  58.     if( e.type == SDL_QUIT )
  59.         global sys_exit = true;
  60.     if( e.type == SDL_MOUSEMOTION )
  61.     {
  62.         npos = vec2( e.x, e.y );
  63.         if( ( opos - npos ).length > 2 )
  64.         {
  65.             thread_create( draw_moveline, null, opos, npos );
  66.             global opos = npos;
  67.         }
  68.         global mpos = npos;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement