int main( void ) { uint32_t dim_cl[2] = { 1024, 512 }; uint32_t dim_gl[2] = { 1024, 512 }; engine_init( dim_cl, dim_gl ); world_init( &engine.world ); while( 1 ) { if( engine_main() < 0 ) break; render_main(); } engine_destroy(); return EXIT_SUCCESS; }
void CRender::render_forward () { VERIFY (0==mapDistort.size()); RImplementation.o.distortion = RImplementation.o.distortion_enabled; // enable distorion //******* Main render - second order geometry (the one, that doesn't support deffering) //.todo: should be done inside "combine" with estimation of of luminance, tone-mapping, etc. { // level r_pmask (false,true); // enable priority "1" phase = PHASE_NORMAL; render_main (Device.mFullTransform,false);// r_dsgraph_render_graph (1) ; // normal level, secondary priority PortalTraverser.fade_render () ; // faded-portals r_dsgraph_render_sorted () ; // strict-sorted geoms r_dsgraph_render_hud_sorted () ; g_pGamePersistent->Environment().RenderLast() ; // rain/thunder-bolts } RImplementation.o.distortion = FALSE; // disable distorion }
/* Purpose: animate and run the game with the clock Input : a char length pointer to the frame buffer and a long length pointer to the frame buffer Returns: nothing, but constantly runs the game and its functions Assume : nothing */ void animate_main(char *base,long *iBase) { long *back,*temp; int musicCounter = 0; int enMisCount = 0; int plMisCount = 0; int x,y = 0; long clock; long newClock; int mouseClicked = 0; unsigned short mouseX,mouseY; int i= 0,j = 0,k = 0,l = 0; int randX,randY,randX2; int fire = 0; int s = 0; int done = 0; int render = 0; struct missile friendlyMis[NUM_MISSILES]; struct missile enemyMis[NUM_MISSILES]; struct explosion explosions[NUM_EXPLOSIONS]; struct missile_Silo silo; struct city city1; struct city city2; struct city city3; struct city city4; struct city city5; struct city city6; int *music = get_music(); Vector original_Vector; /*start the music*/ stop_sound(); start_music(); /*init ther model*/ initialize_model(&city1,&city2,&city3,&city4,&city5,&city6,&silo,friendlyMis,enemyMis,explosions); /*create the backbuffer*/ back = (long *)(buffer + (256 -((long)&buffer)%256)); init_VBL_ISR(original_Vector); while(done == 0) { /*random values for enemy missiles*/ randX = rand() % BORDER_RIGHT + 16; randX2 = rand() % BORDER_RIGHT + 16; randY = rand() % GROUND_LEVEL - 200; /* needs to fire a player missile at the mouse click coordinates */ if (mouseClicked == TRUE) { /* process on input */ if (k > NUM_MISSILES-1) { k = 0; } if (friendlyMis[k].destroyed == TRUE) { friendlyMis[k].destroyed = FALSE; friendlyMis[k].currentY = GROUND_LEVEL-20; friendly_Missile_Fired(mouseX,mouseY, &friendlyMis[k],MISSILE_SILO_FIRING_POINT); missile_fired_sound(); k++; } } clock = clockGet(); if (clock != newClock) { /* process on clock change */ fire++; if(fire == MISSILE_FIRED_TIME) { enemyMis[j].destroyed = FALSE; enemy_Missile_Fired(randX, GROUND_LEVEL, &enemyMis[j],randX2); j++; if(fire == MISSILE_FIRED_TIME) { fire = 0; } if (j == NUM_MISSILES-1) { j = 0; } } mouseClicked = get_mouse_pos(&mouseX,&mouseY); if(render == 1) { render_main(back, city1, city2, city3, city4, city5, city6, silo, enemyMis,friendlyMis, explosions,mouseX,mouseY,render); } /* T */ temp = iBase; iBase = back; back = temp; /* wait for sync and then set the screen to the current buffer */ set_video_base_wrap((char *)iBase); /* process missiles might need to change to be able to handle more */ for (i = 0; i < NUM_MISSILES; i++) { if (enemyMis[i].destroyed == FALSE && explosions[i].exists == FALSE) { processEnemyMissiles(&enemyMis[i],&explosions[i],clock,ENEMY_SPEED); } if (friendlyMis[i].destroyed == FALSE && explosions[i+NUM_MISSILES].exists == FALSE) { processEnemyMissiles(&friendlyMis[i],&explosions[i+NUM_MISSILES],clock,FRIENDLY_SPEED); } } /* process explosions might need to change to be able to handle more */ for (i = 0; i < NUM_EXPLOSIONS; i++) { if (explosions[i].exists == TRUE) { processExplosions(&explosions[i]); } } /* process missile -> explosion collisions */ for (i = NUM_MISSILES; i < NUM_EXPLOSIONS; i++) { if (explosions[i].exists == TRUE) { processCollisions(friendlyMis,enemyMis,explosions[i]); } } /* process explosion -> city explosions */ for (i = 0; i < NUM_MISSILES; i++) { if (explosions[i].hit_city != FALSE) { city_collision(explosions[i].hit_city,&city1,&city2,&city3,&city4,&city5,&city6); } } if (musicCounter < SONG_LENGTH){ if (fire % 4 == 0) { play_music(music[musicCounter]); musicCounter++; } } else { musicCounter = 0; } } newClock = clockGet(); done = game_over(city1,city2,city3,city4,city5,city6); } stop_sound(); }
void CRender::Render () { g_r = 1; VERIFY (0==mapDistort.size()); bool _menu_pp = g_pGamePersistent?g_pGamePersistent->OnRenderPPUI_query():false; if (_menu_pp) { render_menu () ; return ; }; if( !(g_pGameLevel && g_pGameLevel->pHUD) ) return; //. VERIFY (g_pGameLevel && g_pGameLevel->pHUD); // Configure RImplementation.o.distortion = FALSE; // disable distorion Fcolor sun_color = ((light*)Lights.sun_adapted._get())->color; BOOL bSUN = ps_r2_ls_flags.test(R2FLAG_SUN) && (u_diffuse2s(sun_color.r,sun_color.g,sun_color.b)>EPS); if (o.sunstatic) bSUN = FALSE; // Msg ("sstatic: %s, sun: %s",o.sunstatic?"true":"false", bSUN?"true":"false"); // HOM ViewBase.CreateFromMatrix (Device.mFullTransform, FRUSTUM_P_LRTB + FRUSTUM_P_FAR); View = 0; if (!ps_r2_ls_flags.test(R2FLAG_EXP_MT_CALC)) { HOM.Enable (); HOM.Render (ViewBase); } //******* Z-prefill calc - DEFERRER RENDERER if (ps_r2_ls_flags.test(R2FLAG_ZFILL)) { Device.Statistic->RenderCALC.Begin (); float z_distance = ps_r2_zfill ; Fmatrix m_zfill, m_project ; m_project.build_projection ( deg2rad(Device.fFOV/* *Device.fASPECT*/), Device.fASPECT, VIEWPORT_NEAR, z_distance * g_pGamePersistent->Environment().CurrentEnv.far_plane); m_zfill.mul (m_project,Device.mView); r_pmask (true,false); // enable priority "0" set_Recorder (NULL) ; phase = PHASE_SMAP; render_main (m_zfill,false) ; r_pmask (true,false); // disable priority "1" Device.Statistic->RenderCALC.End ( ) ; // flush Target->phase_scene_prepare (); RCache.set_ColorWriteEnable (FALSE); r_dsgraph_render_graph (0); RCache.set_ColorWriteEnable ( ); } else { Target->phase_scene_prepare (); } //******* // Sync point Device.Statistic->RenderDUMP_Wait_S.Begin (); if (1) { CTimer T; T.Start (); BOOL result = FALSE; HRESULT hr = S_FALSE; while ((hr=q_sync_point[q_sync_count]->GetData (&result,sizeof(result),D3DGETDATA_FLUSH))==S_FALSE) { if (!SwitchToThread()) Sleep(ps_r2_wait_sleep); if (T.GetElapsed_ms() > 500) { result = FALSE; break; } } } Device.Statistic->RenderDUMP_Wait_S.End (); q_sync_count = (q_sync_count+1)%2; CHK_DX (q_sync_point[q_sync_count]->Issue(D3DISSUE_END)); //******* Main calc - DEFERRER RENDERER // Main calc Device.Statistic->RenderCALC.Begin (); r_pmask (true,false,true); // enable priority "0",+ capture wmarks if (bSUN) set_Recorder (&main_coarse_structure); else set_Recorder (NULL); phase = PHASE_NORMAL; render_main (Device.mFullTransform,true); set_Recorder (NULL); r_pmask (true,false); // disable priority "1" Device.Statistic->RenderCALC.End (); BOOL split_the_scene_to_minimize_wait = FALSE; if (ps_r2_ls_flags.test(R2FLAG_EXP_SPLIT_SCENE)) split_the_scene_to_minimize_wait=TRUE; //******* Main render :: PART-0 -- first if (!split_the_scene_to_minimize_wait) { // level, DO NOT SPLIT Target->phase_scene_begin (); r_dsgraph_render_hud (); r_dsgraph_render_graph (0); r_dsgraph_render_lods (true,true); if(Details) Details->Render (); Target->phase_scene_end (); } else { // level, SPLIT Target->phase_scene_begin (); r_dsgraph_render_graph (0); Target->disable_aniso (); } //******* Occlusion testing of volume-limited light-sources Target->phase_occq (); LP_normal.clear (); LP_pending.clear (); { // perform tests u32 count = 0; light_Package& LP = Lights.package; // stats stats.l_shadowed = LP.v_shadowed.size(); stats.l_unshadowed = LP.v_point.size() + LP.v_spot.size(); stats.l_total = stats.l_shadowed + stats.l_unshadowed; // perform tests count = _max (count,LP.v_point.size()); count = _max (count,LP.v_spot.size()); count = _max (count,LP.v_shadowed.size()); for (u32 it=0; it<count; it++) { if (it<LP.v_point.size()) { light* L = LP.v_point [it]; L->vis_prepare (); if (L->vis.pending) LP_pending.v_point.push_back (L); else LP_normal.v_point.push_back (L); } if (it<LP.v_spot.size()) { light* L = LP.v_spot [it]; L->vis_prepare (); if (L->vis.pending) LP_pending.v_spot.push_back (L); else LP_normal.v_spot.push_back (L); } if (it<LP.v_shadowed.size()) { light* L = LP.v_shadowed [it]; L->vis_prepare (); if (L->vis.pending) LP_pending.v_shadowed.push_back (L); else LP_normal.v_shadowed.push_back (L); } } } LP_normal.sort (); LP_pending.sort (); //******* Main render :: PART-1 (second) if (split_the_scene_to_minimize_wait) { // skybox can be drawn here if (0) { Target->u_setrt ( Target->rt_Generic_0, Target->rt_Generic_1,0,HW.pBaseZB ); RCache.set_CullMode ( CULL_NONE ); RCache.set_Stencil ( FALSE ); // draw skybox RCache.set_ColorWriteEnable (); CHK_DX(HW.pDevice->SetRenderState ( D3DRS_ZENABLE, FALSE )); g_pGamePersistent->Environment().RenderSky (); CHK_DX(HW.pDevice->SetRenderState ( D3DRS_ZENABLE, TRUE )); } // level Target->phase_scene_begin (); r_dsgraph_render_hud (); r_dsgraph_render_lods (true,true); if(Details) Details->Render (); Target->phase_scene_end (); } // Wall marks if(Wallmarks) { Target->phase_wallmarks (); if (!ps_common_flags.test(RFLAG_BLOODMARKS)) g_r = 0; Wallmarks->Render (); // wallmarks has priority as normal geometry } // Update incremental shadowmap-visibility solver { u32 it=0; for (it=0; it<Lights_LastFrame.size(); it++) { if (0==Lights_LastFrame[it]) continue ; try { Lights_LastFrame[it]->svis.flushoccq() ; } catch (...) { Msg ("! Failed to flush-OCCq on light [%d] %X",it,*(u32*)(&Lights_LastFrame[it])); } } Lights_LastFrame.clear (); } // Directional light - f*****g sun if (bSUN) { RImplementation.stats.l_visible ++; render_sun_near (); render_sun (); render_sun_filtered (); Target->accum_direct_blend (); } // Lighting, non dependant on OCCQ Target->phase_accumulator (); HOM.Disable (); render_lights (LP_normal); // Lighting, dependant on OCCQ render_lights (LP_pending); // Postprocess Target->phase_combine (); VERIFY (0==mapDistort.size()); }