void game::draw_interface(const DRAW_MODE_UI draw_mode a2e_unused, rtt::fbo* buffer) { const uint2 screen_size(buffer->width, buffer->height); switch(status.load()) { case GAME_STATUS::DEATH: draw_center_screen_tex(screen_size, death_tex, float4(1.0f, 0.0f, 0.0f, 0.5f)); break; case GAME_STATUS::MAP_LOAD: gfx2d::draw_rectangle_fill(rect(0, 0, screen_size.x, screen_size.y), float4(1.0f)); break; case GAME_STATUS::AI_PUSHED: case GAME_STATUS::OBJECT_SWAPPED: case GAME_STATUS::OBJECT_PUSHED: case GAME_STATUS::OBJECT_SELECTED: case GAME_STATUS::OBJECT_SELECTED_FINISHED: // selected object will be drawn by the geometry-render method default: { // draw health overlay const float cur_health = get_health(); if(cur_health < 100.0f) { const float4 health_background(1.0f, 0.0f, 0.0f, (1.0f - (get_health() / 100.0f))); gfx2d::draw_rectangle_fill(rect(0, 0, screen_size.x, screen_size.y), health_background); } // draw crosshair draw_crosshair(screen_size); } break; } }
static void show_crosshair (gboolean paint_new_location) { render_priv *priv = gport->render_priv; GdkWindow *window = gtk_widget_get_window (gport->drawing_area); GtkStyle *style = gtk_widget_get_style (gport->drawing_area); gint x, y; static gint x_prev = -1, y_prev = -1; static GdkGC *xor_gc; static GdkColor cross_color; if (gport->crosshair_x < 0 || ghidgui->creating || !gport->has_entered) return; if (!xor_gc) { xor_gc = gdk_gc_new (window); gdk_gc_copy (xor_gc, style->white_gc); gdk_gc_set_function (xor_gc, GDK_XOR); gdk_gc_set_clip_origin (xor_gc, 0, 0); set_clip (priv, xor_gc); /* FIXME: when CrossColor changed from config */ ghid_map_color_string (Settings.CrossColor, &cross_color); } x = DRAW_X (gport->crosshair_x); y = DRAW_Y (gport->crosshair_y); gdk_gc_set_foreground (xor_gc, &cross_color); if (x_prev >= 0 && !paint_new_location) draw_crosshair (xor_gc, x_prev, y_prev); if (x >= 0 && paint_new_location) { draw_crosshair (xor_gc, x, y); x_prev = x; y_prev = y; } else x_prev = y_prev = -1; }
void ghid_screen_update (void) { render_priv *priv = gport->render_priv; GdkWindow *window = gtk_widget_get_window (gport->drawing_area); if (gport->pixmap == NULL) return; gdk_draw_drawable (window, priv->bg_gc, gport->pixmap, 0, 0, 0, 0, gport->width, gport->height); draw_crosshair (priv); }
gboolean ghid_drawing_area_expose_cb (GtkWidget *widget, GdkEventExpose *ev, GHidPort *port) { render_priv *priv = port->render_priv; GdkWindow *window = gtk_widget_get_window (gport->drawing_area); gdk_draw_drawable (window, priv->bg_gc, port->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); draw_crosshair (priv); return FALSE; }
static void draw(struct game_state *gs) { extern struct game_state *cur_state; extern struct game_state playback_state; glMatrixMode(GL_MODELVIEW); glPushMatrix(); set_modelview_matrix(); if (!settings.static_settings || settings.static_settings->background) draw_level_background(); if (cur_state != &playback_state && settings.control_type == CONTROL_HYBRID && ship_is_visible()) draw_crosshair(); if (inner_state.state != IS_LEVEL_CLEARED && inner_state.state != IS_LEVEL_TRANSITION && (inner_state.state != IS_WAVE_CLEARED || inner_state.tics < WAVE_CLEARED_TICS/2)) draw_arena_outline(cur_arena, 1, cur_arena->border_type); draw_explosions(); draw_particles(); if (ship_is_visible()) { draw_ship(); draw_missiles(); draw_bombs(); draw_lasers(); draw_foes(); draw_powerups(); } draw_in_game_texts(); draw_text(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void ghid_show_crosshair (gboolean show) { gint x, y; static gint x_prev = -1, y_prev = -1; static gboolean draw_markers, draw_markers_prev = FALSE; static GdkGC *xor_gc; static GdkColor cross_color; if (gport->x_crosshair < 0 || ghidgui->creating || !gport->has_entered) return; if (!xor_gc) { xor_gc = gdk_gc_new (ghid_port.drawing_area->window); gdk_gc_copy (xor_gc, ghid_port.drawing_area->style->white_gc); gdk_gc_set_function (xor_gc, GDK_XOR); /* FIXME: when CrossColor changed from config */ ghid_map_color_string (Settings.CrossColor, &cross_color); } x = DRAW_X (gport->x_crosshair); y = DRAW_Y (gport->y_crosshair); gdk_gc_set_foreground (xor_gc, &cross_color); if (x_prev >= 0) { draw_crosshair (xor_gc, x_prev, y_prev); if (draw_markers_prev) { gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, 0, y_prev - VCD, VCD, VCW); gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, gport->width - VCD, y_prev - VCD, VCD, VCW); gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, x_prev - VCD, 0, VCW, VCD); gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, x_prev - VCD, gport->height - VCD, VCW, VCD); } } if (x >= 0 && show) { draw_crosshair (xor_gc, x, y); draw_markers = ghidgui->auto_pan_on && have_crosshair_attachments (); if (draw_markers) { gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, 0, y - VCD, VCD, VCW); gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, gport->width - VCD, y - VCD, VCD, VCW); gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, x - VCD, 0, VCW, VCD); gdk_draw_rectangle (gport->drawing_area->window, xor_gc, TRUE, x - VCD, gport->height - VCD, VCW, VCD); } x_prev = x; y_prev = y; draw_markers_prev = draw_markers; } else { x_prev = y_prev = -1; draw_markers_prev = FALSE; } }
void on_draw() override { al_draw_rectangle(0, 0, place.size.x, place.size.y, color, 4.0); if (mouse_over) draw_crosshair(local_mouse_x, local_mouse_y, color, 30); }
int main(int argc, char *argv[]) { byte keypress; client_init(); if( argc > 1 ) /* Command line arguments */ handle_cl_args(argc, argv); srand( time(NULL) ); calc_lookup_tables(DEGREES); win_init(); entity_init(); if( (ent_img_loaded = (char *)malloc(num_entity_types)) == NULL ) { perror("Malloc"); ERR_QUIT("Error allocating ent_img_loaded array", 1); } else { memset(ent_img_loaded, 0, num_entity_types); } /* Load client preferences from file */ read_config_file( &client ); /* Set view dimensions, which are calculated by tile width & heights */ client.view_w = client.x_tiles * TILE_W; client.view_h = client.y_tiles * TILE_H; /* What the client WISHES their dimensions were (this may not be what it actually is, ie in demo's etc */ client.desired_w = client.view_w; client.desired_h = client.view_h; weapon_type_init(); particle_init(); menu_init(); cl_network_init(); client.state = MENU; if( client.demo == DEMO_PLAY ) { cl_network_connect(NULL, 42); client.state = GAME_LOAD; } for( ; ; ) { switch( client.state ) { case MENU: win_ungrab_pointer(); menu_driver(); break; case GAME_LOAD: win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H); wait_till_expose(5); /* Finished loading, we are ready to play */ cl_change_map(client.map, client.gamemode); break; case GAME_RESUME: /* Resume game from menu */ win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H); wait_till_expose(5); input_clear(); draw_status_bar(); cl_netmsg_send_ready(); /* Tell server new details */ cl_net_finish(); /* Send the NETMSG_READY to the server */ client.state = GAME_JOIN; break; case GAME_JOIN: win_set_cursor( client.mousemode!=MOUSEMODE_ROTATE ); win_set_cursor( 1 ); if( client.mousemode ) { win_grab_pointer(); } text_buf_clear(); particle_clear(); case GAME_PLAY: cl_net_update(); if( client.state == GAME_PLAY ) { /* Maybe changed in net_update */ draw_crosshair( my_entity ); if( client.map_target_active ) draw_map_target( my_entity ); text_buf_update(); if( client.netstats ) cl_net_stats(); win_update(); /* Keyboard Input */ client.dir = my_entity.dir; keypress = get_input(); cl_netmsg_send_cl_update(keypress, client.dir); } cl_net_finish(); /* Send things that need sending */ cap_fps(client.fps); break; case QUIT: game_close(); image_close(); /* Free all the images */ win_close(); write_config_file(&client); if( ent_img_loaded != NULL ) free(ent_img_loaded); exit(EXIT_SUCCESS); break; } } return EXIT_SUCCESS; }
static int draw_proc(struct menu_item *item, struct menu_draw_params *draw_params) { static Gfx null_dl = gsSPEndDisplayList(); struct item_data *data = item->data; /* handle input */ if (!input_bind_held(COMMAND_PREVROOM) && !input_bind_held(COMMAND_NEXTROOM)) { uint16_t pad = input_pad(); if (pad & BUTTON_Z) { if (pad & BUTTON_D_UP) data->y += 50.f; if (pad & BUTTON_D_DOWN) data->y += -50.f; if (pad & BUTTON_D_LEFT) { data->x -= cos(data->yaw) * 50.f; data->z += sin(data->yaw) * 50.f; } if (pad & BUTTON_D_RIGHT) { data->x -= cos(data->yaw) * -50.f; data->z += sin(data->yaw) * -50.f; } } else { if (pad & BUTTON_D_UP) { data->x -= sin(data->yaw) * 50.f; data->z -= cos(data->yaw) * 50.f; } if (pad & BUTTON_D_DOWN) { data->x -= sin(data->yaw) * -50.f; data->z -= cos(data->yaw) * -50.f; } if (pad & BUTTON_D_LEFT) data->yaw += .2f; if (pad & BUTTON_D_RIGHT) data->yaw -= .2f; } } /* load resources */ if (data->state == STATE_LOAD) { /* initialize segment table */ z64_stab_t stab = z64_stab; /* load scene */ if (data->scene_index != data->scene_next || !data->scene_file) { if (data->scene_file) free(data->scene_file); data->scene_index = data->scene_next; data->room_index = -1; z64_scene_table_t *scene_entry = &z64_scene_table[data->scene_index]; uint32_t scene_vrom_start = scene_entry->scene_vrom_start; uint32_t scene_vrom_end = scene_entry->scene_vrom_end; uint32_t scene_vrom_size = scene_vrom_end - scene_vrom_start; data->scene_file = malloc(scene_vrom_size); zu_getfile(scene_vrom_start, data->scene_file, scene_vrom_size); } stab.seg[Z64_SEG_SCENE] = MIPS_KSEG0_TO_PHYS(data->scene_file); /* populate room list */ struct zu_file room_files[0x100]; zu_scene_rooms(zu_sr_header(data->scene_file, z64_file.scene_setup_index, &stab), room_files, 0x100, &data->n_rooms, &stab); /* load room */ if (data->room_index != data->room_next || !data->room_file) { if (data->room_file) { free(data->room_file); zu_mesh_destroy(&data->room_mesh); } data->room_index = data->room_next; uint32_t room_vrom_start = room_files[data->room_index].vrom_start; uint32_t room_vrom_end = room_files[data->room_index].vrom_end; uint32_t room_vrom_size = room_vrom_end - room_vrom_start; data->room_file = malloc(room_vrom_size); zu_getfile(room_vrom_start, data->room_file, room_vrom_size); stab.seg[Z64_SEG_ROOM] = MIPS_KSEG0_TO_PHYS(data->room_file); /* populate mesh */ zu_room_mesh(zu_sr_header(data->room_file, z64_file.scene_setup_index, &stab), &data->room_mesh, &stab); /* populate vertex list */ struct zu_vlist vlist; zu_vlist_init(&vlist); stab.seg[0x08] = MIPS_KSEG0_TO_PHYS(&null_dl); stab.seg[0x09] = MIPS_KSEG0_TO_PHYS(&null_dl); stab.seg[0x0A] = MIPS_KSEG0_TO_PHYS(&null_dl); stab.seg[0x0B] = MIPS_KSEG0_TO_PHYS(&null_dl); stab.seg[0x0C] = MIPS_KSEG0_TO_PHYS(&null_dl); stab.seg[0x0D] = MIPS_KSEG0_TO_PHYS(&null_dl); for (int i = 0; i < ZU_MESH_TYPES; ++i) for (int j = 0; j < data->room_mesh.all[i].size; ++j) zu_vlist_add_dl(&vlist, &stab, zu_seg_locate(&stab, data->room_mesh.all[i].dlists[j])); /* compute bounding box */ struct zu_bbox bbox; zu_vlist_bbox(&vlist, &bbox); /* set orientation */ { data->x = (bbox.x1 + bbox.x2) / 2.f; data->y = (bbox.y1 + bbox.y2) / 2.f; data->z = (bbox.z1 + bbox.z2) / 2.f; data->yaw = 0.f; } zu_vlist_destroy(&vlist); } /* proceed to rendering */ data->state = STATE_RENDER; } /* render room */ if (data->state == STATE_RENDER && data->room_file) { /* initialize rcp for rendering rooms */ static void *zbuf = NULL; if (!zbuf) zbuf = memalign(64, 2 * Z64_SCREEN_WIDTH * Z64_SCREEN_HEIGHT); gDisplayListAppend(&data->gfx.poly_opa.p, /* clear z buffer */ gsDPPipeSync(), gsDPSetCycleType(G_CYC_FILL), gsDPSetRenderMode(G_RM_NOOP, G_RM_NOOP2), gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, Z64_SCREEN_WIDTH, zbuf), gsDPSetFillColor((GPACK_ZDZ(G_MAXFBZ, 0) << 16) | GPACK_ZDZ(G_MAXFBZ, 0)), gsDPFillRectangle(0, 0, Z64_SCREEN_WIDTH - 1, Z64_SCREEN_HEIGHT - 1), gsDPPipeSync(), gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, Z64_SCREEN_WIDTH, ZU_MAKE_SEG(Z64_SEG_CIMG, 0)), gsDPSetDepthImage(zbuf), /* rsp settings */ gsSPSegment(Z64_SEG_SCENE, data->scene_file), gsSPSegment(Z64_SEG_ROOM, data->room_file), gsSPSegment(0x08, &null_dl), gsSPSegment(0x09, &null_dl), gsSPSegment(0x0A, &null_dl), gsSPSegment(0x0B, &null_dl), gsSPSegment(0x0C, &null_dl), gsSPSegment(0x0D, &null_dl), gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), /* rdp settings */ gsDPSetAlphaCompare(G_AC_NONE), gsDPSetDepthSource(G_ZS_PIXEL), gsDPSetAlphaDither(G_AD_DISABLE), gsDPSetColorDither(G_CD_DISABLE), gsDPSetCombineKey(G_OFF), gsDPSetTextureConvert(G_TC_FILT), gsDPSetTextureFilter(G_TF_BILERP), gsDPSetTextureLOD(G_TL_TILE), gsDPSetTexturePersp(G_TP_PERSP), gsDPSetCycleType(G_CYC_2CYCLE), gsDPPipelineMode(G_PM_NPRIMITIVE), gsDPSetEnvColor(0xFF, 0xFF, 0xFF, 0xFF), gsDPSetFogColor(0x00, 0x00, 0x00, 0x00), gsDPSetScissor(G_SC_NON_INTERLACE, 32, 32, Z64_SCREEN_WIDTH - 32, Z64_SCREEN_HEIGHT - 32), ); /* create projection matrix */ { Mtx m; MtxF mf; MtxF mt; guPerspectiveF(&mf, NULL, atanf(2.f), (float)Z64_SCREEN_WIDTH / (float)Z64_SCREEN_HEIGHT, 50.f, 5000.f, 1.f); { guScaleF(&mt, data->scale, data->scale, data->scale); guMtxCatF(&mt, &mf, &mf); } { guRotateF(&mt, M_PI / 6.f, 1.f, 0.f, 0.f); guMtxCatF(&mt, &mf, &mf); } { guTranslateF(&mt, 0.f, -100.f, -200.f); guMtxCatF(&mt, &mf, &mf); } { guRotateF(&mt, -data->yaw, 0.f, 1.f, 0.f); guMtxCatF(&mt, &mf, &mf); } { guTranslateF(&mt, -data->x, -data->y, -data->z); guMtxCatF(&mt, &mf, &mf); } guMtxF2L(&mf, &m); gSPMatrix(data->gfx.poly_opa.p++, gDisplayListData(&data->gfx.poly_opa.d, m), G_MTX_PROJECTION | G_MTX_LOAD); gSPMatrix(data->gfx.poly_xlu.p++, gDisplayListData(&data->gfx.poly_xlu.d, m), G_MTX_PROJECTION | G_MTX_LOAD); } /* create modelview matrix */ { Mtx m; guMtxIdent(&m); gSPMatrix(data->gfx.poly_opa.p++, gDisplayListData(&data->gfx.poly_opa.d, m), G_MTX_MODELVIEW | G_MTX_LOAD); gSPMatrix(data->gfx.poly_xlu.p++, gDisplayListData(&data->gfx.poly_xlu.d, m), G_MTX_MODELVIEW | G_MTX_LOAD); } /* configure lights */ zu_gfx_inject(&data->gfx); set_lighting(); /* execute scene config */ z64_scene_config_table[z64_scene_table[ z64_game.scene_index].scene_config](&z64_game); zu_gfx_restore(&data->gfx); /* draw scene */ for (int i = 0; i < ZU_MESH_TYPES; ++i) for (int j = 0; j < data->room_mesh.all[i].size; ++j) { if (i == ZU_MESH_OPA || i == ZU_MESH_NEAR) { gSPDisplayList(data->gfx.poly_opa.p++, data->room_mesh.all[i].dlists[j]); } else if (i == ZU_MESH_XLU || i == ZU_MESH_FAR) { gSPDisplayList(data->gfx.poly_xlu.p++, data->room_mesh.all[i].dlists[j]); } } /* draw actors */ if (z64_game.pause_state == 0) { zu_gfx_inject(&data->gfx); z64_DrawActors(&z64_game, &z64_game.actor_ctxt); zu_gfx_restore(&data->gfx); } /* draw additional stuff */ draw_crosshair(item); /* flush */ gfx_disp(gsSPDisplayList(zu_gfx_flush(&data->gfx))); /* restore rcp modes */ gfx_mode_init(); /* draw info */ gfx_mode_set(GFX_MODE_COLOR, GPACK_RGBA8888(0xC0, 0xC0, 0xC0, draw_params->alpha)); gfx_printf(draw_params->font, 36, 44, "scene %i", data->scene_index); gfx_printf(draw_params->font, 36, 44 + menu_get_cell_height(item->owner, 1), "room %i", data->room_index); } /* wait for rendering to finish before unloading */ if (data->state == STATE_UNLOAD) data->state = STATE_LOAD; return 1; }