示例#1
0
void Critter::Eat(int food)
{
	std::cout << "Burp!!" << std::endl;
	m_Hunger -= food;
	if(m_Hunger < 0)
	{
		m_Hunger = 0;
	}
	PassTime();
}
void *CollectThread(void *args) {
	struct Handler *handler = (struct Handler *)args;
	int i = 0;
	for (i = 0; i < THREAD_NUM; i ++) {
		pthread_join(t[i], NULL);
	}
	EndTime();
	PassTime();

	LoopStop(handler->loop);
}
示例#3
0
void Critter::Play(int fun)
{
    cout << "Wheee!\n";

    m_Boredom -= fun;
    if (m_Boredom < 0)
	{
        m_Boredom = 0;
	}

    PassTime();
}
示例#4
0
void Critter::Eat(int food) 
{
    cout << "Num num num.\n";

    m_Hunger -= food;
    if (m_Hunger < 0)
	{
        m_Hunger = 0;
	}

    PassTime();
}
示例#5
0
void Critter::PerformTrick()
{
	if(GetMood() != "happy")
	{
		std::cout << "I dont feel like doing a trick" << std::endl;
		return;
	}
	RandGen rg;
	unsigned choice = rg(NUM_TRICKS);
	std::cout << "\n\nI " << TRICKS[choice] << " .\n";
	PassTime();
}
void TestSingleHandler(CuTest *tc) {
	struct Handler *handler = NewHandler();
	CuAssertPtrNotNull(tc, handler);
        handler->HandleMessage = SingleHandleMessageImpl;
	struct TestObj obj;
	obj.context = tc;
	obj.handler = handler;

	pthread_t t;
	pthread_create(&t, NULL, SingleHandlerSub, &obj);
	
	LoopStart(handler->loop);
	EndTime();
	PassTime();
}
void TestOldThreadMessage(CuTest *tc) {
	int id = msgget(IPC_PRIVATE, 0660|IPC_CREAT);
	static int ret1 = 0;
	
	pthread_t t1;
	pthread_create(&t1, NULL, OldThreadMessageSub, &id);
	struct msgbuf buf;
	while (1) {
		msgrcv(id, &buf, sizeof(int), 0x100, 0);
		//CuAssertIntEquals(tc, ret1++, buf.mtext);
		//printf("%d\n", buf.mtext);
		if (buf.mtext == 0xFFFFE) {
			break;
		}
	}
	EndTime();
	PassTime();
}
示例#8
0
void Critter::Talk()
{
    cout << "I'm a critter and I feel ";

    int mood = GetMood();
    if (mood > 15)
	{
        cout << "mad.\n";
	}
    else if (mood > 10)
	{
        cout << "frustrated.\n";
	}
    else if (mood > 5)
	{
        cout << "okay.\n";
	}
    else
	{
        cout << "happy.\n";
	}

    PassTime();
}
示例#9
0
// Make sure it runs the same everywhere
void Delay()
{
	SDL_Delay(PassTime());
}
示例#10
0
void Delay()
{
	SDL::Delay(PassTime());
}
示例#11
0
void Critter::Talk()
{
	std::cout << "I'm a Critter and I feel " << GetMood() << ".\n";
	PassTime();
}