From 0b8582a9aa825024edbd0a21c6287bfcccec28de Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 18 Feb 2008 17:52:15 +0000 Subject: core redesign, part II --- src/game/game.cc | 48 +++++++++++++++++++++++++++++------------------- src/game/game.h | 7 +++---- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'src/game') 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) diff --git a/src/game/game.h b/src/game/game.h index f5f0bc0..811de84 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -30,18 +30,18 @@ const unsigned int cube_enttype = 258; const unsigned int sphere_enttype = 259; const unsigned int axis_enttype = 260; -class Game : public core::GameInterface { +class Game : public core::Module { public: Game(); ~Game(); /// initialize the game - bool init(); + void init(); /// shutdown the game void shutdown(); - /// execute one game grame + /// run one time frame void frame(float seconds); /// is called when a player connects @@ -49,7 +49,6 @@ public: /// is called when a player disconnects void player_disconnect(core::Player *player); - }; } -- cgit v1.2.3