/* * Yes it does seem to be expensive but events happen at user speed (slow) * Recursive when it finds a new slot (canvas) * Beware all these non-widgets are canvas based! Return Qnil if no non-natives * match the x,y. Return the matching non-native (not it's containing canvas/slot) */ VALUE shoes_event_find_psuedo (VALUE self, int x, int y, VALUE *hitobj) { long i; int ox = x, oy = y; VALUE v = Qnil; // v is t/f, Qtrue/Qnil shoes_canvas *self_t; Data_Get_Struct(self, shoes_canvas, self_t); if (ORIGIN(self_t->place)) { oy = y + self_t->slot->scrolly; ox = x - self_t->place.ix + self_t->place.dx; oy = oy - (self_t->place.iy + self_t->place.dy); if (oy < self_t->slot->scrolly || ox < 0 || oy > self_t->slot->scrolly + self_t->place.ih || ox > self_t->place.iw) return Qnil; } if (ATTR(self_t->attr, hidden) != Qtrue) { if (self_t->app->canvas == self) // when we are the app's slot y -= self_t->slot->scrolly; if (IS_INSIDE(self_t, x, y)) { // TODO: something VALUE click = ATTR(self_t->attr, click); if (!NIL_P(click)) { if (ORIGIN(self_t->place)) y += self_t->slot->scrolly; //hoes_safe_block(self, click, rb_ary_new3(4, INT2NUM(button), INT2NUM(x), INT2NUM(y), mods)); } } for (i = RARRAY_LEN(self_t->contents) - 1; i >= 0; i--) { VALUE ele = rb_ary_entry(self_t->contents, i); if (rb_obj_is_kind_of(ele, cCanvas)) { v = shoes_event_find_psuedo(ele, ox, oy, hitobj); } else if (rb_obj_is_kind_of(ele, cTextBlock)) { v = shoes_textblock_event_is_here(ele, ox, oy); *hitobj = ele; } else if (rb_obj_is_kind_of(ele, cImage)) { v = shoes_image_event_is_here(ele, ox, oy); *hitobj = ele; } else if (rb_obj_is_kind_of(ele, cSvg)) { v = shoes_svg_event_is_here(ele, ox, oy); *hitobj = ele; } else if (rb_obj_is_kind_of(ele, cPlot)) { v = shoes_plot_event_is_here(ele, ox, oy); *hitobj = ele; } else if (rb_obj_is_kind_of(ele, cShape)) { v = shoes_shape_event_is_here(ele, ox, oy); *hitobj = ele; } if (!NIL_P(v)) return v; } } return Qnil; }
void USObstacleGrid::draw() { DECLARE_DEBUG_DRAWING("representation:USObstacleGrid", "drawingOnField"); DECLARE_DEBUG_DRAWING("origin:USObstacleGrid", "drawingOnField"); ORIGIN("origin:USObstacleGrid", drawingOrigin.translation.x, drawingOrigin.translation.y, drawingOrigin.rotation); COMPLEX_DRAWING("representation:USObstacleGrid", { unsigned char colorOccupiedStep(255 / cellMaxOccupancy); ColorRGBA baseColor(200, 200, 255, 128); unsigned char cellsForDrawing[GRID_SIZE]; for(int i = 0; i < GRID_SIZE; ++i) cellsForDrawing[i] = colorOccupiedStep* cells[i].state; GRID_MONO("representation:USObstacleGrid", CELL_SIZE, GRID_LENGTH, GRID_LENGTH, baseColor, cellsForDrawing); const int gridWidth(GRID_LENGTH* CELL_SIZE); const int gridHeight(GRID_LENGTH* CELL_SIZE); RECTANGLE("representation:USObstacleGrid", -gridWidth / 2, -gridHeight / 2, gridWidth / 2, gridHeight / 2, 20, Drawings::ps_solid, ColorRGBA(0, 0, 100)); });
/* Initialize database tables */ int inittab() { register int dbt_lc; /* loop control */ register INT i, j; int key_offset = 0, key_count; char dbfile[DtSrFILENMLEN], dbd_ver[DBD_COMPAT_LEN + 1]; char dbname[FILENMLEN]; /* Temporary working space */ int dbf; FILE_ENTRY FAR *file_ptr; FIELD_ENTRY FAR *fld_ptr; #ifndef ONE_DB #define DB_ENABLE 1 #else #define DB_ENABLE 0 #endif #ifndef NO_TIMESTAMP #define TS_ENABLE 1 #else #define TS_ENABLE 0 #endif #if DB_ENABLE | TS_ENABLE RECORD_ENTRY FAR *rec_ptr; SET_ENTRY FAR *set_ptr; #endif #ifndef ONE_DB MEMBER_ENTRY FAR *mem_ptr; SORT_ENTRY FAR *srt_ptr; KEY_ENTRY FAR *key_ptr; #endif #ifndef NO_TIMESTAMP db_tsrecs = db_tssets = FALSE; #endif size_ft = size_rt = size_st = size_mt = size_srt = size_fd = size_kt = 0; /* compute individual dictionary sizes and offsets */ #ifndef ONE_DB for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; dbt_lc < no_of_dbs; ++dbt_lc, ++curr_db_table) { #endif /* form database dictionary name */ if ( DB_REF(db_path[0]) ) strcpy(dbname, DB_REF(db_path)); else dbname[0] = '\0'; #ifdef DEBUG_INITTAB if (debugging_inittab) { printf (__FILE__"100 inittab: path='%s' dbname='%s'\n", dbname, DB_REF(db_name)); fflush (stdout); } #endif if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4) return( dberr(S_NAMELEN) ); strcat(dbname, DB_REF(db_name)); if (con_dbd(dbfile, dbname, get_element(dbdpath, dbt_lc)) != S_OKAY) return( dberr(db_status) ); /*----------------- PASS 1 ------------------- * In this first pass, only opening to determine * required table sizes, so opening read-only is ok. */ if ( (dbf = open_b(dbfile, O_RDONLY)) < 0 ) return( dberr( S_INVDB ) ); /* Read in and verify the dictionary version */ DB_READ(dbf, dbd_ver, DBD_COMPAT_LEN); dbd_ver[DBD_COMPAT_LEN] = '\0'; for ( i=0; i<size_compat; i++ ) { if ( strcmp( dbd_ver, compat_dbd[i] ) == 0 ) goto goodver; } /* Incompatible dictionary file */ close( dbf ); return( dberr( S_INCOMPAT ) ); goodver: /* Read in database page size */ DB_READ(dbf, (char FAR *)&DB_REF(Page_size), sizeof(INT)); NTOHS (DB_REF(Page_size)); /* Read in table sizes */ DB_READ(dbf, (char FAR *)&DB_REF(Size_ft), sizeof(INT)); NTOHS (DB_REF(Size_ft)); DB_READ(dbf, (char FAR *)&DB_REF(Size_rt), sizeof(INT)); NTOHS (DB_REF(Size_rt)); DB_READ(dbf, (char FAR *)&DB_REF(Size_fd), sizeof(INT)); NTOHS (DB_REF(Size_fd)); DB_READ(dbf, (char FAR *)&DB_REF(Size_st), sizeof(INT)); NTOHS (DB_REF(Size_st)); DB_READ(dbf, (char FAR *)&DB_REF(Size_mt), sizeof(INT)); NTOHS (DB_REF(Size_mt)); DB_READ(dbf, (char FAR *)&DB_REF(Size_srt), sizeof(INT)); NTOHS (DB_REF(Size_srt)); DB_READ(dbf, (char FAR *)&DB_REF(Size_kt), sizeof(INT)); NTOHS (DB_REF(Size_kt)); close(dbf); /* end of PASS 1 */ #ifdef DEBUG_INITTAB if (debugging_inittab) { printf (__FILE__"152 sizes: pg=%d ft=%d rt=%d fd=%d\n" " st=%d mt=%d srt=%d kt=%d\n", (int) DB_REF(Page_size), (int) DB_REF(Size_ft), (int) DB_REF(Size_rt), (int) DB_REF(Size_fd), (int) DB_REF(Size_st), (int) DB_REF(Size_mt), (int) DB_REF(Size_srt), (int) DB_REF(Size_kt) ); fflush (stdout); } #endif DB_REF(sysdba) = NULL_DBA; #ifndef ONE_DB /* update merged dictionary offsets and sizes */ if ( curr_db_table->Page_size > page_size ) { page_size = curr_db_table->Page_size; #ifdef DEBUG_INITTAB if (debugging_inittab) { printf (__FILE__"191 db's page_size-->%d (largest = %d)\n", (int)page_size, (int)largest_page); fflush(stdout); } #endif } curr_db_table->ft_offset = size_ft; size_ft += curr_db_table->Size_ft; curr_db_table->rt_offset = size_rt; size_rt += curr_db_table->Size_rt; curr_db_table->fd_offset = size_fd; size_fd += curr_db_table->Size_fd; curr_db_table->st_offset = size_st; size_st += curr_db_table->Size_st; curr_db_table->mt_offset = size_mt; size_mt += curr_db_table->Size_mt; curr_db_table->srt_offset = size_srt; size_srt += curr_db_table->Size_srt; curr_db_table->kt_offset = size_kt; size_kt += curr_db_table->Size_kt; } #endif /* allocate dictionary space */ if ( alloc_dict() != S_OKAY ) return( db_status ); /* read in and adjust dictionary entries for each database */ #ifndef ONE_DB for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; dbt_lc < no_of_dbs; ++dbt_lc, ++curr_db_table) { #endif /* form database dictionary name */ if ( DB_REF(db_path[0]) ) strcpy(dbname, DB_REF(db_path)); else dbname[0] = '\0'; if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4) return( dberr(S_NAMELEN) ); strcat(dbname,DB_REF(db_name)); if (con_dbd(dbfile,dbname,get_element(dbdpath, dbt_lc)) != S_OKAY) return( dberr(db_status) ); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf (__FILE__"247 Tables for database '%s':\n", dbfile); fflush (stdout); } #endif /*----------------- PASS 2 ------------------- * Second pass just loads allocated tables, * so opening .dbd file read-only is still ok. */ dbf = open_b (dbfile, O_RDONLY); DB_LSEEK(dbf, DBD_COMPAT_LEN + 8L*sizeof(INT), 0); /*----------------- FILE TABLE -------------------*/ DB_READ(dbf, (char FAR *)&file_table[ORIGIN(ft_offset)], (DB_REF(Size_ft)*sizeof(FILE_ENTRY))); /* Invalid if sizeof(xxxx_ENTRY) diff on each machine */ for ( i = 0, file_ptr = &file_table[ORIGIN(ft_offset)]; i < DB_REF(Size_ft); i++, file_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (file_ptr->ft_slots); NTOHS (file_ptr->ft_slsize); NTOHS (file_ptr->ft_pgsize); NTOHS (file_ptr->ft_flags); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf (" FILE#%d: ty=%c slts=%2d slsz=%3d pgsz=%d '%s'\n", (int)i, file_ptr->ft_type, (int)file_ptr->ft_slots, (int)file_ptr->ft_slsize, (int)file_ptr->ft_pgsize, file_ptr->ft_name); fflush (stdout); } #endif } /*----------------- RECORD TABLE -------------------*/ DB_READ(dbf, (char FAR *)&record_table[ORIGIN(rt_offset)], (DB_REF(Size_rt)*sizeof(RECORD_ENTRY))); for ( i = 0, rec_ptr = &record_table[ORIGIN(rt_offset)]; i < DB_REF(Size_rt); i++, rec_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (rec_ptr->rt_file); NTOHS (rec_ptr->rt_len); NTOHS (rec_ptr->rt_data); NTOHS (rec_ptr->rt_fields); NTOHS (rec_ptr->rt_fdtot); NTOHS (rec_ptr->rt_flags); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf ( " REC #%d: fil=%d len=%3d data=%2d fld1=%2d flds=%2d\n", (int)i, (int)rec_ptr->rt_file, (int)rec_ptr->rt_len, (int)rec_ptr->rt_data, (int)rec_ptr->rt_fields, (int)rec_ptr->rt_fdtot); fflush (stdout); } #endif } /*----------------- FIELD TABLE -------------------*/ DB_READ(dbf, (char FAR *)&field_table[ORIGIN(fd_offset)], (DB_REF(Size_fd)*sizeof(FIELD_ENTRY))); for ( i = 0, fld_ptr = &field_table[ORIGIN(fd_offset)]; i < DB_REF(Size_fd); i++, fld_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (fld_ptr->fd_len); NTOHS (fld_ptr->fd_keyfile); NTOHS (fld_ptr->fd_keyno); NTOHS (fld_ptr->fd_ptr); NTOHS (fld_ptr->fd_rec); NTOHS (fld_ptr->fd_flags); for (j=0; j<MAXDIMS; j++) NTOHS (fld_ptr->fd_dim[j]); #ifdef DEBUG_INITTAB if (dump_init_tables) { if (i == 0) puts (" key typ len kfil key# ofs rec# flg dims"); printf ( " FLD#%2d %c %c %3d %d %d %3d %d %x", (int)i, fld_ptr->fd_key, fld_ptr->fd_type, (int)fld_ptr->fd_len, (int)fld_ptr->fd_keyfile, (int)fld_ptr->fd_keyno, (int)fld_ptr->fd_ptr, (int)fld_ptr->fd_rec, (int)fld_ptr->fd_flags); for (j=0; j<MAXDIMS; j++) if (fld_ptr->fd_dim[j]) printf (" %d:%d", j, (int)fld_ptr->fd_dim[j]); putchar ('\n'); fflush (stdout); } #endif } /*----------------- SET TABLE -------------------*/ DB_READ(dbf, (char FAR *)&set_table[ORIGIN(st_offset)], (DB_REF(Size_st)*sizeof(SET_ENTRY))); for ( i = 0, set_ptr = &set_table[ORIGIN(st_offset)]; i < DB_REF(Size_st); i++, set_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (set_ptr->st_order); NTOHS (set_ptr->st_own_rt); NTOHS (set_ptr->st_own_ptr); NTOHS (set_ptr->st_members); NTOHS (set_ptr->st_memtot); NTOHS (set_ptr->st_flags); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf ( " SET #%d: ord=%c owner=%d ownofs=%2d mem1=%d mems=%d\n", (int)i, (char)set_ptr->st_order, (int)set_ptr->st_own_rt, (int)set_ptr->st_own_ptr, (int)set_ptr->st_members, (int)set_ptr->st_memtot); fflush (stdout); } #endif } /*----------------- MEMBER TABLE -------------------*/ DB_READ(dbf, (char FAR *)&member_table[ORIGIN(mt_offset)], (DB_REF(Size_mt)*sizeof(MEMBER_ENTRY))); for ( i = 0, mem_ptr = &member_table[ORIGIN(mt_offset)]; i < DB_REF(Size_mt); i++, mem_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (mem_ptr->mt_record); NTOHS (mem_ptr->mt_mem_ptr); NTOHS (mem_ptr->mt_sort_fld); NTOHS (mem_ptr->mt_totsf); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf ( " MEM #%d: rec=%d ofs=%d sort1=%d sorts=%d\n", (int)i, (int)mem_ptr->mt_record, (int)mem_ptr->mt_mem_ptr, (int)mem_ptr->mt_sort_fld, (int)mem_ptr->mt_totsf); fflush (stdout); } #endif } DB_READ(dbf, (char FAR *)&sort_table[ORIGIN(srt_offset)], (DB_REF(Size_srt)*sizeof(SORT_ENTRY))); /* Member sort tables not used by DtSearch @@@ */ if (DB_REF(Size_srt)) { /* Byte swap each INT on LITTLE_ENDIAN machines */ srt_ptr = &sort_table[ORIGIN(srt_offset)]; NTOHS (srt_ptr->se_fld); NTOHS (srt_ptr->se_set); } DB_READ(dbf, (char FAR *)&key_table[ORIGIN(kt_offset)], (DB_REF(Size_kt)*sizeof(KEY_ENTRY))); /* Compound key tables not used by DtSearch @@@ */ if (DB_REF(Size_kt)) { /* Byte swap each INT on LITTLE_ENDIAN machines */ key_ptr = &key_table[ORIGIN(kt_offset)]; NTOHS (key_ptr->kt_key); NTOHS (key_ptr->kt_field); NTOHS (key_ptr->kt_ptr); NTOHS (key_ptr->kt_sort); } close(dbf); /* end of PASS 2 */ #ifdef DEBUG_INITTAB dump_init_tables = FALSE; #endif #ifndef ONE_DB curr_db_table->key_offset = key_offset; #endif /* update file table path entries */ if ( DB_REF(db_path[0]) || dbfpath[0] ) { for (i = 0, file_ptr = &file_table[ORIGIN(ft_offset)]; i < DB_REF(Size_ft); ++i, ++file_ptr) { /* Construct the data/key file name */ if ( DB_REF(db_path[0]) ) strcpy(dbname, DB_REF(db_path)); else dbname[0] = '\0'; if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4) return( dberr(S_NAMELEN) ); strcat(dbname, DB_REF(db_name)); if (con_dbf(dbfile, file_ptr->ft_name, dbname, get_element(dbfpath, dbt_lc)) != S_OKAY) return( dberr(db_status) ); /* Save new name in dictionary */ strcpy(file_ptr->ft_name, dbfile); } } #if DB_ENABLE | TS_ENABLE /* adjust record table entries */ for (i = ORIGIN(rt_offset), rec_ptr = &record_table[ORIGIN(rt_offset)]; i < ORIGIN(rt_offset) + DB_REF(Size_rt); ++i, ++rec_ptr) { #ifndef ONE_DB rec_ptr->rt_file += curr_db_table->ft_offset; rec_ptr->rt_fields += curr_db_table->fd_offset; #endif #ifndef NO_TIMESTAMP if ( rec_ptr->rt_flags & TIMESTAMPED ) { db_tsrecs = TRUE; #ifdef ONE_DB break; #endif } #endif } #endif /* adjust field table entries */ for (key_count = 0, i = ORIGIN(fd_offset), fld_ptr = &field_table[ORIGIN(fd_offset)]; i < ORIGIN(fd_offset) + DB_REF(Size_fd); ++i, ++fld_ptr) { #ifndef ONE_DB fld_ptr->fd_rec += curr_db_table->rt_offset; #endif if ( fld_ptr->fd_key != NOKEY ) { fld_ptr->fd_keyno += key_offset; ++key_count; #ifndef ONE_DB fld_ptr->fd_keyfile += curr_db_table->ft_offset; if ( fld_ptr->fd_type == 'k' ) fld_ptr->fd_ptr += curr_db_table->kt_offset; #endif } } key_offset += key_count; #if DB_ENABLE | TS_ENABLE /* adjust set table entries */ for (i = ORIGIN(st_offset), set_ptr = &set_table[ORIGIN(st_offset)]; i < ORIGIN(st_offset) + DB_REF(Size_st); ++i, ++set_ptr) { #ifndef ONE_DB set_ptr->st_own_rt += curr_db_table->rt_offset; set_ptr->st_members += curr_db_table->mt_offset; #endif #ifndef NO_TIMESTAMP if ( set_ptr->st_flags & TIMESTAMPED ) { db_tssets = TRUE; #ifdef ONE_DB break; #endif } #endif } #endif #ifndef ONE_DB /* adjust member table entries */ for (i = curr_db_table->mt_offset, mem_ptr = &member_table[curr_db_table->mt_offset]; i < curr_db_table->mt_offset + curr_db_table->Size_mt; ++i, ++mem_ptr) { mem_ptr->mt_record += curr_db_table->rt_offset; mem_ptr->mt_sort_fld += curr_db_table->srt_offset; } /* adjust sort table entries */ for (i = curr_db_table->srt_offset, srt_ptr = &sort_table[curr_db_table->srt_offset]; i < curr_db_table->srt_offset + curr_db_table->Size_srt; ++i, ++srt_ptr) { srt_ptr->se_fld += curr_db_table->fd_offset; srt_ptr->se_set += curr_db_table->st_offset; } /* adjust key table entries */ for (i = curr_db_table->kt_offset, key_ptr = &key_table[curr_db_table->kt_offset]; i < curr_db_table->kt_offset + curr_db_table->Size_kt; ++i, ++key_ptr) { key_ptr->kt_key += curr_db_table->fd_offset; key_ptr->kt_field += curr_db_table->fd_offset; } } /* end loop for each database */ #endif initcurr(); return( db_status ); }
/* Initialize currency tables */ static int initcurr() { register int dbt_lc; /* loop control */ register int rec, i; RECORD_ENTRY FAR *rec_ptr; SET_ENTRY FAR *set_ptr; DB_ADDR FAR *co_ptr; int old_size; int new_size; /* Initialize current record and type */ #ifndef ONE_DB for (dbt_lc = no_of_dbs, curr_db_table = &db_table[old_no_of_dbs], curr_rn_table = &rn_table[old_no_of_dbs]; --dbt_lc >= 0; ++curr_db_table, ++curr_rn_table) { DB_REF(curr_dbt_rec) = NULL_DBA; #endif RN_REF(rn_dba) = NULL_DBA; RN_REF(rn_type) = -1; #ifndef ONE_DB } #endif if ( size_st ) { new_size = size_st * sizeof(DB_ADDR); old_size = old_size_st * sizeof(DB_ADDR); if ( ALLOC_TABLE(&db_global.Curr_own, new_size, old_size, "curr_own") != S_OKAY ) { return( db_status ); } if ( ALLOC_TABLE(&db_global.Curr_mem, new_size, old_size, "curr_mem") != S_OKAY ) { return( db_status ); } #ifndef NO_TIMESTAMP new_size = size_st * sizeof(ULONG); old_size = old_size_st * sizeof(ULONG); if ( db_tsrecs ) { if ( ALLOC_TABLE(&db_global.Co_time, new_size, old_size, "co_time") != S_OKAY ) { return( db_status ); } if ( ALLOC_TABLE(&db_global.Cm_time, new_size, old_size, "cm_time") != S_OKAY ) { return( db_status ); } } if ( db_tssets ) { if ( ALLOC_TABLE(&db_global.Cs_time, new_size, old_size, "cs_time") != S_OKAY ) { return( db_status ); } } #endif /* for each db make system record as curr_own of its sets */ #ifndef ONE_DB for (dbt_lc = no_of_dbs, curr_db_table = &db_table[old_no_of_dbs]; --dbt_lc >= 0; ++curr_db_table) { #endif for (rec = ORIGIN(rt_offset), rec_ptr = &record_table[ORIGIN(rt_offset)]; rec < ORIGIN(rt_offset) + DB_REF(Size_rt); ++rec, ++rec_ptr) { if (rec_ptr->rt_fdtot == -1) { /* found system record */ curr_rec = ((FILEMASK & NUM2EXT(rec_ptr->rt_file, ft_offset)) << FILESHIFT) | 1L; /* make system record current of sets it owns */ for (i = ORIGIN(st_offset), set_ptr = &set_table[ORIGIN(st_offset)], co_ptr = &curr_own[ORIGIN(st_offset)]; i < ORIGIN(st_offset) + DB_REF(Size_st); ++i, ++set_ptr, ++co_ptr) { if (set_ptr->st_own_rt == rec) { *co_ptr = curr_rec; } } DB_REF(sysdba) = curr_rec; #ifndef ONE_DB DB_REF(curr_dbt_rec) = curr_rec; #endif break; } } #ifndef ONE_DB } #endif } else { curr_own = NULL; curr_mem = NULL; } #ifndef ONE_DB curr_db = 0; MEM_LOCK(&db_global.Db_table); curr_db_table = db_table; MEM_LOCK(&db_global.Rn_table); curr_rn_table = rn_table; setdb_on = FALSE; curr_rec = DB_REF(curr_dbt_rec); #endif return( db_status = S_OKAY ); }
bool PcpPrimIndex_Graph::_ComputeEraseCulledNodeIndexMapping( std::vector<size_t>* erasedIndexMapping) const { TRACE_FUNCTION(); // Figure out which of the nodes that are marked for culling can // actually be erased from the node pool. const size_t numNodes = _GetNumNodes(); std::vector<bool> nodeCanBeErased(numNodes); for (size_t i = 0; i < numNodes; ++i) { nodeCanBeErased[i] = _GetNode(i).smallInts.culled; } // If a node is marked for culling, but serves as the origin node for a // node that is *not* culled, we can't erase it from the graph. Doing so // would break the chain of origins Pcp relies on for strength ordering. // So, we iterate through the nodes to detect this situation and mark // the appropriate nodes as un-erasable. // // XXX: This has some O(N^2) behavior, as we wind up visiting the nodes // in the chain of origins multiple times. We could keep track of // nodes we've already visited to avoid re-processing them. for (size_t i = 0; i < numNodes; ++i) { if (ORIGIN(_GetNode(i)) == _Node::_invalidNodeIndex) { continue; } // Follow origin chain until we find the first non-culled node. // All subsequent nodes in the chain cannot be erased. This also // means that the parents of those nodes cannot be erased. bool subsequentOriginsCannotBeCulled = false; for (size_t nIdx = i; ; nIdx = ORIGIN(_GetNode(nIdx))) { const bool nodeIsCulled = nodeCanBeErased[nIdx]; if (!nodeIsCulled) { subsequentOriginsCannotBeCulled = true; } else if (nodeIsCulled && subsequentOriginsCannotBeCulled) { for (size_t pIdx = nIdx; pIdx != _Node::_invalidNodeIndex && nodeCanBeErased[pIdx]; pIdx = PARENT(_GetNode(pIdx))) { nodeCanBeErased[pIdx] = false; } } if (ORIGIN(_GetNode(nIdx)) == PARENT(_GetNode(nIdx))) { break; } } } // Now that we've determined which nodes can and can't be erased, // create the node index mapping. const size_t numNodesToCull = std::count(nodeCanBeErased.begin(), nodeCanBeErased.end(), true); if (numNodesToCull == 0) { return false; } size_t numCulledNodes = 0; erasedIndexMapping->resize(numNodes); for (size_t i = 0; i < numNodes; ++i) { if (nodeCanBeErased[i]) { (*erasedIndexMapping)[i] = _Node::_invalidNodeIndex; ++numCulledNodes; } else { (*erasedIndexMapping)[i] = i - numCulledNodes; } } return true; }
size_t PcpPrimIndex_Graph::_CreateNodesForSubgraph( const PcpPrimIndex_Graph& subgraph, const PcpArc& arc) { // The subgraph's root should never have a parent or origin node; we // rely on this invariant below. TF_VERIFY(!subgraph.GetRootNode().GetParentNode() && !subgraph.GetRootNode().GetOriginNode()); // Insert a copy of all of the node data in the given subgraph into our // node pool. const size_t oldNumNodes = _GetNumNodes(); _data->finalized = false; _data->nodes.insert( _data->nodes.end(), subgraph._data->nodes.begin(), subgraph._data->nodes.end()); _nodeSitePaths.insert( _nodeSitePaths.end(), subgraph._nodeSitePaths.begin(), subgraph._nodeSitePaths.end()); _nodeHasSpecs.insert( _nodeHasSpecs.end(), subgraph._nodeHasSpecs.begin(), subgraph._nodeHasSpecs.end()); const size_t newNumNodes = _GetNumNodes(); const size_t subgraphRootNodeIndex = oldNumNodes; // Set the arc connecting the root of the subgraph to the rest of the // graph. _Node& subgraphRoot = _data->nodes[subgraphRootNodeIndex]; subgraphRoot.SetArc(arc); // XXX: This is very similar to code in _ApplyNodeIndexMapping that // adjust node references. There must be a good way to factor // all of that out... // Iterate over all of the newly-copied nodes and adjust references to // other nodes in the node pool. struct _ConvertOldToNewIndex { _ConvertOldToNewIndex(size_t base, size_t numNewNodes) : _base(base), _numNewNodes(numNewNodes) { } size_t operator()(size_t oldIndex) const { if (oldIndex != _Node::_invalidNodeIndex) { TF_VERIFY(oldIndex + _base < _numNewNodes); return oldIndex + _base; } else { return oldIndex; } } size_t _base; size_t _numNewNodes; }; const _ConvertOldToNewIndex convertToNewIndex(subgraphRootNodeIndex, newNumNodes); for (size_t i = oldNumNodes; i < newNumNodes; ++i) { _Node& newNode = _data->nodes[i]; // Update the node's mapToRoot since it is now part of a new graph. if (i != subgraphRootNodeIndex) { newNode.mapToRoot = subgraphRoot.mapToRoot.Compose(newNode.mapToRoot); } // The parent and origin of the root of the newly-inserted subgraph // don't need to be fixed up because it doesn't point to a node // within the subgraph. if (i != subgraphRootNodeIndex) { PARENT(newNode) = convertToNewIndex(PARENT(newNode)); ORIGIN(newNode) = convertToNewIndex(ORIGIN(newNode)); } FIRST_CHILD(newNode) = convertToNewIndex(FIRST_CHILD(newNode)); LAST_CHILD(newNode) = convertToNewIndex(LAST_CHILD(newNode)); PREV_SIBLING(newNode) = convertToNewIndex(PREV_SIBLING(newNode)); NEXT_SIBLING(newNode) = convertToNewIndex(NEXT_SIBLING(newNode)); } return subgraphRootNodeIndex; }
void PcpPrimIndex_Graph::_ApplyNodeIndexMapping( const std::vector<size_t>& nodeIndexMap) { _NodePool& oldNodes = _data->nodes; SdfPathVector& oldSitePaths = _nodeSitePaths; std::vector<bool>& oldHasSpecs = _nodeHasSpecs; TF_VERIFY(oldNodes.size() == oldSitePaths.size() && oldNodes.size() == oldHasSpecs.size()); TF_VERIFY(nodeIndexMap.size() == oldNodes.size()); const size_t numNodesToErase = std::count(nodeIndexMap.begin(), nodeIndexMap.end(), _Node::_invalidNodeIndex); const size_t oldNumNodes = oldNodes.size(); const size_t newNumNodes = oldNumNodes - numNodesToErase; TF_VERIFY(newNumNodes <= oldNumNodes); struct _ConvertOldToNewIndex { _ConvertOldToNewIndex(const std::vector<size_t>& table, size_t numNewNodes) : _table(table) { for (size_t i = 0, n = _table.size(); i != n; ++i) { TF_VERIFY(_table[i] < numNewNodes || _table[i] == _Node::_invalidNodeIndex); } } size_t operator()(size_t oldIndex) const { if (oldIndex != _Node::_invalidNodeIndex) { return _table[oldIndex]; } else { return oldIndex; } } const std::vector<size_t>& _table; }; const _ConvertOldToNewIndex convertToNewIndex(nodeIndexMap, newNumNodes); // If this mapping causes nodes to be erased, it's much more convenient // to fix up node indices to accommodate those erasures in the old node // pool before moving nodes to their new position. if (numNodesToErase > 0) { for (size_t i = 0; i < oldNumNodes; ++i) { const size_t oldNodeIndex = i; const size_t newNodeIndex = convertToNewIndex(oldNodeIndex); _Node& node = _data->nodes[oldNodeIndex]; // Sanity-check: If this node isn't going to be erased, its parent // can't be erased either. const bool nodeWillBeErased = (newNodeIndex == _Node::_invalidNodeIndex); if (!nodeWillBeErased) { const bool parentWillBeErased = PARENT(node) != _Node::_invalidNodeIndex && convertToNewIndex(PARENT(node)) == _Node::_invalidNodeIndex; TF_VERIFY(!parentWillBeErased); continue; } if (PREV_SIBLING(node) != _Node::_invalidNodeIndex) { _Node& prevNode = _data->nodes[PREV_SIBLING(node)]; NEXT_SIBLING(prevNode) = NEXT_SIBLING(node); } if (NEXT_SIBLING(node) != _Node::_invalidNodeIndex) { _Node& nextNode = _data->nodes[NEXT_SIBLING(node)]; PREV_SIBLING(nextNode) = PREV_SIBLING(node); } _Node& parentNode = _data->nodes[PARENT(node)]; if (FIRST_CHILD(parentNode) == oldNodeIndex) { FIRST_CHILD(parentNode) = NEXT_SIBLING(node); } if (LAST_CHILD(parentNode) == oldNodeIndex) { LAST_CHILD(parentNode) = PREV_SIBLING(node); } } } // Swap nodes into their new position. _NodePool nodesAfterMapping(newNumNodes); SdfPathVector nodeSitePathsAfterMapping(newNumNodes); std::vector<bool> nodeHasSpecsAfterMapping(newNumNodes); for (size_t i = 0; i < oldNumNodes; ++i) { const size_t oldNodeIndex = i; const size_t newNodeIndex = convertToNewIndex(oldNodeIndex); if (newNodeIndex == _Node::_invalidNodeIndex) { continue; } // Swap the node from the old node pool into the new node pool at // the desired location. _Node& oldNode = oldNodes[oldNodeIndex]; _Node& newNode = nodesAfterMapping[newNodeIndex]; newNode.Swap(oldNode); PARENT(newNode) = convertToNewIndex(PARENT(newNode)); ORIGIN(newNode) = convertToNewIndex(ORIGIN(newNode)); FIRST_CHILD(newNode) = convertToNewIndex(FIRST_CHILD(newNode)); LAST_CHILD(newNode) = convertToNewIndex(LAST_CHILD(newNode)); PREV_SIBLING(newNode) = convertToNewIndex(PREV_SIBLING(newNode)); NEXT_SIBLING(newNode) = convertToNewIndex(NEXT_SIBLING(newNode)); // Copy the corresponding node site path. nodeSitePathsAfterMapping[newNodeIndex] = oldSitePaths[oldNodeIndex]; nodeHasSpecsAfterMapping[newNodeIndex] = oldHasSpecs[oldNodeIndex]; } _data->nodes.swap(nodesAfterMapping); _nodeSitePaths.swap(nodeSitePathsAfterMapping); _nodeHasSpecs.swap(nodeHasSpecsAfterMapping); }
void shoes_place_decide(shoes_place *place, VALUE c, VALUE attr, int dw, int dh, unsigned char rel, int padded) { shoes_canvas *canvas = NULL; if (!NIL_P(c)) Data_Get_Struct(c, shoes_canvas, canvas); VALUE ck = rb_obj_class(c); VALUE stuck = ATTR(attr, attach); // for image : we want to scale the image, given only one attribute :width or :height // get dw and dh, set width or height if (REL_FLAGS(rel) & REL_SCALE) { // 8 VALUE rw = ATTR(attr, width), rh = ATTR(attr, height); if (NIL_P(rw) && !NIL_P(rh)) { // we have height // fetch height in pixels whatever the input (string, float, positive/negative int) int spx = shoes_px(rh, dh, CPH(canvas), 1); // compute width with image aspect ratio [(dh == dw) means a square ] dw = (dh == dw) ? spx : ROUND(((dh * 1.) / dw) * spx); dh = spx; // now re-init 'dh' for next calculations ATTRSET(attr, width, INT2NUM(dw)); // set calculated width } else if (NIL_P(rh) && !NIL_P(rw)) { int spx = shoes_px(rw, dw, CPW(canvas), 1); dh = (dh == dw) ? spx : ROUND(((dh * 1.) / dw) * spx); dw = spx; ATTRSET(attr, height, INT2NUM(dh)); } } ATTR_MARGINS(attr, 0, canvas); if (padded || dh == 0) dh += tmargin + bmargin; if (padded || dw == 0) dw += lmargin + rmargin; int testw = dw; if (testw == 0) testw = lmargin + 1 + rmargin; if (!NIL_P(stuck)) { if (stuck == cShoesWindow) rel = REL_FLAGS(rel) | REL_WINDOW; else if (stuck == cMouse) rel = REL_FLAGS(rel) | REL_CURSOR; else rel = REL_FLAGS(rel) | REL_STICKY; } place->flags = rel; place->dx = place->dy = 0; if (canvas == NULL) { place->ix = place->x = 0; place->iy = place->y = 0; place->iw = place->w = dw; place->ih = place->h = dh; } else { int cx, cy, ox, oy, tw = dw, th = dh; switch (REL_COORDS(rel)) { case REL_WINDOW: cx = 0; cy = 0; ox = 0; oy = canvas->slot->scrolly; break; case REL_CANVAS: cx = canvas->cx - CPX(canvas); cy = canvas->cy - CPY(canvas); ox = CPX(canvas); oy = CPY(canvas); break; case REL_CURSOR: cx = 0; cy = 0; ox = canvas->app->mousex; oy = canvas->app->mousey; break; case REL_TILE: cx = 0; cy = 0; ox = CPX(canvas); oy = CPY(canvas); testw = dw = CPW(canvas); dh = max(canvas->height, CPH(canvas)); // Fix #2 ? //dh = (max(canvas->height, canvas->fully - CPB(canvas)) - CPY(canvas)); break; default: cx = 0; cy = 0; ox = canvas->cx; oy = canvas->cy; if ((REL_COORDS(rel) & REL_STICKY) && shoes_is_element(stuck)) { shoes_element *element; Data_Get_Struct(stuck, shoes_element, element); ox = element->place.x; oy = element->place.y; } break; } place->w = PX(attr, width, testw, CPW(canvas)); if (dw == 0 && place->w + (int)canvas->cx > canvas->place.iw) { canvas->cx = canvas->endx = CPX(canvas); canvas->cy = canvas->endy; place->w = canvas->place.iw; } place->h = PX(attr, height, dh, CPH(canvas)); if (REL_COORDS(rel) != REL_TILE) { tw = place->w; th = place->h; } place->x = PX2(attr, left, right, cx, tw, canvas->place.iw) + ox; place->y = PX2(attr, top, bottom, cy, th, ORIGIN(canvas->place) ? canvas->height : canvas->fully) + oy; if (!ORIGIN(canvas->place)) { place->dx = canvas->place.dx; place->dy = canvas->place.dy; } place->dx += PXN(attr, displace_left, 0, CPW(canvas)); place->dy += PXN(attr, displace_top, 0, CPH(canvas)); place->flags |= NIL_P(ATTR(attr, left)) && NIL_P(ATTR(attr, right)) ? 0 : FLAG_ABSX; place->flags |= NIL_P(ATTR(attr, top)) && NIL_P(ATTR(attr, bottom)) ? 0 : FLAG_ABSY; if (REL_COORDS(rel) != REL_TILE && ABSY(*place) == 0 && (ck == cStack || place->x + place->w > CPX(canvas) + canvas->place.iw)) { canvas->cx = place->x = CPX(canvas); canvas->cy = place->y = canvas->endy; } } place->ix = place->x + lmargin; place->iy = place->y + tmargin; place->iw = place->w - (lmargin + rmargin); //place->iw = (RTEST(ATTR(attr, width))) ? place->w : place->w - (lmargin + rmargin); if (place->iw < 0) place->iw = 0; place->ih = place->h - (tmargin + bmargin); //place->ih = (RTEST(ATTR(attr, height))) ? place->h : place->h - (tmargin + bmargin); if (place->ih < 0) place->ih = 0; INFO("PLACE: (%d, %d), (%d: %d, %d: %d) [%d, %d] %x\n", place->x, place->y, place->w, place->iw, place->h, place->ih, ABSX(*place), ABSY(*place), place->flags); }
bool TeamRobot::main() { { SYNC; OUTPUT(idProcessBegin, bin, 't'); DECLARE_DEBUG_DRAWING("representation:RobotPose", "drawingOnField"); // The robot pose DECLARE_DEBUG_DRAWING("representation:RobotPose:deviation", "drawingOnField"); // The robot pose DECLARE_DEBUG_DRAWING("origin:RobotPose", "drawingOnField"); // Set the origin to the robot's current position DECLARE_DEBUG_DRAWING("representation:BallModel", "drawingOnField"); // drawing of the ball model DECLARE_DEBUG_DRAWING("representation:CombinedWorldModel", "drawingOnField"); // drawing of the combined world model DECLARE_DEBUG_DRAWING("representation:GoalPercept:Field", "drawingOnField"); // drawing of the goal percept DECLARE_DEBUG_DRAWING("representation:MotionRequest", "drawingOnField"); // drawing of a request walk vector DECLARE_DEBUG_DRAWING("representation:ObstacleModel:Center", "drawingOnField"); //drawing center of obstacle model DECLARE_DEBUG_DRAWING("representation:LinePercept:Field", "drawingOnField"); uint8_t teamColor = 0, swapSides = 0; MODIFY("teamColor", ownTeamInfo.teamColor); MODIFY("swapSides", swapSides); if(SystemCall::getTimeSince(robotPoseReceived) < 1000) robotPose.draw(); if(SystemCall::getTimeSince(ballModelReceived) < 1000) ballModel.draw(); if(SystemCall::getTimeSince(combinedWorldModelReceived) < 1000) combinedWorldModel.draw(); if(SystemCall::getTimeSince(goalPerceptReceived) < 1000) goalPercept.draw(); if(SystemCall::getTimeSince(motionRequestReceived) < 1000) motionRequest.draw(); if(SystemCall::getTimeSince(obstacleModelReceived) < 1000) obstacleModel.draw(); if(SystemCall::getTimeSince(linePerceptReceived) < 1000) linePercept.draw(); if(swapSides ^ teamColor) { ORIGIN("field polygons", 0, 0, pi2); // hack: swap sides! } fieldDimensions.draw(); fieldDimensions.drawPolygons(teamColor); DECLARE_DEBUG_DRAWING("robotState", "drawingOnField"); // text decribing the state of the robot int lineY = 3550; DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "batteryLevel: " << robotHealth.batteryLevel << " %"); DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "role: " << Role::getName(behaviorStatus.role)); lineY -= 180; DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "temperatures: joint " << JointData::getName(robotHealth.jointWithMaxTemperature)<< ":" << robotHealth.maxJointTemperature << " C, cpu: " << robotHealth.cpuTemperature << " C"); lineY -= 180; DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "rates: cognition: " << (int) std::floor(robotHealth.cognitionFrameRate + 0.5f) << " fps, motion: " << (int) std::floor(robotHealth.motionFrameRate + 0.5f) << " fps"); if(ballModel.timeWhenLastSeen) { DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "ballLastSeen: " << SystemCall::getRealTimeSince(ballModel.timeWhenLastSeen) << " ms"); } else { DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "ballLastSeen: never"); } //DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "ballPercept: " << ballModel.lastPerception.position.x << ", " << ballModel.lastPerception.position.y); lineY -= 180; DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "memory usage: " << robotHealth.memoryUsage << " %"); if(goalPercept.timeWhenGoalPostLastSeen) { DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "goalLastSeen: " << SystemCall::getRealTimeSince(goalPercept.timeWhenGoalPostLastSeen) << " ms"); } else { DRAWTEXT("robotState", 3700, lineY, 150, ColorRGBA::white, "goalLastSeen: never"); } lineY -= 180; DRAWTEXT("robotState", -5100, lineY, 150, ColorRGBA::white, "load average: " << (float(robotHealth.load[0]) / 10.f) << " " << (float(robotHealth.load[1]) / 10.f) << " " << (float(robotHealth.load[2]) / 10.f)); DRAWTEXT("robotState", -4100, 0, 150, ColorRGBA(255, 255, 255, 50), robotHealth.robotName); DECLARE_DEBUG_DRAWING("robotOffline", "drawingOnField"); // A huge X to display the online/offline state of the robot if(SystemCall::getTimeSince(robotPoseReceived) > 500 || (SystemCall::getTimeSince(isPenalizedReceived) < 1000 && isPenalized) || (SystemCall::getTimeSince(hasGroundContactReceived) < 1000 && !hasGroundContact) || (SystemCall::getTimeSince(isUprightReceived) < 1000 && !isUpright)) { LINE("robotOffline", -5100, 3600, 5100, -3600, 50, Drawings::ps_solid, ColorRGBA(0xff, 0, 0)); LINE("robotOffline", 5100, 3600, -5100, -3600, 50, Drawings::ps_solid, ColorRGBA(0xff, 0, 0)); } if(SystemCall::getTimeSince(isPenalizedReceived) < 1000 && isPenalized) { // Draw a text in red letters to tell that the robot is penalized DRAWTEXT("robotState", -2000, 0, 200, ColorRGBA::red, "PENALIZED"); } if(SystemCall::getTimeSince(hasGroundContactReceived) < 1000 && !hasGroundContact) { // Draw a text in red letters to tell that the robot doesn't have ground contact DRAWTEXT("robotState", 300, 0, 200, ColorRGBA::red, "NO GROUND CONTACT"); } if(SystemCall::getTimeSince(isUprightReceived) < 1000 && !isUpright) { // Draw a text in red letters to tell that the robot is fallen down DRAWTEXT("robotState", 300, 0, 200, ColorRGBA::red, "NOT UPRIGHT"); } DEBUG_RESPONSE_ONCE("automated requests:DrawingManager", OUTPUT(idDrawingManager, bin, Global::getDrawingManager());); DEBUG_RESPONSE_ONCE("automated requests:DrawingManager3D", OUTPUT(idDrawingManager3D, bin, Global::getDrawingManager3D()););
PROVIDE(__process_stack_size = __process_stack_size); /* +=============================================================================+ | available memories definitions +=============================================================================+ */ MEMORY { rom (rx) : org = ROM_START, len = ROM_SIZE ram (rwx) : org = RAM_START, len = RAM_SIZE nul (rwx) : org = 0x20000000, len = 0k } __rom_start = ORIGIN(rom); __rom_size = LENGTH(rom); __rom_end = __rom_start + __rom_size; __ram_start = ORIGIN(ram); __ram_size = LENGTH(ram); __ram_end = __ram_start + __ram_size; PROVIDE(__rom_start = __rom_start); PROVIDE(__rom_size = __rom_size); PROVIDE(__rom_end = __rom_end); PROVIDE(__ram_start = __ram_start); PROVIDE(__ram_size = __ram_size); PROVIDE(__ram_end = __ram_end);