stomped in changes done on nancy's dime

git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/personal/carm/dev-1.0@288 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
psperl
2007-08-02 02:25:45 +00:00
parent b3b88bb194
commit da16f06cbc
14 changed files with 151 additions and 135 deletions

View File

@ -17,7 +17,6 @@
#include "Func.hpp"
#include <cmath>
#include <cstdlib>
#include <cassert>
#include "projectM.hpp"
/* Wrappers for all the builtin functions
The arg_list pointer is a list of floats. Its
@ -118,13 +117,8 @@ static inline float below_wrapper(float * arg_list) {
return (arg_list[0] < arg_list[1]);
}
static float sin_wrapper(float * arg_list) {
assert(arg_list);
//return .5;
float d = sinf(*arg_list);
return d;
//return (sin (arg_list[0]));
static inline float sin_wrapper(float * arg_list) {
return (sin (arg_list[0]));
}

View File

@ -82,16 +82,16 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode);
inline void DWRITE( char *fmt, ... ) {
va_list args;
va_start( args, fmt );
//#ifdef DEBUG
#ifdef DEBUG
//#ifdef MACOS
// if ( debugFile != NULL ) {\
vprintf(fmt, args );
// fflush( debugFile );\
// } else {\
// printf( fmt, args );\
// }
//#endif
if ( debugFile != NULL ) {\
vfprintf( debugFile, fmt, args );\
fflush( debugFile );\
} else {\
vprintf( fmt, args );\
}
//#endif
#endif
va_end( args );
}

View File

@ -62,7 +62,8 @@ CustomWave::CustomWave(int _id):
scaling(1.0),
per_frame_eqn_string_index(0),
per_frame_init_eqn_string_index(0),
per_point_eqn_string_index(0)
per_point_eqn_string_index(0),
param_tree(new std::map<std::string, Param*>())
{
Param * param;

View File

@ -29,8 +29,7 @@
float GenExpr::eval_gen_expr(int mesh_i, int mesh_j) {
float l;
assert(item);
switch(this->type) {
switch(type) {
case VAL_T:
return ((ValExpr*)item)->eval_val_expr(mesh_i, mesh_j);
case PREFUN_T:
@ -51,29 +50,25 @@ float GenExpr::eval_gen_expr(int mesh_i, int mesh_j) {
/* Evaluates functions in prefix form */
float PrefunExpr::eval_prefun_expr(int mesh_i, int mesh_j) {
int i;
float rv;
assert(func_ptr);
/* This is slightly less than safe, since
who knows if the passed argument is valid. For
speed purposes we'll go with this */
float arg_list[this->num_args];
float *arg_list = (float *)wipemalloc( sizeof( float ) * num_args );
#ifdef EVAL_DEBUG_DOUBLE
DWRITE( "fn[");
#endif
//printf("numargs %d", num_args);
#endif
/* Evaluate each argument before calling the function itself */
for (int i = 0; i < num_args; i++) {
for (i = 0; i < num_args; i++) {
arg_list[i] = expr_list[i]->eval_gen_expr(mesh_i, mesh_j);
#ifdef EVAL_DEBUG_DOUBLE
if (i < (num_args - 1))
DWRITE( ", ");
#endif
//printf("numargs %x", arg_list[i]);
}
#ifdef EVAL_DEBUG_DOUBLE
@ -83,8 +78,10 @@ float PrefunExpr::eval_prefun_expr(int mesh_i, int mesh_j) {
/* Now we call the function, passing a list of
floats as its argument */
return (func_ptr)(arg_list);
rv = (func_ptr)(arg_list);
free( arg_list );
arg_list = NULL;
return rv;
}
@ -132,7 +129,6 @@ float ValExpr::eval_val_expr(int mesh_i, int mesh_j) {
return (((float*)term.param->matrix)[mesh_i]);
}
}
//assert(mesh_i >=0);
}
//std::cout << term.param->name << ": " << (*((float*)term.param->engine_val)) << std::endl;
return *((float*)(term.param->engine_val));
@ -329,8 +325,9 @@ TreeExpr *TreeExpr::new_tree_expr(InfixOp * infix_op, GenExpr * gen_expr, TreeEx
TreeExpr * tree_expr;
tree_expr = (TreeExpr*)wipemalloc(sizeof(TreeExpr));
assert(tree_expr);
if (tree_expr == NULL)
return NULL;
tree_expr->infix_op = infix_op;
tree_expr->gen_expr = gen_expr;
tree_expr->left = left;
@ -340,7 +337,7 @@ TreeExpr *TreeExpr::new_tree_expr(InfixOp * infix_op, GenExpr * gen_expr, TreeEx
/* Creates a new value expression */
ValExpr *ValExpr::new_val_expr(int _type, Term * _term) {
ValExpr *ValExpr::new_val_expr(int type, Term *term) {
ValExpr * val_expr;
val_expr = (ValExpr*)wipemalloc(sizeof(ValExpr));
@ -348,23 +345,23 @@ ValExpr *ValExpr::new_val_expr(int _type, Term * _term) {
if (val_expr == NULL)
return NULL;
val_expr->type = _type;
val_expr->term.constant = _term->constant;
val_expr->term.param = _term->param;
val_expr->type = type;
val_expr->term.constant = term->constant;
val_expr->term.param = term->param;
return val_expr;
}
/* Creates a new general expression */
GenExpr * GenExpr::new_gen_expr(int _type, void * _item) {
GenExpr * GenExpr::new_gen_expr(int type, void * item) {
GenExpr * gen_expr;
gen_expr = (GenExpr*)wipemalloc(sizeof(GenExpr));
if (gen_expr == NULL)
return NULL;
gen_expr->type = _type;
gen_expr->item = _item;
gen_expr->type = type;
gen_expr->item = item;
return gen_expr;
}

View File

@ -502,7 +502,7 @@ int Parser::parse_line(FILE * fs, Preset * preset) {
CustomWave * custom_wave;
/* Retrieve custom shape associated with this id */
if ((custom_wave = preset->find_custom_wave(last_custom_wave_id, TRUE)) == NULL)
if ((custom_wave = Preset::find_custom_object(last_custom_wave_id, true, *preset->customWaves)) == NULL)
return PROJECTM_FAILURE;
return parse_wave_per_frame_eqn(fs, custom_wave, preset);
@ -517,7 +517,7 @@ int Parser::parse_line(FILE * fs, Preset * preset) {
CustomShape * custom_shape;
/* Retrieve custom shape associated with this id */
if ((custom_shape = preset->find_custom_shape(last_custom_shape_id, TRUE)) == NULL)
if ((custom_shape = Preset::find_custom_object(last_custom_shape_id, true, *preset->customShapes)) == NULL)
return PROJECTM_FAILURE;
return parse_shape_per_frame_eqn(fs, custom_shape, preset);
@ -527,7 +527,7 @@ int Parser::parse_line(FILE * fs, Preset * preset) {
CustomShape * custom_shape;
/* Retrieve custom shape associated with this id */
if ((custom_shape = preset->find_custom_shape(last_custom_shape_id, TRUE)) == NULL)
if ((custom_shape = preset->find_custom_object(last_custom_shape_id, true, *preset->customShapes)) == NULL)
return PROJECTM_FAILURE;
return parse_shape_per_frame_init_eqn(fs, custom_shape, preset);
@ -1397,7 +1397,7 @@ int Parser::parse_wavecode(char * token, FILE * fs, Preset * preset) {
/* Retrieve custom wave information from preset. The 3rd argument
if true creates a custom wave if one does not exist */
if ((custom_wave = preset->find_custom_wave(id, TRUE)) == NULL) {
if ((custom_wave = Preset::find_custom_object(id, true, *preset->customWaves)) == NULL) {
//if (PARSE_DEBUG) printf("parse_wavecode: failed to load (or create) custom wave (id = %d)!\n", id);
return PROJECTM_FAILURE;
}
@ -1475,7 +1475,7 @@ int Parser::parse_shapecode(char * token, FILE * fs, Preset * preset) {
/* Retrieve custom shape information from preset. The 3rd argument
if true creates a custom shape if one does not exist */
if ((custom_shape = preset->find_custom_shape(id, TRUE)) == NULL) {
if ((custom_shape = Preset::find_custom_object(id, true, *preset->customShapes)) == NULL) {
//if (PARSE_DEBUG) printf("parse_shapecode: failed to load (or create) custom shape (id = %d)!\n", id);
return PROJECTM_FAILURE;
}
@ -1730,7 +1730,7 @@ int Parser::parse_wave_helper(FILE * fs, Preset * preset, int id, char * eqn_ty
InitCond * init_cond;
/* Retrieve custom wave associated with this id */
if ((custom_wave = preset->find_custom_wave(id, TRUE)) == NULL) {
if ((custom_wave = Preset::find_custom_object(id, true, *preset->customWaves)) == NULL) {
if (PARSE_DEBUG) printf("parse_wave_helper: custom wave id %d not found!\n", id);
return PROJECTM_FAILURE;
}
@ -1890,7 +1890,7 @@ int Parser::parse_shape(char * token, FILE * fs, Preset * preset) {
}
/* Retrieve custom shape associated with this id */
if ((custom_shape = preset->find_custom_shape(id, TRUE)) == NULL)
if ((custom_shape = Preset::find_custom_object(id,true,*preset->customShapes)) == NULL)
return PROJECTM_FAILURE;

View File

@ -30,7 +30,7 @@
#define _PARSER_H
//#define PARSE_DEBUG 2
#define PARSE_DEBUG 2
#define PARSE_DEBUG 0
#include <stdio.h>

View File

@ -51,6 +51,36 @@ void PerFrameEqn::evaluate() {
}
/*
void eval_per_frame_init_eqn(PerFrameEqn * per_frame_eqn) {
float val;
init_cond_t * init_cond;
if (per_frame_eqn == NULL)
return;
if (PER_FRAME_EQN_DEBUG) {
printf("per_frame_init: %s = ", per_frame_eqn->param->name);
fflush(stdout);
}
val = *((float*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr);
if (PER_FRAME_EQN_DEBUG) printf(" = %f\n", *((float*)per_frame_eqn->param->engine_val));
if (per_frame_eqn->param->flags & P_FLAG_QVAR) {
per_frame_eqn->param->init_val.float_val = val;
if ((init_cond = new_init_cond(per_frame_eqn->param)) == NULL)
return;
if ((list_append(init_cond_list, init_cond)) < 0) {
free_init_cond(init_cond);
return;
}
}
}
*/
/* Frees perframe equation structure. Warning: assumes gen_expr pointer is not freed by anyone else! */
PerFrameEqn::~PerFrameEqn() {
@ -62,4 +92,11 @@ PerFrameEqn::~PerFrameEqn() {
/* Create a new per frame equation */
PerFrameEqn::PerFrameEqn(int _index, Param * _param, GenExpr * _gen_expr) :
index(_index), param(_param), gen_expr(_gen_expr) {}
index(_index), param(_param), gen_expr(_gen_expr) {
/* Set per frame eqn name */
/// @bug why are we commented out?
// memset(per_frame_eqn->name, 0, MAX_TOKEN_SIZE);
//strncpy(per_frame_eqn->name, name, MAX_TOKEN_SIZE-1);
}

View File

@ -29,7 +29,7 @@
#ifndef _PER_FRAME_EQN_H
#define _PER_FRAME_EQN_H
#define PER_FRAME_EQN_DEBUG 0
#define PER_FRAME_EQN_DEBUG 1
class GenExpr;
class Param;
@ -44,9 +44,8 @@ public:
PerFrameEqn(int index, Param * param, GenExpr * gen_expr);
~PerFrameEqn();
/// Evaluate the per frame equation
void evaluate();
void eval_per_frame_init_eqn( PerFrameEqn *per_frame_eqn );
};

View File

@ -70,10 +70,10 @@ Preset::~Preset()
/// @note no need to clear the actual container itself
for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos)
delete(*pos);
delete(pos->second);
for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos)
delete(*pos);
delete(pos->second);
#if defined(PRESET_DEBUG) && defined(DEBUG)
@ -168,7 +168,7 @@ void Preset::evalCustomShapeInitConditions()
{
for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos)
(*pos)->eval_custom_shape_init_conds();
pos->second->eval_custom_shape_init_conds();
}
@ -176,7 +176,7 @@ void Preset::evalCustomWaveInitConditions()
{
for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos)
(*pos)->eval_custom_wave_init_conds();
pos->second->eval_custom_wave_init_conds();
}
@ -187,11 +187,11 @@ void Preset::evalCustomWavePerFrameEquations()
for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos)
{
std::map<std::string, InitCond*> & init_cond_tree = (*pos)->init_cond_tree;
std::map<std::string, InitCond*> & init_cond_tree = pos->second->init_cond_tree;
for (std::map<std::string, InitCond*>::iterator _pos = init_cond_tree.begin(); _pos != init_cond_tree.end(); ++_pos)
_pos->second->evaluate();
std::map<int, PerFrameEqn*> & per_frame_eqn_tree = (*pos)->per_frame_eqn_tree;
std::map<int, PerFrameEqn*> & per_frame_eqn_tree = pos->second->per_frame_eqn_tree;
for (std::map<int, PerFrameEqn*>::iterator _pos = per_frame_eqn_tree.begin(); _pos != per_frame_eqn_tree.end(); ++_pos)
_pos->second->evaluate();
}
@ -204,11 +204,11 @@ void Preset::evalCustomShapePerFrameEquations()
for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos)
{
std::map<std::string, InitCond*> & init_cond_tree = (*pos)->init_cond_tree;
std::map<std::string, InitCond*> & init_cond_tree = pos->second->init_cond_tree;
for (std::map<std::string, InitCond*>::iterator _pos = init_cond_tree.begin(); _pos != init_cond_tree.end(); ++_pos)
_pos->second->evaluate();
std::map<int, PerFrameEqn*> & per_frame_eqn_tree = (*pos)->per_frame_eqn_tree;
std::map<int, PerFrameEqn*> & per_frame_eqn_tree = pos->second->per_frame_eqn_tree;
for (std::map<int, PerFrameEqn*>::iterator _pos = per_frame_eqn_tree.begin(); _pos != per_frame_eqn_tree.end(); ++_pos)
_pos->second->evaluate();
}
@ -459,7 +459,7 @@ void Preset::load_custom_wave_init_conditions()
{
for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos)
(*pos)->load_unspecified_init_conds();
pos->second->load_unspecified_init_conds();
}
@ -469,7 +469,7 @@ void Preset::load_custom_shape_init_conditions()
// void eval_custom_shape_init_conds();
for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos)
(*pos)->load_custom_shape_init();
pos->second->load_custom_shape_init();
}
@ -499,7 +499,9 @@ void Preset::evalPerPixelEqns()
pos != per_pixel_eqn_tree.end(); ++pos)
pos->second->evaluate();
/* Set mesh i / j values to -1 so engine vars are used by default again */
this->mesh_i = -1;
this->mesh_j = -1;
}
/** Finds / Creates (if necessary) initial condition associated with passed parameter */
@ -643,65 +645,8 @@ void Preset::load_init_conditions()
CustomWave * Preset::find_custom_wave(int id, bool create_flag)
{
CustomWave * custom_wave = NULL;
assert(customWaves);
if ((custom_wave = (*customWaves)[id]) == NULL)
{
if (CUSTOM_WAVE_DEBUG) { printf("find_custom_wave: creating custom wave (id = %d)...", id);fflush(stdout);}
if (create_flag == FALSE)
{
if (CUSTOM_WAVE_DEBUG) printf("you specified not to (create flag = false), returning null\n");
return NULL;
}
if ((custom_wave = new CustomWave(id)) == NULL)
{
if (CUSTOM_WAVE_DEBUG) printf("failed...out of memory?\n");
return NULL;
}
customWaves->push_back(custom_wave);
}
return custom_wave;
}
CustomShape * Preset::find_custom_shape(int id, bool create_flag)
{
CustomShape * custom_shape = NULL;
assert(customShapes);
if ((custom_shape = (*customShapes)[id]) == NULL)
{
if (CUSTOM_SHAPE_DEBUG) { printf("find_custom_shape: creating custom shape (id = %d)...", id);fflush(stdout);}
if (create_flag == FALSE)
{
if (CUSTOM_SHAPE_DEBUG) printf("you specified not to (create flag = false), returning null\n");
return NULL;
}
if ((custom_shape = new CustomShape(id)) == NULL)
{
if (CUSTOM_SHAPE_DEBUG) printf("failed...out of memory?\n");
return NULL;
}
customShapes->push_back(custom_shape);
}
return custom_shape;
}
/* Find a parameter given its name, will create one if not found */
Param * Preset::find(char * name, int flags)

View File

@ -31,6 +31,8 @@
#include "Common.hpp"
#include <string>
#include <cassert>
#define PRESET_DEBUG 2 /* 0 for no debugging, 1 for normal, 2 for insane */
#include "CustomShape.hpp"
@ -42,14 +44,14 @@
#include "PresetFrameIO.hpp"
#include <map>
#include "InitCond.hpp"
#include <vector>
class CustomWave;
class CustomShape;
class InitCond;
//#include <map>
class Preset {
@ -71,10 +73,11 @@ public:
std::string name;
std::string file_path;
int mesh_i,mesh_j;
void load_init_conditions();
CustomShape * find_custom_shape(int id, bool create_flag);
CustomWave * find_custom_wave(int id, bool create_flag);
template <class CustomObject>
static CustomObject * find_custom_object(int id, bool create_flag, std::map<int,CustomObject*> & customObjects);
int per_pixel_eqn_string_index;
int per_frame_eqn_string_index;
@ -90,12 +93,14 @@ public:
/* Data structures that contain equation and initial condition information */
std::map<int, PerFrameEqn*> per_frame_eqn_tree; /* per frame equations */
std::map<int, PerPixelEqn*> per_pixel_eqn_tree; /* per pixel equation tree */
GenExpr * per_pixel_eqn_array[NUM_OPS]; /* per pixel equation array */
std::map<std::string,InitCond*> per_frame_init_eqn_tree; /* per frame initial equations */
std::map<std::string,InitCond*> init_cond_tree; /* initial conditions */
std::map<std::string,Param*> user_param_tree; /* user parameter splay tree */
int add_per_pixel_eqn( char *name, GenExpr *gen_expr );
int isPerPixelEqn( int op );
int resetPerPixelEqns();
int resetPerPixelEqnFlags();
@ -123,6 +128,9 @@ public:
int destroy();
void load_init_cond(char *name, int flags);
PresetOutputs::cwave_container * customWaves;
PresetOutputs::cshape_container * customShapes;
private:
void evalCustomWavePerFrameEquations();
@ -133,9 +141,42 @@ private:
void evalPerPixelEqns();
void evalPerFrameEquations();
PresetOutputs::cwave_container * customWaves;
PresetOutputs::cshape_container * customShapes;
PresetOutputs & m_presetOutputs;
};
template <class CustomObject>
CustomObject * Preset::find_custom_object(int id, bool create_flag, std::map<int, CustomObject*> & customObjects)
{
CustomObject * custom_object = NULL;
typename std::map<int, CustomObject*>::iterator pos = customObjects.find(id);
if (pos == customObjects.end())
{
if (create_flag == FALSE)
{
return NULL;
}
if ((custom_object = new CustomObject(id)) == NULL)
{
return NULL;
}
std::pair<typename std::map<int,CustomObject*>::iterator, bool> inserteePair =
customObjects.insert(std::make_pair(custom_object->id, custom_object));
assert(inserteePair.second);
custom_object = inserteePair.first->second;
} else
custom_object = pos->second;
assert(custom_object);
return custom_object;
}
#endif /** !_PRESET_HPP */

View File

@ -184,6 +184,7 @@ void PresetInputs::ResetMesh()
int x,y;
assert(x_mesh);
assert(y_mesh);
assert(rad_mesh);
assert(theta_mesh);

View File

@ -1,6 +1,6 @@
#ifndef PRESET_FRAME_IO_HPP
#define PRESET_FRAME_IO_HPP
#include <vector>
#include <map>
class CustomWave;
class CustomShape;
@ -11,8 +11,8 @@ class CustomShape;
* members for Mr. Sperl's convenience */
class PresetOutputs {
public:
typedef std::vector<CustomWave*> cwave_container;
typedef std::vector<CustomShape*> cshape_container;
typedef std::map<int, CustomWave*> cwave_container;
typedef std::map<int, CustomShape*> cshape_container;
cwave_container customWaves;
cshape_container customShapes;
@ -168,7 +168,10 @@ public:
/* variables were added in milkdrop 1.04 */
int gx,gy;
/// @bug are these in use?
/// @bugfix YES, presets reference meshx and meshy
int meshx;
int meshy;
float **x_mesh;
float **y_mesh;
float **rad_mesh;

View File

@ -1495,8 +1495,7 @@ void Renderer::draw_preset() {
title_font->FaceSize((unsigned)(12*(this->vh/512.0)));
if(this->noSwitch) title_font->Render("[LOCKED] " );
title_font->FaceSize((unsigned)(20*(this->vh/512.0)));
if (this->presetName)
title_font->Render(this->presetName );
title_font->Render(this->presetName );

View File

@ -105,9 +105,8 @@ DLLEXPORT void projectM::renderFrame() {
// printf("start:%d at:%d min:%d stop:%d on:%d %d\n",startframe, frame frame-startframe,avgtime, noSwitch,progress);
presetInputs.ResetMesh();
// assert(m_activePreset.get());
assert(m_activePreset.get());
m_activePreset->evaluateFrame();