Skip to content

Commit

Permalink
Merge branch 'Rubberduckycooly:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
LittlePlanetCD authored Jul 27, 2023
2 parents b8eff91 + 2894eb7 commit 596ba09
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Even if your platform isn't supported by the official releases, you **must** buy

## Mac
* Clone the repo, follow the instructions in the [dependencies readme for Mac](./dependencies/mac/dependencies.txt) to setup dependencies, then build via the Xcode project.
* A Mac build of v1.3.0 by [Sappharad](https://github.com/Sappharad) can be found [here](https://github.com/Sappharad/Sonic-CD-11-Decompilation/releases/tag/1.3.0_mac).
* A Mac build by [Sappharad](https://github.com/Sappharad) can be found [here](https://github.com/Sappharad/Sonic-CD-11-Decompilation/releases/latest).

## Linux
* To setup your build enviroment and library dependecies, run the following commands:
Expand Down
101 changes: 69 additions & 32 deletions RSDKv3/RetroEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,39 +582,76 @@ void RetroEngine::LoadXMLPalettes()

if (success) {
const tinyxml2::XMLElement *gameElement = FirstXMLChildElement(doc, nullptr, "game");
const tinyxml2::XMLElement *paletteElement = FirstXMLChildElement(doc, gameElement, "palette");
const tinyxml2::XMLElement *paletteElement = gameElement->FirstChildElement("palette");
if (paletteElement) {
const tinyxml2::XMLElement *clrElement = FirstXMLChildElement(doc, paletteElement, "color");
if (clrElement) {
do {
const tinyxml2::XMLAttribute *bankAttr = FindXMLAttribute(clrElement, "bank");
int clrBank = 0;
if (bankAttr)
clrBank = GetXMLAttributeValueInt(bankAttr);

const tinyxml2::XMLAttribute *indAttr = FindXMLAttribute(clrElement, "index");
int clrInd = 0;
if (indAttr)
clrInd = GetXMLAttributeValueInt(indAttr);

const tinyxml2::XMLAttribute *rAttr = FindXMLAttribute(clrElement, "r");
int clrR = 0;
if (rAttr)
clrR = GetXMLAttributeValueInt(rAttr);

const tinyxml2::XMLAttribute *gAttr = FindXMLAttribute(clrElement, "g");
int clrG = 0;
if (gAttr)
clrG = GetXMLAttributeValueInt(gAttr);

const tinyxml2::XMLAttribute *bAttr = FindXMLAttribute(clrElement, "b");
int clrB = 0;
if (bAttr)
clrB = GetXMLAttributeValueInt(bAttr);

SetPaletteEntry(clrBank, clrInd, clrR, clrG, clrB);

} while ((clrElement = NextXMLSiblingElement(doc, clrElement, "color")));
for (const tinyxml2::XMLElement *clrElement = paletteElement->FirstChildElement("color"); clrElement;
clrElement = clrElement->NextSiblingElement("color")) {
const tinyxml2::XMLAttribute *bankAttr = clrElement->FindAttribute("bank");
int clrBank = 0;
if (bankAttr)
clrBank = bankAttr->IntValue();

const tinyxml2::XMLAttribute *indAttr = clrElement->FindAttribute("index");
int clrInd = 0;
if (indAttr)
clrInd = indAttr->IntValue();

const tinyxml2::XMLAttribute *rAttr = clrElement->FindAttribute("r");
int clrR = 0;
if (rAttr)
clrR = rAttr->IntValue();

const tinyxml2::XMLAttribute *gAttr = clrElement->FindAttribute("g");
int clrG = 0;
if (gAttr)
clrG = gAttr->IntValue();

const tinyxml2::XMLAttribute *bAttr = clrElement->FindAttribute("b");
int clrB = 0;
if (bAttr)
clrB = bAttr->IntValue();

SetPaletteEntry(clrBank, clrInd, clrR, clrG, clrB);
}

for (const tinyxml2::XMLElement *clrsElement = paletteElement->FirstChildElement("colors"); clrsElement;
clrsElement = clrsElement->NextSiblingElement("colors")) {
const tinyxml2::XMLAttribute *bankAttr = clrsElement->FindAttribute("bank");
int bank = 0;
if (bankAttr)
bank = bankAttr->IntValue();

const tinyxml2::XMLAttribute *indAttr = clrsElement->FindAttribute("start");
int index = 0;
if (indAttr)
index = indAttr->IntValue();

std::string text = clrsElement->GetText();
// working: AABBFF #FFaaFF (12, 32, 34) (145 53 234)
std::regex search(R"((?:#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2}))|(?:\((\d+),?\s*(\d+),?\s*(\d+)\)))",
std::regex_constants::icase | std::regex_constants::ECMAScript);
std::smatch match;
while (std::regex_search(text, match, search)) {
int r, g, b;
int base, start;
if (match[1].matched) {
// we have hex
base = 16;
start = 1;
}
else {
// triplet
base = 10;
start = 4;
}

r = std::stoi(match[start + 0].str(), nullptr, base);
g = std::stoi(match[start + 1].str(), nullptr, base);
b = std::stoi(match[start + 2].str(), nullptr, base);

SetPaletteEntry(bank, index++, r, g, b);
text = match.suffix();
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions RSDKv3/RetroEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <stdio.h>
#include <string.h>
#include <cmath>
#if RETRO_USE_MOD_LOADER
#include <regex>
#endif

// ================
// STANDARD TYPES
Expand Down

0 comments on commit 596ba09

Please sign in to comment.