Skip to content

Commit

Permalink
First pass of string work
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jun 24, 2024
1 parent dfe0a71 commit 206de27
Show file tree
Hide file tree
Showing 40 changed files with 269 additions and 386 deletions.
4 changes: 2 additions & 2 deletions source/bsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ build_result_e BuildFile(buildinfo_t *build_info)
return BUILD_OK;
}

void VisitFile(std::string filename, buildinfo_t *build_info)
static void VisitFile(const std::string &filename, buildinfo_t *build_info)
{
LogPrint("\n");
LogPrint("Building %s\n", filename.c_str());
Expand Down Expand Up @@ -308,7 +308,7 @@ void CheckTypeSizes(buildinfo_t *build_info)
assert_size(raw_vertex_t, 4);
}

int AJBSP_BuildNodes(std::string filename, buildinfo_t *build_info)
int AJBSP_BuildNodes(const std::string &filename, buildinfo_t *build_info)
{
// need this early, especially for fatal errors in utility/wad code
ajbsp::SetInfo(build_info);
Expand Down
4 changes: 2 additions & 2 deletions source/bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef enum
BUILD_LumpOverflow
} build_result_e;

int AJBSP_BuildNodes(std::string filename, buildinfo_t *build_info);
int AJBSP_BuildNodes(const std::string &filename, buildinfo_t *build_info);

namespace ajbsp
{
Expand All @@ -97,7 +97,7 @@ void SetInfo(buildinfo_t *info);

// attempt to open a wad. on failure, the FatalError method in the
// buildinfo_t interface is called.
void OpenWad(std::string filename);
void OpenWad(const std::string &filename);

// close a previously opened wad.
void CloseWad();
Expand Down
8 changes: 7 additions & 1 deletion source/bsp_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@ void GetLinedefs()
num_real_lines++;

line->self_ref = (line->left && line->right && (line->left->sector == line->right->sector));

if (line->self_ref)
line->is_precious = true;
}
}

Expand Down Expand Up @@ -1482,6 +1485,9 @@ void ParseUDMF_Block(ajparse::lexer_c &lex, int cur_type)
num_real_lines++;

line->self_ref = (line->left && line->right && (line->left->sector == line->right->sector));

if (line->self_ref)
line->is_precious = true;
}
}

Expand Down Expand Up @@ -2817,7 +2823,7 @@ void SetInfo(buildinfo_t *info)
cur_info = info;
}

void OpenWad(std::string filename)
void OpenWad(const std::string &filename)
{
cur_wad = Wad_file::Open(filename.c_str(), 'a');
if (cur_wad == NULL)
Expand Down
4 changes: 4 additions & 0 deletions source/bsp_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ void EvaluateFastWorker(quadtree_c *tree, seg_t **best_H, seg_t **best_V, int mi
if (part->linedef == NULL)
continue;

/* ignore self-ref and polyobj stuff as partition candidates */
if (part->linedef->is_precious)
continue;

if (part->pdy == 0)
{
// horizontal seg
Expand Down
4 changes: 2 additions & 2 deletions source/csg_doom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ class dummy_line_info_c
int flags;

public:
dummy_line_info_c(std::string _tex, int _special = 0, int _tag = 0, int _flags = 0)
dummy_line_info_c(std::string_view _tex, int _special = 0, int _tag = 0, int _flags = 0)
: tex(_tex), special(_special), tag(_tag), flags(_flags)
{
}
Expand Down Expand Up @@ -2311,7 +2311,7 @@ class dummy_sector_c
return (share_count >= DUMMY_MAX_SHARE);
}

void AddInfo(std::string &tex, int special, int tag, int flags)
void AddInfo(std::string_view tex, int special, int tag, int flags)
{
SYS_ASSERT(!isFull());

Expand Down
2 changes: 0 additions & 2 deletions source/csg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class region_c
void ComputeMidPoint();
void ComputeBounds();
void ClockwiseSnags(); // requires CalcMidPoint()

void DebugDump();
};

class gap_c
Expand Down
28 changes: 14 additions & 14 deletions source/csg_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,36 +203,36 @@ extern int q_low_light;

extern void SPOT_FillPolygon(uint8_t content, const int *shape, int count);

void csg_property_set_c::Add(std::string key, std::string value)
void csg_property_set_c::Add(const std::string &key, std::string_view value)
{
dict[key] = std::string(value);
dict[key] = value;
}

void csg_property_set_c::Remove(std::string key)
void csg_property_set_c::Remove(const std::string &key)
{
dict.erase(key);
}

std::string csg_property_set_c::getStr(std::string key, std::string def_val) const
std::string csg_property_set_c::getStr(const std::string &key, std::string_view def_val) const
{
std::map<std::string, std::string>::const_iterator PI = dict.find(key);

if (PI == dict.end())
{
return def_val;
return std::string(def_val);
}

return PI->second.c_str();
return PI->second;
}

double csg_property_set_c::getDouble(std::string key, double def_val) const
double csg_property_set_c::getDouble(const std::string &key, double def_val) const
{
std::string str = getStr(key);

return !str.empty() ? StringToDouble(str) : def_val;
}

int csg_property_set_c::getInt(std::string key, int def_val) const
int csg_property_set_c::getInt(const std::string &key, int def_val) const
{
std::string str = getStr(key);

Expand Down Expand Up @@ -649,7 +649,7 @@ csg_entity_c::~csg_entity_c()
{
}

bool csg_entity_c::Match(std::string want_name) const
bool csg_entity_c::Match(std::string_view want_name) const
{
return (StringCompare(id, want_name) == 0);
}
Expand Down Expand Up @@ -779,7 +779,7 @@ class brush_quad_node_c

private:
bool IntersectBrush(const csg_brush_c *B, double x1, double y1, double z1, double x2, double y2, double z2,
std::string mode)
std::string_view mode)
{
if (mode[0] == 'v')
{
Expand Down Expand Up @@ -833,7 +833,7 @@ class brush_quad_node_c
}

public:
bool TraceRay(double x1, double y1, double z1, double x2, double y2, double z2, std::string mode)
bool TraceRay(double x1, double y1, double z1, double x2, double y2, double z2, std::string_view mode)
{
for (unsigned int k = 0; k < brushes.size(); k++)
{
Expand Down Expand Up @@ -1611,7 +1611,7 @@ int CSG_trace_ray(lua_State *L)
return 1;
}

bool CSG_TraceRay(double x1, double y1, double z1, double x2, double y2, double z2, std::string mode)
bool CSG_TraceRay(double x1, double y1, double z1, double x2, double y2, double z2, std::string_view mode)
{
SYS_ASSERT(brush_quad_tree);

Expand Down Expand Up @@ -1644,7 +1644,7 @@ void CSG_spot_processing(int x1, int y1, int x2, int y2, int floor_h)

//------------------------------------------------------------------------

csg_property_set_c *CSG_LookupTexProps(std::string name)
csg_property_set_c *CSG_LookupTexProps(const std::string &name)
{
std::map<std::string, csg_property_set_c *>::iterator TPI;

Expand Down Expand Up @@ -1672,7 +1672,7 @@ static void CSG_FreeTexProps()
all_tex_props.clear();
}

void CSG_LinkBrushToEntity(csg_brush_c *B, std::string link_key)
void CSG_LinkBrushToEntity(csg_brush_c *B, const std::string &link_key)
{
for (unsigned int k = 0; k < all_entities.size(); k++)
{
Expand Down
20 changes: 9 additions & 11 deletions source/csg_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,16 @@ class csg_property_set_c
{
}

void Add(std::string key, std::string value);
void Remove(std::string key);
void Add(const std::string &key, std::string_view value);
void Remove(const std::string &key);

std::string getStr(std::string key, std::string def_val = "") const;
std::string getStr(const std::string &key, std::string_view def_val = "") const;

double getDouble(std::string key, double def_val = 0) const;
int getInt(std::string key, int def_val = 0) const;
double getDouble(const std::string &key, double def_val = 0) const;
int getInt(const std::string &key, int def_val = 0) const;

void getHexenArgs(uint8_t *arg5) const;

void DebugDump();

public:
typedef std::map<std::string, std::string>::iterator iterator;

Expand Down Expand Up @@ -252,7 +250,7 @@ class csg_entity_c
csg_entity_c();
~csg_entity_c();

bool Match(std::string want_name) const;
bool Match(std::string_view want_name) const;
};

/***** VARIABLES ****************/
Expand All @@ -268,13 +266,13 @@ extern std::string dummy_plane_tex;

void CSG_Main_Free();

bool CSG_TraceRay(double x1, double y1, double z1, double x2, double y2, double z2, std::string mode);
bool CSG_TraceRay(double x1, double y1, double z1, double x2, double y2, double z2, std::string_view mode);

int CSG_BrushContents(double x, double y, double z, double *liquid_depth = NULL);

csg_property_set_c *CSG_LookupTexProps(std::string name);
csg_property_set_c *CSG_LookupTexProps(const std::string &name);

void CSG_LinkBrushToEntity(csg_brush_c *B, std::string link_key);
void CSG_LinkBrushToEntity(csg_brush_c *B, const std::string &link_key);

//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
13 changes: 7 additions & 6 deletions source/ff_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>

#include "ff.h"
#include "lib_util.h"

extern "C"
{
Expand All @@ -22,32 +23,32 @@ std::string result;

void year()
{
result.append(std::to_string(now.tm_year + 1900));
result.append(NumToString(now.tm_year + 1900));
}

void month()
{
result.append(std::to_string(now.tm_mon + 1));
result.append(NumToString(now.tm_mon + 1));
}

void day()
{
result.append(std::to_string(now.tm_mday));
result.append(NumToString(now.tm_mday));
}

void hour()
{
result.append(std::to_string(now.tm_hour));
result.append(NumToString(now.tm_hour));
}

void minute()
{
result.append(std::to_string(now.tm_min));
result.append(NumToString(now.tm_min));
}

void second()
{
result.append(std::to_string(now.tm_sec));
result.append(NumToString(now.tm_sec));
}

void game()
Expand Down
14 changes: 7 additions & 7 deletions source/g_doom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ bool BuildNodes(std::string filename)

namespace Doom
{
void WriteLump(std::string name, const void *data, uint32_t len)
void WriteLump(std::string_view name, const void *data, uint32_t len)
{
SYS_ASSERT(name.size() <= 8);

Expand All @@ -363,7 +363,7 @@ void WriteLump(std::string name, const void *data, uint32_t len)
}
} // namespace Doom

void Doom::WriteLump(std::string name, qLump_c *lump)
void Doom::WriteLump(std::string_view name, qLump_c *lump)
{
WriteLump(name, lump->GetBuffer(), lump->GetSize());
}
Expand Down Expand Up @@ -429,7 +429,7 @@ static void WriteSections()

} // namespace Doom

void Doom::AddSectionLump(char ch, std::string name, qLump_c *lump)
void Doom::AddSectionLump(char ch, std::string_view name, qLump_c *lump)
{
int k;
switch (ch)
Expand Down Expand Up @@ -459,7 +459,7 @@ void Doom::AddSectionLump(char ch, std::string name, qLump_c *lump)
sections[k]->push_back(lump);
}

bool Doom::StartWAD(std::string filename)
bool Doom::StartWAD(const std::string &filename)
{
if (!WAD_OpenWrite(filename))
{
Expand Down Expand Up @@ -562,7 +562,7 @@ int Doom::v094_begin_level(lua_State *L)
return 0;
}

void Doom::EndLevel(std::string level_name)
void Doom::EndLevel(const std::string &level_name)
{
// terminate header lump with trailing NUL
if (header_lump->GetSize() > 0)
Expand Down Expand Up @@ -695,7 +695,7 @@ int Doom::v094_add_vertex(lua_State *L)
return 0;
}

void Doom::AddSector(int f_h, std::string f_tex, int c_h, std::string c_tex, int light, int special, int tag)
void Doom::AddSector(int f_h, const std::string &f_tex, int c_h, const std::string &c_tex, int light, int special, int tag)
{
if (!UDMF_mode)
{
Expand Down Expand Up @@ -740,7 +740,7 @@ int Doom::v094_add_sector(lua_State *L)
return 0;
}

void Doom::AddSidedef(int sector, std::string l_tex, std::string m_tex, std::string u_tex, int x_offset, int y_offset)
void Doom::AddSidedef(int sector, const std::string &l_tex, const std::string &m_tex, const std::string &u_tex, int x_offset, int y_offset)
{
if (!UDMF_mode)
{
Expand Down
12 changes: 6 additions & 6 deletions source/g_doom.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ extern int sub_format;

/***** FUNCTIONS ****************/

bool StartWAD(std::string filename);
bool StartWAD(const std::string &filename);
bool EndWAD();

void BeginLevel();
void EndLevel(std::string level_name);
void EndLevel(const std::string &level_name);

void WriteLump(std::string name, qLump_c *lump);
void WriteLump(std::string_view name, qLump_c *lump);

// the section parameter can be:
// 'P' : patches // 'F' : flats
// 'S' : sprites // 'C' : colormaps (Boom)
// 'T' : textures (Zdoom)
void AddSectionLump(char section, std::string name, qLump_c *lump);
void AddSectionLump(char section, std::string_view name, qLump_c *lump);

void HeaderPrintf(const char *str, ...);

void AddVertex(int x, int y);

void AddSector(int f_h, std::string f_tex, int c_h, std::string c_tex, int light, int special, int tag);
void AddSector(int f_h, const std::string &f_tex, int c_h, const std::string &c_tex, int light, int special, int tag);

void AddSidedef(int sector, std::string l_tex, std::string m_tex, std::string u_tex, int x_offset, int y_offset);
void AddSidedef(int sector, const std::string &l_tex, const std::string &m_tex, const std::string &u_tex, int x_offset, int y_offset);

void AddLinedef(int vert1, int vert2, int side1, int side2, int type, int flags, int tag, const uint8_t *args);

Expand Down
Loading

0 comments on commit 206de27

Please sign in to comment.