1.1 --- a/core/smn_keyvalues.cpp Fri Nov 30 15:50:32 2007 +0000
1.2 +++ b/core/smn_keyvalues.cpp Sat Dec 01 00:37:47 2007 +0000
1.3 @@ -218,6 +218,35 @@
1.4 return 1;
1.5 }
1.6
1.7 +static cell_t smn_KvSetVector(IPluginContext *pCtx, const cell_t *params)
1.8 +{
1.9 + Handle_t hndl = static_cast<Handle_t>(params[1]);
1.10 + HandleError herr;
1.11 + HandleSecurity sec;
1.12 + KeyValueStack *pStk;
1.13 +
1.14 + sec.pOwner = NULL;
1.15 + sec.pIdentity = g_pCoreIdent;
1.16 +
1.17 + if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
1.18 + != HandleError_None)
1.19 + {
1.20 + return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
1.21 + }
1.22 +
1.23 + char *key;
1.24 + char buffer[64];
1.25 + cell_t *vector;
1.26 + pCtx->LocalToStringNULL(params[2], &key);
1.27 + pCtx->LocalToPhysAddr(params[3], &vector);
1.28 +
1.29 + UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(vector[0]), sp_ctof(vector[1]), sp_ctof(vector[2]));
1.30 +
1.31 + pStk->pCurRoot.front()->SetString(key, buffer);
1.32 +
1.33 + return 1;
1.34 +}
1.35 +
1.36 static cell_t smn_KvGetString(IPluginContext *pCtx, const cell_t *params)
1.37 {
1.38 Handle_t hndl = static_cast<Handle_t>(params[1]);
1.39 @@ -358,6 +387,79 @@
1.40 return 1;
1.41 }
1.42
1.43 +static cell_t smn_KvGetVector(IPluginContext *pCtx, const cell_t *params)
1.44 +{
1.45 + Handle_t hndl = static_cast<Handle_t>(params[1]);
1.46 + HandleError herr;
1.47 + HandleSecurity sec;
1.48 + KeyValueStack *pStk;
1.49 +
1.50 + sec.pOwner = NULL;
1.51 + sec.pIdentity = g_pCoreIdent;
1.52 +
1.53 + if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
1.54 + != HandleError_None)
1.55 + {
1.56 + return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
1.57 + }
1.58 +
1.59 + char *key;
1.60 + const char *value;
1.61 + cell_t *defvector, *outvector;
1.62 + char buffer[64];
1.63 + pCtx->LocalToStringNULL(params[2], &key);
1.64 + pCtx->LocalToPhysAddr(params[3], &outvector);
1.65 + pCtx->LocalToPhysAddr(params[4], &defvector);
1.66 +
1.67 + UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(defvector[0]), sp_ctof(defvector[1]), sp_ctof(defvector[2]));
1.68 +
1.69 + value = pStk->pCurRoot.front()->GetString(key, buffer);
1.70 +
1.71 + float out;
1.72 + int components = 0;
1.73 + while (*value && components < 3)
1.74 + {
1.75 + while ((*value) && (*value == ' '))
1.76 + {
1.77 + value++;
1.78 + }
1.79 +
1.80 + out = 0.0f;
1.81 + bool isnegative;
1.82 + if (*value == '-')
1.83 + {
1.84 + isnegative = true;
1.85 + value++;
1.86 + }
1.87 + else
1.88 + {
1.89 + isnegative = false;
1.90 + }
1.91 +
1.92 + for (; *value && isdigit(*value); ++value)
1.93 + {
1.94 + out *= 10.0f;
1.95 + out += *value - '0';
1.96 + }
1.97 +
1.98 + if (*value == '.')
1.99 + {
1.100 + value++;
1.101 + float factor = 0.1f;
1.102 + for (; *value && isdigit(*value); ++value)
1.103 + {
1.104 + out += (*value - '0') * factor;
1.105 + factor *= 0.1f;
1.106 + }
1.107 + }
1.108 +
1.109 + out = (isnegative) ? -out : out;
1.110 + outvector[components++] = sp_ftoc(out);
1.111 + }
1.112 +
1.113 + return 1;
1.114 +}
1.115 +
1.116 static cell_t smn_CreateKeyValues(IPluginContext *pCtx, const cell_t *params)
1.117 {
1.118 KeyValueStack *pStk;
1.119 @@ -1015,5 +1117,7 @@
1.120 {"KvFindKeyById", smn_FindKeyById},
1.121 {"KvGetNameSymbol", smn_GetNameSymbol},
1.122 {"KvGetSectionSymbol", smn_KvGetSectionSymbol},
1.123 + {"KvGetVector", smn_KvGetVector},
1.124 + {"KvSetVector", smn_KvSetVector},
1.125 {NULL, NULL}
1.126 };