Separated away save/load of xml to separate file. Added 60 Hz

This commit is contained in:
Daniel Collin 2012-10-25 21:51:21 +02:00
parent c15809ae52
commit c4cd4355d8
5 changed files with 141 additions and 70 deletions

View File

@ -5,7 +5,7 @@
#include <string.h>
#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();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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);

115
ogl_editor/src/loadsave.c Normal file
View File

@ -0,0 +1,115 @@
#include "LoadSave.h"
#include "Dialog.h"
#include "External/mxml/mxml.h"
#include <Types.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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;
}

View File

@ -0,0 +1,7 @@
#pragma once
int LoadSave_loadRocketXML(const char* path);
int LoadSave_loadRocketXMLDialog();
int LoadSave_saveRocketXML(const char* path);
int LoadSave_saveRocketXMLDialog();

View File

@ -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;
}