Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/entity.cc32
-rw-r--r--src/core/entity.h91
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/parser.cc26
-rw-r--r--src/game/base/game.cc6
-rw-r--r--src/game/base/planet.cc3
-rw-r--r--src/game/base/star.cc3
-rw-r--r--src/game/intro/intro.cc89
-rw-r--r--src/render/draw.cc36
-rw-r--r--src/render/render.cc20
-rw-r--r--src/render/renderext.cc17
11 files changed, 204 insertions, 121 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 013e66d..d6b0a10 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -711,7 +711,7 @@ void EntityControlable::ActionInterface::debugDraw(btIDebugDraw* debugDrawer)
EntityControlable::EntityControlable() : EntityDynamic()
{
entity_thrust = 0;
- entity_movement = 0;
+ entity_control_flags = 0;
target_direction = 0.0f;
target_thrust = 0.0f;
@@ -729,7 +729,7 @@ EntityControlable::EntityControlable(std::istream & is) :
EntityDynamic(is)
{
entity_thrust = 0;
- entity_movement = 0;
+ entity_control_flags = 0;
target_direction = 0.0f;
target_thrust = 0.0f;
@@ -828,8 +828,8 @@ void EntityControlable::receive_client_update(std::istream &is)
void EntityControlable::serialize_server_update(std::ostream & os) const
{
EntityDynamic::serialize_server_update(os);
- os << roundf(entity_thrust*100.0f) << " ";
- os << roundf(entity_movement * 100.0f) << " ";
+ os << roundf(entity_thrust * 100.0f) << " ";
+ os << roundf(entity_control_flags) << " ";
}
void EntityControlable::receive_server_update(std::istream &is)
@@ -837,8 +837,8 @@ void EntityControlable::receive_server_update(std::istream &is)
EntityDynamic::receive_server_update(is);
is >> entity_thrust;
entity_thrust /= 100.0f;
- is >> entity_movement;
- entity_movement /= 100.0f;
+
+ is >> entity_control_flags;
}
void EntityControlable::set_thrust(float thrust)
@@ -1017,14 +1017,16 @@ void EntityControlable::frame(float seconds)
EntityGlobe::EntityGlobe() : Entity()
{
- render_texture = 0;
+ entity_texture_id = 0;
+ entity_corona_id = 0;
entity_rotationspeed = 0;
set_shape(Sphere);
}
EntityGlobe::EntityGlobe(std::istream & is) : Entity(is)
{
- render_texture = 0;
+ entity_texture_id = 0;
+ entity_corona_id = 0;
entity_rotationspeed = 0;
set_shape(Sphere);
}
@@ -1036,7 +1038,7 @@ EntityGlobe::~EntityGlobe()
void EntityGlobe::serialize_server_create(std::ostream & os) const
{
Entity::serialize_server_create(os);
- os << entity_rotationspeed << " \"" << entity_texture << "\" ";
+ os << entity_rotationspeed << " \"" << texturename() << "\" \"" << coronaname() << "\" ";
}
void EntityGlobe::receive_server_create(std::istream &is)
@@ -1047,12 +1049,20 @@ void EntityGlobe::receive_server_create(std::istream &is)
std::string n;
char c;
+
+ // read texture name
while ((is.get(c)) && (c != '"'));
while ((is.get(c)) && (c != '"'))
n += c;
- entity_texture = n;
+
+ entity_texturename.assign(n);
+
+ // read corona name
n.clear();
-
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
+ entity_coronaname.assign(n);
}
}
diff --git a/src/core/entity.h b/src/core/entity.h
index 5c34f97..2d79132 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -595,6 +595,10 @@ class EntityControlable : public EntityDynamic
{
friend class Player;
public:
+
+ /// control flags
+ enum ControlFlags {ControlFlagNone = 0, ControlFlagImpulse = 1};
+
/// bullet action interface class
class ActionInterface: public btActionInterface {
public:
@@ -634,9 +638,9 @@ public:
return entity_thrust;
}
- /// movement indicator
- inline float movement() const {
- return entity_movement;
+ /// control flags
+ inline unsigned int control_flags() const {
+ return entity_control_flags;
}
/// physics action
@@ -656,6 +660,21 @@ public:
virtual void serialize_server_update(std::ostream & os) const;
/*----- mutators -------------------------------------------------- */
+
+ /// set all control flags
+ inline void set_control_flags(unsigned int control_flags) {
+ entity_control_flags = control_flags;
+ }
+
+ /// set a single control flag
+ inline void set_control_flag(ControlFlags control_flag) {
+ entity_control_flags |= control_flag;
+ }
+
+ /// unset a single control flag
+ inline void unset_control_flag(ControlFlags control_flag) {
+ entity_control_flags &= ~control_flag;
+ }
/**
* @brief set the zone the entity is currently in
@@ -748,7 +767,7 @@ protected:
float target_vstrafe;
- float entity_movement;
+ unsigned int entity_control_flags;
ActionInterface *entity_actioninterface;
@@ -768,16 +787,58 @@ public:
virtual ~EntityGlobe();
/*----- inspectors ----------------------------------------------- */
+ /// core type id
+ virtual inline const unsigned int type() const {
+ return Entity::Globe;
+ }
+
/// texture name
- inline const std::string &texture() const {
- return entity_texture;
+ inline const std::string &texturename() const {
+ return entity_texturename;
+ }
+
+ /// texture render id
+ inline size_t texture_id() const {
+ return entity_texture_id;
+ }
+
+ /// corona texture name
+ inline const std::string &coronaname() const {
+ return entity_coronaname;
}
+ /// corona texture id
+ inline size_t corona_id() const {
+ return entity_corona_id;
+ }
+
/// rotation speed in degrees per second
inline float rotationspeed() const {
return entity_rotationspeed;
}
+ /*----- mutators -------------------------------------------------- */
+
+ inline void set_rotationspeed(const float rotationspeed) {
+ entity_rotationspeed = rotationspeed;
+ }
+
+ inline void set_texture_id(size_t texture_id) {
+ entity_texture_id = texture_id;
+ }
+
+ inline void set_corona_id(size_t texture_id) {
+ entity_corona_id = texture_id;
+ }
+
+ inline void set_texturename(const std::string & texturename) {
+ entity_texturename.assign(texturename);
+ }
+
+ inline void set_coronaname(const std::string & texturename) {
+ entity_coronaname.assign(texturename);
+ }
+
/*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
@@ -786,20 +847,12 @@ public:
/// receive a server-to-client create from a stream
virtual void receive_server_create(std::istream &is);
- /*----- inspectors ------------------------------------------------ */
-
- /// core type id
- virtual inline const unsigned int type() const {
- return Entity::Globe;
- }
-
- std::string entity_texture;
-
- /// client side, texture id
- unsigned int render_texture;
-
- /// rotation speed in degrees/second;
+private:
float entity_rotationspeed;
+ size_t entity_texture_id;
+ size_t entity_corona_id;
+ std::string entity_texturename;
+ std::string entity_coronaname;
};
}
diff --git a/src/core/net.h b/src/core/net.h
index 31fc6d7..f89d0d8 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 20;
+const unsigned int PROTOCOLVERSION = 21;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/parser.cc b/src/core/parser.cc
index efcc58b..943cfb7 100644
--- a/src/core/parser.cc
+++ b/src/core/parser.cc
@@ -122,6 +122,32 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
return true;
}
+ // special globe keys
+ if (entity->type() == Entity::Globe) {
+ EntityGlobe *globe = static_cast<EntityGlobe *>(entity);
+
+ if (inifile.got_key_string("texture", strval)) {
+ globe->set_texturename(strval);
+ return true;
+
+ } else if (inifile.got_key_string("corona", strval)) {
+ globe->set_coronaname(strval);
+ return true;
+
+ } else if (inifile.got_key_float("rotationspeed", f)) {
+ globe->set_rotationspeed(f);
+ return true;
+
+ } else if (inifile.got_key_bool("bright", blnval)) {
+ if (blnval) {
+ globe->set_flag(core::Entity::Bright);
+ } else {
+ globe->unset_flag(core::Entity::Bright);
+ }
+ return true;
+ }
+ }
+
return false;
}
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 7ed01e1..108c13f 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -1232,8 +1232,6 @@ bool Game::load_zone(core::Zone *zone)
} else if (zoneini.in_section("star")) {
if (core::Parser::got_entity_key(zoneini, star)) {
continue;
- } else if (zoneini.got_key_string("texture", star->entity_texture)) {
- continue;
} else {
zoneini.unkown_key();
}
@@ -1289,10 +1287,6 @@ bool Game::load_zone(core::Zone *zone)
} else if (zoneini.in_section("planet")) {
if (core::Parser::got_entity_key(zoneini, planet)) {
continue;
- } else if (zoneini.got_key_string("texture", planet->entity_texture)) {
- continue;
- } else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) {
- continue;
} else if (zoneini.got_key_bool("dock", b)) {
if (b) {
planet->set_flag(core::Entity::Dockable);
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index 8723af4..2adb1fb 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -17,10 +17,9 @@ Planet::Planet() : core::EntityGlobe()
get_color().assign(1.0f, 1.0f); // white
set_radius(64.0f); // 64 game units
+ set_rotationspeed(1.0f); // default rotationspeed: 1 degree per second
entity_moduletypeid = planet_enttype;
-
- entity_rotationspeed = 1.0f;
}
Planet::~Planet()
diff --git a/src/game/base/star.cc b/src/game/base/star.cc
index 6327223..c54788a 100644
--- a/src/game/base/star.cc
+++ b/src/game/base/star.cc
@@ -21,6 +21,9 @@ Star::Star() : core::EntityGlobe()
set_radius(96.0f);
entity_moduletypeid = star_enttype;
+
+ // default star corona name
+ set_coronaname("default");
}
Star::~Star()
diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc
index 072f06d..8d44391 100644
--- a/src/game/intro/intro.cc
+++ b/src/game/intro/intro.cc
@@ -37,11 +37,11 @@ bool Intro::load_world()
{
std::string filename("ini/intro");
- filesystem::IniFile ini;
- ini.open(filename);
+ filesystem::IniFile inifile;
+ inifile.open(filename);
- if (!ini.is_open()) {
- con_error << "Could not open " << ini.name() << std::endl;
+ if (!inifile.is_open()) {
+ con_error << "Could not open " << inifile.name() << std::endl;
return false;
}
@@ -54,101 +54,94 @@ bool Intro::load_world()
math::Color color;
math::Vector3f v;
float f;
- bool b;
- while (ini.getline()) {
+ while (inifile.getline()) {
- if (ini.got_section()) {
- if (ini.got_section("intro")) {
+ if (inifile.got_section()) {
+ if (inifile.got_section("intro")) {
zone = new core::Zone("intro");
zone->set_name("Introduction");
zone->set_sky("sky");
core::Zone::add(zone);
- } else if (ini.got_section("entity")) {
+ } else if (inifile.got_section("entity")) {
if (zone) {
entity = new core::Entity();
+ entity->set_zone(zone);
+ entity->set_radius(0);
}
- } else if (ini.got_section("convoy")) {
+ } else if (inifile.got_section("convoy")) {
if (zone) {
convoy = new Convoy(zone);
}
- } else if (ini.got_section("globe")) {
+ } else if (inifile.got_section("globe")) {
if (zone) {
globe = new core::EntityGlobe();
globe->set_zone(zone);
}
} else {
- ini.unknown_section();
+ inifile.unknown_section();
}
- } else if (zone && ini.got_key()) {
+ } else if (zone && inifile.got_key()) {
- if (ini.in_section("intro")) {
+ if (inifile.in_section("intro")) {
- if (ini.got_key_string("label", strval)) {
+ if (inifile.got_key_string("label", strval)) {
zone->set_label(strval);
- } else if (ini.got_key_string("sky", strval)) {
+ } else if (inifile.got_key_string("sky", strval)) {
zone->set_sky(strval);
- } else if (ini.got_key()) {
- ini.unkown_key();
+ } else if (inifile.got_key()) {
+ inifile.unkown_key();
}
- } else if (ini.in_section("entity")) {
+ } else if (inifile.in_section("entity")) {
- if (core::Parser::got_entity_key(ini, entity)) {
- entity->set_radius(0);
+ if (core::Parser::got_entity_key(inifile, entity)) {
continue;
} else {
- ini.unkown_key();
+ inifile.unkown_key();
+ }
+
+ } else if (inifile.in_section("globe")) {
+
+ if (core::Parser::got_entity_key(inifile, globe)) {
+ continue;
+
+ } else if (inifile.got_key()) {
+ inifile.unkown_key();
}
- } else if (ini.in_section("convoy")) {
+ } else if (inifile.in_section("convoy")) {
- if (ini.got_key_string("label", strval)) {
+ if (inifile.got_key_string("label", strval)) {
convoy->set_label(strval);
- } else if (ini.got_key_color("color", color)) {
+ } else if (inifile.got_key_color("color", color)) {
convoy->set_color(color);
- } else if (ini.got_key_color("colorsecond", color)) {
+ } else if (inifile.got_key_color("colorsecond", color)) {
convoy->set_color_second(color);
- } else if (ini.got_key_vector3f("location", v)) {
+ } else if (inifile.got_key_vector3f("location", v)) {
convoy->get_location().assign(v);
- } else if (ini.got_key_float("direction", f)) {
+ } else if (inifile.got_key_float("direction", f)) {
convoy->get_axis().change_direction(f);
- } else if (ini.got_key_float("speed", f)) {
+ } else if (inifile.got_key_float("speed", f)) {
convoy->set_speed(f);
- } else if (ini.got_key_string("ship", strval)) {
+ } else if (inifile.got_key_string("ship", strval)) {
convoy->add(strval);
- } else if (ini.got_key()) {
- ini.unkown_key();
- }
-
- } else if (ini.in_section("globe")) {
-
- if (core::Parser::got_entity_key(ini, globe)) {
- continue;
- } else if (ini.got_key_string("texture", globe->entity_texture)) {
- continue;
- } else if (ini.got_key_float("rotationspeed", globe->entity_rotationspeed)) {
- continue;
- } else if (ini.got_key_bool("bright", b)) {
- if (b) {
- globe->set_flag(core::Entity::Bright);
- }
- } else if (ini.got_key()) {
- ini.unkown_key();
+ } else if (inifile.got_key()) {
+ inifile.unkown_key();
}
}
}
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 4cf5571..79daffd 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -202,9 +202,9 @@ void draw_globe(const core::EntityGlobe* globe)
gl::disable(GL_LIGHT0);
}
- if (globe->render_texture) {
+ if (globe->texture_id()) {
// textured globe
- Textures::bind(globe->render_texture);
+ Textures::bind(globe->texture_id());
gl::enable(GL_TEXTURE_2D);
}
@@ -238,29 +238,23 @@ void draw_globe(const core::EntityGlobe* globe)
draw_sphere(globe->color(), radius);
gl::pop();
-
- if (globe->flag_is_set(core::Entity::Bright)) {
+ if (globe->flag_is_set(core::Entity::Bright) && globe->corona_id()) {
math::Vector3f v = globe->location() - Camera::eye();
v.normalize();
float a = dotproduct(v, Camera::axis().forward());
if (a > 0.1f) {
- // FIXME a corona is actually just a giant flare
- if (!globe->render_texture) {
- gl::enable(GL_TEXTURE_2D);
- }
- Textures::bind("textures/fx/corona");
- /*
- if (ext_render(globe)->distance() <= farplane) {
- gl::depthmask(GL_FALSE);
- }*/
+ gl::enable(GL_BLEND);
gl::disable(GL_DEPTH_TEST);
+ gl::enable(GL_TEXTURE_2D);
+
+ Textures::bind(globe->corona_id());
math::Color color(globe->color());
color.a = a - 0.1f;
gl::color(color);
- gl::enable(GL_BLEND);
+
gl::begin(gl::Quads);
glTexCoord2f(0, 1);
@@ -275,16 +269,10 @@ void draw_globe(const core::EntityGlobe* globe)
Stats::quads++;
- gl::disable(GL_BLEND);
- /*
- if (ext_render(globe)->distance() <= farplane) {
- gl::depthmask(GL_TRUE);
- }*/
- if (!globe->render_texture) {
- gl::disable(GL_TEXTURE_2D);
- }
-
+
+ gl::disable(GL_TEXTURE_2D);
gl::enable(GL_DEPTH_TEST);
+ gl::disable(GL_BLEND);
}
}
@@ -305,7 +293,7 @@ void draw_globe(const core::EntityGlobe* globe)
gl::enable(GL_LIGHT0);
}
- if (globe->render_texture) {
+ if (globe->texture_id()) {
gl::disable(GL_TEXTURE_2D);
}
}
diff --git a/src/render/render.cc b/src/render/render.cc
index 7776ef2..33dcb0c 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -172,9 +172,14 @@ void unload()
if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
- if (globe->render_texture) {
- render::Textures::unload(globe->render_texture);
- globe->render_texture = 0;
+
+ if (globe->texture_id()) {
+ render::Textures::unload("textures/" + globe->texturename());
+ globe->set_texture_id(0);
+ }
+ if (globe->corona_id()) {
+ render::Textures::unload("textures/corona/" + globe->coronaname());
+ globe->set_corona_id(0);
}
}
@@ -199,7 +204,14 @@ void clear()
if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
- globe->render_texture = 0;
+ if (globe->texture_id()) {
+ render::Textures::unload("textures/" + globe->texturename());
+ globe->set_texture_id(0);
+ }
+ if (globe->corona_id()) {
+ render::Textures::unload("textures/corona/" + globe->coronaname());
+ globe->set_corona_id(0);
+ }
}
if (ext_render(entity)) {
diff --git a/src/render/renderext.cc b/src/render/renderext.cc
index 049b3de..8ec31bf 100644
--- a/src/render/renderext.cc
+++ b/src/render/renderext.cc
@@ -82,12 +82,17 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
// load globe textures
- if (!globe->render_texture && globe->texture().size()) {
- std::stringstream texname;
- texname << "textures/" << globe->texture();
- globe->render_texture = Textures::load(texname.str());
- if (!globe->render_texture)
- globe->entity_texture.clear();
+ if (!globe->texture_id() && globe->texturename().size()) {
+ globe->set_texture_id(Textures::load("textures/" + globe->texturename()));
+ if (!globe->texture_id())
+ globe->set_texturename("");
+ }
+
+ if (!globe->corona_id() && globe->coronaname().size()) {
+ globe->set_corona_id(Textures::bind("textures/corona/" + globe->coronaname()));
+ if (!globe->corona_id()) {
+ globe->set_coronaname("");
+ }
}
}
}