Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added public API for R (Resource) subsystem
libdoom now compiles and links successfully.
  • Loading branch information
skyjake committed Jan 4, 2013
1 parent bd814ed commit ec0024a
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 147 deletions.
129 changes: 129 additions & 0 deletions doomsday/engine/api/api_resource.h
@@ -0,0 +1,129 @@
#ifndef DOOMSDAY_API_RESOURCE_H
#define DOOMSDAY_API_RESOURCE_H

#include "apis.h"
#include "api_uri.h"
#include "dd_share.h"

DENG_API_TYPEDEF(R)
{
de_api_t api;

patchid_t (*DeclarePatch)(const char* name);

/**
* Retrieve extended info for the patch associated with @a id.
*
* @param id Unique identifier of the patch to lookup.
* @param info Extend info will be written here if found.
* @return @c true: Extended info for this patch was found.
*/
boolean (*GetPatchInfo)(patchid_t id, patchinfo_t* info);

/// @return Uri for the patch associated with @a id. Should be released with Uri_Delete()
Uri* (*ComposePatchUri)(patchid_t id);

/// @return Path for the patch associated with @a id. A zero-length string is
/// returned if the id is invalid/unknown.
AutoStr* (*ComposePatchPath)(patchid_t id);

/**
* Create a new animation group.
* @return Logical (unique) identifier reference associated with the new group.
*/
int (*CreateAnimGroup)(int flags);

/**
* Append a new @a texture frame to the identified @a animGroupNum.
*
* @param animGroupNum Logical identifier reference to the group being modified.
* @param texture Texture frame to be inserted into the group.
* @param tics Base duration of the new frame in tics.
* @param randomTics Extra frame duration in tics (randomized on each cycle).
*/
void (*AddAnimGroupFrame)(int groupNum, const Uri* texture, int tics, int randomTics);

/**
* Add a new (named) color palette.
*
* The idea with the two-teered implementation is to allow maximum flexibility.
* Within the engine we can create new palettes and manipulate them directly
* via the DGL interface. The underlying implementation is wrapped in a similar
* way to the materials so that publically, there is a set of (eternal) names
* and unique identifiers that survive game and GL resets.
*
* @param fmt Format string describes the format of @p data.
* Expected form: "C#C#C"
* C = color component, one of R, G, B.
* # = bits per component.
*
* @param name Unique name by which the palette will be known.
* @param colorData Color component triplets (at least @a colorCount * 3 values).
* @param colorCount Number of colors.
*
* @return Color palette id.
*/
colorpaletteid_t (*CreateColorPalette)(const char* fmt, const char* name, const uint8_t* colorData, int colorCount);

/**
* Given a color palette name, look up the associated identifier.
*
* @param name Unique name of the palette to locate.
* @return Identifier of the palette associated with this name, else @c 0
*/
colorpaletteid_t (*GetColorPaletteNumForName)(const char* name);

/**
* Given a color palette id, look up the specified unique name.
*
* @param id Id of the color palette to locate.
* @return Pointer to the unique name associated with the specified id else @c NULL
*/
const char* (*GetColorPaletteNameForNum)(colorpaletteid_t id);

/**
* Given a color palette index, calculate the equivalent RGB color.
*
* @param id Id of the ColorPalette to use.
* @param colorIdx ColorPalette color index.
* @param rgb Final color will be written back here.
* @param applyTexGamma @c true: the texture gamma ramp should be applied.
*/
void (*GetColorPaletteRGBf)(colorpaletteid_t id, int colorIdx, float rgb[3], boolean applyTexGamma);

/**
* Given a color palette index, calculate the equivalent RGB color.
*
* @param id Id of the ColorPalette to use.
* @param colorIdx ColorPalette color index.
* @param rgb Final color will be written back here.
* @param applyTexGamma @c true= the texture gamma ramp should be applied.
*/
void (*GetColorPaletteRGBubv)(colorpaletteid_t id, int colorIdx, uint8_t rgb[3], boolean applyTexGamma);

int (*TextureUniqueId)(const Uri* uri); /*quiet=false*/
int (*TextureUniqueId2)(const Uri* uri, boolean quiet);
}
DENG_API_T(R);

#ifndef DENG_NO_API_MACROS_RESOURCE
#define R_DeclarePatch _api_R.DeclarePatch
#define R_GetPatchInfo _api_R.GetPatchInfo
#define R_ComposePatchUri _api_R.ComposePatchUri
#define R_ComposePatchPath _api_R.ComposePatchPath
#define R_CreateAnimGroup _api_R.CreateAnimGroup
#define R_AddAnimGroupFrame _api_R.AddAnimGroupFrame
#define R_CreateColorPalette _api_R.CreateColorPalette
#define R_GetColorPaletteNumForName _api_R.GetColorPaletteNumForName
#define R_GetColorPaletteNameForNum _api_R.GetColorPaletteNameForNum
#define R_GetColorPaletteRGBf _api_R.GetColorPaletteRGBf
#define R_GetColorPaletteRGBubv _api_R.GetColorPaletteRGBubv
#define Textures_UniqueId _api_R.TextureUniqueId
#define Textures_UniqueId2 _api_R.TextureUniqueId2
#endif

#ifdef __DOOMSDAY__
DENG_USING_API(R);
#endif

#endif // DOOMSDAY_API_RESOURCE_H
22 changes: 1 addition & 21 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -75,6 +75,7 @@ struct font_s;
#include "api_svg.h"
#include "api_sound.h"
#include "api_render.h"
#include "api_resource.h"
#include "api_map.h"
#include "api_mapedit.h"
#include "api_client.h"
Expand Down Expand Up @@ -149,27 +150,6 @@ extern "C" {
* @defgroup render Renderer
*/

// R (Resource)

patchid_t R_DeclarePatch(const char* name);
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);
Uri* R_ComposePatchUri(patchid_t id);
AutoStr* R_ComposePatchPath(patchid_t id);

int Textures_UniqueId2(const Uri* uri, boolean quiet);
int Textures_UniqueId(const Uri* uri); /*quiet=false*/

int R_CreateAnimGroup(int flags);
void R_AddAnimGroupFrame(int groupNum, const Uri* texture, int tics, int randomTics);

colorpaletteid_t R_CreateColorPalette(const char* fmt, const char* name, const uint8_t* colorData, int colorCount);
colorpaletteid_t R_GetColorPaletteNumForName(const char* name);
const char* R_GetColorPaletteNameForNum(colorpaletteid_t id);

void R_GetColorPaletteRGBubv(colorpaletteid_t id, int colorIdx, uint8_t rgb[3], boolean applyTexGamma);
void R_GetColorPaletteRGBf(colorpaletteid_t id, int colorIdx, float rgb[3], boolean applyTexGamma);


#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
8 changes: 5 additions & 3 deletions doomsday/engine/engine.pro
Expand Up @@ -97,6 +97,7 @@ DENG_API_HEADERS = \
api/api_player.h \
api/api_plugin.h \
api/api_render.h \
api/api_resource.h \
api/api_resourceclass.h \
api/api_sound.h \
api/api_svg.h \
Expand Down Expand Up @@ -426,7 +427,7 @@ deng_nodisplaymode {
# Platform-independent sources.
SOURCES += \
src/api_material.cpp \
src/render/api_render.c \
src/api_uri.cpp \
src/audio/audiodriver.cpp \
src/audio/audiodriver_music.c \
src/audio/m_mus2midi.c \
Expand Down Expand Up @@ -544,6 +545,7 @@ SOURCES += \
src/network/sys_network.c \
src/network/ui_mpi.c \
src/r_util.c \
src/render/api_render.c \
src/render/lumobj.cpp \
src/render/r_draw.cpp \
src/render/r_fakeradio.c \
Expand All @@ -570,6 +572,7 @@ SOURCES += \
src/render/vignette.c \
src/render/vlight.cpp \
src/resource/animgroups.cpp \
src/resource/api_resource.c \
src/resource/bitmapfont.cpp \
src/resource/colorpalette.c \
src/resource/colorpalettes.cpp \
Expand Down Expand Up @@ -634,8 +637,7 @@ SOURCES += \
src/updater/updaterdialog.cpp \
src/updater/updatersettings.cpp \
src/updater/updatersettingsdialog.cpp \
src/uri.cpp \
src/uri_wrapper.cpp
src/uri.cpp

!deng_nosdlmixer:!deng_nosdl {
HEADERS += include/audio/sys_audiod_sdlmixer.h
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/include/de_resource.h
Expand Up @@ -46,4 +46,6 @@
# include "resource/zip.h"
#endif

#include "api_resource.h"

#endif /* LIBDENG_RESOURCE_SUBSYSTEM_H */
16 changes: 0 additions & 16 deletions doomsday/engine/include/resource/animgroups.h
Expand Up @@ -60,22 +60,6 @@ void R_ClearAnimGroups(void);
/// @return AnimGroup associated with @a animGroupNum else @c NULL
animgroup_t const *R_ToAnimGroup(int animGroupNum);

/**
* Create a new animation group.
* @return Logical (unique) identifier reference associated with the new group.
*/
int R_CreateAnimGroup(int flags);

/**
* Append a new @a texture frame to the identified @a animGroupNum.
*
* @param animGroupNum Logical identifier reference to the group being modified.
* @param texture Texture frame to be inserted into the group.
* @param tics Base duration of the new frame in tics.
* @param randomTics Extra frame duration in tics (randomized on each cycle).
*/
void R_AddAnimGroupFrame(int animGroupNum, Uri const *texture, int tics, int randomTics);

/// @return @c true iff @a texture is linked to the identified @a animGroupNum.
boolean R_IsTextureInAnimGroup(Uri const *texture, int animGroupNum);

Expand Down
64 changes: 0 additions & 64 deletions doomsday/engine/include/resource/colorpalettes.h
Expand Up @@ -59,70 +59,6 @@ colorpalette_t *R_ToColorPalette(colorpaletteid_t id);
*/
colorpalette_t *R_GetColorPaletteByIndex(int paletteIdx);

/**
* Add a new (named) color palette.
* @note Part of the Doomsday public API.
*
* The idea with the two-teered implementation is to allow maximum flexibility.
* Within the engine we can create new palettes and manipulate them directly
* via the DGL interface. The underlying implementation is wrapped in a similar
* way to the materials so that publically, there is a set of (eternal) names
* and unique identifiers that survive game and GL resets.
*
* @param fmt Format string describes the format of @p data.
* Expected form: "C#C#C"
* C = color component, one of R, G, B.
* # = bits per component.
*
* @param name Unique name by which the palette will be known.
* @param colorData Color component triplets (at least @a colorCount * 3 values).
* @param colorCount Number of colors.
*
* @return Color palette id.
*/
colorpaletteid_t R_CreateColorPalette(char const *fmt, char const *name,
uint8_t const *colorData, int colorCount);

/**
* Given a color palette id, look up the specified unique name.
* @note Part of the Doomsday public API.
*
* @param id Id of the color palette to locate.
* @return Pointer to the unique name associated with the specified id else @c NULL
*/
char const *R_GetColorPaletteNameForNum(colorpaletteid_t id);

/**
* Given a color palette name, look up the associated identifier.
* @note Part of the Doomsday public API.
*
* @param name Unique name of the palette to locate.
* @return Identifier of the palette associated with this name, else @c 0
*/
colorpaletteid_t R_GetColorPaletteNumForName(char const *name);

/**
* Given a color palette index, calculate the equivalent RGB color.
* @note Part of the Doomsday public API.
*
* @param id Id of the ColorPalette to use.
* @param colorIdx ColorPalette color index.
* @param rgb Final color will be written back here.
* @param correctGamma @c true= the texture gamma ramp should be applied.
*/
void R_GetColorPaletteRGBubv(colorpaletteid_t id, int colorIdx, uint8_t rgb[3], boolean correctGamma);

/**
* Given a color palette index, calculate the equivalent RGB color.
* @note Part of the Doomsday public API.
*
* @param id Id of the ColorPalette to use.
* @param colorIdx ColorPalette color index.
* @param rgb Final color will be written back here.
* @param correctGamma @c true= the texture gamma ramp should be applied.
*/
void R_GetColorPaletteRGBf(colorpaletteid_t id, int colorIdx, float rgb[3], boolean correctGamma);

/**
* Change the default color palette.
*
Expand Down
16 changes: 0 additions & 16 deletions doomsday/engine/include/resource/r_data.h
Expand Up @@ -67,22 +67,6 @@ void R_InitCompositeTextures(void);
void R_InitFlatTextures(void);
void R_InitSpriteTextures(void);

patchid_t R_DeclarePatch(char const *name);

/**
* Retrieve extended info for the patch associated with @a id.
* @param id Unique identifier of the patch to lookup.
* @param info Extend info will be written here if found.
* @return @c true= Extended info for this patch was found.
*/
boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info);

/// @return Uri for the patch associated with @a id. Should be released with Uri_Delete()
Uri *R_ComposePatchUri(patchid_t id);

/// @return Path for the patch associated with @a id. A zero-length string is
/// returned if the id is invalid/unknown.
AutoStr *R_ComposePatchPath(patchid_t id);
#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
3 changes: 0 additions & 3 deletions doomsday/engine/include/resource/textures.h
Expand Up @@ -277,9 +277,6 @@ void Textures_Init(void);
/// Shutdown this module.
void Textures_Shutdown(void);

int Textures_UniqueId2(Uri const *uri, boolean quiet);
int Textures_UniqueId(Uri const *uri/*, quiet = false */);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
@@ -1,6 +1,6 @@
/**
* @file uri_wrapper.cpp
* Universal Resource Identifier (C wrapper). @ingroup base
* @file api_uri.cpp
* Universal Resource Identifier (public C wrapper). @ingroup base
*
* @author Copyright &copy; 2010-2012 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2010-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/src/library.cpp
Expand Up @@ -35,6 +35,7 @@
#include "api_materialarchive.h"
#include "api_map.h"
#include "api_mapedit.h"
#include "api_resource.h"
#include "api_sound.h"
#include "api_fontrender.h"
#include "api_svg.h"
Expand Down Expand Up @@ -198,6 +199,7 @@ void Library_PublishAPIs(Library *lib)
PUBLISH(_api_MaterialArchive);
PUBLISH(_api_Player);
PUBLISH(_api_Plug);
PUBLISH(_api_R);
PUBLISH(_api_S);
PUBLISH(_api_Thinker);
PUBLISH(_api_Uri);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/src/resource/animgroups.cpp
Expand Up @@ -73,8 +73,8 @@ int R_AnimGroupCount()
return numgroups;
}

/// @note Part of the Doomsday public API.
int R_CreateAnimGroup(int flags)
#undef R_CreateAnimGroup
DENG_EXTERN_C int R_CreateAnimGroup(int flags)
{
// Allocating one by one is inefficient but it doesn't really matter.
groups = (animgroup_t *) Z_Realloc(groups, sizeof(*groups) * ++numgroups, PU_APPSTATIC);
Expand All @@ -90,8 +90,8 @@ int R_CreateAnimGroup(int flags)
return group->id;
}

/// @note Part of the Doomsday public API.
void R_AddAnimGroupFrame(int groupNum, uri_s const *textureUri, int tics, int randomTics)
#undef R_AddAnimGroupFrame
DENG_EXTERN_C void R_AddAnimGroupFrame(int groupNum, uri_s const *textureUri, int tics, int randomTics)
{
LOG_AS("R_AddAnimGroupFrame");

Expand Down

0 comments on commit ec0024a

Please sign in to comment.