Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-13 18:29:55 +0000
committerStijn Buys <ingar@osirion.org>2008-02-13 18:29:55 +0000
commitee891311ccc79bbc7837caac8546aac5b9bdf80f (patch)
tree4279b0bec63d2152669b19d1f11199c56ae57b7b /src
parenta65427370dfe27dfa74efb0bddd44d7ffb9552ac (diff)
camera Overview as spectator only, join works
Diffstat (limited to 'src')
-rw-r--r--src/client/camera.cc103
-rw-r--r--src/client/client.cc2
-rw-r--r--src/client/video.cc4
-rw-r--r--src/core/application.cc23
-rw-r--r--src/core/application.h5
-rw-r--r--src/core/commandbuffer.cc12
-rw-r--r--src/core/cvar.h2
-rw-r--r--src/core/func.cc54
-rw-r--r--src/core/func.h34
-rw-r--r--src/core/gameinterface.h6
-rw-r--r--src/game/game.cc60
-rw-r--r--src/game/game.h11
12 files changed, 210 insertions, 106 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 85929cc..f274e12 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -77,18 +77,71 @@ void shutdown()
{
}
+void set_mode(Mode newmode) {
+ switch(newmode) {
+ case Track:
+ // switch camera to Track mode
+ mode = Track;
+ yaw_target = core::localplayer.controled->direction;
+ yaw_current = yaw_target;
+ pitch_target = pitch_track;
+ pitch_current = pitch_target;
+ distance = 0.4f;
+ break;
+ case Free:
+ // switch camera to Free mode
+ mode = Free;
+ yaw_target = core::localplayer.controled->direction;
+ yaw_current = yaw_target;
+ pitch_target = pitch_track;
+ pitch_current = pitch_target;
+ distance = 0.4f;
+ break;
+ case Overview:
+ // switch camera to Overview mode
+ mode = Overview;
+ x_offset = 0;
+ z_offset = 0;
+ distance = 20.0f;
+ default:
+ break;
+ }
+
+}
+
+void next_mode()
+{
+
+ if (!core::localplayer.controled) {
+ set_mode(Overview);
+ return;
+ }
+
+ switch(mode) {
+ case Free:
+ // switch camera to Track mode
+ set_mode(Track);
+ break;
+ case Track:
+ // switch camera to Free mode
+ set_mode(Free);
+ break;
+ default:
+ break;
+ }
+}
+
void draw(float elapsed)
{
if (!core::localplayer.controled) {
// switch the camera to Overview of the player is not controling anything
if (mode != Overview) {
- mode = Overview;
- target = math::Vector3f(0,0,0);
- x_offset = 0;
- z_offset = 0;
- distance = 20.0f;
+ set_mode(Overview);
}
} else {
+ if (mode == Overview)
+ set_mode(Track);
+
camera::target = core::localplayer.controled->location;
}
@@ -168,46 +221,6 @@ void key_down()
}
}
-void next_mode() {
-
- if (!core::localplayer.controled) {
- mode = Overview;
- target = math::Vector3f(0,0,0);
- x_offset = 0;
- z_offset = 0;
- distance = 20.0f;
- }
-
- switch(mode) {
- case Overview:
- // switch camera to Track mode
- mode = Track;
- yaw_target = core::localplayer.controled->direction;
- yaw_current = yaw_target;
- pitch_target = pitch_track;
- pitch_current = pitch_target;
- distance = 0.4f;
- break;
- case Track:
- // switch camera to Free mode
- mode = Free;
- yaw_target = core::localplayer.controled->direction;
- yaw_current = yaw_target;
- pitch_target = pitch_track;
- pitch_current = pitch_target;
- distance = 0.4f;
- break;
- case Free:
- // switch camera to Overview mode
- mode = Overview;
- x_offset = 0;
- z_offset = 0;
- distance = 20.0f;
- default:
- break;
- }
-}
-
} // namespace camera
} // namespace client
diff --git a/src/client/client.cc b/src/client/client.cc
index 6ae6ba8..214ba2f 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -83,7 +83,7 @@ void Client::init()
con_print << "Initializing client..." << std::endl;
// initialize core
- core::localplayer.name = "Client";
+ core::sv_dedicated = core::cvar::get("sv_dedicated", "0", core::cvar::ReadOnly);
core::Application::init();
// initialize SDL, but do not initialize any subsystems
diff --git a/src/client/video.cc b/src/client/video.cc
index 19555ec..1a1f5e2 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -60,13 +60,13 @@ bool init()
int flags = 0;
if( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) {
- std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl;
+ con_error << "SDL_InitSubSystem() failed: " << SDL_GetError() << std::endl;
return false;
}
const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo();
if( !sdl_videoinfo) {
- std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
+ con_error << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
return false;
}
diff --git a/src/core/application.cc b/src/core/application.cc
index c9239cf..9fea8ee 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -18,10 +18,13 @@
#include "core/core.h"
#include "core/entity.h"
#include "core/func.h"
+#include "core/cvar.h"
namespace core
{
+Cvar sv_dedicated;
+
// --------------- engine functions ------------------------------
void func_print(std::stringstream &args)
{
@@ -83,16 +86,16 @@ extern "C" void signal_handler(int signum)
case SIGQUIT:
case SIGTERM:
if (Application::instance()) {
- con_warn << "received signal " << signum << ", shutting down..." << std::endl;
+ con_warn << "Received signal " << signum << ", shutting down..." << std::endl;
Application::instance()->shutdown();
Application::instance()->quit(0);
} else {
- std::cerr << "received signal " << signum << ", terminated..." << std::endl;
+ std::cerr << "Received signal " << signum << ", terminated..." << std::endl;
sys::quit(1);
}
break;
default:
- std::cerr << "received signal " << signum << ", terminated..." << std::endl;
+ std::cerr << "Received signal " << signum << ", terminated..." << std::endl;
sys::quit(1);
break;
}
@@ -133,6 +136,14 @@ void Application::init()
// initialize core subsystems
filesystem::init();
+
+ // dedicated or not
+ core::sv_dedicated = core::cvar::get("sv_dedicated", "1", core::cvar::ReadOnly);
+ if (sv_dedicated->value())
+ localplayer.name = "Console";
+ else
+ localplayer.name = "Client";
+
// register our functions
func::add("print", func_print);
@@ -145,7 +156,7 @@ void Application::init()
func::add("list_var", func_list_var);
func::add("list_func", func_list_func);
func::add("list_ent", func_list_ent);
-
+
if (game())
game()->connected = false;
current_time = 0;
@@ -207,6 +218,10 @@ void Application::disconnect()
game()->current_time = 0;
entity::clear();
+
+ // TODO remove all game functions
+
+ // TODO remove all game cvars
con_print << "Disconnected." << std::endl;
}
diff --git a/src/core/application.h b/src/core/application.h
index 1e2869a..d5c83d6 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -7,9 +7,14 @@
#ifndef __INCLUDED_CORE_APPLICATION_H__
#define __INCLUDED_CORE_APPLICATION_H__
+#include "core/cvar.h"
+
namespace core
{
+/// cvar to indicate dedicated server status
+extern Cvar sv_dedicated;
+
/// core interface for the client and server Application classes
class Application
{
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index c381d38..7f1cda0 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -32,7 +32,17 @@ void exec(const char *text)
Func f = func::find(cmdname);
if (f) {
// function exists, execute it
- f(cmdstream);
+ if (f->flags && func::Game) {
+ // it's a game function
+ if (connected()) {
+ GameFuncPtr function = (GameFuncPtr) f->ptr;
+ function(localplayer, cmdstream);
+ }
+ } else {
+ // it's a normal function
+ FuncPtr function = (FuncPtr) f->ptr;
+ function(cmdstream);
+ }
return;
}
diff --git a/src/core/cvar.h b/src/core/cvar.h
index 9b23563..16ceb46 100644
--- a/src/core/cvar.h
+++ b/src/core/cvar.h
@@ -43,7 +43,7 @@ namespace cvar
{
/// cvar flags
-enum Flags {Archive=2, ReadOnly=4};
+enum Flags {Archive=1, ReadOnly=2, Game=4};
/// get a cvar value from the registry
/** If the a cvar with the given name already exists in the registry,
diff --git a/src/core/func.cc b/src/core/func.cc
index 9f64906..af811cd 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -16,20 +16,57 @@ namespace func
std::map<std::string, Func> registry;
+void add(const char * functionname, FuncPtr functionptr, unsigned int flags)
+{
+ std::map<std::string, Func>::iterator it = registry.find(functionname);
+ Func f;
+ if (it == registry.end()) {
+ // function does not yet exist in the registry
+ f = new Func_t();
+ registry[std::string(functionname)] = f;
+ } else {
+ f = (*it).second;
+ }
-void add(const char * functionname, Func functionptr)
+ f->name = functionname;
+ f->ptr = (void *)functionptr;
+ f->flags = flags;
+}
+
+void add(const char * functionname, GameFuncPtr gamefunctionptr, unsigned int flags)
{
- registry[std::string(functionname)] = functionptr;
+ std::map<std::string, Func>::iterator it = registry.find(functionname);
+ Func f;
+ if (it == registry.end()) {
+ // function does not yet exist in the registry
+ f = new Func_t();
+ registry[std::string(functionname)] = f;
+ } else {
+ f = (*it).second;
+ }
+
+ f->name = functionname;
+ f->ptr = (void *)gamefunctionptr;
+ f->flags = flags & func::Game;
}
void remove(const char *functionname)
{
- registry.erase(std::string(functionname));
+ std::map<std::string, Func>::iterator it = registry.find(functionname);
+ if (it != registry.end()) {
+ delete (*it).second;
+ registry.erase(std::string(functionname));
+ }
}
void remove(const std::string &functionname)
{
- registry.erase(functionname);
+ std::map<std::string, Func>::iterator it = registry.find(functionname);
+ if (it != registry.end()) {
+ delete (*it).second;
+ registry.erase(std::string(functionname));
+ }
+
}
Func find(const std::string &functionname)
@@ -43,10 +80,17 @@ Func find(const std::string &functionname)
void list()
{
+ char typeindicator;
+
std::map<std::string, Func>::iterator it;
for (it = registry.begin(); it != registry.end(); it++) {
- con_print << " " << (*it).first << std::endl;
+ if ((*it).second->flags & func::Game)
+ typeindicator = 'G';
+ else
+ typeindicator = ' ';
+ con_print << " " << typeindicator << " " << (*it).first << std::endl;
}
+
con_print << registry.size() << " registered functions" << std::endl;
}
diff --git a/src/core/func.h b/src/core/func.h
index ae158b5..d98e954 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -8,6 +8,7 @@
#define __INCLUDED_CORE_FUNC_H__
#include "sys/sys.h"
+#include "core/player.h"
#include <sstream>
#include <string>
@@ -16,14 +17,41 @@
namespace core
{
-/// function pointer type
-typedef void(* Func)(std::stringstream &args);
+class Func_t
+{
+public:
+ /// pointer to the function
+ void *ptr;
+ /// name of the function
+ std::string name;
+ /// flags
+ unsigned int flags;
+};
+
+/// function type
+typedef Func_t *Func;
+
+/// function pointer type for local functions
+typedef void(* FuncPtr)(std::stringstream &args);
+
+/// fuction pointer for game functions
+typedef void(* GameFuncPtr)(Player &player, std::stringstream &args);
/// the function registry
namespace func
{
+
+/// function flags
+enum Flags {Game=1};
+
/// add a function to the registry
-void add(const char *functionname, Func functionptr);
+void add(const char *functionname, FuncPtr functionptr, unsigned int flags=0);
+
+/**
+ * @brief add a game function to the registry
+ * the flag core::func::Game will automaticly be set
+ */
+void add(const char *functionname, GameFuncPtr gamefunctionptr, unsigned int flags=0);
/// remove a function from the registry
void remove(const char *functionname);
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index 3e2a5f7..6e53575 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -34,12 +34,6 @@ public:
*/
virtual void frame(float seconds) = 0;
- /// a player joins the game
- virtual void event_join(Player *player) = 0;
-
- /// a player leaves the game
- virtual void event_leave(Player *player) = 0;
-
/// a pointer to the current game instance
static GameInterface * instance();
diff --git a/src/game/game.cc b/src/game/game.cc
index 25f8926..f88c753 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -18,6 +18,32 @@
namespace game
{
+/// a player joins the game
+void func_join(core::Player &player, std::stringstream &args)
+{
+ Ship *ship = new Ship();
+ ship->location = math::Vector3f(0,0,0);
+ ship->label = "ship: <" + player.name + "> Micron Vector";
+ ship->owner = &player;
+ player.controled = ship;
+
+ con_print << player.name << " joins the game" << std::endl;
+ /// TODO net broadcast
+}
+
+/// a player joins the spectators
+void func_spectate(core::Player &player, std::stringstream &args)
+{
+ con_print << player.name << " joins the spectators" << std::endl;
+ /// TODO net broadcast
+
+ if (player.controled) {
+ // player only has one ship for now
+ core::entity::remove(player.controled->id);
+ player.controled = 0;
+ }
+}
+
Game::Game()
{
}
@@ -106,7 +132,7 @@ bool Game::init()
con_print << " " << sectors[n]->label << " " << sectors[n]->name << std::endl;
*/
- star = new Star();
+ Star *star = new Star();
star->location = Vector3f(256.0f, 0.0f, 256.0f);
star->label = "star: Sabishi Hoshi";
@@ -136,6 +162,9 @@ bool Game::init()
axis->location = Vector3f(0, 0, 0);
axis->label = "axis: Origin";
+ core::func::add("join", func_join, core::func::Game);
+ core::func::add("spectate", func_spectate, core::func::Game);
+
return true;
}
@@ -143,6 +172,9 @@ void Game::shutdown()
{
con_print << "Shutting down game..." << std::endl;
+ core::func::remove("join");
+ core::func::remove("spectate");
+
// delete every sector object in the sectors vector
for (unsigned int n =0; n< sectors.size(); n++) {
delete sectors[n];
@@ -157,33 +189,7 @@ void Game::frame(float seconds)
}
-void Game::event_join(core::Player *player)
-{
- if (!player)
- return;
-
- ship = new Ship();
- ship->location = math::Vector3f(0,0,0);
- ship->label = "ship: <"+player->name+"> Micron Vector";
- ship->owner = player;
-
- player->controled = ship;
-
- con_print << player->name << " joins" << std::endl;
-}
-void Game::event_leave(core::Player *player)
-{
- if (!player)
- return;
-
- con_print << player->name << " leaves" << std::endl;
-
- if (player->controled) {
- // player only has one ship for now
- core::entity::remove(player->controled->id);
- }
-}
} // namespace game
diff --git a/src/game/game.h b/src/game/game.h
index 9c993fe..d8a6185 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -36,20 +36,9 @@ public:
/// execute one game grame
void frame(float seconds);
- /// a player joins the game
- void event_join(core::Player *player);
-
- /// a player leaves the game
- void event_leave(core::Player *player);
-
/// sectors in space
std::vector<Sector*> sectors;
- /// the only ship in the game
- Ship *ship;
- /// the only star in the game
- Star *star;
-
private:
std::string name;
std::string label;