void route_keyupdate (void *routeglob, ChimeraHost * me) { RouteGlobal *rg = (RouteGlobal *) routeglob; rg->me = me; sprintf (rg->keystr, "%s", get_key_string (&rg->me->key)); }
void printTable (ChimeraState * state) { int i, j, k; RouteGlobal *routeglob = (RouteGlobal *) state->route; /* print the table */ fprintf (stderr, "------------------------------- TABLE-------------------------------\n"); for (i = 0; i < MAX_ROW; i++) { for (j = 0; j < MAX_COL; j++) { for (k = 0; k < MAX_ENTRY; k++) if (routeglob->table[i][j][k] != NULL) fprintf (stderr, "%s ", get_key_string (&routeglob-> table[i][j][k]->key)); else fprintf (stderr, "00000000 00000000 00000000 00000000 00000000"); } fprintf (stderr, "\n"); } fprintf (stderr, "----------------------------------------------------------------------\n"); }
static void draw_mark_filter(void) { int screen_x=0; int screen_y=0; // display the Mark filter title glColor3f(1.0f,1.0f,0.0f); screen_x = 25 - 1.5*strlen(label_mark_filter); screen_y = 150 + 22; draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_mark_filter, 1, 0.3); // if filtering marks, display the label and the current filter text if (mark_filter_active) { char * show_mark_filter_text; int max_show_len = 15; if (strlen(mark_filter_text) > max_show_len) show_mark_filter_text = &mark_filter_text[strlen(mark_filter_text)-max_show_len]; else if (strlen(mark_filter_text) == 0) show_mark_filter_text = "_"; else show_mark_filter_text = mark_filter_text; screen_x = 25 - 1.5*strlen(show_mark_filter_text); screen_y = 150 + 29; draw_string_zoomed(screen_x, screen_y, (unsigned char*)show_mark_filter_text, 1, 0.3); } // display which key to activate the filter else { char buf[20]; get_key_string(K_MARKFILTER, buf, sizeof(buf)); draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 29, (const unsigned char *)buf, 1, 0.3); } }
void leafset_print (ChimeraState * state) { int i; int Lsize, Rsize; RouteGlobal *routeglob = (RouteGlobal *) state->route; Lsize = leafset_size (routeglob->leftleafset); Rsize = leafset_size (routeglob->rightleafset); fprintf (stderr, "LEFT: "); for (i = 0; i < Lsize; i++) fprintf (stderr, "%s ", get_key_string (&routeglob->leftleafset[i]->key)); fprintf (stderr, "\nRIGHT: "); for (i = 0; i < Rsize; i++) fprintf (stderr, "%s ", get_key_string (&routeglob->rightleafset[i]->key)); fprintf (stderr, "\n"); }
int btree_index::handler_to_inv_idx(const handler& query) { get_key_string(query); data_t k(v_static_key.get(), v_static_key.size()); if ( v_idx_agent_ptr -> member(k) == false ) throw(stringException("first_of_invlist(): key is not in btree")); return int(k.dt); }
void route_update (ChimeraState * state, ChimeraHost * host, int joined) { int i, j, k, found, pick; ChimeraHost *tmp, *deleted = NULL, *added = NULL; RouteGlobal *routeglob = (RouteGlobal *) state->route; pthread_mutex_lock (&routeglob->lock); if (key_equal (routeglob->me->key, host->key)) { pthread_mutex_unlock (&routeglob->lock); return; } i = key_index (state->log, routeglob->me->key, host->key); j = hexalpha_to_int (get_key_string (&host->key)[i]); /*join */ if (joined) { found = 0; for (k = 0; k < MAX_ENTRY; k++) { if (routeglob->table[i][j][k] == NULL) { routeglob->table[i][j][k] = host_get (state, host->name, host->port); leafset_update (state, host, joined, &deleted, &added); found = 1; break; } else if (routeglob->table[i][j][k] != NULL && key_equal (routeglob->table[i][j][k]->key, host->key)) { pthread_mutex_unlock (&routeglob->lock); return; } } /* the entry array is full we have to get rid of one */ /* replace the new node with the node with the highest latncy in the entry array */ if (!found) { pick = 0; for (k = 1; k < MAX_ENTRY; k++) { if (routeglob->table[i][j][pick]->success_avg > routeglob->table[i][j][k]->success_avg) pick = k; } host_release (state, routeglob->table[i][j][pick]); routeglob->table[i][j][pick] = host_get (state, host->name, host->port); leafset_update (state, host, joined, &deleted, &added); } } /*delete */ else { for (k = 0; k < MAX_ENTRY; k++) if (routeglob->table[i][j][k] != NULL && key_equal (routeglob->table[i][j][k]->key, host->key)) { host_release (state, routeglob->table[i][j][k]); routeglob->table[i][j][k] = NULL; break; } leafset_update (state, host, joined, &deleted, &added); } if (deleted != NULL) { leafset_range_update (routeglob, &(routeglob->Rrange), &(routeglob->Lrange)); chimera_update_upcall (state, &(deleted->key), deleted, 0); } if (added != NULL) { leafset_range_update (routeglob, &(routeglob->Rrange), &(routeglob->Lrange)); chimera_update_upcall (state, &(added->key), added, 1); } pthread_mutex_unlock (&routeglob->lock); fflush (stderr); }
void draw_game_map (int map, int mouse_mini) { int screen_x=0; int screen_y=0; int x=-1,y=-1; float x_size=0,y_size=0; GLuint map_small, map_large; actor *me; static int fallback_text = -1; // if we don't have a continent texture (instance may be), fallback to blank paper if (cont_text < 0) { if (fallback_text < 0) #ifdef NEW_TEXTURES { fallback_text = load_texture_cached("./textures/paper1", tt_gui); } #else /* NEW_TEXTURES */ fallback_text = load_texture_cache ("./textures/paper1.bmp", 0); #endif /* NEW_TEXTURES */ cont_text = fallback_text; } if(map){ #ifdef NEW_TEXTURES map_small = cont_text; #else /* NEW_TEXTURES */ map_small=get_texture_id(cont_text); #endif /* NEW_TEXTURES */ if(inspect_map_text == 0) { map_large=map_text; } else { map_large = inspect_map_text; } } else { map_small=map_text; #ifdef NEW_TEXTURES map_large = cont_text; #else /* NEW_TEXTURES */ map_large=get_texture_id(cont_text); #endif /* NEW_TEXTURES */ if(cur_map!=-1){ x_size = ((float)(continent_maps[cur_map].x_end - continent_maps[cur_map].x_start)) / tile_map_size_x; y_size = ((float)(continent_maps[cur_map].y_end - continent_maps[cur_map].y_start)) / tile_map_size_y; } else { x_size=y_size=0; } } glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(300, (GLdouble)0, (GLdouble)0, 200, -250.0, 250.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(300, 0); glVertex2i(300, 200); glVertex2i(0, 200); glEnd(); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); #ifdef NEW_TEXTURES bind_texture(map_large); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3i(50,0,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(50,200,0); glTexCoord2f(0.0f, 0.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(250,0,0); glEnd(); #else /* NEW_TEXTURES */ bind_texture_id(map_large); glBegin(GL_QUADS); glTexCoord2f(1.0f,0.0f); glVertex3i(50,0,0); glTexCoord2f(1.0f,1.0f); glVertex3i(50,200,0); glTexCoord2f(0.0f,1.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f,0.0f); glVertex3i(250,0,0); glEnd(); #endif /* NEW_TEXTURES */ if (mouse_mini) glColor4f (1.0f, 1.0f, 1.0f, 1.0f); else glColor4f (0.7f, 0.7f, 0.7f, 0.7f); glEnable(GL_ALPHA_TEST); #ifdef NEW_TEXTURES bind_texture(map_small); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3i(250,150,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f, 0.0f); glVertex3i(300,200,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(300,150,0); glEnd(); #else /* NEW_TEXTURES */ bind_texture_id(map_small); glBegin(GL_QUADS); glTexCoord2f(1.0f,0.0f); glVertex3i(250,150,0); glTexCoord2f(1.0f,1.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f,1.0f); glVertex3i(300,200,0); glTexCoord2f(0.0f,0.0f); glVertex3i(300,150,0); glEnd(); #endif /* NEW_TEXTURES */ glDisable(GL_ALPHA_TEST); glColor3f(1.0f,1.0f,1.0f); #ifdef NEW_TEXTURES bind_texture(legend_text); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3i(250,50,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(250,150,0); glTexCoord2f(0.0f, 0.0f); glVertex3i(300,150,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(300,50,0); glEnd(); #else /* NEW_TEXTURES */ get_and_set_texture_id(legend_text); glBegin(GL_QUADS); glTexCoord2f(1.0f,0.0f); glVertex3i(250,50,0); glTexCoord2f(1.0f,1.0f); glVertex3i(250,150,0); glTexCoord2f(0.0f,1.0f); glVertex3i(300,150,0); glTexCoord2f(0.0f,0.0f); glVertex3i(300,50,0); glEnd(); #endif /* NEW_TEXTURES */ // this is necessary for the text over map // need to execute this for any map now // because of the coordinate display - Lachesis if(map/*&&(adding_mark||max_mark>0)*/){ glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho((GLdouble)0, (GLdouble)300, (GLdouble)200, (GLdouble)0, -250.0, 250.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // Draw help for toggling the mini-map { char buf[80]; char keybuf[20]; glEnable(GL_TEXTURE_2D); safe_snprintf(buf, sizeof(buf), "%s %s", win_minimap, get_key_string(K_MINIMAP, keybuf, sizeof(keybuf))); glColor3f (1.0f, 1.0f, 0.0f); draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 43, (const unsigned char *)buf, 1, 0.3); } // draw a temporary mark until the text is entered if (adding_mark) { int x = mark_x; int y = mark_y; screen_x=(51+200*x/(tile_map_size_x*6)); screen_y=201-200*y/(tile_map_size_y*6); glColor3f(1.0f,1.0f,0.0f); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom); glEnd(); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,0.0f); draw_string_zoomed (screen_x, screen_y, (unsigned char*)input_text_line.data, 1, mapmark_zoom); } draw_mark_filter(); if(inspect_map_text == 0) { draw_marks(marks, max_mark, tile_map_size_x, tile_map_size_y); draw_coordinates(tile_map_size_x, tile_map_size_y); } else { draw_marks(temp_marks, max_temp_mark, temp_tile_map_size_x, temp_tile_map_size_y); draw_coordinates(temp_tile_map_size_x, temp_tile_map_size_y); } } //if we're following a path, draw the destination on the map if (pf_follow_path && inspect_map_text == 0) { int px = pf_dst_tile->x; int py = pf_dst_tile->y; if (!map) { if (cur_map!=-1) { screen_x = 300 - (50 + 200 * ( (px * x_size / 6) + continent_maps[cur_map].x_start) / 512); screen_y = 200 * ( (py * y_size / 6) + continent_maps[cur_map].y_start) / 512; } else { screen_x = screen_y = 0; } } else { screen_x=51 +200*px/(tile_map_size_x*6); screen_y=201-200*py/(tile_map_size_y*6); } glColor3f(1.0f,0.0f,0.0f); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom); glEnd(); } //ok, now let's draw our possition... if ( (me = get_our_actor ()) != NULL && inspect_map_text == 0) { x = me->x_tile_pos; y = me->y_tile_pos; } else { //We don't exist (usually happens when teleporting) x = -1; y = -1; } if (!map) { if (cur_map != -1) { screen_x = 300 - (50 + 200 * ( (x * x_size / 6) + continent_maps[cur_map].x_start) / 512); screen_y = 200 * ( (y * y_size / 6) + continent_maps[cur_map].y_start) / 512; } else { screen_x = screen_y = 0; } } else { screen_x=51 +200*x/(tile_map_size_x*6); screen_y=201-200*y/(tile_map_size_y*6); } if ( (map || !dungeon) && x != -1 ) { glColor3f (0.0f, 0.0f, 1.0f); glDisable (GL_TEXTURE_2D); glBegin (GL_LINES); glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom); glEnd(); } if(!map && show_continent_map_boundaries && cont_text!=fallback_text) { int i; /* Convert mouse coordinates to map coordinates (stolen from pf_get_mouse_position()) */ int min_mouse_x = (window_width-hud_x)/6; int min_mouse_y = 0; int max_mouse_x = min_mouse_x+((window_width-hud_x)/1.5); int max_mouse_y = window_height - hud_y; int screen_map_width = max_mouse_x - min_mouse_x; int screen_map_height = max_mouse_y - min_mouse_y; int m_px = ((mouse_x-min_mouse_x) * 512) / screen_map_width; int m_py = 512 - ((mouse_y * 512) / screen_map_height); int mouse_over = -1; glColor3f (0.267f, 0.267f, 0.267f); glDisable (GL_TEXTURE_2D); glBegin(GL_LINES); /* Draw borders for the maps except the one with the mouse over it */ glColor3f (0.267f, 0.267f, 0.267f); for(i = 0; continent_maps[i].name != NULL; i++) { if(continent_maps[i].cont == continent_maps[cur_map].cont) { if(!mouse_mini && mouse_over == -1 && m_px > continent_maps[i].x_start && m_px < continent_maps[i].x_end && m_py > continent_maps[i].y_start && m_py < continent_maps[i].y_end) { /* Mouse over this map */ mouse_over = i; } else { int x_start = 300-(50+200*continent_maps[i].x_start/512); int x_end = 300-(50+200*continent_maps[i].x_end/512); int y_start = 200*continent_maps[i].y_start / 512; int y_end = 200*continent_maps[i].y_end / 512; glVertex2i(x_start, y_start); glVertex2i(x_start, y_end); glVertex2i(x_start, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_start); glVertex2i(x_end, y_start); glVertex2i(x_start, y_start); } } } /* Draw border for the map with the mouse over it */ if(mouse_over >= 0) { float flash_effect_colour = 0.90f - sin((float)SDL_GetTicks()/100.0f) / 10.0f; int x_start = 300-(50+200*continent_maps[mouse_over].x_start/512); int x_end = 300-(50+200*continent_maps[mouse_over].x_end/512); int y_start = 200*continent_maps[mouse_over].y_start / 512; int y_end = 200*continent_maps[mouse_over].y_end / 512; glColor3f(flash_effect_colour, flash_effect_colour, flash_effect_colour); glVertex2i(x_start, y_start); glVertex2i(x_start, y_end); glVertex2i(x_start, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_start); glVertex2i(x_end, y_start); glVertex2i(x_start, y_start); } glEnd(); } #ifdef DEBUG_MAP_SOUND // If we are in map view (not continent view) draw the sound area boundaries if (map) { print_sound_boundaries(cur_tab_map); } #endif // DEBUG_MAP_SOUND if (map) { glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } glEnable (GL_TEXTURE_2D); glColor3f (1.0f, 1.0f, 1.0f); glMatrixMode (GL_MODELVIEW); glPopMatrix (); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }