Ejemplo n.º 1
0
//============================================================
//<T>解析字符串内容。</T>
// 
// @param pValue 字符串
// @return 是否解析成功
//============================================================
TBool S{type_name}Size3::Parse(TCharC* pValue){
   // 检查长度
   TStringRefer value(pValue);
   TInt length = value.Length();
   if(length == 0){
      MO_ERROR(TC("It is invalid length."));
      return EFalse;
   }
   // 分割内容
   TFsText temp;
   TInt begin = 0;
   TInt index = value.IndexOf(',', begin);
   if(ENotFound  == index){
      MO_ERROR(TC("Splite value failure."));
      return EFalse;
   }
   // 解析内容X
   temp.Assign(value.SubStrC(begin, index));
   width = R{type_name}::Parse(temp.MemoryC());
   // 分割内容
   begin = index + 1;
   index = value.IndexOf(',', begin);
   if(ENotFound == index){
      MO_ERROR(TC("Splite value failure."));
      return EFalse;
   }
   // 解析内容Y
   temp.Assign(value.SubStrC(begin, index));
   height = R{type_name}::Parse(temp.MemoryC());
   // 解析内容Z
   temp.Assign(value.SubStrC(index + 1, length));
   deep = R{type_name}::Parse(temp.MemoryC());
   return ETrue;
}
Ejemplo n.º 2
0
/*
Scan off a network label or process name (this is used for ports as well, as we don't know if a string is a port until later...)

Allowable characters are alphameric, hyphen, underscore; if character is preceded by backslash, will be accepted

This routine exits when an nonallowed character (or EOL) is encountered
*/
inline int scan_sym(FILE *fp, char * out_str)
{
	//extern char curr_char;
	char * o_ptr;

	o_ptr = out_str;
X4:
	TA(NA4);	
	goto X5;
NA4: 
	TN(NN4);
	goto X5;
NN4: 
	TC(NU4,'_');
	goto X5;
NU4:
	TC(ES4,'-');
	goto X5;
ES4:
	TCO(ES5, '\\');  // as per discussion on https://groups.google.com/forum/#!searchin/flow-based-programming/commas -
	                //             find "Special characters in process names" 
	CC;    	
X5:
	goto X4;
ES5:
	*o_ptr = '\0';           
	return(0);
}
Ejemplo n.º 3
0
void
timer_call_shutdown(
	processor_t			processor)
{
	timer_call_t		call;
	queue_t				queue, myqueue;

	assert(processor != current_processor());

	queue = &PROCESSOR_DATA(processor, timer_call_queue);
	myqueue = &PROCESSOR_DATA(current_processor(), timer_call_queue);

	simple_lock(&timer_call_lock);

	call = TC(queue_first(queue));

	while (!queue_end(queue, qe(call))) {
		_delayed_call_dequeue(call);

		_delayed_call_enqueue(myqueue, call);

		call = TC(queue_first(queue));
	}

	call = TC(queue_first(myqueue));

	if (!queue_end(myqueue, qe(call)))
		_set_delayed_call_timer(call);

	simple_unlock(&timer_call_lock);
}
Ejemplo n.º 4
0
/*
 *	_remove_from_delayed_queue:
 *
 *	Remove the first (or all) matching
 *	entries	from the delayed queue.
 *
 *	Returns	TRUE if any matching entries
 *	were found.
 *
 *	Called with thread_call_lock held.
 */
static boolean_t
_remove_from_delayed_queue(
    thread_call_func_t		func,
    thread_call_param_t		param0,
    boolean_t				remove_all)
{
	boolean_t			call_removed = FALSE;
	thread_call_t			call;
	thread_call_group_t		group = &thread_call_groups[THREAD_CALL_PRIORITY_HIGH];

	call = TC(queue_first(&group->delayed_queue));

	while (!queue_end(&group->delayed_queue, qe(call))) {
		if (call->tc_call.func == func	&&
				call->tc_call.param0 == param0) {
			thread_call_t	next = TC(queue_next(qe(call)));

			_call_dequeue(call, group);

			_internal_call_release(call);

			call_removed = TRUE;
			if (!remove_all)
				break;

			call = next;
		}
		else	
			call = TC(queue_next(qe(call)));
	}

	return (call_removed);
}
Ejemplo n.º 5
0
//============================================================
// <T>将一个数据写入管道。</T>
//
// @param pData 数据指针
// @param length 数据长度
// @return 压入是否成功
//============================================================
EStreamResult FBufferedQueueBlock::Push(TAnyC* pData, TInt length){
   // 检查参数
   MO_ASSERT(pData);
   // 检查长度
   if(0 == length){
      MO_WARN(TC("Write empty data. (data=0x%08X, length=%d)"), pData, length);
      return EStreamResult_WriteEmpty;
   }
   // 判断管道是否可以写入
   TInt free = _length - _position;
   TInt dataSize = sizeof(TInt32) + length;
   if(dataSize > free){
      MO_WARN(TC("Current queue is full. (data=0x%08X, capacity=%d, position=%d, free=%d, length=%d)"), pData, _capacity, _position, free, length);
      return EStreamResult_WriteFull;
   }
   // 写入数据
   FStreamBlockHead* pHead = (FStreamBlockHead*)(_pMemory + _position);
   pHead->length = length;
   MO_LIB_MEMORY_COPY(pHead->data, free, pData, length);
   // 设置位置
   _position += sizeof(TInt32) + length;
#ifdef _MO_DEBUG
   _count++;
   if(_count > _countMax){
      _countMax = _count;
   }
#endif // _DEBUG
   return EStreamResult_Success;
}
Ejemplo n.º 6
0
/*
 *	thread_call_func:
 *
 *	Enqueue a function callout.
 *
 *	Guarantees { function, argument }
 *	uniqueness if unique_call is TRUE.
 */
void
thread_call_func(
    thread_call_func_t		func,
    thread_call_param_t		param,
    boolean_t				unique_call)
{
	thread_call_t		call;
	thread_call_group_t	group = &thread_call_groups[THREAD_CALL_PRIORITY_HIGH];
	spl_t			s;

	s = splsched();
	thread_call_lock_spin();

	call = TC(queue_first(&group->pending_queue));

	while (unique_call && !queue_end(&group->pending_queue, qe(call))) {
		if (call->tc_call.func == func && call->tc_call.param0 == param) {
			break;
		}

		call = TC(queue_next(qe(call)));
	}

	if (!unique_call || queue_end(&group->pending_queue, qe(call))) {
		call = _internal_call_allocate();
		call->tc_call.func	= func;
		call->tc_call.param0	= param;
		call->tc_call.param1	= NULL;

		_pending_call_enqueue(call, group);
	}

	thread_call_unlock();
	splx(s);
}
Ejemplo n.º 7
0
//============================================================
TBool TFileFinder::Reset(){
	OsClose();
	_cpath = _path;
	_cfile = TC("");
	_cfull = TC("");
	return ETrue;
}
Ejemplo n.º 8
0
//============================================================
// <T>加载动态库。</T>
//
// @param hInstance 实例句柄
// @param reason 加载类型
// @param pReserved 保留字
// @return 类名
//============================================================
TInt32 main(TInt argumentsCount, TChar** pArguments){
#ifdef __TEST__2
   // 调试参数
   //TString sourceFileName = TC("D:/Resource/xiong/xiong.fbx");
   //TString targetFileName = TC("D:/Microbject/MoTypeScript/Script/res/model/xiong/xiong.model");
   //TString targetConfigName = TC("D:/Microbject/MoTypeScript/Script/res/model/xiong/xiong.xml");
   TString sourceFileName = TC("D:/MoProject/Resource/demo/model/fd-pvw-展示/fd-sc.car.01-场景.汽车.01/md-001-汽车.奥迪/model.fbx");
   TString targetFileName = TC("D:/MoProject/Asset/demo/model/pvw.sc.car.01.001.model");
#else
   // 获取参数
   if(argumentsCount != 3){
      return -1;
   }
   TString sourceFileName = pArguments[1];
   TString targetFileName = pArguments[2];
#endif // __TEST__
   // 设置语言
   setlocale(LC_ALL, "chs");
   // 初始化处理
   MoInitialize();
   MO_STATIC_DEBUG(TC("Source file: [%s]"), (TCharC*)sourceFileName);
   MO_STATIC_DEBUG(TC("Target file: [%s]"), (TCharC*)targetFileName);
   // 打开场景
   FModelScene* pScene = RModelManager::SafeInstance().OpenScene(sourceFileName);
   // 存储资源
   FFbxResModel* pModel = MO_CREATE(FFbxResModel);
   pScene->Store(pModel);
   pModel->SaveFile(targetFileName);
   // 释放处理
   MO_DELETE(pScene);
   MoRelease();
   // getchar();
   return 0;
}
Ejemplo n.º 9
0
MO_NAMESPACE_BEGIN

//============================================================
//<T>½âÎö×Ö·û´®ÄÚÈÝ¡£</T>
// 
// @param pValue ×Ö·û´®
// @return ÊÇ·ñ½âÎö³É¹¦
//============================================================
TBool SIntRange::Parse(TCharC* pValue){
   // ¼ì²é³¤¶È
   TStringRefer value(pValue);
   TInt length = value.Length();
   if(length == 0){
      MO_ERROR(TC("It is invalid length."));
      return EFalse;
   }
   // ·Ö¸îÄÚÈÝ
   TFsText temp;
   TInt begin = 0;
   TInt index = value.IndexOf(',', begin);
   if(ENotFound  == index){
      MO_ERROR(TC("Splite value failure."));
      return EFalse;
   }
   // ½âÎöÄÚÈÝX
   temp.Assign(value.SubStrC(begin, index));
   min = RInt::Parse(temp.MemoryC());
   // ½âÎöÄÚÈÝY
   temp.Assign(value.SubStrC(index + 1, length));
   max = RInt::Parse(temp.MemoryC());
   return ETrue;
}
Ejemplo n.º 10
0
//============================================================
// <T>×¢ÏúÒ»¸ö²¶×½Æ÷¡£</T>
//
// @param code ´úÂë
// @return ´¦Àí½á¹û
//============================================================
TBool FThreadCatcher::Jump(TInt code){
   // ÊÇ·ñ×¢²á¹ý¼¤»î²¶×½Æ÷
   if(NULL == _pActiveCatcher){
      MO_ERROR(TC("Active catcher is not exists."));
      MO_THROW(TC("Uncatcher exception."));
      return EFalse;
   }
   // ¼ì²éÉϲã
   _pJumpCatcher = _pActiveCatcher;
   while(NULL != _pJumpCatcher){
      if(_pJumpCatcher->IsRegistered(code)){
         break;
      }
      // µ¯³ö¶¥²ã¶ÔÏó
      FCatcher* pCatcher = _pCatchers->Pop();
      if(pCatcher == _pJumpCatcher){
         MO_FATAL(TC("Pop catcher and jump not same. (jump_captcher=%s:0x%08X, captcher=%s:0x%08X)"),
               _pJumpCatcher->Name(), _pJumpCatcher, pCatcher->Name(), pCatcher);
      }
      _pJumpCatcher = _pJumpCatcher->Parent();
   }
   // ¼ì²é²ÎÊý
   if(NULL == _pJumpCatcher){
      MO_FATAL(TC("Not any catcher catch this code. (code=%d)"), code);
   }
   _pActiveCatcher = _pJumpCatcher;
   // ¸ú×Ù²¶×½Æ÷
   Track(_pJumpCatcher, code);
   // ¿ªÊ¼Ìøת
   _lockerJump.Enter();
   _pJumpCatcher->Jump();
   return ETrue;
}
Ejemplo n.º 11
0
//============================================================
TBool FFileString16::LoadFile(TCharC* pFileName){
   // 打开文件
   TFileHandle handle;
#ifdef _MO_WINDOWS
   MO_LIB_FILE_OPEN(&handle, pFileName, TC("rb"));
#else
   handle = fopen(pFileName, TC("rb"));
#endif
   if(NULL == handle){
      MO_PERROR(fopen);
      return EFalse;
   }
   // 获得长度
   if(ESuccess != fseek(handle, 0, SEEK_END)){
      MO_PERROR(fseek);
      return EFalse;
   }
   TInt length = ftell(handle);
   EnsureSize(length);
   // 从开始位置读取
   if(ESuccess != fseek(handle, 0, SEEK_SET)){
      MO_PERROR(fseek);
      return EFalse;
   }
   TInt readed = fread(_pMemory, length, 1, handle);
   if(1 != readed){
      MO_PFATAL(fread);
   }
   _length = length;
   // 关闭文件
   if(ESuccess != fclose(handle)){
      MO_PFATAL(fclose);
   }
   return ETrue;
}
Ejemplo n.º 12
0
//============================================================
// <T>从管道内弹出一个完整的数据。</T>
// <P>先读出数据长度(4byte),再读出数据内容。</P>
//
// @param pData 数据指针
// @param capacity 数据长度
// @return 读出数据的长度,为0表示没有读出有效数据,为-1表示读出缓冲不够
//============================================================
EStreamResult FBufferedQueueBlock::Pop(TAny* pData, TInt capacity, TInt* pLength){
   // 检查参数
   MO_ASSERT(pData);
   MO_ASSERT(capacity > 0);
   // 检查容量
   TInt position = _position + sizeof(TInt32);
   if(position >= _length){
      return EStreamResult_ReadEnd;
   }
   // 检查数据长度
   FStreamBlockHead* pHead = (FStreamBlockHead*)(_pMemory + _position);
   // 检查长度
   if(pHead->length > capacity){
      MO_WARN(TC("Current data capacity is not enouth. (data=0x%08X, capacity=%d, length=%d)"), pData, capacity, pHead->length);
      return EStreamResult_ReadCapacity;
   }
   // 检查有效
   if(position + pHead->length > _length){
      MO_WARN(TC("Current data is invalid. (data=0x%08X, capacity=%d, length=%d)"), pData, capacity, pHead->length);
      return EStreamResult_ReadEnd;
   }
   // 读取数据
   MO_LIB_MEMORY_COPY(pData, capacity, pHead->data, pHead->length);
   // 设置位置
#ifdef _MO_DEBUG
   _count--;
#endif // _DEBUG
   _position += sizeof(TInt32) + pHead->length;
   *pLength = pHead->length;
   return EStreamResult_Success;
}
Ejemplo n.º 13
0
/*
 *	_remove_from_pending_queue:
 *
 *	Remove the first (or all) matching
 *	entries	from the pending queue.
 *
 *	Returns	TRUE if any matching entries
 *	were found.
 *
 *	Called with thread_call_lock held.
 */
static boolean_t
_remove_from_pending_queue(
    thread_call_func_t		func,
    thread_call_param_t		param0,
    boolean_t				remove_all)
{
	boolean_t			call_removed = FALSE;
	thread_call_t			call;
	thread_call_group_t		group = &thread_call_group0;
    
    call = TC(queue_first(&group->pending_queue));
    
    while (!queue_end(&group->pending_queue, qe(call))) {
    	if (	call->func == func			&&
				call->param0 == param0			) {
			thread_call_t	next = TC(queue_next(qe(call)));
		
			_call_dequeue(call, group);

			_internal_call_release(call);
	    
			call_removed = TRUE;
			if (!remove_all)
				break;
		
			call = next;
		}
		else	
			call = TC(queue_next(qe(call)));
    }
    
    return (call_removed);
}
Ejemplo n.º 14
0
PROCESS_THREAD(ctimer_process, ev, data)
{
  struct ctimer * SAFE c;
  PROCESS_BEGIN();

  for(c = TC (list_head(ctimer_list)); c != NULL; c = c->next) {
    etimer_set(&c->etimer, c->etimer.timer.interval);
  }
  initialized = 1;

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);
    for(c = TC (list_head(ctimer_list)); c != NULL; c = c->next) {
      if(&c->etimer == data) {
	list_remove(ctimer_list,TC(c));
	PROCESS_CONTEXT_BEGIN(c->p);
	if(c->f != NULL) {
	  c->f(c->ptr);
	}
	PROCESS_CONTEXT_END(c->p);
	break;
      }
    }
  }
  PROCESS_END();
}
Ejemplo n.º 15
0
void
thread_call_delayed_timer(
		timer_call_param_t		p0,
		__unused timer_call_param_t	p1
)
{
	thread_call_t			call;
	thread_call_group_t		group = p0;
	uint64_t				timestamp;

	thread_call_lock_spin();

	timestamp = mach_absolute_time();

	call = TC(queue_first(&group->delayed_queue));

	while (!queue_end(&group->delayed_queue, qe(call))) {
		if (call->tc_call.deadline <= timestamp) {
			_pending_call_enqueue(call, group);
		}
		else
			break;

		call = TC(queue_first(&group->delayed_queue));
	}

	if (!queue_end(&group->delayed_queue, qe(call)))
		_set_delayed_call_timer(call, group);

	thread_call_unlock();
}
Ejemplo n.º 16
0
int scan_sym(FILE *fp, char *o_ptr)
  {

       int i;

X3:    TA(NA4);
       goto X4;
NA4:   TN(NN4);
       goto X4;
NN4:   TC(ES4,'_');
 /* loop back to here */  
X4:    TA(NA5);
       goto X4;
NA5:   TN(NN5);
       goto X4;
NN5:   TC(ES5,'_');
       goto X4;
ES4:   printf("Invalid name: ");
       for (i = 0; i < 7; i++) {
          printf("%c",curr_char);
          curr_char = getc(fp);
          } 
       printf("\n");       
       return(4);

ES5:   *o_ptr = '\0';
       return(0);
  }
Ejemplo n.º 17
0
//============================================================
void TFileFinder::Restart(){
	_cpath = _path;
	_cfile = TC("");
	_cfull = TC("");
#ifdef _MO_LINUX
	_cur = -1;
#endif
}
Ejemplo n.º 18
0
//============================================================
// <T>将尾部项存入文件。</T>
//
// @param out 输出文件流。
//============================================================
void FCsvFooters::Store(TDataOutput& out){
   FDictionary<FCsvFooter*>::TIteratorC it = _pFooters->IteratorC();
   TString foot = TC("@footer.name\n");
   TBool showLabel = EFalse;
   TBool showDescription = EFalse;
   TInt count = 0;
   TInt lastFooterIndex = _pFooters->Count() - 1;
   while(it.Next()){
      FCsvFooter* pFoot = it.Value();
      foot.Append(pFoot->Name());
      if(count != lastFooterIndex){
         foot.Append(',');
      }else{
         foot.Append('\n');
      }

      TInt labelLength = RString::Length(pFoot->Label());
      if(labelLength){
         showLabel = ETrue;
      }
      TInt desLength = RString::Length(pFoot->Description());
      if(desLength){
         showDescription= ETrue;
      }
      ++count;
   }
   if(showLabel){
      foot.Append(TC("@footer.label\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvFooter* pFoot = it.Value();
         foot.Append(pFoot->Label());
         if(count != lastFooterIndex){
            foot.Append(',');
         }else{
            foot.Append('\n');
         }
      }
   }
   if(showDescription){
      foot.Append(TC("@head.description\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvFooter* pFoot = it.Value();
         foot.Append(pFoot->Description());
         if(count != lastFooterIndex){
            foot.Append(',');
         }else{
            foot.Append('\n');
         }
      }
   }
   out.Write((TCharC*)foot, foot.Length());
}
Ejemplo n.º 19
0
//============================================================
// <T>¸ú×Ù²¶×½Æ÷¡£</T>
//
// @param pCatcher ²¶×½Æ÷
//============================================================
void FThreadCatcher::Track(FCatcher* pCatcher, TInt code){
   TFsDump info;
#ifdef _MO_LINUX
   TCharC* pCodeName = strsignal(code);
#else
   TCharC* pCodeName = TC("Unknown");
#endif // _LINUX
   //............................................................
   info.Append(TC("System rais error."));
   info.Append(TC("\n-- Crash track info begin ----------------------------------"));
   if(NULL != pCatcher){
      info.AppendFormat(TC("\n Catch success. (name=%s@0x%08X, code=%d:%s, info=%s)"),
         pCatcher->Name(), pCatcher, code, pCodeName, pCatcher->Info());
   }else{
      info.AppendFormat(TC("\n Catch failure. (pointer=0x%08X, code=%d:%s)"),
         pCatcher, code, pCodeName);
   }
   //............................................................
   // Êä³ö°²×°µÄ²¶×½Æ÷
   TInt countCatcher = _pCatchers->Count();
   for(TInt n = 0; n < countCatcher; n++){
      FCatcher* pFind  = _pCatchers->Get(n);
      info.AppendFormat(TC("\n   Installed (%2d = %s@0x%08X (jump_count=%4d) - %s)"),
         n++, pFind->Name(), pFind, pFind->JumpCount(), pFind->Info());
   }
   //............................................................
   info.Append(TC("\n Crash track info [ BS you begin]"));
   RSystem::FetchStack(&info);
   info.Append(TC("\n Crash track info [ BS you end]"));
   info.Append(TC("\n-- Crash track info end ------------------------------------"));
   MO_DUMP_STACK((TCharC*)info);
   RLoggerManager::Instance().Flush();
}
Ejemplo n.º 20
0
//============================================================
// <T>将头部存入文件。</T>
//
// @param out 文件输出流。
//============================================================
void FCsvHeads::SaveToFile(TDataOutput& out){
   FDictionary<FCsvHead*>::TIteratorC it = _pHeads->IteratorC();
   TString head = TC("@head.name\n");
   TBool showLabel = EFalse;
   TBool showDescription = EFalse;
   TInt count = 0;
   TInt headCount = _pHeads->Count() - 1;
   while(it.Next()){
      FCsvHead* pHead = it.Value();
      head.Append(pHead->Name());
      if(count != headCount){
         head.Append(',');
      }else{
         head.Append('\n');
      }
      TInt labelLength = RString::Length(pHead->Label());
      if(labelLength){
         showLabel = ETrue;
      }
      TInt desLength = RString::Length(pHead->Description());
      if(desLength){
         showDescription= ETrue;
      }
      ++count;
   }
   if(showLabel){
      head.Append(TC("@head.label\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvHead* pHead = it.Value();
         head.Append(pHead->Label());
         if(count != headCount){
            head.Append(',');
         }else{
            head.Append('\n');
         }
      }
   }
   if(showDescription){
      head.Append(TC("@head.description\n"));
      count = 0;
      it.Reset();
      while(it.Next()){
         FCsvHead* pHead = it.Value();
         head.Append(pHead->Description());
         if(count != headCount){
            head.Append(',');
         }else{
            head.Append('\n');
         }
      }
   }
   out.Write((TCharC*)head, head.Length());
}
    _3cases() {
        master = BOOST_TEST_SUITE( "master" );

        tc1 = TC( test1 );
        tc2 = TC( test2 );
        tc3 = TC( test3 );

        master->add( tc1 );
        master->add( tc2 );
        master->add( tc3 );
    }
Ejemplo n.º 22
0
TEST_F(ComplexGpuMathTest, scaleTest) {


    TC x1[] = {1, 2, 3, TC(4, 6), 5, 6};
    TC result[] = {0.5, 1, 1.5, TC(2, 3), 2.5, 3};
    this->b1.copyFrom(x1);
    gpuScale(b1.count(), 0.5, b1.data());
    b1.copyTo(x1);

    ASSERT_NEAR_VEC_COMPLEX(x1, result, b1.count());
}
Ejemplo n.º 23
0
/*---------------------------------------------------------------------------*/
void
ctimer_reset(struct ctimer *c)
{
  if(initialized) {
    PROCESS_CONTEXT_BEGIN(&ctimer_process);
    etimer_reset(&c->etimer);
    PROCESS_CONTEXT_END(&ctimer_process);
  }

  list_remove(ctimer_list,TC(c));
  list_add(ctimer_list,TC(c));
}
Ejemplo n.º 24
0
/* Heartbeat interrupt handler */
interrupt VECTOR_NUM(TC_VECTOR(TC_HEARTBEAT)) void heartbeat_ISR(void) {
    static word prev_count = 0;
    word cur_count;
    
    cur_count = TC(TC_HEARTBEAT);   // Acknowledge interrupt by accessing timer channel
    
    // Check if correct number of overflows has occurred
    if(get_overflow_count() == 15) { //HEARTBEAT / 0xFFFF) {
        TC(TC_HEARTBEAT) += HEARTBEAT;  // Rearm channel register, clearing TFLG as well
        heartbeat_count++;
    }
    
    prev_count = cur_count;     // Remember count for next time
}
Ejemplo n.º 25
0
/*---------------------------------------------------------------------------*/
void
timetable_init(void)
{
  char dummy1=0, dummy2=0;
#define temp_size 4
  TIMETABLE_STATIC(temp);
  
  timetable_clear(&temp);

  /* Measure the time for taking a timestamp. */
  TIMETABLE_TIMESTAMP(temp, TC(&dummy1));
  TIMETABLE_TIMESTAMP(temp, TC(&dummy2));
  timetable_timestamp_time = timetable_timediff(&temp, TC(&dummy1), TC(&dummy2));
}
Ejemplo n.º 26
0
int CALLBACK WinMain(
  __in  HINSTANCE hInstance,
  __in  HINSTANCE hPrevInstance,
  __in  LPSTR lpCmdLine,
  __in  int nCmdShow
)
{
    gHwnd = InitWindow();
    if (gHwnd == NULL) {
        LogError(TC("Failed to create window..."));
        return 1;
    }

    HDC dc = GetDC(gHwnd);

    bool success = InitGL(dc);
    if (!success) {
        LogError(TC("Failed to initialize OpenGL..."));
        return 1;
    }

    Initialize();
	Options* opts = ParseCommandLine(0, NULL);

	gTrace = GLTrace::Load(opts->OutputTraceName);
	gTrace->CreateResources();
	gTrace->RestoreContextState();

    MSG msg = {};
    while (msg.message != WM_QUIT) {
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		} else {
			Render();
			SwapBuffers(dc);
		}
    }

	ReleaseDC(gHwnd, dc);

    DestroyWindow(gHwnd);
    UnregisterClass(L"WindowClass", NULL);

	SafeDelete(gTextureViewer);
	SafeDelete(gTrace);
	SafeDelete(opts);

    return (int)msg.wParam;
}
Ejemplo n.º 27
0
/* to count in milisecond increments */
void msleep(word ms) {
    word i;
    
    // Enable timer module if not already enabled
    if(!(TSCR1 & TSCR1_TEN_MASK)) EnableTimer;
    
    TC(TC_SLEEP) = TCNT + OC_DELTA_1MS; // Preset channel register
    TC_OC(TC_SLEEP);                    // Enable channel as output compare
    
    for(i=0; i < ms; i++) {
        while(!(TFLG1 & (1 << TC_SLEEP)));  // Wait for event
        TC(TC_SLEEP) += OC_DELTA_1MS;       // Rearm channel register, clearing TFLG as well
    }
}
Ejemplo n.º 28
0
//============================================================
// <T>获得当前内部状态信息。</T>
//
// @param pDump 输出信息指针
// @param capacity 输出信息大小
// @return 处理结果
//============================================================
TCharC* TNetRouter::DumpRouter(TChar* pDump, TSize capacity){
   // 获取网络信息
   TNetLength length = _netHead.Length();
   TUint16 protocol = _netHead.Protocol();
   TNetHash hash = _netHead.Hash();
   // 获取消息信息
   TUint8 type = _messageHead.Type();
   TUint8 command = _messageHead.Command();
   TUint16 code = _messageHead.Code();
   TCharC* pName = RNetMessageFactory::CodeName(code);
   // 获取Orgin信息
   SNetTarget& origin = _routerHead.Origin();
   TUint8 originType = origin.ServerType();
   TCharC* pOriginTypeCode = REnumNetTerminal::ToCode((ENetTerminal)originType);
   // 获取Source信息
   SNetTarget& source = _routerHead.Source();
   TUint8 sourceType = source.ServerType();
   TCharC* pSourceType = REnumNetTerminal::ToString((ENetTerminal)sourceType);
   TCharC* pSourceTypeCode = REnumNetTerminal::ToCode((ENetTerminal)sourceType);
   // 获取Target信息
   SNetTarget& target = _routerHead.Target();
   TUint8 targetType = target.ServerType();
   TCharC* pTargetType = REnumNetTerminal::ToString((ENetTerminal)targetType);
   TCharC* pTargetTypeCode = REnumNetTerminal::ToCode((ENetTerminal)targetType);
   // 获得会话编号
   TNetSessionId sessionId = _routerHead.SessionId();
   // 获取目标集合
   TFsDump targetDump;
   TNetTargets& targets = _routerHead.Targets();
   TInt count = targets.Count();
   for(TInt n = 0; n < count; n++){
      if(n > 0){
         targetDump.Append(',');
      }
      SNetTarget& netTarget = targets[n];
      targetDump.AppendFormat(TC("(%02X-%02X-%08X)"),
            netTarget.GroupId(), netTarget.ServerId(), netTarget.ObjectHandle());
   }
   // 生成数据信息
   TFsTrack dataTrack;
   TCharC* pDataTrack = RNetMessageFactory::DumpData(this, &dataTrack);
   // 生成信息
   MO_LIB_STRING_FORMAT(pDump, capacity,
         "[ %s ] - 0x%08X:%d\n"
         "--------------------------------------------------------------------------------\n"
         "-- Net     : length=0x%04X(%d), protocol=%d, hash=0x%04X\n"
         "-- Message : code=(%02X:%04X), command=%d, sender=%s(0x%02X), target=%s(0x%02X)\n"
         "-- Router  : orgin=%s(%02X-%02X-%08X), source=%s(%02X-%02X-%08X), target=%s(%02X-%02X-%08X), targets=%" MO_FMT_INT "[%s]\n"
         "--------------------------------------------------------------------------------\n"
         "%s",
         pName, sessionId, sessionId,
         length, length, protocol, hash,
         type, code, command, pSourceType, sourceType, pTargetType, targetType,
         pOriginTypeCode, origin.GroupId(), origin.ServerId(), origin.ObjectHandle(),
         pSourceTypeCode, source.GroupId(), source.ServerId(), source.ObjectHandle(),
         pTargetTypeCode, target.GroupId(), target.ServerId(), target.ObjectHandle(),
         count, (TCharC*)targetDump,
         pDataTrack);
   return pDump;
}
Ejemplo n.º 29
0
//============================================================
TBool FFileString16::SaveFile(TCharC* pFileName){
   // 打开文件
   TFileHandle handle;
#ifdef _MO_WINDOWS
   MO_LIB_FILE_OPEN(&handle, pFileName, TC("wb"));
#else
   handle = fopen(pFileName, "wb");
#endif
   if(NULL == handle){
      MO_PERROR(fopen);
      return EFalse;
   }
   // 从开始位置写入
   if(ESuccess != fseek(handle, 0, SEEK_SET)){
      MO_PERROR(fseek);
      return EFalse;
   }
   TInt writted = fwrite(_pMemory, _length, 1, handle);
   if(writted != _length){
      MO_PFATAL(fwrite);
   }
   // 关闭文件
   if(ESuccess != fclose(handle)){
      MO_PFATAL(fclose);
      return EFalse;
   }
   return ETrue;
}
Ejemplo n.º 30
0
//============================================================
// <T>从输入流里反序列化信息内容</T>
//
// @param pInput 输入流
// @return 处理结果
//============================================================
TResult FAnimationFrame::Unserialize(IDataInput* pInput){
   // 读取资源属性
   _optionEmpty = pInput->ReadBool();
   _delay = pInput->ReadInt32();
   // 读取位图
   if(!_optionEmpty){
      // 读取大小
      _size.Unserialize16(pInput);
      // 读取有效区域
      _validLocation.Unserialize16(pInput);
      _validSize.Unserialize16(pInput);
      _validBarycenter.Unserialize16(pInput);
      _mergeLocation.Unserialize16(pInput);
      // 计算纹理
      SFloatSize2& mergeSize = _pAnimation->MergeFitSize();
      _coord.x1 = (TFloat)_mergeLocation.x / mergeSize.width;
      _coord.y1 = (TFloat)_mergeLocation.y / mergeSize.height;
      _coord.x2 = (TFloat)(_mergeLocation.x + _validSize.width) / mergeSize.width;
      _coord.y2 = (TFloat)(_mergeLocation.y + _validSize.height) / mergeSize.height;
      // 读取数据
      MO_DEBUG(TC("Unserialize resource picture info. (code=%d, size=%dx%d, valid_location=%d,%d, valid_size=%dx%d)"),
            _pAnimation->Code(), _size.width, _size.height, _validLocation.x, _validLocation.y, _validSize.width, _validSize.height);
   }
   return ESuccess;
}