Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 8218925f7e6c9818f273e7b0877a3472f1d1c271 Mon Sep 17 00:00:00 2001
- From: John Stumpo <stump@jstump.com>
- Date: Mon, 14 Dec 2009 07:37:13 -0500
- Subject: [PATCH 1/6] Change a couple of unnecessarily non-const iterators into const_iterators to make MSVC happy.
- ---
- game/players.cc | 2 +-
- game/songitems.cc | 2 +-
- 2 files changed, 2 insertions(+), 2 deletions(-)
- diff --git a/game/players.cc b/game/players.cc
- index 47188c6..1982bdf 100644
- --- a/game/players.cc
- +++ b/game/players.cc
- @@ -72,7 +72,7 @@ int Players::lookup(std::string const& name) const {
- std::string Players::lookup(int id) const {
- PlayerItem pi;
- pi.id = id;
- - players_t::iterator it = m_players.find(pi);
- + players_t::const_iterator it = m_players.find(pi);
- if (it == m_players.end()) return "Unkown Player";
- else return it->name;
- }
- diff --git a/game/songitems.cc b/game/songitems.cc
- index 8e78ae0..a35a434 100644
- --- a/game/songitems.cc
- +++ b/game/songitems.cc
- @@ -86,7 +86,7 @@ int SongItems::lookup(boost::shared_ptr<Song> song) const {
- std::string SongItems::lookup (int id) const {
- SongItem si;
- si.id = id;
- - songs_t::iterator it = m_songs.find(si);
- + songs_t::const_iterator it = m_songs.find(si);
- if (it == m_songs.end()) return "Unkown Song";
- else if (!it->song) return it->artist + " - " + it->title;
- else return it->song->artist + " - " + it->song->title;
- --
- 1.6.5.1.1367.gcd48
- From f471e516cd20ab41fa7b067c465ac2723ccf776a Mon Sep 17 00:00:00 2001
- From: John Stumpo <stump@jstump.com>
- Date: Mon, 14 Dec 2009 07:39:10 -0500
- Subject: [PATCH 2/6] Fix the preprocessor test in dll.cc to actually do the correct test for Windows - this was breaking under MSVC.
- ---
- libs/plugin++/src/dll.cc | 2 +-
- 1 files changed, 1 insertions(+), 1 deletions(-)
- diff --git a/libs/plugin++/src/dll.cc b/libs/plugin++/src/dll.cc
- index 21e69b8..2414d09 100644
- --- a/libs/plugin++/src/dll.cc
- +++ b/libs/plugin++/src/dll.cc
- @@ -4,7 +4,7 @@
- using namespace plugin;
- -#ifdef __WIN32
- +#ifdef _WIN32
- #include <windows.h>
- --
- 1.6.5.1.1367.gcd48
- From ad3d5ab970d7b37492888f5ae74943c42941573e Mon Sep 17 00:00:00 2001
- From: John Stumpo <stump@jstump.com>
- Date: Mon, 14 Dec 2009 08:19:21 -0500
- Subject: [PATCH 3/6] Conditionally include stdint.h where necessary under MSVC.
- ---
- game/midifile.hh | 4 ++++
- game/util.hh | 3 +++
- 2 files changed, 7 insertions(+), 0 deletions(-)
- diff --git a/game/midifile.hh b/game/midifile.hh
- index aee0830..0845ca9 100644
- --- a/game/midifile.hh
- +++ b/game/midifile.hh
- @@ -4,7 +4,11 @@
- #include <string>
- #include <vector>
- +#ifdef _MSC_VER
- +#include <stdint.h>
- +#else
- using boost::uint32_t;
- +#endif
- #if 0
- diff --git a/game/util.hh b/game/util.hh
- index e00fcef..6254634 100644
- --- a/game/util.hh
- +++ b/game/util.hh
- @@ -2,6 +2,9 @@
- #include <limits>
- #include <stdexcept>
- +#ifdef _MSC_VER
- +#include <stdint.h>
- +#endif
- /** Implement C99 mathematical rounding (which C++ unfortunately currently lacks) **/
- template <typename T> T round(T val) { return int(val + (val >= 0 ? 0.5 : -0.5)); }
- --
- 1.6.5.1.1367.gcd48
- From 789d3c3b4e974dfe037a395e7798557dd3c7066f Mon Sep 17 00:00:00 2001
- From: John Stumpo <stump@jstump.com>
- Date: Mon, 14 Dec 2009 08:31:05 -0500
- Subject: [PATCH 4/6] Use SDL_image instead of Magick++ to load images if SDL_image is available.
- ---
- game/CMakeLists.txt | 10 ++++++++++
- game/surface.cc | 23 ++++++++++++++++++++++-
- 2 files changed, 32 insertions(+), 1 deletions(-)
- diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
- index 7c411c9..0b58bf3 100644
- --- a/game/CMakeLists.txt
- +++ b/game/CMakeLists.txt
- @@ -47,6 +47,16 @@ else()
- message(STATUS "MIDI I/O: Disabled (libportmidi not found)")
- endif()
- +find_package(SDL_image)
- +if(SDL_image_FOUND)
- + include_directories(${SDL_image_INCLUDE_DIRS})
- + add_definitions(-DLESS_MAGIC) # ;)
- + list(APPEND LIBS ${SDL_image_LIBRARIES})
- + message(STATUS "SDL_image: found, enabling replacements for Magick++ code")
- +else()
- + message(STATUS "SDL_image: not found, falling back to Magick++")
- +endif()
- +
- # Set default compile flags for GCC
- if(CMAKE_COMPILER_IS_GNUCXX)
- message(STATUS "GCC detected, adding compile flags")
- diff --git a/game/surface.cc b/game/surface.cc
- index f46936f..d98cddc 100644
- --- a/game/surface.cc
- +++ b/game/surface.cc
- @@ -6,13 +6,17 @@
- #include <librsvg/rsvg.h>
- #include <librsvg/rsvg-cairo.h>
- +#ifdef LESS_MAGIC
- +#include <SDL_image.h>
- +#else
- #include <Magick++.h>
- +using boost::uint32_t;
- +#endif
- #include <fstream>
- #include <stdexcept>
- #include <sstream>
- #include <vector>
- -using boost::uint32_t;
- float Dimensions::screenY() const {
- switch (m_screenAnchor) {
- @@ -85,6 +89,22 @@ template <typename T> void loader(T& target, std::string filename, bool autocrop
- gdk_pixbuf_unref(pb);
- rsvg_term();
- } else {
- +#ifdef LESS_MAGIC
- + IMG_Init(0);
- + SDL_Surface* imgsurf = IMG_Load(filename.c_str());
- + IMG_Quit();
- + if (imgsurf == NULL) {
- + throw std::runtime_error("Unable to load " + filename + ": " + IMG_GetError());
- + }
- + // TODO: blit to a new RGBA surface to ensure it actually *is* RGBA
- + try {
- + target.load(imgsurf->w, imgsurf->h, pix::CHAR_RGBA, reinterpret_cast<const unsigned char*>(imgsurf->pixels));
- + SDL_FreeSurface(imgsurf);
- + } catch (...) {
- + SDL_FreeSurface(imgsurf);
- + throw;
- + }
- +#else
- Magick::Image image;
- Magick::Blob blob;
- try {
- @@ -112,6 +132,7 @@ template <typename T> void loader(T& target, std::string filename, bool autocrop
- {
- throw std::runtime_error("Image Error");
- }
- +#endif
- }
- }
- --
- 1.6.5.1.1367.gcd48
- From 7e560393bbb9f73cdf29ab6b24748f8ba9a6125c Mon Sep 17 00:00:00 2001
- From: John Stumpo <stump@jstump.com>
- Date: Mon, 14 Dec 2009 08:39:43 -0500
- 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++.
- ---
- game/video_driver.cc | 39 +++++++++++++++++++++++++++++++++++----
- 1 files changed, 35 insertions(+), 4 deletions(-)
- diff --git a/game/video_driver.cc b/game/video_driver.cc
- index ac6a69d..3a7c3b8 100644
- --- a/game/video_driver.cc
- +++ b/game/video_driver.cc
- @@ -7,7 +7,12 @@
- #include "joystick.hh"
- #include <SDL.h>
- +#ifdef LESS_MAGIC
- +#include <sstream>
- +#include <fstream>
- +#else
- #include <Magick++.h>
- +#endif
- namespace {
- unsigned s_width;
- @@ -63,8 +68,35 @@ void Window::screenshot() {
- std::vector<char> buffer(width*height*3);
- glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
- + std::ostringstream fnstr;
- + fnstr << "/tmp/performous_screenshot_" << count;
- +#ifdef LESS_MAGIC
- + /* Write the image out as an uncompressed tga. */
- + fnstr << ".tga";
- + std::ofstream tgaout(fnstr.str().c_str(), std::ios::binary);
- + char tga_hdr_part1[] = {
- + 0x00, /* no identification field */
- + 0x00, /* no palette */
- + 0x02, /* 24-bit RGB */
- + 0x00, 0x00, 0x00, 0x00, 0x00, /* palette info (ignored) */
- + 0x00, 0x00, /* x-origin */
- + 0x00, 0x00, /* y-origin */
- + };
- + tgaout.write(tga_hdr_part1, sizeof(tga_hdr_part1));
- + /* two 16-bit little endian words for width and height */
- + tgaout << static_cast<char>(width & 0xff);
- + tgaout << static_cast<char>(width >> 8);
- + tgaout << static_cast<char>(height & 0xff);
- + tgaout << static_cast<char>(height >> 8);
- + tgaout << static_cast<char>(24); /* bits per pixel */
- + tgaout << static_cast<char>(0x00); /* no special flags */
- + for (int i = 0; i < width*height*3; i += 3)
- + std::swap(buffer[i], buffer[i+2]); /* fix the channel order */
- + tgaout.write(&buffer[0], width*height*3); /* dump the image data */
- + tgaout.close();
- +#else
- + fnstr << ".png";
- Magick::Blob blob( &buffer[0], width*height*3);
- -
- Magick::Image image;
- char geometry[16];
- sprintf(geometry,"%dx%d",width,height);
- @@ -73,9 +105,8 @@ void Window::screenshot() {
- image.magick( "RGB" );
- image.read(blob);
- image.flip();
- - char filename[256];
- - sprintf(filename,"/tmp/performous_screenshot_%u.png",count);
- - image.write(filename);
- + image.write(fnstr.str().c_str());
- +#endif
- count++;
- }
- --
- 1.6.5.1.1367.gcd48
- From db78b76cf0de5a11de63e7dca1ece1305a0117ec Mon Sep 17 00:00:00 2001
- From: John Stumpo <stump@jstump.com>
- Date: Mon, 14 Dec 2009 08:43:37 -0500
- Subject: [PATCH 6/6] Use the standard Windows temp directory as returned by GetTempPathA() (as opposed to "/tmp") for screenshots under Windows.
- Also fix some variable names that the Windows headers #define to nothing.
- ---
- game/video_driver.cc | 23 ++++++++++++++++++-----
- 1 files changed, 18 insertions(+), 5 deletions(-)
- diff --git a/game/video_driver.cc b/game/video_driver.cc
- index 3a7c3b8..8dbd640 100644
- --- a/game/video_driver.cc
- +++ b/game/video_driver.cc
- @@ -14,6 +14,11 @@
- #include <Magick++.h>
- #endif
- +#ifdef _WIN32
- +// for GetTempPathA
- +#include <windows.h>
- +#endif
- +
- namespace {
- unsigned s_width;
- unsigned s_height;
- @@ -69,7 +74,14 @@ void Window::screenshot() {
- std::vector<char> buffer(width*height*3);
- glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
- std::ostringstream fnstr;
- - fnstr << "/tmp/performous_screenshot_" << count;
- +#ifdef _WIN32
- + char tmppath[256];
- + GetTempPathA(256, tmppath); /* this includes a backslash at the end */
- + fnstr << tmppath;
- +#else
- + fnstr << "/tmp/";
- +#endif
- + fnstr << "performous_screenshot_" << count;
- #ifdef LESS_MAGIC
- /* Write the image out as an uncompressed tga. */
- fnstr << ".tga";
- @@ -150,14 +162,15 @@ void Window::resize() {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- float h = virtH();
- - 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)
- - const float far = 100.0f; // How far away can things be seen
- + // stump: under MSVC, near and far are #defined to nothing for compatibility with ancient code, hence the underscores.
- + 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)
- + const float far_ = 100.0f; // How far away can things be seen
- // Set model-view matrix
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- const float f = 0.9f; // Avoid texture surface being exactly at the near plane (MacOSX fix)
- - glFrustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, f * near, far);
- - glTranslatef(0.0f, 0.0f, -near); // So that z = 0.0f is still on monitor surface
- + glFrustum(-0.5f * f, 0.5f * f, 0.5f * h * f, -0.5f * h * f, f * near_, far_);
- + glTranslatef(0.0f, 0.0f, -near_); // So that z = 0.0f is still on monitor surface
- }
- --
- 1.6.5.1.1367.gcd48
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement