t_screen *screen_clone(t_screen *screen) { if(screen) { t_screen *clone = screen_new(screen->id.name); clone->is_active = screen->is_active; clone->is_visible = screen->is_visible; clone->always_active = screen->always_active; clone->always_visible = screen->always_visible; clone->width = screen->width; clone->height = screen->height; clone->zoom = screen->zoom; clone->pan_x = screen->pan_x; clone->pan_y = screen->pan_y; clone->blocks = list_clone(screen->blocks, dt_block); clone->viewports = list_clone(screen->viewports, dt_viewport); clone->draw = screen->draw; clone->keymap = screen->keymap; return clone; } else { return NULL; } }
static screen_t * screen_add(lua_State *L, screen_array_t *screens) { screen_t *new_screen = screen_new(L); luaA_object_ref(L, -1); screen_array_append(screens, new_screen); return new_screen; }
bool swc_drm_create_screens(struct wl_list * screens) { drmModeRes * resources; drmModeConnector * connector; uint32_t index; struct swc_output * output; uint32_t taken_crtcs = 0; if (!(resources = drmModeGetResources(swc.drm->fd))) { ERROR("Could not get DRM resources\n"); return false; } for (index = 0; index < resources->count_connectors; ++index, drmModeFreeConnector(connector)) { connector = drmModeGetConnector(swc.drm->fd, resources->connectors[index]); if (connector->connection == DRM_MODE_CONNECTED) { uint32_t crtc_index; uint32_t id; if (!find_available_crtc(resources, connector, taken_crtcs, &crtc_index)) { WARNING("Could not find CRTC for connector %u\n", index); continue; } if (!find_available_id(&id)) { WARNING("No more available output IDs\n"); drmModeFreeConnector(connector); break; } if (!(output = swc_output_new(connector))) continue; output->screen = screen_new(resources->crtcs[crtc_index], output); output->screen->id = id; taken_crtcs |= 1 << crtc_index; drm.taken_ids |= 1 << id; wl_list_insert(screens, &output->screen->link); } } drmModeFreeResources(resources); return true; }
void screen_init(void) { struct geo g; SLIST_INIT(&W->h.screen); #ifdef HAVE_XINERAMA XineramaScreenInfo *xsi; int i, n = 0; if(XineramaIsActive(W->dpy)) { xsi = XineramaQueryScreens(W->dpy, &n); for(i = 0; i < n; ++i) { g.x = xsi[i].x_org; g.y = xsi[i].y_org; g.w = xsi[i].width; g.h = xsi[i].height; screen_new(&g, i); } W->nscreen = n; XFree(xsi); } else #endif /* HAVE_XINERAMA */ { g.x = g.y = 0; g.w = DisplayWidth(W->dpy, W->xscreen); g.h = DisplayHeight(W->dpy, W->xscreen); screen_new(&g, 0); W->nscreen = 1; } }
/* Ready a game structure for actual use: */ void game_finalize(GameData *gd) { Level *lvl; TankList *tl; DrawBuffer *b; PList *pl; Screen *s; ASSERT_CONFIG(); /* Initialize most of the structures: */ s = screen_new (gd->data.config.is_fullscreen); pl = plist_new (); b = drawbuffer_new(gd->data.config.w, gd->data.config.h); lvl = level_new (b, gd->data.config.w, gd->data.config.h); tl = tanklist_new (lvl, pl); /* Generate our random level: */ generate_level(lvl, gd->data.config.gen); level_decorate(lvl); level_make_bases(lvl); /* Debug the starting data, if we're debugging: */ if(gd->is_debug) level_dump_bmp(lvl, "debug_start.bmp"); /* Start drawing! */ drawbuffer_set_default(b, color_rock); level_draw_all(lvl, b); screen_set_mode_level(s, b); /* Set up the players/GUI: */ if (gd->data.config.player_count == 1) init_single_player(s, tl, lvl); else if(gd->data.config.player_count == 2) init_double_player(s, tl, lvl); else { ERR_OUT("Don't know how to draw more than 2 players at once..."); exit(1); } /* Copy all of our variables into the GameData struct: */ gd->is_active = 1; gd->data.active.s = s; gd->data.active.pl = pl; gd->data.active.b = b; gd->data.active.lvl = lvl; gd->data.active.tl = tl; }
VTermScreen *vterm_obtain_screen(VTerm *vt) { if(!vt->screen) vt->screen = screen_new(vt); return vt->screen; }
GAME * game_init () { if (!al_init ()) { fprintf (stderr, "Failed to initialize Allegro.\n"); return NULL; } if (!al_init_image_addon ()) { fprintf (stderr, "Failed to initialize image addon.\n"); return NULL; } if (!al_install_keyboard ()) { fprintf (stderr, "Failed to install keyboard.\n"); return NULL; } al_init_font_addon (); if (!al_init_ttf_addon ()) { fprintf (stderr, "Failed to initialize ttf addon.\n"); return NULL; } if (!al_init_primitives_addon ()) { fprintf (stderr, "Failed to initialize primitives addon.\n"); return NULL; } GAME *game = al_malloc (sizeof (GAME)); if (!game) return NULL; srand (time (NULL)); game->running = true; game->paused = false; game->fullscreen = 1; game->windowed = 1; game->rrate = 60; game->suggest_vsync = 1; game->force_vsync = 0; game->current_npc = NULL; game->screen = screen_new (); char *filename; const char *str; filename = get_resource_path_str ("data/game.ini"); ALLEGRO_CONFIG *game_config = al_load_config_file (filename); al_free (filename); str = al_get_config_value (game_config, "", "org"); al_set_org_name (str); str = al_get_config_value (game_config, "", "app"); al_set_app_name (str); ALLEGRO_PATH *settpath = al_get_standard_path (ALLEGRO_USER_SETTINGS_PATH); ALLEGRO_PATH *gcpath = al_clone_path (settpath); al_set_path_filename (gcpath, "general.ini"); const char * gcpath_str = al_path_cstr (gcpath, ALLEGRO_NATIVE_PATH_SEP); ALLEGRO_CONFIG *gconfig = al_load_config_file (gcpath_str); if (!gconfig) { gconfig = al_create_config (); al_make_directory (al_path_cstr (settpath, ALLEGRO_NATIVE_PATH_SEP)); set_config_i (gconfig, "display", "width", game->screen.width); set_config_i (gconfig, "display", "height", game->screen.height); set_config_i (gconfig, "display", "fullscreen", game->fullscreen); set_config_i (gconfig, "display", "windowed", game->windowed); set_config_i (gconfig, "display", "refreshrate", game->rrate); set_config_i (gconfig, "display", "suggest_vsync", game->suggest_vsync); set_config_i (gconfig, "display", "force_vsync", game->force_vsync); } else { get_config_i (gconfig, "display", "width", &game->screen.width); get_config_i (gconfig, "display", "height", &game->screen.height); get_config_i (gconfig, "display", "fullscreen", &game->fullscreen); get_config_i (gconfig, "display", "windowed", &game->windowed); get_config_i (gconfig, "display", "refreshrate", &game->rrate); get_config_i (gconfig, "display", "suggest_vsync", &game->suggest_vsync); get_config_i (gconfig, "display", "force_vsync", &game->force_vsync); } al_save_config_file (gcpath_str, gconfig); al_destroy_path (settpath); al_destroy_path (gcpath); al_destroy_config (gconfig); int flags = 0; if (game->fullscreen == game->windowed) flags |= ALLEGRO_FULLSCREEN_WINDOW; else if (game->fullscreen) flags |= ALLEGRO_FULLSCREEN; else flags |= ALLEGRO_WINDOWED; al_set_new_display_option (ALLEGRO_VSYNC, game->suggest_vsync, ALLEGRO_SUGGEST); al_set_new_display_option (ALLEGRO_DEPTH_SIZE, 8, ALLEGRO_SUGGEST); al_set_new_display_flags (flags); al_set_new_display_refresh_rate (game->rrate); game->display = al_create_display (game->screen.width, game->screen.height); if (!game->display) { fprintf (stderr, "Failed to create display.\n"); al_free (game); return NULL; } al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP); game->timer = al_create_timer (1.0 / FPS); if (!game->timer) { fprintf (stderr, "Failed to create timer.\n"); al_free (game); return NULL; } game->screen.width = al_get_display_width (game->display); game->screen.height = al_get_display_height (game->display); screen_update_size (&game->screen, game->screen.width, game->screen.height); game->rrate = al_get_display_refresh_rate (game->display); game->event_queue = al_create_event_queue (); if (!game->event_queue) { fprintf (stderr, "Failed to create event queue.\n"); al_free (game); return NULL; } al_register_event_source (game->event_queue, al_get_display_event_source (game->display)); al_register_event_source (game->event_queue, al_get_timer_event_source (game->timer)); al_set_render_state (ALLEGRO_ALPHA_FUNCTION, ALLEGRO_RENDER_EQUAL); al_set_render_state (ALLEGRO_ALPHA_TEST_VALUE, 1); filename = get_resource_path_str ("data/sprites.ini"); game->sprites = sprite_load_sprites (filename); al_free (filename); filename = get_resource_path_str ("data/scenes.ini"); game->scenes = scene_load_file (filename); scene_load_scenes (game->scenes, game->sprites); al_free (filename); str = al_get_config_value (game_config, "", "scene"); game->current_scene = scene_get (game->scenes, str); str = al_get_config_value (game_config, "", "actor"); game->current_actor = sprite_new_actor (game->sprites, str); str = al_get_config_value (game_config, "", "portal"); SCENE_PORTAL *portal = scene_get_portal (game->scenes, str); al_destroy_config (game_config); filename = get_resource_path_str ("data/ui.ini"); game->ui = ui_load_file (filename); al_free (filename); sprite_center (game->current_actor, &portal->position); screen_center (&game->screen, portal->position, game->current_scene->map); return game; }