Exemple #1
0
// ============================================================================
CVMSDocTemplate::CVMSDocTemplate(
    UINT nIDResource,
    CRuntimeClass* pDocClass,
    CRuntimeClass* pFrameClass,
    CRuntimeClass* pViewClass,
    CVisualMSThread *pThread)
    : CSingleDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass)
{
    m_pThread = pThread;

    m_pOnlyDoc = CreateNewDocument();
    ASSERT(m_pOnlyDoc != NULL);
    m_pThread->m_pMainDoc = (CVisualMSDoc*)m_pOnlyDoc;

    CFrameWnd *pFrame = CreateNewFrame(m_pOnlyDoc, NULL);
    ASSERT(pFrame != NULL);
    m_pThread->m_pMainWnd = pFrame;

    InitialUpdateFrame(pFrame, m_pOnlyDoc, FALSE);
    m_pOnlyDoc->OnNewDocument();
}
Exemple #2
0
CDocument* CMyMultiDocTemplate::OpenDocumentFile(SDialingDir *psDialingDir)
{
    CDComDoc* pDocument = (CDComDoc*)CreateNewDocument();
    if (pDocument == NULL)
    {
        TRACE(traceAppMsg, 0, "CDocTemplate::CreateNewDocument returned NULL.\n");
        AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
        return NULL;
    }
    ASSERT_VALID(pDocument);

    BOOL bAutoDelete = pDocument->m_bAutoDelete;
    pDocument->m_bAutoDelete = FALSE;   // don't destroy if something goes wrong
    CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL);
    pDocument->m_bAutoDelete = bAutoDelete;
    if (pFrame == NULL)
    {
        AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
        delete pDocument;       // explicit delete on error
        return NULL;
    }
    ASSERT_VALID(pFrame);

    // open an existing document
    CWaitCursor wait;
    if (!pDocument->OnOpenDocument(psDialingDir))
    {
        // user has be alerted to what failed in OnOpenDocument
        TRACE(traceAppMsg, 0, "CDocument::OnOpenDocument returned FALSE.\n");
        pFrame->DestroyWindow();
        return NULL;
    }

    InitialUpdateFrame(pFrame, pDocument, TRUE);
    return pDocument;
}
bool CGameServer::Update()
{
	if(lastSyncRequest<gu->gameTime-2){
		lastSyncRequest=gu->gameTime;

		if (game && game->playing) {
			//check if last times sync responses is correct
			if (outstandingSyncFrame > 0) {
				// I've disabled majority voting for now.
				// Should be tested in a few big multiplayer games first.
#if 0
				std::map<CChecksum, int> freq; // maps checksums to their frequency
				for(int a = 0; a < gs->activePlayers; ++a)
					if(gs->players[a]->active) {
						//if the checksum really happens to be 0 we will get lots of falls positives here
						if(!syncResponses[a]) {
							if (!serverNet->playbackDemo)
								logOutput.Print("No response from %s", gs->players[a]->playerName.c_str());
						} else
							++freq[syncResponses[a]];
					}
				if (freq.size() != 1) {
					CChecksum correctSync;
					int highestFreq = 0;
					for (std::map<CChecksum, int>::const_iterator it = freq.begin(); it != freq.end(); ++it)
						if (it->second > highestFreq) {
							correctSync = it->first;
							highestFreq = it->second;
						}
					if (correctSync)
						for (int a = 0; a < gs->activePlayers; ++a)
							if (gs->players[a]->active && syncResponses[a] && correctSync != syncResponses[a]) {
								char buf[10];
								SendSystemMsg("Sync error for %s %i %s",
									gs->players[a]->playerName.c_str(), outstandingSyncFrame, correctSync.diff(buf, syncResponses[a]));
							}
				}
#else
				CChecksum correctSync;
				bool err = false;
				for(int a = 0; a < gs->activePlayers; ++a)
					if(gs->players[a]->active) {
						//if the checksum really happens to be 0 we will get lots of falls positives here
						if(!syncResponses[a] && !serverNet->playbackDemo) {
							logOutput.Print("No response from %s", gs->players[a]->playerName.c_str());
							continue;
						}
						if (correctSync && correctSync != syncResponses[a]) {
							char buf[10];
							SendSystemMsg("Sync error for %s %i %s",
										  gs->players[a]->playerName.c_str(), outstandingSyncFrame, correctSync.diff(buf, syncResponses[a]));
							err = true;
							continue;
						}
						//this assumes the lowest num player is the correct one, should maybe some sort of majority voting instead
						correctSync = syncResponses[a];
					}
#endif
#ifdef SYNCDEBUG
				if (err || fakeDesync) {
					CSyncDebugger::GetInstance()->ServerTriggerSyncErrorHandling(serverframenum);
					fakeDesync = false;
				}
#else // SYNCDEBUG
				if (err && gu->autoQuit)
					serverNet->SendData(NETMSG_QUIT);
#endif // !SYNCDEBUG
			}
			for(int a=0;a<gs->activePlayers;++a)
				syncResponses[a]=0;
			
			if(!serverNet->playbackDemo){
				//send sync request
				serverNet->SendData<int>(NETMSG_SYNCREQUEST, serverframenum);
				outstandingSyncFrame=serverframenum;
			}

			int firstReal=0;
			if(gameSetup)
				firstReal=gameSetup->numDemoPlayers;
			//send info about the players
			for(int a=firstReal;a<gs->activePlayers;++a){
				if(gs->players[a]->active){
					serverNet->SendData<unsigned char, float, int>(
							NETMSG_PLAYERINFO, a, gs->players[a]->cpuUsage, gs->players[a]->ping);
				}
			}

			//decide new internal speed
			float maxCpu=0;
			for(int a=0;a<gs->activePlayers;++a){
				if(gs->players[a]->cpuUsage>maxCpu && gs->players[a]->active){
					maxCpu=gs->players[a]->cpuUsage;
				}
			}

			if (maxCpu != 0) {
				float wantedCpu=0.35f+(1-gs->speedFactor/gs->userSpeedFactor)*0.5f;
				//float speedMod=1+wantedCpu-maxCpu;
				float newSpeed=gs->speedFactor*wantedCpu/maxCpu;
				//logOutput.Print("Speed %f %f %f %f",maxCpu,wantedCpu,speedMod,newSpeed);
				newSpeed=(newSpeed+gs->speedFactor)*0.5f;
				if(newSpeed>gs->userSpeedFactor)
					newSpeed=gs->userSpeedFactor;
				if(newSpeed<0.1f)
					newSpeed=0.1f;
				if(newSpeed!=gs->speedFactor)
					serverNet->SendData<float>(NETMSG_INTERNAL_SPEED, newSpeed);
			}
		}
	}

	if(!ServerReadNet()){
		logOutput.Print("Server read net wanted quit");
		return false;
	}
	if (game && game->playing && !serverNet->playbackDemo){
		Uint64 currentFrame;
		currentFrame = SDL_GetTicks();
		float timeElapsed=((float)(currentFrame - lastframe))/1000.f;
		if(gameEndDetected)
			gameEndTime+=timeElapsed;
//		logOutput.Print("float value is %f",timeElapsed);

		if(gameClientUpdated){
			gameClientUpdated=false;
			maxTimeLeft=2;
		}
		if(timeElapsed>maxTimeLeft)
			timeElapsed=maxTimeLeft;
		maxTimeLeft-=timeElapsed;

		timeLeft+=GAME_SPEED*gs->speedFactor*timeElapsed;
		lastframe=currentFrame;

		while((timeLeft>0) && (!gs->paused || game->bOneStep)){
			if(!game->creatingVideo){
				game->bOneStep=false;
				CreateNewFrame(true);
			}
			timeLeft--;
		}
	}
	serverNet->Update();

	CheckForGameEnd();
	return true;
}
bool CGameServer::Update(void)
{
	if (terminate) {
		delete this;
		return true;
	}

	if (game->playing) {

		HandleChecksumResponses();

		if(HandleSyncResponses()) {

			// Do some more stuff at the same interval syncrequests are pushed out.

			int firstReal=0;
			if(gameSetup)
				firstReal=gameSetup->numDemoPlayers;
			//send info about the players
			for(int a=firstReal;a<gs->activePlayers;++a){
				if(gs->players[a]->active){
					serverNet->SendData<unsigned char, float, int>(
							NETMSG_PLAYERINFO, a, gs->players[a]->cpuUsage, gs->players[a]->ping);
				}
			}

			//decide new internal speed
			float maxCpu=0;
			for(int a=0;a<gs->activePlayers;++a){
				if(gs->players[a]->cpuUsage>maxCpu && gs->players[a]->active){
					maxCpu=gs->players[a]->cpuUsage;
				}
			}

			float wantedCpu=0.35+(1-gs->speedFactor/gs->userSpeedFactor)*0.5;
			//float speedMod=1+wantedCpu-maxCpu;
			float newSpeed=gs->speedFactor*wantedCpu/maxCpu;
			//info->AddLine("Speed %f %f %f %f",maxCpu,wantedCpu,speedMod,newSpeed);
			newSpeed=(newSpeed+gs->speedFactor)*0.5;
			if(newSpeed>gs->userSpeedFactor)
				newSpeed=gs->userSpeedFactor;
			if(newSpeed<0.1)
				newSpeed=0.1;
			if(newSpeed!=gs->speedFactor)
				serverNet->SendData<float>(NETMSG_INTERNAL_SPEED, newSpeed);
		}
	}

	if(!ServerReadNet()){
		info->AddLine("Server read net wanted quit");
		return false;
	}
	if (game->playing && !serverNet->playbackDemo){
		Uint64 currentFrame;
		currentFrame = SDL_GetTicks();
		double timeElapsed=((double)(currentFrame - lastframe))/1000.;
		if(gameEndDetected)
			gameEndTime+=timeElapsed;
//		info->AddLine("float value is %f",timeElapsed);

		if(gameClientUpdated){
			gameClientUpdated=false;
			maxTimeLeft=2;
		}
		if(timeElapsed>maxTimeLeft)
			timeElapsed=maxTimeLeft;
		maxTimeLeft-=timeElapsed;

		timeLeft+=GAME_SPEED*gs->speedFactor*timeElapsed;
		lastframe=currentFrame;
		
		while((timeLeft>0) && (!gs->paused || game->bOneStep)){
			if(!game->creatingVideo){
				game->bOneStep=false;
				CreateNewFrame(true);
			}
			timeLeft--;
		}
	}
	serverNet->Update();

	CheckForGameEnd();
	return true;
}
Exemple #5
0
void TimelineProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HPEN hRedPen = CreatePen(PS_SOLID, 1, RGB(255,0,0));
	static HPEN hBluePen = CreatePen(PS_SOLID, 1, RGB(0,0,255));
	static HPEN hGreenPen = CreatePen(PS_SOLID, 1, RGB(0,255,0));
	static HPEN hDashRedPen = CreatePen(PS_DOT, 1, RGB(255,0,0));
	static HPEN hDashBluePen = CreatePen(PS_DOT, 1, RGB(0,0,255));
	static HPEN hDashGreenPen = CreatePen(PS_DOT, 1, RGB(0,255,0));

	//SetFocus(hWnd);
	if(msg==WM_KEYDOWN || msg==WM_KEYUP)
		CallWindowProc((WNDPROC)GetWindowLong(hGLWnd, GWL_WNDPROC), hGLWnd, msg, wParam, lParam);

	static int mouse_lbtn=0, mouse_rbtn=0;
	if(msg==WM_LBUTTONDOWN) mouse_lbtn=1;
	if(msg==WM_LBUTTONUP)   mouse_lbtn=0;
	if(msg==WM_RBUTTONDOWN) mouse_rbtn=1;
	if(msg==WM_RBUTTONUP){
		
		RECT rt;
		GetClientRect(vTimeline.GetHWnd(),&rt);
		mouse_rbtn=0;
		long mx = LOWORD(lParam);
		float msx = (mx-40)/(float)(rt.right-50);
		if(msx>1.0f) msx = 1.0f;
		if(msx<0.0f) msx = 0.0f;

		//一番近くのキーフレームを選択する
		vTimeline.select_keyframe_rate = GetNearestTimelineSelection(msx);
	}
	if(msg==WM_MBUTTONDOWN){
		float current_rate = vTimeline.GetSelectRate();//白い線のRate
		long sc = GetSelectedScene();
		long sco = GetSelectedSceneObject();
		float keyframe_rate = vTimeline.select_keyframe_rate;//赤い線のRate
		vector<KCloneData> cln;
		if(sc!=-1 && sco!=-1){
			if(&demo.scene[sc].sceneobj[sco]!=NULL){
				KModelEdit* mdl = demo.scene[sc].sceneobj[sco].model;
				if(mdl){
					int nObj = mdl->GetCloneAllocNum();
					
					int i;
					for(i=0; i<nObj; i++){
						KCloneData bt = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(i, current_rate, demo.scene[sc].sceneobj[sco].interpolate);
						cln.push_back(bt);
					}

					for(i=0; i<nObj; i++){
						long keyframe_skt = GetFindAnimNumber(keyframe_rate, &(demo.scene[sc].sceneobj[sco].anim));
						KCloneData* bt = &(demo.scene[sc].sceneobj[sco].anim.anim[i][keyframe_skt]);
						*bt = cln[i];
					}
				}
			}
		}
	}

	if(nCurrentMode==LAYOUTER){
		if((mouse_lbtn==1)&&(mouse_rbtn==1)){
			mouse_rbtn=0;
			//新規フレーム
			CreateNewFrame(vTimeline.GetSelectRate());
		}
		if(msg==WM_RBUTTONDBLCLK){//削除
			long sc = GetSelectedScene();
			long sco = GetSelectedSceneObject();
			float rt = vTimeline.select_keyframe_rate;
			if((sc!=-1)&&(sco!=-1)){
				if(&demo.scene[sc].sceneobj[sco]!=NULL){
					demo.scene[sc].sceneobj[sco].DeleteKeyFrame(rt);
				}
			}
		}
	}

	BOOL isShiftPressing = ((GetAsyncKeyState(VK_SHIFT)&0x8000) == 0x8000);
	BOOL isCtrlPressing = ((GetAsyncKeyState(VK_CONTROL)&0x8000) == 0x8000);
	if(msg==WM_MOUSEWHEEL){
		if(nCurrentMode==TIMELINER && isPlaying) return;

		long sc = GetSelectedScene();
		long sco = GetSelectedSceneObject();
		float rt = vTimeline.select_keyframe_rate;
		if(sc!=-1 && sco!=-1){
			if(&demo.scene[sc].sceneobj[sco]!=NULL){
				if((rt==0.0f)||(rt==1.0f)) return;

				float fNewTimeRate;
				if((int)wParam>0){//UP     ...unsignedだから,intにキャストしないとマイナスが算出できない
					fNewTimeRate = (isShiftPressing) ? rt+0.001f : rt+0.01f;
					fNewTimeRate = (isCtrlPressing) ? rt+0.1f : fNewTimeRate;
					if(fNewTimeRate>=1.0f) fNewTimeRate = 0.999f;
				}else{//DOWN
					fNewTimeRate = (isShiftPressing) ? rt-0.001f : rt-0.01f;
					fNewTimeRate = (isCtrlPressing) ? rt-0.1f : fNewTimeRate;
					if(fNewTimeRate<=0.0f) fNewTimeRate = 0.001f;
				}

				vector<float>::iterator tit,teit=demo.scene[sc].sceneobj[sco].anim.anim_time.end();
				for(tit=demo.scene[sc].sceneobj[sco].anim.anim_time.begin(); tit!=teit; tit++){
					if(*tit == rt){
						*tit = fNewTimeRate;
						break;
					}
				}
				vTimeline.select_keyframe_rate = fNewTimeRate;

				sort(demo.scene[sc].sceneobj[sco].anim.anim_time.begin(), demo.scene[sc].sceneobj[sco].anim.anim_time.end());
				//tit,teit=demo.scene[sc].sceneobj[sco].anim.anim_time.end();//STLすげぇぇぇぇぇぇぇぇぇ!!!!!!
				//for(tit=demo.scene[sc].sceneobj[sco].anim.anim_time.begin(); tit!=teit; tit++){
				//	char sz[64];
				//	sprintf(sz, "%f\n", *tit);
				//	OutputDebugString(sz);
				//}
			}
		}
	}

	Render();//InvalidateRect(wingl.CGethWnd(), NULL, FALSE);
	
	RECT rt;
	GetClientRect(vTimeline.GetHWnd(),&rt);
	HDC hdc = vTimeline.GetBackDC();

	//draw frame marking
	if(demo.scene.size()>0){
		long sc = GetSelectedScene();
		long sco = GetSelectedSceneObject();
		if(sc!=-1 && sco!=-1){
			
			vector<float>::iterator tit,teit=demo.scene[sc].sceneobj[sco].anim.anim_time.end();
			
			//Marker
			SelectBrush(hdc,GetStockBrush(WHITE_BRUSH));
			for(tit=demo.scene[sc].sceneobj[sco].anim.anim_time.begin(); tit!=teit; tit++){
				long w = (long)((*tit)*(rt.right-50) + 40);
				long h = (long)((rt.bottom*0.5f));
				Rectangle(hdc,w-3,h-3,w+3,h+3);
			}

			long son = CloneGetSelectedItem();
			if(son!=-1){
				//Speed Line
				HPEN oldPen;
				if(GetModifyMode() == MODIFY_TRANSLATION)
					oldPen = SelectPen(hdc,hDashRedPen);
				else
					oldPen = SelectPen(hdc,hRedPen);

				MoveToEx(hdc, 40, (rt.bottom*0.5f), NULL);
				const float difRate = 0.01f;
				for(float atim = difRate; atim <= 1.0f; atim += difRate){
					KCloneData kcd1 = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(son, atim - difRate, demo.scene[sc].sceneobj[sco].interpolate);
					KCloneData kcd2 = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(son, atim, demo.scene[sc].sceneobj[sco].interpolate);
					if(GetModifyMode() == MODIFY_TRANSLATION)
						LineTo(hdc, atim*(rt.right-50) + 40, (kcd1.pos.x - kcd2.pos.x) * 100.0f + (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_ROTATION)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.rot.x / 360.0f + 1.0f ) * (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_SCALING)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.scale.x*0.1f + 1.0f ) * (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_ALPHA)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.alpha + 1.0f ) * (rt.bottom*0.5f));
				}
				if(GetModifyMode() == MODIFY_TRANSLATION)
					SelectPen(hdc,hDashGreenPen);
				else
					SelectPen(hdc,hGreenPen);
				MoveToEx(hdc, 40, (rt.bottom*0.5f), NULL);
				for(float atim = difRate; atim < 1.0f; atim += difRate){
					KCloneData kcd1 = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(son, atim - difRate, demo.scene[sc].sceneobj[sco].interpolate);
					KCloneData kcd2 = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(son, atim, demo.scene[sc].sceneobj[sco].interpolate); 
					if(GetModifyMode() == MODIFY_TRANSLATION)
						LineTo(hdc, atim*(rt.right-50) + 40, (kcd1.pos.y - kcd2.pos.y) * 100.0f + (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_ROTATION)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.rot.y / 360.0f + 1.0f ) * (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_SCALING)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.scale.y*0.1f + 1.0f ) * (rt.bottom*0.5f));
				}
				if(GetModifyMode() == MODIFY_TRANSLATION)
					SelectPen(hdc,hDashBluePen);
				else
					SelectPen(hdc,hBluePen);
				MoveToEx(hdc, 40, (rt.bottom*0.5f), NULL);
				for(float atim = difRate; atim < 1.0f; atim += difRate){
					KCloneData kcd1 = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(son, atim - difRate, demo.scene[sc].sceneobj[sco].interpolate);
					KCloneData kcd2 = demo.scene[sc].sceneobj[sco].anim.GetBoneTrans(son, atim, demo.scene[sc].sceneobj[sco].interpolate); 
					if(GetModifyMode() == MODIFY_TRANSLATION)
						LineTo(hdc, atim*(rt.right-50) + 40, (kcd1.pos.z - kcd2.pos.z) * 100.0f + (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_ROTATION)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.rot.z / 360.0f + 1.0f ) * (rt.bottom*0.5f));
					else if(GetModifyMode() == MODIFY_SCALING)
						LineTo(hdc, atim*(rt.right-50) + 40, ( -kcd1.scale.z*0.1f + 1.0f ) * (rt.bottom*0.5f));
				}

				SelectPen(hdc,oldPen);
			}
		}
	}

	HDC hWndDC = GetDC(vTimeline.GetHWnd());
	BitBlt(hWndDC, 0,0,rt.right,rt.bottom, hdc, 0,0, SRCCOPY);
	ReleaseDC(vTimeline.GetHWnd(), hWndDC);
}
bool CGameServer::Update()
{
	if(lastPlayerInfo<gu->gameTime-2){
		lastPlayerInfo=gu->gameTime;

		if (game && game->playing) {
			int firstReal=0;
			if(gameSetup)
				firstReal=gameSetup->numDemoPlayers;
			//send info about the players
			for(int a=firstReal;a<gs->activePlayers;++a){
				if(gs->players[a]->active){
					serverNet->SendData<unsigned char, float, int>(
							NETMSG_PLAYERINFO, a, gs->players[a]->cpuUsage, gs->players[a]->ping);
				}
			}

			//decide new internal speed
			float maxCpu=0;
			for(int a=0;a<gs->activePlayers;++a){
				if(gs->players[a]->cpuUsage>maxCpu && gs->players[a]->active){
					maxCpu=gs->players[a]->cpuUsage;
				}
			}

			if (maxCpu != 0) {
				float wantedCpu=0.35f+(1-gs->speedFactor/gs->userSpeedFactor)*0.5f;
				//float speedMod=1+wantedCpu-maxCpu;
				float newSpeed=gs->speedFactor*wantedCpu/maxCpu;
				//logOutput.Print("Speed %f %f %f %f",maxCpu,wantedCpu,speedMod,newSpeed);
				newSpeed=(newSpeed+gs->speedFactor)*0.5f;
				if(newSpeed>gs->userSpeedFactor)
					newSpeed=gs->userSpeedFactor;
				if(newSpeed<0.1f)
					newSpeed=0.1f;
				if(newSpeed!=gs->speedFactor)
					serverNet->SendData<float>(NETMSG_INTERNAL_SPEED, newSpeed);
			}
		}
	}

	if(!ServerReadNet()){
		logOutput.Print("Server read net wanted quit");
		return false;
	}
	if (game && game->playing && !serverNet->playbackDemo){
		CheckSync();

		// Send out new frame messages.
		unsigned currentTick = SDL_GetTicks();
		float timeElapsed=((float)(currentTick - lastTick))/1000.f;
		if(gameEndDetected)
			gameEndTime+=timeElapsed;
//		logOutput.Print("float value is %f",timeElapsed);

		if(gameClientUpdated){
			gameClientUpdated=false;
			maxTimeLeft=2;
		}
		if(timeElapsed>maxTimeLeft)
			timeElapsed=maxTimeLeft;
		maxTimeLeft-=timeElapsed;

		timeLeft+=GAME_SPEED*gs->speedFactor*timeElapsed;
		lastTick=currentTick;

		while((timeLeft>0) && (!gs->paused || game->bOneStep)){
			if(!game->creatingVideo){
				game->bOneStep=false;
				CreateNewFrame(true);
			}
			timeLeft--;
		}
	}
	serverNet->Update();

	CheckForGameEnd();
	return true;
}
bool CGameServer::Update(void)
{
	if(lastSyncRequest<gu->gameTime-2){
		lastSyncRequest=gu->gameTime;

		if(game->playing){
			//check if last times sync responses is correct
			if(outstandingSyncFrame>0){
				int correctSync=0;
				for(int a=0;a<MAX_PLAYERS;++a){
					if(gs->players[a]->active){
						if(!syncResponses[a] && !serverNet->playbackDemo){		//if the checksum really happens to be 0 we will get lots of falls positives here
							info->AddLine("No sync response from %s",gs->players[a]->playerName.c_str());
							continue;
						}
						if(correctSync && correctSync!=syncResponses[a]){
							SendSystemMsg("Sync error for %s %i %X %X",gs->players[a]->playerName.c_str(),outstandingSyncFrame,correctSync,syncResponses[a]);
							continue;
						}
						correctSync=syncResponses[a];		//this assumes the lowest num player is the correct one, should maybe use some sort of majority voting instead
					}
				}
			}
			for(int a=0;a<MAX_PLAYERS;++a)
				syncResponses[a]=0;
			
			if(!serverNet->playbackDemo){
				//send sync request
				outbuf[0]=NETMSG_SYNCREQUEST;
				(*((int*)&outbuf[1]))=serverframenum;
				serverNet->SendData(outbuf,5);
				outstandingSyncFrame=serverframenum;
			}

			int firstReal=0;
			if(gameSetup)
				firstReal=gameSetup->numDemoPlayers;
			//send info about the players
			for(int a=firstReal;a<MAX_PLAYERS;++a){
				if(gs->players[a]->active){
					outbuf[0]=NETMSG_PLAYERINFO;
					outbuf[1]=a;
					*(float*)&outbuf[2]=gs->players[a]->cpuUsage;
					*(int*)&outbuf[6]=gs->players[a]->ping;
					serverNet->SendData(outbuf,10);
				}
			}

			//decide new internal speed
			float maxCpu=0;
			for(int a=0;a<MAX_PLAYERS;++a){
				if(gs->players[a]->cpuUsage>maxCpu && gs->players[a]->active){
					maxCpu=gs->players[a]->cpuUsage;
				}
			}

			float wantedCpu=0.35+(1-gs->speedFactor/gs->userSpeedFactor)*0.5;
			//float speedMod=1+wantedCpu-maxCpu;
			float newSpeed=gs->speedFactor*wantedCpu/maxCpu;
			//info->AddLine("Speed %f %f %f %f",maxCpu,wantedCpu,speedMod,newSpeed);
			newSpeed=(newSpeed+gs->speedFactor)*0.5;
			if(newSpeed>gs->userSpeedFactor)
				newSpeed=gs->userSpeedFactor;
			if(newSpeed<0.1)
				newSpeed=0.1;
			if(newSpeed!=gs->speedFactor){
				outbuf[0]=NETMSG_INTERNAL_SPEED;
				*((float*)&outbuf[1])=newSpeed;
				serverNet->SendData(outbuf,5);
			}
		}
	}

	if(!ServerReadNet()){
		info->AddLine("Server read net wanted quit");
		return false;
	}
	if (game->playing && !serverNet->playbackDemo){
		LARGE_INTEGER currentFrame;
		QueryPerformanceCounter(&currentFrame);
		
		double timeElapsed=((double)(currentFrame.QuadPart - lastframe.QuadPart))/timeSpeed.QuadPart;
		if(gameEndDetected)
			gameEndTime+=timeElapsed;
//		info->AddLine("float value is %f",timeElapsed);

		if(gameClientUpdated){
			gameClientUpdated=false;
			maxTimeLeft=2;
		}
		if(timeElapsed>maxTimeLeft)
			timeElapsed=maxTimeLeft;
		maxTimeLeft-=timeElapsed;

		timeLeft+=GAME_SPEED*gs->speedFactor*timeElapsed;
		lastframe=currentFrame;
		
		while((timeLeft>0) && (!gs->paused || game->bOneStep)){
			if(!game->creatingVideo){
				game->bOneStep=false;
				CreateNewFrame(true);
			}
			timeLeft--;
		}
	}
	serverNet->Update();

	CheckForGameEnd();
	return true;
}
Exemple #8
0
CDocument* CSingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,
	BOOL bMakeVisible)
	// if lpszPathName == NULL => create new file of this type
{
	CDocument* pDocument = NULL;
	CFrameWnd* pFrame = NULL;
	BOOL bCreated = FALSE;      // => doc and frame created
	BOOL bWasModified = FALSE;

	if (m_pOnlyDoc != NULL)
	{
		// already have a document - reinit it
		pDocument = m_pOnlyDoc;
		if (!pDocument->SaveModified())
			return NULL;        // leave the original one

		pFrame = (CFrameWnd*)AfxGetMainWnd();
		ASSERT(pFrame != NULL);
		ASSERT(pFrame->IsKindOf(RUNTIME_CLASS(CFrameWnd)));
		ASSERT_VALID(pFrame);
	}
	else
	{
		// create a new document
		pDocument = CreateNewDocument();
		ASSERT(pFrame == NULL);     // will be created below
		bCreated = TRUE;
	}

	if (pDocument == NULL)
	{
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		return NULL;
	}
	ASSERT(pDocument == m_pOnlyDoc);

	if (pFrame == NULL)
	{
		ASSERT(bCreated);

		// create frame - set as main document frame
		BOOL bAutoDelete = pDocument->m_bAutoDelete;
		pDocument->m_bAutoDelete = FALSE;
					// don't destroy if something goes wrong
		pFrame = CreateNewFrame(pDocument, NULL);
		pDocument->m_bAutoDelete = bAutoDelete;
		if (pFrame == NULL)
		{
			AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
			delete pDocument;       // explicit delete on error
			return NULL;
		}
	}

	if (lpszPathName == NULL)
	{
		// create a new document
		SetDefaultTitle(pDocument);

		// avoid creating temporary compound file when starting up invisible
		if (!bMakeVisible)
			pDocument->m_bEmbedded = TRUE;

		if (!pDocument->OnNewDocument())
		{
			// user has been alerted to what failed in OnNewDocument
			TRACE0("CDocument::OnNewDocument returned FALSE.\n");
			if (bCreated)
				pFrame->DestroyWindow();    // will destroy document
			return NULL;
		}
	}
	else
	{
		BeginWaitCursor();

		// open an existing document
		bWasModified = pDocument->IsModified();
		pDocument->SetModifiedFlag(FALSE);  // not dirty for open

		if (!pDocument->OnOpenDocument(lpszPathName))
		{
			// user has been alerted to what failed in OnOpenDocument
			TRACE0("CDocument::OnOpenDocument returned FALSE.\n");
			if (bCreated)
			{
				pFrame->DestroyWindow();    // will destroy document
			}
			else if (!pDocument->IsModified())
			{
				// original document is untouched
				pDocument->SetModifiedFlag(bWasModified);
			}
			else
			{
				// we corrupted the original document
				SetDefaultTitle(pDocument);

				if (!pDocument->OnNewDocument())
				{
					TRACE0("Error: OnNewDocument failed after trying to open a document - trying to continue.\n");
					// assume we can continue
				}
			}
			EndWaitCursor();
			return NULL;        // open failed
		}
#ifdef _MAC
		// if the document is dirty, we must have opened a stationery pad - don't
		// change the pathname because we want to treat the document as untitled
		if (!pDocument->IsModified())
#endif
			pDocument->SetPathName(lpszPathName);

		EndWaitCursor();
	}

	if (bCreated && AfxGetMainWnd() == NULL)
	{
		// set as main frame (InitialUpdateFrame will show the window)
		AfxGetThread()->m_pMainWnd = pFrame;
	}
	InitialUpdateFrame(pFrame, pDocument, bMakeVisible);

	return pDocument;
}