Commit 47336936 authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Added code to Functy for stream output to memory rather than a file (to be...

Added code to Functy for stream output to memory rather than a file (to be used for animation export). Added interface elements for animation export. Simplified configure and makefiles to perform improved library checks.
parent ffd10e60
This diff is collapsed.
......@@ -13,7 +13,9 @@ AC_PROG_CC
AM_PROG_CC_C_O
# Checks for libraries.
PKG_CHECK_MODULES([FUNCTY], [gtk+-2.0 libglade-2.0 gdk-2.0 gtkglext-1.0 glee])
PKG_CHECK_MODULES([FUNCTY], [gtk+-2.0 libglade-2.0 gdk-2.0 gtkglext-1.0 glee libzip])
AC_CHECK_LIB([glut], [glutInit], [], [AC_MSG_ERROR([The glut library is missing.])])
AC_CHECK_LIB([symbolic], [CreateInteger], [], [AC_MSG_ERROR([The symbolic library is missing.])])
# Checks for header files.
AC_HEADER_DIRENT
......
bin_PROGRAMS = ../functy
___functy_SOURCES = function.c function.h function_private.h functy.c functy.h textures.c textures.h utils.c utils.h vis.c vis.h filesave.c filesave.h cartesian.c cartesian.h spherical.c spherical.h shader.c shader.h curve.c curve.h vecsym.c vecsym.h exportply.c exportply.h
___functy_SOURCES = function.c function.h function_private.h functy.c functy.h textures.c textures.h utils.c utils.h vis.c vis.h filesave.c filesave.h cartesian.c cartesian.h spherical.c spherical.h shader.c shader.h curve.c curve.h vecsym.c vecsym.h exportply.c exportply.h recall.c recall.h
___functy_LDADD = -lsymbolic -lgtkglext-x11-1.0 -lgdkglext-x11-1.0 -lGLU -lglut -lXmu -lXt -lSM -lICE -lgtk-x11-2.0 -lpangox-1.0 -lX11 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglee @FUNCTY_LIBS@
___functy_LDADD = -lm @FUNCTY_LIBS@
___functy_CPPFLAGS = -DFUNCTYDIR=\"$(datadir)/@PACKAGE@\" -Wall -I/usr/include/gtkglext-1.0 -I/usr/lib/gtkglext-1.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/atk-1.0 @FUNCTY_CFLAGS@
___functy_CPPFLAGS = -DFUNCTYDIR=\"$(datadir)/@PACKAGE@\" -Wall @FUNCTY_CFLAGS@
#dist_pkgdata_DATA = ../ui/Functy.glade
......@@ -597,7 +597,7 @@ char const * CartesianGetZCentreString (FuncPersist * psFuncData) {
return "0";
}
int CartesianOutputStoredVertices (FILE * hFile, bool boBinary, bool boExportAlpha, bool boScreenCoords, double fMultiplier, FuncPersist const * psFuncData) {
int CartesianOutputStoredVertices (Recall * hFile, bool boBinary, bool boExportAlpha, bool boScreenCoords, double fMultiplier, FuncPersist const * psFuncData) {
CartesianPersist * psCartesianData = psFuncData->Func.psCartesianData;
int nVertex;
double fX;
......@@ -701,24 +701,24 @@ int CartesianOutputStoredVertices (FILE * hFile, bool boBinary, bool boExportAlp
SetVector3 (vVertex, fXFunc, fYFunc, fZFunc);
}
if (boBinary) {
fwrite (& vVertex, sizeof (float), 3, hFile);
recwrite (& vVertex, sizeof (float), 3, hFile);
if (boExportAlpha) {
fwrite (ucColour, sizeof (unsigned char), 4, hFile);
recwrite (ucColour, sizeof (unsigned char), 4, hFile);
}
else {
fwrite (ucColour, sizeof (unsigned char), 3, hFile);
recwrite (ucColour, sizeof (unsigned char), 3, hFile);
}
fwrite (& vN, sizeof (float), 3, hFile);
recwrite (& vN, sizeof (float), 3, hFile);
}
else {
fprintf (hFile, "%f %f %f ", vVertex.fX, vVertex.fY, vVertex.fZ);
recprintf (hFile, "%f %f %f ", vVertex.fX, vVertex.fY, vVertex.fZ);
if (boExportAlpha) {
fprintf (hFile, "%u %u %u %u ", ucColour[0], ucColour[1], ucColour[2], ucColour[3]);
recprintf (hFile, "%u %u %u %u ", ucColour[0], ucColour[1], ucColour[2], ucColour[3]);
}
else {
fprintf (hFile, "%u %u %u ", ucColour[0], ucColour[1], ucColour[2]);
recprintf (hFile, "%u %u %u ", ucColour[0], ucColour[1], ucColour[2]);
}
fprintf (hFile, "%f %f %f\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "%f %f %f\n", vN.fX, vN.fY, vN.fZ);
}
nVertex++;
}
......@@ -727,7 +727,7 @@ int CartesianOutputStoredVertices (FILE * hFile, bool boBinary, bool boExportAlp
return nVertex;
}
int CartesianOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData) {
int CartesianOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData) {
int nIndices;
int anIndex[3];
unsigned char uVertices;
......@@ -760,11 +760,11 @@ int CartesianOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplie
anIndex[2] = ((nXVertex + 0) * nYVertices) + ((nYVertex + 1) % nYVertices) + nOffset;
if (boBinary) {
fwrite (& uVertices, sizeof (unsigned char), 1, hFile);
fwrite (& anIndex, sizeof (int), 3, hFile);
recwrite (& uVertices, sizeof (unsigned char), 1, hFile);
recwrite (& anIndex, sizeof (int), 3, hFile);
}
else {
fprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
recprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
}
nIndices++;
......@@ -773,11 +773,11 @@ int CartesianOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplie
anIndex[2] = ((nXVertex + 1) * nYVertices) + ((nYVertex + 1) % nYVertices) + nOffset;
if (boBinary) {
fwrite (& uVertices, sizeof (unsigned char), 1, hFile);
fwrite (& anIndex, sizeof (int), 3, hFile);
recwrite (& uVertices, sizeof (unsigned char), 1, hFile);
recwrite (& anIndex, sizeof (int), 3, hFile);
}
else {
fprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
recprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
}
nIndices++;
}
......
......@@ -14,6 +14,8 @@
///////////////////////////////////////////////////////////////////
// Includes
#include "recall.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -47,8 +49,8 @@ void CartesianGetCentre (double * afCentre, FuncPersist const * psFuncData);
char const * CartesianGetXCentreString (FuncPersist * psFuncData);
char const * CartesianGetYCentreString (FuncPersist * psFuncData);
char const * CartesianGetZCentreString (FuncPersist * psFuncData);
int CartesianOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData);
int CartesianOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CartesianOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData);
int CartesianOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CartesianCountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CartesianCountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
......
......@@ -1106,7 +1106,7 @@ double CurveGetFunctionAccuracyRadius (FuncPersist * psFuncData) {
return psCurveData->fAccuracyRadius;
}
int CurveOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData) {
int CurveOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData) {
CurvePersist * psCurveData = psFuncData->Func.psCurveData;
int nPiece;
int nSegment;
......@@ -1282,24 +1282,24 @@ int CurveOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords,
SetVector3 (vVertex, fXFunc, fYFunc, fZFunc);
}
if (boBinary) {
fwrite (& vVertex, sizeof (float), 3, hFile);
recwrite (& vVertex, sizeof (float), 3, hFile);
if (boExportAlpha) {
fwrite (ucColour, sizeof (unsigned char), 4, hFile);
recwrite (ucColour, sizeof (unsigned char), 4, hFile);
}
else {
fwrite (ucColour, sizeof (unsigned char), 3, hFile);
recwrite (ucColour, sizeof (unsigned char), 3, hFile);
}
fwrite (& vNormalOut, sizeof (float), 3, hFile);
recwrite (& vNormalOut, sizeof (float), 3, hFile);
}
else {
fprintf (hFile, "%f %f %f ", vVertex.fX, vVertex.fY, vVertex.fZ);
recprintf (hFile, "%f %f %f ", vVertex.fX, vVertex.fY, vVertex.fZ);
if (boExportAlpha) {
fprintf (hFile, "%u %u %u %u ", ucColour[0], ucColour[1], ucColour[2], ucColour[3]);
recprintf (hFile, "%u %u %u %u ", ucColour[0], ucColour[1], ucColour[2], ucColour[3]);
}
else {
fprintf (hFile, "%u %u %u ", ucColour[0], ucColour[1], ucColour[2]);
recprintf (hFile, "%u %u %u ", ucColour[0], ucColour[1], ucColour[2]);
}
fprintf (hFile, "%f %f %f\n", vNormalOut.fX, vNormalOut.fY, vNormalOut.fZ);
recprintf (hFile, "%f %f %f\n", vNormalOut.fX, vNormalOut.fY, vNormalOut.fZ);
}
nVertices++;
}
......@@ -1308,7 +1308,7 @@ int CurveOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords,
return nVertices;
}
int CurveOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData) {
int CurveOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData) {
CurvePersist * psCurveData = psFuncData->Func.psCurveData;
int nFaces;
int anIndex[3];
......@@ -1337,11 +1337,11 @@ int CurveOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, i
anIndex[2] = ((nPiece + 0) * nSegments) + ((nSegment + 1) % nSegments) + nOffset;
if (boBinary) {
fwrite (& uVertices, sizeof (unsigned char), 1, hFile);
fwrite (& anIndex, sizeof (int), 3, hFile);
recwrite (& uVertices, sizeof (unsigned char), 1, hFile);
recwrite (& anIndex, sizeof (int), 3, hFile);
}
else {
fprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
recprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
}
nFaces++;
......@@ -1350,11 +1350,11 @@ int CurveOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, i
anIndex[2] = ((nPiece + 1) * nSegments) + ((nSegment + 1) % nSegments) + nOffset;
if (boBinary) {
fwrite (& uVertices, sizeof (unsigned char), 1, hFile);
fwrite (& anIndex, sizeof (int), 3, hFile);
recwrite (& uVertices, sizeof (unsigned char), 1, hFile);
recwrite (& anIndex, sizeof (int), 3, hFile);
}
else {
fprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
recprintf (hFile, "3 %d %d %d\n", anIndex[0], anIndex[1], anIndex[2]);
}
nFaces++;
}
......
......@@ -14,6 +14,8 @@
///////////////////////////////////////////////////////////////////
// Includes
#include "recall.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -56,8 +58,8 @@ bool CurveGetCentreTimeDependent (FuncPersist const * psFuncData);
void CurveGetCentre (double * afCentre, FuncPersist const * psFuncData);
void CurveUpdateCentre (FuncPersist * psFuncData);
void CurveSetFunctionTime (double fTime, FuncPersist * psFuncData);
int CurveOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData);
int CurveOutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CurveOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData);
int CurveOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CurveCountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CurveCountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
......
......@@ -40,7 +40,7 @@ bool ExportModel (char const * szFilename, bool boBinary, bool boScreenCoords, b
bool boResult;
int nVertices;
int nFaces;
FILE * hFile;
Recall * hFile;
int nOffset;
GSList const * psFuncList;
GSList * psOffsets;
......@@ -66,32 +66,32 @@ bool ExportModel (char const * szFilename, bool boBinary, bool boScreenCoords, b
}
boResult = FALSE;
hFile = fopen (szFilename, "w");
hFile = recopen (szFilename, "m");
if (hFile) {
fprintf (hFile, "ply\n");
recprintf (hFile, "ply\n");
if (boBinary) {
fprintf (hFile, "format " PLY_ENDIANNESS " 1.0 1.0\n");
recprintf (hFile, "format " PLY_ENDIANNESS " 1.0 1.0\n");
}
else {
fprintf (hFile, "format ascii 1.0\n");
recprintf (hFile, "format ascii 1.0\n");
}
fprintf (hFile, "comment Functy generated\n");
fprintf (hFile, "element vertex %d\n", nVertices);
fprintf (hFile, "property float32 x\n");
fprintf (hFile, "property float32 y\n");
fprintf (hFile, "property float32 z\n");
fprintf (hFile, "property uint8 red\n");
fprintf (hFile, "property uint8 green\n");
fprintf (hFile, "property uint8 blue\n");
recprintf (hFile, "comment Functy generated\n");
recprintf (hFile, "element vertex %d\n", nVertices);
recprintf (hFile, "property float32 x\n");
recprintf (hFile, "property float32 y\n");
recprintf (hFile, "property float32 z\n");
recprintf (hFile, "property uint8 red\n");
recprintf (hFile, "property uint8 green\n");
recprintf (hFile, "property uint8 blue\n");
if (boExportAlpha) {
fprintf (hFile, "property uint8 alpha\n");
recprintf (hFile, "property uint8 alpha\n");
}
fprintf (hFile, "property float32 nx\n");
fprintf (hFile, "property float32 ny\n");
fprintf (hFile, "property float32 nz\n");
fprintf (hFile, "element face %d\n", nFaces);
fprintf (hFile, "property list uchar int vertex_indices\n");
fprintf (hFile, "end_header\n");
recprintf (hFile, "property float32 nx\n");
recprintf (hFile, "property float32 ny\n");
recprintf (hFile, "property float32 nz\n");
recprintf (hFile, "element face %d\n", nFaces);
recprintf (hFile, "property list uchar int vertex_indices\n");
recprintf (hFile, "end_header\n");
// Output the vertices
psOffsets = NULL;
......@@ -114,7 +114,7 @@ bool ExportModel (char const * szFilename, bool boBinary, bool boScreenCoords, b
}
g_slist_free (psOffsets);
fclose (hFile);
recclose (hFile);
boResult = TRUE;
}
......
......@@ -752,7 +752,7 @@ void SetFunctionCentre (char const * const szXCentre, char const * const szYCent
}
}
int OutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData) {
int OutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData) {
int nVertices;
switch (psFuncData->eType) {
......@@ -774,7 +774,7 @@ int OutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool
return nVertices;
}
int OutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData) {
int OutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData) {
int nIndices;
switch (psFuncData->eType) {
......
......@@ -14,6 +14,8 @@
///////////////////////////////////////////////////////////////////
// Includes
#include "recall.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -86,8 +88,8 @@ void GetCentre (double * afCentre, FuncPersist const * psFuncData);
char const * GetXCentreString (FuncPersist * psFuncData);
char const * GetYCentreString (FuncPersist * psFuncData);
char const * GetZCentreString (FuncPersist * psFuncData);
int OutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData);
int OutputStoredIndices (FILE * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int OutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData);
int OutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
......
This diff is collapsed.
......@@ -43,13 +43,20 @@ struct _FunctyPersist {
bool boFileLoaded;
GString * szFilename;
bool boFolderSet;
bool boFolderSetAnim;
bool boExportedModel;
bool boExportedAnim;
GString * szExportModelName;
GString * szExportAnimName;
bool boBinary;
double fExportMultiplier;
bool boExportScreen;
bool boExportAlpha;
double fExportTimeStart;
double fExportTimeEnd;
int nExportFrames;
GString * szFolder;
GString * szFolderAnim;
FUNCTYPE eNextFunctionType;
bool boButtonBarHidden;
};
......
///////////////////////////////////////////////////////////////////
// Recall
// File and memory management
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// Summer 2013
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Includes
#include "recall.h"
#include <string.h>
#include <gtk/gtk.h>
///////////////////////////////////////////////////////////////////
// Defines
#define RECALL_MEMORY_BLOCKSIZE (10*1024)
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef enum _RECALLMODE {
RECALLMODE_INVALID = -1,
RECALLMODE_MEMORY,
RECALLMODE_FILEWRITE,
RECALLMODE_NUM
} RECALLMODE;
typedef struct _RecallMemory {
char * pStore;
unsigned long int uAllocated;
unsigned long int uFilled;
unsigned long int uBlockSize;
GString * szFilename;
} RecallMemory;
typedef struct _RecallFile {
FILE * psFile;
} RecallFile;
struct _Recall {
RECALLMODE eMode;
// Type specific data
union {
RecallMemory * psMemory;
RecallFile * psFile;
void * psNone;
} Store;
// Virtual functions
size_t (*recwrite) (const void * ptr, size_t size, size_t count, Recall * stream);
int (*recprintf) (Recall * stream, const char * format, va_list arg);
int (*recclose) (Recall * stream);
};
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
void SetupRecall (const char * szFilename, Recall * psRecall);
void Memory_SetupRecall (const char * szFilename, Recall * psRecall);
void FileWrite_SetupRecall (const char * szFilename, const char * mode, Recall * psRecall);
size_t Memory_recwrite (const void * ptr, size_t size, size_t count, Recall * stream);
int Memory_recprintf (Recall * stream, const char * format, va_list arg);
int Memory_recclose (Recall * stream);
void Memory_realloc (unsigned long int uSize, Recall * psRecall);
size_t FileWrite_recwrite (const void * ptr, size_t size, size_t count, Recall * stream);
int FileWrite_recprintf (Recall * stream, const char * format, va_list arg);
int FileWrite_recclose (Recall * stream);
///////////////////////////////////////////////////////////////////
// Function definitions
Recall * recopen (const char * filename, const char * mode) {
Recall * psRecall;
RECALLMODE eMode;
psRecall = g_new0 (Recall, 1);
// Figure out the mode
eMode = RECALLMODE_FILEWRITE;
if (mode != NULL) {
if (strchr (mode, 'm') != NULL) {
eMode = RECALLMODE_MEMORY;
}
}
psRecall->eMode = eMode;
switch (eMode) {
case RECALLMODE_MEMORY:
Memory_SetupRecall (filename, psRecall);
break;
case RECALLMODE_FILEWRITE:
FileWrite_SetupRecall (filename, mode, psRecall);
break;
default:
SetupRecall (filename, psRecall);
break;
}
return psRecall;
}
void SetupRecall (const char * szFilename, Recall * psRecall) {
psRecall->Store.psNone = NULL;
}
void Memory_SetupRecall (const char * szFilename, Recall * psRecall) {
psRecall->Store.psMemory = g_new0 (RecallMemory, 1);
psRecall->recwrite = Memory_recwrite;
psRecall->recprintf = Memory_recprintf;
psRecall->recclose = Memory_recclose;
psRecall->Store.psMemory->pStore = NULL;
psRecall->Store.psMemory->uAllocated = 0u;
psRecall->Store.psMemory->uFilled = 0u;
psRecall->Store.psMemory->uBlockSize = RECALL_MEMORY_BLOCKSIZE;
if (szFilename != NULL) {
psRecall->Store.psMemory->szFilename = g_string_new (szFilename);
}
else {
psRecall->Store.psMemory->szFilename = g_string_new ("");
}
}
void FileWrite_SetupRecall (const char * szFilename, const char * mode, Recall * psRecall) {
psRecall->Store.psFile = g_new0 (RecallFile, 1);
psRecall->recwrite = FileWrite_recwrite;
psRecall->recprintf = FileWrite_recprintf;
psRecall->recclose = FileWrite_recclose;
psRecall->Store.psFile->psFile = fopen (szFilename, mode);
}
size_t recwrite (const void * ptr, size_t size, size_t count, Recall * stream) {
size_t nResult;
if (stream != NULL) {
nResult = stream->recwrite (ptr, size, count, stream);
}
else {
nResult = 0;
}
return nResult;
}
int recprintf (Recall * stream, const char * format, ...) {
int nResult;
if (stream != NULL) {
va_list args;
va_start (args, format);
nResult = stream->recprintf (stream, format, args);
va_end (args);
}
else {
nResult = 0;
}
return nResult;
}
int recclose (Recall * stream) {
int nResult;
if (stream != NULL) {
nResult = stream->recclose (stream);
}
else {
nResult = 0;
}
g_free (stream);
return nResult;
}
size_t Memory_recwrite (const void * ptr, size_t size, size_t count, Recall * stream) {
unsigned long int uMemoryNeeded;
size_t uResult;
uMemoryNeeded = stream->Store.psMemory->uFilled + (size * count);
Memory_realloc (uMemoryNeeded, stream);
// Copy the data into the memory
memcpy (stream->Store.psMemory->pStore + stream->Store.psMemory->uFilled, ptr, (size * count));
stream->Store.psMemory->uFilled += (size * count);
uResult = count;
return uResult;
}
int Memory_recprintf (Recall * stream, const char * format, va_list arg) {
int nLength;
unsigned long int uMemoryNeeded;
GString * szText;
// Create a temporary string to store the result in
szText = g_string_new ("");
g_string_vprintf (szText, format, arg);
nLength = szText->len;
uMemoryNeeded = stream->Store.psMemory->uFilled + nLength;
Memory_realloc (uMemoryNeeded, stream);
// Store the new data
memcpy (stream->Store.psMemory->pStore + stream->Store.psMemory->uFilled, szText->str, nLength);
stream->Store.psMemory->uFilled += szText->len;
// Free up the temporary copy of the data
g_string_free (szText, TRUE);
return nLength;
}
int Memory_recclose (Recall * stream) {
FILE * psFile;
int nResult = 0;
// Save out the data if a filename was provided
if (stream->Store.psMemory->szFilename->len > 0) {
psFile = fopen (stream->Store.psMemory->szFilename->str, "w");
if (psFile != NULL) {
fwrite (stream->Store.psMemory->pStore, 1, stream->Store.psMemory->uFilled, psFile);
nResult = fclose (psFile);
}
}
if (stream->Store.psMemory->pStore != NULL) {
g_free (stream->Store.psMemory->pStore);
stream->Store.psMemory->pStore = NULL;
}
g_free (stream->Store.psMemory);
stream->Store.psMemory = NULL;
return nResult;
}
void Memory_realloc (unsigned long int uSize, Recall * psRecall) {
unsigned long int uAllocate;
if (uSize > psRecall->Store.psMemory->uAllocated) {
// Allocate more memory
uAllocate = (((unsigned long int)(uSize / psRecall->Store.psMemory->uBlockSize)) + 1) * psRecall->Store.psMemory->uBlockSize;
psRecall->Store.psMemory->pStore = g_realloc (psRecall->Store.psMemory->pStore, uAllocate);
psRecall->Store.psMemory->uAllocated = uAllocate;
}
}
size_t FileWrite_recwrite (const void * ptr, size_t size, size_t count, Recall * stream) {
return fwrite (ptr, size, count, stream->Store.psFile->psFile);
}
int FileWrite_recprintf (Recall * stream, const char * format, va_list arg) {
int nResult;
nResult = vfprintf (stream->Store.psFile->psFile, format, arg);
return nResult;
}
int FileWrite_recclose (Recall * stream) {
int nResult;
nResult = fclose (stream->Store.psFile->psFile);
g_free (stream->Store.psFile);
stream->Store.psFile = NULL;
return nResult;
}
///////////////////////////////////////////////////////////////////
// Recall
// File and memory management
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// Summer 2013
///////////////////////////////////////////////////////////////////
#ifndef RECALL_H
#define RECALL_H
///////////////////////////////////////////////////////////////////
// Includes
#include <stdio.h>
///////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _Recall Recall;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
Recall * recopen (const char * filename, const char * mode);
size_t recwrite (const void * ptr, size_t size, size_t count, Recall * stream);
int recprintf (Recall * stream, const char * format, ...);
int recclose (Recall * stream);
///////////////////////////////////////////////////////////////////
// Function definitions
#endif /* RECALL_H */
......@@ -749,7 +749,7 @@ void SphericalSetShaderActive (bool boActive, FuncPersist * psFuncData) {
SphericalPopulateVertices (psFuncData);
}
int SphericalOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData) {
int SphericalOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, FuncPersist const * psFuncData) {
SphericalPersist * psSphericalData = psFuncData->Func.psSphericalData;
int nVertex;
double fA;
......@@ -884,24 +884,24 @@ int SphericalOutputStoredVertices (FILE * hFile, bool boBinary, bool boScreenCoo
vN.fY = -vN.fY;
vN.fZ = -vN.fZ;
if (boBinary) {
fwrite (& vVertex, sizeof (float), 3, hFile);
recwrite (& vVertex, sizeof (float), 3, hFile);
if (boExportAlpha) {
fwrite (ucColour, sizeof (unsigned char), 4, hFile);
recwrite (ucColour, sizeof (unsigned char), 4