Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.91 KB | None | 0 0
  1. Index: src/unit_frame.cpp
  2. ===================================================================
  3. --- src/unit_frame.cpp (révision 48595)
  4. +++ src/unit_frame.cpp (copie de travail)
  5. @@ -663,13 +663,24 @@
  6. result.insert(src.get_direction(map_location::SOUTH_WEST));
  7. }
  8. } else {
  9. - surface image;
  10. - if(!image_loc.is_void() && image_loc.get_filename() != "") { // invalid diag image, or not diagonal
  11. - image=image::get_image(image_loc,
  12. - image::SCALED_TO_ZOOM
  13. - );
  14. + int w=0;
  15. + int h =0;
  16. +#ifdef _OPENMP
  17. +#pragma omp critical(image_cache)
  18. +#endif //_OPENMP
  19. + {
  20. + surface image;
  21. + if(!image_loc.is_void() && image_loc.get_filename() != "") { // invalid diag image, or not diagonal
  22. + image=image::get_image(image_loc,
  23. + image::SCALED_TO_ZOOM
  24. + );
  25. + }
  26. + if(image != NULL) {
  27. + w = image->w;
  28. + h = image->h;
  29. + }
  30. }
  31. - if (image != NULL) {
  32. + if (w != 0 || h != 0) {
  33. const int x = static_cast<int>(tmp_offset * xdst + (1.0-tmp_offset) * xsrc);
  34. const int y = static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * ysrc);
  35. #ifdef LOW_MEM
  36. @@ -680,8 +691,8 @@
  37. bool facing_north = direction == map_location::NORTH_WEST || direction == map_location::NORTH || direction == map_location::NORTH_EAST;
  38. if(!current_data.auto_vflip) facing_north = true;
  39. if(!current_data.auto_hflip) facing_west = false;
  40. - int my_x = x +current_data.x+d2- image->w/2;
  41. - int my_y = y +current_data.y+d2- image->h/2;
  42. + int my_x = x +current_data.x+d2- w/2;
  43. + int my_y = y +current_data.y+d2- h/2;
  44. if(facing_west) {
  45. my_x += current_data.directional_x;
  46. } else {
  47. @@ -693,7 +704,7 @@
  48. my_y -= current_data.directional_y;
  49. }
  50.  
  51. - const SDL_Rect r = create_rect(my_x, my_y, image->w, image->h);
  52. + const SDL_Rect r = create_rect(my_x, my_y, w, h);
  53. // check if our underlying hexes are invalidated
  54. // if we need to update ourselve because we changed, invalidate our hexes
  55. // and return whether or not our hexs was invalidated
  56. Index: src/display.cpp
  57. ===================================================================
  58. --- src/display.cpp (révision 48595)
  59. +++ src/display.cpp (copie de travail)
  60. @@ -2416,6 +2416,9 @@
  61. {
  62. DBG_DP << "invalidate_all()\n";
  63. invalidateAll_ = true;
  64. +#ifdef _OPENMP
  65. +#pragma omp critical(invalidated_)
  66. +#endif //_OPENMP
  67. invalidated_.clear();
  68. update_rect(map_area());
  69. }
  70. @@ -2425,7 +2428,12 @@
  71. if(invalidateAll_)
  72. return false;
  73.  
  74. - return invalidated_.insert(loc).second;
  75. + bool tmp;
  76. +#ifdef _OPENMP
  77. +#pragma omp critical(invalidated_)
  78. +#endif //_OPENMP
  79. + tmp = invalidated_.insert(loc).second;
  80. + return tmp;
  81. }
  82.  
  83. bool display::invalidate(const std::set<map_location>& locs)
  84. @@ -2434,6 +2442,9 @@
  85. return false;
  86. bool ret = false;
  87. foreach (const map_location& loc, locs) {
  88. +#ifdef _OPENMP
  89. +#pragma omp critical(invalidated_)
  90. +#endif //_OPENMP
  91. ret = invalidated_.insert(loc).second || ret;
  92. }
  93. return ret;
  94. @@ -2447,20 +2458,27 @@
  95. if(locs.size()<=1)
  96. return false; // propagation never needed
  97.  
  98. + bool result = false;
  99. +#ifdef _OPENMP
  100. +#pragma omp critical(invalidated_)
  101. +#endif //_OPENMP
  102. +{
  103. // search the first hex invalidated (if any)
  104. std::set<map_location>::const_iterator i = locs.begin();
  105. for(; i != locs.end() && invalidated_.count(*i) == 0 ; ++i) {}
  106.  
  107. - if (i == locs.end())
  108. - return false; // no invalidation, don't propagate
  109. + if (i != locs.end()) {
  110.  
  111. - // propagate invalidation
  112. - // 'i' is already in, but I suspect that splitting the range is bad
  113. - // especially because locs are often adjacents
  114. - size_t previous_size = invalidated_.size();
  115. - invalidated_.insert(locs.begin(), locs.end());
  116. - return previous_size < invalidated_.size();
  117. + // propagate invalidation
  118. + // 'i' is already in, but I suspect that splitting the range is bad
  119. + // especially because locs are often adjacents
  120. + size_t previous_size = invalidated_.size();
  121. + invalidated_.insert(locs.begin(), locs.end());
  122. + result = previous_size < invalidated_.size();
  123. + }
  124. }
  125. + return result;
  126. +}
  127.  
  128. bool display::invalidate_visible_locations_in_rect(const SDL_Rect& rect)
  129. {
  130. Index: src/game_display.cpp
  131. ===================================================================
  132. --- src/game_display.cpp (révision 48595)
  133. +++ src/game_display.cpp (copie de travail)
  134. @@ -905,16 +905,24 @@
  135. foreach(unit* temp_unit, temp_units_) {
  136. temp_unit->refresh();
  137. }
  138. - bool new_inval = true;
  139. - while(new_inval) {
  140. + std::vector<unit*> unit_list;
  141. + foreach (unit &u, units_) {
  142. + unit_list.push_back(&u);
  143. + }
  144. + foreach (unit *u, temp_units_) {
  145. + unit_list.push_back(u);
  146. + }
  147. + bool new_inval;
  148. + do {
  149. new_inval = false;
  150. - foreach (unit& u, units_) {
  151. - new_inval |= u.invalidate(u.get_location());
  152. +#ifdef _OPENMP
  153. +#pragma omp parallel for reduction(|:new_inval) shared(unit_list) schedule(guided)
  154. +#endif //_OPENMP
  155. + for(unsigned int i=0; i < unit_list.size(); i++) {
  156. +#pragma omp criticall(debug)
  157. + new_inval |= unit_list[i]->invalidate(unit_list[i]->get_location());
  158. }
  159. - foreach(unit* temp_unit, temp_units_) {
  160. - new_inval |= temp_unit->invalidate(temp_unit->get_location());
  161. - }
  162. - }
  163. + }while(new_inval);
  164. }
  165.  
  166. int& game_display::debug_highlight(const map_location& loc)
  167. Index: src/image.cpp
  168. ===================================================================
  169. --- src/image.cpp (révision 48595)
  170. +++ src/image.cpp (copie de travail)
  171. @@ -146,19 +146,24 @@
  172.  
  173. void flush_cache()
  174. {
  175. - images_.flush();
  176. - hexed_images_.flush();
  177. - tod_colored_images_.flush();
  178. - scaled_to_zoom_.flush();
  179. - scaled_to_hex_images_.flush();
  180. - brightened_images_.flush();
  181. - semi_brightened_images_.flush();
  182. - in_hex_info_.flush();
  183. - mini_terrain_cache.clear();
  184. - mini_fogged_terrain_cache.clear();
  185. - reversed_images_.clear();
  186. - image_existence_map.clear();
  187. - precached_dirs.clear();
  188. +#ifdef _OPENMP
  189. +#pragma omp critical(image_cache)
  190. +#endif //_OPENMP
  191. + {
  192. + images_.flush();
  193. + hexed_images_.flush();
  194. + tod_colored_images_.flush();
  195. + scaled_to_zoom_.flush();
  196. + scaled_to_hex_images_.flush();
  197. + brightened_images_.flush();
  198. + semi_brightened_images_.flush();
  199. + in_hex_info_.flush();
  200. + mini_terrain_cache.clear();
  201. + mini_fogged_terrain_cache.clear();
  202. + reversed_images_.clear();
  203. + image_existence_map.clear();
  204. + precached_dirs.clear();
  205. + }
  206. /* We can't reset last_index_, since some locators are still alive
  207. when using :refresh. That would cause them to point to the wrong
  208. images. Not resetting the variable causes a memory leak, though. */
  209. @@ -1054,61 +1059,67 @@
  210. image_cache *imap;
  211. // select associated cache
  212. switch(type) {
  213. - case UNSCALED:
  214. - imap = &images_;
  215. - break;
  216. - case TOD_COLORED:
  217. - imap = &tod_colored_images_;
  218. - break;
  219. - case SCALED_TO_ZOOM:
  220. - imap = &scaled_to_zoom_;
  221. - break;
  222. - case HEXED:
  223. - imap = &hexed_images_;
  224. - break;
  225. - case SCALED_TO_HEX:
  226. - imap = &scaled_to_hex_images_;
  227. - break;
  228. - case BRIGHTENED:
  229. - imap = &brightened_images_;
  230. - break;
  231. - case SEMI_BRIGHTENED:
  232. - imap = &semi_brightened_images_;
  233. - break;
  234. - default:
  235. - return res;
  236. + case UNSCALED:
  237. + imap = &images_;
  238. + break;
  239. + case TOD_COLORED:
  240. + imap = &tod_colored_images_;
  241. + break;
  242. + case SCALED_TO_ZOOM:
  243. + imap = &scaled_to_zoom_;
  244. + break;
  245. + case HEXED:
  246. + imap = &hexed_images_;
  247. + break;
  248. + case SCALED_TO_HEX:
  249. + imap = &scaled_to_hex_images_;
  250. + break;
  251. + case BRIGHTENED:
  252. + imap = &brightened_images_;
  253. + break;
  254. + case SEMI_BRIGHTENED:
  255. + imap = &semi_brightened_images_;
  256. + break;
  257. + default:
  258. + return res;
  259. }
  260.  
  261. // return the image if already cached
  262. - if(i_locator.in_cache(*imap))
  263. - return i_locator.locate_in_cache(*imap);
  264. + bool tmp;
  265. + tmp=i_locator.in_cache(*imap);
  266.  
  267. + if(tmp) {
  268. + surface result;
  269. + result = i_locator.locate_in_cache(*imap);
  270. + return result;
  271. + }
  272. +
  273. // not cached, generate it
  274. switch(type) {
  275. - case UNSCALED:
  276. - // If type is unscaled, directly load the image from the disk.
  277. - res = i_locator.load_from_disk();
  278. - break;
  279. - case TOD_COLORED:
  280. - res = get_tod_colored(i_locator);
  281. - break;
  282. - case SCALED_TO_ZOOM:
  283. - res = get_scaled_to_zoom(i_locator);
  284. - break;
  285. - case HEXED:
  286. - res = get_hexed(i_locator);
  287. - break;
  288. - case SCALED_TO_HEX:
  289. - res = get_scaled_to_hex(i_locator);
  290. - break;
  291. - case BRIGHTENED:
  292. - res = get_brightened(i_locator);
  293. - break;
  294. - case SEMI_BRIGHTENED:
  295. - res = get_semi_brightened(i_locator);
  296. - break;
  297. - default:
  298. - return res;
  299. + case UNSCALED:
  300. + // If type is unscaled, directly load the image from the disk.
  301. + res = i_locator.load_from_disk();
  302. + break;
  303. + case TOD_COLORED:
  304. + res = get_tod_colored(i_locator);
  305. + break;
  306. + case SCALED_TO_ZOOM:
  307. + res = get_scaled_to_zoom(i_locator);
  308. + break;
  309. + case HEXED:
  310. + res = get_hexed(i_locator);
  311. + break;
  312. + case SCALED_TO_HEX:
  313. + res = get_scaled_to_hex(i_locator);
  314. + break;
  315. + case BRIGHTENED:
  316. + res = get_brightened(i_locator);
  317. + break;
  318. + case SEMI_BRIGHTENED:
  319. + res = get_semi_brightened(i_locator);
  320. + break;
  321. + default:
  322. + return res;
  323. }
  324.  
  325. // Optimizes surface before storing it
  326. @@ -1128,8 +1139,13 @@
  327.  
  328. bool is_in_hex(const locator& i_locator)
  329. {
  330. + bool result;
  331. +#ifdef _OPENMP
  332. +#pragma omp critical(in_hex_info_)
  333. +#endif //_OPENMP
  334. + {
  335. if(i_locator.in_cache(in_hex_info_)) {
  336. - return i_locator.locate_in_cache(in_hex_info_);
  337. + result= i_locator.locate_in_cache(in_hex_info_);
  338. } else {
  339. const surface image(get_image(i_locator, UNSCALED));
  340.  
  341. @@ -1140,8 +1156,10 @@
  342. //std::cout << "in_hex : " << i_locator.get_filename()
  343. // << " " << (res ? "yes" : "no") << "\n";
  344.  
  345. - return res;
  346. + result= res;
  347. }
  348. + }
  349. + return result;
  350. }
  351.  
  352.  
  353. Index: src/unit.cpp
  354. ===================================================================
  355. --- src/unit.cpp (révision 48595)
  356. +++ src/unit.cpp (copie de travail)
  357. @@ -1993,10 +1993,11 @@
  358. {
  359. bool result = false;
  360.  
  361. + {
  362. // Very early calls, anim not initialized yet
  363. if(get_animation()) {
  364. frame_parameters params;
  365. - game_display * disp = game_display::get_singleton();
  366. + const game_display * disp = game_display::get_singleton();
  367. const gamemap & map = disp->get_map();
  368. const t_translation::t_terrain terrain = map.get_terrain(loc);
  369. const terrain_type& terrain_info = map.get_terrain_info(terrain);
  370. @@ -2011,6 +2012,7 @@
  371.  
  372. result |= get_animation()->invalidate(params);
  373. }
  374. + }
  375.  
  376. return result;
  377.  
  378. Index: src/display.hpp
  379. ===================================================================
  380. --- src/display.hpp (révision 48595)
  381. +++ src/display.hpp (copie de travail)
  382. @@ -297,14 +297,6 @@
  383. */
  384. virtual void invalidate_animations_location(const map_location& /*loc*/) {}
  385.  
  386. - /**
  387. - * What hex are currently invalidated (read only)
  388. - * used for some fine grained invalidation algorithm which need recurstion
  389. - */
  390. - const std::set<map_location> & get_invalidated() const { return invalidated_; }
  391. -
  392. -
  393. -
  394. const gamemap& get_map() const { return *map_; }
  395.  
  396. /**
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement