示例#1
0
void MovieClip::play()
{
	passoneframe_ = true;
	playing_ = true;
    prevClock_ = iclock();
	addEventListener(EnterFrameEvent::ENTER_FRAME, &MovieClip::nextFrame);
}
示例#2
0
SplashScreen::SplashScreen(Application* application) : Sprite(application)
{
	Dib dib1 = logo2dib(application, logo1, sizeof(logo1), 320, 44);
	Dib dib2 = logo2dib(application, logo2, sizeof(logo2), 320, 96);

	TextureParameters parameters;
	data1_ = application_->getTextureManager()->createTextureFromDib(dib1, parameters);
	data2_ = application_->getTextureManager()->createTextureFromDib(dib2, parameters);
	
	graphicsBase1_ = createGraphicsBase(data1_, 0, 0);
	graphicsBase2_ = createGraphicsBase(data2_, 0, 30);

	startTime_ = iclock();

	Orientation orientation = application->orientation();
	float width = application->getHardwareWidth();
	float height = application->getHardwareHeight();
	if (orientation == eLandscapeLeft || orientation == eLandscapeRight)
		std::swap(width, height);	
	float dx = (width - 320) / 2;
	float dy = (height - 140) / 2; 

	float sx = application->getLogicalScaleX();
	float sy = application->getLogicalScaleY();
	float tx = application->getLogicalTranslateX();
	float ty = application->getLogicalTranslateY();
	setScaleXY(1/sx, 1/sy);
	setXY((-tx + dx) / sx, (-ty + dy) / sy);
}
示例#3
0
static double GetCounter() {
#if _WIN32
	LARGE_INTEGER li;
	QueryPerformanceCounter(&li);
	return double(li.QuadPart-CounterStart)/PCFreq;
#else
	return (iclock() - CounterStart) * 1000.0;
#endif
}
示例#4
0
double StopWatch::clock()
{
	double current = iclock();
	if (isRunning_ == true)
		total_ += current - last_;
	last_ = current;

	return total_;
}
示例#5
0
void SplashScreen::doDraw(const CurrentTransform&, float sx, float sy, float ex, float ey)
{
	double t = iclock() - startTime_;
	
	float a1 = alphaFunction(t);
	float a2 = alphaFunction(t - 0.25);
	
	graphicsBase1_.setColor(1, 1, 1, a1);
	graphicsBase1_.draw(shader_);

	graphicsBase2_.setColor(1, 1, 1, a2);
	graphicsBase2_.draw(shader_);
}
示例#6
0
static void StartCounter() {
#if _WIN32
	LARGE_INTEGER li;
	if(!QueryPerformanceFrequency(&li))
	printf("QueryPerformanceFrequency failed!\n");

	PCFreq = double(li.QuadPart)/1000.0;

	QueryPerformanceCounter(&li);
	CounterStart = li.QuadPart;
#else
	CounterStart = iclock();
#endif
}
示例#7
0
int main()
{
	client_sock = make_sock("127.0.0.1");
	ikcpcb *kcp = ikcp_create(0x11223344, (void*)0);
	kcp->output = udp_output;
	ikcp_wndsize(kcp, 128, 128);
	ikcp_nodelay(kcp, 0, 10, 0, 0);

	char buf[ECHO_LEN];
	char *buf_in;
	char *msg = "hello";
	int i=0;
	int current;
	int ret;
	for(;;)
	{
		++i;
		isleep(1);
		current = iclock();
		ikcp_update(kcp, current);

		if (i % 1000 == 0)
		{
			sprintf(buf, "%s:%d, %u", msg, i, current);
			ret = ikcp_send(kcp, buf, strlen(buf));
			check(ret >= 0, "send");
			printf("send [%s]\n", buf);
		}

		ret = recv(client_sock, buf, ECHO_LEN-1, 0);
		check_silently(ret > 0);

		ikcp_input(kcp, buf, ret);
		printf("\nrecv from server raw: %s\n", buf);

		ret = ikcp_recv(kcp, buf, ECHO_LEN-1);
		check_silently(ret > 0);

		buf[ret] = '\0';
		printf("\nrecv from server: %s\n", buf);

error:
		continue;
	}
}
示例#8
0
void MovieClip::nextFrame(EnterFrameEvent *)
{
    switch (type_)
    {
    case eFrame:
        oneFrame();
        break;
    case eTime:
    {
        double curr = iclock();
        int delta = (curr - prevClock_) * 1000;
        prevClock_ = curr;

        delta = std::min(std::max(delta, 0), 1000);

        for (int i = 0; i < delta; ++i)
            oneFrame();
        break;
    }
    }
}
void connection_manager::handle_kcp_time(void)
{
    //std::cout << "."; std::cout.flush();
    hook_kcp_timer();
    connections_.update_all_kcp(iclock());
}
示例#10
0
文件: dialog.cpp 项目: 2thetop/OpenCR
void Dialog::ProgramThread_run()
{
    int i;
    int j;
    int ret = 0;
    err_code_t err_code = OK;
    long t, dt;
    float calc_time;
    uint32_t fw_size = 256*1024*3;
    uint8_t  board_str[16];
    uint8_t  board_str_len;
    uint32_t board_version;
    uint32_t board_revision;
    uint32_t crc;
    uint32_t crc_ret = 0;
    uint8_t  *p_buf_crc;
    char *portname;
    char *filename;
    uint32_t baud;
    uint8_t  block_buf[FLASH_TX_BLOCK_LENGTH];
    uint32_t addr;
    uint32_t len;

    baud     = (uint32_t)port->baudRate();
    //QString --> QByteArray --> const char*

    QString strportName = port->portName();
    QByteArray ba = strportName.toLatin1();
    portname = ba.data();

    // Open port
    if (!port->isOpen())
    {
        onTextBoxLogPrint("serial port is not opened\r\n");
        return;
    }

    QString selectedFile;
    for(int nIndex=0; nIndex < fileNames.size(); nIndex++)
    {
        selectedFile.append(fileNames.at(nIndex).toLocal8Bit().constData());
    }
    QByteArray bafilename = selectedFile.toLatin1();
    filename = bafilename.data();

    QString textPrint;
    if( ( opencr_fp = fopen(filename, "rb" ) ) == NULL )
    {
        onTextBoxLogPrint(textPrint.sprintf("Failed to open file : %s\r\n",filename));
        return;
        //exit( 1 );
    }
    else
    {
        fseek( opencr_fp, 0, SEEK_END );
        opencr_fpsize = ftell( opencr_fp );
        fseek( opencr_fp, 0, SEEK_SET );
        onTextBoxLogPrint(">>\r\n");
        onTextBoxLogPrint(textPrint.sprintf("file name :\r\n %s \r\n", filename));
        onTextBoxLogPrint(textPrint.sprintf("file size : %d KB\r\n", opencr_fpsize/1024));
    }

    fw_size = opencr_fpsize;

    t = iclock();
    ret = opencr_ld_flash_erase(fw_size);
    dt = iclock() - t;

    onTextBoxLogPrint(textPrint.sprintf("flash_erase : %d : %f sec\r\n", ret, GET_CALC_TIME(dt)));
    if( ret < 0 )
    {
        //port->close();
        fclose( opencr_fp );
        onTextBoxLogPrint("erase flash failed...\r\n");
        return;//exit(1);
    }
    else
    {
        onTextBoxLogPrint("erase flash completed...\r\n");
    }

    t = iclock();
    crc  = 0;
    addr = 0;
    while(1)
    {
        // ui->progressBar_Status->setValue(100*addr/fw_size);
        len = opencr_ld_file_read_data( block_buf, FLASH_TX_BLOCK_LENGTH);
        if( len == 0 ) break;

        for( i=0; i<len; i++ )
        {
            crc = crc_calc( crc,  block_buf[i] );
        }

        ret = opencr_ld_flash_write( addr, block_buf, len );
        if( ret < 0 ) break;
        addr += len;

        ui->textEdit_Log->insertPlainText(".");
    }
    ui->textEdit_Log->insertPlainText("\r\n");
    dt = iclock() - t;

    onTextBoxLogPrint(textPrint.sprintf("flash_write : %d : %f sec \r\n", ret,  GET_CALC_TIME(dt)));
    if( ret < 0 )
    {
        port->close();
        fclose( opencr_fp );
        return;
    }

    t = iclock();
    err_code = cmd_flash_fw_verify( fw_size, crc, &crc_ret );
    dt = iclock() - t;
    if( err_code == OK )
    {
        onTextBoxLogPrint(textPrint.sprintf("CRC OK %X %X %f sec\r\n", crc, crc_ret, GET_CALC_TIME(dt)));
    }
    else
    {
        onTextBoxLogPrint(textPrint.sprintf("CRC Fail : 0x%X : %X, %X %f sec\r\n", err_code, crc, crc_ret, GET_CALC_TIME(dt)));
    }

    onTextBoxLogPrint(textPrint.sprintf("jump_to_fw \r\n"));
    cmd_jump_to_fw();

    port->close();
    fclose( opencr_fp );
}
示例#11
0
void Application::renderScene(int deltaFrameCount) {
	if (nframe_ < 0 || time_ < 0) {
		nframe_ = 0;
		time_ = iclock();
	}

	double time = iclock();
	nframe_++;
	if (nframe_ == 60) {
		double dtime = time - time_;
		time_ = time;

		glog_v("fps: %g %d", nframe_ / dtime, GReferenced::instanceCount);

		nframe_ = 0;
	}

	if (!ShaderEngine::Engine)
		return;
	ShaderEngine *gfx = ShaderEngine::Engine;
	//oglTextureReset();
	gfx->reset();

	gtexture_tick();

	if (scale_ == 0)
		scale_ = 1;

	switch (hardwareOrientation_) {
	case eFixed:
	case ePortrait:
	case ePortraitUpsideDown:
		gfx->setViewport(0, 0, width_ / scale_, height_ / scale_);
		break;
	case eLandscapeLeft:
	case eLandscapeRight:
		gfx->setViewport(0, 0, height_ / scale_, width_ / scale_);
		break;
	}

	if (projectionDirty_) {
		projectionDirty_ = false;
		Matrix4 projection, frustum;
		//glMatrixMode(GL_PROJECTION);
		//glLoadIdentity();

		//glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

		projection.scale(logicalScaleX_, logicalScaleY_, 1);
		projection.translate(logicalTranslateX_, logicalTranslateY_, 0);
		projection.scale(1.f / scale_, 1.f / scale_, 1.f);

		if (hardwareOrientation_ == eFixed) {
		} else {
			switch (orientation_) {
			case ePortrait:
				break;
			case ePortraitUpsideDown:
				projection.translate(-(width_ / scale_) / 2,
						-(height_ / scale_) / 2, 0);
				projection.rotate(180, 0, 0, 1);
				projection.translate((width_ / scale_) / 2,
						(height_ / scale_) / 2, 0);
				break;
			case eLandscapeLeft:
				projection.translate(-(width_ / scale_) / 2,
						-(width_ / scale_) / 2, 0);
				projection.rotate(90, 0, 0, 1);
				projection.translate((width_ / scale_) / 2,
						(width_ / scale_) / 2, 0);
				break;
			case eLandscapeRight:
				projection.translate(-(height_ / scale_) / 2,
						-(height_ / scale_) / 2, 0);
				projection.rotate(270, 0, 0, 1);
				projection.translate((height_ / scale_) / 2,
						(height_ / scale_) / 2, 0);
				break;
			}

			switch (hardwareOrientation_) {
			case ePortrait:
				break;
			case ePortraitUpsideDown:
				projection.translate(-(width_ / scale_) / 2,
						-(height_ / scale_) / 2, 0);
				projection.rotate(180, 0, 0, 1);
				projection.translate((width_ / scale_) / 2,
						(height_ / scale_) / 2, 0);
				break;
			case eLandscapeLeft:
				projection.translate(-(width_ / scale_) / 2,
						-(width_ / scale_) / 2, 0);
				projection.rotate(-90, 0, 0, 1);
				projection.translate((width_ / scale_) / 2,
						(width_ / scale_) / 2, 0);
				break;
			case eLandscapeRight:
				projection.translate(-(height_ / scale_) / 2,
						-(height_ / scale_) / 2, 0);
				projection.rotate(-270, 0, 0, 1);
				projection.translate((height_ / scale_) / 2,
						(height_ / scale_) / 2, 0);
				break;
			}
		}

		Matrix4 vpProjection = projection;
		switch (hardwareOrientation_) {
		case eFixed:
		case ePortrait:
		case ePortraitUpsideDown:
			if (fov_ > 0) {
				float hw = width_ * 0.5 / scale_;
				float hh = height_ * 0.5 / scale_;
				float np = hh / tan(fov_ * M_PI / 360.0);
				float fp = (farplane_ > 0) ? farplane_ : hh * 2;
				float cnp = (nearplane_ > 0) ? nearplane_ : 0.01;
				frustum = gfx->setFrustum(-hw * cnp, hw * cnp, hh * cnp,
						-hh * cnp, np * cnp, np + fp);
				projection.translate(-hw, -hh, -np - 0.001);
			} else {
				float fp = (farplane_ > 0) ? farplane_ : 1; //Conservative default
				frustum = gfx->setOrthoFrustum(0, width_ / scale_,
						height_ / scale_, 0, -fp, fp);
			}
			gfx->adjustViewportProjection(vpProjection, width_ / scale_,
					height_ / scale_);
			break;
		case eLandscapeLeft:
		case eLandscapeRight:
			if (fov_ > 0) {
				float hw = width_ * 0.5 / scale_;
				float hh = height_ * 0.5 / scale_;
				float np = hh / tan(fov_ * M_PI / 360.0);
				float fp = (farplane_ > 0) ? farplane_ : hh * 2;
				float cnp = (nearplane_ > 0) ? nearplane_ : 0.01;
				frustum = gfx->setFrustum(-hh * cnp, hh * cnp, hw * cnp,
						-hw * cnp, np * cnp, np + fp);
				projection.translate(-hh, -hw, -np - 0.001);
			} else {
				float fp = (farplane_ > 0) ? farplane_ : 1; //Conservative default
				frustum = gfx->setOrthoFrustum(0, height_ / scale_,
						width_ / scale_, 0, -fp, fp);
			}
			gfx->adjustViewportProjection(vpProjection, height_ / scale_,
					width_ / scale_);
			break;
		}
		projectionMatrix_ = frustum * projection;
		vpProjectionMatrix_ = vpProjection;
	}
	gfx->setViewportProjection(vpProjectionMatrix_);

	//glMatrixMode(GL_MODELVIEW);
	//glLoadIdentity();

	float ltx = this->getLogicalTranslateX();
	float lty = this->getLogicalTranslateY();
	float lsx = this->getLogicalScaleX();
	float lsy = this->getLogicalScaleY();
	int hw = this->getHardwareWidth();
	int hh = this->getHardwareHeight();
	
	if (hardwareOrientation_!=eFixed) {
		Orientation orientation = this->orientation();

		if (orientation == eLandscapeLeft || orientation == eLandscapeRight)
			std::swap(hw, hh);
	}
	gfx->setProjection(projectionMatrix_);

	// hardware start/end x/y
	//if(lsx == 0) lsx = 1;
	//if(lsy == 0) lsy = 1;
	float sx = (0 - ltx) / lsx;
	float sy = (0 - lty) / lsy;
	float ex = (hw - ltx) / lsx;
	float ey = (hh - lty) / lsy;

	CurrentTransform currentTransform;
	stage_->draw(currentTransform, sx, sy, ex, ey);

#if 0 && defined(QT_CORE_LIB)
	qDebug() << "bindTextureCount: " << getBindTextureCount();
	qDebug() << "clientStateCount: " << getClientStateCount();
	qDebug() << "texture2DStateCount: " << getTexture2DStateCount();

	qDebug() << getVertexArrayCount() << getTextureCoordArrayCount();
#endif

//	Referenced::emptyPool();
	lastFrameRenderTime_ = iclock() - time;
}
示例#12
0
StopWatch::StopWatch()
{
	isRunning_ = true;
	last_ = iclock();
	total_ = 0;
}
示例#13
0
static int os_timer(lua_State* L)
{
	lua_pushnumber(L, iclock());
	return 1;
}
示例#14
0
// 测试用例
void test(int mode)
{
	// 创建模拟网络:丢包率10%,Rtt 60ms~125ms
	vnet = new LatencySimulator(10, 60, 125);

	// 创建两个端点的 kcp对象,第一个参数 conv是会话编号,同一个会话需要相同
	// 最后一个是 user参数,用来传递标识
	ikcpcb *kcp1 = ikcp_create(0x11223344, (void*)0);
	ikcpcb *kcp2 = ikcp_create(0x11223344, (void*)1);

	// 设置kcp的下层输出,这里为 udp_output,模拟udp网络输出函数
	kcp1->output = udp_output;
	kcp2->output = udp_output;

	IUINT32 current = iclock();
	IUINT32 slap = current + 20;
	IUINT32 index = 0;
	IUINT32 next = 0;
	IINT64 sumrtt = 0;
	int count = 0;
	int maxrtt = 0;

	// 配置窗口大小:平均延迟200ms,每20ms发送一个包,
	// 而考虑到丢包重发,设置最大收发窗口为128
	ikcp_wndsize(kcp1, 128, 128);
	ikcp_wndsize(kcp2, 128, 128);

	// 判断测试用例的模式
	if (mode == 0) {
		// 默认模式
		ikcp_nodelay(kcp1, 0, 10, 0, 0);
		ikcp_nodelay(kcp2, 0, 10, 0, 0);
	}
	else if (mode == 1) {
		// 普通模式,关闭流控等
		ikcp_nodelay(kcp1, 0, 10, 0, 1);
		ikcp_nodelay(kcp2, 0, 10, 0, 1);
	}	else {
		// 启动快速模式
		// 第二个参数 nodelay-启用以后若干常规加速将启动
		// 第三个参数 interval为内部处理时钟,默认设置为 10ms
		// 第四个参数 resend为快速重传指标,设置为2
		// 第五个参数 为是否禁用常规流控,这里禁止
		ikcp_nodelay(kcp1, 1, 10, 2, 1);
		ikcp_nodelay(kcp2, 1, 10, 2, 1);
		kcp1->rx_minrto = 10;
		kcp1->fastresend = 1;
	}


	char buffer[2000];
	int hr;

	IUINT32 ts1 = iclock();

	while (1) {
		isleep(1);
		current = iclock();
		ikcp_update(kcp1, iclock());
		ikcp_update(kcp2, iclock());

		// 每隔 20ms,kcp1发送数据
		for (; current >= slap; slap += 20) {
			((IUINT32*)buffer)[0] = index++;
			((IUINT32*)buffer)[1] = current;

			// 发送上层协议包
			ikcp_send(kcp1, buffer, 8);
		}

		// 处理虚拟网络:检测是否有udp包从p1->p2
		while (1) {
			hr = vnet->recv(1, buffer, 2000);
			if (hr < 0) break;
			// 如果 p2收到udp,则作为下层协议输入到kcp2
			ikcp_input(kcp2, buffer, hr);
		}

		// 处理虚拟网络:检测是否有udp包从p2->p1
		while (1) {
			hr = vnet->recv(0, buffer, 2000);
			if (hr < 0) break;
			// 如果 p1收到udp,则作为下层协议输入到kcp1
			ikcp_input(kcp1, buffer, hr);
		}

		// kcp2接收到任何包都返回回去
		while (1) {
			hr = ikcp_recv(kcp2, buffer, 10);
			// 没有收到包就退出
			if (hr < 0) break;
			// 如果收到包就回射
			ikcp_send(kcp2, buffer, hr);
		}

		// kcp1收到kcp2的回射数据
		while (1) {
			hr = ikcp_recv(kcp1, buffer, 10);
			// 没有收到包就退出
			if (hr < 0) break;
			IUINT32 sn = *(IUINT32*)(buffer + 0);
			IUINT32 ts = *(IUINT32*)(buffer + 4);
			IUINT32 rtt = current - ts;
			
			if (sn != next) {
				// 如果收到的包不连续
				printf("ERROR sn %d<->%d\n", (int)count, (int)next);
				return;
			}

			next++;
			sumrtt += rtt;
			count++;
			if (rtt > (IUINT32)maxrtt) maxrtt = rtt;

			printf("[RECV] mode=%d sn=%d rtt=%d\n", mode, (int)sn, (int)rtt);
		}
		if (next > 1000) break;
	}

	ts1 = iclock() - ts1;

	ikcp_release(kcp1);
	ikcp_release(kcp2);

	const char *names[3] = { "default", "normal", "fast" };
	printf("%s mode result (%dms):\n", names[mode], (int)ts1);
	printf("avgrtt=%d maxrtt=%d tx=%d\n", (int)(sumrtt / count), (int)maxrtt, (int)vnet->tx1);
	printf("press enter to next ...\n");
	char ch; scanf("%c", &ch);
}
示例#15
0
bool SplashScreen::isFinished() const
{
	double t = iclock() - startTime_;

	return t > 4.25;
}