Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Makefile.am6
-rw-r--r--src/client/client.cc21
-rw-r--r--src/client/console.cc3
-rw-r--r--src/client/input.cc7
-rw-r--r--src/client/keyboard.cc112
-rw-r--r--src/client/keyboard.h24
-rw-r--r--src/client/video.cc34
7 files changed, 181 insertions, 26 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index cd7a028..1550238 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -1,12 +1,12 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libclient_la_SOURCES = camera.cc client.cc console.cc hud.cc input.cc keys.cc \
- shipdrawer.cc stardrawer.cc video.cc view.cc
+libclient_la_SOURCES = camera.cc client.cc console.cc hud.cc input.cc \
+ keyboard.cc shipdrawer.cc stardrawer.cc video.cc view.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_LTLIBRARIES = libclient.la
-noinst_HEADERS = camera.h client.h console.h input.h keys.h shipdrawer.h \
+noinst_HEADERS = camera.h client.h console.h input.h keyboard.h shipdrawer.h \
stardrawer.h video.h view.h
libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \
$(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \
diff --git a/src/client/client.cc b/src/client/client.cc
index 993e849..8970dea 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -49,7 +49,12 @@ Client app;
extern "C" void func_r_restart(std::stringstream &args)
{
video::shutdown();
- video::init();
+ console::flush();
+
+ if (!video::init()) {
+ console::flush();
+ app.quit(1);
+ }
}
//--- public ------------------------------------------------------
@@ -85,15 +90,17 @@ void Client::init()
SDL_Init(0);
// Initialize the video subsystem
- if (!client::video::init())
+ if (!video::init()) {
+ console::flush();
quit(1);
+ }
// initialize console
console::init();
-
+
// initialize input
input::init();
-
+
// add engine functions
core::func::add("r_restart", func_r_restart);
}
@@ -115,13 +122,13 @@ void Client::run()
// run a core frame
float seconds = ((float)(current - chrono)) / 1000.0f;
core::Application::frame(seconds);
-
+
// run a video frame
video::frame(seconds);
-
+
// process input
input::frame(seconds);
-
+
// update the main loop chronometer
chrono = current;
}
diff --git a/src/client/console.cc b/src/client/console.cc
index d10be50..42ef78a 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -6,7 +6,7 @@
#include "client/console.h"
#include "client/video.h"
-#include "client/keys.h"
+#include "client/keyboard.h"
#include "core/core.h"
#include "render/render.h"
@@ -158,6 +158,7 @@ void flush()
void toggle()
{
console_visible = !console_visible;
+ setkeyboardmode(console_visible);
}
void keypressed(const SDL_keysym &keysym)
diff --git a/src/client/input.cc b/src/client/input.cc
index b7c02af..ccfd998 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -9,6 +9,7 @@
#include "client/input.h"
#include "client/console.h"
#include "client/camera.h"
+#include "client/keyboard.h"
#include "SDL/SDL.h"
@@ -21,10 +22,7 @@ namespace input
void init()
{
con_print << "Initializing input..." << std::endl;
-
- //condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl;
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
- //SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
+ client::setkeyboardmode(console::visible());
}
void shutdown()
@@ -32,7 +30,6 @@ void shutdown()
con_print << "Shutting down input..." << std::endl;
}
-
// handle pressed keys for the game world
void keypressed(const SDL_keysym &keysym)
{
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
new file mode 100644
index 0000000..45e9284
--- /dev/null
+++ b/src/client/keyboard.cc
@@ -0,0 +1,112 @@
+/*
+ client/keyboard.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "client/keyboard.h"
+
+#include <iostream>
+
+namespace client {
+
+void setkeyboardmode(bool input)
+{
+ if(input)
+ SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
+ else
+ SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
+}
+
+char keysym_to_char(const SDL_keysym &keysym)
+{
+ char c = (char) keysym.sym;
+ bool shiftstate = false;
+
+ if (keysym.mod & KMOD_CAPS)
+ shiftstate = true;
+
+ if ((keysym.mod & KMOD_LSHIFT) || (keysym.mod & KMOD_RSHIFT)) {
+ shiftstate = !shiftstate;
+ }
+
+ if (!shiftstate)
+ return c;
+
+ if ((c >= 'a' && c <= 'z')) {
+ c = c + 'A' - 'a';
+ } else {
+ switch (c) {
+ case '`':
+ c = '~';
+ break;
+ case '1':
+ c = '!';
+ break;
+ case '2':
+ c = '@';
+ break;
+ case '3':
+ c = '#';
+ break;
+ case '4':
+ c = '$';
+ break;
+ case '5':
+ c = '%';
+ break;
+ case '6':
+ c = '^';
+ break;
+ case '7':
+ c = '&';
+ break;
+ case '8':
+ c = '*';
+ break;
+ case '9':
+ c = '(';
+ break;
+ case '0':
+ c = ')';
+ break;
+ case '-':
+ c = '_';
+ break;
+ case '=':
+ c = '+';
+ break;
+ // second row
+ case '[':
+ c = '{';
+ break;
+ case ']':
+ c = '}';
+ break;
+ case '|':
+ c = '\\';
+ break;
+ // third row
+ case ';':
+ c = ':';
+ break;
+ case '\'':
+ c = '"';
+ break;
+ // fourth row
+ case ',':
+ c = '<';
+ break;
+ case '.':
+ c = '>';
+ break;
+ case '/':
+ c = '?';
+ break;
+ }
+ }
+
+ return c;
+}
+
+} // namespace client
diff --git a/src/client/keyboard.h b/src/client/keyboard.h
new file mode 100644
index 0000000..10953c9
--- /dev/null
+++ b/src/client/keyboard.h
@@ -0,0 +1,24 @@
+/*
+ client/keyboard.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_KEYS_H__
+#define __INCLUDED_CLIENT_KEYS_H__
+
+#include "SDL/SDL.h"
+
+namespace client {
+
+/// convert SDL_keysym to an ascii character
+char keysym_to_char(const SDL_keysym &keysym);
+
+/// set the keyboard input mode
+/** @param input true for console input, false for game input
+ */
+void setkeyboardmode(bool input);
+
+} // namespace client
+
+#endif // __INCLUDED_CLIENT_KEYS_H__
diff --git a/src/client/video.cc b/src/client/video.cc
index df11b90..f7ae792 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -18,11 +18,15 @@ namespace client {
namespace video {
-const int defaultwidth = 1024;
-const int defaultheight = 768;
-
int width = 0;
int height = 0;
+
+int width_prev = 0;
+int height_prev = 0;
+
+const int width_default = 1024;
+const int height_default = 768;
+
float aspect = 1;
//--- cvars -------------------------------------------------------
@@ -48,8 +52,8 @@ bool init()
con_print << "Initializing video..." << std::endl;
// initialize cvars
- r_width = core::cvar::get("r_width", defaultwidth);
- r_height = core::cvar::get("r_height", defaultheight);
+ r_width = core::cvar::get("r_width", width_default);
+ r_height = core::cvar::get("r_height", height_default);
r_fullscreen = core::cvar::get("r_fullscreen", 1);
int bpp = 0;
@@ -66,8 +70,11 @@ bool init()
return false;
}
- width = 1024;
- height = 768;
+ width_prev = width;
+ height_prev = height;
+ width = (int) r_width->value();
+ height = (int) r_height->value();
+
bpp = sdl_videoinfo->vfmt->BitsPerPixel;
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
@@ -80,10 +87,17 @@ bool init()
flags = SDL_OPENGL | SDL_FULLSCREEN;
if(!SDL_SetVideoMode(width, height, bpp, flags )) {
- std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl;
- return false;
+ con_warn << "Failed to set video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
+ if (width_prev && height_prev) {
+ width = width_prev;
+ height = height_prev;
+ if(!SDL_SetVideoMode(width, height, bpp, flags )) {
+ con_error << "Failed to restore video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
+ return false;
+ }
+ } else
+ return false;
}
-
con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
aspect = (float) width / (float) height;