Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/mapfile.cc229
-rw-r--r--src/model/model.cc11
-rw-r--r--src/model/model.h36
3 files changed, 163 insertions, 113 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 8dff219..aa0cb37 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -970,11 +970,12 @@ Model * MapFile::load(std::string const &name)
Model *model = new Model(name);
mapfile.clear_bbox();
- Dock *dock = 0;
- Particles *particles = 0;
- Flare *flare = 0;
- Light *light = 0;
- SubModel *submodel = 0;
+ Dock *tag_dock = 0;
+ Particles *tag_particles = 0;
+ Flare *tag_flare = 0;
+ Light *tag_light = 0;
+ SubModel *tag_submodel = 0;
+ Sound *tag_sound = 0;
std::string modelname;
math::Vector3f location;
@@ -1074,50 +1075,50 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_classname("light")) {
- // new light
- light = new Light();
- model->add_light(light);
+ // new light tag
+ tag_light = new Light();
+ model->add_light(tag_light);
continue;
} else if (mapfile.classname().compare("light") == 0) {
// light attributes
if (mapfile.got_key_vector3f("origin", location)) {
- light->get_location().assign(location * SCALE);
+ tag_light->get_location().assign(location * SCALE);
continue;
} else if (mapfile.got_key_color("_color", color)) {
- light->get_color().assign(color);
+ tag_light->get_color().assign(color);
continue;
} else if (mapfile.got_key_int("spawnflags", u)) {
- light->set_strobe(spawnflag_isset(u, 1));
- light->set_entity(spawnflag_isset(u, 2));
- light->set_engine(spawnflag_isset(u, 4));
+ tag_light->set_strobe(spawnflag_isset(u, 1));
+ tag_light->set_entity(spawnflag_isset(u, 2));
+ tag_light->set_engine(spawnflag_isset(u, 4));
continue;
} else if (mapfile.got_key_float("light", r)) {
- light->set_radius(r * LIGHTSCALE);
+ tag_light->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("radius", r)) {
- light->set_radius(r * LIGHTSCALE);
+ tag_light->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("frequency", r)) {
- light->set_frequency(r);
+ tag_light->set_frequency(r);
continue;
} else if (mapfile.got_key_float("offset", r)) {
- light->set_offset(r);
+ tag_light->set_offset(r);
continue;
} else if (mapfile.got_key_float("time", r)) {
- light->set_time(r);
+ tag_light->set_time(r);
continue;
} else if (mapfile.got_key_int("flare", u)) {
- light->set_flare(u);
+ tag_light->set_flare(u);
continue;
} else if (mapfile.got_key()) {
@@ -1128,76 +1129,76 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_classname("fx_flare")) {
- // new flare
- flare = new Flare();
- model->add_flare(flare);
+ // new flare tag
+ tag_flare = new Flare();
+ model->add_flare(tag_flare);
} else if (mapfile.classname().compare("fx_flare") == 0) {
// flare attributes
if (mapfile.got_key_vector3f("origin", location)) {
- flare->get_location().assign(location * SCALE);
+ tag_flare->get_location().assign(location * SCALE);
continue;
} else if (mapfile.got_key_color("_color", color)) {
- flare->get_color().assign(color);
+ tag_flare->get_color().assign(color);
continue;
} else if (mapfile.got_key_int("spawnflags", u)) {
- flare->set_strobe(spawnflag_isset(u, 1));
- flare->set_entity(spawnflag_isset(u, 2));
- flare->set_engine(spawnflag_isset(u, 4));
+ tag_flare->set_strobe(spawnflag_isset(u, 1));
+ tag_flare->set_entity(spawnflag_isset(u, 2));
+ tag_flare->set_engine(spawnflag_isset(u, 4));
} else if (mapfile.got_key_float("light", r)) {
- flare->set_radius(r * LIGHTSCALE);
+ tag_flare->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("radius", r)) {
- flare->set_radius(r * LIGHTSCALE);
+ tag_flare->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("frequency", r)) {
- flare->set_frequency(r);
+ tag_flare->set_frequency(r);
continue;
} else if (mapfile.got_key_float("offset", r)) {
- flare->set_offset(r);
+ tag_flare->set_offset(r);
continue;
} else if (mapfile.got_key_float("time", r)) {
- flare->set_time(r);
+ tag_flare->set_time(r);
continue;
} else if (mapfile.got_key_int("flare", u)) {
- flare->set_flare(u);
+ tag_flare->set_flare(u);
continue;
} else if (mapfile.got_key_float("angle", angle)) {
if (angle == ANGLEUP) {
- flare->get_axis().change_pitch(90.0f);
+ tag_flare->get_axis().change_pitch(90.0f);
} else if (angle == ANGLEDOWN) {
- flare->get_axis().change_pitch(-90.0f);
+ tag_flare->get_axis().change_pitch(-90.0f);
} else {
- flare->get_axis().change_direction(angle);
+ tag_flare->get_axis().change_direction(angle);
}
} else if (mapfile.got_key_float("direction", angle)) {
- flare->get_axis().change_direction(angle);
+ tag_flare->get_axis().change_direction(angle);
} else if (mapfile.got_key_float("pitch", angle)) {
- flare->get_axis().change_pitch(angle);
+ tag_flare->get_axis().change_pitch(angle);
} else if (mapfile.got_key_float("roll", angle)) {
- flare->get_axis().change_roll(angle);
+ tag_flare->get_axis().change_roll(angle);
} else if (mapfile.got_key_string("cull", str)) {
aux::to_lowercase(str);
if (str.compare("none") == 0) {
- flare->set_cull(CullNone);
+ tag_flare->set_cull(CullNone);
} else if (str.compare("back") == 0) {
- flare->set_cull(CullBack);
+ tag_flare->set_cull(CullBack);
} else if (str.compare("front") == 0) {
- flare->set_cull(CullFront);
+ tag_flare->set_cull(CullFront);
} else {
mapfile.unknown_value();
}
@@ -1208,54 +1209,53 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_classname("fx_particles")) {
- // new particle system
- particles = new Particles();
- model->add_particles(particles);
+ // new particle system tag
+ tag_particles = new Particles();
+ model->add_particles(tag_particles);
} else if (mapfile.classname().compare("fx_particles") == 0) {
// particle system attributes
if (mapfile.got_key_vector3f("origin", location)) {
- particles->get_location().assign(location * SCALE);
+ tag_particles->get_location().assign(location * SCALE);
continue;
} else if (mapfile.got_key_string("script", str)) {
- particles->set_script(str);
+ tag_particles->set_script(str);
continue;
} else if (mapfile.got_key_float("angle", angle)) {
if (angle == ANGLEUP) {
- particles->get_axis().change_pitch(90.0f);
+ tag_particles->get_axis().change_pitch(90.0f);
} else if (angle == ANGLEDOWN) {
- particles->get_axis().change_pitch(-90.0f);
+ tag_particles->get_axis().change_pitch(-90.0f);
} else {
- particles->get_axis().change_direction(angle);
+ tag_particles->get_axis().change_direction(angle);
}
} else if (mapfile.got_key_float("direction", angle)) {
- particles->get_axis().change_direction(angle);
+ tag_particles->get_axis().change_direction(angle);
} else if (mapfile.got_key_float("pitch", angle)) {
- particles->get_axis().change_pitch(angle);
+ tag_particles->get_axis().change_pitch(angle);
} else if (mapfile.got_key_float("roll", angle)) {
- particles->get_axis().change_roll(angle);
+ tag_particles->get_axis().change_roll(angle);
} else if (mapfile.got_key_int("spawnflags", u)) {
- particles->set_entity(spawnflag_isset(u, 2));
- particles->set_engine(spawnflag_isset(u, 4));
+ tag_particles->set_entity(spawnflag_isset(u, 2));
+ tag_particles->set_engine(spawnflag_isset(u, 4));
} else if (mapfile.got_key_float("radius", r)) {
- particles->set_radius(r * LIGHTSCALE);
+ tag_particles->set_radius(r * LIGHTSCALE);
} else if (mapfile.got_key_string("cull", str)) {
-
aux::to_lowercase(str);
if (str.compare("none") == 0) {
- particles->set_cull(CullNone);
+ tag_particles->set_cull(CullNone);
} else if (str.compare("back") == 0) {
- particles->set_cull(CullBack);
+ tag_particles->set_cull(CullBack);
} else if (str.compare("front") == 0) {
- particles->set_cull(CullFront);
+ tag_particles->set_cull(CullFront);
} else {
mapfile.unknown_value();
}
@@ -1264,61 +1264,75 @@ Model * MapFile::load(std::string const &name)
mapfile.unknown_key();
}
+ } else if (mapfile.got_classname("fx_sound")) {
+
+ // new sound tag
+ tag_sound = new Sound();
+ model->add_sound(tag_sound);
+
+ } else if (mapfile.classname().compare("fx_sound") == 0) {
+
+ // sound attributes
+ if (mapfile.got_key_vector3f("origin", location)) {
+ tag_sound->get_location().assign(location * SCALE);
+ continue;
+ } else {
+ mapfile.unknown_key();
+ }
+
} else if (mapfile.got_classname("misc_model")) {
- // new submodel
- submodel = new SubModel();
- submodel_list.push_back(submodel);
+ // new submodel tag
+ tag_submodel = new SubModel();
+ submodel_list.push_back(tag_submodel);
} else if (mapfile.classname().compare("misc_model") == 0) {
// submodel attributes
if (mapfile.got_key_vector3f("origin", location)) {
- submodel->get_location().assign(location * SCALE);
+ tag_submodel->get_location().assign(location * SCALE);
continue;
} else if (mapfile.got_key_string("model", modelname)) {
-
// remove extension
if (modelname[modelname.size()-4] == '.') {
modelname.erase(modelname.size() - 4);
}
-
- submodel->set_name(modelname);
+ tag_submodel->set_name(modelname);
continue;
} else if (mapfile.got_key_float("angle", angle)) {
if (angle == ANGLEUP) {
- submodel->get_axis().change_pitch(90.0f);
+ tag_submodel->get_axis().change_pitch(90.0f);
} else if (angle == ANGLEDOWN) {
- submodel->get_axis().change_pitch(-90.0f);
+ tag_submodel->get_axis().change_pitch(-90.0f);
} else {
- submodel->get_axis().change_direction(angle);
+ tag_submodel->get_axis().change_direction(angle);
}
} else if (mapfile.got_key_float("modelscale", s)) {
if (s) {
- submodel->set_scale(s);
+ tag_submodel->set_scale(s);
} else {
- submodel->set_scale(1.0f);
+ tag_submodel->set_scale(1.0f);
}
}
} else if (mapfile.got_classname("location_dock")) {
// new docking location
- dock = new Dock();
- model->add_dock(dock);
+ tag_dock = new Dock();
+ model->add_dock(tag_dock);
} else if (mapfile.classname().compare("location_dock") == 0) {
// dock attributes
if (mapfile.got_key_vector3f("origin", location)) {
- dock->get_location().assign(location * SCALE);
+ tag_dock->get_location().assign(location * SCALE);
continue;
} else if (mapfile.got_key_float("radius", r)) {
- dock->set_radius(r * SCALE);
+ tag_dock->set_radius(r * SCALE);
continue;
} else if (mapfile.got_key("angle")) {
@@ -1362,7 +1376,7 @@ Model * MapFile::load(std::string const &name)
mapfile.close();
- // reposition docks, lights, flares and particles according to the model center
+ // translate model tags
for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) {
(*lit)->get_location() -= mapfile.map_center;
}
@@ -1375,20 +1389,24 @@ Model * MapFile::load(std::string const &name)
(*pit)->get_location() -= mapfile.map_center;
}
+ for(Model::Sounds::iterator sit = model->sounds().begin(); sit != model->sounds().end(); sit++) {
+ (*sit)->get_location() -= mapfile.map_center;
+ }
+
for (Model::Docks::iterator dit = model->docks().begin(); dit != model->docks().end(); dit++) {
(*dit)->get_location() -= mapfile.map_center;
}
for (SubModelList::iterator smit = submodel_list.begin(); smit != submodel_list.end(); smit++) {
- submodel = (*smit);
+ tag_submodel = (*smit);
Model *submodel_model = 0;
- if (submodel->name().size()) {
- submodel_model = Model::load(submodel->name());
+ if (tag_submodel->name().size()) {
+ submodel_model = Model::load(tag_submodel->name());
}
if (submodel_model) {
- submodel->get_location() -= mapfile.map_center;
+ tag_submodel->get_location() -= mapfile.map_center;
// copy fragmentgroups
for (Model::Groups::iterator git = submodel_model->groups().begin(); git != submodel_model->groups().end(); git++) {
@@ -1397,12 +1415,12 @@ Model * MapFile::load(std::string const &name)
groupdst->set_transform(true);
groupdst->set_type(groupsrc->type());
- groupdst->set_scale(groupsrc->scale() * submodel->scale());
+ groupdst->set_scale(groupsrc->scale() * tag_submodel->scale());
groupdst->set_speed(groupsrc->speed());
- groupdst->set_location(submodel->location() + (submodel_model->origin() + groupsrc->location()) * submodel->scale());
- groupdst->set_axis(groupsrc->axis() * submodel->axis());
+ groupdst->set_location(tag_submodel->location() + (submodel_model->origin() + groupsrc->location()) * tag_submodel->scale());
+ groupdst->set_axis(groupsrc->axis() * tag_submodel->axis());
- // copy fragments
+ // copy fragments, this only copies the original fragment's pointer into the vertex array
for (FragmentGroup::iterator fit = groupsrc->begin(); fit != groupsrc->end(); fit++) {
Fragment *fragmentdst = new Fragment(*(*fit));
groupdst->add_fragment(fragmentdst);
@@ -1418,12 +1436,12 @@ Model * MapFile::load(std::string const &name)
// recalculate bbox
for (size_t i = 0; i < 3; i ++) {
float c;
- c = submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_maxbbox[i]) * submodel->scale();
+ c = tag_submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_maxbbox[i]) * tag_submodel->scale();
if (c > model->model_maxbbox[i]) {
model->model_maxbbox[i] = c;
}
- c = submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_minbbox[i]) * submodel->scale();
+ c = tag_submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_minbbox[i]) * tag_submodel->scale();
if (c < model->model_minbbox[i]) {
model->model_minbbox[i] = c;
}
@@ -1431,33 +1449,42 @@ Model * MapFile::load(std::string const &name)
}
model->set_radius(sqrtf(math::max(model->model_maxbbox.lengthsquared(), model->model_minbbox.lengthsquared())));
- // copy lights, flares and particle systems
+ // copy light tags
for (Model::Lights::const_iterator lit = submodel_model->lights().begin(); lit != submodel_model->lights().end(); lit++) {
- light = new Light(*(*lit));
- light->get_location().assign(submodel->location() + (submodel_model->origin() + light->location()) * submodel->scale());
- light->set_radius(light->radius() * submodel->scale());
- model->add_light(light);
+ tag_light = new Light(*(*lit));
+ tag_light->get_location().assign(tag_submodel->location() + (submodel_model->origin() + tag_light->location()) * tag_submodel->scale());
+ tag_light->set_radius(tag_light->radius() * tag_submodel->scale());
+ model->add_light(tag_light);
}
+ // copy flare tags
for (Model::Flares::const_iterator flit = submodel_model->flares().begin(); flit != submodel_model->flares().end(); flit++) {
- flare = new Flare(*(*flit));
- flare->get_location().assign(submodel->location() + (submodel_model->origin() + flare->location()) * submodel->scale());
- flare->set_radius(flare->radius() * submodel->scale());
- model->add_flare(flare);
+ tag_flare = new Flare(*(*flit));
+ tag_flare->get_location().assign(tag_submodel->location() + (submodel_model->origin() + tag_flare->location()) * tag_submodel->scale());
+ tag_flare->set_radius(tag_flare->radius() * tag_submodel->scale());
+ model->add_flare(tag_flare);
}
+ // copy particle system tags
for (Model::ParticleSystems::const_iterator pit = submodel_model->particles().begin(); pit != submodel_model->particles().end(); pit++) {
- particles = new Particles(*(*pit));
- particles->get_location().assign(submodel->location() + (submodel_model->origin() + particles->location()) * submodel->scale());
- particles->set_radius(particles->radius() * submodel->scale());
- model->add_particles(particles);
+ tag_particles = new Particles(*(*pit));
+ tag_particles->get_location().assign(tag_submodel->location() + (submodel_model->origin() + tag_particles->location()) * tag_submodel->scale());
+ tag_particles->set_radius(tag_particles->radius() * tag_submodel->scale());
+ model->add_particles(tag_particles);
+ }
+
+ // copy sound tags
+ for (Model::Sounds::const_iterator sit = submodel_model->sounds().begin(); sit != submodel_model->sounds().end(); sit++) {
+ tag_sound = new Sound(*(*sit));
+ tag_sound->get_location().assign(tag_submodel->location() + (submodel_model->origin() + tag_sound->location()) * tag_submodel->scale());
}
+ // TODO copy engines and docks
//con_debug << " imported submodel '" << submodel->name() << "'" << std::endl;
}
- delete submodel;
+ delete tag_submodel;
}
diff --git a/src/model/model.cc b/src/model/model.cc
index 2ac2b50..5ba4deb 100644
--- a/src/model/model.cc
+++ b/src/model/model.cc
@@ -62,6 +62,12 @@ Model::~Model()
delete(*flit);
}
model_flares.clear();
+
+ // delete all sound tags
+ for (Sounds::iterator sit = model_sounds.begin(); sit != model_sounds.end(); sit++) {
+ delete (*sit);
+ }
+ model_sounds.clear();
}
void Model::set_radius(const float radius)
@@ -94,6 +100,11 @@ void Model::add_flare(Flare *flare)
model_flares.push_back(flare);
}
+void Model::add_sound(Sound *sound)
+{
+ model_sounds.push_back(sound);
+}
+
void Model::add_dock(Dock *dock)
{
model_docks.push_back(dock);
diff --git a/src/model/model.h b/src/model/model.h
index c8f60f1..dd9cdf2 100644
--- a/src/model/model.h
+++ b/src/model/model.h
@@ -37,18 +37,21 @@ public:
/// type definition for a list of model fragments
typedef std::list<Fragment *> Fragments;
- /// type definition for a list of model lights
+ /// type definition for a list of model light tags
typedef std::list<Light *> Lights;
- /// type definition for a list of model flares
+ /// type definition for a list of model flare tags
typedef std::list<Flare *> Flares;
- /// type definition for a lost of dockable locations
+ /// type definition for a list of model dock tags
typedef std::list<Dock *> Docks;
- /// type definition for a list of model particles
+ /// type definition for a list of model particle system tags
typedef std::list<Particles *> ParticleSystems;
+ /// type definition for a list of model sound tags
+ typedef std::list<Sound *> Sounds;
+
/// type definition for a list of FragmentGroups
typedef std::list<FragmentGroup *> Groups;
@@ -73,22 +76,27 @@ public:
return model_groups;
}
- /// list of lights
+ /// list of model light tags
inline Lights & lights() {
return model_lights;
}
- /// list of dockable locations
+ /// list of model dock tags
inline Docks & docks() {
return model_docks;
}
- /// list of flares
+ /// list of model flare tags
inline Flares & flares() {
return model_flares;
}
- /// list of engines
+ /// list of model sound tags
+ inline Sounds & sounds() {
+ return model_sounds;
+ }
+
+ /// list of model particle system tags
inline ParticleSystems & particles() {
return model_particles;
}
@@ -123,18 +131,21 @@ public:
return model_origin;
}
- /// add a light to the model
+ /// add a light tag to the model
void add_light(Light *light);
- /// add a particle system to the model
+ /// add a particle system tag to the model
void add_particles(Particles *particles);
- /// add a flare to the model
+ /// add a flare tag to the model
void add_flare(Flare *flare);
- /// add a docking location to the model
+ /// add a docking location tag to the model
void add_dock(Dock *dock);
+ /// add a sound tag to the model
+ void add_sound(Sound *sound);
+
/// add a fragment group to the model
void add_group(FragmentGroup *group);
@@ -187,6 +198,7 @@ private:
Docks model_docks;
Flares model_flares;
+ Sounds model_sounds;
Lights model_lights;
ParticleSystems model_particles;
Groups model_groups;