static void cntr_array_add_back (cntr ca, void* object) { cntr_array* pca = (cntr_array*)ca; dbg_assert(pca->capacity >= pca->size); if (pca->capacity == pca->size) __expand_capacity(pca); pca->data[pca->size++] = object; }
static void* citer_local_get_ref(citer itr) { citer_cont* cur = (citer_cont*)itr; void** ele = (void**)cur->connection; dbg_assert(ele); return *ele; }
static void ch_generate_ddsg(FILE *in, FILE *ref, FILE *idx, FILE *ddsg) { GHashTable *hash=coord_hash_new(); struct item_bin *ib; int nodes=0,edges=0; while ((ib=read_item(in))) { int ccount=ib->clen/2; struct coord *c=(struct coord *)(ib+1); if (road_speed(ib->type)) { add_node_to_hash(idx, hash, &c[0], &nodes); add_node_to_hash(idx, hash, &c[ccount-1], &nodes); edges++; } } edge_hash=g_hash_table_new_full(edge_hash_hash, edge_hash_equal, edge_hash_slice_free, item_id_slice_free); fseek(in, 0, SEEK_SET); fprintf(ddsg,"d\n"); fprintf(ddsg,"%d %d\n", nodes, edges); while ((ib=read_item(in))) { int i,ccount=ib->clen/2; struct coord *c=(struct coord *)(ib+1); int n1,n2,speed=road_speed(ib->type); struct item_id road_id; double l; fread(&road_id, sizeof(road_id), 1, ref); if (speed) { struct edge_hash_item *hi=g_slice_new(struct edge_hash_item); struct item_id *id=g_slice_new(struct item_id); *id=road_id; dbg_assert((n1=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[0]))) != 0); dbg_assert((n2=GPOINTER_TO_INT(g_hash_table_lookup(hash, &c[ccount-1]))) != 0); l=0; for (i = 0 ; i < ccount-1 ; i++) { l+=sqrt(sq(c[i+1].x-c[i].x)+sq(c[i+1].y-c[i].y)); } fprintf(ddsg,"%d %d %d 0\n", n1-1, n2-1, (int)(l*36/speed)); hi->first=n1-1; hi->last=n2-1; g_hash_table_insert(edge_hash, hi, id); } } g_hash_table_destroy(hash); }
void CGraphics_Threaded::QuadsBegin() { dbg_assert(m_Drawing == 0, "called Graphics()->QuadsBegin twice"); m_Drawing = DRAWING_QUADS; QuadsSetSubset(0,0,1,1,-1); QuadsSetRotation(0); SetColor(1,1,1,1); }
int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2) { dbg_assert(r1->lu.x <= r1->rl.x); dbg_assert(r1->lu.y >= r1->rl.y); dbg_assert(r2->lu.x <= r2->rl.x); dbg_assert(r2->lu.y >= r2->rl.y); dbg(1,"0x%x,0x%x - 0x%x,0x%x vs 0x%x,0x%x - 0x%x,0x%x\n", r1->lu.x, r1->lu.y, r1->rl.x, r1->rl.y, r2->lu.x, r2->lu.y, r2->rl.x, r2->rl.y); if (r1->lu.x > r2->rl.x) return 0; if (r1->rl.x < r2->lu.x) return 0; if (r1->lu.y < r2->rl.y) return 0; if (r1->rl.y > r2->lu.y) return 0; return 1; }
static void _bind_self(worker_t *worker) { dbg_assert(worker); if (self && self != worker) { dbg_error("HPX does not permit worker structure switching.\n"); } self = worker; self->thread = pthread_self(); }
void CGraphics_OpenGL::QuadsBegin() { dbg_assert(m_Drawing == 0, "called quads_begin twice"); m_Drawing = DRAWING_QUADS; QuadsSetSubset(0,0,1,1); QuadsSetRotation(0); SetColor(1,1,1,1); }
void CEcon::Update() { if(!m_Ready) return; m_NetConsole.Update(); char aBuf[NET_MAX_PACKETSIZE]; int ClientID; while(m_NetConsole.Recv(aBuf, (int)(sizeof(aBuf))-1, &ClientID)) { dbg_assert(m_aClients[ClientID].m_State != CClient::STATE_EMPTY, "got message from empty slot"); if(m_aClients[ClientID].m_State == CClient::STATE_CONNECTED) { if(str_comp(aBuf, g_Config.m_EcPassword) == 0) { m_aClients[ClientID].m_State = CClient::STATE_AUTHED; m_NetConsole.Send(ClientID, "Authentication successful. External console access granted."); str_format(aBuf, sizeof(aBuf), "cid=%d authed", ClientID); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", aBuf); } else { m_aClients[ClientID].m_AuthTries++; char aMsg[128]; str_format(aMsg, sizeof(aMsg), "Wrong password %d/%d.", m_aClients[ClientID].m_AuthTries, MAX_AUTH_TRIES); m_NetConsole.Send(ClientID, aMsg); if(m_aClients[ClientID].m_AuthTries >= MAX_AUTH_TRIES) { if(!g_Config.m_EcBantime) m_NetConsole.Drop(ClientID, CLIENTDROPTYPE_KICK, "Too many authentication tries"); else m_NetConsole.NetBan()->BanAddr(m_NetConsole.ClientAddr(ClientID), g_Config.m_EcBantime*60, "Too many authentication tries"); } } } else if(m_aClients[ClientID].m_State == CClient::STATE_AUTHED) { char aFormatted[256]; str_format(aFormatted, sizeof(aFormatted), "cid=%d cmd='%s'", ClientID, aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aFormatted); m_UserClientID = ClientID; Console()->ExecuteLine(aBuf); m_UserClientID = -1; } } for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; ++i) { if(m_aClients[i].m_State == CClient::STATE_CONNECTED && time_get() > m_aClients[i].m_TimeConnected + g_Config.m_EcAuthTimeout * time_freq()) m_NetConsole.Drop(i, CLIENTDROPTYPE_KICK, "authentication timeout"); } }
static void data_seeds_init() { int i; int* seeds_random = (int*)malloc(sizeof(int) * g_op_count); int* seeds_inorder = (int*)malloc(sizeof(int) * g_op_count); g_seeds_inuse = (int*)malloc(sizeof(int) * g_op_count); for (i = 0; i < g_op_count; i ++) { seeds_random[i] = generate_in_range(g_pagesize_min, g_pagesize_max); seeds_inorder[i] = seeds_random[i]; } qsort(seeds_inorder, g_op_count, sizeof(int), cmpfunc); switch (g_page_pattern) { int index; case ht_pattern_unique: index = generate_in_range(0, g_op_count); for (i = 0; i < g_op_count; i ++) { g_seeds_inuse[i] = seeds_random[index]; } break; case ht_pattern_increasing: for (i = 0; i < g_op_count; i ++) { g_seeds_inuse[i] = seeds_inorder[i]; } break; case ht_pattern_decreasing: for (i = 0; i < g_op_count; i ++) { g_seeds_inuse[i] = seeds_inorder[g_op_count-1-i]; } break; case ht_pattern_jag: /* TODO: jag is not implemented, currently using random */ for (i = 0; i < g_op_count; i ++) { g_seeds_inuse[i] = seeds_random[i]; } case ht_pattern_random_restricted: dbg_assert(g_pagepattern_random_restricted_count < g_op_count); for (i = 0; i < g_op_count; i ++) { int index = generate_in_range(0, g_pagepattern_random_restricted_count); g_seeds_inuse[i] = seeds_inorder[index]; } case ht_pattern_random: for (i = 0; i < g_op_count; i ++) { g_seeds_inuse[i] = seeds_random[i]; } break; default: break; } free(seeds_random); free(seeds_inorder); }
void CGraphics_Threaded::SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight) { dbg_assert(m_Drawing != 0, "called Graphics()->SetColor without begin"); CColorVertex Array[4] = { CColorVertex(0, TopLeft.r, TopLeft.g, TopLeft.b, TopLeft.a), CColorVertex(1, TopRight.r, TopRight.g, TopRight.b, TopRight.a), CColorVertex(2, BottomRight.r, BottomRight.g, BottomRight.b, BottomRight.a), CColorVertex(3, BottomLeft.r, BottomLeft.g, BottomLeft.b, BottomLeft.a)}; SetColorVertex(Array, 4); }
void CGraphics_OpenGL::SetColor(float r, float g, float b, float a) { dbg_assert(m_Drawing != 0, "called gfx_quads_setcolor without begin"); CColorVertex Array[4] = { CColorVertex(0, r, g, b, a), CColorVertex(1, r, g, b, a), CColorVertex(2, r, g, b, a), CColorVertex(3, r, g, b, a)}; SetColorVertex(Array, 4); }
static void* cntr_array_remove_front(cntr ca) { cntr_array* pca = (cntr_array*)ca; void* obj = pca->data[0]; dbg_assert(pca->size > 0); pca->size --; memory_move((char*)(pca->data), (char*)(pca->data + 1), pca->size * sizeof(void*) / sizeof(char)); return obj; }
void CGraphics_Threaded::SetColor(float r, float g, float b, float a) { dbg_assert(m_Drawing != 0, "called Graphics()->SetColor without begin"); CColorVertex Array[4] = { CColorVertex(0, r, g, b, a), CColorVertex(1, r, g, b, a), CColorVertex(2, r, g, b, a), CColorVertex(3, r, g, b, a)}; SetColorVertex(Array, 4); }
void CGraphics_OpenGL::QuadsSetSubset(float TlU, float TlV, float BrU, float BrV) { dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsSetSubset without begin"); m_aTexture[0].u = TlU; m_aTexture[1].u = BrU; m_aTexture[0].v = TlV; m_aTexture[1].v = TlV; m_aTexture[3].u = TlU; m_aTexture[2].u = BrU; m_aTexture[3].v = BrV; m_aTexture[2].v = BrV; }
static void eoc_to_cpu(struct zip_eoc *eoc) { dbg_assert(eoc != NULL); eoc->zipesig = le32_to_cpu(eoc->zipesig); eoc->zipedsk = le16_to_cpu(eoc->zipedsk); eoc->zipecen = le16_to_cpu(eoc->zipecen); eoc->zipenum = le16_to_cpu(eoc->zipenum); eoc->zipecenn = le16_to_cpu(eoc->zipecenn); eoc->zipecsz = le32_to_cpu(eoc->zipecsz); eoc->zipeofst = le32_to_cpu(eoc->zipeofst); eoc->zipecoml = le16_to_cpu(eoc->zipecoml); }
static void event_sdl_watch_startthread(GPtrArray *watch_list) { dbg(lvl_debug, "enter\n"); if (sdl_watch_thread) event_sdl_watch_stopthread(); int ret; ret = pthread_create(&sdl_watch_thread, NULL, (void *) event_sdl_watch_thread, (void *) watch_list); dbg_assert(ret == 0); }
static void cntr_array_add_front (cntr ca, void* object) { cntr_array* pca = (cntr_array*)ca; dbg_assert(pca->capacity >= pca->size); if (pca->capacity == pca->size) __expand_capacity(pca); memory_move((char*)(pca->data + 1), (char*)(pca->data), pca->size * sizeof(void*) / sizeof(char)); pca->data[0] = object; pca->size ++; }
void CGraphics_OpenGL::SetColorVertex(const CColorVertex *pArray, int Num) { dbg_assert(m_Drawing != 0, "called gfx_quads_setcolorvertex without begin"); for(int i = 0; i < Num; ++i) { m_aColor[pArray[i].m_Index].r = pArray[i].m_R; m_aColor[pArray[i].m_Index].g = pArray[i].m_G; m_aColor[pArray[i].m_Index].b = pArray[i].m_B; m_aColor[pArray[i].m_Index].a = pArray[i].m_A; } }
void CGraphics_Threaded::SetColorVertex(const CColorVertex *pArray, int Num) { dbg_assert(m_Drawing != 0, "called Graphics()->SetColorVertex without begin"); for(int i = 0; i < Num; ++i) { m_aColor[pArray[i].m_Index].r = pArray[i].m_R; m_aColor[pArray[i].m_Index].g = pArray[i].m_G; m_aColor[pArray[i].m_Index].b = pArray[i].m_B; m_aColor[pArray[i].m_Index].a = pArray[i].m_A; } }
int CNetServer::Send(CNetChunk *pChunk) { if(pChunk->m_Flags&NETSENDFLAG_CONNLESS) { if(pChunk->m_DataSize >= NET_MAX_PAYLOAD) { dbg_msg("netserver", "packet payload too big. %d. dropping packet", pChunk->m_DataSize); return -1; } // send connectionless packet CNetBase::SendPacketConnless(m_Socket, &pChunk->m_Address, pChunk->m_pData, pChunk->m_DataSize); } else { if(pChunk->m_DataSize+NET_MAX_CHUNKHEADERSIZE >= NET_MAX_PAYLOAD) { dbg_msg("netclient", "chunk payload too big. %d. dropping chunk", pChunk->m_DataSize); return -1; } int Flags = 0; dbg_assert(pChunk->m_ClientID >= 0, "errornous client id"); dbg_assert(pChunk->m_ClientID < MaxClients(), "errornous client id"); if(pChunk->m_Flags&NETSENDFLAG_VITAL) Flags = NET_CHUNKFLAG_VITAL; if(m_aSlots[pChunk->m_ClientID].m_Connection.QueueChunk(Flags, pChunk->m_DataSize, pChunk->m_pData) == 0) { if(pChunk->m_Flags&NETSENDFLAG_FLUSH) m_aSlots[pChunk->m_ClientID].m_Connection.Flush(); } else { Drop(pChunk->m_ClientID, "Error sending data"); } } return 0; }
static void cntr_array_assign_capacity(cntr ca, int n_size) { cntr_array* pca = (cntr_array*)ca; void** n_data = NULL; dbg_assert(n_size >= pca->size); pca->capacity = n_size; n_data = (void**)malloc(sizeof(void*) * pca->capacity); memory_move((char*)n_data, (char*)pca->data, pca->size * sizeof(void*) / sizeof(char)); free((void*)pca->data); pca->data = n_data; }
void CGraphics_OpenGL::TextureSet(int TextureID) { dbg_assert(m_Drawing == 0, "called Graphics()->TextureSet within begin"); if(TextureID == -1) { glDisable(GL_TEXTURE_2D); } else { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_aTextures[TextureID].m_Tex); } }
static int _user_lco_init(_user_lco_t *u, size_t size, hpx_action_t id, hpx_action_t op, hpx_action_t predicate, void *init, size_t init_size) { dbg_assert(id); dbg_assert(op); dbg_assert(predicate); lco_init(&u->lco, &_user_lco_vtable); cvar_reset(&u->cvar); u->size = size; u->id = id; u->op = op; u->predicate = predicate; u->init = u->data; u->buffer = (char*)u->data + init_size; handler_t f = actions[u->id].handler; _hpx_user_lco_id_t init_fn = (_hpx_user_lco_id_t)f; init_fn(u->buffer, u->size, init, init_size); return HPX_SUCCESS; }
static void set_bench_search_randomly() { int i; dbg_assert(iset_empty(__set)); log_printline("[number of search: %d]", __num_search); for (i = 0; i < __data_diff_type; i ++) { /* insert all data one by one */ iset_insert(__set, s_test_data_addr[i]); } /* now the set contains __data_diff_type * 2 of data, each elememt int [0, __data_diff_type) * appears at least once */ for (i = 0; i < __num_search; i ++) { intptr_t x = rand() % __data_diff_type; bool res = iset_contains(__set, s_test_data_addr[x]); dbg_assert(res == true); } iset_clear(__set); }
inline unknown* __cast(const unknown* x, unique_id id) { if (__is_object(x)) { _object* obj = (_object*)x; return obj->__cast(obj, id); } else if (__is_interface(x)) { _object* obj = (_object*)__object_from_interface((_interface*)x); return obj->__cast(obj, id); } dbg_assert(false); return NULL; }
inline bool __is_interface(const unknown *x) { const _interface* inf = (const _interface*)x; dbg_assert((intptr_t)(inf->__offset) <= __MAX_NUM_INTERFACE_PER_OBJECT); { const _object* obj = __object_from_interface(inf); if (__is_object((unknown*)obj)) { return true; } } return false; }
void CGraphics_Threaded::QuadsSetSubset(float TlU, float TlV, float BrU, float BrV, int TextureIndex) { dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsSetSubset without begin"); m_aTexture[0].u = TlU; m_aTexture[1].u = BrU; m_aTexture[0].v = TlV; m_aTexture[1].v = TlV; m_aTexture[3].u = TlU; m_aTexture[2].u = BrU; m_aTexture[3].v = BrV; m_aTexture[2].v = BrV; m_aTexture[0].i = m_aTexture[1].i = m_aTexture[2].i = m_aTexture[3].i = (0.5f + TextureIndex) / 256.0f; m_State.m_Dimension = (TextureIndex < 0) ? 2 : 3; }
static int item_bin_sort_compare(const void *p1, const void *p2) { struct item_bin *ib1=*((struct item_bin **)p1),*ib2=*((struct item_bin **)p2); struct attr_bin *attr1,*attr2; char *s1,*s2; int ret; #if 0 dbg_assert(ib1->clen==2); dbg_assert(ib2->clen==2); attr1=(struct attr_bin *)((int *)(ib1+1)+ib1->clen); attr2=(struct attr_bin *)((int *)(ib2+1)+ib1->clen); #else attr1=item_bin_get_attr_bin_last(ib1); attr2=item_bin_get_attr_bin_last(ib2); #endif #if 0 dbg_assert(attr1->type == attr_town_name || attr1->type == attr_town_name_match); dbg_assert(attr2->type == attr_town_name || attr2->type == attr_town_name_match); #endif s1=(char *)(attr1+1); s2=(char *)(attr2+1); if (attr1->type == attr_house_number && attr2->type == attr_house_number) { ret=atoi(s1)-atoi(s2); if (ret) return ret; } ret=strcmp(s1, s2); if (!ret) { int match1=0,match2=0; match1=(attr1->type == attr_town_name_match || attr1->type == attr_district_name_match); match2=(attr2->type == attr_town_name_match || attr2->type == attr_district_name_match); ret=match1-match2; } #if 0 fprintf(stderr,"sort_countries_compare p1=%p p2=%p %s %s\n",p1,p2,s1,s2); #endif return ret; }
static void popup_show_item(struct navit *nav, void *popup, struct displayitem *di) { struct map_rect *mr; void *menu, *menu_map, *menu_item, *menu_dist; char *label; struct item *item,*diitem; int count; label=graphics_displayitem_get_label(di); diitem=graphics_displayitem_get_item(di); count=graphics_displayitem_get_coord_count(di); dbg_assert(diitem); if (label) menu=popup_printf(popup, menu_type_submenu, "%s '%s' (%d coords)", item_to_name(diitem->type), label, count); else menu=popup_printf(popup, menu_type_submenu, "%s (%d coords)", item_to_name(diitem->type), count); menu_item=popup_printf(menu, menu_type_submenu, "Item"); popup_printf(menu_item, menu_type_menu, "type: 0x%x", diitem->type); popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", diitem->id_hi, diitem->id_lo); if (diitem->map) { struct attr type,data; if (!map_get_attr(diitem->map, attr_type, &type, NULL)) type.u.str=""; if (!map_get_attr(diitem->map, attr_data, &data, NULL)) data.u.str=""; popup_printf(menu_item, menu_type_menu, "map: %s:%s", type.u.str, data.u.str); } if (diitem->map) { mr=map_rect_new(diitem->map,NULL); item=map_rect_get_item_byid(mr, diitem->id_hi, diitem->id_lo); dbg(1,"item=%p\n", item); if (item) { popup_show_attrs(item->map, menu_item, item); popup_printf_cb(menu_item, menu_type_menu, callback_new_1(callback_cast(popup_item_dump), diitem), "Dump"); if (item->type < type_line) { struct coord co; struct pcoord *c; if (item_coord_get(item, &co, 1)) { c=g_new(struct pcoord, 1); c->pro = transform_get_projection(navit_get_trans(nav)); c->x = co.x; c->y = co.y; popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c), _("Set as position")); popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c), _("Set as destination")); popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c), _("Add as bookmark")); } } }
nfa* nfa_union (nfa* first, nfa* second) { atm_context* context = first->context; atm* fa = atm_create(context); atm_state *source, *dest; dbg_assert(first->context == second->context); dbg_assert(ilist_size(first->accept_states) == 1); dbg_assert(ilist_size(second->accept_states) == 1); foreach_v(ilist_itr_begin(first->states), ilist_itr_end(first->states), add_state, fa); foreach_v(ilist_itr_begin(second->states), ilist_itr_end(second->states), add_state, fa); source = atm_state_create(fa); dest = atm_state_create(fa); dbg_assert(source != NULL && dest != NULL); ilist_add_back(fa->states, source); ilist_add_back(fa->states, dest); fa->start_state = source; ilist_add_back(fa->accept_states, dest); atm_transform_create(fa, source, first->start_state, Epsilon); atm_transform_create(fa, source, second->start_state, Epsilon); atm_transform_create(fa, (atm_state*)ilist_front(first->accept_states), dest, Epsilon); atm_transform_create(fa, (atm_state*)ilist_front(second->accept_states), dest, Epsilon); ilist_clear(first->accept_states); ilist_clear(first->states); first->start_state = NULL; first->lifestate = atm_joined; ilist_clear(second->accept_states); ilist_clear(second->states); second->start_state = NULL; second->lifestate = atm_joined; fa->lifestate = atm_active; return fa; }