diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 31 | ||||
-rw-r--r-- | src/auxiliary/Makefile.am | 6 | ||||
-rw-r--r-- | src/auxiliary/functions.cc | 51 | ||||
-rw-r--r-- | src/auxiliary/functions.h | 28 | ||||
-rw-r--r-- | src/client/input.cc | 8 | ||||
-rw-r--r-- | src/core/Makefile.am | 5 | ||||
-rw-r--r-- | src/core/application.cc | 8 | ||||
-rw-r--r-- | src/core/gameconnection.cc | 2 | ||||
-rw-r--r-- | src/core/gameserver.cc | 3 | ||||
-rw-r--r-- | src/game/game.cc | 12 | ||||
-rw-r--r-- | src/math/functions.cc | 9 | ||||
-rw-r--r-- | src/math/functions.h | 1 |
12 files changed, 129 insertions, 35 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 19ad3be..81bd629 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,7 +4,7 @@ SUFFIXES = .rc .rc.o: windres $< -o $@ -SUBDIRS = sys math filesystem model core render server client game +SUBDIRS = auxiliary sys math filesystem model core server render client game noinst_HEADERS = config.h bin_PROGRAMS = osiriond osirion @@ -12,26 +12,29 @@ bin_PROGRAMS = osiriond osirion osiriond_SOURCES = osiriond.cc EXTRA_osiriond_SOURCES = osiriond-res.rc osiriond_DEPENDENCIES = $(ICON_SERVER) $(top_builddir)/src/core/libcore.la \ - $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/server/libserver.la $(top_builddir)/src/sys/libsys.la -osiriond_LDADD = $(top_builddir)/src/game/libgame.la \ + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/server/libserver.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/auxiliary/libauxiliary.la +osiriond_LDADD = $(top_builddir)/src/auxiliary/libauxiliary.la \ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/server/libserver.la $(top_builddir)/src/sys/libsys.la $(HOST_LIBS) $(ICON_SERVER) + $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/server/libserver.la \ + $(top_builddir)/src/sys/libsys.la $(HOST_LIBS) $(ICON_SERVER) # client osirion_SOURCES = osirion.cc EXTRA_osirion_SOURCES = osirion-res.rc osirion_DEPENDENCIES = $(ICON_CLIENT) $(top_builddir)/src/client/libclient.la \ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la $(ICON_CLIENT) \ + $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la \ $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/render/librender.la \ - $(top_builddir)/src/sys/libsys.la + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/auxiliary/libauxiliary.la osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) $(GLUT_CFLAGS) -osirion_LDADD = $(top_builddir)/src/game/libgame.la \ - $(top_builddir)/src/client/libclient.la $(top_builddir)/src/core/libcore.la \ - $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/math/libmath.la $(top_builddir)/src/render/librender.la \ - $(top_builddir)/src/sys/libsys.la $(GL_LIBS) $(HOST_LIBS) $(ICON_CLIENT) +osirion_LDADD = $(top_builddir)/src/client/libclient.la \ + $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/render/librender.la \ + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/sys/libsys.la \ + $(top_builddir)/src/auxiliary/libauxiliary.la + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/sys/libsys.la \ + $(top_builddir)/src/auxiliary/libauxiliary.la $(GL_LIBS) $(HOST_LIBS) $(ICON_CLIENT) osirion_LDFLAGS = $(LIBSDL_LIBS) diff --git a/src/auxiliary/Makefile.am b/src/auxiliary/Makefile.am new file mode 100644 index 0000000..6db5443 --- /dev/null +++ b/src/auxiliary/Makefile.am @@ -0,0 +1,6 @@ +INCLUDES = -I$(top_srcdir)/src +METASOURCES = AUTO +noinst_LTLIBRARIES = libauxiliary.la +libauxiliary_la_LDFLAGS = -avoid-version -no-undefined +libauxiliary_la_SOURCES = functions.cc +noinst_HEADERS = functions.h diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc new file mode 100644 index 0000000..373a6f0 --- /dev/null +++ b/src/auxiliary/functions.cc @@ -0,0 +1,51 @@ +/* + aux/functions.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "auxiliary/functions.h" + +namespace aux +{ + +const std::string plural(const char * word, size_t n) +{ + std::string p(word); + + if (n != 1) + p += 's'; + return p; +} + +const std::string article(const char * word) +{ + std::string w(word); + + if (!w.size()) + return w; + + switch (word[0]) { + case 'a': + case 'A': + case 'e': + case 'E': + case 'i': + case 'I': + case 'o': + case 'O': + case 'u': + case 'U': + case 'y': + case 'Y': + w.assign("an "); + break; + default: + w.assign("a "); + } + + w.append(word); + return w; +} + +} diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h new file mode 100644 index 0000000..88af5c7 --- /dev/null +++ b/src/auxiliary/functions.h @@ -0,0 +1,28 @@ +/* + aux/functions.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_AUX_FUNCTIONS_H__ +#define __INCLUDED_AUX_FUNCTIONS_H__ + +#include <string> + + +/// auxiliary functions +namespace aux +{ + +/// if n != 1, append a plural s to word +const std::string plural(const char * word, size_t n); + +inline const std::string plural(const std::string & word, size_t n) { return plural(word.c_str(), n); } + +/// prepend the "a" or "an" article to a word +const std::string article(const char * word); + +inline const std::string article(const std::string & word) { return article(word.c_str()); } +} + +#endif // __INCLUDED_AUX_FUNCTIONS_H__ diff --git a/src/client/input.cc b/src/client/input.cc index d8639cc..45c39a9 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -38,8 +38,8 @@ unsigned int last_control = 0; int mouse_x = 0; int mouse_y = 0; -float mouse_pitch; -float mouse_direction; +float mouse_pitch = 0; +float mouse_direction = 0; // true if the mouse is in the deadzone bool mouse_deadzone = false; @@ -204,6 +204,10 @@ void frame(float seconds) local_roll = 0.0f; local_thrust = core::localcontrol()->thrust(); last_control = core::localcontrol()->id(); + mouse_pitch = 0.0f; + mouse_direction = 0.0f; + mouse_x = video::width / 2; + mouse_y = video::height / 2; camera::reset(); } diff --git a/src/core/Makefile.am b/src/core/Makefile.am index efa4e7b..8b99c72 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -5,8 +5,9 @@ libcore_la_SOURCES = application.cc commandbuffer.cc clientstate.cc core.cc cvar func.cc gameconnection.cc gameinterface.cc gameserver.cc module.cc netclient.cc \ netconnection.cc netserver.cc player.cc stats.cc libcore_la_LDFLAGS = -avoid-version -no-undefined -libcore_la_LIBADD = $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/model/libmodel.la +libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \ + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la \ + $(top_builddir)/src/auxiliary/libauxiliary.la noinst_LTLIBRARIES = libcore.la noinst_HEADERS = application.h commandbuffer.h clientstate.h core.h cvar.h entity.h func.h \ diff --git a/src/core/application.cc b/src/core/application.cc index 2ff7bb0..be1dcac 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -100,10 +100,10 @@ Application::Application() application_game = 0; #ifndef _WIN32 - sys::signal(SIGHUP, signal_handler); - sys::signal(SIGINT, signal_handler); - sys::signal(SIGQUIT, signal_handler); - sys::signal(SIGTERM, signal_handler); + //sys::signal(SIGHUP, signal_handler); + //sys::signal(SIGINT, signal_handler); + //sys::signal(SIGQUIT, signal_handler); + //sys::signal(SIGTERM, signal_handler); #endif } diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index c86a0ae..e77a3d8 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -104,7 +104,7 @@ void GameConnection::frame(float seconds) } } - if (localcontrol() && localcontrol()->dirty()) { + if ((connection_network->state() == NetConnection::Connected) && localcontrol() && localcontrol()->dirty()) { std::ostringstream netmsg; netmsg << "cup " << localcontrol()->id() << " "; localcontrol()->serialize_client_update(netmsg); diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 5064ccd..98823e0 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -6,6 +6,7 @@ #include <iomanip> +#include "auxiliary/functions.h" #include "sys/sys.h" #include "core/cvar.h" #include "core/func.h" @@ -132,7 +133,7 @@ void GameServer::list_players(Player *player) } msgstr.str(""); - msgstr << count << " connected players"; + msgstr << count << " connected " << aux::plural("player", count); send(player, msgstr.str()); } diff --git a/src/game/game.cc b/src/game/game.cc index 3bdcb8e..8b70958 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -6,14 +6,16 @@ #include <vector> +#include "auxiliary/functions.h" +#include "core/gameserver.h" +#include "filesystem/filesystem.h" +#include "filesystem/inifile.h" #include "game/game.h" #include "game/ship.h" #include "game/star.h" -#include "core/gameserver.h" -#include "sys/sys.h" #include "math/mathlib.h" -#include "filesystem/filesystem.h" -#include "filesystem/inifile.h" +#include "sys/sys.h" + namespace game { @@ -92,7 +94,7 @@ void func_buy(core::Player *player, std::string const &args) player->player_control = new Ship(player, shipmodel); player->control()->entity_color = player->color(); - core::server()->broadcast(player->name() + " purchased a " + shipmodel->name()); + core::server()->broadcast(player->name() + " purchased " + aux::article(shipmodel->name())); player->player_dirty = true; } else { core::server()->send(player, "Usage: buy <" + helpstr + ">"); diff --git a/src/math/functions.cc b/src/math/functions.cc index 53ce41e..e048659 100644 --- a/src/math/functions.cc +++ b/src/math/functions.cc @@ -1,10 +1,9 @@ /* - common/functions.cc + math/functions.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ -// project headers #include "math/functions.h" namespace math @@ -43,9 +42,9 @@ unsigned randomi(const unsigned int max) float degrees180f(float angle) { float r = angle; - while (r <= -180.0f) + while (r < -180.0f) r += 360.0f; - while (r >= 180.0f) + while (r > 180.0f) r -= 360.0f; return r; } @@ -55,7 +54,7 @@ float degrees360f(float angle) float r = angle; while (r < 0.0f) r += 360.0f; - while (r >= 360.0f) + while (r > 360.0f) r -= 360.0f; return r; } diff --git a/src/math/functions.h b/src/math/functions.h index d84fe05..3d5d056 100644 --- a/src/math/functions.h +++ b/src/math/functions.h @@ -7,7 +7,6 @@ #ifndef __INCLUDED_MATH_FUNCTIONS_H__ #define __INCLUDED_MATH_FUNCTIONS_H__ -// C++ headers #include <math.h> #include <cstdlib> |