Skip to content

Commit

Permalink
Make vapor ids mod private
Browse files Browse the repository at this point in the history
  • Loading branch information
Yankes authored and SupSuper committed May 15, 2021
1 parent 268a8ff commit 765d67d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
64 changes: 52 additions & 12 deletions src/Mod/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ const std::string ModNameMaster = "master";
/// Predefined name for current mod that is loading rulesets.
const std::string ModNameCurrent = "current";

/// Reduction of size allocated for transparcey LUTs.
const size_t ModTransparceySizeReduction = 100;

void Mod::resetGlobalStatics()
{
DOOR_OPEN = 3;
Expand Down Expand Up @@ -673,8 +676,9 @@ int Mod::getModOffset() const
* @param node Node with data
* @param shared Max offset limit that is shared for every mod
* @param multiplier Value used by `projectile` surface set to convert projectile offset to index offset in surface.
* @param sizeScale Value used by transparency colors, reduce total number of avaialbe space for offset.
*/
void Mod::loadOffsetNode(const std::string &parent, int& offset, const YAML::Node &node, int shared, const std::string &set, size_t multiplier) const
void Mod::loadOffsetNode(const std::string &parent, int& offset, const YAML::Node &node, int shared, const std::string &set, size_t multiplier, size_t sizeScale) const
{
assert(_modCurrent);
const ModData* curr = _modCurrent;
Expand Down Expand Up @@ -734,14 +738,14 @@ void Mod::loadOffsetNode(const std::string &parent, int& offset, const YAML::Nod
{
int f = offset;
f *= multiplier;
if ((size_t)f > curr->size)
if ((size_t)f > curr->size / sizeScale)
{
std::ostringstream err;
err << "Error for '" << parent << "': offset '" << offset << "' exceeds mod size limit " << (curr->size / multiplier) << " in set '" << set << "'";
err << "Error for '" << parent << "': offset '" << offset << "' exceeds mod size limit " << (curr->size / multiplier / sizeScale) << " in set '" << set << "'";
throw Exception(err.str());
}
if (f >= shared)
f += curr->offset;
f += curr->offset / sizeScale;
offset = f;
}
}
Expand Down Expand Up @@ -779,6 +783,20 @@ void Mod::loadSoundOffset(const std::string &parent, int& sound, const YAML::Nod
}
}

/**
* Gets the mod offset array for a certain transparency index.
* @param parent Name of parent node, used for better error message.
* @param index Member to load new transparency index.
* @param node Node with data.
*/
void Mod::loadTransparencyOffset(const std::string &parent, int& index, const YAML::Node &node) const
{
if (node)
{
loadOffsetNode(parent, index, node, 0, "TransparencyLUTs", 1, ModTransparceySizeReduction);
}
}

/**
* Gets the mod offset array for a certain sound.
* @param parent Name of parent node, used for better error message
Expand Down Expand Up @@ -1029,16 +1047,38 @@ void Mod::loadResourceConfigFile(const std::string &filename)
rule->load(*i);
}
}
for (YAML::const_iterator i = doc["transparencyLUTs"].begin(); i != doc["transparencyLUTs"].end(); ++i)

if (const YAML::Node& luts = doc["transparencyLUTs"])
{
for (YAML::const_iterator j = (*i)["colors"].begin(); j != (*i)["colors"].end(); ++j)
const size_t start = _modCurrent->offset / ModTransparceySizeReduction;
const size_t limit = _modCurrent->size / ModTransparceySizeReduction;
size_t curr = 0;

_transparencies.resize(start + limit);
for (YAML::const_iterator i = luts.begin(); i != luts.end(); ++i)
{
SDL_Color color;
color.r = (*j)[0].as<int>(0);
color.g = (*j)[1].as<int>(0);
color.b = (*j)[2].as<int>(0);
color.unused = (*j)[3].as<int>(2);;
_transparencies.push_back(color);
const YAML::Node& c = (*i)["colors"];
if (c.IsSequence())
{
for (YAML::const_iterator j = c.begin(); j != c.end(); ++j)
{
if (curr == limit)
{
throw Exception("transparencyLUTs mod limit reach");
}
SDL_Color color;
color.r = (*j)[0].as<int>(0);
color.g = (*j)[1].as<int>(0);
color.b = (*j)[2].as<int>(0);
color.unused = (*j)[3].as<int>(2);
// technically its breaking change as it always overwritte from offset `start + 0` but no two mods could work correctly before this change.
_transparencies[start + curr++] = color;
}
}
else
{
throw Exception("unknown transparencyLUTs node type");
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,15 @@ class Mod
/// Gets the mod offset.
int getModOffset() const;
/// Get offset and index for sound set or sprite set.
void loadOffsetNode(const std::string &parent, int& offset, const YAML::Node &node, int shared, const std::string &set, size_t multiplier) const;
void loadOffsetNode(const std::string &parent, int& offset, const YAML::Node &node, int shared, const std::string &set, size_t multiplier, size_t sizeScale = 1) const;
/// Gets the mod offset for a certain sprite.
void loadSpriteOffset(const std::string &parent, int& sprite, const YAML::Node &node, const std::string &set, size_t multiplier = 1) const;
/// Gets the mod offset for a certain sound.
void loadSoundOffset(const std::string &parent, int& sound, const YAML::Node &node, const std::string &set) const;
/// Gets the mod offset array for a certain sound.
void loadSoundOffset(const std::string &parent, std::vector<int>& sounds, const YAML::Node &node, const std::string &set) const;
/// Gets the mod offset array for a certain transparency index.
void loadTransparencyOffset(const std::string &parent, int& index, const YAML::Node &node) const;
/// Gets the mod offset for a generic value.
int getOffset(int id, int max) const;

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/RuleItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void RuleItem::load(const YAML::Node &node, Mod *mod, int listOrder)
_underwaterOnly = node["underwaterOnly"].as<bool>(_underwaterOnly);
_landOnly = node["landOnly"].as<bool>(_landOnly);
_specialType = node["specialType"].as<int>(_specialType);
_vaporColor = node["vaporColor"].as<int>(_vaporColor);
mod->loadTransparencyOffset(_type, _vaporColor, node["vaporColor"]);
_vaporDensity = node["vaporDensity"].as<int>(_vaporDensity);
_vaporProbability = node["vaporProbability"].as<int>(_vaporProbability);
if (!_listOrder)
Expand Down

0 comments on commit 765d67d

Please sign in to comment.