HRESULT APPLICATION::Update(float deltaTime) { //Set World matrix D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); m_pDevice->SetTransform(D3DTS_WORLD, &matWorld); //Update m_mouse m_mouse.Update(); //Update m_camera m_camera.Update(m_mouse, deltaTime); //Change intersection test type if(KEYDOWN(VK_SPACE)) { Sleep(300); m_intersectType++; if(m_intersectType > 2)m_intersectType = 0; } if(KEYDOWN(VK_ESCAPE)) Quit(); return S_OK; }
HRESULT APPLICATION::Update(float deltaTime) { //Control camera D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); m_pDevice->SetTransform(D3DTS_WORLD, &matWorld); //Update mouse m_mouse.Update(); //Update camera m_camera.Update(m_mouse, deltaTime); if(KEYDOWN(VK_ESCAPE)) Quit(); return S_OK; }
bool LoadWorld() { UnloadWorld(); editordata.helppage = 0; editordata.numbezinput = 0; editordata.mousebounce[1] = false; //teststrip = track.AddNewRoad(); //begin loading world LoadingScreen("Loading...\nConfiguration files"); CONFIGFILE setupfile; setupfile.Load(settings.GetDataDir() + "/tracks/editor.config"); setupfile.GetParam("active track", editordata.activetrack); if (editordata.activetrack == "") editordata.activetrack = "default"; objects.LoadObjectsFromFolder(settings.GetDataDir() + "/tracks/" + editordata.activetrack + "/objects/"); track.Load(editordata.activetrack); //float aangle[] = {0, 1, 0, 0}; //track.GetStartOrientation(0).GetAxisAngle(aangle); //cam.Rotate(aangle[0], aangle[1], aangle[2], aangle[3]); VERTEX start = track.GetStart(0); cam.Move(-start.x, -start.y, -start.z); cam.Update(); cam.LoadVelocityIdentity(); //car_file = "s2000"; //ifstream csfile; //car_file = ""; //csfile.open((settings.GetSettingsDir() + "/selected_car").c_str()); //car_paint = 0; /* if (csfile) { state.SetCarName(0, utility.sGetLine(csfile)); state.SetCarPaint(0, utility.iGetParam(csfile)); csfile.close(); } */ //LoadingScreen("Loading...\nLoading scenery objects"); //objects.LoadObjectsFromFolder(settings.GetDataDir() + "/tracks/" + state.GetTrackName() + "/objects"); /*trees.DeleteAll(); int numtrees = 200; for (i = 0; i < numtrees/2; i++) { VERTEX tp; tp.x = ((float) rand()/RAND_MAX)*(param[0]/2.0)+param[0]/4.0; tp.z = ((float) rand()/RAND_MAX)*(param[2]/2.0)+param[2]/4.0; tp.x += param[3]; tp.z += param[4]; tp.y = terrain.GetHeight(tp.x, tp.z); trees.Add(tp, 40.0, 0, 5); } for (i = 0; i < numtrees/2; i++) { VERTEX tp; tp.x = ((float) rand()/RAND_MAX)*(param[0]/2.0)+param[0]/4.0; tp.z = ((float) rand()/RAND_MAX)*(param[2]/2.0)+param[2]/4.0; tp.x += param[3]; tp.z += param[4]; tp.y = terrain.GetHeight(tp.x, tp.z); trees.Add(tp, 60.0, 1, 5); }*/ LoadingScreen("Loading...\nDone"); mq1.AddMessage("Editor started, press H for help"); return true; }
void Update() { //cam.position.DebugPrint(); bool mainloop = false; //std::cout << "Mainloop" << std::endl; //if unpaused and getting a reasonable framerate //if (fps > MIN_FPS && timefactor != 0.0f) if (fps > 0.0f && timefactor != 0.0f) { double time_increment = timefactor / fps; //std::cout << "Time elapsed: " << execution_time << " + " << time_increment << std::endl; execution_time += time_increment; //int num_updates = (int) (execution_time / FRAME_TIME); // double this_frame = (double) num_updates * FRAME_TIME; mouse.Update(cam, SCREEN_WIDTH, SCREEN_HEIGHT, timefactor, fps); cam.dir = mouse.GetDir(); while (execution_time > FRAME_TIME) { //std::cout << "Frame start: " << execution_time << std::endl; #ifdef PERFORMANCE_PROFILE suseconds_t t1, t2; t1 = GetMicroSeconds(); t1 = GetMicroSeconds(); #endif //multiplay.Update(FRAME_TIME); //weather tick #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "multiplay.Update() ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif cam.Update(); //handle input //keyman.DoHeldKeys(timefactor, fps, cam); keyman.DoHeldKeys(1.0, 1.0/FRAME_TIME, cam); #ifdef PERFORMANCE_PROFILE t1 = GetMicroSeconds(); t1 = GetMicroSeconds(); #endif #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "world update ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif keyman.DoOneTimeKeys(cam); //particle.Update(timefactor, fps); //particle.Update(1.0, 1.0/FRAME_TIME); cam.ExtractFrustum(); //float timepassed = (timefactor/fps)/86400.0; float timepassed = (FRAME_TIME)/86400.0; /*if (keyman.keys[keyman.GetKey("AccelTimeVFast")]) timefactor = 10000.0; else if (keyman.keys[keyman.GetKey("AccelTimeFast")]) timefactor = 1000.0; else timefactor = 1.0;*/ //float timepassed = (timefactor/fps)/60.0; //float timepassed = (timefactor/fps)/10.0; abs_time += timepassed; day_time += timepassed; if (day_time > 1.0f) day_time -= 1.0f; #ifdef PERFORMANCE_PROFILE t2 = GetMicroSeconds(); cout << "Time increment ticks: " << t2-t1 << endl; t1 = GetMicroSeconds(); #endif mainloop = true; //terrain.Update(cam, timefactor, fps, day_time); //terrain.Update(cam, 1.0, 1.0/FRAME_TIME, day_time); execution_time -= FRAME_TIME; //num_updates++; //replay.IncrementFrame(); } } else { //print "paused" } if (pauserequest) { if (timefactor != 0.0f) timefactor = 0.0f; pauserequest = false; } if (unpauserequest) { if (timefactor == 0.0f) timefactor = 1.0f; unpauserequest = false; } /*if (!mainloop) multiplay.Update(0);*/ //don't need this anymore because we're stopping things from being paused in multiplayer mode }