카테고리 없음

[FdF] MiniLibX mlx_loop_hook

드디어 마즈막이다!!!

우어어!!!!

(실은 숨어있는 함수들이 몇개 있긴하다 그건 따로  )

int mlx_loop_hook(mlx_ptr_t *mlx_ptr, void (*fct)(void *), void *param)
{
  CFRunLoopTimerContext	tcontext = {0, mlx_ptr, NULL, NULL, NULL};
  CFRunLoopTimerRef	timer;
  /*
  그냥 구조체
  https://developer.apple.com/documentation/corefoundation/cfrunlooptimercontext
  https://developer.apple.com/documentation/corefoundation/cfrunlooptimerref
  */

  if (mlx_ptr->loop_hook != NULL)
    {
      CFRunLoopTimerInvalidate(mlx_ptr->loop_timer);
      /*
      	메모리 해제때문에??
        https://developer.apple.com/documentation/corefoundation/1542231-cfrunlooptimerinvalidate?language=objc
      */
      [(id)(mlx_ptr->loop_timer) release];
    }

  mlx_ptr->loop_hook = fct;
  mlx_ptr->loop_hook_data = param;

  if (fct)
    {
      timer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.0, 0.0001, 0, 0, &do_loop_hook2, &tcontext);
      mlx_ptr->loop_timer = timer;
      CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes);
    }
    /* 
    	뭔가 시간을 저장하는거 같은데 왜일까?
        https://developer.apple.com/documentation/corefoundation/1543570-cfrunlooptimercreate?language=objc
        
        그리고 시간을 그만큼 더 추가해준다 리스트로?? 아마도??
        https://developer.apple.com/documentation/corefoundation/1542132-cfrunloopaddtimer
    */

  return (0);
}


void	do_loop_hook2(CFRuㅇnLoopTimerRef observer, void * info)
{
  ((mlx_ptr_t *)info)->loop_hook(((mlx_ptr_t *)info)->loop_hook_data);
}

/* 
	이전에 데이터를 넣어준걸
  	mlx_ptr->loop_hook = fct;
  	mlx_ptr->loop_hook_data = param;
    
	여기보면 루프 훅에 함수를 루프 훅 데이터로 실행하는걸 볼수 있다
    즉 실행 함수는 fct(param); 식이다
   */

음 이벤트가 실행되면 화면은 바껴야 하니 그 화면 바꾸는 함수라고 생각하면 되려나?