src/engine.cpp
changeset 10737 0f704b9afd93
parent 10707 81a4013a7680
child 10775 7061477bfbcf
equal deleted inserted replaced
10736:e3111a03f9c2 10737:0f704b9afd93
   113 {
   113 {
   114 	UnloadWagonOverrides(this);
   114 	UnloadWagonOverrides(this);
   115 	free(this->name);
   115 	free(this->name);
   116 }
   116 }
   117 
   117 
   118 /** Sort all items using qsort() and given 'CompareItems' function
       
   119  * @param el list to be sorted
       
   120  * @param compare function for evaluation of the quicksort
       
   121  */
       
   122 void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
       
   123 {
       
   124 	size_t size = el->size();
       
   125 	/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
       
   126 	 * generally, do not sort if there are less than 2 items */
       
   127 	if (size < 2) return;
       
   128 	qsort(&((*el)[0]), size, sizeof(EngineID), compare); // MorphOS doesn't know vector::at(int) ...
       
   129 }
       
   130 
       
   131 /** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
       
   132  * @param el list to be sorted
       
   133  * @param compare function for evaluation of the quicksort
       
   134  * @param begin start of sorting
       
   135  * @param num_items count of items to be sorted
       
   136  */
       
   137 void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
       
   138 {
       
   139 	assert(begin <= (uint)el->size());
       
   140 	assert(begin + num_items <= (uint)el->size());
       
   141 	if (num_items < 2) return;
       
   142 	qsort(&((*el)[begin]), num_items, sizeof(EngineID), compare);
       
   143 }
       
   144 
       
   145 
       
   146 /** Sets cached values in Player::num_vehicles and Group::num_vehicles
   118 /** Sets cached values in Player::num_vehicles and Group::num_vehicles
   147  */
   119  */
   148 void SetCachedEngineCounts()
   120 void SetCachedEngineCounts()
   149 {
   121 {
   150 	uint engines = GetEnginePoolSize();
   122 	uint engines = GetEnginePoolSize();