void print_pixel( int x, int y ){ static bool init_done = false; if( ! init_done ){ init_done = true; create_screen( SCALE * 128, SCALE * 64 );\ atexit ( winloop ); } for( int dx = 0; dx < SCALE; dx++ ){ for( int dy = 0; dy < SCALE; dy++ ){ SetPixel( hdc, SCALE * x + dx, SCALE * y + dy, RGB( 0x00, 0x00, 0x00 )); } } }
Screen* create_screen(Controller* controller, ScreenID sid) { switch(sid) { case s_UNKNOWN_ID: throw "Unable to create a screen with undefined id."; break; case s_INDEX: return new Index_Screen(controller); break; default: if(sid < s_TREAT_EVERYTHING_AFTER_AS_INDEX) throw "Unable to create a screen that is not implemented."; else return create_screen(controller, s_INDEX); } }
int main(int argc,char ** argv){ if(al_init()<0){ //fonction d'initialisation fprintf(stderr,"Error at the initialisation of Allegro"); return -1; } if(!al_init_image_addon() ) { printf("addon Error"); return 0; } options=create_options(); load_options(options,"Options.txt"); screen=create_screen(options); control=create_control(screen); ALLEGRO_BITMAP * bg_picture=NULL; bg_picture = al_load_bitmap("./Ressources/Pictures/test.png"); ALLEGRO_BITMAP * image_titre_d=NULL; image_titre_d =al_load_bitmap("./Ressources/Pictures/play_d.png"); ALLEGRO_BITMAP * image_titre_s=NULL; image_titre_s=al_load_bitmap("./Ressources/Pictures/play_s.png"); /** DEBUT ALLEGRO_BITMAP * image_credit_d=NULL; image_credit_d =al_load_bitmap("./ressource/image/credit_d.png"); ALLEGRO_BITMAP * image_credit_s=NULL; image_credit_s=al_load_bitmap("./ressource/image/credit_s.png"); ALLEGRO_BITMAP * image_quitter_d=NULL; image_quitter_d =al_load_bitmap("./ressource/image/quitter_d.png"); ALLEGRO_BITMAP * image_quitter_s=NULL; image_quitter_s=al_load_bitmap("./ressource/image/quitter_s.png"); */ if (!bg_picture || !image_titre_d || !image_titre_s){ printf("bug image\n"); } struct Title *titles=malloc(sizeof(struct Title)*1); struct Menu * menu=create_menu(bg_picture,titles,create_column_position(1,200,300,300),1); //struct Control* control=creer_control(ecran); /** DEBUT void (*p)(void); void jouer(){ partie = creer_partie(); lancer_jeu(partie);} void credits(){ ALLEGRO_BITMAP * image_credits=NULL; image_credits = al_load_bitmap("./ressource/image/credits.png"); al_draw_bitmap(image_credits,0,0,0); al_flip_display(); al_rest(5.0); } void quitter(){quitter_jeu(partie);} p=jouer; titres[0]=*creer_titre(image_titre_s,image_titre_d,*p); p=credits; titres[1]=*creer_titre(image_credit_s,image_credit_d,*p); p=quitter; titres[2]=*creer_titre(image_quitter_s,image_quitter_d,*p); */ void (*p)(void); void f(){control_menu(menu,control);}
SDLYuvViewer::SDLYuvViewer(uint32_t width, uint32_t height) throw(SDLException) : width(width), height(height) { // create SDL surface screen = create_screen(width, height); flipcnt = 0; }
SDLYuvViewer::SDLYuvViewer() throw(SDLException) : width(YUV_VIEWER_DEFAULT_WIDTH), height(YUV_VIEWER_DEFAULT_HEIGHT) { // create SDL surface screen = create_screen(YUV_VIEWER_DEFAULT_WIDTH, YUV_VIEWER_DEFAULT_HEIGHT); flipcnt = 0; }
/** * main * * TODO: Write function block once this is cleaned up. */ int main(int argc, char** argv) { /* * Local Variables. */ SDL_Event transient_event; SCREEN *screen; MATCH_STATE *match_state; Uint32 frame_start_time; Uint32 frame_time_taken_ms; Uint32 physics_time_delta; Uint32 last_physics_update; Uint32 ai_time_delta; Uint32 last_ai_update; Uint32 ms_per_frame; int rc; StrMap *config_table; Uint32 last_animation_update = 0; Uint32 animation_ms_per_frame; int max_fps; FONT *font; char disc_graphic_file[MAX_CONFIG_VALUE_LEN + 1]; char grass_tile_file[MAX_CONFIG_VALUE_LEN + 1]; char o_xml_file[MAX_CONFIG_VALUE_LEN + 1]; char d_xml_file[MAX_CONFIG_VALUE_LEN + 1]; int ii; SDL_Color white = {0xFF, 0xFF, 0xFF, 0x00}; /* * Begin logging. */ DT_INIT_LOG; /* * TODO: Move loading and retrieving constants using defaults from the config * file to a different folder, code file. Simple api. */ load_config_to_str_map("config.txt", &config_table); if (!get_config_value_int(config_table, cv_animation_ms_per_frame, (int *)&animation_ms_per_frame)) { game_exit("Programmer error: animation ms per frame not handled in cfg."); } if (!get_config_value_int(config_table, cv_max_fps, &max_fps)) { game_exit("Programmer error: max fps not handled in cfg."); } ms_per_frame = (int) MILLISECONDS_PER_SECOND / max_fps; if (!get_config_value_str(config_table, cv_disc_graphic, (char *)disc_graphic_file)) { game_exit("Programmer error: disc graphic not handled in cfg."); } if (!get_config_value_str(config_table, cv_grass_tile_filename, (char *)grass_tile_file)) { game_exit("Programmer error: grass tile graphic not handled in cfg."); } if (!get_config_value_str(config_table, cv_o_xml_file, (char *)o_xml_file)) { game_exit("Programmer error: O XML file not handled in cfg."); } if (!get_config_value_str(config_table, cv_d_xml_file, (char *)d_xml_file)) { game_exit("Programmer error: D XML file not handled in cfg."); } DT_DEBUG_LOG("Config file loaded\n"); /* * Create the screen object and use it to initialise the window system. */ screen = create_screen(); rc = init_window_system(screen, SCREEN_WIDTH, SCREEN_HEIGHT, BPP); if (INIT_OK != rc) { game_exit("Window system could not be initialised."); } DT_DEBUG_LOG("Graphics subsystem created and initialized\n"); /* * Initialise Audio subsystem */ rc = init_audio_subsystem(config_table); if (INIT_AUDIO_SYSTEM_OK != rc) { /* * Don't exit just because we can't output audio. The audio code will * handle this case. */ DT_DEBUG_LOG("Audio subsystem could not be initialised\n"); } else { DT_DEBUG_LOG("Audio subsystem created and initialized\n"); } /* * Initialise the opengl components of the screen. */ rc = init_gl(screen); if (GL_INIT_OK != rc) { game_exit("Could not do opengl initialisation."); } DT_DEBUG_LOG("OpenGL setup complete\n"); /* * TODO: Proper font management system where more than one font can be loaded * * Create the font object that is going to be used to write text throughout * the game. */ rc = create_font("..\\..\\resources\\Fonts\\LucidaSansRegular.ttf", &font, 30, TTF_STYLE_NORMAL, white); if (BUILD_FONT_OK != rc) { game_exit("Could not load up LucidaSansRegular font."); } DT_DEBUG_LOG("Lucida sans regular font loaded\n"); /* * TODO: Constants to move from here. * * Create a new match state object before starting the game loop. */ match_state = create_match_state(15, 60 * 60, disc_graphic_file, grass_tile_file, o_xml_file, d_xml_file, create_o_automaton_states, create_automaton_events); if (NULL == match_state) { game_exit("Failed to create match state."); } init_pitch(match_state->pitch); DT_DEBUG_LOG("Match state created and initialized\n"); /* * Scale the pitch by an arbitrary amount to account for the otherwise small * scaling. */ scale_camera(match_state->camera_handler, 10.0f); /* * Load the animation data. */ rc = load_animation_data(match_state->animation_handler); if (LOAD_ANIMATION_DATA_OK != rc) { game_exit("Failed to load animation data."); } DT_DEBUG_LOG("Animation data loaded\n"); /* * Initialise the timings */ last_physics_update = SDL_GetTicks(); last_ai_update = SDL_GetTicks(); /* * Initialise and start a new match. */ start_match(match_state); // @@@DAT testing throw_multi_player_ai_event_by_name(match_state->teams, match_state->players_per_team, match_state->teams[0]->players[0]->automaton, AUTOMATON_EVENT_PULL_THROWN); /* * Game loop */ while(true) { /* * Frame time is tracked so that we can determine how long to wait before * displaying the next frame. i.e. to fix the FPS. */ frame_start_time = SDL_GetTicks(); /* * Look at disc */ look_at_location(match_state->camera_handler, match_state->disc->position.x, match_state->disc->position.y, screen); /* * While there are events to process, do so. */ while(SDL_PollEvent(&transient_event)) { /* * First check whether it is an SDL_QUIT event. If so then exit with * message. */ if (transient_event.type == SDL_QUIT) { destroy_match_state(match_state); game_exit("User requested exit via SDL_QUIT event."); } else if ((transient_event.type == SDL_KEYDOWN) || (transient_event.type == SDL_KEYUP)) { /* * The event was the user either depressing or releasing a key so call * to the keyboard event handler to deal with the event. */ handle_keyboard_event(&(transient_event.key), transient_event.type, match_state, screen); } else if ((transient_event.type == SDL_MOUSEBUTTONDOWN) || (transient_event.type == SDL_MOUSEBUTTONUP)) { /* * The event was the user either depressing or releasing a mouse button * so pass to the mouse button event handler to deal with it. This * includes the mouse wheel moving. */ handle_mousebutton_event(&(transient_event.button), match_state); } } /* * Perform an update on all the ai objects. */ ai_time_delta = SDL_GetTicks() - last_ai_update; process_all_player_ai(match_state->teams, match_state->players_per_team, ai_time_delta); last_ai_update = SDL_GetTicks(); /* * Process the automaton timed event queue to see if any events need to be * popped. */ pop_all_timed_events(match_state->automaton_handler->timed_event_queue, SDL_GetTicks(), match_state); /* * Do physics processing. This updates the positions of all moving entities * in the game. * * WARNING - If this takes longer than the amount of time allocated per * frame then there might be 'interesting' problems in the frame refresh. */ physics_time_delta = SDL_GetTicks() - last_physics_update; calculate_positions(match_state, physics_time_delta); last_physics_update = SDL_GetTicks(); /* * Having moved all of the objects to their new positions we need to * detect collisions and verify the new locations. * * At the end of this function the positions of all objects will have been * updated. */ detect_and_handle_collisions(match_state->teams, match_state->players_per_team, match_state->disc); /* * Update the camera object. */ update_camera_position(match_state); /* * TODO: Is this management of animations sufficient? * * Update the animation frame counters. */ if (SDL_GetTicks() - last_animation_update >= animation_ms_per_frame) { last_animation_update = SDL_GetTicks(); for (ii = 0; ii < match_state->players_per_team; ii++) { increment_animation_frame_counter(match_state->teams[0]->players[ii], match_state->animation_handler); increment_animation_frame_counter(match_state->teams[1]->players[ii], match_state->animation_handler); } } /* * If the frame has taken less than the maximum allowed amount of time to * render then delay the screen update. */ frame_time_taken_ms = SDL_GetTicks() - frame_start_time; if (frame_time_taken_ms < ms_per_frame) { SDL_Delay(ms_per_frame - frame_time_taken_ms); } /* * Redraw the screen. */ redraw_screen(screen, match_state, font); } return(0); }
static bool rootwin_init(WRootWin *rootwin, int xscr) { Display *dpy=ioncore_g.dpy; WFitParams fp; Window root; WScreen *scr; /* Try to select input on the root window */ root=RootWindow(dpy, xscr); redirect_error=FALSE; XSetErrorHandler(my_redirect_error_handler); XSelectInput(dpy, root, IONCORE_EVENTMASK_ROOT); XSync(dpy, 0); XSetErrorHandler(my_error_handler); if(redirect_error){ warn(TR("Unable to redirect root window events for screen %d." "Maybe another window manager is running?"), xscr); return FALSE; } rootwin->xscr=xscr; rootwin->default_cmap=DefaultColormap(dpy, xscr); rootwin->tmpwins=NULL; rootwin->tmpnwins=0; rootwin->dummy_win=None; rootwin->xor_gc=None; fp.mode=REGION_FIT_EXACT; fp.g.x=0; fp.g.y=0; fp.g.w=DisplayWidth(dpy, xscr); fp.g.h=DisplayHeight(dpy, xscr); if(!window_do_init((WWindow*)rootwin, NULL, &fp, root, "WRootWin")){ return FALSE; } ((WWindow*)rootwin)->event_mask=IONCORE_EVENTMASK_ROOT; ((WRegion*)rootwin)->flags|=REGION_BINDINGS_ARE_GRABBED|REGION_PLEASE_WARP; ((WRegion*)rootwin)->rootwin=rootwin; REGION_MARK_MAPPED(rootwin); scan_initial_windows(rootwin); create_wm_windows(rootwin); preinit_gr(rootwin); netwm_init_rootwin(rootwin); region_add_bindmap((WRegion*)rootwin, ioncore_screen_bindmap); scr=create_screen(rootwin, &fp, xscr); if(scr==NULL){ return FALSE; } region_set_manager((WRegion*)scr, (WRegion*)rootwin); region_map((WRegion*)scr); LINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rootwin, p_next, p_prev); ioncore_screens_updated(rootwin); xwindow_set_cursor(root, IONCORE_CURSOR_DEFAULT); return TRUE; }