Skip to content

Commit

Permalink
Merge pull request #1035 from stephengtuggy/fix/FTL_0.9.x
Browse files Browse the repository at this point in the history
Fix Jumping - 0.9.x
  • Loading branch information
stephengtuggy authored Mar 9, 2025
2 parents c6daf00 + 5c5f7cc commit 23de3c4
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 90 deletions.
14 changes: 12 additions & 2 deletions engine/src/cmd/csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "unit_json_factory.h"
#include "vs_exit.h"

#include <boost/algorithm/string.hpp>

using std::string;

std::vector<string> readCSV(const string &s, string delim) {
Expand Down Expand Up @@ -119,10 +121,18 @@ string writeCSV(const std::map<std::string, std::string> &unit, string delim) {
std::string first_line;
std::string second_line;
for (auto const& pair : unit) {
first_line += addQuote(pair.first, delim);
std::string pair_first = pair.first;
std::string pair_second = pair.second;

// Replaces standard comma with turned comma (U+2E32)
// Prevents CSV corruption on load.
boost::replace_all(pair_first, ",", "");
boost::replace_all(pair_second, ",", "");

first_line += addQuote(pair_first, delim);
first_line += delim[0];

second_line += addQuote(pair.second, delim);
second_line += addQuote(pair_second, delim);
second_line += delim[0];
}

Expand Down
22 changes: 11 additions & 11 deletions engine/src/cmd/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ inline static float perspectiveFactor(float d) {
}
}

Drawable::Drawable() :
halos(new HaloSystem()),
animatedMesh(true),
activeAnimation(0),
timeperframe(3.0),
done(true),
activeMesh(0),
nextactiveMesh(1),
infiniteLoop(true),
loopCount(0),
curtime(0.0) {
Drawable::Drawable() : halos(new HaloSystem()),
animatedMesh(true),
activeAnimation(0),
timeperframe(3.0),
done(true),
activeMesh(0),
nextactiveMesh(1),
infiniteLoop(true),
loopCount(0),
num_chunks(0),
curtime(0.0) {
}

Drawable::~Drawable() {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/energetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Energetic::Energetic() : energy(0, 0),
afterburnenergy(0),
afterburntype(0) {
jump.warpDriveRating = 0;
jump.energy = 100;
jump.energy = 0.1;
jump.insysenergy = configuration()->warp_config.insystem_jump_cost * jump.energy;
jump.drive = -2;
jump.delay = 5;
Expand Down
11 changes: 5 additions & 6 deletions engine/src/cmd/role_bitmask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ static vsUMap<string, int> rolemap;
static vsUMap<int, string> irolemap;

unsigned char InternalGetRole(const std::string &s) {
vsUMap<string, int>::const_iterator i = rolemap.find(strtoupper(s));
const vsUMap<string, int>::const_iterator i = rolemap.find(strtoupper(s));
if (i != rolemap.end()) {
return (*i).second;
return i->second;
}
return 0;
}

const std::string &InternalGetStrRole(unsigned char c) {
static const std::string empty;

vsUMap<int, string>::const_iterator i = irolemap.find(c);
const vsUMap<int, string>::const_iterator i = irolemap.find(c);
if (i != irolemap.end()) {
return (*i).second;
return i->second;
}
return rolemap.size() ? rolemap.begin()->first : empty;
return !rolemap.empty() ? rolemap.begin()->first : empty;
}

std::vector<std::vector<std::string> > buildscripts() {
Expand Down Expand Up @@ -290,4 +290,3 @@ unsigned int getCapitalRoles() {
return retval;
}
}

14 changes: 5 additions & 9 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,16 @@ void YawPitchRollParser(std::string unit_key,
void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_game) {
Unit::XML xml;
xml.unitModifications = modification.c_str();
xml.randomstartframe = ((float) rand()) / RAND_MAX;
xml.randomstartframe = static_cast<float>(rand()) / RAND_MAX;
xml.randomstartseconds = 0;
xml.calculated_role = false;
xml.damageiterator = 0;
xml.shieldmesh = NULL;
xml.rapidmesh = NULL;
xml.shieldmesh = nullptr;
xml.rapidmesh = nullptr;
xml.hasColTree = true;
xml.unitlevel = 0;
xml.unitscale = 1;
xml.data = xml.shieldmesh = xml.rapidmesh = NULL; //was uninitialized memory
xml.data = xml.shieldmesh = xml.rapidmesh = nullptr; //was uninitialized memory
string tmpstr;
csvRow = unit_identifier;

Expand Down Expand Up @@ -1403,11 +1403,7 @@ string Unit::WriteUnitString() {
}
unit["Tractorability"] = trac;
}
unit["Unit_Role"] = getUnitRole();

return writeCSV(unit);
}





40 changes: 25 additions & 15 deletions engine/src/gfx/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ void Mesh::InitUnit() {
numlods = 1;
alphatest = 0;
lodsize = FLT_MAX;
forcelogos = NULL;
squadlogos = NULL;
forcelogos = nullptr;
squadlogos = nullptr;
local_pos = Vector(0, 0, 0);
blendSrc = ONE;
blendDst = ZERO;
vlist = NULL;
vlist = nullptr;
mn = Vector(0, 0, 0);
mx = Vector(0, 0, 0);
radialSize = 0;
if (Decal.empty()) {
Decal.push_back(NULL);
Decal.push_back(nullptr);
}

//texturename[0] = -1;
numforcelogo = numsquadlogo = 0;
myMatNum = 0; //default material!
//scale = Vector(1.0,1.0,1.0);
refcount = 1; //FIXME VEGASTRIKE THIS _WAS_ zero...NOW ONE
orig = NULL;
orig = nullptr;

envMapAndLit = 0x3;
setEnvMap(GFXTRUE);
setLighting(GFXTRUE);
detailTexture = NULL;
draw_queue = NULL;
detailTexture = nullptr;
draw_queue = nullptr;
will_be_drawn = GFXFALSE;
draw_sequence = 0;

Expand All @@ -122,7 +122,12 @@ Mesh::Mesh() {
}

bool Mesh::LoadExistant(Mesh *oldmesh) {
*this = *oldmesh;
try {
*this = *oldmesh;
} catch (std::exception& ex) {
VS_LOG(error, (boost::format("Error in %1%: '%2%'") % __FUNCTION__ % ex.what()));
return false;
}
oldmesh->refcount++;
orig = oldmesh;
return true;
Expand All @@ -131,14 +136,19 @@ bool Mesh::LoadExistant(Mesh *oldmesh) {
bool Mesh::LoadExistant(const string filehash, const Vector &scale, int faction) {
Mesh *oldmesh;

hash_name = VSFileSystem::GetHashName(filehash, scale, faction);
oldmesh = meshHashTable.Get(hash_name);
if (oldmesh == 0) {
hash_name = VSFileSystem::GetSharedMeshHashName(filehash, scale, faction);
try {
hash_name = VSFileSystem::GetHashName(filehash, scale, faction);
oldmesh = meshHashTable.Get(hash_name);
}
if (0 != oldmesh) {
return LoadExistant(oldmesh);
if (oldmesh == nullptr) {
hash_name = VSFileSystem::GetSharedMeshHashName(filehash, scale, faction);
oldmesh = meshHashTable.Get(hash_name);
}
if (nullptr != oldmesh) {
return LoadExistant(oldmesh);
}
} catch (std::exception& ex) {
VS_LOG(error, (boost::format("Error in %1%: '%2%'") % __FUNCTION__ % ex.what()));
return false;
}
return false;
}
Expand Down
44 changes: 22 additions & 22 deletions engine/src/gfx/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,49 +189,49 @@ class Mesh {
static Hashtable<std::string, Mesh, MESH_HASTHABLE_SIZE> meshHashTable;
static Hashtable<std::string, std::vector<int>, MESH_HASTHABLE_SIZE> animationSequences;
///The refcount:: how many meshes are referencing the appropriate original
int refcount;
int refcount{1};
///bounding box
Vector mx;
Vector mn;
///The radial size of this mesh
float radialSize;
float radialSize{};
///num lods contained in the array of Mesh "orig"
int numlods;
float framespersecond; //for animation
Mesh *orig;
int numlods{};
float framespersecond{}; //for animation
Mesh *orig{};
///The size that this LOD (if original) comes into effect
float lodsize;
float lodsize{FLT_MAX};
///The number of force logos on this mesh (original)
Logo *forcelogos;
int numforcelogo;
Logo *forcelogos{};
int numforcelogo{};
///The number of squad logos on this mesh (original)
Logo *squadlogos;
int numsquadlogo;
Logo *squadlogos{};
int numsquadlogo{};
///tri,quad,line, strips, etc
GFXVertexList *vlist;
GFXVertexList *vlist{};
///The number of the appropriate material for this mesh (default 0)
unsigned int myMatNum;
unsigned int myMatNum{};
///The technique used to render this mesh
TechniquePtr technique;
///The decal relevant to this mesh
vector<Texture *> Decal;
Texture *detailTexture;
Texture *detailTexture{};
vector<Vector> detailPlanes;
float polygon_offset;
float polygon_offset{};
///whether this should be environment mapped 0x1 and 0x2 for if it should be lit (ored together)
char envMapAndLit;
char envMapAndLit{0x3};
///Whether this original will be drawn this frame
GFXBOOL will_be_drawn;
GFXBOOL will_be_drawn{};
///The blend functions
bool convex;
unsigned char alphatest;
enum BLENDFUNC blendSrc;
enum BLENDFUNC blendDst;
bool convex{};
unsigned char alphatest{};
enum BLENDFUNC blendSrc{ONE};
enum BLENDFUNC blendDst{ZERO};

/// Support for reorganized rendering
vector<MeshDrawContext> *draw_queue;
vector<MeshDrawContext> *draw_queue{};
/// How transparent this mesh is (in what order should it be rendered in
int draw_sequence;
int draw_sequence{};
///The name of this unit
string hash_name;
///Setting all values to defaults (good for mesh copying and stuff)
Expand Down
24 changes: 10 additions & 14 deletions engine/src/gfx/mesh_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,22 @@ extern Hashtable<std::string, std::vector<Mesh *>, MESH_HASTHABLE_SIZE> bfxmHash

Mesh::~Mesh() {
if (!orig || orig == this) {
for (int j = 0; j < NUM_MESH_SEQUENCE; j++) {
for (OrigMeshVector::iterator it = undrawn_meshes[j].begin(); it != undrawn_meshes[j].end(); ++it) {
if (it->orig == this) {
undrawn_meshes[j].erase(it--);
VS_LOG(debug, "stale mesh found in draw queue--removed!");
}
for (auto & undrawn_mesh_vec : undrawn_meshes) {
if (!undrawn_mesh_vec.empty()) {
auto first_to_remove = std::stable_partition(undrawn_mesh_vec.begin(),
undrawn_mesh_vec.end(),
[this](const auto &pi) { return pi.orig != this; });
undrawn_mesh_vec.erase(first_to_remove, undrawn_mesh_vec.end());
}
}
if (vlist != nullptr) {
delete vlist;
vlist = nullptr;
}
for (size_t i = 0; i < Decal.size(); ++i) {
if (Decal[i] != nullptr) {
delete Decal[i];
Decal[i] = nullptr;
for (auto & i : Decal) {
if (i != nullptr) {
delete i;
i = nullptr;
}
}
if (squadlogos != nullptr) {
Expand All @@ -455,10 +455,6 @@ Mesh::~Mesh() {
} else {
orig->refcount--;
VS_LOG(debug, (boost::format("orig refcount: %1%") % refcount));
if (orig->refcount == 0) {
delete[] orig;
orig = nullptr;
}
}
}

Expand Down
20 changes: 13 additions & 7 deletions engine/src/gfx/mesh_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,17 +1323,23 @@ vector<Mesh *> Mesh::LoadMeshes(const char *filename,
* }*/
string hash_name = VSFileSystem::GetHashName(filename, scale, faction);
vector<Mesh *> *oldmesh = bfxmHashTable.Get(hash_name);
if (oldmesh == 0) {
if (oldmesh == nullptr) {
hash_name = VSFileSystem::GetSharedMeshHashName(filename, scale, faction);
oldmesh = bfxmHashTable.Get(hash_name);
}
if (oldmesh && !oldmesh->empty() && oldmesh->size() < UINT32_MAX) {
vector<Mesh *> ret;
for (auto m : *oldmesh) {
ret.push_back(new Mesh());
ret.back()->LoadExistant(m->orig ? m->orig : m);
if (oldmesh) {
if (oldmesh->size() > 0 && oldmesh->size() < UINT32_MAX) {
vector<Mesh *> ret;
for (auto m : *oldmesh) {
ret.push_back(new Mesh());
ret.back()->LoadExistant(m->orig ? m->orig : m);
}
return ret;
} else {
VS_LOG_FLUSH_EXIT(fatal,
(boost::format("Fatal error in %1%: oldmesh->size() out of range!") % __FUNCTION__),
-25);
}
return ret;
}
VSFile f;
VSError err = f.OpenReadOnly(filename, MeshFile);
Expand Down
5 changes: 2 additions & 3 deletions engine/src/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ class Hashtable : public vsUMap<KEY, VALUE *> {

VALUE *Get(const KEY &key) const {
typename supertype::const_iterator iter = this->find(key);
typename supertype::const_iterator end = this->end();
if (iter != end) {
if (iter != this->end()) {
return iter->second;
}
return NULL;
return nullptr;
}

void Put(const KEY &key, VALUE *value) {
Expand Down

0 comments on commit 23de3c4

Please sign in to comment.