Made cbasetypes.h more C++ compatible (#2315)
* Removed inline macro in cbasetypes.h * Renamed swap macro to avoid name clash with std::swap
This commit is contained in:
parent
829f0a1f59
commit
a46e012619
@ -485,7 +485,7 @@ static void mapif_Mail_return(int fd, uint32 char_id, int mail_id)
|
||||
char temp_[MAIL_TITLE_LENGTH];
|
||||
|
||||
// swap sender and receiver
|
||||
swap(msg.send_id, msg.dest_id);
|
||||
SWAP(msg.send_id, msg.dest_id);
|
||||
safestrncpy(temp_, msg.send_name, NAME_LENGTH);
|
||||
safestrncpy(msg.send_name, msg.dest_name, NAME_LENGTH);
|
||||
safestrncpy(msg.dest_name, temp_, NAME_LENGTH);
|
||||
|
@ -249,7 +249,9 @@ typedef uintptr_t uintptr;
|
||||
// keyword replacement
|
||||
#ifdef _MSC_VER
|
||||
// For MSVC (windows)
|
||||
#ifndef __cplusplus
|
||||
#define inline __inline
|
||||
#endif
|
||||
#define forceinline __forceinline
|
||||
#define ra_align(n) __declspec(align(n))
|
||||
#define _chdir chdir
|
||||
@ -277,15 +279,15 @@ typedef char bool;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// macro tools
|
||||
|
||||
#ifdef swap // just to be sure
|
||||
#undef swap
|
||||
#ifdef SWAP // just to be sure
|
||||
#undef SWAP
|
||||
#endif
|
||||
// hmm only ints?
|
||||
//#define swap(a,b) { int temp=a; a=b; b=temp;}
|
||||
//#define SWAP(a,b) { int temp=a; a=b; b=temp;}
|
||||
// if using macros then something that is type independent
|
||||
//#define swap(a,b) ((a == b) || ((a ^= b), (b ^= a), (a ^= b)))
|
||||
//#define SWAP(a,b) ((a == b) || ((a ^= b), (b ^= a), (a ^= b)))
|
||||
// Avoid "value computed is not used" warning and generates the same assembly code
|
||||
#define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
|
||||
#define SWAP(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
|
||||
#define swap_ptr(a,b) if ((a) != (b)) ((a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)))
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -198,7 +198,7 @@ unsigned int gettick(void)
|
||||
static void push_timer_heap(int tid)
|
||||
{
|
||||
BHEAP_ENSURE(timer_heap, 1, 256);
|
||||
BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, swap);
|
||||
BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, SWAP);
|
||||
}
|
||||
|
||||
/*==========================
|
||||
@ -335,9 +335,9 @@ int settick_timer(int tid, unsigned int tick)
|
||||
return (int)tick;// nothing to do, already in propper position
|
||||
|
||||
// pop and push adjusted timer
|
||||
BHEAP_POPINDEX(timer_heap, i, DIFFTICK_MINTOPCMP, swap);
|
||||
BHEAP_POPINDEX(timer_heap, i, DIFFTICK_MINTOPCMP, SWAP);
|
||||
timer_data[tid].tick = tick;
|
||||
BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, swap);
|
||||
BHEAP_PUSH(timer_heap, tid, DIFFTICK_MINTOPCMP, SWAP);
|
||||
return (int)tick;
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ int do_timer(unsigned int tick)
|
||||
break; // no more expired timers to process
|
||||
|
||||
// remove timer
|
||||
BHEAP_POP(timer_heap, DIFFTICK_MINTOPCMP, swap);
|
||||
BHEAP_POP(timer_heap, DIFFTICK_MINTOPCMP, SWAP);
|
||||
timer_data[tid].type |= TIMER_REMOVE_HEAP;
|
||||
|
||||
if( timer_data[tid].func )
|
||||
|
@ -428,8 +428,8 @@ static void warp_get_suggestions(struct map_session_data* sd, const char *name)
|
||||
strcat(buffer, " ");
|
||||
|
||||
// swap elements
|
||||
swap(distance[i][0], distance[min][0]);
|
||||
swap(distance[i][1], distance[min][1]);
|
||||
SWAP(distance[i][0], distance[min][0]);
|
||||
SWAP(distance[i][1], distance[min][1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -697,9 +697,9 @@ int map_foreachinareaV(int(*func)(struct block_list*, va_list), int16 m, int16 x
|
||||
return 0;
|
||||
|
||||
if (x1 < x0)
|
||||
swap(x0, x1);
|
||||
SWAP(x0, x1);
|
||||
if (y1 < y0)
|
||||
swap(y0, y1);
|
||||
SWAP(y0, y1);
|
||||
|
||||
x0 = i16max(x0, 0);
|
||||
y0 = i16max(y0, 0);
|
||||
@ -863,9 +863,9 @@ int map_forcountinarea(int (*func)(struct block_list*,va_list), int16 m, int16 x
|
||||
return 0;
|
||||
|
||||
if ( x1 < x0 )
|
||||
swap(x0, x1);
|
||||
SWAP(x0, x1);
|
||||
if ( y1 < y0 )
|
||||
swap(y0, y1);
|
||||
SWAP(y0, y1);
|
||||
|
||||
x0 = i16max(x0, 0);
|
||||
y0 = i16max(y0, 0);
|
||||
@ -930,9 +930,9 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_
|
||||
y1 = center->y + range;
|
||||
|
||||
if ( x1 < x0 )
|
||||
swap(x0, x1);
|
||||
SWAP(x0, x1);
|
||||
if ( y1 < y0 )
|
||||
swap(y0, y1);
|
||||
SWAP(y0, y1);
|
||||
|
||||
if( dx == 0 || dy == 0 ) {
|
||||
//Movement along one axis only.
|
||||
@ -1158,9 +1158,9 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int16 m,int16 x0,i
|
||||
|
||||
//The two fors assume mx0 < mx1 && my0 < my1
|
||||
if ( mx0 > mx1 )
|
||||
swap(mx0, mx1);
|
||||
SWAP(mx0, mx1);
|
||||
if ( my0 > my1 )
|
||||
swap(my0, my1);
|
||||
SWAP(my0, my1);
|
||||
|
||||
mx0 = max(mx0, 0);
|
||||
my0 = max(my0, 0);
|
||||
@ -1308,9 +1308,9 @@ int map_foreachindir(int(*func)(struct block_list*, va_list), int16 m, int16 x0,
|
||||
|
||||
//The following assumes mx0 < mx1 && my0 < my1
|
||||
if (mx0 > mx1)
|
||||
swap(mx0, mx1);
|
||||
SWAP(mx0, mx1);
|
||||
if (my0 > my1)
|
||||
swap(my0, my1);
|
||||
SWAP(my0, my1);
|
||||
|
||||
//Apply width to the path by turning 90 degrees
|
||||
mx0 -= abs(range*dirx[(dir + 2) % 8]);
|
||||
|
@ -644,9 +644,9 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0
|
||||
|
||||
// normalize x/y coordinates
|
||||
if (x0 > x1)
|
||||
swap(x0, x1);
|
||||
SWAP(x0, x1);
|
||||
if (y0 > y1)
|
||||
swap(y0, y1);
|
||||
SWAP(y0, y1);
|
||||
|
||||
// choose a suitable max. number of attempts
|
||||
max = (y1 - y0 + 1)*(x1 - x0 + 1)*3;
|
||||
|
@ -145,8 +145,8 @@ bool path_search_long(struct shootpath_data *spd,int16 m,int16 x0,int16 y0,int16
|
||||
|
||||
dx = (x1 - x0);
|
||||
if (dx < 0) {
|
||||
swap(x0, x1);
|
||||
swap(y0, y1);
|
||||
SWAP(x0, x1);
|
||||
SWAP(y0, y1);
|
||||
dx = -dx;
|
||||
}
|
||||
dy = (y1 - y0);
|
||||
|
@ -6886,7 +6886,7 @@ int pc_need_status_point(struct map_session_data* sd, int type, int val)
|
||||
high = low + val;
|
||||
|
||||
if ( val < 0 )
|
||||
swap(low, high);
|
||||
SWAP(low, high);
|
||||
|
||||
for ( ; low < high; low++ )
|
||||
sp += PC_STATUS_POINT_COST(low);
|
||||
|
@ -5650,7 +5650,7 @@ BUILDIN_FUNC(rand)
|
||||
int max = script_getnum(st,3);
|
||||
min = script_getnum(st,2);
|
||||
if( max < min )
|
||||
swap(min, max);
|
||||
SWAP(min, max);
|
||||
range = max - min + 1;
|
||||
}
|
||||
else
|
||||
@ -5759,8 +5759,8 @@ BUILDIN_FUNC(areawarp)
|
||||
y3 = 0;
|
||||
} else if( x3 && y3 ) {
|
||||
// normalize x3/y3 coordinates
|
||||
if( x3 < x2 ) swap(x3,x2);
|
||||
if( y3 < y2 ) swap(y3,y2);
|
||||
if( x3 < x2 ) SWAP(x3,x2);
|
||||
if( y3 < y2 ) SWAP(y3,y2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18756,8 +18756,8 @@ BUILDIN_FUNC(setcell)
|
||||
|
||||
int x,y;
|
||||
|
||||
if( x1 > x2 ) swap(x1,x2);
|
||||
if( y1 > y2 ) swap(y1,y2);
|
||||
if( x1 > x2 ) SWAP(x1,x2);
|
||||
if( y1 > y2 ) SWAP(y1,y2);
|
||||
|
||||
for( y = y1; y <= y2; ++y )
|
||||
for( x = x1; x <= x2; ++x )
|
||||
|
@ -185,7 +185,7 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
||||
}
|
||||
|
||||
if( max_price < min_price )
|
||||
swap(min_price, max_price);
|
||||
SWAP(min_price, max_price);
|
||||
|
||||
sd->searchstore.uses--;
|
||||
sd->searchstore.type = type;
|
||||
|
@ -5490,8 +5490,8 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
|
||||
for( i = 0; i <= j - 2; i++ )
|
||||
for( k = i + 1; k <= j - 1; k++ )
|
||||
if( positions[i] < positions[k] ) {
|
||||
swap(positions[i],positions[k]);
|
||||
swap(spheres[i],spheres[k]);
|
||||
SWAP(positions[i],positions[k]);
|
||||
SWAP(spheres[i],spheres[k]);
|
||||
}
|
||||
|
||||
if(j == 5) { // If 5 spheres, remove last one and only do 4 actions (Official behavior)
|
||||
@ -5601,8 +5601,8 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
|
||||
for( k = i + 1; k <= j - 1; k++ )
|
||||
if( positions[i] > positions[k] )
|
||||
{
|
||||
swap(positions[i],positions[k]);
|
||||
swap(spheres[i],spheres[k]);
|
||||
SWAP(positions[i],positions[k]);
|
||||
SWAP(spheres[i],spheres[k]);
|
||||
}
|
||||
|
||||
if( skill_lv == 1 ) j = 1; // Limit only to one ball
|
||||
|
Loading…
x
Reference in New Issue
Block a user