// Create "path". On success set *pf to point at the file and return 0. // On error return < 0. int file_create(const char *path, struct File **pf) { char name[MAXNAMELEN]; int r; struct File *dir, *f; if ((r = walk_path(path, &dir, &f, name)) == 0) return -E_FILE_EXISTS; if (r != -E_NOT_FOUND || dir == 0) return r; if ((r = dir_alloc_file(dir, &f)) < 0) return r; strcpy(f->f_name, name); *pf = f; file_flush(dir); return 0; }
// Open "path". On success set *pf to point at the file and return 0. // On error return < 0. int file_open(const char *path, struct File **pf) { return walk_path(path, 0, pf, 0); }
WALKAROUND::WALKAROUND_STATUS WALKAROUND::singleStep( LINE& aPath, bool aWindingDirection ) { optional<OBSTACLE>& current_obs = aWindingDirection ? m_currentObstacle[0] : m_currentObstacle[1]; bool& prev_recursive = aWindingDirection ? m_recursiveCollision[0] : m_recursiveCollision[1]; if( !current_obs ) return DONE; SHAPE_LINE_CHAIN path_pre[2], path_walk[2], path_post[2]; VECTOR2I last = aPath.CPoint( -1 ); if( ( current_obs->m_hull ).PointInside( last ) || ( current_obs->m_hull ).PointOnEdge( last ) ) { m_recursiveBlockageCount++; if( m_recursiveBlockageCount < 3 ) aPath.Line().Append( current_obs->m_hull.NearestPoint( last ) ); else { aPath = aPath.ClipToNearestObstacle( m_world ); return DONE; } } aPath.Walkaround( current_obs->m_hull, path_pre[0], path_walk[0], path_post[0], aWindingDirection ); aPath.Walkaround( current_obs->m_hull, path_pre[1], path_walk[1], path_post[1], !aWindingDirection ); #ifdef DEBUG m_logger.NewGroup( aWindingDirection ? "walk-cw" : "walk-ccw", m_iteration ); m_logger.Log( &path_walk[0], 0, "path-walk" ); m_logger.Log( &path_pre[0], 1, "path-pre" ); m_logger.Log( &path_post[0], 4, "path-post" ); m_logger.Log( ¤t_obs->m_hull, 2, "hull" ); m_logger.Log( current_obs->m_item, 3, "item" ); #endif int len_pre = path_walk[0].Length(); int len_alt = path_walk[1].Length(); LINE walk_path( aPath, path_walk[1] ); bool alt_collides = static_cast<bool>( m_world->CheckColliding( &walk_path, m_itemMask ) ); SHAPE_LINE_CHAIN pnew; if( !m_forceLongerPath && len_alt < len_pre && !alt_collides && !prev_recursive ) { pnew = path_pre[1]; pnew.Append( path_walk[1] ); pnew.Append( path_post[1] ); if( !path_post[1].PointCount() || !path_walk[1].PointCount() ) current_obs = nearestObstacle( LINE( aPath, path_pre[1] ) ); else current_obs = nearestObstacle( LINE( aPath, path_post[1] ) ); prev_recursive = false; } else { pnew = path_pre[0]; pnew.Append( path_walk[0] ); pnew.Append( path_post[0] ); if( !path_post[0].PointCount() || !path_walk[0].PointCount() ) current_obs = nearestObstacle( LINE( aPath, path_pre[0] ) ); else current_obs = nearestObstacle( LINE( aPath, path_walk[0] ) ); if( !current_obs ) { prev_recursive = false; current_obs = nearestObstacle( LINE( aPath, path_post[0] ) ); } else prev_recursive = true; } pnew.Simplify(); aPath.SetShape( pnew ); return IN_PROGRESS; }
int main(void) { walk_path(); print_path(); return 0; }