Skip to content

Commit

Permalink
Refactor: Relocated memory zone, concurrency, Garbage to libdeng
Browse files Browse the repository at this point in the history
This big commit moves the memory zone, concurrency module, and
the garbage collector to the libdeng1 library. The code has gone through
a little big of cleanup during the move.

Some common definitions, macros and types were moved to
de/libdeng.h and de/types.h.

The commit also removes the LegacyCore* argument from all
libdeng2 C wrapper functions. The argument is not needed as
the LegacyCore is a singleton that can be accessed via the static
LegacyCore::instance() method. Consequently, calls to the C
wrapper functions are less awkward. The de2LegacyCore global
variable is now removed from the engine.

Todo: Move the memzone debug visualization back to the engine
so it can access the GL subsystem. The visualization will still need
to access the zone's private data (needs to include
libdeng/src/memoryzone_private.h).
  • Loading branch information
skyjake committed Jul 5, 2012
1 parent 7cdb3dd commit 9396e6c
Show file tree
Hide file tree
Showing 46 changed files with 799 additions and 600 deletions.
37 changes: 0 additions & 37 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -386,18 +386,6 @@ typedef struct gameinfo_s {
#define FRACEPSILON (1.0f/65535.f) // ~ 1.5e-5
#define FLOATEPSILON .000001f

#define MAX_OF(x, y) ((x) > (y)? (x) : (y))
#define MIN_OF(x, y) ((x) < (y)? (x) : (y))
#define MINMAX_OF(a, x, b) ((x) < (a)? (a) : (x) > (b)? (b) : (x))
#define SIGN_OF(x) ((x) > 0? +1 : (x) < 0? -1 : 0)
#define INRANGE_OF(x, y, r) ((x) >= (y) - (r) && (x) <= (y) + (r))
#define FEQUAL(x, y) (INRANGE_OF(x, y, FLOATEPSILON))
#define ROUND(x) ((int) (((x) < 0.0f)? ((x) - 0.5f) : ((x) + 0.5f)))
#define ABS(x) ((x) >= 0 ? (x) : -(x))

/// Ceiling of integer quotient of @a a divided by @a b.
#define CEILING(a, b) ((a) % (b) == 0 ? (a)/(b) : (a)/(b)+1)

/**
* Used to replace /255 as *reciprocal255 is less expensive with CPU cycles.
* Note that this should err on the side of being < 1/255 to prevent result
Expand Down Expand Up @@ -589,31 +577,6 @@ typedef struct event_s {
#define DD_MWHEEL_DOWN 4
#define DD_MICKEY_ACCURACY 1000

//------------------------------------------------------------------------
//
// Purge Levels
//
//------------------------------------------------------------------------

/**
* @defgroup memzone Memory Zone
* @ingroup base
*/

/**
* @defgroup purgeLevels Purge Levels
* @ingroup memzone
*/
///@{
#define PU_APPSTATIC 1 ///< Static entire execution time.
#define PU_GAMESTATIC 40 ///< Static until the game plugin which allocated it is unloaded.
#define PU_MAP 50 ///< Static until map exited (may still be freed during the map, though).
#define PU_MAPSTATIC 52 ///< Not freed until map exited.

#define PU_PURGELEVEL 100 ///< Tags >= 100 are purgable whenever needed.
#define PU_CACHE 101
///@}

//------------------------------------------------------------------------
//
// Map Data
Expand Down
121 changes: 0 additions & 121 deletions doomsday/engine/api/dd_types.h
Expand Up @@ -28,12 +28,6 @@

#include "de/types.h" // libdeng types

/*
#if defined(__x86_64__) || defined(__x86_64) || defined(_LP64)
# define __64BIT__
#endif
*/

/** In Win32 TCHAR and related macros change size depending on if they are
using wide characters (unicode utf-16le) or ansi for functions and strings.
on Linux and OSX we use utf-8 by default - which conveniently maps to the
Expand All @@ -45,52 +39,6 @@
#define _T(__v__) __v__
#endif

#ifndef _MSC_VER
#include <stdint.h> // Not MSVC so use C99 standard header
#else
/* MSVC must define them ouselves.
ISO C9x Integer types - not all of them though, just what we need
If we need more the this, best of taking the header from MinGW for MSVC users */

/* 7.18.1.1 Exact-width integer types */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;

/* 7.18.1.2 Minimum-width integer types */
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
typedef int int_least32_t;
typedef unsigned uint_least32_t;
typedef long long int_least64_t;
typedef unsigned long long uint_least64_t;

/* 7.18.1.3 Fastest minimum-width integer types
* Not actually guaranteed to be fastest for all purposes
* Here we use the exact-width types for 8 and 16-bit ints.
*/
typedef char int_fast8_t;
typedef unsigned char uint_fast8_t;
typedef short int_fast16_t;
typedef unsigned short uint_fast16_t;
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
typedef long long int_fast64_t;
typedef unsigned long long uint_fast64_t;

/* 7.18.1.5 Greatest-width integer types */
typedef long long intmax_t;
typedef unsigned long long uintmax_t;

#endif

// The C_DECL macro, used with functions.
#ifndef C_DECL
# ifdef WIN32
Expand All @@ -101,31 +49,6 @@ typedef unsigned long long uintmax_t;
# endif
#endif

#ifndef UNIX
typedef unsigned int uint;
typedef unsigned short ushort;
#else
# include <sys/types.h>
//typedef uint32_t uint;
//typedef uint16_t ushort;
#endif
typedef unsigned char byte;
typedef int32_t fixed_t;
typedef uint32_t angle_t;
typedef uint32_t ident_t;
typedef int32_t gameid_t;

typedef uint32_t fontid_t;
typedef uint32_t materialid_t;
typedef int patchid_t;
typedef int32_t spritenum_t;
typedef uint16_t nodeindex_t;
typedef uint16_t thid_t;
typedef double timespan_t;

/// All points in the map coordinate space should be defined using this type.
//typedef double coord_t;

typedef enum slopetype_e {
ST_HORIZONTAL,
ST_VERTICAL,
Expand All @@ -139,15 +62,6 @@ typedef int32_t lumpnum_t;
#define LUMPNAME_T_LASTINDEX 8
typedef char lumpname_t[LUMPNAME_T_MAXLEN];

// Pointer-integer conversion (used for legacy code).
#ifdef __64BIT__
typedef int64_t int_from_pointer_t;
#else
typedef int32_t int_from_pointer_t;
#endif
#define PTR2INT(x) ( (int_from_pointer_t) ((void*)(x)) )
#define INT2PTR(type,x) ( (type*) ((int_from_pointer_t)(x)) )

/// \todo dj: Refactor me away
#define FILENAME_T_MAXLEN 256
#define FILENAME_T_LASTINDEX 255
Expand Down Expand Up @@ -176,22 +90,6 @@ typedef enum {

#define VALID_RESOURCE_CLASS(n) ((n) >= RESOURCECLASS_FIRST && (n) < RESOURCECLASS_COUNT)

/*
#ifndef __BYTEBOOL__
#define __BYTEBOOL__
# ifndef __cplusplus
# undef false
# define false 0
# undef true
# define true 1
# else
# define CPP_BOOL(x) ((x) != 0)
# endif
typedef int ddboolean_t;
#endif
#define boolean ddboolean_t
*/

#define BAMS_BITS 16

#if BAMS_BITS == 32
Expand All @@ -207,25 +105,6 @@ typedef unsigned char binangle_t;

#define ANGLE_TO_BANG(angle) ((binangle_t)((angle_t)angle >> BAMS_BITS))

#define DDMAXCHAR ((char)0x7f)
#define DDMAXSHORT ((int16_t)0x7fff)
#define DDMAXUSHORT ((uint16_t)0xffff)
#define DDMAXINT ((int32_t)0x7fffffff) ///< Max positive 32-bit int
#define DDMAXLONG ((int32_t)0x7fffffff)
#define DDMAXFLOAT ((float)1E+37)

#define DDMINCHAR ((char)0x80)
#define DDMINSHORT ((int16_t)0x8000)
#define DDMININT ((int32_t)0x80000000) ///< Min negative 32-bit integer
#define DDMINLONG ((int32_t)0x80000000)
#define DDMINFLOAT ((float)-(1E+37))

#ifdef _DEBUG
# define DENG_DEBUG_ONLY(x) x
#else
# define DENG_DEBUG_ONLY(x)
#endif

// Forward declarations for map data types. The contents of these structs is
// declared in p_maptypes.h.
struct bspnode_s;
Expand Down
16 changes: 8 additions & 8 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -365,14 +365,14 @@ EXPORTS
W_LumpIsCustom @239 NONAME

; Base: Zone.
Z_Malloc @24 NONAME
Z_Calloc @211 NONAME
Z_Realloc @212 NONAME
Z_Recalloc @213 NONAME
Z_Free @25 NONAME
Z_FreeTags @26 NONAME
Z_ChangeTag2 @27 NONAME
Z_CheckHeap @28 NONAME
; Z_Malloc @24 NONAME
; Z_Calloc @211 NONAME
; Z_Realloc @212 NONAME
; Z_Recalloc @213 NONAME
; Z_Free @25 NONAME
; Z_FreeTags @26 NONAME
; Z_ChangeTag2 @27 NONAME
; Z_CheckHeap @28 NONAME

; Base: Misc.
dd_snprintf @447 NONAME
Expand Down
16 changes: 2 additions & 14 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -87,7 +87,8 @@ struct font_s;
#include "size.h"
#include "stringpool.h"
#include "writer.h"
#include "de/smoother.h"
#include <de/memoryzone.h>
#include <de/smoother.h>

//------------------------------------------------------------------------
//
Expand Down Expand Up @@ -211,19 +212,6 @@ materialid_t DD_MaterialForTextureUniqueId(texturenamespaceid_t texNamespaceId,
const char* F_PrettyPath(const char* path);
///@}

/// @addtogroup memzone
///@{
// Base: Zone.
void* _DECALL Z_Malloc(size_t size, int tag, void* ptr);
void* _DECALL Z_Calloc(size_t size, int tag, void* user);
void* Z_Realloc(void* ptr, size_t n, int mallocTag);
void* Z_Recalloc(void* ptr, size_t n, int callocTag);
void _DECALL Z_Free(void* ptr);
void Z_FreeTags(int lowTag, int highTag);
void Z_ChangeTag2(void* ptr, int tag);
void Z_CheckHeap(void);
///@}

//------------------------------------------------------------------------
//
// Console.
Expand Down
6 changes: 0 additions & 6 deletions doomsday/engine/engine.pro
Expand Up @@ -177,7 +177,6 @@ DENG_HEADERS += \
portable/include/con_busy.h \
portable/include/con_config.h \
portable/include/con_main.h \
portable/include/concurrency.h \
portable/include/consolewindow.h \
portable/include/dam_file.h \
portable/include/dam_main.h \
Expand All @@ -188,7 +187,6 @@ DENG_HEADERS += \
portable/include/dd_main.h \
portable/include/dd_pinit.h \
portable/include/dd_version.h \
portable/include/dd_zone.h \
portable/include/de_audio.h \
portable/include/de_base.h \
portable/include/de_bsp.h \
Expand Down Expand Up @@ -224,7 +222,6 @@ DENG_HEADERS += \
portable/include/fs_util.h \
portable/include/game.h \
portable/include/gamemap.h \
portable/include/garbage.h \
portable/include/generators.h \
portable/include/gl_defer.h \
portable/include/gl_deferredapi.h \
Expand Down Expand Up @@ -478,7 +475,6 @@ SOURCES += \
portable/src/con_config.c \
portable/src/con_data.c \
portable/src/con_main.c \
portable/src/concurrency.cpp \
portable/src/dam_file.c \
portable/src/dam_main.c \
portable/src/dd_help.c \
Expand All @@ -489,7 +485,6 @@ SOURCES += \
portable/src/dd_pinit.c \
portable/src/dd_plugin.c \
portable/src/dd_wad.c \
portable/src/dd_zone.c \
portable/src/def_data.c \
portable/src/def_main.c \
portable/src/def_read.c \
Expand All @@ -509,7 +504,6 @@ SOURCES += \
portable/src/fs_util.c \
portable/src/game.c \
portable/src/gamemap.c \
portable/src/garbage.cpp \
portable/src/generators.c \
portable/src/gl_defer.c \
portable/src/gl_deferredapi.c \
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/dd_input.h
Expand Up @@ -31,7 +31,8 @@

#define NUMKKEYS 256

#include "de/smoother.h"
#include <de/smoother.h>

#include "dd_string.h"
#if _DEBUG
# include "point.h" // For the debug visual.
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/dd_main.h
Expand Up @@ -56,8 +56,6 @@ extern "C" {
# define DEBUG_VERBOSE2_Message(code)
#endif

extern LegacyCore* de2LegacyCore;

extern int verbose;
//extern FILE* outFile; // Output file for console messages.

Expand Down
9 changes: 5 additions & 4 deletions doomsday/engine/portable/include/de_base.h
Expand Up @@ -34,11 +34,15 @@

#include "de_platform.h"

#include <de/memory.h>
#include <de/memoryzone.h>
#include <de/garbage.h>
#include <de/c_wrapper.h>

#include "dd_def.h"
#include "dd_share.h"
#include "dd_api.h"
#include "dd_plugin.h"
#include "dd_zone.h"
#include "dd_main.h"
#include "dd_input.h"
#include "dd_loop.h"
Expand All @@ -47,8 +51,5 @@
#include "library.h"
#include "reader.h"
#include "writer.h"
#include "garbage.h"

#include <de/c_wrapper.h>

#endif /* LIBDENG_BASE_H */
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/de_misc.h
Expand Up @@ -41,6 +41,6 @@
#include "gridmap.h"
#include "m_decomp64.h"
#include "stringarray.h"
#include "de/smoother.h"
#include <de/smoother.h>

#endif /* LIBDENG_MISC_H */
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/de_system.h
Expand Up @@ -25,14 +25,14 @@
#ifndef LIBDENG_SYSTEM_H
#define LIBDENG_SYSTEM_H

#include <de/concurrency.h>

#include "sys_system.h"
#include "sys_console.h"
#include "sys_input.h"
#include "sys_network.h"
#include "masterserver.h"
//#include "sys_sock.h" // obsolete
#include "timer.h"
#include "concurrency.h"
#include "sys_opengl.h"

// Use SDL for window management under *nix
Expand Down
7 changes: 0 additions & 7 deletions doomsday/engine/portable/include/m_misc.h
Expand Up @@ -44,13 +44,6 @@ struct aaboxd_s;
#define ISSPACE(c) ((c) == 0 || (c) == ' ' || (c) == '\t' || (c) == '\n' ||\
(c) == '\r')

// Memory.
void* M_Malloc(size_t size);
void* M_Calloc(size_t size);
void* M_Realloc(void* ptr, size_t size);
void* M_MemDup(const void* ptr, size_t size);
void M_Free(void* ptr);

// File system utility routines.
size_t M_ReadFile(char const* path, char** buffer);
boolean M_WriteFile(char const* path, const char* source, size_t length);
Expand Down

0 comments on commit 9396e6c

Please sign in to comment.