Skip to content

Commit

Permalink
Added a public API for Base domain
Browse files Browse the repository at this point in the history
Also fixed build regarding internal use of the public F API.
  • Loading branch information
skyjake committed Jan 2, 2013
1 parent 86b33db commit 2b359bf
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 62 deletions.
26 changes: 26 additions & 0 deletions doomsday/engine/api/api_base.h
Expand Up @@ -21,8 +21,11 @@
#ifndef DOOMSDAY_API_BASE_H
#define DOOMSDAY_API_BASE_H

#include <de/libdeng.h>

/// All APIs exported from the executable.
enum {
DE_API_BASE_v1 = 0, // 1.10
DE_API_DEFINITIONS_v1 = 100, // 1.10
DE_API_DIRECT_DATA_ACCESS_v1 = 200, // 1.10
DE_API_FILE_SYSTEM_v1 = 300, // 1.10
Expand Down Expand Up @@ -51,4 +54,27 @@ typedef struct de_api_s {
memcpy(&_api_##Name, api, sizeof(_api_##Name)); \
break;

// The Base API.
DENG_API_TYPEDEF(Base) // v1
{
de_api_t api;

int (*GetInteger)(int ddvalue);
void (*SetInteger)(int ddvalue, int parm);
void* (*GetVariable)(int ddvalue);
void (*SetVariable)(int ddvalue, void* ptr);
}
DENG_API_T(Base);

#ifndef DENG_NO_API_MACROS_BASE
#define DD_GetInteger _api_Base.GetInteger
#define DD_SetInteger _api_Base.SetInteger
#define DD_GetVariable _api_Base.GetVariable
#define DD_SetVariable _api_Base.SetVariable
#endif

#ifdef __DOOMSDAY__
DENG_USING_API(Base);
#endif

#endif // DOOMSDAY_API_BASE_H
29 changes: 28 additions & 1 deletion doomsday/engine/api/api_filesys.h
@@ -1,4 +1,4 @@
/** @file api_filesys.h
/** @file api_filesys.h Public API of the file system.
* Primary header file for the Doomsday Engine Public API
*
* @todo Break this header file up into group-specific ones.
Expand Down Expand Up @@ -34,14 +34,41 @@ DENG_API_TYPEDEF(F)
de_api_t api;

int (*Access)(const char* path);

/**
* Checks if a file exists in the native file system.
*
* @param file File to check existence of. Relative path directives are expanded
* automatically: '>' '}' (plus '~' on Unix-based platforms).
*
* @return @c 0 if the path points to a readable file on the local file system.
*/
int (*FileExists)(const char* path);

/**
* @return The time when the file/directory was last modified, as seconds since
* the Epoch else zero if @a path is not found.
*
* @attention This only works on native paths.
*/
unsigned int (*GetLastModified)(const char* path);

/**
* Check that the given directory exists. If it doesn't, create it.
*
* @return @c true if successful.
*/
boolean (*MakePath)(const char* path);

void (*FileName)(Str* dst, const char* src);
void (*ExtractFileBase)(char* dst, const char* path, size_t len);
const char* (*FindFileExtension)(const char* path);
boolean (*TranslatePath)(ddstring_t* dst, const Str* src);

/**
* @warning Not thread-safe!
* @return A prettier copy of the original path.
*/
const char* (*PrettyPath)(const char* path);

size_t (*ReadFile)(const char* path, char** buffer);
Expand Down
5 changes: 1 addition & 4 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -83,6 +83,7 @@ struct font_s;
#endif

#include "dd_share.h"
#include "api_base.h"
#include "api_plugin.h"
#include "api_def.h"
#include "api_filesys.h"
Expand Down Expand Up @@ -189,10 +190,6 @@ void DD_AddGameResource(gameid_t game, resourceclassid_t classId, int fFlags,
*/
boolean DD_GameInfo(GameInfo* info);

int _DECALL DD_GetInteger(int ddvalue);
void DD_SetInteger(int ddvalue, int parm);
void DD_SetVariable(int ddvalue, void* ptr);
void* DD_GetVariable(int ddvalue);
ddplayer_t* DD_GetPlayer(int number);
///@}

Expand Down
5 changes: 0 additions & 5 deletions doomsday/engine/include/dd_main.h
Expand Up @@ -141,11 +141,6 @@ boolean DD_ExchangeGamePluginEntryPoints(pluginid_t pluginId);
*/
void* DD_FindEntryPoint(pluginid_t pluginId, const char* fn);

int DD_GetInteger(int ddvalue);
void DD_SetInteger(int ddvalue, int parm);
void DD_SetVariable(int ddvalue, void* ptr);
void* DD_GetVariable(int ddvalue);

ddplayer_t* DD_GetPlayer(int number);

void DD_CreateResourceClasses();
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/include/de_filesys.h
Expand Up @@ -24,7 +24,6 @@
#define LIBDENG_FILESYS_H

#include "dd_types.h"

#include "resourceclass.h"
#include "filetype.h"

Expand All @@ -35,6 +34,8 @@
#include "filesys/manifest.h"
#include "filesys/sys_direc.h"

#include "api_filesys.h"

#include <de/findfile.h>

#endif /* LIBDENG_FILESYS_H */
2 changes: 0 additions & 2 deletions doomsday/engine/include/filesys/fs_main.h
Expand Up @@ -595,8 +595,6 @@ boolean F_CheckFileId(char const *nativePath);

int F_LumpCount(void);

int F_Access(char const *nativePath);

void F_Index(struct file1_s *file);

void F_Deindex(struct file1_s *file);
Expand Down
39 changes: 0 additions & 39 deletions doomsday/engine/include/filesys/fs_util.h
Expand Up @@ -34,39 +34,9 @@ extern "C" {

void F_FileDir(ddstring_t* dst, const ddstring_t* str);

void F_FileName(ddstring_t* dst, const char* src);

void F_FileNameAndExtension(ddstring_t* dst, const char* src);

const char* F_FindFileExtension(const char* path);

void F_ExtractFileBase2(char* dest, const char* path, size_t len, int ignore);
void F_ExtractFileBase(char* dest, const char* path, size_t len);

/**
* Checks if a file exists in the native file system.
*
* @param file File to check existence of. Relative path directives are expanded
* automatically: '>' '}' (plus '~' on Unix-based platforms).
*
* @return @c 0 if the path points to a readable file on the local file system.
*/
int F_FileExists(const char* path);

/**
* @return The time when the file/directory was last modified, as seconds since
* the Epoch else zero if @a path is not found.
*
* @attention This only works on native paths.
*/
uint F_GetLastModified(const char* path);

/**
* Check that the given directory exists. If it doesn't, create it.
*
* @return @c true if successful.
*/
boolean F_MakePath(const char* path);

/**
* Converts directory slashes to our internal '/'.
Expand Down Expand Up @@ -161,15 +131,6 @@ boolean F_ExpandBasePath(ddstring_t* dst, const ddstring_t* src);

boolean F_MakeAbsolute(ddstring_t* dst, const ddstring_t* src);

/// @todo Refactor me away (duplication).
boolean F_TranslatePath(ddstring_t* dst, const ddstring_t* src);

/**
* @warning Not thread-safe!
* @return A prettier copy of the original path.
*/
const char* F_PrettyPath(const char* path);

/**
* Write the data associated with the specified lump index to @a fileName.
*
Expand Down
4 changes: 0 additions & 4 deletions doomsday/engine/include/m_misc.h
Expand Up @@ -43,10 +43,6 @@ struct aaboxd_s;

#define ISSPACE(c) ((c) == 0 || (c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r')

// 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);

/**
* Reads x bits from the source stream and writes them to out.
*
Expand Down
12 changes: 12 additions & 0 deletions doomsday/engine/src/dd_main.cpp
Expand Up @@ -24,6 +24,8 @@
* 02110-1301 USA</small>
*/

#define DENG_NO_API_MACROS_BASE // functions defined here

#ifdef WIN32
# define _WIN32_DCOM
# include <objbase.h>
Expand Down Expand Up @@ -2939,3 +2941,13 @@ D_CMD(ReloadGame)
DD_ChangeGame(games->currentGame(), true/* allow reload */);
return true;
}

DENG_DECLARE_API(Base) =
{
{ DE_API_BASE_v1 },

DD_GetInteger,
DD_SetInteger,
DD_GetVariable,
DD_SetVariable
};
26 changes: 21 additions & 5 deletions doomsday/engine/src/filesys/fs_main.cpp
Expand Up @@ -23,10 +23,6 @@
* 02110-1301 USA</small>
*/

#define DENG_NO_API_MACROS_FILESYS
#include "api_filesys.h"
#include "m_misc.h"

#include <ctime>

#include <QDir>
Expand All @@ -38,6 +34,10 @@
#include <de/NativePath>
#include <de/memory.h>

#define DENG_NO_API_MACROS_FILESYS
#include "api_filesys.h"
#include "m_misc.h"

#include "de_base.h"
#include "de_console.h"
#include "de_filesys.h"
Expand Down Expand Up @@ -371,7 +371,7 @@ struct FS1::Instance
hndl = FileHandleBuilder::fromNativeFile(*found, baseOffset);

// Prepare the temporary info descriptor.
info = FileInfo(F_GetLastModified(foundPath.toUtf8().constData()));
info = FileInfo(_api_F.GetLastModified(foundPath.toUtf8().constData()));
}
}

Expand Down Expand Up @@ -1722,6 +1722,22 @@ uint F_FindPathInList(resourceclassid_t classId, char const* searchPaths,
return 0; // Not found.
}

// TODO: consolidate public API into a single file

// fs_util.cpp
extern int F_FileExists(const char* path);
extern uint F_GetLastModified(const char* path);
extern boolean F_MakePath(const char* path);
extern void F_FileName(ddstring_t* dst, const char* src);
extern void F_ExtractFileBase(char* dest, const char* path, size_t len);
extern const char* F_FindFileExtension(const char* path);
extern boolean F_TranslatePath(ddstring_t* dst, const ddstring_t* src);
extern const char* F_PrettyPath(const char* path);

// m_misc.c
DENG_EXTERN_C size_t M_ReadFile(const char* name, char** buffer);
DENG_EXTERN_C boolean M_WriteFile(const char* name, const char* source, size_t length);

DENG_DECLARE_API(F) =
{
{ DE_API_FILE_SYSTEM_v1 },
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/src/filesys/fs_util.cpp
Expand Up @@ -23,6 +23,8 @@
* 02110-1301 USA</small>
*/

#define DENG_NO_API_MACROS_FILESYS

#ifdef WIN32
# include <direct.h>
#endif
Expand Down
5 changes: 4 additions & 1 deletion doomsday/engine/src/m_misc.c
Expand Up @@ -58,6 +58,9 @@

#include "lzss.h"

#undef M_WriteFile
#undef M_ReadFile

// MACROS ------------------------------------------------------------------

#define SLOPERANGE 2048
Expand Down Expand Up @@ -1075,7 +1078,7 @@ int M_ScreenShot(const char* name, int bits)

Str_Init(&fullName);
Str_Set(&fullName, name);
if(!F_FindFileExtension(name))
if(!_api_F.FindFileExtension(name))
{
Str_Append(&fullName, ".png"); // Default format.
}
Expand Down

0 comments on commit 2b359bf

Please sign in to comment.