- init cond stuff refactored properly

- hit a wall in splaytree compilation, involving symbolic types


git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/personal/carm/dev-1.0@220 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
w1z7ard
2007-06-24 04:49:28 +00:00
parent d03e24e347
commit 8dcfbceafd
9 changed files with 94 additions and 169 deletions

View File

@ -127,7 +127,7 @@ int BuiltinFuncs::init_builtin_func_db() {
int retval;
builtin_func_tree =
SplayTree::create_splaytree((int (*)(void*,void*))compare_string, (void*(*)(void*))copy_string, (void(*)(void*))free_string);
SplayTree<Func>::create_splaytree((int (*)(void*,void*))SplayKeyFunctions::compare_string, (void*(*)(void*))SplayKeyFunctions::copy_string, (void(*)(void*))SplayKeyFunctions::free_string);
if (builtin_func_tree == NULL)
return PROJECTM_OUTOFMEM_ERROR;

View File

@ -82,7 +82,8 @@ int BuiltinParams::load_builtin_param_float(char * name, void * engine_val, void
Generally, do this on projectm exit */
int BuiltinParams::destroy_builtin_param_db() {
builtin_param_tree->splay_traverse((void (*)(void*))delete);
builtin_param_tree->traverse
<SplayTreeFunctors::Delete<Param> >();
delete builtin_param_tree;
builtin_param_tree = NULL;
return PROJECTM_SUCCESS;
@ -184,7 +185,7 @@ int BuiltinParams::insert_builtin_param( Param *param ) {
int BuiltinParams::init_builtin_param_db(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) {
/* Create the builtin parameter splay tree (go Sleator...) */
if ((this->builtin_param_tree = SplayTree::create_splaytree((int (*)(void*,void*))compare_string,(void* (*)(void*)) copy_string, (void (*)(void*))free_string)) == NULL) {
if ((this->builtin_param_tree = SplayTree<Param>::create_splaytree((int (*)(void*,void*))SplayKeyFunctions::compare_string,(void* (*)(void*)) SplayKeyFunctions::copy_string, (void (*)(void*))SplayKeyFunctions::free_string)) == NULL) {
if (BUILTIN_PARAMS_DEBUG) printf("init_builtin_param_db: failed to initialize database (FATAL)\n");
return PROJECTM_OUTOFMEM_ERROR;
}

View File

@ -35,6 +35,7 @@
#include "Preset.hpp"
#include "SplayTree.hpp"
#include "ParamUtils.hpp"
#include "InitCondUtils.hpp"
#include "wipemalloc.h"
@ -199,20 +200,18 @@ CustomShape::~CustomShape() {
return;
abort();
per_frame_eqn_tree->traverse<SplayTreeFunctors::Delete<PerFrameEqn>();
init_cond_tree->trave
param_tree;
per_frame_init_eqn_tree;
per_frame_eqn_tree->traverse<SplayTreeFunctors::Delete<PerFrameEqn> >();
init_cond_tree->traverse<SplayTreeFunctors::Delete<InitCond> >();
param_tree->traverse<SplayTreeFunctors::Delete<Param> > ();
per_frame_init_eqn_tree->traverse<SplayTreeFunctors::Delete<InitCond> > ();
return;
}
void CustomShape::load_custom_shape_init() {
load_unspecified_init_conds_shape();
}
}
void CustomShape::eval_custom_shape_init_conds() {
per_frame_init_eqn_tree->splay_traverse((void (*)(void*))eval_init_cond_helper );
@ -220,91 +219,8 @@ void CustomShape::eval_custom_shape_init_conds() {
void CustomShape::load_unspecified_init_conds_shape() {
param_tree->splay_traverse((void (*)(void*))load_unspec_init_cond_shape_helper);
}
Param * CustomShape::findParam(char * name, bool create_flag) {
assert(name);
Param * param = NULL;
/* First look in the builtin database */
param = (Param *)splay_find(name);
if (((param = (Param *)param_tree->splay_find(name)) == NULL) && (create_flag == TRUE)) {
/* Check if string is valid */
if (!param->is_valid_param_string(name))
return NULL;
/* Now, create the user defined parameter given the passed name */
if ((param = Param::create_user_param(name)) == NULL)
return NULL;
/* Finally, insert the new parameter into this preset's proper splaytree */
if (splay_insert(param, param->name) < 0) {
delete param;
return NULL;
}
}
/* Return the found (or created) parameter. Note that this could be null */
return param;
InitCondUtils::LoadUnspecInitCond fun(*this->init_cond_tree, *this->per_frame_init_eqn_tree);
}
/// @bug BROKEN: FIX ME (carm)
void CustomShape::load_unspec_init_cond_shape() {
abort();
#if 0
InitCond * init_cond;
CValue init_val;
/* Don't count read only parameters as initial conditions */
if (flags & P_FLAG_READONLY)
return;
if (flags & P_FLAG_QVAR)
return;
if (flags & P_FLAG_TVAR)
return;
if (flags & P_FLAG_USERDEF)
return;
/* If initial condition was not defined by the preset file, force a default one
with the following code */
if ((init_cond =(InitCond*)CustomShape::interface_shape->init_cond_tree->splay_find(name)) == NULL) {
/* Make sure initial condition does not exist in the set of per frame initial equations */
if ((init_cond = (InitCond*)CustomShape::interface_shape->per_frame_init_eqn_tree->splay_find(name)) != NULL)
return;
if (type == P_TYPE_BOOL)
init_val.bool_val = 0;
else if (type == P_TYPE_INT)
init_val.int_val = *(int*)engine_val;
else if (type == P_TYPE_DOUBLE)
init_val.float_val = *(float*)engine_val;
//printf("%s\n", param->name);
/* Create new initial condition */
if ((init_cond = new InitCond(this, init_val)) == NULL)
return;
/* Insert the initial condition into this presets tree */
if (CustomShape::interface_shape->init_cond_tree->splay_insert(init_cond, init_cond->param->name) < 0) {
delete init_cond;
return;
}
}
#endif
param_tree->traverse(fun);
}

View File

@ -38,6 +38,7 @@
#include "Preset.hpp"
#include "SplayTree.hpp"
#include "ParamUtils.hpp"
#include "InitCondUtils.hpp"
#include "wipemalloc.h"
#define MAX_SAMPLE_SIZE 4096
@ -550,59 +551,11 @@ void CustomWave::evalPerPointEqns() {
void CustomWave::load_unspecified_init_conds() {
LoadUnspecInitCond fun(*this);
InitCondUtils::LoadUnspecInitCond fun(*this->init_cond_tree, *this->per_frame_init_eqn_tree);
param_tree->traverse(fun);
}
CustomWave::LoadUnspecInitCond::LoadUnspecInitCond(CustomWave & customWave):m_customWave(customWave) {}
void CustomWave::LoadUnspecInitCond::operator() (Param * param) {
InitCond * init_cond;
CValue init_val;
/* Don't count these parameters as initial conditions */
if (param->flags & P_FLAG_READONLY)
return;
if (param->flags & P_FLAG_QVAR)
return;
if (param->flags & P_FLAG_TVAR)
return;
if (param->flags & P_FLAG_USERDEF)
return;
/* If initial condition was not defined by the preset file, force a default one
with the following code */
if ((init_cond = (InitCond*)m_customWave.init_cond_tree->splay_find(param->name)) == NULL) {
/* Make sure initial condition does not exist in the set of per frame initial equations */
if ((init_cond = (InitCond*)m_customWave.per_frame_init_eqn_tree->splay_find(param->name)) != NULL)
return;
if (param->type == P_TYPE_BOOL)
init_val.bool_val = 0;
else if (param->type == P_TYPE_INT)
init_val.int_val = *(int*)param->engine_val;
else if (param->type == P_TYPE_DOUBLE)
init_val.float_val = *(float*)param->engine_val;
//printf("%s\n", param->name);
/* Create new initial condition */
if ((init_cond = new InitCond(param, init_val)) == NULL)
return;
/* Insert the initial condition into this presets tree */
if (m_customWave.init_cond_tree->splay_insert(init_cond, init_cond->param->name) < 0) {
delete init_cond;
return;
}
}
}

View File

@ -61,10 +61,6 @@ public:
/** Destructor is necessary so we can free the per point matrices **/
~CustomWave();
/** Search for parameter 'name' in 'database', if create_flag is true, then generate the parameter
and insert it into 'database' */
Param * findParam(char * name, bool create_flag);
/* Numerical id */
int id;
int per_frame_count;
@ -131,7 +127,7 @@ public:
/* Per point equation array */
GenExpr * per_point_eqn_array[NUM_POINT_OPS];
void reset_per_point_eqn_array(CustomWave *custom_wave );
void reset_per_point_eqn_array(CustomWave *custom_wave);
int add_per_point_eqn(char * name, GenExpr * gen_expr);
void evalCustomWaveInitConditions(Preset *preset);
@ -148,17 +144,8 @@ public:
void destroy_init_cond_tree(SplayTree<InitCond> * tree);
void evalPerPointEqn(PerPointEqn * per_point_eqn);
class LoadUnspecInitCond {
public:
LoadUnspecInitCond(CustomWave & customWave) ;
void operator()(Param * param);
private:
CustomWave & m_customWave;
};
};
/** Splaytree traversal helpers */
inline void free_custom_wave_helper( void *custom_wave ) {

View File

@ -0,0 +1,68 @@
#ifndef _INIT_COND_UTILS_HPP
#define _INIT_COND_UTILS_HPP
#include "SplayTree.hpp"
#include "InitCond.h"
namespace InitCondUtils {
class LoadUnspecInitCond {
public:
LoadUnspecInitCond(SplayTree<InitCond> & initCondTree, SplayTree<InitCond> & perFrameInitEqnTree):
m_initCondTree(initCondTree), m_perFrameInitEqnTree(perFrameInitEqnTree) {}
void operator()(Param * param);
private:
SplayTree<InitCond> & m_initCondTree;
SplayTree<InitCond> & m_perFrameInitEqnTree;
};
inline void LoadUnspecInitCond::operator() (Param * param) {
InitCond * init_cond;
CValue init_val;
/* Don't count these parameters as initial conditions */
if (param->flags & P_FLAG_READONLY)
return;
if (param->flags & P_FLAG_QVAR)
return;
if (param->flags & P_FLAG_TVAR)
return;
if (param->flags & P_FLAG_USERDEF)
return;
/* If initial condition was not defined by the preset file, force a default one
with the following code */
if ((init_cond = m_initCondTree.splay_find(param->name)) == NULL) {
/* Make sure initial condition does not exist in the set of per frame initial equations */
if ((init_cond = m_perFrameInitEqnTree.splay_find(param->name)) != NULL)
return;
if (param->type == P_TYPE_BOOL)
init_val.bool_val = 0;
else if (param->type == P_TYPE_INT)
init_val.int_val = *(int*)param->engine_val;
else if (param->type == P_TYPE_DOUBLE)
init_val.float_val = *(float*)param->engine_val;
//printf("%s\n", param->name);
/* Create new initial condition */
if ((init_cond = new InitCond(param, init_val)) == NULL)
return;
/* Insert the initial condition into this presets tree */
if (m_initCondTree.splay_insert(init_cond, init_cond->param->name) < 0) {
delete init_cond;
return;
}
}
}
}
#endif

View File

@ -20,6 +20,7 @@ public:
}
static const int AUTO_CREATE = 1;
static const int NO_CREATE = 0;
template <int FLAGS>
static Param * find(char * name, SplayTree<Param> * paramTree) {

View File

@ -758,18 +758,17 @@ GenExpr * Parser::parse_gen_expr ( FILE * fs, TreeExpr * tree_expr, Preset * pre
/* CASE 5: custom wave variable */
if (current_wave != NULL) {
if ((param = current_wave->findParam(string, FALSE)) == NULL) {
if ((param = ParamUtils::find<ParamUtils::NO_CREATE>(string, current_wave->param_tree)) == NULL) {
if ((param = preset->builtinParams.find_builtin_param(string)) == NULL)
if ((param = current_wave->findParam(string, TRUE)) == NULL) {
if ((param = ParamUtils::find<ParamUtils::AUTO_CREATE>(string, current_wave->param_tree)) == NULL) {
delete tree_expr;
return NULL;
}
}
if (PARSE_DEBUG) {
DWRITE("parse_gen_expr: custom wave parameter (name = %s)... \n", param->name);
}
/* Convert parameter to an expression */
@ -782,12 +781,12 @@ GenExpr * Parser::parse_gen_expr ( FILE * fs, TreeExpr * tree_expr, Preset * pre
/* Parse the rest of the line */
return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
}
/* CASE 6: regular parameter. Will be created if necessary and the string has no invalid characters */
if ((param = Param::find_param(string, preset, P_CREATE)) != NULL) {
if (PARSE_DEBUG) {
DWRITE("parse_gen_expr: parameter (name = %s)...\n", param->name);

View File

@ -53,7 +53,7 @@ public:
static SplayTree<Data> *create_splaytree(int (*compare)(void*,void*), void * (*copy_key)(void*), void (*free_key)(void*));
~SplayTree();
void *splay_find(void * key);
Data *splay_find(void * key);
int splay_insert(Data * data, void * key);
int splay_insert_node( SplayNode<Data> *node );
int splay_insert_link(void * alias_key, void * orig_key);
@ -119,7 +119,7 @@ SplayTree<Data> * SplayTree<Data>::create_splaytree(int (*compare)(void *,void*)
splaytree->compare = compare;
splaytree->copy_key = copy_key;
splaytree->free_key = free_key;
/* Return instantiated splay tree */
return splaytree;
}
@ -235,7 +235,7 @@ void SplayTree<Data>::traverseRec (Fun & fun, SplayNode<Data> * splaynode) {
}
/* Find the node corresponding to the given key in splaytree, return its data pointer */
template <class Data>
void * SplayTree<Data>::splay_find(void * key) {
Data * SplayTree<Data>::splay_find(void * key) {
SplayNode<Data> * splaynode;
int match_type;
@ -427,7 +427,7 @@ int SplayTree<Data>::splay_insert_link(void * alias_key, void * orig_key) {
return SPLAYTREE_FAILURE;
/* Create a new splay node of symbolic link type */
if ((splaynode = new SplayNode<Data>(SYMBOLIC_NODE_TYPE, (key_clone = copy_key(alias_key)), data_node, this)) == NULL) {
if ((splaynode = new SplayNode<SplayNode<Data> >(SYMBOLIC_NODE_TYPE, (key_clone = copy_key(alias_key)), data_node, free_key)) == NULL) {
free_key(key_clone);
return PROJECTM_OUTOFMEM_ERROR;
}