Register for your free account! | Forgot your password?

You last visited: Today at 16:26

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



FOR_LINKMAP with Lambda

Discussion on FOR_LINKMAP with Lambda within the Flyff PServer Guides & Releases forum part of the Flyff Private Server category.

Reply
 
Old   #1
 
Mognakor's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 598
Received Thanks: 465
FOR_LINKMAP with Lambda

I got no Test Server right now, so this is not tested. It does compile, though

World.h

Put this somewhere near the top.
Code:
#include <functional>
Put this where FOR_LINKMAP is.

Update:
Code:
inline void for_Linkmap(CWorld* p_World, const D3DXVECTOR3&	vPos, const int nRange, DWORD dwLinkType, int nLayer, std::function<void(CObj* p_Obj)> lambda)
{
	int nLinkX = int(vPos.x / p_World->m_iMPU);
	int nLinkZ = int(vPos.z / p_World->m_iMPU);

#ifdef __WORLDSERVER
	for (int i = 0; i < p_World->m_linkMap.GetMaxLinkLevel(dwLinkType, nLayer); i++)
	{
		int nWidthLink = p_World->m_linkMap.GetLinkWidth(dwLinkType, i, nLayer);

		CObj** p_Objs = p_World->m_linkMap.GetObj(dwLinkType, i, nLayer);
		ASSERT(p_Objs);	
#else
	for( int i = 0; i < MAX_LINKLEVEL; i++ )
	{
		int nWidthLink = CLandscape::m_nWidthLinkMap[i];
#endif

		int nMaxWidth = nWidthLink * p_World->m_nLandWidth;
		int nMaxHeight = nWidthLink * p_World->m_nLandHeight;

		int nUnit = (MAP_SIZE * p_World->m_nLandWidth) / nMaxWidth;

		int nX = (nLinkX / nUnit) * nUnit * p_World->m_iMPU;
		int nZ = (nLinkZ / nUnit) * nUnit * p_World->m_iMPU;

		int d = nUnit * p_World->m_iMPU / 2;

		nX = (int(vPos.x) - nX > d) ? 1 : 0;
		nZ = (int(vPos.z) - nZ > d) ? 1 : 0;

		int nLinkXMin = ( (nLinkX - nRange) / nUnit) + (nX - 1);
		int nLinkZMin = ( (nLinkZ - nRange) / nUnit) + (nZ - 1);

		if( nLinkXMin < 0 ) 
			nLinkXMin = 0;

		if( nLinkZMin < 0 ) 
			nLinkZMin = 0;

		int nLinkXMax = ( (nLinkX + nRange) / nUnit) + nX;
		int nLinkZMax = ( (nLinkZ + nRange) / nUnit) + nZ;	

		if( nLinkXMax >= nMaxWidth ) 
			nLinkXMax = nMaxWidth - 1;

		if( nLinkZMax >= nMaxHeight ) 
			nLinkZMax = nMaxHeight - 1;

		for (int j = nLinkZMin; j <= nLinkZMax; j++)
		{
			for (int k = nLinkXMin; k <= nLinkXMax; k++)
			{
#ifdef __WORLDSERVER
				{
					int nPos = j * nMaxWidth + k;
					CObj* pObj = p_Objs[nPos];
					int limit = 1000; 

					while( pObj && limit-- )
					{ 
#else
				CLandscape* pLand = p_World->m_apLand[(j / nWidthLink) * p_World->m_nLandWidth + (k / nWidthLink)];
				if (pLand)
				{
					int nPos = (j % nWidthLink) * nWidthLink + (k % nWidthLink);
					CObj** p_Objs = pLand->GetObjLink(dwLinkType, i);
					ASSERT(p_Objs);

					CObj* pObj = p_Objs[nPos];

					while (pObj)
						if (IsValidObj(pObj))
						{
#endif
							lambda(pObj);

							pObj = pObj->GetNextNode();
					}
				}

			}
		}

	}
}
Original(causes link error)

Now you can do stuff like
Code:
forLinkmap( GetWorld(), vPos, nRange, CObj::linkDynamic, GetLayer(), [] (CObj* p_Obj) {
// Do Stuff
} );
Mognakor is offline  
Thanks
8 Users
Old 02/23/2017, 14:56   #2
 
elite*gold: 0
Join Date: Jul 2016
Posts: 230
Received Thanks: 7
What does this do?
elitemember21 is offline  
Old 02/23/2017, 15:29   #3



 
Sedrika's Avatar
 
elite*gold: 18
The Black Market: 103/0/0
Join Date: Sep 2009
Posts: 20,177
Received Thanks: 14,471
Quote:
Originally Posted by elitemember21 View Post
What does this do?
https://en.wikipedia.org/wiki/Anonymous_function
Sedrika is offline  
Old 02/23/2017, 22:36   #4
 
Mognakor's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 598
Received Thanks: 465
Quote:
Originally Posted by elitemember21 View Post
What does this do?
You can do the same as with regular FOR_LINKMAP but it's much easier to debug.
Mognakor is offline  
Old 02/24/2017, 18:44   #5
 
elite*gold: 0
Join Date: Apr 2013
Posts: 511
Received Thanks: 431
This!

Best release ever i seen in this section! you made my day!

But over 90% don't know what lambda is..
Wanetrain is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
Lambda gate
09/17/2012 - DarkOrbit - 3 Replies
how many spins does it usually take to build lambda gate
Boxybot Lambda
07/28/2012 - DarkOrbit - 3 Replies
EDIT: damn i always get these stupid gate names mixed up. i meant kappa gate. has anyone done KAPPA on boxybot? i have it in there right now and it doesnt seem to be doing that great. i have it on waltz and antilag 450.
lambda bug
06/28/2012 - DarkOrbit - 5 Replies
LAMBDA GALAXY GATE BUG - WARNUNG!!! - YouTube can someone translate it?
Lambda by Me :)
06/28/2012 - DarkOrbit - 13 Replies
i m done Lambda Biuld :) Round 1: 1 . wawe - 8 Boss Streuner 2. wawe - 8 Boss Lordakia 3. wawe - 8 boxx Lordakia Round 2: 4. wawe - 6x Boss Mordor 5. wawe - 6x Boss Saimon 6. wawe- 6x Boss Saimon Round 3:
[NEW]Lambda Reward
06/28/2012 - DarkOrbit - 16 Replies
Here comes the Lambda reward ;) 5 Beute-Keys 3 Logfiles 100000 Honor



All times are GMT +1. The time now is 16:26.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.