Replace byte with std::byte.
Some checks failed
Emscripten Build / Build_and_Deploy_Web_Build (push) Failing after 14s

This commit is contained in:
sigonasr2 2025-05-05 16:25:06 -04:00
parent 81a7c31dd7
commit e7fc60b923
2 changed files with 56 additions and 56 deletions

View File

@ -187,44 +187,44 @@ struct Rom{
BattleBackground(std::u8string_view data,uint_fast32_t index){
DataBlock readData{data,0xDCA1+index*uint_fast32_t(this->data.size())};
for(int i=0;i<this->data.size();i++){
this->data[i]=readData.readInt8();
this->data[i]=std::byte(readData.readInt8());
}
};
union{
std::array<byte,17>data;
std::array<std::byte,17>data;
struct{
byte graphicsInd;
byte paletteInd;
byte bbp;
byte paletteCycleType;
byte paletteCycle1StartInd;
byte paletteCycle1EndInd;
byte paletteCycle2StartInd;
byte paletteCycle2EndInd;
byte paletteCycleSpeed;
byte horizontalMovement;
byte verticalMovement;
byte horizontalAcceleration;
byte verticalAcceleration;
std::byte graphicsInd;
std::byte paletteInd;
std::byte bbp;
std::byte paletteCycleType;
std::byte paletteCycle1StartInd;
std::byte paletteCycle1EndInd;
std::byte paletteCycle2StartInd;
std::byte paletteCycle2EndInd;
std::byte paletteCycleSpeed;
std::byte horizontalMovement;
std::byte verticalMovement;
std::byte horizontalAcceleration;
std::byte verticalAcceleration;
uint_fast32_t animationEffectsData;
};
};
uint_fast32_t GetAnimation(){
return (data[13]<<24)+(data[14]<<16)+(data[15]<<8)+data[16];
return (uint_fast32_t(data[13])<<24)+(uint_fast32_t(data[14])<<16)+(uint_fast32_t(data[15])<<8)+uint_fast32_t(data[16]);
};
};
struct BackgroundPalette{
std::vector<Pixel>colors;
byte bpp;
std::byte bpp;
uint_fast32_t addr;
BackgroundPalette(std::u8string_view data,uint_fast16_t index,byte bpp)
BackgroundPalette(std::u8string_view data,uint_fast16_t index,std::byte bpp)
:bpp(bpp){
DataBlock pointer{data,0xDAD9U+index*4U};
uint_fast32_t addr=snesToHex(pointer.readInt32());
DataBlock dataBlock{data,addr};
this->addr=addr;
if(bpp!=2&&bpp!=4)throw std::invalid_argument{std::format("Palette Error: Incorrect color depth specified. Must be 2 or 4, provided {}",bpp)};
for(uint_fast8_t i:std::views::iota(0,pow(2,bpp))){
if(uint_fast8_t(bpp)!=2&&uint_fast8_t(bpp)!=4)throw std::invalid_argument{std::format("Palette Error: Incorrect color depth specified. Must be 2 or 4, provided {}",uint_fast8_t(bpp))};
for(uint_fast8_t i:std::views::iota(0,pow(2,uint_fast8_t(bpp)))){
uint_fast16_t clr16{dataBlock.readShort()};
uint_fast8_t b{((clr16>>10)&31)*8U};
uint_fast8_t g{((clr16>>5)&31)*8U};
@ -238,17 +238,17 @@ struct Rom{
std::vector<uint_fast16_t>graphicsData;
std::vector<uint_fast16_t>arrayGraphicsData;
std::vector<Tile>tiles;
byte bpp;
std::byte bpp;
private:
void buildTiles(){
int n{int(graphicsData.size())/(8*bpp)};
int n{int(graphicsData.size())/(8*uint_fast8_t(bpp))};
for(int i{};i<n;i++){
tiles.emplace_back();
int o{i*8*bpp};
int o{i*8*uint_fast8_t(bpp)};
for(int x{};x<8;x++){
for(int y{};y<8;y++){
int c{};
for(int bp{};bp<bpp;bp++){
for(int bp{};bp<uint_fast8_t(bpp);bp++){
int halfBp{bp/2};
int gfx{int(graphicsData[o+y*2+(halfBp*16+(bp&1))])};
c+=((gfx&(1<<7-x))>>7-x)<<bp;
@ -259,7 +259,7 @@ struct Rom{
}
}
public:
BackgroundGraphics(std::u8string_view data,uint_fast16_t index,byte bpp)
BackgroundGraphics(std::u8string_view data,uint_fast16_t index,std::byte bpp)
:bpp(bpp){
DataBlock graphicsPtr{data,0xD7A1U+index*4U};
DataBlock loadGraphicsPtr{data,snesToHex(graphicsPtr.readInt32())};
@ -371,52 +371,52 @@ struct Rom{
struct PaletteCycle{
std::vector<Pixel>originalCols;
std::vector<Pixel>currentCols;
byte type,start1,end1,start2,end2,speed,cycleCountdown,cycleCount{};
std::byte type,start1,end1,start2,end2,speed,cycleCountdown,cycleCount{};
PaletteCycle(BattleBackground&background,BackgroundPalette&palette)
:type(background.paletteCycleType),start1(background.paletteCycle1StartInd),end1(background.paletteCycle1EndInd),start2(background.paletteCycle2StartInd),end2(background.paletteCycle2EndInd),speed(background.paletteCycleSpeed/2),cycleCountdown(speed),originalCols(palette.colors),currentCols(originalCols){
:type(background.paletteCycleType),start1(background.paletteCycle1StartInd),end1(background.paletteCycle1EndInd),start2(background.paletteCycle2StartInd),end2(background.paletteCycle2EndInd),speed(std::byte(uint_fast8_t(background.paletteCycleSpeed)/2) ),cycleCountdown(speed),originalCols(palette.colors),currentCols(originalCols){
for(int i:std::views::iota(0U,originalCols.size())){
originalCols.emplace_back(originalCols[i]);
}
}
void cycle(){
if(speed==0)return;
cycleCountdown=std::clamp(cycleCountdown-1,0,int(std::numeric_limits<byte>::max()));
if(cycleCountdown<=0){
if(uint_fast8_t(speed)==0)return;
cycleCountdown=std::byte(std::clamp(uint_fast8_t(cycleCountdown)-1,0,int(std::numeric_limits<std::byte>::max())));
if(uint_fast8_t(cycleCountdown)<=0){
cycleColors();
cycleCount++;
cycleCount=std::byte(uint_fast8_t(cycleCount)+1);
cycleCountdown=speed;
}
}
void cycleColors(){
if(type==1||type==2){
int cycleLength{end1-start1+1};
int cycle1Position{cycleCount%cycleLength};
for(int i:std::views::iota(int(start1),end1+1)){
if(uint_fast8_t(type)==1||uint_fast8_t(type)==2){
int cycleLength{uint_fast8_t(end1)-uint_fast8_t(start1)+1};
int cycle1Position{uint_fast8_t(cycleCount)%cycleLength};
for(int i:std::views::iota(int(start1),uint_fast8_t(end1)+1)){
int newColor=i-cycle1Position;
if(newColor<start1)newColor+=cycleLength;
if(newColor<uint_fast8_t(start1))newColor+=cycleLength;
currentCols[i]=originalCols[newColor];
}
}
if(type==2){
int cycleLength{end2-start2+1};
int cycle2Position{cycleCount%cycleLength};
for(int i:std::views::iota(int(start2),end2+1)){
if(uint_fast8_t(type)==2){
int cycleLength{uint_fast8_t(end2)-uint_fast8_t(start2)+1};
int cycle2Position{uint_fast8_t(cycleCount)%cycleLength};
for(int i:std::views::iota(int(start2),uint_fast8_t(end2)+1)){
int newColor=i-cycle2Position;
if(newColor<start2)newColor+=cycleLength;
if(newColor<uint_fast8_t(start2))newColor+=cycleLength;
currentCols[i]=originalCols[newColor];
}
}
if(type==3){
int cycleLength{end1-start1+1};
int cycle1Position{cycleCount%(cycleLength*2)};
for(int i:std::views::iota(int(start1),end1+1)){
if(uint_fast8_t(type)==3){
int cycleLength{uint_fast8_t(end1)-uint_fast8_t(start1)+1};
int cycle1Position{uint_fast8_t(cycleCount)%(cycleLength*2)};
for(int i:std::views::iota(int(start1),uint_fast8_t(end1)+1)){
int newColor=i+cycle1Position;
if(newColor>end1){
int difference{newColor-end1-1};
newColor=end1-difference;
if(newColor<start1){
difference=start1-newColor-1;
newColor=start1+difference;
if(newColor>uint_fast8_t(end1)){
int difference{newColor-uint_fast8_t(end1)-1};
newColor=uint_fast8_t(end1)-difference;
if(newColor<uint_fast8_t(start1)){
difference=uint_fast8_t(start1)-newColor-1;
newColor=uint_fast8_t(start1)+difference;
}
}
currentCols[i]=originalCols[newColor];
@ -470,7 +470,7 @@ struct Rom{
}
}
BackgroundLayer(PixelGameEngine*pge,uint_fast16_t backgroundInd,std::vector<BattleBackground>&backgrounds,std::vector<BackgroundPalette>&palettes,std::vector<BackgroundGraphics>&graphics,std::u8string_view data)
:pge(pge),spr(new Sprite(256,256)),distorter(*spr),backgroundInd(backgroundInd),background(backgrounds[backgroundInd]),graphics(graphics[background.graphicsInd]),cycle(background,palettes[background.paletteInd]){
:pge(pge),spr(new Sprite(256,256)),distorter(*spr),backgroundInd(backgroundInd),background(backgrounds[backgroundInd]),graphics(graphics[uint_fast8_t(background.graphicsInd)]),cycle(background,palettes[uint_fast8_t(background.paletteInd)]){
uint_fast32_t effectVal{((background.GetAnimation()>>16)&0xFF)};
if(effectVal==0)effectVal=(((background.GetAnimation()>>24)&0xFF));
distorter.effect=std::make_unique<DistortionEffect>(data,effectVal);
@ -524,14 +524,14 @@ public:
for(uint_fast16_t i:std::views::iota(0U,MAX_INDEX+1U)){
backgrounds.emplace_back(data,i);
paletteBits[backgrounds.back().paletteInd]=backgrounds.back().bbp;
graphicsBits[backgrounds.back().graphicsInd]=backgrounds.back().bbp;
paletteBits[uint_fast8_t(backgrounds.back().paletteInd)]=uint_fast8_t(backgrounds.back().bbp);
graphicsBits[uint_fast8_t(backgrounds.back().graphicsInd)]=uint_fast8_t(backgrounds.back().bbp);
}
for(uint_fast16_t i:std::views::iota(0U,paletteBits.size())){
palettes.emplace_back(data,i,paletteBits[i]);
palettes.emplace_back(data,i,std::byte(paletteBits[i]));
}
for(uint_fast16_t i:std::views::iota(0U,graphicsBits.size())){
graphics.emplace_back(data,i,graphicsBits[i]);
graphics.emplace_back(data,i,std::byte(graphicsBits[i]));
}
layer1=std::make_unique<BackgroundLayer>(pge,0U,backgrounds,palettes,graphics,data);