diff --git a/src/dynamic_body.h b/src/dynamic_body.h index 60dd210..ec5de19 100644 --- a/src/dynamic_body.h +++ b/src/dynamic_body.h @@ -4,8 +4,6 @@ #include "vector3.h" #include "matrix4x4.h" -class ObjMesh; - class DynamicBody : public ModelBody { public: OBJDEF(DynamicBody, ModelBody, DYNAMICBODY); @@ -35,5 +33,4 @@ protected: virtual void Load(void); private: - ObjMesh* m_mesh; }; diff --git a/src/info_view.cpp b/src/info_view.cpp index 0fa4889..b647cb8 100644 --- a/src/info_view.cpp +++ b/src/info_view.cpp @@ -23,17 +23,17 @@ void InfoView::UpdateInfo(void) { Equip::Type e = L3D::player->m_equipment.Get(Equip::SLOT_ENGINE); nfo += std::string("\n\nDrive system: ")+EquipType::types[e].name; - shipstats_t stats; - L3D::player->CalcStats(&stats); + const shipstats_t* stats; + stats = L3D::player->CalcStats(); snprintf(buf, sizeof(buf), "n\nCapacity: %dt\n" "Free: %dt\n" "Used: %dt\n" - "All-up weight: %dt", stats.max_capacity, - stats.free_capacity, stats.used_capacity, - stats.total_mass); + "All-up weight: %dt", stats->max_capacity, + stats->free_capacity, stats->used_capacity, + stats->total_mass); nfo += std::string(buf); - snprintf(buf, sizeof(buf), "\n\nHyperspace range: %.2f light years.", stats.hyperspace_range); + snprintf(buf, sizeof(buf), "\n\nHyperspace range: %.2f light years.", stats->hyperspace_range); nfo += std::string(buf); info1->SetText(nfo); diff --git a/src/sbre_viewer.cpp b/src/sbre_viewer.cpp index aeb09d1..3ce4fc5 100644 --- a/src/sbre_viewer.cpp +++ b/src/sbre_viewer.cpp @@ -214,7 +214,7 @@ static void raytraceCollMesh(vector3d camPos, vector3d camera_up, vector3d camer glPushMatrix(); glLoadIdentity(); - glActiveTextureARB(GL_TEXTURE0_ARB); + //glActiveTextureARB(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glBindTexture(GL_TEXTURE_2D, mytexture); diff --git a/src/sector_view.cpp b/src/sector_view.cpp index ffa04b8..38d368c 100644 --- a/src/sector_view.cpp +++ b/src/sector_view.cpp @@ -163,13 +163,13 @@ void SectorView::DrawSector(int sx, int sy) { glCallList(m_gluDiskDlist); /* Player location indicator. */ if((sx == playerLocSecX) && (sy == playerLocSecY) && (num == playerLocSysIdx)) { - shipstats_t stats; - L3D::player->CalcStats(&stats); + const shipstats_t* stats; + stats = L3D::player->CalcStats(); glColor3f(0, 0, 1); glBegin(GL_LINE_LOOP); /* Draw a lovely circle around our beloved player. */ for(float theta = 0; theta < 2*M_PI; theta += 0.05*M_PI) { - glVertex3f(stats.hyperspace_range*sin(theta), stats.hyperspace_range*cos(theta), 0); + glVertex3f(stats->hyperspace_range*sin(theta), stats->hyperspace_range*cos(theta), 0); } glEnd(); diff --git a/src/ship.cpp b/src/ship.cpp index 27a1d9d..f2fbcfa 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -112,9 +112,8 @@ Ship::Ship(ShipType::Type shipType) : DynamicBody() { } void Ship::UpdateMass(void) { - shipstats_t s; - CalcStats(&s); - dMassAdjust(&m_mass, s.total_mass*1000); + CalcStats(); + dMassAdjust(&m_mass, m_stats.total_mass*1000); dBodySetMass(m_body, &m_mass); } @@ -124,6 +123,18 @@ bool Ship::OnCollision(Body* b, Uint32 flags) { if(m_flightState != FLYING) return false; else m_testLanded = true; } + if(b->IsType(Object::MODELBODY)) { + vector3d relVel; + if(b->IsType(Object::DYNAMICBODY)) { + relVel = static_cast(b)->GetVelocity() - GetVelocity(); + } else { + relVel = GetVelocity(); + } + /* Crappy recalculation of all this... */ + float v = relVel.Length(); + float kineticEnergy = m_stats.total_mass * v * v; + printf("%f ek\n", kineticEnergy); + } return true; } @@ -155,23 +166,24 @@ void Ship::ClearThrusterState(void) { /* Hyperspace range is: * (200 * hyperspace_class^2) / total_mass (in tonnes) */ -void Ship::CalcStats(shipstats_t* stats) { +const shipstats_t* Ship::CalcStats(void) { const ShipType& stype = GetShipType(); - stats->max_capacity = stype.capacity; - stats->used_capacity = 0; + m_stats.max_capacity = stype.capacity; + m_stats.used_capacity = 0; for(int i = 0; i < Equip::SLOT_MAX; i++) { for(int j = 0; j < stype.equipSlotCapacity[i]; j++) { Equip::Type t = m_equipment.Get((Equip::Slot)i, j); - if(t) stats->used_capacity += EquipType::types[t].mass; + if(t) m_stats.used_capacity += EquipType::types[t].mass; } } - stats->free_capacity = stats->max_capacity - stats->used_capacity; - stats->total_mass = stats->used_capacity + stype.hullMass; + m_stats.free_capacity = m_stats.max_capacity - m_stats.used_capacity; + m_stats.total_mass = m_stats.used_capacity + stype.hullMass; Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE); float hyperclass = EquipType::types[t].pval; - stats->hyperspace_range = 200 * hyperclass * hyperclass / stats->total_mass; + m_stats.hyperspace_range = 200 * hyperclass * hyperclass / m_stats.total_mass; + return &m_stats; } void Ship::Blastoff(void) { diff --git a/src/ship.h b/src/ship.h index 1701953..4f3b730 100644 --- a/src/ship.h +++ b/src/ship.h @@ -31,7 +31,7 @@ public: void ClearThrusterState(void); void SetGunState(int idx, int state); const ShipType& GetShipType(void); - void CalcStats(shipstats_t* stats); + const shipstats_t* CalcStats(void); void UpdateMass(void); vector3d CalcRotDamping(); bool SetWheelState(bool down); /* Returns success of state change, NOT state itself. */ @@ -82,5 +82,6 @@ private: LaserObj m_laserCollisionObj; Body* m_navTarget; Body* m_combatTarget; + shipstats_t m_stats; }; diff --git a/src/space.cpp b/src/space.cpp index 867c4af..5a20f45 100644 --- a/src/space.cpp +++ b/src/space.cpp @@ -342,10 +342,11 @@ static bool _OnCollision2(Object* o1, Object* o2, CollisionContact* c) { return true; } -#define MAX_CONTACTS 10 +#define MAX_CONTACTS 1 static int contact_num; static void hitCallback(CollisionContact* c) { if(contact_num++ >= MAX_CONTACTS) return; + printf("AUCH!! %x\n", SDL_GetTicks()); dContact contact; contact.surface.mode = dContactBounce;