Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
etorth committed Apr 9, 2022
1 parent 9b70b72 commit f31b5f7
Show file tree
Hide file tree
Showing 22 changed files with 593 additions and 466 deletions.
24 changes: 12 additions & 12 deletions client/src/attachmagic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,48 @@ extern PNGTexOffDB *g_magicDB;

void AttachMagic::drawShift(int shiftX, int shiftY, uint32_t modColor) const
{
if(m_gfxEntry.gfxID == SYS_U32NIL){
if(m_gfxEntry->gfxID == SYS_U32NIL){
return;
}

const auto texID = [this]() -> uint32_t
{
switch(m_gfxEntry.gfxDirType){
case 1: return m_gfxEntry.gfxID + frame();
switch(m_gfxEntry->gfxDirType){
case 1: return m_gfxEntry->gfxID + frame();
case 4:
case 8:
case 16: return m_gfxEntry.gfxID + frame() + m_gfxDirIndex * m_gfxEntry.gfxIDCount;
default: throw fflerror("invalid gfxDirType: %d", m_gfxEntry.gfxDirType);
case 16: return m_gfxEntry->gfxID + frame() + m_gfxDirIndex * m_gfxEntry->gfxIDCount;
default: throw fflerror("invalid gfxDirType: %d", m_gfxEntry->gfxDirType);
}
}();

if(auto [texPtr, offX, offY] = g_magicDB->retrieve(texID); texPtr){
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(m_gfxEntryRef ? m_gfxEntryRef.modColor : m_gfxEntry.modColor, modColor));
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(m_gfxEntryRef ? m_gfxEntryRef->modColor : m_gfxEntry->modColor, modColor));
SDLDeviceHelper::EnableTextureBlendMode enableBlendMode(texPtr, SDL_BLENDMODE_BLEND);
g_sdlDevice->drawTexture(texPtr, shiftX + offX, shiftY + offY);
}
}

void Thunderbolt::drawShift(int shiftX, int shiftY, uint32_t modColor) const
{
if(m_gfxEntry.gfxID == SYS_U32NIL){
if(m_gfxEntry->gfxID == SYS_U32NIL){
return;
}

const auto texID = [this]() -> uint32_t
{
switch(m_gfxEntry.gfxDirType){
case 1: return m_gfxEntry.gfxID + frame();
switch(m_gfxEntry->gfxDirType){
case 1: return m_gfxEntry->gfxID + frame();
case 4:
case 8:
case 16: return m_gfxEntry.gfxID + frame() + m_gfxDirIndex * m_gfxEntry.gfxIDCount;
default: throw fflerror("invalid gfxDirType: %d", m_gfxEntry.gfxDirType);
case 16: return m_gfxEntry->gfxID + frame() + m_gfxDirIndex * m_gfxEntry->gfxIDCount;
default: throw fflerror("invalid gfxDirType: %d", m_gfxEntry->gfxDirType);
}
}();

if(auto [texPtr, offX, offY] = g_magicDB->retrieve(texID); texPtr){
const auto [texW, texH] = SDLDeviceHelper::getTextureSize(texPtr);
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(m_gfxEntryRef ? m_gfxEntryRef.modColor : m_gfxEntry.modColor, modColor));
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(m_gfxEntryRef ? m_gfxEntryRef->modColor : m_gfxEntry->modColor, modColor));
SDLDeviceHelper::EnableTextureBlendMode enableBlendMode(texPtr, SDL_BLENDMODE_BLEND);

// thunder bolt has 5 frames
Expand Down
2 changes: 1 addition & 1 deletion client/src/attachmagic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AttachMagic: public BaseMagic
AttachMagic(const char8_t *magicName, const char8_t *magicStage, int gfxDirIndex = 0)
: BaseMagic(magicName, magicStage, gfxDirIndex)
{
fflassert(m_gfxEntry.checkType(u8"附着"));
fflassert(m_gfxEntry->checkType(u8"附着"));
}

public:
Expand Down
61 changes: 60 additions & 1 deletion client/src/basemagic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,69 @@
#include "basemagic.hpp"
#include "magicrecord.hpp"

uint32_t magicGetSeffID(const std::u8string_view &name, const std::u8string_view &stage)
static std::optional<uint32_t> magicGetSeffIDHelper(const std::u8string_view &name, const std::u8string_view &stage)
{
fflassert(str_haschar(name));
fflassert(str_haschar(stage));
fflassert(magicStageID(stage.data()) >= MST_BEGIN);

const auto [gfxEntry, gfxEntryRef] = DBCOM_MAGICGFXENTRY(name, stage);
fflassert(gfxEntry, name, stage);

if(gfxEntry->seff.ref){
return magicGetSeffIDHelper(gfxEntry->seff.ref.name, gfxEntry->seff.ref.stage.empty() ? stage : gfxEntry->seff.ref.stage);
}

if(gfxEntry->seff.absSeffID.has_value()){
return gfxEntry->seff.absSeffID;
}

const auto &mr = DBCOM_MAGICRECORD(name);
fflassert(mr, name);

if(!mr.seffBase.has_value()){
return {};
}

return 0X04000000 + mr.seffBase.value() * 16 + (magicStageID(stage.data()) - MST_BEGIN);
}


BaseMagic::BaseMagic(const char8_t *magicName, const char8_t *magicStage, int dirIndex)
: m_magicID([magicName]() -> uint32_t
{
if(const auto magicID = DBCOM_MAGICID(magicName)){
return magicID;
}
throw fflerror("invalid magicName: %s", to_cstr(magicName));
}())
, m_magicRecord([this]() -> const auto &
{
if(const auto &mr = DBCOM_MAGICRECORD(magicID())){
return mr;
}
throw fflerror("invalid magicID: %d", magicID());
}())
, m_gfxEntryPair([magicName, magicStage]()
{
fflassert(str_haschar(magicName));
fflassert(str_haschar(magicStage));

const auto gfxPair = DBCOM_MAGICGFXENTRY(magicName, magicStage);
fflassert(gfxPair.first);
fflassert(gfxPair.first->checkType(magicStage));

fflassert(gfxPair.first->frameCount > 0);
fflassert(gfxPair.first->frameCount <= gfxPair.first->gfxIDCount);

fflassert(gfxPair.first->speed >= SYS_MINSPEED);
fflassert(gfxPair.first->speed <= SYS_MAXSPEED);
return gfxPair;
}())
, m_seffID(magicGetSeffIDHelper(to_u8sv(magicName), to_u8sv(magicStage)))
, m_gfxDirIndex(dirIndex)
{
// gfxDirIndex is the index of gfx set
// the gfx set can be for different direction or not
fflassert(gfxDirIndex() >= 0 && gfxDirIndex() < getGfxEntry()->gfxDirType);
}
63 changes: 21 additions & 42 deletions client/src/basemagic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class BaseMagic
const MagicRecord &m_magicRecord;

private:
const std::pair<const MagicGfxEntry &, const MagicGfxEntryRef &> m_gfxEntryPair;
const std::pair<const MagicGfxEntry *, const MagicGfxEntryRef *> m_gfxEntryPair;

protected:
const MagicGfxEntry &m_gfxEntry = m_gfxEntryPair.first;
const MagicGfxEntryRef &m_gfxEntryRef = m_gfxEntryPair.second;
const MagicGfxEntry * m_gfxEntry = m_gfxEntryPair.first;
const MagicGfxEntryRef * m_gfxEntryRef = m_gfxEntryPair.second;

protected:
const uint32_t m_seffID;
const std::optional<uint32_t> m_seffID;

protected:
const int m_gfxDirIndex;
Expand All @@ -35,35 +35,7 @@ class BaseMagic
std::list<std::function<bool(BaseMagic *)>> m_onUpdateCBList;

public:
BaseMagic(const char8_t *magicName, const char8_t *magicStage, int dirIndex)
: m_magicID([magicName]() -> uint32_t
{
if(const auto magicID = DBCOM_MAGICID(magicName)){
return magicID;
}
throw fflerror("invalid magicName: %s", to_cstr(magicName));
}())
, m_magicRecord([this]() -> const auto &
{
if(const auto &mr = DBCOM_MAGICRECORD(magicID())){
return mr;
}
throw fflerror("invalid magicID: %d", magicID());
}())
, m_gfxEntryPair([magicStage, this]()
{
if(const auto &p = m_magicRecord.getGfxEntry(magicStage); p.first){
return p;
}
throw fflerror("invalid magicStage: %s", to_cstr(magicStage));
}())
, m_seffID(???)
, m_gfxDirIndex(dirIndex)
{
// gfxDirIndex is the index of gfx set
// the gfx set can be for different direction or not
fflassert(gfxDirIndex() >= 0 && gfxDirIndex() < getGfxEntry().gfxDirType);
}
BaseMagic(const char8_t *, const char8_t *, int);

public:
virtual ~BaseMagic() = default;
Expand All @@ -79,7 +51,7 @@ class BaseMagic
return DBCOM_MAGICRECORD(magicID()).name;
}

const MagicGfxEntry &getGfxEntry() const
const MagicGfxEntry * getGfxEntry() const
{
return m_gfxEntry;
}
Expand All @@ -89,6 +61,11 @@ class BaseMagic
return m_gfxDirIndex;
}

std::optional<uint32_t> getSeffID() const
{
return m_seffID;
}

public:
bool checkMagic(const char8_t *name) const
{
Expand All @@ -97,7 +74,7 @@ class BaseMagic

bool checkMagic(const char8_t *name, const char8_t *stage) const
{
return magicID() == DBCOM_MAGICID(name) && getGfxEntry().checkStage(stage);
return magicID() == DBCOM_MAGICID(name) && getGfxEntry()->checkStage(stage);
}

public:
Expand Down Expand Up @@ -146,8 +123,8 @@ class BaseMagic
public:
int frame() const
{
if(m_gfxEntry.loop){
return absFrame() % m_gfxEntry.frameCount;
if(m_gfxEntry->loop){
return absFrame() % m_gfxEntry->frameCount;
}
else{
return absFrame();
Expand All @@ -156,27 +133,29 @@ class BaseMagic

virtual int absFrame() const
{
return std::lround((m_accuTime / 1000.0) * SYS_DEFFPS * (m_gfxEntry.speed / 100.0));
return std::lround((m_accuTime / 1000.0) * SYS_DEFFPS * (m_gfxEntry->speed / 100.0));
}

public:
void addOnDone(std::function<void(BaseMagic *)> onDone)
BaseMagic *addOnDone(std::function<void(BaseMagic *)> onDone)
{
m_onDoneCBList.push_back(std::move(onDone));
return this;
}

void addTrigger(std::function<bool(BaseMagic *)> onUpdate)
BaseMagic *addTrigger(std::function<bool(BaseMagic *)> onUpdate)
{
m_onUpdateCBList.push_back(std::move(onUpdate));
return this;
}

public:
virtual bool done() const
{
if(m_gfxEntry.loop){
if(m_gfxEntry->loop){
return false;
}
return absFrame() >= m_gfxEntry.frameCount;
return absFrame() >= m_gfxEntry->frameCount;
}

protected:
Expand Down
12 changes: 6 additions & 6 deletions client/src/fixedlocmagic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ void FixedLocMagic::drawViewOff(int viewX, int viewY, uint32_t modColor) const
return;
}

if(m_gfxEntry.gfxID == SYS_U32NIL){
if(m_gfxEntry->gfxID == SYS_U32NIL){
return;
}

const int gfxDirOff = ((m_gfxDirIndex >= 0) ? m_gfxDirIndex : 0) * m_gfxEntry.gfxIDCount;
if(auto [texPtr, offX, offY] = g_magicDB->retrieve(m_gfxEntry.gfxID + gfxDirOff + frame()); texPtr){
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef.modColor : m_gfxEntry.modColor;
const int gfxDirOff = ((m_gfxDirIndex >= 0) ? m_gfxDirIndex : 0) * m_gfxEntry->gfxIDCount;
if(auto [texPtr, offX, offY] = g_magicDB->retrieve(m_gfxEntry->gfxID + gfxDirOff + frame()); texPtr){
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef->modColor : m_gfxEntry->modColor;
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(gfxEntryModColor, modColor));
SDLDeviceHelper::EnableTextureBlendMode enableBlendMode(texPtr, SDL_BLENDMODE_BLEND);
g_sdlDevice->drawTexture(texPtr, m_x * SYS_MAPGRIDXP - viewX + offX, m_y * SYS_MAPGRIDYP - viewY + offY);
Expand All @@ -46,7 +46,7 @@ void FixedLocMagic::drawViewOff(int viewX, int viewY, uint32_t modColor) const
void FireAshEffect_RUN::drawGroundAsh(int viewX, int viewY, uint32_t modColor) const
{
if(auto [texPtr, offX, offY] = g_magicDB->retrieve(0X0F0000DC); texPtr){
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef.modColor : m_gfxEntry.modColor;
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef->modColor : m_gfxEntry->modColor;
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(colorf::modRGBA(gfxEntryModColor, getPlainModColor()), modColor));
SDLDeviceHelper::EnableTextureBlendMode enableBlendMode(texPtr, SDL_BLENDMODE_BLEND);

Expand Down Expand Up @@ -121,7 +121,7 @@ void IceThorn_RUN::drawGroundIce(int viewX, int viewY, uint32_t modColor) const
}();

if(texPtr){
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef.modColor : m_gfxEntry.modColor;
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef->modColor : m_gfxEntry->modColor;
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(colorf::modRGBA(gfxEntryModColor, getPlainModColor()), modColor));
SDLDeviceHelper::EnableTextureBlendMode enableBlendMode(texPtr, SDL_BLENDMODE_BLEND);
g_sdlDevice->drawTextureExt(texPtr,
Expand Down
8 changes: 4 additions & 4 deletions client/src/fixedlocmagic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FixedLocMagic: public BaseMagic
, m_x(x)
, m_y(y)
{
fflassert(m_gfxEntry.checkType(u8"固定"));
fflassert(m_gfxEntry->checkType(u8"固定"));
}

public:
Expand Down Expand Up @@ -259,7 +259,7 @@ class IceThorn_RUN: public FixedLocMagic
public:
bool done() const override
{
return absFrame() >= std::max<int>(m_gfxEntry.frameCount, m_iceSlagFrameCount[0] + m_iceSlagFrameCount[1] + m_iceSlagFrameCount[2]);
return absFrame() >= std::max<int>(m_gfxEntry->frameCount, m_iceSlagFrameCount[0] + m_iceSlagFrameCount[1] + m_iceSlagFrameCount[2]);
}

private:
Expand Down Expand Up @@ -288,7 +288,7 @@ class IceThorn_RUN: public FixedLocMagic
public:
void drawViewOff(int viewX, int viewY, uint32_t modColor) const override
{
if(absFrame() < m_gfxEntry.frameCount){
if(absFrame() < m_gfxEntry->frameCount){
FixedLocMagic::drawViewOff(viewX, viewY, modColor);
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ class SingleFrameEffect_RUN: public FixedLocMagic
{
fflassert(t1 >= 0);
fflassert(t2 > 0);
fflassert(m_gfxEntry.frameCount == 1);
fflassert(m_gfxEntry->frameCount == 1);
}

public:
Expand Down
10 changes: 5 additions & 5 deletions client/src/followuidmagic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ FollowUIDMagic::FollowUIDMagic(

uint32_t FollowUIDMagic::frameTexID() const
{
if(m_gfxEntry.gfxID == SYS_U32NIL){
if(m_gfxEntry->gfxID == SYS_U32NIL){
return SYS_U32NIL;
}

switch(m_gfxEntry.gfxDirType){
case 1: return m_gfxEntry.gfxID + frame();
switch(m_gfxEntry->gfxDirType){
case 1: return m_gfxEntry->gfxID + frame();
case 4:
case 8:
case 16:
default: return m_gfxEntry.gfxID + frame() + m_gfxDirIndex * m_gfxEntry.gfxIDCount;
default: return m_gfxEntry->gfxID + frame() + m_gfxDirIndex * m_gfxEntry->gfxIDCount;
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ void FollowUIDMagic::drawViewOff(int viewX, int viewY, uint32_t modColor) const
{
if(const auto texID = frameTexID(); texID != SYS_U32NIL){
if(auto [texPtr, offX, offY] = g_magicDB->retrieve(texID); texPtr){
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef.modColor : m_gfxEntry.modColor;
const auto gfxEntryModColor = m_gfxEntryRef ? m_gfxEntryRef->modColor : m_gfxEntry->modColor;
SDLDeviceHelper::EnableTextureModColor enableModColor(texPtr, colorf::modRGBA(gfxEntryModColor, modColor));
SDLDeviceHelper::EnableTextureBlendMode enableBlendMode(texPtr, SDL_BLENDMODE_BLEND);

Expand Down
6 changes: 3 additions & 3 deletions client/src/followuidmagic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FollowUIDMagic: public BaseMagic
const char8_t *, // stageName
int, // x
int, // y
int, // gfxDirIndex, can be [0, m_gfxEntry.gfxDirIndex), used to indexing gfx resource
int, // gfxDirIndex, can be [0, m_gfxEntry->gfxDirIndex), used to indexing gfx resource
int, // flyDirIndex, flying direction when targetUID is unavailable and lastFlyOff is not set, always use [0, 16), only used to calculate location off, this is not gfxDirIndex
int, // moveSpeed
uint64_t, // targetUID
Expand All @@ -71,8 +71,8 @@ class FollowUIDMagic: public BaseMagic
// not from raw mir2 database
// offset generated by FollowUIDMagicEditor

if(m_gfxDirIndex < to_d(m_gfxEntry.targetOffList.size())){
return m_gfxEntry.targetOffList.begin()[m_gfxDirIndex];
if(m_gfxDirIndex < to_d(m_gfxEntry->targetOffList.size())){
return m_gfxEntry->targetOffList.begin()[m_gfxDirIndex];
}
return {0, 0};
}
Expand Down
Loading

0 comments on commit f31b5f7

Please sign in to comment.