int init(void) { // ARA begin insert new code #ifdef __ANDROID__ runNEONTests(); #endif // ARA end perf_init(); ctrl_init(); render_init(); physics_init(); landscapeMeshId = render_init_mesh( LargeMeshVtx,sizeof(float)*6, LargeMeshVtx+3,sizeof(float)*6, LargeMeshIdx,sizeof(unsigned short)*3, LargeMeshVtxCount,LargeMeshIdxCount/3); convexMeshId = render_init_mesh( BarrelVtx,sizeof(float)*6, BarrelVtx+3,sizeof(float)*6, BarrelIdx,sizeof(unsigned short)*3, BarrelVtxCount,BarrelIdxCount/3); return 0; }
void init(int_ choice){ server_loop_code = new loop_t; reserve_ids(); console_init(); load_previous_server_state(); server_loop_code->array.name = "server loop code"; //signal(SIGINT, simple_signal_handler); switch(choice){ case 1: server_info_init(); if(check_for_parameter("--net-disable", argc_, argv_) == false) net_init(); if(check_for_parameter("--physics-disable", argc_, argv_) == false) physics_init(); if(check_for_parameter("--gametype-disable", argc_, argv_) == false) gametype_init(); if(check_for_parameter("--input-disable", argc_, argv_) == false) input_init(); // signals should still work from the console break; case 2: test_logic_init(); break; case 3: set_signal(SIGTERM, true); break; default: printf("WARNING: This was NOT one of the options, terminating\n"); set_signal(SIGTERM, true); break; } server_time = new server_time_t; }
void GridOrient(vec3d *forward, vec3d *right) { vec3d center; int nrows, ncols; float square_size; if (The_grid != NULL) { center = The_grid->center; nrows = The_grid->nrows; ncols = The_grid->ncols; square_size = The_grid->square_size; } else { vm_vec_make(¢er, 0.0f, 0.0f, 0.0f); nrows = 20; ncols = 20; square_size = 2.0f; } The_grid = create_grid(The_grid, forward, right, ¢er, nrows, ncols, square_size); physics_init(&The_grid->physics); }
int main(int argc, char **argv) { srand(get_tick_count()); memset(&kb, 0, sizeof(kb)); set_keys(); player_init(&p1); smp_alloc((void*)&p1); graphics_init(); physics_init(); glutInit(&argc, argv); glutInitWindowPosition(200, 100); glutInitWindowSize(window_x, window_y); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow(PROGRAM_NAME); glutDisplayFunc(graphics_loop); glutIdleFunc(graphics_loop); glutReshapeFunc(reshape); glutKeyboardFunc(kb_controller_dn_char); glutKeyboardUpFunc(kb_controller_up_char); glutSpecialFunc(kb_controller_dn); glutSpecialUpFunc(kb_controller_up); glutMouseFunc(mouse_handler); glutMotionFunc(mouse_motion_handler); glutPassiveMotionFunc(mouse_motion_handler); threads.phys_main = thread_create(physics_loop, NULL); glutMainLoop(); return EXIT_SUCCESS; }
// ************************************************* GLBoidsScreen::creation GLBoidsScreen( GL3DEnginePtr engine, float xmin=-10.f, float xmax=10.f, float xgap=1.f, float ymin=-10.f, float ymax=10.f, float ygap=1.f ) : _window(engine->window()), _zoom(1.0), _start(0,0), _pos{0,0}, _orient{0,0,0,1}, _action(MouseAction::NOTHING), _finished(false), _viewer_frame( engine ), _viewer_grid( engine, xmin, xmax, xgap, ymin, ymax, ygap ), _viewer_token( engine, 32 ), _gl_text( engine->gl_text() ), _gui_rect( engine ), _physics_running(false), _physics_eng(nullptr), _physics_time(0.0), _frame_time_cur(0.0), _frame_time_mean(0.0), _phys_time_cur(0.0), _phys_time_mean(0.0) { _gui_rect.set_color( {0.8f, 0.8f, 0.8f}, 0.2f ); physics_init(); // // Create some Tokens to display // // 1, 0 + 0rad // glm::vec3 ori {1, 0, 0}; // float orient {M_PI * 0.f}; // glm::vec3 tok_color {1.f, 0.f, 0.f}; // glm::vec3 arr_color {0.2f, 0.2f, 0.2f}; // _token_l.push_back( GLToken::TToken{ ori, orient, tok_color, arr_color } ); // ori = glm::vec3{1.5, 2, 0}; // orient = M_PI / 4.f; // tok_color = glm::vec3{0.f, 1.f, 0.f}; // arr_color = glm::vec3{0.2f, 0.2f, 0.9f}; // _token_l.push_back( GLToken::TToken{ ori, orient, tok_color, arr_color } ); std::cout << "__BOIDS : " << _token_l.size() << std::endl; }
int main (int argc, char * argv[]) { bool restart; unsigned long int particles_n; if (argc < 2) { particles_n = NUMBER_OF_PARTICLES; } else { errno = 0; particles_n = strtoul(argv[1], NULL, 0); if (errno) { perror(__func__); exit(EXIT_FAILURE); } } n = particles_n; px = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); py = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); vx = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); vy = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); m = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); if (px == NULL || py == NULL || vx == NULL || vy == NULL || m == NULL) { perror("main"); exit(EXIT_FAILURE); } draw_init(SCREEN_WIDTH, SCREEN_HEIGHT, FRAME_RATE, n); physics_init(n); rng_init(); do { draw_reset(n); physics_reset(n); restart = main_loop(); } while (restart); rng_free(); physics_free(); draw_free(); align_free(m); align_free(vy); align_free(vx); align_free(py); align_free(px); exit(EXIT_SUCCESS); }
int observer_create(matrix *orient, vec3d *pos) { int objnum,idx; physics_info *pi; // try and find the first free observer slot for(idx=0;idx<MAX_OBSERVER_OBS;idx++){ if(!(Observers[idx].flags & OBS_FLAG_USED)) break; } // if we couldn't find an open slot if(idx == MAX_OBSERVER_OBS){ mprintf(("Ran out of observer slots!\n")); return -1; } // attempt to create the object flagset<Object::Object_Flags> default_flagset; objnum = obj_create(OBJ_OBSERVER,-1,idx,orient,pos,1.0f, default_flagset); // fail situation if(objnum == -1) return -1; // give the observer Descent style physics Objects[objnum].flags.set(Object::Object_Flags::Physics); physics_init(&Objects[objnum].phys_info); pi = &Objects[objnum].phys_info; pi->flags |= PF_ACCELERATES | PF_SLIDE_ENABLED; // setup some physics parameters pi->max_vel.xyz.x = OBS_MAX_VEL_X; pi->max_vel.xyz.y = OBS_MAX_VEL_Y; pi->max_vel.xyz.z = OBS_MAX_VEL_Z; vm_vec_zero(&pi->prev_ramp_vel); vm_vec_zero(&pi->desired_vel); vm_vec_zero(&pi->desired_rotvel); vm_vec_zero(&pi->vel); vm_vec_zero(&pi->rotvel); vm_vec_zero(&pi->prev_fvec); vm_set_identity(&pi->last_rotmat); pi->forward_thrust = 0.0f; pi->speed = 0.0f; pi->fspeed = 0.0f; pi->heading = 0.0f; // set up the observer data Observers[idx].flags |= OBS_FLAG_USED; Observers[idx].objnum = objnum; Observers[idx].target_objnum = -1; return objnum; }
// Create a nice grid -- centered at origin, 10x10, 10.0 size squares, in xz plane. grid *create_default_grid(void) { grid *rgrid; vector fvec, rvec, cvec; rgrid = create_grid(&Global_grid, vm_vec_make(&fvec, 0.0f, 0.0f, 1.0f), vm_vec_make(&rvec, 1.0f, 0.0f, 0.0f), vm_vec_make(&cvec, 0.0f, 0.0f, 0.0f), 100, 100, 5.0f); physics_init(&rgrid->physics); return rgrid; }
int init(void) { perf_init(); ctrl_init(); render_init(); physics_init(); float angX,angY,r; render_get_view_angle(angX,angY,r); r *= 0.5f; render_set_view_angle(angX,angY,r); return 0; }
int init(void) { perf_init(); ctrl_init(); render_init(); physics_init(); landscapeMeshId = render_init_mesh( LargeMeshVtx,sizeof(float)*6, LargeMeshVtx+3,sizeof(float)*6, LargeMeshIdx,sizeof(unsigned short)*3, LargeMeshVtxCount,LargeMeshIdxCount/3); convexMeshId = render_init_mesh( BarrelVtx,sizeof(float)*6, BarrelVtx+3,sizeof(float)*6, BarrelIdx,sizeof(unsigned short)*3, BarrelVtxCount,BarrelIdxCount/3); return 0; }
int main(void) { physics_init(LCD_WIDTH, LCD_HEIGHT); input_init(); display_init(); segment_init(); players_init(); playerA = players_get(0); playerB = players_get(1); ball = physics_create(LCD_WIDTH / 2, LCD_HEIGHT / 2, BALL_RADIUS, BALL_MASS); for (;;) { input_update(); players_update(0.01f); physics_update(0.01f); game_update(); game_draw(); } return 0; }
Simulator::Simulator() { physics_init(); physics_set_collider(&collide_callback); }
int main (int argc, const char **argv) { #ifdef WIN32 { // set the console to accept escape sequences (Win10+) HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); if (console != INVALID_HANDLE_VALUE) { DWORD consoleMode = 0; GetConsoleMode(console, &consoleMode); consoleMode |= 4; // ENABLE_VIRTUAL_TERMINAL_PROCESSING; but that isn't available in our current SDK target SetConsoleMode(console, consoleMode); } } #endif int exit_code = EXIT_SUCCESS; try { // Experiment with floating point masks. // #ifdef FE_NOMASK_ENV // feenableexcept(FE_INVALID); // feenableexcept(FE_DIVBYZERO | FE_INVALID); // #endif bgl = new BackgroundLoader(); size_t winid = gfx_init(cb); debug_drawer = new BulletDebugDrawer(ogre_sm); // FIXME: hack #ifdef WIN32 mouse = new MouseDirectInput8(winid); bool use_dinput = getenv("GRIT_DINPUT")!=NULL; keyboard = use_dinput ? (Keyboard *)new KeyboardDirectInput8(winid) : (Keyboard *)new KeyboardWinAPI(winid); #else mouse = new MouseX11(winid); keyboard = new KeyboardX11(winid); #endif clipboard_init(); physics_init(); net_init(); core_option_init(); streamer_init(); navigation_init(); // audio_init(getenv("GRIT_AUDIO_DEV")); audio_init(NULL); std::vector<std::string> args; for (int i=0 ; i<argc ; i++) { args.push_back(argv[i]); } try { const char *init_file = getenv("GRIT_INIT"); if (init_file == nullptr) init_file = "/system/init.lua"; init_lua(init_file, args, core_L); } catch (Exception &e) { CERR << "Fatal error: " << e << std::endl; exit_code = EXIT_FAILURE; } // Lua returns - we quit. CVERB << "Shutting down Lua net subsystem..." << std::endl; net_shutdown(core_L); navigation_shutdown(); object_all_del(core_L); // Will remove all demands from background loader. CVERB << "Shutting down Lua graphics subsystem..." << std::endl; gfx_shutdown_lua(core_L); CVERB << "Shutting down Background Loader..." << std::endl; bgl->shutdown(); CVERB << "Shutting down Mouse & Keyboard..." << std::endl; if (mouse) delete mouse; if (keyboard) delete keyboard; CVERB << "Shutting down clipboard..." << std::endl; clipboard_shutdown(); CVERB << "Shutting down Lua VM..." << std::endl; if (core_L) shutdown_lua(core_L); CVERB << "Shutting down audio subsystem..." << std::endl; audio_shutdown(); //close AL device CVERB << "Shutting down physics subsystem..." << std::endl; physics_shutdown(); CVERB << "Shutting down the physics debug drawer..." << std::endl; if (debug_drawer) delete debug_drawer; CVERB << "Shutting down the Graphics subsystem..." << std::endl; gfx_shutdown(); delete bgl; } catch (Exception &e) { std::cerr << "TOP LEVEL ERROR: " << e << std::endl; return EXIT_FAILURE; } return exit_code; }
int main(int argc, char* argv[]) { CommandLineArgs args(argc,argv); if (args.CheckCmdLineFlag("help")) { Usage(); return 0; } args.GetCmdLineArgument("enable_interop", useInterop); printf("useInterop=%d\n",useInterop); args.GetCmdLineArgument("pause_simulation", pauseSimulation); printf("pause_simulation=%d\n",pauseSimulation); char* tmpfile = 0; args.GetCmdLineArgument("load_bulletfile", tmpfile ); if (tmpfile) fileName = tmpfile; printf("load_bulletfile=%s\n",fileName); printf("\n"); #ifdef __APPLE__ MacOpenGLWindow* window = new MacOpenGLWindow(); #else Win32OpenGLWindow* window = new Win32OpenGLWindow(); #endif window->init(1024,768); #ifndef __APPLE__ GLenum err = glewInit(); #endif window->runMainLoop(); window->startRendering(); window->endRendering(); int maxObjectCapacity=128*1024; GLInstancingRenderer render(maxObjectCapacity); render.setCameraDistance(30); render.InitShaders(); // createSceneProgrammatically(render); render.writeTransforms(); window->runMainLoop(); physics_init(); physics_create_scene(2); create_graphics_from_physics_objects(render); window->setMouseCallback(btDefaultMouseCallback); window->setKeyboardCallback(btDefaultKeyboardCallback); while (!window->requestedExit()) { CProfileManager::Reset(); if (shootObject) { shootObject = false; btVector3 linVel;// = (m_cameraPosition-m_cameraTargetPosition).normalize()*-100; int x,y; window->getMouseCoordinates(x,y); render.getMouseDirection(&linVel[0],x,y); linVel.normalize(); linVel*=100; // btVector3 startPos; float orn[4] = {0,0,0,1}; float pos[4]; render.getCameraPosition(pos); // demo.setObjectTransform(pos,orn,0); // render.writeSingleTransformInstanceToCPU(pos,orn,0); // createScene(render, demo); // printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances); // printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances); // render.writeTransforms(); } // float deltaTime = 1.f/60.f; if (!pauseSimulation) physics_simulate(); // stepSimulation(deltaTime); { BT_PROFILE("sync_graphics_to_physics_objects"); sync_graphics_to_physics_objects(render); } { BT_PROFILE("render.writeTransforms"); render.writeTransforms(); } { BT_PROFILE("window->startRendering"); window->startRendering(); } { BT_PROFILE("render.RenderScene"); render.RenderScene(); } { BT_PROFILE("window->endRendering"); window->endRendering(); } { BT_PROFILE("glFinish"); //glFinish(); // glFlush(); } CProfileManager::Increment_Frame_Counter(); static bool printStats = true; if (printStats && !pauseSimulation) { static int count = 0; count--; if (count<0) { count = 100; CProfileManager::dumpAll(); //printStats = false; } else { // printf("."); } } } render.CleanupShaders(); window->exit(); delete window; return 0; }
//simple demo: int main (int argc, char *argv[]) { //issue printf("\n -=[ Hello, and welcome to RollCageX version %s ]=-\n\n", VERSION); printf(" Copyright (C) 2009, This program comes with ABSOLUTELY NO WARRANTY; see\n \"license.txt\" for details\n\n"); printf(" This is free software, and you are welcome to redistribute it and/or modify\n it under the GNU General Public License as published by the Free Software\n Foundation, version 3 or (at your option) later\n\n"); printf("= Credits (nicknames refers to usernames on the gorcx.net forum):\n"); printf(" \"MaAkaJon\"\t\tproject creator\n"); printf(" \"Soul Slinger\"\tcoder (created this and the earlier versions)\n"); printf(" All of you on the planetrollcage.com and gorcx.net forums!\n\n"); printf("* Projects that made RCX possible:\n"); printf(" GNU\t\t\t\tdefines computer freedom itself... :-)\n"); printf(" Simple DirectMedia Layer\twindow handling, input/outputs\n"); printf(" Open Dynamics Engine\trigid body dynamics\n"); printf("= End of credits\n\n"); printf(" Default controls (can be changed in profile):\n"); printf(" > Arrow keys: Steering and throttling\n"); printf(" > Spacebar: Drifting break\n"); printf(" > Left Alt: Soft breaks\n"); printf(" > Q and E: change camera distance along Z axis\n"); printf(" > A and D: change camera distance along X axis\n"); printf(" > W and S: change camera distance along Y axis\n"); printf(" > F1 to F4: change camera settings\n"); printf(" > F5: spawn box\n"); printf(" > F6: spawn box (10s above ground)\n\n"); //end of issue if (argc != 1) printf("(Passing arguments - not supported)\n\n"); //printlog needs internal.verbosity, set it to default value printf("(verbosity level is assumed \"1\" until read from internal conf)\n"); internal.verbosity = 1; //check if program was called with another pwd (got '/' in "name") int count; for (count = strlen(argv[0]); count != -1; --count) if (argv[0][count] == '/') { char pwd[count+2]; //1 for \0 and 1 for [0] strncpy (pwd, argv[0], count+1); pwd[count+1] = '\0'; printf ("(changing pwd: %s)\n", pwd); chdir (pwd); break; } if (load_conf ((char *)"data/internal.conf", (char *)&internal, internal_index)) return -1; if (graphics_init()) return -1; //<insert menu here> profile *prof = load_profile ((char *)"data/profiles/default"); if (!prof) return -1; venom = load_car((char *)"data/teams/Nemesis/cars/Venom"); if (!venom) emergency_quit(); prof->car = venom; camera.car = venom; //menu done, race selected, starting race... if (physics_init()) { graphics_quit(); return -1; } if (load_track((char *)"data/worlds/Sandbox/tracks/Box")) emergency_quit(); //load box for online spawning box = load_object((char *)"data/objects/misc/box"); sphere = load_object((char *)"data/objects/misc/sphere"); if (!box) emergency_quit(); spawn_car (venom, track.start[0], track.start[1], track.start[2]); focused_car = venom; //single-thread function //WARNING: Don't run the game constantly for more than around 49 days! //(or the realtime will wrap, and the timing solution will go crazy) Uint32 simtime = SDL_GetTicks(); //set simulated time to realtime Uint32 realtime; //real time (with possible delay since last update) Uint32 stepsize_ms = internal.stepsize*1000+0.0001; //calculate stepsize from s to ms (append 0.0001 for correct conversion) printlog (0, "\n-> Starting Race\n"); runlevel = running; while (runlevel == running) { event_step(stepsize_ms); //always check for events physics_step(); simtime += stepsize_ms; //if realtime is larger than simtime (and graphics threshold) if (SDL_GetTicks()+internal.threshold > simtime) { printlog(2, "\nWarning: simtime less than realtime (to low stepsize), dropping frame..\n\n"); ++stepsize_warnings; } else //we got time left to draw frame on { graphics_step(stepsize_ms); realtime = SDL_GetTicks(); if (simtime > realtime) { SDL_Delay (simtime - realtime); } else { printlog(2, "\nWarning: (not sleeping, realtime became to high (to low treshold?))\n"); ++threshold_warnings; } } } printlog(0, "-> Race done!\n"); free_all(); physics_quit(); //race done //<insert menu here> //menu done, quit selected, ending graphics and terminating program graphics_quit(); printlog(0, "\n<-- Some basic info: -->\n"); printlog(0, "(does not interest most people)\n"); printlog(0, "Race time (ms): %i\n", simtime); printlog(0, "Stepsize-to-low (framedrop) warnings: %i\n", stepsize_warnings); printlog(0, "Graphics-threshold-to-low warnings: %i\n", threshold_warnings); printlog(0, "\nBye!\n\n"); return 0; }
//simple demo: int main (int argc, char *argv[]) { //issue printf("\n -=[ Hello, and welcome to RollCageX version %s ]=-\n\n%s\n", VERSION, ISSUE); //end if (argc != 1) printf("(Passing arguments - not supported)\n\n"); //check if program was called with another pwd (got '/' in "name") if (char *s = strrchr(argv[0], '/')) { *s='\0'; //modify string to end at last slash printf("(changing pwd: %s)\n", argv[0]); chdir (argv[0]); } printlog(0, "Loading...\n"); load_conf ("data/internal.conf", (char *)&internal, internal_index); if (!graphics_init()) return -1; //TODO: there should be menus here, but menu/osd system is not implemented yet... also: //on failure, rcx should not just terminate but instead abort the race and warn the user //MENU: welcome to rcx, please select profile or create a new profile Profile *prof = Profile_Load ("data/profiles/default"); if (!prof) return -1; //GOTO: profile menu if (!physics_init()) { //menu: warn and quit! graphics_quit(); return -1; } //MENU: select race type // - assuming 2P free roam - //MENU: P1: select theme/car Car_Template *venom_template = Car_Template::Load("data/teams/Nemesis/cars/Venom"); if (!venom_template) return -1; //GOTO: car selection menu //MENU: P2: select theme/car Car_Template *reaper_template = Car_Template::Load("data/teams/Vostok/cars/Reaper"); if (!reaper_template) return -1; //GOTO: car selection //MENU: select world/track if (!load_track((char *)"data/worlds/Sandbox/tracks/Box")) return -1; //GOTO: track selection menu //TMP: load box for online spawning box = Object_Template::Load("data/objects/misc/box"); sphere = Object_Template::Load("data/objects/misc/sphere"); funbox = Object_Template::Load("data/objects/misc/funbox"); if (!box || !sphere || !funbox) return -1; //spawn car Venom = venom_template->Spawn(track.start[0]-4, track.start[1], track.start[2]); prof->car = Venom; camera.car = Venom; //lets spawn another car: Reaper = reaper_template->Spawn(track.start[0]+4, track.start[1], track.start[2]); //MENU: race configured, start? start_race(); //race done, remove all objects... Object::Destroy_All(); //MENU: race done, replay, play again, quit? // - assuming quit - //remove loaded data (not all data, only "racetime" - for this race) Racetime_Data::Destroy_All(); //MENU: back to main menu here // - assuming player wants to log out - physics_quit(); Profile_Remove_All(); //should only be one active profile right now, but any case, remove all //MENU: select profile // - assumes player wants to quit - graphics_quit(); //some basic info (until menu for printing it) print_info(); printf("\nBye!\n\n"); return 0; }