Advertisement
Guest User

Untitled

a guest
May 7th, 2017
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.68 KB | None | 0 0
  1. From 8218925f7e6c9818f273e7b0877a3472f1d1c271 Mon Sep 17 00:00:00 2001
  2. From: John Stumpo <stump@jstump.com>
  3. Date: Mon, 14 Dec 2009 07:37:13 -0500
  4. Subject: [PATCH 1/6] Change a couple of unnecessarily non-const iterators into const_iterators to make MSVC happy.
  5.  
  6. ---
  7. game/players.cc | 2 +-
  8. game/songitems.cc | 2 +-
  9. 2 files changed, 2 insertions(+), 2 deletions(-)
  10.  
  11. diff --git a/game/players.cc b/game/players.cc
  12. index 47188c6..1982bdf 100644
  13. --- a/game/players.cc
  14. +++ b/game/players.cc
  15. @@ -72,7 +72,7 @@ int Players::lookup(std::string const& name) const {
  16. std::string Players::lookup(int id) const {
  17. PlayerItem pi;
  18. pi.id = id;
  19. - players_t::iterator it = m_players.find(pi);
  20. + players_t::const_iterator it = m_players.find(pi);
  21. if (it == m_players.end()) return "Unkown Player";
  22. else return it->name;
  23. }
  24. diff --git a/game/songitems.cc b/game/songitems.cc
  25. index 8e78ae0..a35a434 100644
  26. --- a/game/songitems.cc
  27. +++ b/game/songitems.cc
  28. @@ -86,7 +86,7 @@ int SongItems::lookup(boost::shared_ptr<Song> song) const {
  29. std::string SongItems::lookup (int id) const {
  30. SongItem si;
  31. si.id = id;
  32. - songs_t::iterator it = m_songs.find(si);
  33. + songs_t::const_iterator it = m_songs.find(si);
  34. if (it == m_songs.end()) return "Unkown Song";
  35. else if (!it->song) return it->artist + " - " + it->title;
  36. else return it->song->artist + " - " + it->song->title;
  37. --
  38. 1.6.5.1.1367.gcd48
  39.  
  40. From f471e516cd20ab41fa7b067c465ac2723ccf776a Mon Sep 17 00:00:00 2001
  41. From: John Stumpo <stump@jstump.com>
  42. Date: Mon, 14 Dec 2009 07:39:10 -0500
  43. Subject: [PATCH 2/6] Fix the preprocessor test in dll.cc to actually do the correct test for Windows - this was breaking under MSVC.
  44.  
  45. ---
  46. libs/plugin++/src/dll.cc | 2 +-
  47. 1 files changed, 1 insertions(+), 1 deletions(-)
  48.  
  49. diff --git a/libs/plugin++/src/dll.cc b/libs/plugin++/src/dll.cc
  50. index 21e69b8..2414d09 100644
  51. --- a/libs/plugin++/src/dll.cc
  52. +++ b/libs/plugin++/src/dll.cc
  53. @@ -4,7 +4,7 @@
  54.  
  55. using namespace plugin;
  56.  
  57. -#ifdef __WIN32
  58. +#ifdef _WIN32
  59.  
  60. #include <windows.h>
  61.  
  62. --
  63. 1.6.5.1.1367.gcd48
  64.  
  65. From ad3d5ab970d7b37492888f5ae74943c42941573e Mon Sep 17 00:00:00 2001
  66. From: John Stumpo <stump@jstump.com>
  67. Date: Mon, 14 Dec 2009 08:19:21 -0500
  68. Subject: [PATCH 3/6] Conditionally include stdint.h where necessary under MSVC.
  69.  
  70. ---
  71. game/midifile.hh | 4 ++++
  72. game/util.hh | 3 +++
  73. 2 files changed, 7 insertions(+), 0 deletions(-)
  74.  
  75. diff --git a/game/midifile.hh b/game/midifile.hh
  76. index aee0830..0845ca9 100644
  77. --- a/game/midifile.hh
  78. +++ b/game/midifile.hh
  79. @@ -4,7 +4,11 @@
  80. #include <string>
  81. #include <vector>
  82.  
  83. +#ifdef _MSC_VER
  84. +#include <stdint.h>
  85. +#else
  86. using boost::uint32_t;
  87. +#endif
  88.  
  89. #if 0
  90.  
  91. diff --git a/game/util.hh b/game/util.hh
  92. index e00fcef..6254634 100644
  93. --- a/game/util.hh
  94. +++ b/game/util.hh
  95. @@ -2,6 +2,9 @@
  96.  
  97. #include <limits>
  98. #include <stdexcept>
  99. +#ifdef _MSC_VER
  100. +#include <stdint.h>
  101. +#endif
  102.  
  103. /** Implement C99 mathematical rounding (which C++ unfortunately currently lacks) **/
  104. template <typename T> T round(T val) { return int(val + (val >= 0 ? 0.5 : -0.5)); }
  105. --
  106. 1.6.5.1.1367.gcd48
  107.  
  108. From 789d3c3b4e974dfe037a395e7798557dd3c7066f Mon Sep 17 00:00:00 2001
  109. From: John Stumpo <stump@jstump.com>
  110. Date: Mon, 14 Dec 2009 08:31:05 -0500
  111. Subject: [PATCH 4/6] Use SDL_image instead of Magick++ to load images if SDL_image is available.
  112.  
  113. ---
  114. game/CMakeLists.txt | 10 ++++++++++
  115. game/surface.cc | 23 ++++++++++++++++++++++-
  116. 2 files changed, 32 insertions(+), 1 deletions(-)
  117.  
  118. diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
  119. index 7c411c9..0b58bf3 100644
  120. --- a/game/CMakeLists.txt
  121. +++ b/game/CMakeLists.txt
  122. @@ -47,6 +47,16 @@ else()
  123. message(STATUS "MIDI I/O: Disabled (libportmidi not found)")
  124. endif()
  125.  
  126. +find_package(SDL_image)
  127. +if(SDL_image_FOUND)
  128. + include_directories(${SDL_image_INCLUDE_DIRS})
  129. + add_definitions(-DLESS_MAGIC) # ;)
  130. + list(APPEND LIBS ${SDL_image_LIBRARIES})
  131. + message(STATUS "SDL_image: found, enabling replacements for Magick++ code")
  132. +else()
  133. + message(STATUS "SDL_image: not found, falling back to Magick++")
  134. +endif()
  135. +
  136. # Set default compile flags for GCC
  137. if(CMAKE_COMPILER_IS_GNUCXX)
  138. message(STATUS "GCC detected, adding compile flags")
  139. diff --git a/game/surface.cc b/game/surface.cc
  140. index f46936f..d98cddc 100644
  141. --- a/game/surface.cc
  142. +++ b/game/surface.cc
  143. @@ -6,13 +6,17 @@
  144.  
  145. #include <librsvg/rsvg.h>
  146. #include <librsvg/rsvg-cairo.h>
  147. +#ifdef LESS_MAGIC
  148. +#include <SDL_image.h>
  149. +#else
  150. #include <Magick++.h>
  151. +using boost::uint32_t;
  152. +#endif
  153. #include <fstream>
  154. #include <stdexcept>
  155. #include <sstream>
  156. #include <vector>
  157.  
  158. -using boost::uint32_t;
  159.  
  160. float Dimensions::screenY() const {
  161. switch (m_screenAnchor) {
  162. @@ -85,6 +89,22 @@ template <typename T> void loader(T& target, std::string filename, bool autocrop
  163. gdk_pixbuf_unref(pb);
  164. rsvg_term();
  165. } else {
  166. +#ifdef LESS_MAGIC
  167. + IMG_Init(0);
  168. + SDL_Surface* imgsurf = IMG_Load(filename.c_str());
  169. + IMG_Quit();
  170. + if (imgsurf == NULL) {
  171. + throw std::runtime_error("Unable to load " + filename + ": " + IMG_GetError());
  172. + }
  173. + // TODO: blit to a new RGBA surface to ensure it actually *is* RGBA
  174. + try {
  175. + target.load(imgsurf->w, imgsurf->h, pix::CHAR_RGBA, reinterpret_cast<const unsigned char*>(imgsurf->pixels));
  176. + SDL_FreeSurface(imgsurf);
  177. + } catch (...) {
  178. + SDL_FreeSurface(imgsurf);
  179. + throw;
  180. + }
  181. +#else
  182. Magick::Image image;
  183. Magick::Blob blob;
  184. try {
  185. @@ -112,6 +132,7 @@ template <typename T> void loader(T& target, std::string filename, bool autocrop
  186. {
  187. throw std::runtime_error("Image Error");
  188. }
  189. +#endif
  190. }
  191. }
  192.  
  193. --
  194. 1.6.5.1.1367.gcd48
  195.  
  196. From 7e560393bbb9f73cdf29ab6b24748f8ba9a6125c Mon Sep 17 00:00:00 2001
  197. From: John Stumpo <stump@jstump.com>
  198. Date: Mon, 14 Dec 2009 08:39:43 -0500
  199. Subject: [PATCH 5/6] Replace the Magick++-based png-emitting screenshot code with a quickly-hacked-up uncompressed TGA writer if we are using SDL_image instead of Magick++.
  200.  
  201. ---
  202. game/video_driver.cc | 39 +++++++++++++++++++++++++++++++++++----
  203. 1 files changed, 35 insertions(+), 4 deletions(-)
  204.  
  205. diff --git a/game/video_driver.cc b/game/video_driver.cc
  206. index ac6a69d..3a7c3b8 100644
  207. --- a/game/video_driver.cc
  208. +++ b/game/video_driver.cc
  209. @@ -7,7 +7,12 @@
  210. #include "joystick.hh"
  211.  
  212. #include <SDL.h>
  213. +#ifdef LESS_MAGIC
  214. +#include <sstream>
  215. +#include <fstream>
  216. +#else
  217. #include <Magick++.h>
  218. +#endif
  219.  
  220. namespace {
  221. unsigned s_width;
  222. @@ -63,8 +68,35 @@ void Window::screenshot() {
  223.  
  224. std::vector<char> buffer(width*height*3);
  225. glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
  226. + std::ostringstream fnstr;
  227. + fnstr << "/tmp/performous_screenshot_" << count;
  228. +#ifdef LESS_MAGIC
  229. + /* Write the image out as an uncompressed tga. */
  230. + fnstr << ".tga";
  231. + std::ofstream tgaout(fnstr.str().c_str(), std::ios::binary);
  232. + char tga_hdr_part1[] = {
  233. + 0x00, /* no identification field */
  234. + 0x00, /* no palette */
  235. + 0x02, /* 24-bit RGB */
  236. + 0x00, 0x00, 0x00, 0x00, 0x00, /* palette info (ignored) */
  237. + 0x00, 0x00, /* x-origin */
  238. + 0x00, 0x00, /* y-origin */
  239. + };
  240. + tgaout.write(tga_hdr_part1, sizeof(tga_hdr_part1));
  241. + /* two 16-bit little endian words for width and height */
  242. + tgaout << static_cast<char>(width & 0xff);
  243. + tgaout << static_cast<char>(width >> 8);
  244. + tgaout << static_cast<char>(height & 0xff);
  245. + tgaout << static_cast<char>(height >> 8);
  246. + tgaout << static_cast<char>(24); /* bits per pixel */
  247. + tgaout << static_cast<char>(0x00); /* no special flags */
  248. + for (int i = 0; i < width*height*3; i += 3)
  249. + std::swap(buffer[i], buffer[i+2]); /* fix the channel order */
  250. + tgaout.write(&buffer[0], width*height*3); /* dump the image data */
  251. + tgaout.close();
  252. +#else
  253. + fnstr << ".png";
  254. Magick::Blob blob( &buffer[0], width*height*3);
  255. -
  256. Magick::Image image;
  257. char geometry[16];
  258. sprintf(geometry,"%dx%d",width,height);
  259. @@ -73,9 +105,8 @@ void Window::screenshot() {
  260. image.magick( "RGB" );
  261. image.read(blob);
  262. image.flip();
  263. - char filename[256];
  264. - sprintf(filename,"/tmp/performous_screenshot_%u.png",count);
  265. - image.write(filename);
  266. + image.write(fnstr.str().c_str());
  267. +#endif
  268. count++;
  269. }
  270.  
  271. --
  272. 1.6.5.1.1367.gcd48
  273.  
  274. From db78b76cf0de5a11de63e7dca1ece1305a0117ec Mon Sep 17 00:00:00 2001
  275. From: John Stumpo <stump@jstump.com>
  276. Date: Mon, 14 Dec 2009 08:43:37 -0500
  277. Subject: [PATCH 6/6] Use the standard Windows temp directory as returned by GetTempPathA() (as opposed to "/tmp") for screenshots under Windows.
  278.  
  279. Also fix some variable names that the Windows headers #define to nothing.
  280. ---
  281. game/video_driver.cc | 23 ++++++++++++++++++-----
  282. 1 files changed, 18 insertions(+), 5 deletions(-)
  283.  
  284. diff --git a/game/video_driver.cc b/game/video_driver.cc
  285. index 3a7c3b8..8dbd640 100644
  286. --- a/game/video_driver.cc
  287. +++ b/game/video_driver.cc
  288. @@ -14,6 +14,11 @@
  289. #include <Magick++.h>
  290. #endif
  291.  
  292. +#ifdef _WIN32
  293. +// for GetTempPathA
  294. +#include <windows.h>
  295. +#endif
  296. +
  297. namespace {
  298. unsigned s_width;
  299. unsigned s_height;
  300. @@ -69,7 +74,14 @@ void Window::screenshot() {
  301. std::vector<char> buffer(width*height*3);
  302. glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
  303. std::ostringstream fnstr;
  304. - fnstr << "/tmp/performous_screenshot_" << count;
  305. +#ifdef _WIN32
  306. + char tmppath[256];
  307. + GetTempPathA(256, tmppath); /* this includes a backslash at the end */
  308. + fnstr << tmppath;
  309. +#else
  310. + fnstr << "/tmp/";
  311. +#endif
  312. + fnstr << "performous_screenshot_" << count;
  313. #ifdef LESS_MAGIC
  314. /* Write the image out as an uncompressed tga. */
  315. fnstr << ".tga";
  316. @@ -150,14 +162,15 @@ void Window::resize() {
  317. glMatrixMode(GL_PROJECTION);
  318. glLoadIdentity();
  319. float h = virtH();
  320. - const float near = 1.5f; // This determines FOV: the value is your distance from the monitor (the unit being the width of the Performous window)
  321. - const float far = 100.0f; // How far away can things be seen
  322. + // stump: under MSVC, near and far are #defined to nothing for compatibility with ancient code, hence the underscores.
  323. + const float near_ = 1.5f; // This determines FOV: the value is your distance from the monitor (the unit being the width of the Performous window)
  324. + const float far_ = 100.0f; // How far away can things be seen
  325. // Set model-view matrix
  326. glMatrixMode(GL_MODELVIEW);
  327. glLoadIdentity();
  328. const float f = 0.9f; // Avoid texture surface being exactly at the near plane (MacOSX fix)
  329. - glFrustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, f * near, far);
  330. - glTranslatef(0.0f, 0.0f, -near); // So that z = 0.0f is still on monitor surface
  331. + glFrustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, f * near_, far_);
  332. + glTranslatef(0.0f, 0.0f, -near_); // So that z = 0.0f is still on monitor surface
  333.  
  334. }
  335.  
  336. --
  337. 1.6.5.1.1367.gcd48
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement