Skip to content

Commit

Permalink
Merge pull request #483 from wheybags/graphics_refactor_2
Browse files Browse the repository at this point in the history
Trim atlas sprites
  • Loading branch information
wheybags authored Mar 27, 2020
2 parents fa6f5d1 + f3bb1ed commit 30de41b
Show file tree
Hide file tree
Showing 50 changed files with 798 additions and 738 deletions.
4 changes: 2 additions & 2 deletions apps/celview/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int main(int argc, char** argv)
{
selectedImage = argv[1];
frame = 0;
nextImage = std::unique_ptr<NuklearMisc::GuiSprite>(guiHandler.getSprite(new Render::SpriteGroup(selectedImage)));
nextImage = std::unique_ptr<NuklearMisc::GuiSprite>(guiHandler.getSprite(new Render::SpriteGroup(selectedImage, false)));
}
}
}
Expand All @@ -183,7 +183,7 @@ int main(int argc, char** argv)
{
selectedImage = celFiles[i];
frame = 0;
nextImage = std::unique_ptr<NuklearMisc::GuiSprite>(guiHandler.getSprite(new Render::SpriteGroup(selectedImage)));
nextImage = std::unique_ptr<NuklearMisc::GuiSprite>(guiHandler.getSprite(new Render::SpriteGroup(selectedImage, false)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/fontgenerator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main(int argc, char** argv)
{
for (int32_t y = 0; y < frame.height(); y++)
{
if (frame.get(x, y).visible)
if (frame.get(x, y).a)
if (x > maximumVisibleX)
maximumVisibleX = x;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/freeablo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ add_library(freeablo_lib # split into a library so I can link to it from tests
fasavegame/gameloader.cpp
)

target_link_libraries(freeablo_lib PUBLIC NuklearMisc Render Audio Serial Input Random enet cxxopts fmt::fmt)
target_link_libraries(freeablo_lib PUBLIC NuklearMisc Render Audio Serial Input Random Image enet cxxopts fmt::fmt)
target_include_directories(freeablo_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(freeablo main.cpp)
Expand Down
6 changes: 3 additions & 3 deletions apps/freeablo/fagui/characterdialoguepopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace FAGui
{
auto renderer = FARender::Renderer::get();

auto boxTex = renderer->loadImage(this->mWide ? "data/textbox.cel" : "data/textbox2.cel");
auto boxTex = renderer->loadImage(this->mWide ? "data/textbox.cel" : "data/textbox2.cel", false);
int32_t screenW, screenH;
renderer->getWindowDimensions(screenW, screenH);

Expand Down Expand Up @@ -59,7 +59,7 @@ namespace FAGui

// TODO: the "cursor" of the scrollbar is still the default nuklear look, which should change

auto sliderImg = renderer->loadImage("data/textslid.cel");
auto sliderImg = renderer->loadImage("data/textslid.cel", false);

// TODO: this image should repeat, not stretch
ctx->style.scrollv.normal = nk_style_item_image(sliderImg->getNkImage(scrollbarBackgroundIndex));
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace FAGui

void CharacterDialoguePopup::drawBackgroundCheckerboard(FARender::Renderer* renderer, struct nk_context* ctx, struct nk_rect dialogRectangle)
{
auto blackTex = renderer->loadImage(Misc::getResourcesPath().str() + "/black.png");
auto blackTex = renderer->loadImage(Misc::getResourcesPath().str() + "/black.png", false);
auto cbRect = nk_rect(dialogRectangle.x + 3, dialogRectangle.y + 3, dialogRectangle.w - 6, dialogRectangle.h - 6);

ScopedApplyEffect effect(ctx, EffectType::checkerboarded);
Expand Down
22 changes: 11 additions & 11 deletions apps/freeablo/fagui/guimanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace FAGui
auto renderer = FARender::Renderer::get();
mSmallPentagram.reset(new FARender::AnimationPlayer());
mSmallPentagram->playAnimation(
renderer->loadImage("data/pentspn2.cel"), FAWorld::World::getTicksInPeriod("0.06"), FARender::AnimationPlayer::AnimationType::Looped);
renderer->loadImage("data/pentspn2.cel", false), FAWorld::World::getTicksInPeriod("0.06"), FARender::AnimationPlayer::AnimationType::Looped);

startingScreen();
}
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace FAGui
if (!shown)
return;
auto renderer = FARender::Renderer::get();
auto invTex = renderer->loadImage(bgImgPath(panelType));
auto invTex = renderer->loadImage(bgImgPath(panelType), false);
int32_t screenW, screenH;
renderer->getWindowDimensions(screenW, screenH);
struct nk_rect dims = nk_rect(
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace FAGui

auto frame = item.getGraphicValue();
auto imgPath = "data/inv/objcurs.cel";
auto sprite = renderer->loadImage(imgPath);
auto sprite = renderer->loadImage(imgPath, false);
auto img = sprite->getNkImage(frame);
auto w = sprite->getWidth(frame);
auto h = sprite->getHeight(frame);
Expand Down Expand Up @@ -332,7 +332,7 @@ namespace FAGui
int32_t screenW, screenH;
auto renderer = FARender::Renderer::get();
renderer->getWindowDimensions(screenW, screenH);
auto img = renderer->loadImage("ctrlpan/golddrop.cel");
auto img = renderer->loadImage("ctrlpan/golddrop.cel", false);
double leftTopX = 31.0, leftTopY = 42.0;
nk_layout_space_push(ctx, nk_rect(leftTopX, leftTopY, img->getWidth(), img->getHeight()));
nk_image(ctx, img->getNkImage());
Expand Down Expand Up @@ -430,8 +430,8 @@ namespace FAGui
nk_layout_space_begin(ctx, NK_STATIC, 0, INT_MAX);

FARender::Renderer* renderer = FARender::Renderer::get();
FARender::FASpriteGroup* selectedTabButtons = renderer->loadImage("data/spellbkb.cel");
FARender::FASpriteGroup* icons = renderer->loadImage("data/spelli2.cel");
FARender::FASpriteGroup* selectedTabButtons = renderer->loadImage("data/spellbkb.cel", false);
FARender::FASpriteGroup* icons = renderer->loadImage("data/spelli2.cel", false);

int32_t buttonWidth = selectedTabButtons->getWidth();
int32_t buttonHeight = selectedTabButtons->getHeight();
Expand Down Expand Up @@ -534,10 +534,10 @@ namespace FAGui
// The bottom menu is made of two sprites: panel8.cel, which is the background,
// and panel8bu.cel, which contains overlays for each button. It's pretty primitive,
// the buttons are baked into the background image.
FARender::FASpriteGroup* bottomMenuTex = renderer->loadImage("ctrlpan/panel8.cel");
FARender::FASpriteGroup* bottomMenuButtonsTex = renderer->loadImage("ctrlpan/panel8bu.cel");
FARender::FASpriteGroup* healthAndManaEmptyBulbs = renderer->loadImage("ctrlpan/p8bulbs.cel");
FARender::FASpriteGroup* spellIcons = renderer->loadImage("ctrlpan/spelicon.cel");
FARender::FASpriteGroup* bottomMenuTex = renderer->loadImage("ctrlpan/panel8.cel", false);
FARender::FASpriteGroup* bottomMenuButtonsTex = renderer->loadImage("ctrlpan/panel8bu.cel", false);
FARender::FASpriteGroup* healthAndManaEmptyBulbs = renderer->loadImage("ctrlpan/p8bulbs.cel", false);
FARender::FASpriteGroup* spellIcons = renderer->loadImage("ctrlpan/spelicon.cel", false);

int32_t bulbWidth = healthAndManaEmptyBulbs->getWidth();
int32_t bulbHeight = healthAndManaEmptyBulbs->getHeight();
Expand Down Expand Up @@ -715,7 +715,7 @@ namespace FAGui
return;

FARender::Renderer* renderer = FARender::Renderer::get();
FARender::FASpriteGroup* spellIcons = renderer->loadImage("ctrlpan/spelicon.cel");
FARender::FASpriteGroup* spellIcons = renderer->loadImage("ctrlpan/spelicon.cel", false);
int32_t iconWidth = spellIcons->getWidth();
int32_t iconHeight = spellIcons->getHeight();

Expand Down
4 changes: 2 additions & 2 deletions apps/freeablo/fagui/menu/pausemenuscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace FAGui
{
auto renderer = FARender::Renderer::get();
mBigPentagram.reset(new FARender::AnimationPlayer());
auto pentImg = renderer->loadImage("data/pentspin.cel");
auto pentImg = renderer->loadImage("data/pentspin.cel", false);
mBigPentagram->playAnimation(pentImg, FAWorld::World::getTicksInPeriod("0.06"), FARender::AnimationPlayer::AnimationType::Looped);
auto pentRect = nk_rect(0, 0, pentImg->getWidth(), pentImg->getHeight());

Expand Down Expand Up @@ -99,7 +99,7 @@ namespace FAGui

nk_layout_space_begin(ctx, NK_STATIC, 0.0f, INT_MAX);
{
auto img = renderer->loadImage("data/diabsmal.cel");
auto img = renderer->loadImage("data/diabsmal.cel", false);
int32_t screenW, screenH;
renderer->getWindowDimensions(screenW, screenH);
constexpr int itemHeight = 45;
Expand Down
10 changes: 5 additions & 5 deletions apps/freeablo/fagui/menu/selectheromenuscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace FAGui
auto renderer = FARender::Renderer::get();
mSmLogo = menu.createSmLogo();
mFocus.reset(new FARender::AnimationPlayer());
mFocus->playAnimation(renderer->loadImage("ui_art/focus.pcx&trans=0,255,0&vanim=30"),
mFocus->playAnimation(renderer->loadImage("ui_art/focus.pcx&trans=0,255,0&vanim=30", false),
FAWorld::World::getTicksInPeriod("0.06"),
FARender::AnimationPlayer::AnimationType::Looped);
mFocus16.reset(new FARender::AnimationPlayer());
mFocus16->playAnimation(renderer->loadImage("ui_art/focus16.pcx&trans=0,255,0&vanim=20"),
mFocus16->playAnimation(renderer->loadImage("ui_art/focus16.pcx&trans=0,255,0&vanim=20", false),
FAWorld::World::getTicksInPeriod("0.06"),
FARender::AnimationPlayer::AnimationType::Looped);
setType(ContentType::chooseClass);
Expand Down Expand Up @@ -199,8 +199,8 @@ namespace FAGui
nk_layout_space_push(ctx, {26, 207, 180, 76});
{
auto renderer = FARender::Renderer::get();
auto heros_img =
renderer->loadImage("ui_art/heros.pcx&vanim=76")->getNkImage(mSelectedCharacterInfo ? static_cast<int>(mSelectedCharacterInfo->charClass) : 3);
auto heros_img = renderer->loadImage("ui_art/heros.pcx&vanim=76", false)
->getNkImage(mSelectedCharacterInfo ? static_cast<int>(mSelectedCharacterInfo->charClass) : 3);
nk_image(ctx, heros_img);
}
nk_layout_space_end(ctx);
Expand All @@ -214,7 +214,7 @@ namespace FAGui
auto renderer = FARender::Renderer::get();
int32_t screenW, screenH;
renderer->getWindowDimensions(screenW, screenH);
auto bg = renderer->loadImage("ui_art/selhero.pcx")->getNkImage();
auto bg = renderer->loadImage("ui_art/selhero.pcx", false)->getNkImage();
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background, nk_style_item_image(bg));
if (nk_begin(
ctx,
Expand Down
4 changes: 2 additions & 2 deletions apps/freeablo/fagui/menu/startingmenuscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FAGui
{
auto renderer = FARender::Renderer::get();
mFocus42.reset(new FARender::AnimationPlayer());
mFocus42->playAnimation(renderer->loadImage("ui_art/focus42.pcx&trans=0,255,0&vanim=42"),
mFocus42->playAnimation(renderer->loadImage("ui_art/focus42.pcx&trans=0,255,0&vanim=42", false),
FAWorld::World::getTicksInPeriod("0.06"),
FARender::AnimationPlayer::AnimationType::Looped);
mSmLogo = menu.createSmLogo();
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace FAGui
int32_t screenW, screenH;
renderer->getWindowDimensions(screenW, screenH);
Misc::ScopedSetter<float> setter(ctx->style.window.border, 0);
auto bg = renderer->loadImage("ui_art/mainmenu.pcx")->getNkImage();
auto bg = renderer->loadImage("ui_art/mainmenu.pcx", false)->getNkImage();
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background, nk_style_item_image(bg));
if (nk_begin(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion apps/freeablo/fagui/menuhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace FAGui
{
auto ret = std::make_unique<FARender::AnimationPlayer>();
auto renderer = FARender::Renderer::get();
ret->playAnimation(renderer->loadImage("ui_art/smlogo.pcx&trans=0,255,0&vanim=154"),
ret->playAnimation(renderer->loadImage("ui_art/smlogo.pcx&trans=0,255,0&vanim=154", false),
FAWorld::World::getTicksInPeriod("0.06"),
FARender::AnimationPlayer::AnimationType::Looped);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions apps/freeablo/fagui/mouseandclickmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace FAGui
{
MouseAndClickMenu::MouseAndClickMenu()
{
mPentagramAnimation.playAnimation(FARender::Renderer::get()->loadImage("data/pentspn2.cel"),
mPentagramAnimation.playAnimation(FARender::Renderer::get()->loadImage("data/pentspn2.cel", false),
FAWorld::World::getTicksInPeriod(FixedPoint("0.1")),
FARender::AnimationPlayer::AnimationType::Looped);
}
Expand All @@ -22,7 +22,7 @@ namespace FAGui
ctx->style.button.active = ctx->style.button.normal;

auto renderer = FARender::Renderer::get();
auto pentagram = renderer->loadImage("data/pentspn2.cel");
auto pentagram = renderer->loadImage("data/pentspn2.cel", false);
nk_layout_row_template_begin(ctx, lineHeight);
{
nk_layout_row_template_push_static(ctx, pentagram->getWidth());
Expand Down
2 changes: 1 addition & 1 deletion apps/freeablo/fagui/talkdialoguepopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace FAGui
{
auto renderer = FARender::Renderer::get();

auto boxTex = renderer->loadImage("data/textbox.cel");
auto boxTex = renderer->loadImage("data/textbox.cel", false);
int32_t screenW, screenH;
renderer->getWindowDimensions(screenW, screenH);

Expand Down
2 changes: 1 addition & 1 deletion apps/freeablo/farender/animationplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FARender
bool hasCurrentAnim = loader.load<bool>();

if (hasCurrentAnim)
mCurrentAnim = Renderer::get()->loadImage(loader.load<std::string>());
mCurrentAnim = Renderer::get()->loadImage(loader.load<std::string>(), true);

mPlayingAnimDuration = loader.load<FAWorld::Tick>();
mPlayingAnimType = AnimationType(loader.load<uint8_t>());
Expand Down
21 changes: 9 additions & 12 deletions apps/freeablo/farender/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cel/celdecoder.h"
#include "cel/celfile.h"
#include "fontinfo.h"
#include <Image/image.h>
#include <audio/fa_audio.h>
#include <functional>
#include <input/inputmanager.h>
Expand All @@ -28,12 +29,12 @@ namespace FARender
std::unique_ptr<CelFontInfo> Renderer::generateCelFont(const std::string& texturePath, const DiabloExe::FontData& fontData, int spacing)
{
std::unique_ptr<CelFontInfo> ret(new CelFontInfo());
auto mergedTex = mSpriteManager.get(texturePath + "&convertToSingleTexture");
auto mergedTex = mSpriteManager.get(texturePath + "&convertToSingleTexture", false);
ret->initByFontData(fontData, mergedTex->getWidth(), spacing);
ret->nkFont.userdata.ptr = ret.get();
ret->nkFont.height = mergedTex->getHeight();
ret->nkFont.width = &CelFontInfo::getWidth;
mSpriteManager.get(texturePath);
// mSpriteManager.get(texturePath);
ret->nkFont.query = &CelFontInfo::queryGlyph;
ret->nkFont.texture = mergedTex->getNkImage().handle;
return ret;
Expand All @@ -42,7 +43,7 @@ namespace FARender
std::unique_ptr<PcxFontInfo> Renderer::generateFont(const std::string& pcxPath, const std::string& binPath, const PcxFontInitData& fontInitData)
{
std::unique_ptr<PcxFontInfo> ret(new PcxFontInfo());
auto tex = mSpriteManager.get(pcxPath);
auto tex = mSpriteManager.get(pcxPath, false);
ret->init(binPath, fontInitData);
ret->nkFont.userdata.ptr = ret.get();
ret->nkFont.height = fontInitData.spacingY;
Expand All @@ -66,7 +67,7 @@ namespace FARender
int w, h;
image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32);

FASpriteGroup* sprite = spriteManager.getFromRaw((uint8_t*)image, w, h);
FASpriteGroup* sprite = spriteManager.getFromRaw(Image(w, h, reinterpret_cast<ByteColour*>(const_cast<void*>(image)), PointerDataType::Copy));
spriteManager.setImmortal(sprite->getCacheIndex(), true);

nk_handle handle = sprite->getNkImage().handle;
Expand Down Expand Up @@ -142,12 +143,12 @@ namespace FARender
const Level::Level& level = gameLevel.mLevel;

Tileset tileset;
tileset.minTops = mSpriteManager.getTileset(level.getTileSetPath(), level.getMinPath(), true);
tileset.minBottoms = mSpriteManager.getTileset(level.getTileSetPath(), level.getMinPath(), false);
tileset.minTops = mSpriteManager.getTileset(level.getTileSetPath(), level.getMinPath(), true, true);
tileset.minBottoms = mSpriteManager.getTileset(level.getTileSetPath(), level.getMinPath(), false, true);
// Special Cels may not exist for certain levels.
tileset.mSpecialSprites = NULL;
if (!level.getSpecialCelPath().empty())
tileset.mSpecialSprites = mSpriteManager.get(level.getSpecialCelPath());
tileset.mSpecialSprites = mSpriteManager.get(level.getSpecialCelPath(), true);
tileset.mSpecialSpriteMap = level.getSpecialCelMap();
return tileset;
}
Expand All @@ -168,11 +169,7 @@ namespace FARender

void Renderer::setCurrentState(RenderState* current) { Engine::ThreadManager::get()->sendRenderState(current); }

FASpriteGroup* Renderer::loadImage(const std::string& path) { return mSpriteManager.get(path); }

FASpriteGroup* Renderer::loadServerImage(uint32_t index) { return mSpriteManager.getByServerSpriteIndex(index); }

void Renderer::fillServerSprite(uint32_t index, const std::string& path) { mSpriteManager.fillServerSprite(index, path); }
FASpriteGroup* Renderer::loadImage(const std::string& path, bool trim) { return mSpriteManager.get(path, trim); }

std::string Renderer::getPathForIndex(uint32_t index) { return mSpriteManager.getPathForIndex(index); }

Expand Down
4 changes: 1 addition & 3 deletions apps/freeablo/farender/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ namespace FARender
RenderState* getFreeState(); // ooh ah up de ra
void setCurrentState(RenderState* current);

FASpriteGroup* loadImage(const std::string& path);
FASpriteGroup* loadServerImage(uint32_t index);
void fillServerSprite(uint32_t index, const std::string& path);
FASpriteGroup* loadImage(const std::string& path, bool trim);
std::string getPathForIndex(uint32_t index);

Render::Tile getTileByScreenPos(size_t x, size_t y, const FAWorld::Position& screenPos);
Expand Down
Loading

0 comments on commit 30de41b

Please sign in to comment.