Skip to content

Commit

Permalink
Changes for linux #201
Browse files Browse the repository at this point in the history
  • Loading branch information
kremius committed Nov 14, 2016
1 parent 78ed193 commit c95f6fe
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions sources/FastSerializer.cpp
Expand Up @@ -19,10 +19,10 @@ static_assert(
sizeof(bool) == 1,
"Unsupported platform, sizeof(bool) should be 1!");

FastSerializer::FastSerializer()
FastSerializer::FastSerializer(int size)
: index_(0)
{
data_.resize(DEFAULT_SIZE);
data_.resize(size);
}

FastSerializer::~FastSerializer()
Expand Down
2 changes: 1 addition & 1 deletion sources/FastSerializer.h
Expand Up @@ -15,7 +15,7 @@ class FastSerializer
const T& value);
public:
static const int DEFAULT_SIZE = 32 * 1024 * 1024;
FastSerializer();
FastSerializer(int size = DEFAULT_SIZE);
~FastSerializer();

void ResetIndex()
Expand Down
8 changes: 8 additions & 0 deletions sources/MapEditor.cpp
Expand Up @@ -288,13 +288,21 @@ void MapEditor::LoadMapgen(const QString& name)
void MapEditor::fix_borders(int *posx, int *posy)
{
if (*posx < 0)
{
*posx = 0;
}
if (*posx >= static_cast<int>(editor_map_.size()))
{
*posx = static_cast<int>(editor_map_.size()) - 1;
}
if (*posy < 0)
{
*posy = 0;
}
if (*posy >= static_cast<int>(editor_map_[0].size()))
{
*posy = static_cast<int>(editor_map_[0].size()) - 1;
}
}

void MapEditor::SetPointer(int posx, int posy)
Expand Down
4 changes: 3 additions & 1 deletion sources/MapEditor.h
Expand Up @@ -13,6 +13,8 @@
#include <QKeyEvent>
#include <QVector>

typedef std::map<QString, QByteArray> MapgenVariablesType;

class MapEditor: public QObject
{
Q_OBJECT
Expand All @@ -23,7 +25,7 @@ class MapEditor: public QObject

QString item_type;

std::map<QString, QString> variables;
MapgenVariablesType variables;

QGraphicsPixmapItem* pixmap_item;
};
Expand Down
6 changes: 4 additions & 2 deletions sources/core/ObjectFactory.cpp
Expand Up @@ -11,6 +11,8 @@
#include "net/NetworkMessagesTypes.h"
#include "AutogenMetadata.h"

#include "MapEditor.h"

ObjectFactory::ObjectFactory(IGame* game)
{
objects_table_.resize(100);
Expand Down Expand Up @@ -94,7 +96,7 @@ void ObjectFactory::SaveMapHeader(FastSerializer& savefile)
savefile << game_->GetMap().GetDepth();

// Save player table
savefile << players_table_.size();
savefile << static_cast<quint32>(players_table_.size());
for (auto it = players_table_.begin(); it != players_table_.end(); ++it)
{
savefile << it->first;
Expand Down Expand Up @@ -264,7 +266,7 @@ void ObjectFactory::LoadFromMapGen(const QString& name)
}
//qDebug() << "Success!";

std::map<QString, QByteArray> variables;
MapgenVariablesType variables;
WrapReadMessage(ss, variables);

for (auto it = variables.begin(); it != variables.end(); ++it)
Expand Down
2 changes: 1 addition & 1 deletion sources/core/StreamWrapper.h
Expand Up @@ -21,7 +21,7 @@ inline FastSerializer& WrapWriteMessage(
FastSerializer& file,
std::map<KeyType, ValueType>& to_write)
{
file << to_write.size();
file << static_cast<quint32>(to_write.size());
for (auto it = to_write.begin(); it != to_write.end(); ++it)
{
WrapWriteMessage(file, it->first);
Expand Down
2 changes: 1 addition & 1 deletion sources/core/objects/Projectiles.cpp
Expand Up @@ -3,7 +3,7 @@

FastSerializer& operator<<(FastSerializer& file, const std::vector<Dir>& s)
{
file << s.size();
file << static_cast<quint32>(s.size());
for (auto it : s)
{
file << it;
Expand Down
2 changes: 1 addition & 1 deletion sources/core/objects/Tile.h
Expand Up @@ -10,7 +10,7 @@
template<class T>
FastSerializer& operator<<(FastSerializer& file, const std::vector<IdPtr<T>>& content)
{
file << content.size();
file << static_cast<quint32>(content.size());
for (auto it = content.begin(); it != content.end(); ++it)
{
file << it->Id();
Expand Down
4 changes: 2 additions & 2 deletions sources/representation/ViewInfo.cpp
Expand Up @@ -6,13 +6,13 @@ FastSerializer& operator<<(FastSerializer& file, ViewInfo& view_info)
{
WrapWriteMessage(file, view_info.base_frameset_);

file << view_info.underlays_.size();
file << static_cast<quint32>(view_info.underlays_.size());
for (auto it = view_info.underlays_.begin(); it != view_info.underlays_.end(); ++it)
{
WrapWriteMessage(file, *it);
}

file << view_info.overlays_.size();
file << static_cast<quint32>(view_info.overlays_.size());
for (auto it = view_info.overlays_.begin(); it != view_info.overlays_.end(); ++it)
{
WrapWriteMessage(file, *it);
Expand Down
24 changes: 13 additions & 11 deletions sources/representation/qt/mapeditorform.cpp
Expand Up @@ -347,20 +347,21 @@ void MapEditorForm::on_listWidgetVariables_itemSelectionChanged()
return;
}

QString& variable_value = ee->variables[ui->listWidgetVariables->currentItem()->text()];
QByteArray& variable_value = ee->variables[ui->listWidgetVariables->currentItem()->text()];

ui->lineEditRaw->setText(variable_value);
ui->lineEditRaw->setText(variable_value.toHex());

std::stringstream ss;
ss << variable_value.toStdString();
// TODO: As string

// FastDeserializer deserializer(variable_value.data(), variable_value.size());

QString parsed_value;
if (WrapReadMessage(ss, parsed_value).fail())
/*QString parsed_value;
if (WrapReadMessage(deserializer, parsed_value))
{
parsed_value = "PARSING_ERROR";
}
ui->lineEditAsString->setText(parsed_value);
ui->lineEditAsString->setText(parsed_value);*/
}

void MapEditorForm::on_lineEditRaw_returnPressed()
Expand All @@ -378,9 +379,9 @@ void MapEditorForm::on_lineEditRaw_returnPressed()



QString& variable_value = ee->variables[ui->listWidgetVariables->currentItem()->text()];
QByteArray& variable_value = ee->variables[ui->listWidgetVariables->currentItem()->text()];

variable_value = ui->lineEditRaw->text();
variable_value = QByteArray::fromHex(ui->lineEditRaw->text().toUtf8());

on_listWidgetVariables_itemSelectionChanged();
UpdateVariablesColor(*ee);
Expand All @@ -401,7 +402,8 @@ void MapEditorForm::on_lineEditAsString_returnPressed()
return;
}

QString& variable_value = ee->variables[ui->listWidgetVariables->currentItem()->text()];
// TODO: reimplement this
/*QString& variable_value = ee->variables[ui->listWidgetVariables->currentItem()->text()];
std::stringstream ss;
QString loc = ui->lineEditAsString->text();
Expand All @@ -410,7 +412,7 @@ void MapEditorForm::on_lineEditAsString_returnPressed()
variable_value = QString::fromStdString(ss.str());
on_listWidgetVariables_itemSelectionChanged();
UpdateVariablesColor(*ee);
UpdateVariablesColor(*ee);*/
}

void MapEditorForm::on_listWidgetTurf_clicked(const QModelIndex&index)
Expand Down
3 changes: 3 additions & 0 deletions sources/representation/qt/mapeditorform.h
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "MapEditor.h"
#include "FastSerializer.h"

namespace Ui {
class MapEditorForm;
Expand Down Expand Up @@ -82,6 +83,8 @@ private slots:
std::vector<QString> types_;
std::vector<QString> turf_types_;

FastSerializer serializer_;

Ui::MapEditorForm *ui;
};

Expand Down

0 comments on commit c95f6fe

Please sign in to comment.