Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cc')
-rw-r--r--src/game/game.cc48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/game/game.cc b/src/game/game.cc
index fb0d917..311a696 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -9,7 +9,7 @@
#include "game/game.h"
#include "game/ship.h"
#include "game/star.h"
-#include "core/entity.h"
+#include "core/gameserver.h"
#include "sys/sys.h"
#include "math/mathlib.h"
#include "filesystem/filesystem.h"
@@ -17,6 +17,8 @@
namespace game
{
+/*----- engine game functions ------------------------------------- */
+
/// a player joins the game
void func_join(core::Player *player, std::string const &args)
{
@@ -25,9 +27,9 @@ void func_join(core::Player *player, std::string const &args)
player->control = new Ship(player);
- std::ostringstream osstream;
- osstream << player->name() << " joins the game";
- core::message_broadcast(osstream.str(), player->id());
+ std::string message(player->name());
+ message.append(" joins the game.");
+ core::server()->broadcast(message);
}
/// a player joins the spectators
@@ -36,9 +38,9 @@ void func_spectate(core::Player *player, std::string const &args)
if (!player->control)
return;
- std::ostringstream osstream;
- osstream << player->name() << " spectates";
- core::message_broadcast(osstream.str(), player->id());
+ std::string message(player->name());
+ message.append(" spectates.");
+ core::server()->broadcast(message);
if (player->control) {
// player has only ship for now
@@ -47,7 +49,9 @@ void func_spectate(core::Player *player, std::string const &args)
}
}
-Game::Game() : core::GameInterface("Project::OSiRiON")
+/*----- Game ------------------------------------------------------ */
+
+Game::Game() : core::Module("Project::OSiRiON")
{
}
@@ -55,19 +59,21 @@ Game::~Game()
{
}
-bool Game::init()
+void Game::init()
{
using math::Vector3f;
using math::Color;
- con_print << "Initializing game..." << std::endl;
- con_print << " " << name() << std::endl;
+ module_running = false;
- // set up some stuff in the game world
+ // setup the game world
+
+ // the star
Star *star = new Star();
star->entity_location = Vector3f(256.0f, 0.0f, 256.0f);
star->entity_name = "star: Sabishi Hoshi";
+ // the green cube
core::Entity *cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
cube->entity_shape = core::Entity::Cube;
cube->entity_color = Color(0.0f, 0.8f, 0.0f);
@@ -75,6 +81,7 @@ bool Game::init()
cube->entity_name ="cube: Borg cube green";
cube->entity_moduletypeid = cube_enttype;
+ // the red cube
cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
cube->entity_shape = core::Entity::Cube;
cube->entity_color = Color(1.0f, 0.0f, 0.0f);
@@ -82,38 +89,41 @@ bool Game::init()
cube->entity_name ="cube: Borg cube red";
cube->entity_moduletypeid = cube_enttype;
+ // the yellow sphere
core::Entity *sphere = new core::Entity(core::Entity::Solid & core::Entity::Static);
sphere->entity_shape = core::Entity::Sphere;
sphere->entity_color = Color(0.8f, 0.8f, 0.0f);
sphere->entity_location = Vector3f(0.0f, 0.0f, -32.0f);
sphere->entity_name ="sphere: The Sphere";
+ // the galactic origin
core::Entity *axis = new core::Entity(core::Entity::Static);
axis->entity_shape = core::Entity::Diamond;
axis->entity_color = Color(1.0f, 1.0f, 0.0f);
axis->entity_location = Vector3f(0, 0, 0);
axis->entity_name = "axis: Origin";
- // add game functions
+ // add engine game functions
core::Func::add("join", (core::GameFuncPtr) func_join);
core::Func::add("spectate", (core::GameFuncPtr) func_spectate);
- // add game variables
+ // add engine game variables
core::Cvar::set("g_borgcubes", "2", core::Cvar::Game);
core::Cvar::set("g_name", name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly);
- return true;
+
+ // indicate the module is ready to run frames
+ module_running = true;
}
void Game::shutdown()
{
- con_print << "Shutting down game..." << std::endl;
-
- //core::Func::remove("join");
- //core::Func::remove("spectate");
+ module_running = false;
}
void Game::frame(float seconds)
{
+ if (!running())
+ return;
}
void Game::player_connect(core::Player *player)