Skip to content

Commit

Permalink
WIP: Add LodColl, SharedPtrHashtable; etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengtuggy committed Jan 25, 2025
1 parent c16e740 commit 7be29bd
Show file tree
Hide file tree
Showing 38 changed files with 517 additions and 294 deletions.
2 changes: 2 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ SET(LIBGFXGENERIC_SOURCES
src/gfx/soundcontainer_generic.cpp
src/gfx/sphere_generic.cpp
src/gfx/tvector.cpp
src/gfx/lod_coll.cpp
src/gfx/lod_coll.h
)

SET(LIBGFXCLIENT_SOURCES
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/asteroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Asteroid : public Unit {
/// default constructor forbidden
Asteroid();

Asteroid(std::vector<Mesh *> m, bool b, int i) : Unit(m, b, i) {
Asteroid(std::deque<std::shared_ptr<Mesh>> m, bool b, int i) : Unit(m, b, i) {
}

/// copy constructor forbidden
Expand Down
11 changes: 5 additions & 6 deletions engine/src/cmd/atmosphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ class Atmosphere {

class SunBox {
public:
SunBox(Mesh *m) : sunbox(m) {
SunBox(std::shared_ptr<Mesh> m) : sunbox(m) {
}

~SunBox();
Mesh *sunbox;
std::shared_ptr<Mesh> sunbox;
};
void setArray(float *, const GFXColor &);
void setArray1(float *, const GFXColor &);
/* Internal state information */
Mesh *dome; /* entire sky; for texture mapping */
std::shared_ptr<Mesh> dome; /* entire sky; for texture mapping */
/* 3 rendering passes, to preserve framerate */
Mesh *cap; /* mid to zenith */
Mesh *stack; /* horizon to zenith */
std::shared_ptr<Mesh> cap; /* mid to zenith */
std::shared_ptr<Mesh> stack; /* horizon to zenith */
/* box around the sun (single star for now) */
std::vector<SunBox *> sunboxes;
Matrix tmatrix;
Expand Down Expand Up @@ -96,4 +96,3 @@ class Atmosphere {
* the transformation matrix */
static void DrawAtmospheres();
};

3 changes: 1 addition & 2 deletions engine/src/cmd/briefing.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Briefing {
public:
//Very reduced unit class
class Ship {
std::vector<class Mesh *> meshdata;
std::vector<class std::shared_ptr<Mesh> > meshdata;
Vector pos;
std::list<BriefingOrder> orders;
public:
Expand Down Expand Up @@ -86,4 +86,3 @@ class Briefing {
Briefing();
~Briefing();
};

3 changes: 1 addition & 2 deletions engine/src/cmd/cont_terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class StarSystem;
const int numcontterr = 4;
struct MeshDat {
class Mesh *mesh;
class std::shared_ptr<Mesh> mesh;
class csOPCODECollider *collider;
Matrix mat;
};
Expand Down Expand Up @@ -76,4 +76,3 @@ class ContinuousTerrain {
Z = sizeZ;
}
};

26 changes: 13 additions & 13 deletions engine/src/cmd/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Drawable::Drawable() :
}

Drawable::~Drawable() {
for (Mesh *mesh : meshdata) {
for (std::shared_ptr<Mesh> mesh : meshdata) {
if (mesh != nullptr) {
delete mesh;
mesh = nullptr;
Expand All @@ -92,7 +92,7 @@ bool Drawable::DrawableInit(const char *filename, int faction,
anifilename += string("_") + string(animationExt);
}

std::vector<Mesh *> *meshes = new vector<Mesh *>();
std::deque<std::shared_ptr<Mesh>> *meshes = new std::deque<std::shared_ptr<Mesh>>();
int i = 1;
char count[30] = "1";
string dir = anifilename;
Expand Down Expand Up @@ -120,7 +120,7 @@ bool Drawable::DrawableInit(const char *filename, int faction,
unit_name += count;
string path = dir + "/" + unit_name + ".bfxm";
if (VSFileSystem::FileExistsData(path, VSFileSystem::MeshFile) != -1) {
Mesh *m = Mesh::LoadMesh(path.c_str(), Vector(1, 1, 1), faction, flightgrp);
std::shared_ptr<Mesh> m = Mesh::LoadMesh(path.c_str(), Vector(1, 1, 1), faction, flightgrp);
meshes->push_back(m);
#ifdef DEBUG_MESH_ANI
VS_LOG(debug, (boost::format("Animated Mesh: %1% loaded - with: %2% vertices.") % path % m->getVertexList()->GetNumVertices()));
Expand Down Expand Up @@ -450,7 +450,7 @@ void Drawable::DrawNow(const Matrix &mato, float lod) {
Mount *mahnt = &unit->mounts[i];
if (game_options()->draw_weapons) {
if (mahnt->xyscale != 0 && mahnt->zscale != 0) {
Mesh *gun = mahnt->type->gun;
std::shared_ptr<Mesh> gun = mahnt->type->gun;
if (gun && mahnt->status != Mount::UNCHOSEN) {
Transformation mountLocation(mahnt->GetMountOrientation(), mahnt->GetMountLocation().Cast());
mountLocation.Compose(Transformation::from_matrix(mat), wmat);
Expand Down Expand Up @@ -517,7 +517,7 @@ void Drawable::UpdateFrames() {
}
}

void Drawable::addAnimation(std::vector<Mesh *> *meshes, const char *name) {
void Drawable::addAnimation(std::deque<std::shared_ptr<Mesh>> *meshes, const char *name) {
if ((meshes->size() > 0) && animatedMesh) {
vecAnimations.push_back(meshes);
vecAnimationNames.push_back(string(name));
Expand Down Expand Up @@ -749,7 +749,7 @@ void Drawable::DrawSubunits(bool on_screen, Matrix wmat, Cloak cloak, float aver

for (int i = 0; (int) i < unit->getNumMounts(); i++) {
Mount *mount = &unit->mounts[i];
Mesh *gun = mount->type->gun;
std::shared_ptr<Mesh> gun = mount->type->gun;

// Has to come before check for on screen, as a fired beam can still be seen
// even if the subunit firing it isn't on screen.
Expand Down Expand Up @@ -855,14 +855,14 @@ void Drawable::Split(int level) {
if (nm <= 0 && num_chunks == 0) {
return;
}
vector<Mesh *> old = this->meshdata;
Mesh *shield = old.back();
std::deque<std::shared_ptr<Mesh>> old = this->meshdata;
std::shared_ptr<Mesh> shield = old.back();
old.pop_back();

vector<unsigned int> meshsizes;
if (num_chunks) {
size_t i;
vector<Mesh *> nw;
std::deque<std::shared_ptr<Mesh>> nw;
unsigned int which_chunk = rand() % num_chunks;
string chunkname = UniverseUtil::LookupUnitStat(unit->name, fac, "Chunk_" + XMLSupport::tostring(which_chunk));
string dir = UniverseUtil::LookupUnitStat(unit->name, fac, "Directory");
Expand All @@ -888,7 +888,7 @@ void Drawable::Split(int level) {
old = nw;
} else {
for (int split = 0; split < level; split++) {
vector<Mesh *> nw;
std::deque<std::shared_ptr<Mesh>> nw;
size_t oldsize = old.size();
for (size_t i = 0; i < oldsize; i++) {
PlaneNorm.Set(rand() - RAND_MAX / 2, rand() - RAND_MAX / 2, rand() - RAND_MAX / 2 + .5);
Expand Down Expand Up @@ -921,8 +921,8 @@ void Drawable::Split(int level) {
}
nm = old.size() - 1;
unsigned int k = 0;
vector<Mesh *> tempmeshes;
for (vector<Mesh *>::size_type i = 0; i < meshsizes.size(); i++) {
std::deque<std::shared_ptr<Mesh>> tempmeshes;
for (std::deque<std::shared_ptr<Mesh>>::size_type i = 0; i < meshsizes.size(); i++) {
Unit *splitsub;
tempmeshes.clear();
tempmeshes.reserve(meshsizes[i]);
Expand Down Expand Up @@ -961,7 +961,7 @@ void Drawable::LightShields(const Vector &pnt, const Vector &normal, float amt,
// Not sure about shield percentage - more variance for more damage?
// TODO: figure out the above comment

Mesh *mesh = meshdata.back();
std::shared_ptr<Mesh> mesh = meshdata.back();

if (!mesh) {
return;
Expand Down
6 changes: 3 additions & 3 deletions engine/src/cmd/drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ using std::map;
class Drawable {
public:
//number of meshes (each with separate texture) this unit has
std::vector<Mesh *> meshdata;
std::deque<std::shared_ptr<Mesh>> meshdata;
std::unique_ptr<HaloSystem> halos;

protected:
vector<vector<Mesh *> *> vecAnimations;
vector<std::deque<std::shared_ptr<Mesh>> *> vecAnimations;
vector<string> vecAnimationNames;

bool animatedMesh;
Expand Down Expand Up @@ -117,7 +117,7 @@ class Drawable {

bool isContinuousLoop() const;

void addAnimation(std::vector<Mesh *> *meshes, const char *name);
void addAnimation(std::deque<std::shared_ptr<Mesh>> *meshes, const char *name);

double framesPerSecond() const;

Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Missile : public Unit {
float radmult,
float detonation_radius);

Missile(std::vector<Mesh *> m, bool b, int i) :
Missile(std::deque<std::shared_ptr<Mesh>> m, bool b, int i) :
Unit(m, b, i) {
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void DestroyMount(Mount *mount) {
mount->status = Mount::DESTROYED;
}

float Mount::ComputeAnimatedFrame(Mesh *gun) {
float Mount::ComputeAnimatedFrame(std::shared_ptr<Mesh> gun) {
if (type->type == WEAPON_TYPE::BEAM) {
if (ref.gun) {
if (ref.gun->Ready()) {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Mount {
//for guns!
float xyscale;
float zscale;
float ComputeAnimatedFrame(Mesh *gun);
float ComputeAnimatedFrame(std::shared_ptr<Mesh> gun);
//pass inunit so it can update gunspeed
void ReplaceMounts(Unit *unit, const Mount *other);
double Percentage(const Mount *newammo) const;
Expand Down
27 changes: 13 additions & 14 deletions engine/src/cmd/planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ string GetElMeshName(string name, string faction, char direction) {
return elevator_mesh;
}

static void SetFogMaterialColor(Mesh *thus, const GFXColor &color, const GFXColor &dcolor) {
static void SetFogMaterialColor(std::shared_ptr<Mesh> thus, const GFXColor &color, const GFXColor &dcolor) {
GFXMaterial m{};
setMaterialAmbient(m, 0.0);
setMaterialDiffuse(m, configuration()->graphics_config.atmosphere_diffuse * dcolor);
Expand All @@ -120,7 +120,7 @@ static void SetFogMaterialColor(Mesh *thus, const GFXColor &color, const GFXColo
thus->SetMaterial(m);
}

Mesh *MakeFogMesh(const AtmosphericFogMesh &f, float radius) {
std::shared_ptr<Mesh> MakeFogMesh(const AtmosphericFogMesh &f, float radius) {
static int count = 0;
count++;
string nam = f.meshname + XMLSupport::tostring(count) + ".png";
Expand Down Expand Up @@ -149,7 +149,7 @@ Mesh *MakeFogMesh(const AtmosphericFogMesh &f, float radius) {
}
vector<string> override;
override.push_back(nam);
Mesh *ret = Mesh::LoadMesh(f.meshname.c_str(),
std::shared_ptr<Mesh> ret = Mesh::LoadMesh(f.meshname.c_str(),
Vector(f.scale * radius, f.scale * radius, f.scale * radius),
0,
nullptr,
Expand All @@ -166,7 +166,7 @@ class AtmosphereHalo : public Unit {
public:
float planetRadius;

AtmosphereHalo(float radiusOfPlanet, vector<Mesh *> &meshes, int faction) :
AtmosphereHalo(float radiusOfPlanet, std::deque<std::shared_ptr<Mesh>> &meshes, int faction) :
Unit(meshes, true, faction) {
planetRadius = radiusOfPlanet;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ Planet::Planet(QVector x,
if (jump->name != "LOAD_FAILED") {
anytrue = true;
radius = jump->rSize();
Mesh *shield = jump->meshdata.size() ? jump->meshdata.back() : nullptr;
std::shared_ptr<Mesh> shield = jump->meshdata.size() ? jump->meshdata.back() : nullptr;
if (jump->meshdata.size()) {
jump->meshdata.pop_back();
}
Expand Down Expand Up @@ -496,7 +496,7 @@ void Planet::AddAtmosphere(const std::string &texture,
if (meshdata.empty()) {
meshdata.push_back(nullptr);
}
Mesh *shield = meshdata.back();
std::shared_ptr<Mesh> shield = meshdata.back();
meshdata.pop_back();
const int stacks = configuration()->graphics_config.planet_detail_stacks;
meshdata.push_back(new SphereMesh(radius,
Expand Down Expand Up @@ -533,7 +533,7 @@ void Planet::AddCity(const std::string &texture,
if (meshdata.empty()) {
meshdata.push_back(nullptr);
}
Mesh *shield = meshdata.back();
std::shared_ptr<Mesh> shield = meshdata.back();
meshdata.pop_back();
const float materialweight = configuration()->graphics_config.city_light_strength;
const float daymaterialweight = configuration()->graphics_config.day_city_light_strength;
Expand All @@ -557,12 +557,12 @@ void Planet::AddFog(const std::vector<AtmosphericFogMesh> &v, bool opticalillusi
meshdata.push_back(nullptr);
}
#ifdef MESHONLY
Mesh *shield = meshdata.back();
std::shared_ptr<Mesh> shield = meshdata.back();
meshdata.pop_back();
#endif
std::vector<Mesh *> fogs;
std::deque<std::shared_ptr<Mesh>> fogs;
for (unsigned int i = 0; i < v.size(); ++i) {
Mesh *fog = MakeFogMesh(v[i], rSize());
std::shared_ptr<Mesh> fog = MakeFogMesh(v[i], rSize());
fogs.push_back(fog);
}
Unit *fawg;
Expand Down Expand Up @@ -594,7 +594,7 @@ void Planet::AddRing(const std::string &texture,
if (meshdata.empty()) {
meshdata.push_back(nullptr);
}
Mesh *shield = meshdata.back();
std::shared_ptr<Mesh> shield = meshdata.back();
meshdata.pop_back();
int stacks = configuration()->graphics_config.planet_detail_stacks;
if (slices > 0) {
Expand Down Expand Up @@ -650,9 +650,9 @@ Vector Planet::AddSpaceElevator(const std::string &name, const std::string &fact
}
Matrix ElevatorLoc(Vector(dir.j, dir.k, dir.i), dir, Vector(dir.k, dir.i, dir.j));
scale = dir * radius + Vector(1, 1, 1) - dir;
Mesh *shield = meshdata.back();
std::shared_ptr<Mesh> shield = meshdata.back();
string elevator_mesh = GetElMeshName(name, faction, direction); //filename
Mesh *tmp = meshdata.back() = Mesh::LoadMesh(elevator_mesh.c_str(),
std::shared_ptr<Mesh> tmp = meshdata.back() = Mesh::LoadMesh(elevator_mesh.c_str(),
scale,
FactionUtil::
GetFactionIndex(faction),
Expand Down Expand Up @@ -958,4 +958,3 @@ bool operator==(const Planet &lhs, const Planet &rhs) {

return equal;
}

4 changes: 2 additions & 2 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "components/component_utils.h"

extern int GetModeFromName(const char *input_buffer);
extern void pushMesh(std::vector<Mesh *> &mesh,
extern void pushMesh(std::deque<std::shared_ptr<Mesh>> &mesh,
float &randomstartframe,
float &randomstartseconds,
const char *filename,
Expand All @@ -65,7 +65,7 @@ extern void pushMesh(std::vector<Mesh *> &mesh,
void addShieldMesh(Unit::XML *xml, const char *filename, const float scale, int faction, class Flightgroup *fg);
void addRapidMesh(Unit::XML *xml, const char *filename, const float scale, int faction, class Flightgroup *fg);

void AddMeshes(std::vector<Mesh *> &xmeshes,
void AddMeshes(std::deque<std::shared_ptr<Mesh>> &xmeshes,
float &randomstartframe,
float &randomstartseconds,
float unitscale,
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/unit_csv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef VEGA_STRIKE_ENGINE_CMD_UNIT_CSV_H
#define VEGA_STRIKE_ENGINE_CMD_UNIT_CSV_H

extern void AddMeshes(std::vector<Mesh *> &xmeshes,
extern void AddMeshes(std::deque<std::shared_ptr<Mesh>> &xmeshes,
float &randomstartframe,
float &randomstartseconds,
float unitscale,
Expand Down
3 changes: 1 addition & 2 deletions engine/src/cmd/unit_factory_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Unit *UnitFactory::createServerSideUnit(const char *filename,
fg_subnumber);
}

Unit *UnitFactory::createUnit(vector<Mesh *> &meshes, bool Subunit, int faction) {
Unit *UnitFactory::createUnit(std::deque<std::shared_ptr<Mesh>> &meshes, bool Subunit, int faction) {
return new Unit(meshes,
Subunit,
faction);
Expand Down Expand Up @@ -285,4 +285,3 @@ void UnitFactory::broadcastUnit(Unit *unit, unsigned short zone) {
}
}
}

Loading

0 comments on commit 7be29bd

Please sign in to comment.