From 5dfa34dd56588c9d5efb04fc3805d32f3f76cb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 31 Oct 2013 17:59:18 +0100 Subject: [PATCH] WIP on c++ layers --- src/definition/BaseDefinition.cpp | 43 ++++-- src/definition/BaseDefinition.h | 8 + src/definition/Layers.cpp | 220 +++++++++++++++++++++++++++ src/definition/Layers.h | 98 ++++++++++++ src/definition/LegacyLayer.cpp | 32 ++++ src/definition/LegacyLayer.h | 50 ++++++ src/definition/definition.pro | 8 +- src/editing/baseform.h | 2 +- src/editing/baseformlayer.cpp | 2 +- src/editing/baseformlayer.h | 2 +- src/editing/common/freelayerhelper.h | 2 +- src/editing/dialoglayers.h | 2 +- src/editing/inputlayers.h | 2 +- src/exploring/exploring.pro | 12 ++ src/rendering/atmosphere/public.h | 1 - src/rendering/clouds/public.h | 2 +- src/rendering/layers.c | 210 ------------------------- src/rendering/layers.h | 55 ------- src/rendering/rendering.pro | 2 - src/rendering/textures/public.h | 2 +- src/rendering/water/public.h | 2 +- src/system/PackStream.cpp | 22 +++ src/system/PackStream.h | 3 + 23 files changed, 493 insertions(+), 289 deletions(-) create mode 100644 src/definition/Layers.cpp create mode 100644 src/definition/Layers.h create mode 100644 src/definition/LegacyLayer.cpp create mode 100644 src/definition/LegacyLayer.h delete mode 100644 src/rendering/layers.c delete mode 100644 src/rendering/layers.h diff --git a/src/definition/BaseDefinition.cpp b/src/definition/BaseDefinition.cpp index d3672a8..cc5b823 100644 --- a/src/definition/BaseDefinition.cpp +++ b/src/definition/BaseDefinition.cpp @@ -22,21 +22,14 @@ BaseDefinition::~BaseDefinition() } } -void BaseDefinition::addChild(BaseDefinition* child) +void BaseDefinition::setName(QString name) { - if (not children.contains(child)) - { - children.append(child); - } -} - -void BaseDefinition::removeChild(BaseDefinition* child) -{ - children.removeOne(child); + this->name = name; } void BaseDefinition::save(PackStream* pack) { + pack->write(name); QListIterator it(children); while (it.hasNext()) { @@ -46,9 +39,39 @@ void BaseDefinition::save(PackStream* pack) void BaseDefinition::load(PackStream* pack) { + name = pack->readString(); QListIterator it(children); while (it.hasNext()) { it.next()->load(pack); } } + +void BaseDefinition::copy(BaseDefinition* destination) +{ + // TODO +} + +void BaseDefinition::validate() +{ + QListIterator it(children); + while (it.hasNext()) + { + it.next()->validate(); + } +} + +void BaseDefinition::addChild(BaseDefinition* child) +{ + if (not children.contains(child)) + { + children.append(child); + child->parent = this; + child->root = this->root; + } +} + +void BaseDefinition::removeChild(BaseDefinition* child) +{ + children.removeOne(child); +} diff --git a/src/definition/BaseDefinition.h b/src/definition/BaseDefinition.h index e38dc68..e97d892 100644 --- a/src/definition/BaseDefinition.h +++ b/src/definition/BaseDefinition.h @@ -4,6 +4,7 @@ #include "definition_global.h" #include +#include #include "PackStream.h" // TODO Delete when c++ migration is done namespace paysages { @@ -21,6 +22,12 @@ public: virtual void save(PackStream* pack); virtual void load(PackStream* pack); + virtual void copy(BaseDefinition* destination); + virtual void validate(); + + inline const QString& getName() {return name;} + void setName(QString name); + protected: void addChild(BaseDefinition* child); void removeChild(BaseDefinition* child); @@ -28,6 +35,7 @@ protected: private: BaseDefinition* parent; BaseDefinition* root; + QString name; QList children; }; diff --git a/src/definition/Layers.cpp b/src/definition/Layers.cpp new file mode 100644 index 0000000..d7db0bd --- /dev/null +++ b/src/definition/Layers.cpp @@ -0,0 +1,220 @@ +#include "Layers.h" + +Layers::Layers(BaseDefinition* parent, LayerConstructor layer_constructor, LayerType* legacy_type): + BaseDefinition(parent), layer_constructor(layer_constructor) +{ + if (legacy_type) + { + this->legacy_type = *legacy_type; + } + max_layer_count = 100; + null_layer = layer_constructor(this); +} + +Layers::~Layers() +{ + clear(); + delete null_layer; +} + +void Layers::copy(Layers* destination) +{ + // don't call overridden method, it will copy again the children + // FIXME ... but the definition name (and other future attributes) is not copied + + destination->clear(); + + destination->max_layer_count = max_layer_count; + destination->legacy_type = legacy_type; + + null_layer->copy(destination->null_layer); + + QListIterator it(layers); + while (it.hasNext()) + { + int position = destination->addLayer(); + BaseDefinition* new_layer = destination->getLayer(position); + it.next()->copy(new_layer); + } +} + +void Layers::setMaxLayerCount(int max_layer_count) +{ + this->max_layer_count = max_layer_count; + // TODO Delete overlimit layers ? +} + +int Layers::count() +{ + return layers.count(); +} + +BaseDefinition* Layers::getLayer(int position) +{ + if (position >= 0 and position < layers.size()) + { + return layers[position]; + } + else + { + qWarning("Asked for a undefined layer %d on a total of %d", position, layers.size()); + return null_layer; + } +} + +int Layers::findLayer(BaseDefinition* layer) +{ + int result = layers.indexOf(layer); + if (result < 0) + { + qWarning("Layer %p not found, on a total of %d, returning %d", layer, layers.size(), result); + } + return result; +} + +int Layers::addLayer(BaseDefinition* layer) +{ + if (layers.size() < max_layer_count) + { + layers.append(layer); + addChild(layer); + return layers.size() - 1; + } + else + { + qWarning("Add layer ignored because limit of %d reached", max_layer_count); + return -1; + } +} + +int Layers::addLayer() +{ + return addLayer(layer_constructor(this)); +} + +void Layers::removeLayer(int position) +{ + if (position >= 0 and position < layers.size()) + { + BaseDefinition* removed = layers.takeAt(position); + removeChild(removed); + delete removed; + } +} + +void Layers::removeLayer(BaseDefinition* layer) +{ + removeLayer(findLayer(layer)); +} + +void Layers::moveLayer(int old_position, int new_position) +{ + // TODO +} + +void Layers::moveLayer(BaseDefinition* layer, int new_position) +{ + moveLayer(findLayer(layer), new_position); +} + +void Layers::clear() +{ + while (layers.size() > 0) + { + removeLayer(0); + } +} + +// Transitional C-API + +BaseDefinition* _legacyLayerConstructor(Layers* layers) +{ + return new LegacyLayer(layers, &layers->legacy_type); +} + +Layers* layersCreate(LayerType type, int max_layer_count) +{ + Layers* result = new Layers(NULL, _legacyLayerConstructor, &type); + result->setMaxLayerCount(max_layer_count); + return result; +} + +Layers* layersCreateCopy(Layers* original) +{ + Layers* result = new Layers(NULL, _legacyLayerConstructor, &original->legacy_type); + original->copy(result); + return result; +} + +void layersDelete(Layers* layers) +{ + delete layers; +} + +void layersCopy(Layers* source, Layers* destination) +{ + source->copy(destination); +} + +void layersValidate(Layers* layers) +{ + layers->validate(); +} + +void layersSave(PackStream* stream, Layers* layers) +{ + layers->save(stream); +} + +void layersLoad(PackStream* stream, Layers* layers) +{ + layers->load(stream); +} + +const char* layersGetName(Layers* layers, int layer) +{ + return "TODO"; +} + +void layersSetName(Layers* layers, int layer, const char* name) +{ + layers->getLayer(layer)->setName(name); +} + +void layersClear(Layers* layers) +{ + layers->clear(); +} + +int layersCount(Layers* layers) +{ + return layers->count(); +} + +void* layersGetLayer(Layers* layers, int layer) +{ + LegacyLayer* legacy = (LegacyLayer*)(layers->getLayer(layer)); + return legacy->getLegacyDefinition(); +} + +int layersAddLayer(Layers* layers, void* definition) +{ + int position; + LegacyLayer* legacy = new LegacyLayer(layers, &layers->legacy_type); + if (definition) + { + layers->legacy_type.callback_copy(definition, legacy->getLegacyDefinition()); + } + position = layers->addLayer(legacy); + return position; +} + +void layersDeleteLayer(Layers* layers, int layer) +{ + layers->removeLayer(layer); +} + +void layersMove(Layers* layers, int layer, int new_position) +{ + layers->moveLayer(layer, new_position); +} diff --git a/src/definition/Layers.h b/src/definition/Layers.h new file mode 100644 index 0000000..3f08496 --- /dev/null +++ b/src/definition/Layers.h @@ -0,0 +1,98 @@ +#ifndef LAYERS_H +#define LAYERS_H + +#include "definition_global.h" + +#include "PackStream.h" +#include "LegacyLayer.h" + +#ifdef __cplusplus + +#include "BaseDefinition.h" + +namespace paysages { +namespace definition { + +class Layers; + +typedef BaseDefinition* (*LayerConstructor)(Layers* parent); + +/** + * @brief Layers of definitions, ideally all of the same type. + */ +class DEFINITIONSHARED_EXPORT Layers:public BaseDefinition +{ +public: + Layers(BaseDefinition* parent, LayerConstructor layer_constructor, LayerType* legacy_type=0); + virtual ~Layers(); + + virtual void copy(Layers* destination); + + void setMaxLayerCount(int max_layer_count); + + int count(); + BaseDefinition* getLayer(int position); + int findLayer(BaseDefinition* layer); + + /** + * @brief Add a new layer + * + * This method takes ownership of the layer definition. In any case, it will be deleted by + * this object (even if the layer could not be added). + * @return The position of the new layer, -1 if it couldn't be added. + */ + int addLayer(BaseDefinition* layer); + int addLayer(); + void removeLayer(int position); + void removeLayer(BaseDefinition* layer); + void moveLayer(int old_position, int new_position); + void moveLayer(BaseDefinition* layer, int new_position); + void clear(); + + // Transitional data storage + LayerType legacy_type; + +private: + LayerConstructor layer_constructor; + int max_layer_count; + QList layers; + BaseDefinition* null_layer; +}; + +} +} + +extern "C" { +#endif + +// Transitional C-API + +#ifndef __cplusplus +typedef struct Layers Layers; +#endif + +DEFINITIONSHARED_EXPORT Layers* layersCreate(LayerType type, int max_layer_count); +DEFINITIONSHARED_EXPORT Layers* layersCreateCopy(Layers* original); +DEFINITIONSHARED_EXPORT void layersDelete(Layers* layers); + +DEFINITIONSHARED_EXPORT void layersCopy(Layers* source, Layers* destination); +DEFINITIONSHARED_EXPORT void layersValidate(Layers* layers); + +DEFINITIONSHARED_EXPORT void layersSave(PackStream* stream, Layers* layers); +DEFINITIONSHARED_EXPORT void layersLoad(PackStream* stream, Layers* layers); + +DEFINITIONSHARED_EXPORT const char* layersGetName(Layers* layers, int layer); +DEFINITIONSHARED_EXPORT void layersSetName(Layers* layers, int layer, const char* name); + +DEFINITIONSHARED_EXPORT void layersClear(Layers* layers); +DEFINITIONSHARED_EXPORT int layersCount(Layers* layers); +DEFINITIONSHARED_EXPORT void* layersGetLayer(Layers* layers, int layer); +DEFINITIONSHARED_EXPORT int layersAddLayer(Layers* layers, void* definition); +DEFINITIONSHARED_EXPORT void layersDeleteLayer(Layers* layers, int layer); +DEFINITIONSHARED_EXPORT void layersMove(Layers* layers, int layer, int new_position); + +#ifdef __cplusplus +} +#endif + +#endif // LAYERS_H diff --git a/src/definition/LegacyLayer.cpp b/src/definition/LegacyLayer.cpp new file mode 100644 index 0000000..ce9fc2d --- /dev/null +++ b/src/definition/LegacyLayer.cpp @@ -0,0 +1,32 @@ +#include "LegacyLayer.h" + +LegacyLayer::LegacyLayer(BaseDefinition* parent, LayerType* type): + BaseDefinition(parent), type(*type) +{ + legacy = type->callback_create(); +} + +LegacyLayer::~LegacyLayer() +{ + type.callback_delete(legacy); +} + +void LegacyLayer::save(PackStream* pack) +{ + type.callback_save(pack, legacy); +} + +void LegacyLayer::load(PackStream* pack) +{ + type.callback_load(pack, legacy); +} + +void LegacyLayer::copy(LegacyLayer* destination) +{ + type.callback_copy(legacy, destination->legacy); +} + +void LegacyLayer::validate() +{ + type.callback_validate(legacy); +} diff --git a/src/definition/LegacyLayer.h b/src/definition/LegacyLayer.h new file mode 100644 index 0000000..cef1762 --- /dev/null +++ b/src/definition/LegacyLayer.h @@ -0,0 +1,50 @@ +#ifndef LEGACYLAYER_H +#define LEGACYLAYER_H + +#include + +typedef void* (*LayerCallbackCreate)(); +typedef void (*LayerCallbackDelete)(void* layer); +typedef void (*LayerCallbackCopy)(void* source, void* definition); +typedef void (*LayerCallbackValidate)(void* layer); +typedef void (*LayerCallbackSave)(PackStream* stream, void* layer); +typedef void (*LayerCallbackLoad)(PackStream* stream, void* layer); + +typedef struct { + LayerCallbackCreate callback_create; + LayerCallbackDelete callback_delete; + LayerCallbackCopy callback_copy; + LayerCallbackValidate callback_validate; + LayerCallbackSave callback_save; + LayerCallbackLoad callback_load; +} LayerType; + +#ifdef __cplusplus + +#include + +/** + * @brief Wrapper around the old LayerType, used by C code. + */ +class LegacyLayer:public BaseDefinition +{ +public: + LegacyLayer(BaseDefinition* parent, LayerType* type); + virtual ~LegacyLayer(); + + virtual void save(PackStream* pack); + virtual void load(PackStream* pack); + + virtual void copy(LegacyLayer* destination); + virtual void validate(); + + inline void* getLegacyDefinition() { return legacy; } + +private: + LayerType type; + void* legacy; +}; + +#endif + +#endif // LEGACYLAYER_H diff --git a/src/definition/definition.pro b/src/definition/definition.pro index a3d9a03..39c6b65 100644 --- a/src/definition/definition.pro +++ b/src/definition/definition.pro @@ -12,11 +12,15 @@ TEMPLATE = lib DEFINES += DEFINITION_LIBRARY SOURCES += \ - BaseDefinition.cpp + BaseDefinition.cpp \ + Layers.cpp \ + LegacyLayer.cpp HEADERS +=\ definition_global.h \ - BaseDefinition.h + BaseDefinition.h \ + Layers.h \ + LegacyLayer.h unix:!symbian { maemo5 { diff --git a/src/editing/baseform.h b/src/editing/baseform.h index 80dc3aa..1531909 100644 --- a/src/editing/baseform.h +++ b/src/editing/baseform.h @@ -12,7 +12,7 @@ #include "PackStream.h" #include "rendering/tools/lighting.h" #include "rendering/noise.h" -#include "rendering/layers.h" +#include "Layers.h" class QPushButton; class QComboBox; diff --git a/src/editing/baseformlayer.cpp b/src/editing/baseformlayer.cpp index b88ed28..125be51 100644 --- a/src/editing/baseformlayer.cpp +++ b/src/editing/baseformlayer.cpp @@ -135,7 +135,7 @@ void BaseFormLayer::layerRenamedEvent(int layer, QString new_name) void BaseFormLayer::layerSelectedEvent(int layer) { - if (_layers_modified) + if (_layers_modified && layer >= 0) { layerReadCurrentFrom(layersGetLayer(_layers_modified, layer)); } diff --git a/src/editing/baseformlayer.h b/src/editing/baseformlayer.h index 2f7a1ae..f89ece5 100644 --- a/src/editing/baseformlayer.h +++ b/src/editing/baseformlayer.h @@ -4,7 +4,7 @@ /* Base form, with automatic layer control */ #include "baseform.h" -#include "rendering/layers.h" +#include "Layers.h" class BaseFormLayer:public BaseForm { diff --git a/src/editing/common/freelayerhelper.h b/src/editing/common/freelayerhelper.h index af6178b..0cbec29 100644 --- a/src/editing/common/freelayerhelper.h +++ b/src/editing/common/freelayerhelper.h @@ -2,7 +2,7 @@ #define _EDITING_COMMON_FREELAYERHELPER_H_ #include -#include "rendering/layers.h" +#include "Layers.h" class QTableWidget; class QPushButton; diff --git a/src/editing/dialoglayers.h b/src/editing/dialoglayers.h index 8aca793..9fb08a2 100644 --- a/src/editing/dialoglayers.h +++ b/src/editing/dialoglayers.h @@ -6,7 +6,7 @@ #include #include "tools.h" -#include "rendering/layers.h" +#include "Layers.h" class DialogLayers; class BaseFormLayer; diff --git a/src/editing/inputlayers.h b/src/editing/inputlayers.h index 90565eb..e66c44f 100644 --- a/src/editing/inputlayers.h +++ b/src/editing/inputlayers.h @@ -4,7 +4,7 @@ #include #include "baseinput.h" #include "dialoglayers.h" -#include "rendering/layers.h" +#include "Layers.h" class InputLayers:public BaseInput { diff --git a/src/exploring/exploring.pro b/src/exploring/exploring.pro index de60b83..ccc18dd 100644 --- a/src/exploring/exploring.pro +++ b/src/exploring/exploring.pro @@ -33,3 +33,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/../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/../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 diff --git a/src/rendering/atmosphere/public.h b/src/rendering/atmosphere/public.h index 9a9e53f..0bf20fb 100644 --- a/src/rendering/atmosphere/public.h +++ b/src/rendering/atmosphere/public.h @@ -6,7 +6,6 @@ #include "../tools/euclid.h" #include "../tools/color.h" #include "PackStream.h" -#include "../layers.h" #include "../shared/types.h" #ifdef __cplusplus diff --git a/src/rendering/clouds/public.h b/src/rendering/clouds/public.h index 52ee011..b1698c8 100644 --- a/src/rendering/clouds/public.h +++ b/src/rendering/clouds/public.h @@ -7,7 +7,7 @@ #include "../tools/curve.h" #include "../tools/euclid.h" #include "../noise.h" -#include "../layers.h" +#include "Layers.h" #ifdef __cplusplus extern "C" { diff --git a/src/rendering/layers.c b/src/rendering/layers.c deleted file mode 100644 index f4791fe..0000000 --- a/src/rendering/layers.c +++ /dev/null @@ -1,210 +0,0 @@ -#include "layers.h" - -#include -#include -#include - -#define LAYERS_MAX_NAME_LENGTH 50 - -typedef struct -{ - void* definition; - char name[LAYERS_MAX_NAME_LENGTH + 1]; -} LayerInfo; - -struct Layers { - LayerType type; - int count; - int max_count; - void* null_layer; - LayerInfo* layers_info; -}; - -Layers* layersCreate(LayerType type, int max_layer_count) -{ - Layers* result = malloc(sizeof(Layers)); - - result->type = type; - result->count = 0; - result->max_count = max_layer_count; - result->null_layer = type.callback_create(); - result->layers_info = malloc(sizeof(LayerInfo) * max_layer_count); - - return result; -} - -Layers* layersCreateCopy(Layers* original) -{ - Layers* result = layersCreate(original->type, original->max_count); - layersCopy(original, result); - return result; -} - -void layersDelete(Layers* layers) -{ - int i; - for (i = 0; i < layers->count; i++) - { - layers->type.callback_delete(layers->layers_info[i].definition); - } - - layers->type.callback_delete(layers->null_layer); - free(layers->layers_info); - free(layers); -} - -void layersCopy(Layers* source, Layers* destination) -{ - int i; - - assert(source->type.callback_copy == destination->type.callback_copy); - assert(source->type.callback_create == destination->type.callback_create); - assert(source->type.callback_delete == destination->type.callback_delete); - assert(source->type.callback_load == destination->type.callback_load); - assert(source->type.callback_save == destination->type.callback_save); - assert(source->type.callback_validate == destination->type.callback_validate); - assert(source->max_count == destination->max_count); - - /* TODO Optimize by reusing common layers */ - while (destination->count > 0) - { - layersDeleteLayer(destination, 0); - } - for (i = 0; i < source->count; i++) - { - layersAddLayer(destination, source->layers_info[i].definition); - layersSetName(destination, i, layersGetName(source, i)); - } -} - -void layersValidate(Layers* layers) -{ - int i; - - for (i = 0; i < layers->count; i++) - { - layers->type.callback_validate(layers->layers_info[i].definition); - layers->layers_info[i].name[LAYERS_MAX_NAME_LENGTH] = '\0'; - } -} - -void layersSave(PackStream* stream, Layers* layers) -{ - int i; - - packWriteInt(stream, &layers->count); - for (i = 0; i < layers->count; i++) - { - packWriteString(stream, layers->layers_info[i].name, LAYERS_MAX_NAME_LENGTH); - layers->type.callback_save(stream, layers->layers_info[i].definition); - } -} - -void layersLoad(PackStream* stream, Layers* layers) -{ - int i; - - packReadInt(stream, &layers->count); - for (i = 0; i < layers->count; i++) - { - packReadString(stream, layers->layers_info[i].name, LAYERS_MAX_NAME_LENGTH); - layers->type.callback_load(stream, layers->layers_info[i].definition); - } - layersValidate(layers); -} - -const char* layersGetName(Layers* layers, int layer) -{ - if (layer >= 0 && layer < layers->count) - { - return layers->layers_info[layer].name; - } - else - { - return ""; - } -} - -void layersSetName(Layers* layers, int layer, const char* name) -{ - if (layer >= 0 && layer < layers->count) - { - strncpy(layers->layers_info[layer].name, name, LAYERS_MAX_NAME_LENGTH); - } -} - -void layersClear(Layers* layers) -{ - while (layersCount(layers)) - { - layersDeleteLayer(layers, 0); - } -} - -int layersCount(Layers* layers) -{ - return layers->count; -} - -void* layersGetLayer(Layers* layers, int layer) -{ - if (layer >= 0 && layer < layers->count) - { - return layers->layers_info[layer].definition; - } - else - { - return layers->null_layer; - } -} - -int layersAddLayer(Layers* layers, void* definition) -{ - if (layers->count < layers->max_count) - { - layers->layers_info[layers->count].definition = layers->type.callback_create(); - if (definition) - { - layers->type.callback_copy(definition, layers->layers_info[layers->count].definition); - } - - layers->count++; - layersSetName(layers, layers->count - 1, "unnamed"); - return layers->count - 1; - } - else - { - return -1; - } -} - -void layersDeleteLayer(Layers* layers, int layer) -{ - if (layer >= 0 && layer < layers->count) - { - layers->type.callback_delete(layers->layers_info[layer].definition); - if (layers->count > 1 && layer < layers->count - 1) - { - memmove(layers->layers_info + layer, layers->layers_info + layer + 1, sizeof(LayerInfo) * (layers->count - layer - 1)); - } - layers->count--; - } -} - -void layersMove(Layers* layers, int layer, int new_position) -{ - if (layer >= 0 && layer < layers->count && new_position != layer && new_position >= 0 && new_position < layers->count) - { - LayerInfo temp; - temp = layers->layers_info[layer]; - if (new_position > layer) - { - memmove(layers->layers_info + layer, layers->layers_info + layer + 1, sizeof(LayerInfo) * (new_position - layer)); - } - else - { - memmove(layers->layers_info + new_position + 1, layers->layers_info + new_position, sizeof(LayerInfo) * (layer - new_position)); - } - layers->layers_info[new_position] = temp; - } -} diff --git a/src/rendering/layers.h b/src/rendering/layers.h deleted file mode 100644 index f2bb1db..0000000 --- a/src/rendering/layers.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _PAYSAGES_LAYERS_H_ -#define _PAYSAGES_LAYERS_H_ - -/* Factorized layer management (with names) */ - -#include "rendering_global.h" -#include "PackStream.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void* (*LayerCallbackCreate)(); -typedef void (*LayerCallbackDelete)(void* layer); -typedef void (*LayerCallbackCopy)(void* source, void* definition); -typedef void (*LayerCallbackValidate)(void* layer); -typedef void (*LayerCallbackSave)(PackStream* stream, void* layer); -typedef void (*LayerCallbackLoad)(PackStream* stream, void* layer); - -typedef struct { - LayerCallbackCreate callback_create; - LayerCallbackDelete callback_delete; - LayerCallbackCopy callback_copy; - LayerCallbackValidate callback_validate; - LayerCallbackSave callback_save; - LayerCallbackLoad callback_load; -} LayerType; - -typedef struct Layers Layers; - -RENDERINGSHARED_EXPORT Layers* layersCreate(LayerType type, int max_layer_count); -RENDERINGSHARED_EXPORT Layers* layersCreateCopy(Layers* original); -RENDERINGSHARED_EXPORT void layersDelete(Layers* layers); - -RENDERINGSHARED_EXPORT void layersCopy(Layers* source, Layers* destination); -RENDERINGSHARED_EXPORT void layersValidate(Layers* layers); - -RENDERINGSHARED_EXPORT void layersSave(PackStream* stream, Layers* layers); -RENDERINGSHARED_EXPORT void layersLoad(PackStream* stream, Layers* layers); - -RENDERINGSHARED_EXPORT const char* layersGetName(Layers* layers, int layer); -RENDERINGSHARED_EXPORT void layersSetName(Layers* layers, int layer, const char* name); - -RENDERINGSHARED_EXPORT void layersClear(Layers* layers); -RENDERINGSHARED_EXPORT int layersCount(Layers* layers); -RENDERINGSHARED_EXPORT void* layersGetLayer(Layers* layers, int layer); -RENDERINGSHARED_EXPORT int layersAddLayer(Layers* layers, void* definition); -RENDERINGSHARED_EXPORT void layersDeleteLayer(Layers* layers, int layer); -RENDERINGSHARED_EXPORT void layersMove(Layers* layers, int layer, int new_position); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/rendering/rendering.pro b/src/rendering/rendering.pro index a78c0d4..deb455e 100644 --- a/src/rendering/rendering.pro +++ b/src/rendering/rendering.pro @@ -18,7 +18,6 @@ SOURCES += main.c \ noiseperlin.c \ noisenaive.c \ noise.c \ - layers.c \ geoarea.c \ camera.c \ atmosphere/atm_render.c \ @@ -74,7 +73,6 @@ HEADERS += \ noisenaive.h \ noise.h \ main.h \ - layers.h \ geoarea.h \ camera.h \ atmosphere/public.h \ diff --git a/src/rendering/textures/public.h b/src/rendering/textures/public.h index 7d03bd8..d4daff6 100644 --- a/src/rendering/textures/public.h +++ b/src/rendering/textures/public.h @@ -2,7 +2,7 @@ #define _PAYSAGES_TEXTURES_PUBLIC_H_ #include "../rendering_global.h" -#include "rendering/layers.h" +#include "Layers.h" #include "rendering/tools/zone.h" #include "rendering/tools/lighting.h" #include "rendering/terrain/public.h" diff --git a/src/rendering/water/public.h b/src/rendering/water/public.h index 9e23578..22d6a1a 100644 --- a/src/rendering/water/public.h +++ b/src/rendering/water/public.h @@ -7,7 +7,7 @@ #include "../tools/curve.h" #include "../tools/euclid.h" #include "../noise.h" -#include "../layers.h" +#include "Layers.h" #ifdef __cplusplus extern "C" { diff --git a/src/system/PackStream.cpp b/src/system/PackStream.cpp index fe2d96f..03933af 100644 --- a/src/system/PackStream.cpp +++ b/src/system/PackStream.cpp @@ -58,6 +58,14 @@ void PackStream::write(char* value, int max_length) } } +void PackStream::write(QString value) +{ + if (stream) + { + *stream << value; + } +} + void PackStream::read(int* value) { if (stream and value and not stream->atEnd()) @@ -89,6 +97,20 @@ void PackStream::read(char* value, int max_length) } } +QString PackStream::readString() +{ + if (stream and not stream->atEnd()) + { + QString output; + *stream >> output; + return output; + } + else + { + return QString(); + } +} + // Transitional C-API PackStream* packReadFile(const char* filepath) diff --git a/src/system/PackStream.h b/src/system/PackStream.h index 12b76ed..c001ce2 100644 --- a/src/system/PackStream.h +++ b/src/system/PackStream.h @@ -5,6 +5,7 @@ #ifdef __cplusplus +#include class QFile; class QDataStream; @@ -27,10 +28,12 @@ public: void write(int* value); void write(double* value); void write(char* value, int max_length); + void write(QString value); void read(int* value); void read(double* value); void read(char* value, int max_length); + QString readString(); private: QFile* file;