Jump to content

Official appSetCameraMaxDistance [REVERSED]


Recommended Posts

  • Honorable Member

This is the hidden content, please

 

From: 22.5.7.0

 

It includes a modification that changes the custom distance based on the map names.

 

This is the hidden content, please

Edited by Mali
  • Metin2 Dev 104
  • Eyes 1
  • Think 1
  • Good 19
  • Love 4
  • Love 79

 

Link to comment
Share on other sites

  • Honorable Member
#define ENABLE_CAMERA_ZOOM_OPTIMIZE
#ifdef ENABLE_CAMERA_ZOOM_OPTIMIZE
#include <unordered_map>
#endif

PyObject* appSetCameraMaxDistance(PyObject* poSelf, PyObject* poArgs)
{
	float fMax{};
	if (!PyTuple_GetFloat(poArgs, 0, &fMax))
		return Py_BuildException();

#ifdef ENABLE_CAMERA_ZOOM_OPTIMIZE
	static const std::unordered_map<std::string, float> mapCameraZoom = {
		{"metin2_map_n_flame_dragon", 6000.0f},
		{"metin2_12zi_stage", 5000.0f},
		{"metin2_map_defensewave", 5000.0f},
		{"metin2_map_miniboss_01", 5000.0f},
		{"metin2_map_miniboss_02", 5000.0f},
		{"metin2_map_mists_of_island", 5000.0f},
	};
	const std::string c_rstrMapFileName = CPythonBackground::Instance().GetWarpMapName();
	const auto it = mapCameraZoom.find(c_rstrMapFileName);
	if (it != mapCameraZoom.end())
		fMax = it->second;
#endif

	CCamera::SetCameraMaxDistance(fMax);
	return Py_BuildNone();
}

I slightly refactored it. Now it's O(1).

Edited by martysama0134
  • Metin2 Dev 4
  • Love 1
  • Love 1
Link to comment
Share on other sites

  • Active Member

You can get this error: 'c_rstrMapFileName': redefinition; multiple initialization'

Just remove const std::string c_rstrMapFileName = CPythonBackground::Instance().GetWarpMapName(); in @ martysama0134 code it's defined twice.

This is the hidden content, please

  • Metin2 Dev 20
  • Good 4
  • Love 1
  • Love 5

I'll be always helpful! 👊 

Link to comment
Share on other sites

 Here is my slightly refactored version.. 🤣

 

#include <unordered_map>

// Add a list of maps and their corresponding max distance values to a map.
// This allows us to look up the max distance value for a given map more efficiently than using a series of if statements.
std::unordered_map<std::string, float> mapMaxDistances = {
    {"metin2_map_n_flame_dragon", 6000.0f},
    {"metin2_12zi_stage", 5000.0f},
    {"metin2_map_defensewave", 5000.0f},
    {"metin2_map_miniboss_01", 5000.0f},
    {"metin2_map_miniboss_02", 5000.0f},
    {"metin2_map_mists_of_island", 5000.0f}
};

PyObject* appSetCameraMaxDistance(PyObject* poSelf, PyObject* poArgs)
{
    float fMax;
    if (!PyTuple_GetFloat(poArgs, 0, &fMax))
        return Py_BuildException();

    const std::string c_rstrMapFileName = CPythonBackground::Instance().GetWarpMapName();

    // Look up the max distance value for the current map in the mapMaxDistances map.
    // If the map is not found in the map, the max distance value will be the default value of 0.0f.
    fMax = mapMaxDistances[c_rstrMapFileName];

    CCamera::SetCameraMaxDistance(fMax);
    return Py_BuildNone();
}

 

  • Facepalm 3
Link to comment
Share on other sites

  • Developer
13 minutes ago, Deso said:

 Here is my slightly refactored version.. 🤣

 

#include <unordered_map>

// Add a list of maps and their corresponding max distance values to a map.
// This allows us to look up the max distance value for a given map more efficiently than using a series of if statements.
std::unordered_map<std::string, float> mapMaxDistances = {
    {"metin2_map_n_flame_dragon", 6000.0f},
    {"metin2_12zi_stage", 5000.0f},
    {"metin2_map_defensewave", 5000.0f},
    {"metin2_map_miniboss_01", 5000.0f},
    {"metin2_map_miniboss_02", 5000.0f},
    {"metin2_map_mists_of_island", 5000.0f}
};

PyObject* appSetCameraMaxDistance(PyObject* poSelf, PyObject* poArgs)
{
    float fMax;
    if (!PyTuple_GetFloat(poArgs, 0, &fMax))
        return Py_BuildException();

    const std::string c_rstrMapFileName = CPythonBackground::Instance().GetWarpMapName();

    // Look up the max distance value for the current map in the mapMaxDistances map.
    // If the map is not found in the map, the max distance value will be the default value of 0.0f.
    fMax = mapMaxDistances[c_rstrMapFileName];

    CCamera::SetCameraMaxDistance(fMax);
    return Py_BuildNone();
}

 

Absolutely nonsense.
What's the point of passing fMax to define the camera max distance if it's replaced by 0?

  • kekw 1

when you return 0 and server doesn't boot:

unknown.png

Link to comment
Share on other sites

  • Honorable Member
15 minutes ago, Deso said:
fMax = mapMaxDistances[c_rstrMapFileName];

If the key is missing, it will create a new entry inside the unordered_map. Any m2 map not in table will have a max distance of 0.f. 

Edited by martysama0134
  • kekw 1
Link to comment
Share on other sites

  • Contributor
Spoiler

  

10 minutes ago, Deso said:

 Here is my slightly refactored version.. 🤣

 

#include <unordered_map>

// Add a list of maps and their corresponding max distance values to a map.
// This allows us to look up the max distance value for a given map more efficiently than using a series of if statements.
std::unordered_map<std::string, float> mapMaxDistances = {
    {"metin2_map_n_flame_dragon", 6000.0f},
    {"metin2_12zi_stage", 5000.0f},
    {"metin2_map_defensewave", 5000.0f},
    {"metin2_map_miniboss_01", 5000.0f},
    {"metin2_map_miniboss_02", 5000.0f},
    {"metin2_map_mists_of_island", 5000.0f}
};

PyObject* appSetCameraMaxDistance(PyObject* poSelf, PyObject* poArgs)
{
    float fMax;
    if (!PyTuple_GetFloat(poArgs, 0, &fMax))
        return Py_BuildException();

    const std::string c_rstrMapFileName = CPythonBackground::Instance().GetWarpMapName();

    // Look up the max distance value for the current map in the mapMaxDistances map.
    // If the map is not found in the map, the max distance value will be the default value of 0.0f.
    fMax = mapMaxDistances[c_rstrMapFileName];

    CCamera::SetCameraMaxDistance(fMax);
    return Py_BuildNone();
}

 

 

The fuck did you refactor?

 

Thanks, Mali!

Link to comment
Share on other sites

Announcements



×
×
  • 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.