Example #1
0
void main_loop() {
  struct timespec ptime;
  struct timespec ctime;
  struct timespec diff;
  clock_gettime(CLOCK_MONOTONIC_COARSE, &ctime);
  while (running) {
    clock_gettime(CLOCK_MONOTONIC_COARSE, &ptime);

    reshape_window();
    poll_geometry();
    process_events();
    display_func();

    clock_gettime(CLOCK_MONOTONIC_COARSE, &ctime);
    diff.tv_sec  = ctime.tv_sec - ptime.tv_sec;
    diff.tv_nsec = ctime.tv_nsec - ptime.tv_nsec;
    long sleeptime = 16666666l - ( diff.tv_sec * 1000000000l + diff.tv_nsec );
    diff.tv_sec  = 0;
    diff.tv_nsec = sleeptime;

    while (diff.tv_nsec > 0) {
      struct timespec rem;
      int i = nanosleep(&diff, &rem);
      if (i < 0) {
        diff.tv_sec  = rem.tv_sec;
        diff.tv_nsec = rem.tv_nsec;
      } else {
        break;
      }
    }
  }
}
Example #2
0
void reshape(int width, int height)
{
    reshape_window(width, height);
    //glutReshapeWindow(width, height);
    if (draw_tw)
        TwWindowSize(width, height);
}
Example #3
0
bool Window::SDL_init( unsigned int w , unsigned int h )
{
    log_printf(INFO,"Starting SDL with %dx%d resolution\n",w,h);
    if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) ) {
        log_printf(CRITICAL,"SDL error occurred: %s\n",SDL_GetError());
        return false;
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

    flags|= SDL_OPENGL|SDL_HWSURFACE|SDL_DOUBLEBUF;
    flags|= SDL_RESIZABLE;

    SDL_Surface * image = SDL_LoadBMP(DATA("icon.bmp").c_str());
    if( image ) {
        Uint32 colorkey = SDL_MapRGB(image->format, 255, 0, 255);
        SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey);
        SDL_WM_SetIcon(image,NULL);
    }

    SDL_WM_SetCaption("Planetz","Planetz");

    reshape_window( w , h );

    return true;
}
Example #4
0
void step()
{
    //"1-4: demos, p - pause, y - kick body, ' - draw contacts/constraints"
    clock_t cl = clock();
    if (cl > prevCl + (double)CLOCKS_PER_SEC * speed / 1000 && !pause)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        draw_bodies(world.bodies);
        //draw_ropes(world.ropes);
        if (draw_cos)
        {
            draw_collisions(world.collisions);
            draw_constraints(world.constraints);
        }

        if (drag_force != 0)
        {
            double wx, wy;
            screen_coords2world(motion_x, motion_y, wx, wy);
            Vector2 head(wx, wy), tail(drag_force->Body->form->point + drag_force->LocalPoint);
            Vector2 vect = head - tail;
            drag_force->Magnitude[0] = drag_force_spring_coef * vect.v1 * drag_force->Body->mass
                - drag_force_damper_coef * drag_force->Body->velocity.v1;
            drag_force->Magnitude[1] = drag_force_spring_coef * vect.v2 * drag_force->Body->mass
                - drag_force_damper_coef * drag_force->Body->velocity.v2;
            glColor3f(0.0f, 1.0f, 0.0f);
            draw_segment(Segment(head, tail));
        }
        if (kickBody != 0)
        {
            double wx, wy;
            screen_coords2world(motion_x, motion_y, wx, wy);
            glColor3f(0.0f, 0.0f, 1.0f);
            draw_segment(Segment(Vector2(wx, wy), kickBody->form->point));
        }

        if (player_body)
        {
            camera_xpos = player_body->form->point.v1;
            camera_ypos = player_body->form->point.v2;

            int w = glutGet(GLUT_WINDOW_WIDTH);
            int h = glutGet(GLUT_WINDOW_HEIGHT);
            reshape_window(w, h);
        }
        if (draw_tw)
            TwDraw();
        glutSwapBuffers();
    }

    if (cl > prevCl + (double)CLOCKS_PER_SEC * speed / 1000 && !pause)
    {
        world.update(world.vars.timeStep);
        prevCl = cl;
    }
}
Example #5
0
void check_resize(Game *game, XEvent *e)
{
    if(e->type != ConfigureNotify)
	return;

    XConfigureEvent xce = e->xconfigure;
    if(xce.width != xres || xce.height != yres) {
	reshape_window(game, xce.width, xce.height);
    }
}
Example #6
0
void check_resize(XEvent *e)
{
    if(e->type != ConfigureNotify)
        return;
    XConfigureEvent xce = e->xconfigure;
    if(xce.width != WINDOW_WIDTH || xce.height != WINDOW_HEIGHT)
    {
        reshape_window(xce.width, xce.height);
    }
}
Example #7
0
void check_resize(XEvent *e)
{
	//The ConfigureNotify is sent by the
	//server if the window is resized.
	if (e->type != ConfigureNotify)
		return;
	XConfigureEvent xce = e->xconfigure;
	if (xce.width != xres || xce.height != yres) {
		//Window size did change.
		reshape_window(xce.width, xce.height);
	}
}