Skip to content

Commit

Permalink
Initial work for map server to C++ (#2565)
Browse files Browse the repository at this point in the history
* Initial progression of moving the map-server to C++ format.
* Converted all core files to .cpp and header files to .hpp.
* Refactored the refine database parser to utilize native YAML C++.
Thanks to @Jeybla and @lighta for their help!
  • Loading branch information
aleos89 committed Nov 2, 2017
1 parent c6cc8ed commit c4a364b
Show file tree
Hide file tree
Showing 102 changed files with 1,674 additions and 1,794 deletions.
11 changes: 8 additions & 3 deletions 3rdparty/libconfig/grammar.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#pragma once
/* A Bison parser, made by GNU Bison 2.4.1. */

/* Skeleton interface for Bison's Yacc-like parsers in C
Expand Down Expand Up @@ -32,7 +32,10 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
Expand Down Expand Up @@ -109,5 +112,7 @@ typedef union YYSTYPE
#endif



#ifdef __cplusplus
}
#endif /* __cplusplus */

2 changes: 2 additions & 0 deletions 3rdparty/libconfig/libconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
----------------------------------------------------------------------------
*/

#pragma once

#ifndef __libconfig_h
#define __libconfig_h

Expand Down
2 changes: 2 additions & 0 deletions 3rdparty/libconfig/parsectx.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2010 Mark A Lindner
Expand Down
10 changes: 10 additions & 0 deletions 3rdparty/libconfig/scanctx.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2010 Mark A Lindner
Expand Down Expand Up @@ -31,6 +33,10 @@

#define MAX_INCLUDE_DEPTH 10

#ifdef __cplusplus
extern "C" {
#endif

struct scan_context
{
config_t *config;
Expand Down Expand Up @@ -59,4 +65,8 @@ extern char *scanctx_take_string(struct scan_context *ctx);

extern const char *scanctx_current_filename(struct scan_context *ctx);

#ifdef __cplusplus
}
#endif

#endif /* __libconfig_scanctx_h */
2 changes: 2 additions & 0 deletions 3rdparty/libconfig/scanner.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#ifndef libconfig_yyHEADER_H
#define libconfig_yyHEADER_H 1
#define libconfig_yyIN_HEADER 1
Expand Down
10 changes: 10 additions & 0 deletions 3rdparty/libconfig/strbuf.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2010 Mark A Lindner
Expand Down Expand Up @@ -26,6 +28,10 @@
#include <string.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
char *string;
Expand All @@ -37,4 +43,8 @@ char *strbuf_release(strbuf_t *buf);

void strbuf_append(strbuf_t *buf, const char *text);

#ifdef __cplusplus
}
#endif

#endif /* __libconfig_strbuf_h */
2 changes: 2 additions & 0 deletions 3rdparty/libconfig/wincompat.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/* ----------------------------------------------------------------------------
libconfig - A library for processing structured configuration files
Copyright (C) 2005-2010 Mark A Lindner
Expand Down
10 changes: 10 additions & 0 deletions 3rdparty/mt19937ar/mt19937ar.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Expand Down Expand Up @@ -43,6 +45,10 @@
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/

#ifdef __cplusplus
extern "C" {
#endif

/* initializes mt[N] with a seed */
void init_genrand(unsigned long s);

Expand Down Expand Up @@ -70,3 +76,7 @@ double genrand_real3(void);

/* generates a random number on [0,1) with 53-bit resolution*/
double genrand_res53(void);

#ifdef __cplusplus
}
#endif
3 changes: 2 additions & 1 deletion src/common/cbasetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ typedef char bool;
//#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_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)))
#define swap_ptrcast(c,a,b) if ((a) != (b)) ((a) = static_cast<c>((void*)((intptr_t)(a) ^ (intptr_t)(b))), (b) = static_cast<c>((void*)((intptr_t)(a) ^ (intptr_t)(b))), (a) = static_cast<c>((void*)((intptr_t)(a) ^ (intptr_t)(b))) )
#define swap_ptr(a,b) swap_ptrcast(void*,a,b)

//////////////////////////////////////////////////////////////////////////
// should not happen
Expand Down
8 changes: 8 additions & 0 deletions src/common/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
#ifndef _CONF_H_
#define _CONF_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "cbasetypes.h"
#include "../../3rdparty/libconfig/libconfig.h"

int conf_read_file(config_t *config, const char *config_filename);
int config_setting_copy(config_setting_t *parent, const config_setting_t *src);

#ifdef __cplusplus
}
#endif

#endif // _CONF_H_
24 changes: 12 additions & 12 deletions src/common/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
#ifndef _DB_H_
#define _DB_H_

#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>

#include "cbasetypes.h"

#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif

/*****************************************************************************\
* (1) Section with public typedefs, enums, unions, structures and defines. *
Expand Down Expand Up @@ -1133,12 +1133,12 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
///
/// @param __vec Vector
/// @param __n Size
#define VECTOR_RESIZE(__vec,__n) \
#define VECTOR_RESIZE(__vec,__n,__cast) \
do{ \
if( (__n) > VECTOR_CAPACITY(__vec) ) \
{ /* increase size */ \
if( VECTOR_CAPACITY(__vec) == 0 ) VECTOR_DATA(__vec) = aMalloc((__n)*sizeof(VECTOR_FIRST(__vec))); /* allocate new */ \
else VECTOR_DATA(__vec) = aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))); /* reallocate */ \
if( VECTOR_CAPACITY(__vec) == 0 ) VECTOR_DATA(__vec) = (__cast)(aMalloc((__n)*sizeof(VECTOR_FIRST(__vec))) ); /* allocate new */ \
else VECTOR_DATA(__vec) = (__cast)(aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))) ); /* reallocate */ \
memset(VECTOR_DATA(__vec)+VECTOR_LENGTH(__vec), 0, (VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec))*sizeof(VECTOR_FIRST(__vec))); /* clear new data */ \
VECTOR_CAPACITY(__vec) = (__n); /* update capacity */ \
} \
Expand All @@ -1150,7 +1150,7 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
} \
else if( (__n) < VECTOR_CAPACITY(__vec) ) \
{ /* reduce size */ \
VECTOR_DATA(__vec) = aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))); /* reallocate */ \
VECTOR_DATA(__vec) = (__cast)(aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))) ); /* reallocate */ \
VECTOR_CAPACITY(__vec) = (__n); /* update capacity */ \
if( VECTOR_LENGTH(__vec) > (__n) ) VECTOR_LENGTH(__vec) = (__n); /* update length */ \
} \
Expand All @@ -1164,15 +1164,15 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
/// @param __vec Vector
/// @param __n Empty positions
/// @param __step Increase
#define VECTOR_ENSURE(__vec,__n,__step) \
#define VECTOR_ENSURE2(__vec,__n,__step,__cast) \
do{ \
size_t _empty_ = VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec); \
if( (__n) > _empty_ ) { \
while( (__n) > _empty_ ) _empty_ += (__step); \
VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \
VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec),__cast); \
} \
}while(0)

#define VECTOR_ENSURE(__vec,__n,__step) VECTOR_ENSURE2(__vec,__n,__step,int*)


/// Inserts a zeroed value in the target index.
Expand Down Expand Up @@ -1428,7 +1428,7 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
/// @param __n Empty positions
/// @param __step Increase
#define BHEAP_ENSURE(__heap,__n,__step) VECTOR_ENSURE(__heap,__n,__step)

#define BHEAP_ENSURE2(__heap,__n,__step,__cast) VECTOR_ENSURE2(__heap,__n,__step,__cast)


/// Returns the top value of the heap.
Expand Down
39 changes: 38 additions & 1 deletion src/common/mmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,43 @@ enum item_types {
IT_MAX
};

/// Monster mode definitions to clear up code reading. [Skotlex]
enum e_mode {
MD_NONE = 0x0000000,
MD_CANMOVE = 0x0000001,
MD_LOOTER = 0x0000002,
MD_AGGRESSIVE = 0x0000004,
MD_ASSIST = 0x0000008,
MD_CASTSENSOR_IDLE = 0x0000010,
MD_NORANDOM_WALK = 0x0000020,
MD_NOCAST_SKILL = 0x0000040,
MD_CANATTACK = 0x0000080,
//FREE = 0x0000100,
MD_CASTSENSOR_CHASE = 0x0000200,
MD_CHANGECHASE = 0x0000400,
MD_ANGRY = 0x0000800,
MD_CHANGETARGET_MELEE = 0x0001000,
MD_CHANGETARGET_CHASE = 0x0002000,
MD_TARGETWEAK = 0x0004000,
MD_RANDOMTARGET = 0x0008000,
MD_IGNOREMELEE = 0x0010000,
MD_IGNOREMAGIC = 0x0020000,
MD_IGNORERANGED = 0x0040000,
MD_MVP = 0x0080000,
MD_IGNOREMISC = 0x0100000,
MD_KNOCKBACK_IMMUNE = 0x0200000,
MD_TELEPORT_BLOCK = 0x0400000,
//FREE = 0x0800000,
MD_FIXED_ITEMDROP = 0x1000000,
MD_DETECTOR = 0x2000000,
MD_STATUS_IMMUNE = 0x4000000,
MD_SKILL_IMMUNE = 0x8000000,
};

#define MD_MASK 0x000FFFF
#define ATR_MASK 0x0FF0000
#define CL_MASK 0xF000000

// Questlog states
enum quest_state {
Q_INACTIVE, ///< Inactive quest (the user can toggle between active and inactive quests)
Expand Down Expand Up @@ -405,7 +442,7 @@ struct s_elemental {
int elemental_id;
uint32 char_id;
short class_;
int mode;
enum e_mode mode;
int hp, sp, max_hp, max_sp, matk, atk, atk2;
short hit, flee, amotion, def, mdef;
int life_time;
Expand Down
88 changes: 2 additions & 86 deletions src/map/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,92 +9,8 @@ set( MAP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "" )
#
if( BUILD_SERVERS )
message( STATUS "Creating target map-server" )
set( MAP_HEADERS
"${MAP_SOURCE_DIR}/achievement.h"
"${MAP_SOURCE_DIR}/atcommand.h"
"${MAP_SOURCE_DIR}/battle.h"
"${MAP_SOURCE_DIR}/battleground.h"
"${MAP_SOURCE_DIR}/buyingstore.h"
"${MAP_SOURCE_DIR}/chat.h"
"${MAP_SOURCE_DIR}/chrif.h"
"${MAP_SOURCE_DIR}/clan.h"
"${MAP_SOURCE_DIR}/clif.h"
"${MAP_SOURCE_DIR}/date.h"
"${MAP_SOURCE_DIR}/duel.h"
"${MAP_SOURCE_DIR}/elemental.h"
"${MAP_SOURCE_DIR}/guild.h"
"${MAP_SOURCE_DIR}/homunculus.h"
"${MAP_SOURCE_DIR}/instance.h"
"${MAP_SOURCE_DIR}/intif.h"
"${MAP_SOURCE_DIR}/itemdb.h"
"${MAP_SOURCE_DIR}/log.h"
"${MAP_SOURCE_DIR}/mail.h"
"${MAP_SOURCE_DIR}/map.h"
"${MAP_SOURCE_DIR}/mapreg.h"
"${MAP_SOURCE_DIR}/mercenary.h"
"${MAP_SOURCE_DIR}/mob.h"
"${MAP_SOURCE_DIR}/npc.h"
"${MAP_SOURCE_DIR}/party.h"
"${MAP_SOURCE_DIR}/path.h"
"${MAP_SOURCE_DIR}/pc.h"
"${MAP_SOURCE_DIR}/pc_groups.h"
"${MAP_SOURCE_DIR}/pet.h"
"${MAP_SOURCE_DIR}/quest.h"
"${MAP_SOURCE_DIR}/script.h"
"${MAP_SOURCE_DIR}/script_constants.h"
"${MAP_SOURCE_DIR}/searchstore.h"
"${MAP_SOURCE_DIR}/skill.h"
"${MAP_SOURCE_DIR}/status.h"
"${MAP_SOURCE_DIR}/storage.h"
"${MAP_SOURCE_DIR}/trade.h"
"${MAP_SOURCE_DIR}/unit.h"
"${MAP_SOURCE_DIR}/vending.h"
"${MAP_SOURCE_DIR}/cashshop.h"
"${MAP_SOURCE_DIR}/channel.h"
)
set( MAP_SOURCES
"${MAP_SOURCE_DIR}/achievement.c"
"${MAP_SOURCE_DIR}/atcommand.c"
"${MAP_SOURCE_DIR}/battle.c"
"${MAP_SOURCE_DIR}/battleground.c"
"${MAP_SOURCE_DIR}/buyingstore.c"
"${MAP_SOURCE_DIR}/chat.c"
"${MAP_SOURCE_DIR}/chrif.c"
"${MAP_SOURCE_DIR}/clan.c"
"${MAP_SOURCE_DIR}/clif.cpp"
"${MAP_SOURCE_DIR}/date.c"
"${MAP_SOURCE_DIR}/duel.c"
"${MAP_SOURCE_DIR}/elemental.c"
"${MAP_SOURCE_DIR}/guild.c"
"${MAP_SOURCE_DIR}/homunculus.c"
"${MAP_SOURCE_DIR}/instance.c"
"${MAP_SOURCE_DIR}/intif.c"
"${MAP_SOURCE_DIR}/itemdb.c"
"${MAP_SOURCE_DIR}/log.c"
"${MAP_SOURCE_DIR}/mail.c"
"${MAP_SOURCE_DIR}/map.cpp"
"${MAP_SOURCE_DIR}/mapreg.c"
"${MAP_SOURCE_DIR}/mercenary.c"
"${MAP_SOURCE_DIR}/mob.cpp"
"${MAP_SOURCE_DIR}/npc.c"
"${MAP_SOURCE_DIR}/npc_chat.c"
"${MAP_SOURCE_DIR}/party.c"
"${MAP_SOURCE_DIR}/path.c"
"${MAP_SOURCE_DIR}/pc.c"
"${MAP_SOURCE_DIR}/pc_groups.c"
"${MAP_SOURCE_DIR}/pet.c"
"${MAP_SOURCE_DIR}/quest.c"
"${MAP_SOURCE_DIR}/script.cpp"
"${MAP_SOURCE_DIR}/searchstore.c"
"${MAP_SOURCE_DIR}/skill.cpp"
"${MAP_SOURCE_DIR}/status.c"
"${MAP_SOURCE_DIR}/storage.c"
"${MAP_SOURCE_DIR}/trade.c"
"${MAP_SOURCE_DIR}/unit.c"
"${MAP_SOURCE_DIR}/vending.c"
"${MAP_SOURCE_DIR}/cashshop.c"
"${MAP_SOURCE_DIR}/channel.c"
)
file(GLOB MAP_HEADERS ${MAP_SOURCE_DIR}/*.hpp)
file(GLOB MAP_SOURCES ${MAP_SOURCE_DIR}/*.cpp)
set( DEPENDENCIES common yaml-cpp)
set( LIBRARIES ${GLOBAL_LIBRARIES} yaml-cpp)
set( INCLUDE_DIRS ${GLOBAL_INCLUDE_DIRS} ${COMMON_BASE_INCLUDE_DIRS} )
Expand Down
5 changes: 3 additions & 2 deletions src/map/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ YAML_CPP_AR = ../../3rdparty/yaml-cpp/obj/yaml-cpp.a
YAML_CPP_H = $(shell find ../../3rdparty/yaml-cpp/ -type f -name "*.h")
YAML_CPP_INCLUDE = -I../../3rdparty/yaml-cpp/include

MAP_OBJ = $(shell ls *.c | sed -e "s/\.c/\.o/g") $(shell ls *.cpp | sed -e "s/\.cpp/\.o/g")
MAP_OBJ = $(shell ls *.cpp | sed -e "s/\.cpp/\.o/g")
#MAP_OBJ += $(shell ls *.c | sed -e "s/\.c/\.o/g")
MAP_DIR_OBJ = $(MAP_OBJ:%=obj/%)
MAP_H = $(shell ls ../map/*.h) \
MAP_H = $(shell ls ../map/*.hpp) \
$(shell ls ../config/*.h)

HAVE_MYSQL=@HAVE_MYSQL@
Expand Down
Loading

2 comments on commit c4a364b

@dev1-juan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

1 warning when compiling on windows

@mazvi
Copy link
Contributor

@mazvi mazvi commented on c4a364b Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check battle C sync with #2561

Please sign in to comment.