From 7bb640207ce8a2be6c61e50e4ad2cafde34d5255 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Mon, 2 Jul 2007 16:31:39 +0000 Subject: [PATCH] - added preset loader to build list. it builds but still incomplete - preset class extended to handle partial initialization - preset switcher is #ifdef zeroed git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/personal/carm/dev-1.0@229 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/CMakeLists.txt | 2 +- src/projectM-engine/Preset.cpp | 34 +++++++++++++++++------ src/projectM-engine/Preset.hpp | 11 ++++++-- src/projectM-engine/PresetLoader.cpp | 28 +++++++++++-------- src/projectM-engine/PresetLoader.hpp | 32 ++++++++------------- src/projectM-engine/PresetSwitcher.cpp | 3 ++ src/projectM-engine/common.h | 2 -- src/projectM-engine/console_interface.cpp | 12 ++++---- 8 files changed, 73 insertions(+), 51 deletions(-) diff --git a/src/projectM-engine/CMakeLists.txt b/src/projectM-engine/CMakeLists.txt index 77555ae8c..2e74f3f8c 100644 --- a/src/projectM-engine/CMakeLists.txt +++ b/src/projectM-engine/CMakeLists.txt @@ -6,7 +6,7 @@ Func.h Func.cpp Eval.cpp wipemalloc.h browser.cpp PerFrameEqn.cpp PerPointEqn.cp CValue.h Expr.h timer.cpp wipemalloc.cpp PerFrameEqn.h PerPixelEqn.h PerPointEqn.h browser.h BuiltinFuncs.hpp BuiltinFuncs.cpp compare.h editor.h event.h fatal.h SplayTree.hpp fftsg.h glConsole.h menu.h timer.h SplayNode.hpp BuiltinParams.hpp BuiltinParams.cpp Preset.hpp PresetSwitcher.hpp PresetSwitcher.cpp Renderer.cpp Renderer.hpp -ParamUtils.hpp) +ParamUtils.hpp PresetLoader.cpp PresetLoader.hpp) OPTION(USE_FTGL "Use FTGL for on-screen fonts" ON) diff --git a/src/projectM-engine/Preset.cpp b/src/projectM-engine/Preset.cpp index 82a37c2a7..8cb724ffa 100755 --- a/src/projectM-engine/Preset.cpp +++ b/src/projectM-engine/Preset.cpp @@ -35,16 +35,30 @@ + +Preset::Preset(const std::string & filename): + file_path(filename), + customWaves(0), + customShapes(0) {} + Preset::Preset(const PresetInputs * presetInputs, PresetOutputs * presetOutputs, const std::string & filename): + file_path(filename), builtinParams(*presetInputs, *presetOutputs), - customWaves(presetOutputs->customWaves), - customShapes(presetOutputs->customShapes) + customWaves(&presetOutputs->customWaves), + customShapes(&presetOutputs->customShapes) { initialize(filename); } +/// @bug is memory properly deallocated? verify +void Preset::setIO(const PresetInputs * presetInputs, PresetOutputs * presetOutputs) { + builtinParams = BuiltinParams(*presetInputs, *presetOutputs); + customWaves = &presetOutputs->customWaves; + customShapes = &presetOutputs->customShapes; + initialize(file_path); +} Preset::~Preset() { @@ -93,7 +107,7 @@ void Preset::evalCustomWaveInitConditions() { void Preset::evalCustomWavePerFrameEquations() { - for (cwave_container::iterator pos = customWaves.begin(); pos != customWaves.end(); ++pos) { + for (cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) { (*pos)->init_cond_tree->splay_traverse((void (*)(void*))eval_init_cond_helper); (*pos)->per_frame_eqn_tree->splay_traverse((void (*)(void*))eval_per_frame_eqn_helper); } @@ -102,7 +116,7 @@ void Preset::evalCustomWavePerFrameEquations() { void Preset::evalCustomShapePerFrameEquations() { - for (cshape_container::iterator pos = customShapes.begin(); pos != customShapes.end(); ++pos) { + for (cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) { (*pos)->init_cond_tree->splay_traverse((void (*)(void*))eval_init_cond_helper); (*pos)->per_frame_eqn_tree->splay_traverse((void (*)(void*))eval_per_frame_eqn_helper); } @@ -685,7 +699,9 @@ void Preset::load_init_conditions() { CustomWave * Preset::find_custom_wave(int id, bool create_flag) { CustomWave * custom_wave = NULL; - if ((custom_wave = customWaves[id]) == 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);} @@ -699,7 +715,7 @@ CustomWave * Preset::find_custom_wave(int id, bool create_flag) { return NULL; } - customWaves.push_back(custom_wave); + customWaves->push_back(custom_wave); } return custom_wave; @@ -710,8 +726,8 @@ CustomWave * Preset::find_custom_wave(int id, bool create_flag) { CustomShape * Preset::find_custom_shape(int id, bool create_flag) { CustomShape * custom_shape = NULL; - - if ((custom_shape = (CustomShape*)this->customShapes[id]) == 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);} @@ -725,7 +741,7 @@ CustomShape * Preset::find_custom_shape(int id, bool create_flag) { return NULL; } - customShapes.push_back(custom_shape); + customShapes->push_back(custom_shape); } diff --git a/src/projectM-engine/Preset.hpp b/src/projectM-engine/Preset.hpp index 9d39f13d7..5129b2493 100644 --- a/src/projectM-engine/Preset.hpp +++ b/src/projectM-engine/Preset.hpp @@ -64,8 +64,15 @@ public: * Most common way to allocate new preset */ Preset(const PresetInputs * presetInputs, PresetOutputs * presetOutputs, const std::string & filename); + /** Initializes a preset object and stores the filename associated with it. The preset is NOT properly initialize + * until a call to member function setIO is made */ + Preset(const std::string & filename); + ~Preset(); + /** Set or reset the input and output associations for this preset. */ + void setIO(const PresetInputs * presetInputs, PresetOutputs * presetOutputs); + /** Evaluates the preset for a frame given the current values of preset inputs / outputs */ void evaluateFrame(); @@ -148,8 +155,8 @@ private: void evalPerPixelEqns(); void evalPerFrameEquations(); - cwave_container & customWaves; - cshape_container & customShapes; + cwave_container * customWaves; + cshape_container * customShapes; }; diff --git a/src/projectM-engine/PresetLoader.cpp b/src/projectM-engine/PresetLoader.cpp index 07373c3e9..0426d5de0 100644 --- a/src/projectM-engine/PresetLoader.cpp +++ b/src/projectM-engine/PresetLoader.cpp @@ -11,27 +11,34 @@ // #include "PresetLoader.hpp" #include - +#include extern "C" { #include -#include -#include - +#include } -PresetLoader::PresetLoader(std::string pathame) { +PresetLoader::PresetLoader(std::string dirname) :m_dirname(dirname) +{ + // Do one scan + rescan(); } +void PresetLoader::setScanDirectory(std::string dirname) { + m_dirname = dirname; +} void PresetLoader::rescan() { +// Clear the directory entry collection +m_entries.clear(); + // If directory already opened, close it first if (m_dir) { - closedir(dir); + closedir(m_dir); } // Allocate a new a stream given the current diectory name -if ((m_dir = opendir(m_dirname)) == NULL) { +if ((m_dir = opendir(m_dirname.c_str())) == NULL) { handleDirectoryError(); } @@ -50,14 +57,13 @@ while ((dir_entry = readdir(m_dir)) != NULL) { continue; // Create full path name - out << dirname << PATH_SEPARATOR << filename; + out << m_dirname << PATH_SEPARATOR << filename; - // Save to our directory entry collcetion - m_entries.add(out.str()); + // Add to our directory entry collection + m_entries.push_back(out.str()); // We can now toss out the directory entry struct free(dir_entry); - } } diff --git a/src/projectM-engine/PresetLoader.hpp b/src/projectM-engine/PresetLoader.hpp index cafd9a064..503629519 100644 --- a/src/projectM-engine/PresetLoader.hpp +++ b/src/projectM-engine/PresetLoader.hpp @@ -1,33 +1,25 @@ #ifndef __PRESET_LOADER_HPP #define __PRESET_LOADER_HPP +#include #include "Preset.hpp" -#ifdef LINUX -extern "C" { - #include -} -#endif - -#include "StaticArray.hpp" class PresetLoader { - - public: - static const std::string PROJECTM_FILE_EXTENSION = ".prjm"; - static const std::string MILKDROP_FILE_EXTENSION = ".milk"; + static const std::string PROJECTM_FILE_EXTENSION; + static const std::string MILKDROP_FILE_EXTENSION; #ifdef LINUX - static const std::string PATH_SEPARTOR = "/"; + static const char PATH_SEPARTOR = '/'; #endif #ifdef MACOS - static const std::string PATH_SEPARTOR = "/"; + static const char PATH_SEPARTOR = '/'; #endif #ifdef WIN32 - static const std::string PATH_SEPARTOR = "\"; + static const char PATH_SEPARATOR = '\'; #endif @@ -39,8 +31,8 @@ class PresetLoader { /** Load a preset by indexing the collection of presets from a directory */ /** Autopointers: when you take it, I leave it */ - auto_ptr loadPreset(unsigned int index); - auto_ptr loadPreset(std::string filename); +// auto_ptr loadPreset(unsigned int index, const PresetInputs & presetInputs, PresetOutputs & presetOutputs); +// auto_ptr loadPreset(std::string filename); /** Returns the number of presets in the active directory */ inline std::size_t getNumPresets() { @@ -48,18 +40,18 @@ class PresetLoader { } /** Sets the directory where the loader will search for files */ - void setScanDirectory(std::string pathname); + void setScanDirectory(std::string pathname); /** Rescans the active preset directory */ void rescan(); private: - const std::string m_dirname; - int m_activeIndex; + void handleDirectoryError(); + std::string m_dirname; DIR * m_dir; std::vector m_entries; }; -#endif \ No newline at end of file +#endif diff --git a/src/projectM-engine/PresetSwitcher.cpp b/src/projectM-engine/PresetSwitcher.cpp index d06e6842b..3203f8359 100644 --- a/src/projectM-engine/PresetSwitcher.cpp +++ b/src/projectM-engine/PresetSwitcher.cpp @@ -10,6 +10,8 @@ // // +#if 0 + #include "PresetSwitcher.hpp" int PresetSwitcher::destroyPresetLoader() { @@ -394,3 +396,4 @@ int PresetSwitcher::is_valid_extension(const struct dirent* ent) { return FALSE; } +#endif \ No newline at end of file diff --git a/src/projectM-engine/common.h b/src/projectM-engine/common.h index cbaef84a0..2afc453df 100755 --- a/src/projectM-engine/common.h +++ b/src/projectM-engine/common.h @@ -58,8 +58,6 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #define FALSE 0 #endif -#define PROJECTM_FILE_EXTENSION ".prjm" -#define MILKDROP_FILE_EXTENSION ".milk" #define MAX_DOUBLE_SIZE 10000000.0 #define MIN_DOUBLE_SIZE -10000000.0 diff --git a/src/projectM-engine/console_interface.cpp b/src/projectM-engine/console_interface.cpp index 9f690c909..3b7610d88 100755 --- a/src/projectM-engine/console_interface.cpp +++ b/src/projectM-engine/console_interface.cpp @@ -155,22 +155,22 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode case PROJECTM_K_b: break; case PROJECTM_K_n: - if (PresetSwitcher::switchPreset(ALPHA_NEXT, HARD_CUT) < 0) { +// if (PresetSwitcher::switchPreset(ALPHA_NEXT, HARD_CUT) < 0) { printf("WARNING: Bad preset file, not handling this..aborting!\n"); abort(); - } +// } break; case PROJECTM_K_r: - if (PresetSwitcher::switchPreset(RANDOM_NEXT, HARD_CUT) < 0) { +// if (PresetSwitcher::switchPreset(RANDOM_NEXT, HARD_CUT) < 0) { printf("WARNING: Bad preset file, loading idle preset\n"); abort(); - } +// } break; case PROJECTM_K_p: - if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){ +// if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){ printf("WARNING: Bad preset file, loading idle preset\n"); abort(); - } +// } break; case PROJECTM_K_l: if (renderer->noSwitch==0)renderer->noSwitch=1; else renderer->noSwitch=0;