Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
committerStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
commit982562fa19bb87a3dab352e562f386f61c171b7b (patch)
treeaeade8d5b7d3c68f5c222af1d8ecc6a734e1b43f /src/game
parentd198b7b8d9ff713d891f35ab173d1f428f610e7d (diff)
major rewrite of Cvar, Func and Entity
Diffstat (limited to 'src/game')
-rw-r--r--src/game/Makefile.am4
-rw-r--r--src/game/game.cc193
-rw-r--r--src/game/game.h29
-rw-r--r--src/game/sector.cc22
-rw-r--r--src/game/sector.h31
-rw-r--r--src/game/ship.cc38
-rw-r--r--src/game/ship.h9
-rw-r--r--src/game/shipspecs.cc9
-rw-r--r--src/game/shipspecs.h21
-rw-r--r--src/game/star.cc10
-rw-r--r--src/game/world.h25
11 files changed, 102 insertions, 289 deletions
diff --git a/src/game/Makefile.am b/src/game/Makefile.am
index d327706..a9685cc 100644
--- a/src/game/Makefile.am
+++ b/src/game/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/src
METASOURCES = AUTO
libgame_la_LDFLAGS = -avoid-version
-libgame_la_SOURCES = game.cc sector.cc ship.cc shipspecs.cc star.cc
+libgame_la_SOURCES = game.cc ship.cc star.cc
noinst_LTLIBRARIES = libgame.la
-noinst_HEADERS = game.h sector.h ship.h shipspecs.h star.h world.h
+noinst_HEADERS = game.h ship.h star.h
diff --git a/src/game/game.cc b/src/game/game.cc
index a9d5a6e..fb0d917 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -7,7 +7,6 @@
#include <vector>
#include "game/game.h"
-#include "game/sector.h"
#include "game/ship.h"
#include "game/star.h"
#include "core/entity.h"
@@ -19,36 +18,32 @@ namespace game
{
/// a player joins the game
-void func_join(core::Player &player, std::stringstream &args)
+void func_join(core::Player *player, std::string const &args)
{
- if (player.control)
+ if (player->control)
return;
- Ship *ship = new Ship();
- ship->location = math::Vector3f(0,0,0);
- ship->label = "ship: <" + player.name + "> Micron Vector";
- ship->owner = &player;
- player.control = ship;
-
+ player->control = new Ship(player);
+
std::ostringstream osstream;
- osstream << player.name << " joins the game";
- core::message_broadcast(osstream.str(), player.id);
+ osstream << player->name() << " joins the game";
+ core::message_broadcast(osstream.str(), player->id());
}
/// a player joins the spectators
-void func_spectate(core::Player &player, std::stringstream &args)
+void func_spectate(core::Player *player, std::string const &args)
{
- if (!player.control)
+ if (!player->control)
return;
std::ostringstream osstream;
- osstream << player.name << " spectates";
- core::message_broadcast(osstream.str(), player.id);
+ osstream << player->name() << " spectates";
+ core::message_broadcast(osstream.str(), player->id());
- if (player.control) {
+ if (player->control) {
// player has only ship for now
- core::entity::remove(player.control->id);
- player.control = 0;
+ core::Entity::remove(player->control->id());
+ player->control = 0;
}
}
@@ -64,118 +59,48 @@ bool Game::init()
{
using math::Vector3f;
using math::Color;
- //using filesystem::IniFile;
con_print << "Initializing game..." << std::endl;
con_print << " " << name() << std::endl;
- /*
- // read game.ini
- IniFile f;
- f.open("ini/game.ini");
- while (f) {
- f.getline();
- if (f.got_key()) {
- if (f.section() == "game") {
- // game::name
- if (f.got_key_string("name", name)); else
- // game::label
- if (f.got_key_string("label", label)); else
- // game::author
- if (f.got_key_string("author", author)); else
- // unknown value
- con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- }
- } else if (f.got_section("game")) {
-
- } else if (f.got_section()) {
- con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl;
- }
- }
- f.close();
-
- con_print << name << std::endl;
- con_print << "by " << author << std::endl;
-
- // read world.ini
- std::string tmp;
- Sector *sector =0;
-
- f.open("ini/world.ini");
- while (f) {
- f.getline();
- if (f.got_key()) {
- if (f.section() == "world") {
- // world::name
- if (f.got_key_string("name", tmp)); else
- // world:label
- if (f.got_key_string("label", tmp)); else
- // unknown value
- con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- } else if (f.section() == "sector") {
- // sector::name
- if (f.got_key_string("name", tmp)) {
- sector->name = tmp;
- } else
- // sector:label
- if (f.got_key_string("label", tmp)) {
- sector->label = tmp;
- } else
- // unknown value
- con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- }
- } else if (f.got_section("world")) {
- //con_debug << "[world] section" << std::endl;
- } else if (f.got_section("sector")) {
- sector = new Sector();
- sectors.push_back(sector);
- } else if (f.got_section()) {
- con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl;
- }
- }
- f.close();
-
-
- con_print << "Loading sectors..." << std::endl;
- for (unsigned n =0; n < sectors.size(); n++)
- con_print << " " << sectors[n]->label << " " << sectors[n]->name << std::endl;
- */
-
// set up some stuff in the game world
Star *star = new Star();
- star->location = Vector3f(256.0f, 0.0f, 256.0f);
- star->label = "star: Sabishi Hoshi";
-
- core::Entity *cube = new core::Entity(core::entity::Solid & core::entity::Static);
- cube->core_shape = core::entity::Cube;
- cube->core_color = Color(0.0f, 0.8f, 0.0f);
- cube->location = Vector3f(24.0f, 0.0f, -24.0f);
- cube->label ="cube: Borg cube green";
- cube->type = cube_enttype;
-
- cube = new core::Entity(core::entity::Solid & core::entity::Static);
- cube->core_shape = core::entity::Cube;
- cube->core_color = Color(1.0f, 0.0f, 0.0f);
- cube->location = Vector3f(16.0f, 0.0f, -16.0f);
- cube->label ="cube: Borg cube red";
- cube->type = cube_enttype;
-
- core::Entity *sphere = new core::Entity(core::entity::Solid & core::entity::Static);
- sphere->core_shape = core::entity::Sphere;
- sphere->core_color = Color(0.8f, 0.8f, 0.0f);
- sphere->location = Vector3f(0.0f, 0.0f, -32.0f);
- sphere->label ="sphere: The Sphere";
-
- core::Entity *axis = new core::Entity(core::entity::Static);
- axis->core_shape = core::entity::Diamond;
- axis->core_color = Color(1.0f, 1.0f, 0.0f);
- axis->location = Vector3f(0, 0, 0);
- axis->label = "axis: Origin";
+ star->entity_location = Vector3f(256.0f, 0.0f, 256.0f);
+ star->entity_name = "star: Sabishi Hoshi";
+
+ 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);
+ cube->entity_location = Vector3f(24.0f, 0.0f, -24.0f);
+ cube->entity_name ="cube: Borg cube green";
+ cube->entity_moduletypeid = cube_enttype;
+
+ 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);
+ cube->entity_location = Vector3f(16.0f, 0.0f, -16.0f);
+ cube->entity_name ="cube: Borg cube red";
+ cube->entity_moduletypeid = cube_enttype;
+
+ 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";
+
+ 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
- core::func::add("join", func_join, core::func::Game);
- core::func::add("spectate", func_spectate, core::func::Game);
+ core::Func::add("join", (core::GameFuncPtr) func_join);
+ core::Func::add("spectate", (core::GameFuncPtr) func_spectate);
+ // add 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;
}
@@ -183,34 +108,26 @@ 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];
- sectors[n] = 0;
- }
- // clear the sectors vector
- sectors.clear();
+ //core::Func::remove("join");
+ //core::Func::remove("spectate");
}
void Game::frame(float seconds)
{
}
-void Game::player_connect(core::Player &player)
+void Game::player_connect(core::Player *player)
{
- std::stringstream args;
- game::func_spectate(player, args);
+ std::string args;
+ func_spectate(player, args);
}
-void Game::player_disconnect(core::Player &player)
+void Game::player_disconnect(core::Player *player)
{
- if (player.control) {
+ if (player->control) {
// player has only one ship for now
- core::entity::remove(player.control->id);
- player.control = 0;
+ core::Entity::remove(player->control->id());
+ player->control = 0;
}
}
diff --git a/src/game/game.h b/src/game/game.h
index 7a6348e..f5f0bc0 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -10,7 +10,6 @@
// project headers
#include "game/ship.h"
#include "game/star.h"
-#include "game/sector.h"
#include "core/core.h"
#include "sys/sys.h"
@@ -24,6 +23,13 @@
namespace game
{
+// entity type constants
+const unsigned int ship_enttype = 256;
+const unsigned int star_enttype = 257;
+const unsigned int cube_enttype = 258;
+const unsigned int sphere_enttype = 259;
+const unsigned int axis_enttype = 260;
+
class Game : public core::GameInterface {
public:
Game();
@@ -31,31 +37,20 @@ public:
/// initialize the game
bool init();
+
/// shutdown the game
void shutdown();
+
/// execute one game grame
void frame(float seconds);
/// is called when a player connects
- void player_connect(core::Player &player);
+ void player_connect(core::Player *player);
/// is called when a player disconnects
- void player_disconnect(core::Player &player);
-
- /// sectors in space
- std::vector<Sector*> sectors;
-
-private:
- std::string label;
- std::string author;
-};
+ void player_disconnect(core::Player *player);
-// entity type constants
-const unsigned int ship_enttype = 256;
-const unsigned int star_enttype = 257;
-const unsigned int cube_enttype = 258;
-const unsigned int sphere_enttype = 259;
-const unsigned int axis_enttype = 260;
+};
}
diff --git a/src/game/sector.cc b/src/game/sector.cc
deleted file mode 100644
index a7a97b8..0000000
--- a/src/game/sector.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- game/sector.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
-*/
-
-// project headers
-#include "game/sector.h"
-
-namespace game {
-
-Sector::Sector()
-{
- label = "";
- name = "";
-}
-
-Sector::~Sector()
-{
-}
-
-} // namespace game
diff --git a/src/game/sector.h b/src/game/sector.h
deleted file mode 100644
index 75e6446..0000000
--- a/src/game/sector.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- game/sector.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_SECTOR_H__
-#define __INCLUDED_SECTOR_H__
-
-#include <string>
-
-namespace game
-{
-
-/// a sector of space
-class Sector {
-public:
- /// default constructor
- Sector();
- /// default destructor
- ~Sector();
-
- /// label used in configuration files, e.g. "terran"
- std::string label;
- /// name to display, e.g. "Terran System"
- std::string name;
-};
-
-} // namespace game
-
-#endif // __INCLUDED_SECTOR_H__
diff --git a/src/game/ship.cc b/src/game/ship.cc
index baa97f1..e6fcaeb 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -17,9 +17,12 @@ using math::degrees180f;
namespace game {
-Ship::Ship() : core::EntityControlable(0)
+Ship::Ship(core::Player *owner) :
+ core::EntityControlable(owner, ship_enttype)
{
- type = ship_enttype;
+ // etnity properties
+ entity_name = "ship: <" + owner->name() + "> Micron Vector";
+ entity_owner = owner;
// ship specs
acceleration = 1.5f;
@@ -33,29 +36,32 @@ Ship::~Ship()
void Ship::frame(float seconds)
{
-
- if (target_thrust < 0) target_thrust = 0.0f;
- else if(target_thrust > 1) target_thrust = 1.0f;
+ // update thrust
+ entity_thrust = target_thrust;
+ if (entity_thrust < 0)
+ entity_thrust = 0.0f;
+ else if(entity_thrust > 1)
+ entity_thrust = 1.0f;
// update direction
- float direction_offset = degrees180f(target_direction - direction);
+ float direction_offset = degrees180f(target_direction - entity_direction);
float d = turn_speed * seconds * direction_offset;
- direction = degrees360f(direction + d);
+ entity_direction = degrees360f(entity_direction + d);
// update speed
- if (speed < target_thrust * max_speed) {
- speed += acceleration * seconds;
- if (speed > target_thrust * max_speed) {
- speed = target_thrust * max_speed;
+ if (entity_speed < entity_thrust * max_speed) {
+ entity_speed += acceleration * seconds;
+ if (entity_speed > entity_thrust * max_speed) {
+ entity_speed = entity_thrust * max_speed;
}
- } else if(speed > target_thrust * max_speed) {
- speed -= acceleration * seconds;
- if (speed < 0) speed = 0;
+ } else if(entity_speed > entity_thrust * max_speed) {
+ entity_speed -= acceleration * seconds;
+ if (entity_speed < 0) entity_speed = 0;
}
// location TODO avoid sin/cos calculations
- location.x += cosf(direction * M_PI / 180) * speed * seconds;
- location.z -= sinf(direction * M_PI / 180) * speed * seconds;
+ entity_location.x += cosf(entity_direction * M_PI / 180) * entity_speed * seconds;
+ entity_location.z -= sinf(entity_direction * M_PI / 180) * entity_speed * seconds;
}
} // namespace game
diff --git a/src/game/ship.h b/src/game/ship.h
index d108223..2897d6c 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -7,16 +7,17 @@
#ifndef __INCLUDED_GAME_SHIP_H__
#define __INCLUDED_GAME_SHIP_H__
-// project headers
+#include "core/player.h"
#include "core/entity.h"
#include "math/vector3f.h"
namespace game {
+/// A ship in the game, controled by a player
class Ship : public core::EntityControlable
{
public:
- Ship();
+ Ship(core::Player *owner);
~Ship();
/// update the ship state
@@ -25,13 +26,15 @@ public:
/* -- Ship SPECS --*/
/// acceleration
float acceleration;
+
/// maximum speed
float max_speed;
+
/// turn speed in rotations per second
float turn_speed;
};
-} // namespace game
+}
#endif // __INCLUDED_GAME_SHIP_H__
diff --git a/src/game/shipspecs.cc b/src/game/shipspecs.cc
deleted file mode 100644
index 38a74cc..0000000
--- a/src/game/shipspecs.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- game/shipspecs.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 "shipspecs.h"
-
diff --git a/src/game/shipspecs.h b/src/game/shipspecs.h
deleted file mode 100644
index daefc40..0000000
--- a/src/game/shipspecs.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- game/shipspecs.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_SHIPSPECS_H__
-#define __INCLUDED_SHIPSPECS_H__
-
-class ShipSpecs {
-
-public:
- /// acceleration
- float acceleration;
- /// maximum speed
- float speed_max;
- /// yaw turn speed
- float yaw_speed;
-};
-
-#endif // __INCLUDED_SHIPSPECS_H__
diff --git a/src/game/star.cc b/src/game/star.cc
index 10bb6ee..0bb8fb5 100644
--- a/src/game/star.cc
+++ b/src/game/star.cc
@@ -10,13 +10,13 @@
namespace game {
-Star::Star() : core::Entity(core::entity::Static & core::entity::Solid)
+Star::Star() : core::Entity(core::Entity::Static & core::Entity::Solid)
{
- core_shape = core::entity::Sphere; // a star is a sphere
- core_color = math::Color(1,1,1,1); // white
- core_radius = 48; // 48 game units
+ entity_shape = core::Entity::Sphere; // a star is a sphere
+ entity_color = math::Color(1,1,1,1); // white
+ entity_radius = 48; // 48 game units
- type = star_enttype;
+ entity_moduletypeid = star_enttype;
}
Star::~Star()
diff --git a/src/game/world.h b/src/game/world.h
deleted file mode 100644
index 11a80fc..0000000
--- a/src/game/world.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- game/world.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_WORLD_H__
-#define __INCLUDED_WORLD_H__
-
-#include <string>
-
-namespace Game
-{
-
-/// the game world
-class World {
- /// load the intial game world into memory
- static void init();
- /// unload the game world
- static void shutdown();
-};
-
-} // namespace game
-
-#endif // __INCLUDED_WORLD_H__