Rewritten PackStream in C++, using Qt serialization
This commit is contained in:
parent
00cbc7f424
commit
b789e3879d
39 changed files with 355 additions and 275 deletions
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
|||
BUILDMODE=release
|
||||
BUILDPATH=./build/${BUILDMODE}
|
||||
LIBRARY_PATH=${BUILDPATH}/rendering:${BUILDPATH}/exploring:${BUILDPATH}/system
|
||||
LIBRARY_PATH=${BUILDPATH}/rendering:${BUILDPATH}/exploring:${BUILDPATH}/system:${BUILDPATH}/basics:${BUILDPATH}/definition
|
||||
|
||||
all:build
|
||||
|
||||
|
|
5
src/basics/ColorRGB.cpp
Normal file
5
src/basics/ColorRGB.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "ColorRGB.h"
|
||||
|
||||
ColorRGB::ColorRGB()
|
||||
{
|
||||
}
|
10
src/basics/ColorRGB.h
Normal file
10
src/basics/ColorRGB.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef COLORRGB_H
|
||||
#define COLORRGB_H
|
||||
|
||||
class ColorRGB
|
||||
{
|
||||
public:
|
||||
ColorRGB();
|
||||
};
|
||||
|
||||
#endif // COLORRGB_H
|
|
@ -6,15 +6,17 @@
|
|||
|
||||
QT -= gui
|
||||
|
||||
TARGET = basics
|
||||
TARGET = paysages_basics
|
||||
TEMPLATE = lib
|
||||
|
||||
DEFINES += BASICS_LIBRARY
|
||||
|
||||
SOURCES +=
|
||||
SOURCES += \
|
||||
ColorRGB.cpp
|
||||
|
||||
HEADERS +=\
|
||||
basics_global.h
|
||||
basics_global.h \
|
||||
ColorRGB.h
|
||||
|
||||
unix:!symbian {
|
||||
maemo5 {
|
||||
|
|
6
src/definition/BaseDefinition.cpp
Normal file
6
src/definition/BaseDefinition.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "BaseDefinition.h"
|
||||
|
||||
BaseDefinition::BaseDefinition(BaseDefinition* parent):
|
||||
parent(parent)
|
||||
{
|
||||
}
|
35
src/definition/BaseDefinition.h
Normal file
35
src/definition/BaseDefinition.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef BASEDEFINITION_H
|
||||
#define BASEDEFINITION_H
|
||||
|
||||
#include "definition_global.h"
|
||||
#include <QVector>
|
||||
|
||||
class PackStream;
|
||||
|
||||
namespace paysages {
|
||||
namespace definition {
|
||||
|
||||
/**
|
||||
* @brief Base class for all definition containers
|
||||
*/
|
||||
class DEFINITIONSHARED_EXPORT BaseDefinition
|
||||
{
|
||||
public:
|
||||
BaseDefinition(BaseDefinition* parent);
|
||||
virtual ~BaseDefinition();
|
||||
|
||||
void addChild(BaseDefinition* child);
|
||||
void removeChild(BaseDefinition* child);
|
||||
|
||||
virtual void save(PackStream* pack);
|
||||
virtual void load(PackStream* pack);
|
||||
|
||||
private:
|
||||
BaseDefinition* parent;
|
||||
QVector<BaseDefinition*> children;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BASEDEFINITION_H
|
|
@ -11,10 +11,12 @@ TEMPLATE = lib
|
|||
|
||||
DEFINES += DEFINITION_LIBRARY
|
||||
|
||||
SOURCES +=
|
||||
SOURCES += \
|
||||
BaseDefinition.cpp
|
||||
|
||||
HEADERS +=\
|
||||
definition_global.h
|
||||
definition_global.h \
|
||||
BaseDefinition.h
|
||||
|
||||
unix:!symbian {
|
||||
maemo5 {
|
||||
|
@ -25,14 +27,14 @@ unix:!symbian {
|
|||
INSTALLS += target
|
||||
}
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ -lpaysages_rendering
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering
|
||||
else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering
|
||||
INCLUDEPATH += $$PWD/../rendering
|
||||
DEPENDPATH += $$PWD/../rendering
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system
|
||||
else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system
|
||||
INCLUDEPATH += $$PWD/../system
|
||||
DEPENDPATH += $$PWD/../system
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../basics/release/ -lpaysages_basics
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../basics/debug/ -lpaysages_basics
|
||||
else:unix: LIBS += -L$$OUT_PWD/../basics/ -lpaysages_basics
|
||||
INCLUDEPATH += $$PWD/../basics
|
||||
DEPENDPATH += $$PWD/../basics
|
||||
|
|
|
@ -23,9 +23,13 @@
|
|||
#ifdef __cplusplus
|
||||
namespace paysages
|
||||
{
|
||||
namespace system {}
|
||||
namespace basics {}
|
||||
namespace definition {}
|
||||
}
|
||||
using namespace paysages::system;
|
||||
using namespace paysages::basics;
|
||||
using namespace paysages::definition;
|
||||
#endif
|
||||
|
||||
/* Global imports */
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "rendering/shared/types.h"
|
||||
#include "rendering/tools/curve.h"
|
||||
#include "rendering/tools/color.h"
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
#include "rendering/tools/lighting.h"
|
||||
#include "rendering/noise.h"
|
||||
#include "rendering/layers.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "editing/common/DrawingWidget.h"
|
||||
#include "editing/common/previewrenderer.h"
|
||||
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
#include "rendering/tools/color.h"
|
||||
|
||||
class _ContextChoice
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
#include <QVector>
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
class BaseForm;
|
||||
class FormRender;
|
||||
|
|
|
@ -121,7 +121,7 @@ protected:
|
|||
cameraSetLocation(_renderer->render_camera, camera_location);
|
||||
}
|
||||
|
||||
static double _getWaterHeight(Renderer* renderer)
|
||||
static double _getWaterHeight(Renderer*)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,6 @@ void DialogMaterialEditor::commitLocalDataToScenery()
|
|||
{
|
||||
}
|
||||
|
||||
void DialogMaterialEditor::alterRenderer(Renderer* renderer)
|
||||
void DialogMaterialEditor::alterRenderer(Renderer*)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -76,9 +76,8 @@ double PaintingBrush::getInfluence(double relative_x, double relative_z)
|
|||
}
|
||||
}
|
||||
|
||||
void PaintingBrush::drawPreview(QWidget* widget)
|
||||
void PaintingBrush::drawPreview(QWidget*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString PaintingBrush::getHelpText()
|
||||
|
|
|
@ -187,16 +187,16 @@ void WidgetHeightMap::mouseReleaseEvent(QMouseEvent*)
|
|||
|
||||
void WidgetHeightMap::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->buttons() & Qt::MiddleButton)
|
||||
/*if (event->buttons() & Qt::MiddleButton)
|
||||
{
|
||||
// Rotate around the turntable
|
||||
int move_x = event->x() - _last_mouse_x;
|
||||
int move_y = event->y() - _last_mouse_y;
|
||||
|
||||
// TODO
|
||||
/*_angle_h -= (double)move_x * 0.008;
|
||||
_angle_v += (double)move_y * 0.003;*/
|
||||
}
|
||||
//_angle_h -= (double)move_x * 0.008;
|
||||
//_angle_v += (double)move_y * 0.003;
|
||||
}*/
|
||||
|
||||
_last_mouse_x = event->x();
|
||||
_last_mouse_y = event->y();
|
||||
|
|
|
@ -3,18 +3,19 @@ CONFIG += ordered
|
|||
|
||||
SUBDIRS = \
|
||||
system \
|
||||
basics \
|
||||
definition \
|
||||
rendering \
|
||||
exploring \
|
||||
editing \
|
||||
controlling \
|
||||
definition \
|
||||
basics
|
||||
controlling
|
||||
|
||||
unix:SUBDIRS += testing
|
||||
|
||||
rendering.depends = system
|
||||
basics.depends = system
|
||||
definition.depends = basics
|
||||
rendering.depends = definition
|
||||
exploring.depends = rendering
|
||||
definition.depends = rendering system
|
||||
editing.depends = exploring rendering
|
||||
controlling.depends = rendering
|
||||
unix:testing.depends = rendering
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "rendering/terrain/public.h"
|
||||
#include "rendering/textures/public.h"
|
||||
#include "rendering/water/public.h"
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
#include "rendering/renderer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "../tools/lighting.h"
|
||||
#include "../tools/euclid.h"
|
||||
#include "../tools/color.h"
|
||||
#include "../tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
#include "../layers.h"
|
||||
#include "../shared/types.h"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _PAYSAGES_CAMERA_H_
|
||||
|
||||
#include "rendering_global.h"
|
||||
#include "tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
#include "tools/euclid.h"
|
||||
#include "tools/boundingbox.h"
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
/* Geographic area definition */
|
||||
|
||||
#include "rendering_global.h"
|
||||
#include "tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
/* Factorized layer management (with names) */
|
||||
|
||||
#include "rendering_global.h"
|
||||
#include "tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _PAYSAGES_NOISE_H_
|
||||
|
||||
#include "rendering_global.h"
|
||||
#include "tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _PAYSAGES_NOISENAIVE_H_
|
||||
|
||||
#include "rendering_global.h"
|
||||
#include "tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -48,7 +48,6 @@ SOURCES += main.c \
|
|||
tools/zone.c \
|
||||
tools/texture.c \
|
||||
tools/parallel.c \
|
||||
tools/pack.c \
|
||||
tools/memory.c \
|
||||
tools/lighting.c \
|
||||
tools/euclid.c \
|
||||
|
@ -96,7 +95,6 @@ HEADERS += \
|
|||
tools/zone.h \
|
||||
tools/texture.h \
|
||||
tools/parallel.h \
|
||||
tools/pack.h \
|
||||
tools/memory.h \
|
||||
tools/lighting.h \
|
||||
tools/euclid.h \
|
||||
|
@ -116,3 +114,15 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -l
|
|||
else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system
|
||||
INCLUDEPATH += $$PWD/../system
|
||||
DEPENDPATH += $$PWD/../system
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../basics/release/ -lpaysages_basics
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../basics/debug/ -lpaysages_basics
|
||||
else:unix: LIBS += -L$$OUT_PWD/../basics/ -lpaysages_basics
|
||||
INCLUDEPATH += $$PWD/../basics
|
||||
DEPENDPATH += $$PWD/../basics
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../definition/release/ -lpaysages_definition
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../definition/debug/ -lpaysages_definition
|
||||
else:unix: LIBS += -L$$OUT_PWD/../definition/ -lpaysages_definition
|
||||
INCLUDEPATH += $$PWD/../definition
|
||||
DEPENDPATH += $$PWD/../definition
|
||||
|
|
|
@ -24,9 +24,13 @@
|
|||
namespace paysages
|
||||
{
|
||||
namespace system {}
|
||||
namespace basics {}
|
||||
namespace definition {}
|
||||
namespace rendering {}
|
||||
}
|
||||
using namespace paysages::system;
|
||||
using namespace paysages::basics;
|
||||
using namespace paysages::definition;
|
||||
using namespace paysages::rendering;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "../rendering_global.h"
|
||||
#include "curve.h"
|
||||
#include "pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _PAYSAGES_TOOLS_CURVE_H_
|
||||
|
||||
#include "../rendering_global.h"
|
||||
#include "pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _PAYSAGES_TOOLS_EUCLID_H_
|
||||
|
||||
#include "../rendering_global.h"
|
||||
#include "pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
/*
|
||||
* Cartesian coordinates (X, Y, Z) - right handed :
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "../rendering_global.h"
|
||||
#include "euclid.h"
|
||||
#include "color.h"
|
||||
#include "pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -1,195 +0,0 @@
|
|||
#include "pack.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "color.h"
|
||||
#include "euclid.h"
|
||||
|
||||
struct PackStream
|
||||
{
|
||||
FILE* fd;
|
||||
int write;
|
||||
};
|
||||
|
||||
#define pack754_32(f) (pack754((f), 32, 8))
|
||||
#define pack754_64(f) (pack754((f), 64, 11))
|
||||
#define unpack754_32(i) (unpack754((i), 32, 8))
|
||||
#define unpack754_64(i) (unpack754((i), 64, 11))
|
||||
|
||||
static uint64_t pack754(double f, unsigned bits, unsigned expbits)
|
||||
{
|
||||
double fnorm;
|
||||
int shift;
|
||||
long long sign, exp, significand;
|
||||
unsigned significandbits = bits - expbits - 1; // -1 for sign bit
|
||||
|
||||
if (f == 0.0) return 0; // get this special case out of the way
|
||||
|
||||
// check sign and begin normalization
|
||||
if (f < 0) { sign = 1; fnorm = -f; }
|
||||
else { sign = 0; fnorm = f; }
|
||||
|
||||
// get the normalized form of f and track the exponent
|
||||
shift = 0;
|
||||
while(fnorm >= 2.0) { fnorm /= 2.0; shift++; }
|
||||
while(fnorm < 1.0) { fnorm *= 2.0; shift--; }
|
||||
fnorm = fnorm - 1.0;
|
||||
|
||||
// calculate the binary form (non-double) of the significand data
|
||||
significand = fnorm * ((1LL<<significandbits) + 0.5f);
|
||||
|
||||
// get the biased exponent
|
||||
exp = shift + ((1<<(expbits-1)) - 1); // shift + bias
|
||||
|
||||
// return the final answer
|
||||
return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand;
|
||||
}
|
||||
|
||||
static double unpack754(uint64_t i, unsigned bits, unsigned expbits)
|
||||
{
|
||||
double result;
|
||||
long long shift;
|
||||
unsigned bias;
|
||||
unsigned significandbits = bits - expbits - 1; // -1 for sign bit
|
||||
|
||||
if (i == 0) return 0.0;
|
||||
|
||||
// pull the significand
|
||||
result = (i&((1LL<<significandbits)-1)); // mask
|
||||
result /= (1LL<<significandbits); // convert back to double
|
||||
result += 1.0f; // add the one back on
|
||||
|
||||
// deal with the exponent
|
||||
bias = (1<<(expbits-1)) - 1;
|
||||
shift = ((i>>significandbits)&((1LL<<expbits)-1)) - bias;
|
||||
while(shift > 0) { result *= 2.0; shift--; }
|
||||
while(shift < 0) { result /= 2.0; shift++; }
|
||||
|
||||
// sign it
|
||||
result *= (i>>(bits-1))&1? -1.0: 1.0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PackStream* packReadFile(const char* filepath)
|
||||
{
|
||||
PackStream* result;
|
||||
|
||||
result = malloc(sizeof(PackStream));
|
||||
result->fd = fopen(filepath, "rb");
|
||||
result->write = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PackStream* packWriteFile(const char* filepath)
|
||||
{
|
||||
PackStream* result;
|
||||
|
||||
result = malloc(sizeof(PackStream));
|
||||
result->fd = fopen(filepath, "wb");
|
||||
result->write = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void packCloseStream(PackStream* stream)
|
||||
{
|
||||
if (stream->write)
|
||||
{
|
||||
fflush(stream->fd);
|
||||
}
|
||||
fclose(stream->fd);
|
||||
free(stream);
|
||||
}
|
||||
|
||||
void packWriteDouble(PackStream* stream, double* value)
|
||||
{
|
||||
int written;
|
||||
uint64_t servalue;
|
||||
|
||||
servalue = pack754_64(*value);
|
||||
written = fwrite(&servalue, sizeof(uint64_t), 1, stream->fd);
|
||||
assert(written == 1);
|
||||
}
|
||||
|
||||
void packReadDouble(PackStream* stream, double* value)
|
||||
{
|
||||
int read;
|
||||
uint64_t servalue;
|
||||
|
||||
read = fread(&servalue, sizeof(uint64_t), 1, stream->fd);
|
||||
assert(read == 1);
|
||||
|
||||
*value = unpack754_64(servalue);
|
||||
}
|
||||
|
||||
void packWriteInt(PackStream* stream, int* value)
|
||||
{
|
||||
int written;
|
||||
|
||||
written = fprintf(stream->fd, "%d;", *value);
|
||||
assert(written > 1);
|
||||
}
|
||||
|
||||
void packReadInt(PackStream* stream, int* value)
|
||||
{
|
||||
int read;
|
||||
|
||||
read = fscanf(stream->fd, "%d;", value);
|
||||
assert(read == 1);
|
||||
}
|
||||
|
||||
void packWriteString(PackStream* stream, char* value, int max_length)
|
||||
{
|
||||
int written;
|
||||
int len = 0;
|
||||
while (len < max_length - 1 && value[len] != '\0')
|
||||
{
|
||||
len++;
|
||||
}
|
||||
packWriteInt(stream, &len);
|
||||
if (len > 0)
|
||||
{
|
||||
written = fwrite(value, 1, len, stream->fd);
|
||||
assert(written == len);
|
||||
}
|
||||
}
|
||||
|
||||
void packReadString(PackStream* stream, char* value, int max_length)
|
||||
{
|
||||
int read;
|
||||
int len, clen;
|
||||
|
||||
packReadInt(stream, &len);
|
||||
|
||||
if (len > max_length - 1)
|
||||
{
|
||||
clen = max_length - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
clen = len;
|
||||
}
|
||||
|
||||
if (clen > 0)
|
||||
{
|
||||
read = fread(value, 1, clen, stream->fd);
|
||||
assert(read == clen);
|
||||
value[clen] = '\0';
|
||||
|
||||
if (clen < len)
|
||||
{
|
||||
/* Read rest of the string, discarding it */
|
||||
char* buffer = malloc(len - clen);
|
||||
fread(buffer, 1, len - clen, stream->fd);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef _PAYSAGES_TOOLS_PACK_H_
|
||||
#define _PAYSAGES_TOOLS_PACK_H_
|
||||
|
||||
#include "../rendering_global.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct PackStream PackStream;
|
||||
|
||||
RENDERINGSHARED_EXPORT PackStream* packReadFile(const char* filepath);
|
||||
RENDERINGSHARED_EXPORT PackStream* packWriteFile(const char* filepath);
|
||||
RENDERINGSHARED_EXPORT void packCloseStream(PackStream* stream);
|
||||
|
||||
RENDERINGSHARED_EXPORT void packWriteDouble(PackStream* stream, double* value);
|
||||
RENDERINGSHARED_EXPORT void packReadDouble(PackStream* stream, double* value);
|
||||
RENDERINGSHARED_EXPORT void packWriteInt(PackStream* stream, int* value);
|
||||
RENDERINGSHARED_EXPORT void packReadInt(PackStream* stream, int* value);
|
||||
RENDERINGSHARED_EXPORT void packWriteString(PackStream* stream, char* value, int max_length);
|
||||
RENDERINGSHARED_EXPORT void packReadString(PackStream* stream, char* value, int max_length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#include "texture.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include "System.h"
|
||||
|
|
|
@ -11,7 +11,7 @@ extern "C" {
|
|||
|
||||
#include "../rendering_global.h"
|
||||
#include "color.h"
|
||||
#include "pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
typedef struct Texture2D Texture2D;
|
||||
typedef struct Texture3D Texture3D;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "../rendering_global.h"
|
||||
#include "rendering/tools/euclid.h"
|
||||
#include "rendering/tools/curve.h"
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
141
src/system/PackStream.cpp
Normal file
141
src/system/PackStream.cpp
Normal file
|
@ -0,0 +1,141 @@
|
|||
#include "PackStream.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
#include <QString>
|
||||
|
||||
PackStream::PackStream()
|
||||
{
|
||||
file = NULL;
|
||||
stream = NULL;
|
||||
}
|
||||
|
||||
PackStream::~PackStream()
|
||||
{
|
||||
if (stream)
|
||||
{
|
||||
delete stream;
|
||||
}
|
||||
if (file)
|
||||
{
|
||||
delete file;
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::bindToFile(const char* filepath, bool write)
|
||||
{
|
||||
if (not file and not stream)
|
||||
{
|
||||
file = new QFile(filepath);
|
||||
file->open(write ? QIODevice::WriteOnly : QIODevice::ReadOnly);
|
||||
|
||||
stream = new QDataStream(file);
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::write(int* value)
|
||||
{
|
||||
if (stream and value)
|
||||
{
|
||||
*stream << *value;
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::write(double* value)
|
||||
{
|
||||
if (stream and value)
|
||||
{
|
||||
*stream << *value;
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::write(char* value, int max_length)
|
||||
{
|
||||
if (stream and value)
|
||||
{
|
||||
int length = qstrlen(value);
|
||||
*stream << QString::fromUtf8(value, length > max_length ? max_length : length);
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::read(int* value)
|
||||
{
|
||||
if (stream and value and not stream->atEnd())
|
||||
{
|
||||
int output;
|
||||
*stream >> output;
|
||||
*value = output;
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::read(double* value)
|
||||
{
|
||||
if (stream and value and not stream->atEnd())
|
||||
{
|
||||
double output;
|
||||
*stream >> output;
|
||||
*value = output;
|
||||
}
|
||||
}
|
||||
|
||||
void PackStream::read(char* value, int max_length)
|
||||
{
|
||||
if (stream and value and not stream->atEnd())
|
||||
{
|
||||
QString output;
|
||||
*stream >> output;
|
||||
QByteArray array = output.toUtf8();
|
||||
qstrncpy(value, array.constData(), max_length);
|
||||
}
|
||||
}
|
||||
|
||||
// Transitional C-API
|
||||
|
||||
PackStream* packReadFile(const char* filepath)
|
||||
{
|
||||
PackStream* result = new PackStream();
|
||||
result->bindToFile(filepath, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
PackStream* packWriteFile(const char* filepath)
|
||||
{
|
||||
PackStream* result = new PackStream();
|
||||
result->bindToFile(filepath, true);
|
||||
return result;
|
||||
}
|
||||
|
||||
void packCloseStream(PackStream* stream)
|
||||
{
|
||||
delete stream;
|
||||
}
|
||||
|
||||
void packWriteDouble(PackStream* stream, double* value)
|
||||
{
|
||||
stream->write(value);
|
||||
}
|
||||
|
||||
void packReadDouble(PackStream* stream, double* value)
|
||||
{
|
||||
stream->read(value);
|
||||
}
|
||||
|
||||
void packWriteInt(PackStream* stream, int* value)
|
||||
{
|
||||
stream->write(value);
|
||||
}
|
||||
|
||||
void packReadInt(PackStream* stream, int* value)
|
||||
{
|
||||
stream->read(value);
|
||||
}
|
||||
|
||||
void packWriteString(PackStream* stream, char* value, int max_length)
|
||||
{
|
||||
stream->write(value, max_length);
|
||||
}
|
||||
|
||||
void packReadString(PackStream* stream, char* value, int max_length)
|
||||
{
|
||||
stream->read(value, max_length);
|
||||
}
|
67
src/system/PackStream.h
Normal file
67
src/system/PackStream.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifndef PACKSTREAM_H
|
||||
#define PACKSTREAM_H
|
||||
|
||||
#include "system_global.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
class QFile;
|
||||
class QDataStream;
|
||||
|
||||
namespace paysages
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Data (de)serialization in files or streams.
|
||||
*/
|
||||
class SYSTEMSHARED_EXPORT PackStream
|
||||
{
|
||||
public:
|
||||
PackStream();
|
||||
~PackStream();
|
||||
|
||||
void bindToFile(const char* filepath, bool write=false);
|
||||
|
||||
void write(int* value);
|
||||
void write(double* value);
|
||||
void write(char* value, int max_length);
|
||||
|
||||
void read(int* value);
|
||||
void read(double* value);
|
||||
void read(char* value, int max_length);
|
||||
|
||||
private:
|
||||
QFile* file;
|
||||
QDataStream* stream;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Transitional C-API
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef struct PackStream PackStream;
|
||||
#endif
|
||||
|
||||
SYSTEMSHARED_EXPORT PackStream* packReadFile(const char* filepath);
|
||||
SYSTEMSHARED_EXPORT PackStream* packWriteFile(const char* filepath);
|
||||
SYSTEMSHARED_EXPORT void packCloseStream(PackStream* stream);
|
||||
|
||||
SYSTEMSHARED_EXPORT void packWriteDouble(PackStream* stream, double* value);
|
||||
SYSTEMSHARED_EXPORT void packReadDouble(PackStream* stream, double* value);
|
||||
SYSTEMSHARED_EXPORT void packWriteInt(PackStream* stream, int* value);
|
||||
SYSTEMSHARED_EXPORT void packReadInt(PackStream* stream, int* value);
|
||||
SYSTEMSHARED_EXPORT void packWriteString(PackStream* stream, char* value, int max_length);
|
||||
SYSTEMSHARED_EXPORT void packReadString(PackStream* stream, char* value, int max_length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PACKSTREAM_H
|
|
@ -16,14 +16,16 @@ SOURCES += \
|
|||
PictureFile.cpp \
|
||||
Thread.cpp \
|
||||
Mutex.cpp \
|
||||
System.cpp
|
||||
System.cpp \
|
||||
PackStream.cpp
|
||||
|
||||
HEADERS += \
|
||||
system_global.h \
|
||||
PictureFile.h \
|
||||
Thread.h \
|
||||
Mutex.h \
|
||||
System.h
|
||||
System.h \
|
||||
PackStream.h
|
||||
|
||||
unix:!symbian {
|
||||
maemo5 {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "testing/common.h"
|
||||
|
||||
#include "rendering/tools/pack.h"
|
||||
#include "PackStream.h"
|
||||
|
||||
START_TEST(testPack)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ START_TEST(testPack)
|
|||
data_d = (double)i;
|
||||
packWriteDouble(stream, &data_d);
|
||||
|
||||
data_s = "Testing string 0123 !";
|
||||
data_s = "Testing string 0123 (accentué) !";
|
||||
packWriteString(stream, data_s, 100);
|
||||
packWriteString(stream, data_s, 4);
|
||||
packWriteString(stream, data_s, 5);
|
||||
|
@ -39,7 +39,7 @@ START_TEST(testPack)
|
|||
ck_assert_double_eq(data_d, (double)i);
|
||||
|
||||
packReadString(stream, buffer, 100);
|
||||
ck_assert_str_eq(buffer, "Testing string 0123 !");
|
||||
ck_assert_str_eq(buffer, "Testing string 0123 (accentué) !");
|
||||
packReadString(stream, buffer, 4);
|
||||
ck_assert_str_eq(buffer, "Tes");
|
||||
packReadString(stream, buffer, 3);
|
||||
|
|
|
@ -13,11 +13,6 @@ unix {
|
|||
|
||||
INCLUDEPATH += $$PWD/..
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ -lpaysages_rendering
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering
|
||||
else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering
|
||||
DEPENDPATH += $$PWD/../rendering
|
||||
|
||||
SOURCES += main.c \
|
||||
test_terrain_painting.c \
|
||||
test_render.c \
|
||||
|
@ -37,3 +32,21 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -l
|
|||
else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system
|
||||
INCLUDEPATH += $$PWD/../system
|
||||
DEPENDPATH += $$PWD/../system
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../basics/release/ -lpaysages_basics
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../basics/debug/ -lpaysages_basics
|
||||
else:unix: LIBS += -L$$OUT_PWD/../basics/ -lpaysages_basics
|
||||
INCLUDEPATH += $$PWD/../basics
|
||||
DEPENDPATH += $$PWD/../basics
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../definition/release/ -lpaysages_definition
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../definition/debug/ -lpaysages_definition
|
||||
else:unix: LIBS += -L$$OUT_PWD/../definition/ -lpaysages_definition
|
||||
INCLUDEPATH += $$PWD/../definition
|
||||
DEPENDPATH += $$PWD/../definition
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ -lpaysages_rendering
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering
|
||||
else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering
|
||||
INCLUDEPATH += $$PWD/../rendering
|
||||
DEPENDPATH += $$PWD/../rendering
|
||||
|
|
Loading…
Reference in a new issue