From c4cd4355d843cb0e4739e59021c435621a371ba8 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Thu, 25 Oct 2012 21:51:21 +0200 Subject: [PATCH] Separated away save/load of xml to separate file. Added 60 Hz --- ogl_editor/src/Editor.c | 75 ++---------------------- ogl_editor/src/Editor.h | 1 + ogl_editor/src/loadsave.c | 115 +++++++++++++++++++++++++++++++++++++ ogl_editor/src/loadsave.h | 7 +++ ogl_editor/src/macosx/RocketView.m | 13 +++++ 5 files changed, 141 insertions(+), 70 deletions(-) create mode 100644 ogl_editor/src/loadsave.c create mode 100644 ogl_editor/src/loadsave.h diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index 56c9f19..0ad70fd 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -5,7 +5,7 @@ #include #include "Dialog.h" #include "Editor.h" -#include "External/mxml/mxml.h" +#include "LoadSave.h" typedef struct RETrack { @@ -253,85 +253,20 @@ bool Editor_keyDown(int key) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static void parseXml(mxml_node_t* rootNode) +void Editor_timedUpdate() { - // find the tracks element - mxml_node_t* node = mxmlFindElement(rootNode, rootNode, "tracks", NULL, NULL, MXML_NO_DESCEND); - if (!node) - { - node = mxmlFindElement(rootNode, rootNode, "tracks", NULL, NULL, MXML_DESCEND_FIRST); - if (!node) - { - // TODO: Report back that we couldn't find tracks in xml file - // Dialog_showError(...) - - printf("No tracks found\n"); - - return; - } - } - - // Traverse the tracks node data - - while (1) - { - node = mxmlWalkNext(node, rootNode, MXML_DESCEND); - - if (!node) - break; - - switch (mxmlGetType(node)) - { - case MXML_ELEMENT: - { - const char* element_name = mxmlGetElement(node); - - if (!strcmp("track", element_name)) - { - // TODO: Create the new track/channel here - - printf("Creating track/channel with name %s\n", mxmlElementGetAttr(node, "name")); - } - else if (!strcmp("key", element_name)) - { - const char* row = mxmlElementGetAttr(node, "row"); - const char* value = mxmlElementGetAttr(node, "value"); - const char* interpolation = mxmlElementGetAttr(node, "interpolation"); - - printf("Adding key: row %s | value %s | interpolation %s\n", row, value, interpolation); - } - } - - default: break; - } - } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static void onOpen() { - FILE* fp; - mxml_node_t* tree; - char path[512]; - - if (!Dialog_open(path)) - return; - - if (!(fp = fopen(path, "r"))) - return; - - if (!(tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK))) - { - fclose(fp); - return; - } - - parseXml(tree); - mxmlDelete(tree); + LoadSave_loadRocketXMLDialog(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ogl_editor/src/Editor.h b/ogl_editor/src/Editor.h index 45308d9..5e4c2c7 100644 --- a/ogl_editor/src/Editor.h +++ b/ogl_editor/src/Editor.h @@ -4,6 +4,7 @@ void Editor_create(); void Editor_destroy(); void Editor_init(); void Editor_update(); +void Editor_timedUpdate(); bool Editor_keyDown(int keyCode); void Editor_menuEvent(int menuItem); diff --git a/ogl_editor/src/loadsave.c b/ogl_editor/src/loadsave.c new file mode 100644 index 0000000..bb6491b --- /dev/null +++ b/ogl_editor/src/loadsave.c @@ -0,0 +1,115 @@ +#include "LoadSave.h" +#include "Dialog.h" +#include "External/mxml/mxml.h" +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static void parseXml(mxml_node_t* rootNode) +{ + // find the tracks element + + mxml_node_t* node = mxmlFindElement(rootNode, rootNode, "tracks", NULL, NULL, MXML_NO_DESCEND); + + if (!node) + { + node = mxmlFindElement(rootNode, rootNode, "tracks", NULL, NULL, MXML_DESCEND_FIRST); + + if (!node) + { + // TODO: Report back that we couldn't find tracks in xml file + // Dialog_showError(...) + + printf("No tracks found\n"); + + return; + } + } + + // Traverse the tracks node data + + while (1) + { + node = mxmlWalkNext(node, rootNode, MXML_DESCEND); + + if (!node) + break; + + switch (mxmlGetType(node)) + { + case MXML_ELEMENT: + { + const char* element_name = mxmlGetElement(node); + + if (!strcmp("track", element_name)) + { + // TODO: Create the new track/channel here + + printf("Creating track/channel with name %s\n", mxmlElementGetAttr(node, "name")); + } + else if (!strcmp("key", element_name)) + { + const char* row = mxmlElementGetAttr(node, "row"); + const char* value = mxmlElementGetAttr(node, "value"); + const char* interpolation = mxmlElementGetAttr(node, "interpolation"); + + printf("Adding key: row %s | value %s | interpolation %s\n", row, value, interpolation); + } + } + + default: break; + } + } +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int LoadSave_loadRocketXML(const char* path) +{ + FILE* fp = 0; + mxml_node_t* tree = 0; + + if (!(fp = fopen(path, "r"))) + return false; + + if (!(tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK))) + { + fclose(fp); + return false; + } + + parseXml(tree); + + fclose(fp); + mxmlDelete(tree); + + return true; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int LoadSave_loadRocketXMLDialog() +{ + char path[512]; + + if (!Dialog_open(path)) + return false; + + return LoadSave_loadRocketXML(path); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int LoadSave_saveRocketXML(const char* path) +{ + return false; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int LoadSave_saveRocketXMLDialog() +{ + return false; +} + diff --git a/ogl_editor/src/loadsave.h b/ogl_editor/src/loadsave.h new file mode 100644 index 0000000..518d1fe --- /dev/null +++ b/ogl_editor/src/loadsave.h @@ -0,0 +1,7 @@ +#pragma once + +int LoadSave_loadRocketXML(const char* path); +int LoadSave_loadRocketXMLDialog(); +int LoadSave_saveRocketXML(const char* path); +int LoadSave_saveRocketXMLDialog(); + diff --git a/ogl_editor/src/macosx/RocketView.m b/ogl_editor/src/macosx/RocketView.m index 540d8c7..7f98aa4 100644 --- a/ogl_editor/src/macosx/RocketView.m +++ b/ogl_editor/src/macosx/RocketView.m @@ -7,6 +7,13 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +-(void) updateEditor +{ + Editor_timedUpdate(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; @@ -19,6 +26,12 @@ EMGFXBackend_create(); Editor_create(); + const float framerate = 60; + const float frequency = 1.0f/framerate; + [NSTimer scheduledTimerWithTimeInterval:frequency + target:self selector:@selector(updateEditor) + userInfo:nil repeats:YES]; + return self; }