diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..af13e3a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "cstdint": "cpp" + } +} \ No newline at end of file diff --git a/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp b/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp index 0338d48..f30431d 100644 --- a/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp +++ b/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp @@ -342,8 +342,9 @@ struct Rom{ BattleBackground&background; BackgroundGraphics&graphics; PaletteCycle cycle; + uint_fast16_t backgroundInd; BackgroundLayer(PixelGameEngine*pge,uint_fast16_t backgroundInd,std::vector&backgrounds,std::vector&palettes,std::vector&graphics,std::u8string_view data) - :pge(pge),spr(new Sprite(256,256)),distorter(*spr),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[background.graphicsInd]),cycle(background,palettes[background.paletteInd]){ uint_fast32_t effectVal{((background.GetAnimation()>>16)&0xFF)}; if(effectVal==0)effectVal=(((background.GetAnimation()>>24)&0xFF)); distorter.effect=std::make_unique(data,effectVal); @@ -354,7 +355,20 @@ struct Rom{ std::vectorbackgrounds; std::vectorpalettes; std::vectorgraphics; + + const BackgroundLayer*const GetLayer1(){return layer1.get();} + const BackgroundLayer*const GetLayer2(){return layer2.get();} + void SetLayer1(uint_fast16_t backgroundInd){ + backgroundInd=std::clamp(backgroundInd,0U,uint_fast16_t(backgrounds.size())); + layer1=std::make_unique(nullptr,backgroundInd,backgrounds,palettes,graphics,data); + } + void SetLayer2(uint_fast16_t backgroundInd){ + backgroundInd=std::clamp(backgroundInd,0U,uint_fast16_t(backgrounds.size())); + layer2=std::make_unique(nullptr,backgroundInd,backgrounds,palettes,graphics,data); + } +private: std::unique_ptrlayer1,layer2; +public: Rom(){ #pragma region Setup Reversed Bytes reversedBytes.resize(256); @@ -457,17 +471,28 @@ public: } } - void BackgroundLayerDisplayTest(){ + int yOffset{0}; + float accumulatedTime{}; + void runTick(){ + float alpha1{1.f},alpha2{1.f}; + if(rom.GetLayer1()->backgroundInd&&!rom.GetLayer2()->backgroundInd){ + alpha1=1.f; + alpha2=0.f; + } + if(!rom.GetLayer1()->backgroundInd&&rom.GetLayer2()->backgroundInd){ + alpha1=0.f; + alpha2=1.f; + } } - int yOffset{0}; - bool OnUserUpdate(float fElapsedTime) override { - //PaletteDisplayTest(); - //GraphicsDisplayTest(); - //BackgroundLayerDisplayTest(); + accumulatedTime+=fElapsedTime; + while(accumulatedTime>=1/60.f){ + runTick(); + accumulatedTime-=1/60.f + } return true; } };