Skip to content

Commit

Permalink
fix: remove unnecessary length fields from structs
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed May 24, 2024
1 parent ec76d60 commit 8c2c919
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 167 deletions.
58 changes: 22 additions & 36 deletions include/cbreader/rmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ constexpr std::uint32_t MAX_SOUND_EMITTERS = 16;
struct Header
{
// Length prefixed string
std::uint32_t header_length = 0;
std::string header;

/** Defines whether or not the RMesh file has any triggers embedded within the file. */
Expand All @@ -26,7 +25,6 @@ struct Texture
{
std::byte blendType;

std::uint32_t textureNameLength = 0;
std::string textureName;
};

Expand All @@ -35,31 +33,27 @@ struct Vertex
Vector3 vertex;
Vector2 uv;

float unk1;
float unk2;
float unk1{};
float unk2{};

std::byte r;
std::byte g;
std::byte b;
std::byte r{};
std::byte g{};
std::byte b{};
};

struct Surface
{
Texture textures[2];

std::uint32_t vertexCount = 0;
std::vector<Vertex> vertices;

std::uint32_t trianglesCount = 0;
std::vector<Triangle> triangles;
};

struct Mesh
{
std::int32_t surfaceCount;
std::vector<Surface> surfaces;

std::uint32_t nameLength = 0;
std::string name;
};

Expand All @@ -70,75 +64,69 @@ struct Mesh
*/
struct Entity
{
std::uint32_t classNameLength = 0;
std::string className;

/** This is read per entity. It would be ideal to read it in Entity, but EntityModel is special in that it has the model file name THEN the position. */
Vector3 position;
Vector3 rotation;
Vector3 scale;

virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
virtual void Read(BufferStream& stream, std::string _className);
};

struct EntityScreen : Entity
struct EntityScreen : public Entity
{
std::uint32_t imgPathLength = 0;
std::string imgPath;

virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
void Read(BufferStream& stream, std::string _className) override;
};

struct EntityWaypoint : Entity
struct EntityWaypoint : public Entity
{
virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
void Read(BufferStream& stream, std::string _className) override;
};

struct EntityLight : Entity
struct EntityLight : public Entity
{
/** SCP:CB calculates this as range/2000.0 in the RMesh code*/
float range = 0.f;

/** Space delimited color string. Color is 3 ints, and multiplied by intensity when reading. */
std::uint32_t colorLength = 0;
std::string color;

/** SCP:CB calculates this as Min(intensity*0.8,1)*/
float intensity = 0.f;

virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
void Read(BufferStream& stream, std::string _className) override;
};

struct EntitySpotLight : EntityLight
struct EntitySpotLight : public EntityLight
{
std::uint32_t anglesLength = 0;
std::string angles;

std::uint32_t innerConeAngle = 0;
std::uint32_t outerConeAngle = 0;

virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
void Read(BufferStream& stream, std::string _className) override;
};

struct EntitySoundEmitter : Entity
struct EntitySoundEmitter : public Entity
{
virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
void Read(BufferStream& stream, std::string _className) override;
};

struct EntityPlayerStart : Entity
struct EntityPlayerStart : public Entity
{
std::uint32_t anglesLength = 0;
std::string angles;

virtual void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className);
void Read(BufferStream& stream, std::string _className) override;
};

struct EntityModel : Entity
struct EntityModel : public Entity
{
std::uint32_t pathLength = 0;
std::string path;

void Read(BufferStream stream, std::uint32_t _classNameLength, std::string _className) override;
void Read(BufferStream& stream, std::string _className) override;
};

/**
Expand All @@ -154,10 +142,8 @@ struct RMesh
Mesh drawnMesh;
Mesh collisionMesh;

std::uint32_t triggerBoxCount = 0;
std::vector<Mesh> triggerBoxes;

std::uint32_t entityCount = 0;
std::vector<Entity> entities;

/**
Expand All @@ -169,6 +155,6 @@ struct RMesh
*/
bool Read(const std::string& path);

Mesh ReadDrawnMesh(BufferStream& stream);
Mesh ReadCollisionMesh(BufferStream& stream);
static Mesh ReadDrawnMesh(BufferStream& stream);
static Mesh ReadCollisionMesh(BufferStream& stream);
};
Loading

0 comments on commit 8c2c919

Please sign in to comment.