00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "../ui_nodes.h"
00028 #include "../ui_parse.h"
00029 #include "../ui_internal.h"
00030 #include "ui_node_abstractvalue.h"
00031
00032 #define EXTRADATA_TYPE abstractValueExtraData_t
00033 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00034 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00035
00036 static const uiBehaviour_t const *localBehaviour;
00037
00038 static inline void UI_InitCvarOrFloat (float** adress, float defaultValue)
00039 {
00040 if (*adress == NULL) {
00041 *adress = UI_AllocStaticFloat(1);
00042 **adress = defaultValue;
00043 }
00044 }
00045
00046 static void UI_AbstractValueLoaded (uiNode_t * node)
00047 {
00048 UI_InitCvarOrFloat((float**)&EXTRADATA(node).value, 0);
00049 UI_InitCvarOrFloat((float**)&EXTRADATA(node).delta, 1);
00050 UI_InitCvarOrFloat((float**)&EXTRADATA(node).max, 0);
00051 UI_InitCvarOrFloat((float**)&EXTRADATA(node).min, 0);
00052 }
00053
00054 static void UI_AbstractValueNew (uiNode_t * node)
00055 {
00056 EXTRADATA(node).value = Mem_PoolAlloc(sizeof(float), ui_dynPool, 0);
00057 EXTRADATA(node).delta = Mem_PoolAlloc(sizeof(float), ui_dynPool, 0);
00058 EXTRADATA(node).max = Mem_PoolAlloc(sizeof(float), ui_dynPool, 0);
00059 EXTRADATA(node).min = Mem_PoolAlloc(sizeof(float), ui_dynPool, 0);
00060 }
00061
00062 static void UI_AbstractValueDelete (uiNode_t * node)
00063 {
00064 Mem_Free(EXTRADATA(node).value);
00065 Mem_Free(EXTRADATA(node).delta);
00066 Mem_Free(EXTRADATA(node).max);
00067 Mem_Free(EXTRADATA(node).min);
00068 EXTRADATA(node).value = NULL;
00069 EXTRADATA(node).delta = NULL;
00070 EXTRADATA(node).max = NULL;
00071 EXTRADATA(node).min = NULL;
00072 }
00073
00074 static void UI_CloneCvarOrFloat (const uiNode_t *source, uiNode_t *clone, const float*const* sourceData, float** cloneData)
00075 {
00076
00077 if (!strncmp(*(const char*const*)sourceData, "*cvar", 5)) {
00078
00079 assert(!source->dynamic);
00080 if (clone->dynamic)
00081 Mem_Free(*(char**)cloneData);
00082 *(const char**)cloneData = *(const char*const*)sourceData;
00083 } else {
00084
00085 if (!clone->dynamic)
00086 *cloneData = UI_AllocStaticFloat(1);
00087 **cloneData = **sourceData;
00088 }
00089 }
00090
00094 static void UI_AbstractValueClone (const uiNode_t *source, uiNode_t *clone)
00095 {
00096 localBehaviour->super->clone(source, clone);
00097 UI_CloneCvarOrFloat(source, clone, (const float*const*)&EXTRADATACONST(source).value, (float**)&EXTRADATA(clone).value);
00098 UI_CloneCvarOrFloat(source, clone, (const float*const*)&EXTRADATACONST(source).delta, (float**)&EXTRADATA(clone).delta);
00099 UI_CloneCvarOrFloat(source, clone, (const float*const*)&EXTRADATACONST(source).max, (float**)&EXTRADATA(clone).max);
00100 UI_CloneCvarOrFloat(source, clone, (const float*const*)&EXTRADATACONST(source).min, (float**)&EXTRADATA(clone).min);
00101 }
00102
00103 static const value_t properties[] = {
00104
00105 {"current", V_CVAR_OR_FLOAT, UI_EXTRADATA_OFFSETOF(abstractValueExtraData_t, value), 0},
00106
00107 {"delta", V_CVAR_OR_FLOAT, UI_EXTRADATA_OFFSETOF(abstractValueExtraData_t, delta), 0},
00108
00109 {"max", V_CVAR_OR_FLOAT, UI_EXTRADATA_OFFSETOF(abstractValueExtraData_t, max), 0},
00110
00111 {"min", V_CVAR_OR_FLOAT, UI_EXTRADATA_OFFSETOF(abstractValueExtraData_t, min), 0},
00112
00113
00114
00115
00116 {"lastdiff", V_FLOAT, UI_EXTRADATA_OFFSETOF(abstractValueExtraData_t, lastdiff), MEMBER_SIZEOF(abstractValueExtraData_t, lastdiff)},
00117 {NULL, V_NULL, 0, 0}
00118 };
00119
00120 void UI_RegisterAbstractValueNode (uiBehaviour_t *behaviour)
00121 {
00122 localBehaviour = behaviour;
00123 behaviour->name = "abstractvalue";
00124 behaviour->loaded = UI_AbstractValueLoaded;
00125 behaviour->clone = UI_AbstractValueClone;
00126 behaviour->new = UI_AbstractValueNew;
00127 behaviour->delete = UI_AbstractValueDelete;
00128 behaviour->isAbstract = qtrue;
00129 behaviour->properties = properties;
00130 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00131 }