Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-08-23 19:27:10 +0000
committerStijn Buys <ingar@osirion.org>2008-08-23 19:27:10 +0000
commit184598a43548642b9a4bfe8c2fce58e4a966d0bb (patch)
tree636e7c977d7e93390327da3be060f9c92adefc01
parent37bfbfbd234cce09b67c1d53e1ef7d91a46e53cc (diff)
instant r_fullscreen switching, bound to alt+enter
-rw-r--r--doc/manual.html1
-rw-r--r--osirion.kdevelop2
-rw-r--r--src/client/client.cc8
-rw-r--r--src/client/keyboard.cc3
-rw-r--r--src/client/video.cc20
-rw-r--r--src/client/video.h3
-rw-r--r--src/render/pngfile.cc15
7 files changed, 40 insertions, 12 deletions
diff --git a/doc/manual.html b/doc/manual.html
index 1f110ba..21b8a20 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -200,7 +200,6 @@ r_restart
variable to 1:
<pre>
r_fullscreen 1
-r_restart
</pre>
<p>
You can set your name and player color through the cl_color
diff --git a/osirion.kdevelop b/osirion.kdevelop
index d40c050..0a41004 100644
--- a/osirion.kdevelop
+++ b/osirion.kdevelop
@@ -21,7 +21,7 @@
</general>
<kdevautoproject>
<general>
- <activetarget>src/core/libcore.la</activetarget>
+ <activetarget>src/render/librender.la</activetarget>
<useconfiguration>debug</useconfiguration>
</general>
<run>
diff --git a/src/client/client.cc b/src/client/client.cc
index f67cce0..7ba61d6 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -46,13 +46,7 @@ void func_snd_restart(std::string const &args)
void func_r_restart(std::string const &args)
{
- video::shutdown();
-
- if (!video::init()) {
- app.quit(1);
- }
-
- input::reset();
+ video::restart();
}
//--- public ------------------------------------------------------
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index af7f2ed..aac6548 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -57,7 +57,8 @@ Keyboard::Keyboard()
add_key("backspace", SDLK_BACKSPACE);
add_key("tab", SDLK_TAB, 0, "impulse");
add_key("clear", SDLK_CLEAR);
- add_key("enter", SDLK_RETURN);
+ key = add_key("enter", SDLK_RETURN);
+ key->assign(Key::Alt, "toggle r_fullscreen");
add_key("pause", SDLK_PAUSE);
add_key("esc", SDLK_ESCAPE);
add_key("space", SDLK_SPACE, ' ', "ui_control");
diff --git a/src/client/video.cc b/src/client/video.cc
index aed25ae..39e2c2a 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -9,7 +9,9 @@
#include "auxiliary/functions.h"
#include "client/video.h"
+#include "client/input.h"
#include "client/view.h"
+#include "client/client.h"
#include "render/camera.h"
#include "render/render.h"
#include "render/tga.h"
@@ -26,6 +28,8 @@ namespace client {
namespace video {
+float fullscreen = 0;
+
int width = 0;
int height = 0;
@@ -45,6 +49,17 @@ core::Cvar *r_fullscreen;
core::Cvar *screenshotformat;
+void restart()
+{
+ shutdown();
+
+ if (!init()) {
+ client()->quit(1);
+ }
+
+ input::reset();
+}
+
void reset()
{
// setup our viewport.
@@ -116,6 +131,7 @@ bool init()
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);
+ fullscreen = r_fullscreen->value();
if (r_fullscreen->value()) {
flags = SDL_OPENGL | SDL_FULLSCREEN;
} else {
@@ -170,6 +186,10 @@ bool init()
void frame(float seconds)
{
+ // detect fullscreen/windowed mode switch
+ if (fullscreen != r_fullscreen->value())
+ restart();
+
// render a client frame
view::frame(seconds);
diff --git a/src/client/video.h b/src/client/video.h
index 20cd875..59939e6 100644
--- a/src/client/video.h
+++ b/src/client/video.h
@@ -24,6 +24,9 @@ namespace video
/// reset and clear the viewport
void reset();
+ /// restart the video subsystem
+ void restart();
+
/// make a screenshot
void screenshot();
diff --git a/src/render/pngfile.cc b/src/render/pngfile.cc
index 27cfd8f..8038d22 100644
--- a/src/render/pngfile.cc
+++ b/src/render/pngfile.cc
@@ -60,11 +60,13 @@ Image *PNG::load(const char *filename)
if (!info_ptr) {
con_warn << "Error reading " << filename << ": png_create_info_struct failed!" << std::endl;
filesystem::close(png_file);
+ png_destroy_read_struct(&png_ptr, 0, 0);
return 0;
}
if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error reading " << filename << ": error during init_io!" << std::endl;
filesystem::close(png_file);
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
return 0;
}
@@ -86,6 +88,7 @@ Image *PNG::load(const char *filename)
if (png_depth != 8) {
con_warn << "Error reading " << filename << ": bits per channel must be 8!" << std::endl;
filesystem::close(png_file);
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
return 0;
}
@@ -97,6 +100,7 @@ Image *PNG::load(const char *filename)
con_warn << "Error reading " << filename << std::endl;
filesystem::close(png_file);
delete image;
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
return 0;
}
@@ -111,6 +115,8 @@ Image *PNG::load(const char *filename)
con_debug << " " << filename << " " << png_width << "x" << png_height << "x" << channels * png_depth << "bpp" << std::endl;
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+
return image;
}
@@ -123,7 +129,6 @@ void PNG::save(const char *filename, Image & image)
return;
}
- /* initialize stuff */
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(png_file);
@@ -133,14 +138,16 @@ void PNG::save(const char *filename, Image & image)
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
- fclose(png_file);
con_warn << "Error writing " << filename << ": png_create_info_struct failed!" << std::endl;
+ fclose(png_file);
+ png_destroy_write_struct(&png_ptr, 0);
return;
}
if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error reading " << filename << ": error during init_io!" << std::endl;
fclose(png_file);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
@@ -150,6 +157,7 @@ void PNG::save(const char *filename, Image & image)
if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error writing " << filename << ": error writing header!" << std::endl;
fclose(png_file);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
@@ -162,6 +170,7 @@ void PNG::save(const char *filename, Image & image)
if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error writing " << filename << ": error writing header!" << std::endl;
fclose(png_file);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
@@ -176,12 +185,14 @@ void PNG::save(const char *filename, Image & image)
if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error writing " << filename << std::endl;
fclose(png_file);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
png_write_end(png_ptr, NULL);
fclose(png_file);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
con_print << "Wrote " << filename << std::endl;
}