Example #1
0
u32 CGroupObject::GetObjects(ObjectList& lst)
{
	lst.clear();

    for (ObjectsInGroup::iterator it=m_ObjectsInGroup.begin(); it!=m_ObjectsInGroup.end(); ++it)
        lst.push_back	(it->pObject);

    return lst.size();
}
Example #2
0
/** return a list of data objects where all dependencies appear earlier in the list */
ObjectList<DataObject> Document::sortedDataObjectList() {
  ObjectList<DataObject> sorted;
  ObjectList<DataObject> raw = objectStore()->getObjects<DataObject>();

  sorted.clear();


  // set the flag for all primitives: not strictly necessary
  // since it should have been done in the constructor, but...
  PrimitiveList all_primitives = objectStore()->getObjects<Primitive>();
  int n = all_primitives.size();
  for (int i=0; i<n; i++) {
    all_primitives[i]->setFlag(true);
  }

  // now unset the flags of all output primitives to indicate their parents haven't been
  // put in the sorted list yet
  n = raw.size();
  for (int i=0; i<n; i++) {
    raw[i]->setOutputFlags(false);
  }

  // now place into the sorted list all data objects whose inputs haven't got parents
  // or whose inputs have parents which are already in the sorted list.
  // do this at most n^2 times, which is worse than worse case.
  int i=0;
  while (!raw.isEmpty() && (++i <= n*n)) {
    DataObjectPtr D = raw.takeFirst();
    if (D->inputFlagsSet()) {
      D->setOutputFlags(true);
      sorted.append(D);
    } else {
      raw.append(D); // try again later
    }
  }

  if ((i== n*n) && (n>1)) {
    qDebug() << "Warning: loop detected, File will not be able to be loaded correctly!";
    while (!raw.isEmpty()) {
      DataObjectPtr D = raw.takeFirst();
      sorted.append(D);
    }
  }

  return sorted;
}
Example #3
0
ObjectPtr Game::findObjectByRect(ObjectList &matched_objs, int left, int top, int right, int bottom, unsigned int flags)
{
	ObjectList &objs = this->getObjectList();
	
	matched_objs.clear();
	for(ObjectList::const_iterator it = objs.begin(); it != objs.end(); ++it)
	{
		const ObjectPtr &obj = *it;
		if(obj->insideRect(left, top, right, bottom))
		{
			//fprintf(stderr, "adding object %s\n", obj->getObjectName());
			matched_objs.addObject(obj);
		}
	}
	
	if(matched_objs.empty())
		return ObjectPtr();
	else
		return *matched_objs.begin();
}
Example #4
0
void TaskAggregation::get_task_parts_aux(ObjectList<TaskPart>& result, ObjectList<Statement> &current_prologue, Statement stmt)
{
    if (is_pragma_custom_construct("omp", "task", stmt.get_ast(), stmt.get_scope_link()))
    {
        PragmaCustomConstruct task_construct(stmt.get_ast(), stmt.get_scope_link());
        TaskPart new_task_part(current_prologue, task_construct);
        result.append(new_task_part);
        current_prologue.clear();
    }
    else if (stmt.is_compound_statement())
    {
        ObjectList<Statement> stmt_list = stmt.get_inner_statements();
        for (ObjectList<Statement>::iterator it = stmt_list.begin();
                it != stmt_list.end();
                it++)
        {
            get_task_parts_aux(result, current_prologue, *it);
        }
    }
    else
    {
        current_prologue.append(stmt);
    }
}
    Symbol Overload::solve(
            ObjectList<Symbol> candidate_functions,
            Type implicit_argument_type,
            ObjectList<Type> argument_types, 
            const std::string filename,
            int line,
            bool &valid, 
            ObjectList<Symbol>& viable_functions,
            ObjectList<Symbol>& argument_conversor)
    {
        valid = false;

        // Try hard to not to do useless work
        if (candidate_functions.empty())
        {
            return Symbol(NULL);
        }

        scope_entry_list_t* first_candidate_list = NULL;
        
        // Build the candidates list
        for (ObjectList<Symbol>::iterator it = candidate_functions.begin();
                it != candidate_functions.end();
                it++)
        {
            Symbol sym(*it);
            first_candidate_list = entry_list_add(first_candidate_list, sym.get_internal_symbol());
        }

        // Build the type array
        unsigned int i = argument_types.size();
        type_t** argument_types_array = new type_t*[argument_types.size() + 1];
        argument_types_array[0] = implicit_argument_type.get_internal_type();
        for (i = 0; i < argument_types.size(); i++)
        {
            argument_types_array[i+1] = argument_types[i].get_internal_type();
        }

        // Now we need a decl_context_t but we were not given any explicitly,
        // use the one of the first candidate
        decl_context_t decl_context = candidate_functions[0].get_scope().get_decl_context();

        // Unfold and mix!
        scope_entry_list_t* candidate_list = NULL;
        candidate_list = unfold_and_mix_candidate_functions(first_candidate_list,
                NULL /* builtins */,
                &argument_types_array[1], argument_types.size(),
                decl_context,
                uniquestr(filename.c_str()), line,
                NULL /* explicit template arguments */);

        {
            ObjectList<Symbol> list;
            Scope::convert_to_vector(candidate_list, list);
            viable_functions.append(list);
        }

        candidate_t* candidate_set = NULL;

        scope_entry_list_iterator_t* it = NULL;
        for (it = entry_list_iterator_begin(candidate_list);
                !entry_list_iterator_end(it);
                entry_list_iterator_next(it))
        {
            scope_entry_t* entry = entry_list_iterator_current(it);
            if (entry->entity_specs.is_member)
            {
                candidate_set = add_to_candidate_set(candidate_set,
                        entry,
                        argument_types.size() + 1,
                        argument_types_array);
            }
            else
            {
                candidate_set = add_to_candidate_set(candidate_set,
                        entry,
                        argument_types.size(),
                        argument_types_array + 1);
            }
        }
        entry_list_iterator_free(it);

        // We also need a scope_entry_t** for holding the conversor argument
        scope_entry_t** conversor_per_argument = new scope_entry_t*[argument_types.size() + 1];

        // Now invoke all the machinery
        scope_entry_t* entry_result =
        solve_overload(candidate_set,
                decl_context,
                uniquestr(filename.c_str()), line,
                conversor_per_argument);

        if (entry_result != NULL)
        {
            valid = true;
            // Store the arguments
            argument_conversor.clear();
            for (i = 0; i < argument_types.size(); i++)
            {
                argument_conversor.append(Symbol(conversor_per_argument[i]));
            }
        }

        // Free the conversor per argument
        delete[] conversor_per_argument;

        // Free the type array
        delete[] argument_types_array;

        // Free the scope entry list
        free_scope_entry_list(candidate_list);

        // This one has been allocated above
        free_scope_entry_list(first_candidate_list);

        return Symbol(entry_result);
    }
Example #6
0
// get the best cut possible for this bounding box
Plane_Cut BSPTree::getBestCut(ObjectList objects, BoundingBox box)
{
	// initialize struct
	Plane_Cut bestCut;
	bool random_cut = false;
	int cost_per_object = 8;
	int cost_per_plane = 1;
	
	// cost of the total
	float cost_no_split = cost_per_object * objects.size();

	// get random cut
	if (random_cut){
		bestCut.axis = std::rand()%3;
		float dist = (box.Max())[bestCut.axis]- (box.Min())[bestCut.axis];
		bestCut.pos = (box.Min())[bestCut.axis] + dist/2;
	}

	// other wise
	else{
		// implementing hueristics
		int lowestCost = std::numeric_limits<int>::max();

		// if too many objects, check few splits
		// if (objects.size()>500){
		// 	nSplits = 1;
		// }

		// check along all three axis
		for (int i=0;i<3;i++){

			// generate checking positions
			for (int j=1;j<=nSplits;j++){

				// generate splitting positions
				float dist = (box.Max())[i] - (box.Min())[i];
				float splitPos = box.Min()[i] + (j*(1.0/(nSplits+1.0)))*dist;

				// find bounding boxes at these split pos
				BoundingBox below = getBelowBoundingBox(box,i,splitPos);
				BoundingBox above = getAboveBoundingBox(box,i,splitPos);

				// find objects in the box
				ObjectList objsAbove = objsInBox(objects,above);
				ObjectList objsBelow = objsInBox(objects,below);

				// find the difference
				int diff = std::abs( (int) (objsAbove.size()-objsBelow.size()) );

				// find the probability of hitting
				float pBelow = below.Area()/box.Area();
				float pAbove = above.Area()/box.Area();

				// find the cost
				float cost_split = 2*cost_per_plane +
									pBelow * objsBelow.size() * cost_per_object +
									pAbove * objsAbove.size() * cost_per_object;

				// // if lower save
				if (cost_split < lowestCost){
					lowestCost = cost_split;
					bestCut.axis = i;
					bestCut.pos = splitPos;
					// noObjsAbove = objsAbove.size();
					// noObjsBelow = objsBelow.size();
				} 

				// clear both lists
				objsAbove.clear();
				objsBelow.clear();
			}
		}

		if (lowestCost >= cost_no_split){
			bestCut.axis = -1;
		}
	}

	return bestCut;
}