Skip to content

Commit

Permalink
Added: New console variable type CVT_URIPTR i.e., Uri
Browse files Browse the repository at this point in the history
As Uri is now a fundamental data type in Doomsday - the console should
have built-in support and feature dynamic creation of variables of this
core type.

Mostly these will be handled identically to strings but with the added
benefit of centralised scheme syntax validation and error checking.
Note that this functionality has not yet been implemented - it can wait
until we derive Uri from Qt's QUrl.
  • Loading branch information
danij-deng committed Oct 24, 2011
1 parent 17d0def commit c3e3cbb
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 108 deletions.
11 changes: 9 additions & 2 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -1279,10 +1279,11 @@ typedef enum {
CVT_INT,
CVT_FLOAT,
CVT_CHARPTR, // ptr points to a char*, which points to the string.
CVT_URIPTR, // ptr points to a Uri*, which points to the uri.
CVARTYPE_COUNT
} cvartype_t;

#define VALID_CVARTYPE(val) ((val) >= CVT_NULL && (val) <= CVARTYPE_COUNT)
#define VALID_CVARTYPE(val) ((val) >= CVT_NULL && (val) < CVARTYPE_COUNT)

/**
* Console variable template. Used with Con_AddVariable.
Expand Down Expand Up @@ -1326,6 +1327,9 @@ typedef struct cvartemplate_s {
#define C_VAR_CHARPTR(name, ptr, flags, min, max) \
C_VAR(name, ptr, CVT_CHARPTR, flags, min, max, NULL)

#define C_VAR_URIPTR(name, ptr, flags, min, max) \
C_VAR(name, ptr, CVT_URIPTR, flags, min, max, NULL)

// Same as above but allow for a change notification callback func
#define C_VAR_BYTE2(name, ptr, flags, min, max, notifyChanged) \
C_VAR(name, ptr, CVT_BYTE, flags, min, max, notifyChanged)
Expand All @@ -1339,7 +1343,10 @@ typedef struct cvartemplate_s {
#define C_VAR_CHARPTR2(name, ptr, flags, min, max, notifyChanged) \
C_VAR(name, ptr, CVT_CHARPTR, flags, min, max, notifyChanged)

//------------------------------------------------------------------------
#define C_VAR_URIPTR2(name, ptr, flags, min, max, notifyChanged) \
C_VAR(name, ptr, CVT_URIPTR, flags, min, max, notifyChanged)

//------------------------------------------------------------------------
//
// Networking
//
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/api/dd_types.h
Expand Up @@ -227,6 +227,7 @@ struct surface_s;
struct material_s;

#include "dd_string.h"
#include "uri.h"

#endif /* LIBDENG_TYPES_H */

7 changes: 5 additions & 2 deletions doomsday/engine/api/doomsday.def
@@ -1,7 +1,7 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 589 <--
; Other free ordinals: 337
; Highest ordinal is currently: --> 591 <--
; Other free ordinals: none

NAME "DOOMSDAY"
EXPORTS
Expand Down Expand Up @@ -170,12 +170,15 @@ EXPORTS
Con_GetFloat @227 NONAME
Con_GetByte @228 NONAME
Con_GetString @229 NONAME
Con_GetUri @337 NONAME
Con_SetInteger @230 NONAME
Con_SetInteger2 @490 NONAME
Con_SetFloat @231 NONAME
Con_SetFloat2 @491 NONAME
Con_SetString @36 NONAME
Con_SetString2 @492 NONAME
Con_SetUri @590 NONAME
Con_SetUri2 @591 NONAME
Con_Printf @37 NONAME
Con_FPrintf @38 NONAME
Con_PrintRuler @584 NONAME
Expand Down
17 changes: 12 additions & 5 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -74,7 +74,6 @@ struct font_s;
#include "smoother.h"
#include "stringpool.h"
#include "writer.h"
#include "uri.h"

//------------------------------------------------------------------------
//
Expand Down Expand Up @@ -195,11 +194,15 @@ materialnum_t DD_MaterialForTextureIndex(uint index, texturenamespaceid_t texNam
void Con_AddVariable(const cvartemplate_t* var);
void Con_AddCommandList(const ccmdtemplate_t* cmdList);
void Con_AddVariableList(const cvartemplate_t* varList);

cvartype_t Con_GetVariableType(const char* name);
byte Con_GetByte(const char* name);
int Con_GetInteger(const char* name);
float Con_GetFloat(const char* name);
char* Con_GetString(const char* name);

byte Con_GetByte(const char* name);
int Con_GetInteger(const char* name);
float Con_GetFloat(const char* name);
char* Con_GetString(const char* name);
Uri* Con_GetUri(const char* name);

void Con_SetInteger2(const char* name, int value, int svflags);
void Con_SetInteger(const char* name, int value);

Expand All @@ -208,6 +211,10 @@ void Con_SetFloat(const char* name, float value);

void Con_SetString2(const char* name, const char* text, int svflags);
void Con_SetString(const char* name, const char* text);

void Con_SetUri2(const char* name, const Uri* uri, int svflags);
void Con_SetUri(const char* name, const Uri* uri);

void Con_Printf(const char* format, ...) PRINTF_F(1,2);
void Con_FPrintf(int flags, const char* format, ...) PRINTF_F(2,3);
void Con_PrintRuler(void);
Expand Down
15 changes: 14 additions & 1 deletion doomsday/engine/portable/include/con_main.h
Expand Up @@ -31,6 +31,7 @@

#include <stdio.h>
#include "dd_share.h"
#include "dd_types.h"
#include "de_system.h"
#include "dd_input.h"

Expand All @@ -44,6 +45,7 @@
#define CV_BYTE(var) (*(byte*) var->ptr)
#define CV_FLOAT(var) (*(float*) var->ptr)
#define CV_CHARPTR(var) (*(char**) var->ptr)
#define CV_URIPTR(var) (*(Uri**) var->ptr)

struct cbuffer_s;

Expand Down Expand Up @@ -99,16 +101,20 @@ typedef struct cvar_s {

const ddstring_t* CVar_TypeName(cvartype_t type);

/// @return @see consoleVariableFlags
int CVar_Flags(const cvar_t* var);

/// @return Type of the variable.
cvartype_t CVar_Type(const cvar_t* var);

/// @return Full symbolic name/path-to the variable. Must be destroyed with Str_Delete().
ddstring_t* CVar_ComposeName(cvar_t* var);
ddstring_t* CVar_ComposeName(const cvar_t* var);

int CVar_Integer(const cvar_t* var);
float CVar_Float(const cvar_t* var);
byte CVar_Byte(const cvar_t* var);
char* CVar_String(const cvar_t* var);
Uri* CVar_Uri(const cvar_t* var);

/**
* \note Also used with @c CVT_BYTE.
Expand All @@ -123,6 +129,9 @@ void CVar_SetFloat(cvar_t* var, float value);
void CVar_SetString2(cvar_t* var, const char* text, int svflags);
void CVar_SetString(cvar_t* var, const char* text);

void CVar_SetUri2(cvar_t* var, const Uri* uri, int svflags);
void CVar_SetUri(cvar_t* var, const Uri* uri);

typedef enum {
WT_ANY = -1,
KNOWNWORDTYPE_FIRST = 0,
Expand Down Expand Up @@ -241,6 +250,7 @@ int Con_GetInteger(const char* name);
float Con_GetFloat(const char* name);
byte Con_GetByte(const char* name);
char* Con_GetString(const char* name);
Uri* Con_GetUri(const char* name);

void Con_SetInteger2(const char* name, int value, int svflags);
void Con_SetInteger(const char* name, int value);
Expand All @@ -251,6 +261,9 @@ void Con_SetFloat(const char* name, float value);
void Con_SetString2(const char* name, const char* text, int svflags);
void Con_SetString(const char* name, const char* text);

void Con_SetUri2(const char* name, const Uri* uri, int svflags);
void Con_SetUri(const char* name, const Uri* uri);

calias_t* Con_AddAlias(const char* name, const char* command);

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/resourcerecord.h
Expand Up @@ -24,8 +24,8 @@
#ifndef LIBDENG_RESOURCERECORD_H
#define LIBDENG_RESOURCERECORD_H

#include "uri.h"
#include "dd_string.h"
#include "uri.h"

/**
* Resource Record. Used to record high-level metadata for a known resource.
Expand Down
30 changes: 23 additions & 7 deletions doomsday/engine/portable/src/con_config.c
Expand Up @@ -91,18 +91,34 @@ static int writeVariableToFileWorker(const knownword_t* word, void* paramaters)
fprintf(file, "%s ", Str_Text(name));
if(var->flags & CVF_PROTECTED)
fprintf(file, "force ");
if(var->type == CVT_BYTE)
switch(var->type)
{
case CVT_BYTE:
fprintf(file, "%d", *(byte*) var->ptr);
if(var->type == CVT_INT)
break;
case CVT_INT:
fprintf(file, "%d", *(int*) var->ptr);
if(var->type == CVT_FLOAT)
break;
case CVT_FLOAT:
fprintf(file, "%s", M_TrimmedFloat(*(float*) var->ptr));
if(var->type == CVT_CHARPTR)
{
break;
case CVT_CHARPTR:
fprintf(file, "\"");
if(CV_CHARPTR(var))
M_WriteTextEsc(file, CV_CHARPTR(var));
fprintf(file, "\"");
if(*(char**) var->ptr)
M_WriteTextEsc(file, *(char**) var->ptr);
break;
case CVT_URIPTR:
fprintf(file, "\"");
if(CV_URIPTR(var))
{
ddstring_t* path = Uri_ComposePath(CV_URIPTR(var));
fprintf(file, "%s", Str_Text(path));
Str_Delete(path);
}
fprintf(file, "\"");
break;
default: break;
}
fprintf(file, "\n\n");

Expand Down

0 comments on commit c3e3cbb

Please sign in to comment.