void CheckFrameRate(void) { if(UseFrameSkip) // skipping mode? { if(!(dwActFixes&0x80)) // not old skipping mode? { dwLaceCnt++; // -> store cnt of vsync between frames if(dwLaceCnt>=MAXLACE && UseFrameLimit) // -> if there are many laces without screen toggling, { // do std frame limitation if(dwLaceCnt==MAXLACE) bInitCap=TRUE; if(bSSSPSXLimit) FrameCapSSSPSX(); else FrameCap(); } } else if(UseFrameLimit) { if(bSSSPSXLimit) FrameCapSSSPSX(); else FrameCap(); } calcfps(); // -> calc fps display in skipping mode } else // non-skipping mode: { if(UseFrameLimit) FrameCap(); // -> do it if(ulKeybits&KEY_SHOWFPS) calcfps(); // -> and calc fps display } }
int main(int argc, char **argv) { int i; Light light; const char *filename; Camera cam; Vec3 position = {0, 0, 150e9}; Vec3 up = {0, 1, 0}; Vec3 target = {0, 0, 0}; Shader *shader_light; Shader *shader_simple; Mesh *mesh; Renderable planet; if (argc < 2) filename = STRINGIFY(ROOT_PATH) "/data/teapot.ply"; else filename = argv[1]; solsys = solsys_load(STRINGIFY(ROOT_PATH) "/data/sol.ini"); if (solsys == NULL) return 1; mesh = mesh_import(filename); if (mesh == NULL) return 1; for (i = 0; i < mesh->num_vertices; i++) /* Blow up the teapot */ { mesh->vertex[i].x = mesh->vertex[i].x * 100; mesh->vertex[i].y = mesh->vertex[i].y * 100; mesh->vertex[i].z = mesh->vertex[i].z * 100; } cam.fov = M_PI/4; cam.left = 0; cam.bottom = 0; cam.width = 1024; cam.height = 768; cam.zNear = 1e6; cam.zFar = 4.5e15; init_allegro(&cam); cam_lookat(&cam, position, target, up); glewInit(); shader_light = shader_create(STRINGIFY(ROOT_PATH) "/data/lighting.v.glsl", STRINGIFY(ROOT_PATH) "/data/lighting.f.glsl"); if (shader_light == NULL) return 1; shader_simple = shader_create(STRINGIFY(ROOT_PATH) "/data/simple.v.glsl", STRINGIFY(ROOT_PATH) "/data/simple.f.glsl"); if (shader_simple == NULL) return 1; glmProjectionMatrix = glmNewMatrixStack(); glmViewMatrix = glmNewMatrixStack(); glmModelMatrix = glmNewMatrixStack(); light.position = light_pos; memcpy(light.ambient, light_ambient, sizeof(light_ambient)); memcpy(light.diffuse, light_diffuse, sizeof(light_diffuse)); memcpy(light.specular, light_specular, sizeof(light_specular)); glClearColor(20/255., 30/255., 50/255., 1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glPointSize(2); planet.data = mesh; planet.upload_to_gpu = mesh_upload_to_gpu; planet.render = mesh_render; planet.shader = shader_light; renderable_upload_to_gpu(&planet); /* Transformation matrices */ cam_projection_matrix(&cam, glmProjectionMatrix); /* Start rendering */ while(handle_input(ev_queue, &cam)) { void *ctx; Entity *renderlist, *prev; t += 365*86400; /* Physics stuff */ solsys_update(solsys, t); ctx = ralloc_context(NULL); prev = NULL; for (i = 0; i < solsys->num_bodies; i++) { Entity *e; e = ralloc(ctx, Entity); e->orientation = (Quaternion) {1, 0, 0, 0}; e->renderable = &planet; e->position = solsys->body[i].position; e->radius = solsys->body[i].radius; e->prev = prev; e->next = NULL; if (prev != NULL) e->prev->next = e; prev = e; if (i == 0) renderlist = e; } /* Rendering stuff */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glmLoadIdentity(glmModelMatrix); glmLoadIdentity(glmViewMatrix); cam_view_matrix(&cam, glmViewMatrix); /* view */ light_upload_to_gpu(&light, shader_light); render_entity_list(renderlist); al_flip_display(); calcfps(); ralloc_free(ctx); } ralloc_free(mesh); ralloc_free(solsys); shader_delete(shader_light); shader_delete(shader_simple); glmFreeMatrixStack(glmProjectionMatrix); glmFreeMatrixStack(glmViewMatrix); glmFreeMatrixStack(glmModelMatrix); al_destroy_display(dpy); return 0; }
int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) #endif { int i,n,j; u32 dd,nn; dip_t *dip; #if !defined(_DEBUG) && !defined(GEKKO) && !defined(LINUX) int argc; char **argv,*pstart,*pend,*str; list_c argvlist; pstart = lpCmdLine; for(;;) { while(*pstart == ' ') //skip any spaces pstart++; if(strcmp(pstart,"") != 0) //is there another entry? { if(*pstart == '\"') //beginning quote, this is all one str pend = strchr(pstart,'\"'); else if((pend = strchr(pstart,' ')) == 0) pend = lpCmdLine + strlen(lpCmdLine); str = new char[pend - pstart + 1]; memset(str,0,pend - pstart + 1); strncpy(str,pstart,pend - pstart); pstart = pend; argvlist.add(str); } else break; } argc = argvlist.num() + 1; argv = new char*[argc]; argv[0] = new char[_MAX_PATH]; GetModuleFileName(GetModuleHandle(0),argv[0],_MAX_PATH); for(i=1;i<argc;i++) argv[i] = (char*)argvlist.get(i - 1); #endif memset(RomSets,0,sizeof(CRomSet*) * MAX_ROMSETS); AddRomSets(); ParameterInit_Arg(argv,argc); //set our argument pointers freq = 1000; last = ticks = SDL_GetTicks(); frametime = freq / 60; for(n=0;RomSets[n] != 0;n++) //set default dip settings { for(nn=0,j=0;j<4;j++) { if((dip = RomSets[n]->GetDip(j)) == 0) break; for(dd=0,i=0;dip[i].Name;i++) dd |= dip[i].Default; nn |= dd << (j * 8); } settings.dip_default[n] = nn; } settings.SetDefault(); if(CheckParameter("--setdefaults") == 0) //user wants to reset settings, so dont load settings.Load(); //load settings if(InitSystem(800,600,CheckParameter("--fullscreen")) != 0) { //initialize system classes (vid/inp/snd) message("error initializing system\n"); //complain, hopefully the bad component explained return(1); //return error } if(CheckParameter("--rompath")) { strcpy(settings.romdir,GetParameterData("--rompath")); } if(CheckParameter("--romset")) //if romset parameter specified { for(i=0;RomSets[i] != 0;i++) { if(strcmp(RomSets[i]->GetName(),GetParameterData("--romset")) == 0) { if(Init(RomSets[i]) != 0) //try to create machine break; printf("trying to load %s\n",RomSet->GetName()); video->SetSize(RomSet->ScreenW(),RomSet->ScreenH()); if(Machine) { if(CheckParameter("--loadstate")) //load save state { CState *s = new CState(); //create new state object if(s->Load(0,RomSet->GetName()) == 0) //try to load state { Machine->LoadState(s); //load state into machine s->Close(); //close state object } delete s; //destroy state object } } break; } } } if(CheckParameter("--stop") || //see if emulation should begin paused CheckParameter("--pause")) running = 0; //clear running flag if(CheckParameter("--run")) //see if emulation should begin running (default) running = 1; //set running flag while(quit == 0) { nolock = 0; // if(GetAsyncKeyState('Q')) //cheap fast forward hack // nolock = 1; nolock += ~settings.lockfps & 1; if(running && Machine) //if running flag is set and a machine is loaded Machine->Frame(); //execute a machine frame // else // Sleep(100); //else sleep for 0.1 seconds calcfps(); //show frames per second in title bar checkmessages(); //process messages } Kill(); //destroy machine KillSystem(); //destroy system classes settings.Save(); //save settings for(n=0;RomSets[n] != 0;n++) //free romsets delete RomSets[n]; return(0); }