Jump to content

Recommended Posts

  • 3 weeks later...
  • Honorable Member
6 hours ago, Amun said:

By using what Marty posted here

I've recently moved it outside PointsInstant (just for a better design style)

		CHARACTER_POINT_INSTANT	m_pointsInstant;
		std::unique_ptr<PlayerSlotT> m_PlayerSlots;

and included QuickSlot as well without any issues. (just check in char_quickslot.cpp if the unique_ptr is nullptr like always)

struct PlayerSlotT {
	std::array<LPITEM,INVENTORY_AND_EQUIP_SLOT_MAX> pItems;
	std::array<BYTE,INVENTORY_AND_EQUIP_SLOT_MAX> bItemGrid;
	std::array<LPITEM,DRAGON_SOUL_INVENTORY_MAX_NUM> pDSItems;
	std::array<WORD,DRAGON_SOUL_INVENTORY_MAX_NUM> wDSItemGrid;
	std::array<LPITEM,CUBE_MAX_NUM> pCubeItems;
#ifdef ENABLE_ACCE_COSTUME_SYSTEM
	std::array<TItemPosEx,ACCE_WINDOW_MAX_MATERIALS> pAcceMaterials;
#endif
	std::array<TQuickslot,QUICKSLOT_MAX_NUM> pQuickslot;
};

By using std::array instead of c-arrays, you'll get these differences:

  • You may need to use XXX.data() to get the raw ptr in few occasions.
  • memset is now useless garbage, because XXX = {} does that job for you
  • You get assertions if the array subindex goes out of bound
  • You can use all the generic features std:: containers support

What doesn't change is that std::array is still considered a trivial type for the template trails, and can also be used for client<>server packets.

Edited by martysama0134
  • Metin2 Dev 3
  • Scream 1
  • Good 2
  • Love 6
  • 3 months later...

The biggest fundamental flaw is that players and monsters use the same class and packet communication. This error causes unnecessary memory usage and unnecessarily long processing times. Action on this issue is only a minor improvement. More improvements should be made for large projects. All source code should be modular and independent of each other, with small packet communication and short processing times.

  • Good 1
  • 2 weeks later...
On 9/8/2022 at 5:36 PM, Amun said:

Pretty cool idea.

By using what Marty posted here

  Reveal hidden contents

 

The core reduced memory usage from 471 MB to 221, with a peak of 243 MB when booting(loading).

.png

 

i did everything the same but there is such a bug

https://metin2.download/picture/9Zj97oEe003IAgxykVqjZ4kYmlK86Z02/.png

and i used unique_ptr instead of make_unique in part SetPlayerProto.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Honorable Member
1 hour ago, bossy_max said:

@ martysama0134what can I use instead of make_unique ?

This is its definition:

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
Edited by martysama0134
8 hours ago, martysama0134 said:

This is its definition:

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

i will use it this thank you

m_pointsInstant.playerSlots = std::unique_ptr<character_point_instant::PlayerSlotT>(new character_point_instant::PlayerSlotT());

 

  • 4 months later...
On 11/5/2021 at 1:20 PM, martysama0134 said:

There are far better solutions than using std::map or std::unordered_map (which still takes a lot of ram for no reason for each mob):

(I included the most important parts)

You also forgot the CubeItems, and we could probably fit the quickslot too.

  Reveal hidden contents

u6xpuP5.png

8l52tEd.png

QuAep2f.png

DyiEUfe.png

ls2VRPX.png

from running 1 channel - x3 cores on 2GB RAM and an additional 800MB swap -> running 4 channels -  x12 cores on 2GB RAM and an additional 1.1GB swap 

this is huge

  • 1 year later...
On 11/5/2021 at 12:20 PM, martysama0134 said:

There are far better solutions than using std::map or std::unordered_map (which still takes a lot of ram for no reason for each mob):

(I included the most important parts)

You also forgot the CubeItems, and we could probably fit the quickslot too.

  Reveal hidden contents

u6xpuP5.png

8l52tEd.png

QuAep2f.png

DyiEUfe.png

ls2VRPX.png

Where could the problem be? When I add this, everything runs fine, but when I try to create an offline shop, I put an item in, open the shop, and then the item disappears, and shortly after, the shop closes.

 

I assume that the error will be here

LPITEM CHARACTER::GetItem(TItemPos Cell) const
{
    if (!m_pointsInstant.playerSlots)
        return nullptr;

    if (!IsValidItemPosition(Cell))
        return NULL;

    WORD wCell = Cell.cell;
    BYTE window_type = Cell.window_type;

    // Kontrola rozsahu hodnoty wCell
    if (wCell >= INVENTORY_MAX_NUM)
    {
        sys_err("CHARACTER::GetItem: invalid cell position %d (window_type %d)", wCell, window_type);
        return NULL;
    }

    switch (window_type)
    {
        case INVENTORY:
        case EQUIPMENT:
            if (wCell >= INVENTORY_AND_EQUIP_SLOT_MAX)
            {
                sys_err("CHARACTER::GetInventoryItem: invalid item cell %d", wCell);
                return NULL;
            }
            return m_pointsInstant.playerSlots->pItems[wCell];

        case DRAGON_SOUL_INVENTORY:
            if (wCell >= DRAGON_SOUL_INVENTORY_MAX_NUM)
            {
                sys_err("CHARACTER::GetInventoryItem: invalid DS item cell %d", wCell);
                return NULL;
            }
            return m_pointsInstant.playerSlots->pItems[wCell];

        default:
            sys_err("CHARACTER::GetItem: unknown window_type %d", window_type);
            return NULL;
    }

    return NULL;
}

 

sysser: 

 

db: 

 

SYSERR: Nov 11 00:29:08 :: ChildLoop: AsyncSQL: query failed: Data truncated for column 'window' at row 1 (query: REPLACE INTO item (id, owner_id, window, pos, count, vnum, dwVnum) VALUES(320024369, 0, 0, 0, 1, 11058, 0) errno: 1265)

 

game: cannot find item on pos (%d, %d) (name: %s)

 

  • Honorable Member
11 hours ago, Torch said:

Where could the problem be?

ChildLoop: AsyncSQL: query failed: Data truncated for column 'window' at row 1 (query: REPLACE INTO item (id, owner_id, window, pos, count, vnum, dwVnum) VALUES(320024369, 0, 0, 0, 1, 11058, 0) errno: 1265)

  1. (MySQL) player.item table -> (Navicat) Design table -> add the offlineshop window in the relative window enum field if missing
  2. In your query the window type is 0 and not something like 8-9, which means the error is in the c++.
    1. I don't know which offlineshop system you have, but probably you miss something like this:
    2.         case OFFLINESHOP_INVENTORY:
                  if (wCell >= OFFLINESHOP_SLOT_MAX)
                  {
                      sys_err("CHARACTER::GetInventoryItem: invalid OS item cell %d", wCell);
                      return NULL;
                  }
                  return m_pointsInstant.playerSlots->pOfflineItems[wCell];

       

  3. Furthermore, using a REPLACE query is utter garbage and should be avoided at any cost in MySQL.
Edited by martysama0134
  • 1 year later...

Shouldn’t we add this at the beginning of the function bool CHARACTER::IsEmptyItemGrid ?
It’s possible that without this check there is a risk of a core dump due to SIGSEGV.

 

bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) const
{
    // reduce server memory usage
    if (!m_pointsInstant.playerSlots)
        return false;
}

 

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.