Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Итоговый PR: mouseartiom #6

Open
wants to merge 92 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
8d368e7
added readme
stanf0rd Apr 7, 2018
45851b5
Создана базовая версия библиотеки для абстрактных классов.
Moleque Apr 7, 2018
3eec2bf
Исправлены ошибки компиляции
stanf0rd Apr 7, 2018
ae6d278
Добавлены новые классы предметов (subjects .h/.cpp).
Moleque Apr 8, 2018
b03829f
Конфликты разрешены.
Moleque Apr 8, 2018
1c9a669
Merge branch 'salman' into test
stanf0rd Apr 9, 2018
b4ee6c1
base .gitignore added
stanf0rd Apr 9, 2018
c0b02ee
Переименованны MovAble. Изменены конструкторы классов в subjects. Уда…
Moleque Apr 9, 2018
3d35bbf
abstract class Action added
stanf0rd Apr 10, 2018
47528ac
short chenged to int_fast8_t
stanf0rd Apr 10, 2018
77e8c10
Обновленный base.h
Moleque Apr 10, 2018
e598b20
merge test and salman branches
stanf0rd Apr 10, 2018
1150164
Initial commit
eadium Apr 10, 2018
14ab8f6
Merge branch 'mouseartiom' of github.com:Rasseki-Studios/rasseki.game…
eadium Apr 10, 2018
75405c8
Updated .gitignore
eadium Apr 10, 2018
094d958
added constructor/destructor
eadium Apr 10, 2018
fab1a91
Добавлены методы рассчета маршрута Move() и перемещения Step(). Id до…
Moleque Apr 11, 2018
866f45c
delete readme.md from test
Apr 11, 2018
f0c9cff
delete readme.md from test
Apr 11, 2018
2aedb01
delete readme.md from branch
Apr 11, 2018
13cc973
delete readme.md from branch
Apr 11, 2018
11a3566
Merge remote-tracking branch 'origin/salman' into salman
Apr 11, 2018
359a41d
delete readme.md from branch
Apr 11, 2018
4c61732
added getter and one color
eadium Apr 11, 2018
ec1c69e
Merge branch 'mouseartiom' of github.com:Rasseki-Studios/rasseki.game…
eadium Apr 11, 2018
7a99dcc
updated .gitignore
eadium Apr 11, 2018
728bab5
delete readme.md from branch
Apr 11, 2018
f6b95a0
Updated .gitignore
eadium Apr 11, 2018
291b5a7
Updated .gitignore
eadium Apr 11, 2018
4beb074
Merge branch 'mouseartiom' of github.com:Rasseki-Studios/rasseki.game…
eadium Apr 11, 2018
9bca0ee
const and inline added, pedantic lines swaps made
stanf0rd Apr 11, 2018
806dc48
Merge branch 'stanford' of github.com:Rasseki-Studios/rasseki.game in…
stanf0rd Apr 11, 2018
4a47cb9
Merge branch 'stanford' of github.com:Rasseki-Studios/rasseki.game in…
stanf0rd Apr 11, 2018
117a12a
ID are strings now, std::string can be used as str
stanf0rd Apr 12, 2018
b35eb9f
basic event.h and event.cpp added, class IFactory added
stanf0rd Apr 12, 2018
a5ddf66
IDs are now strings
stanf0rd Apr 12, 2018
dac9c26
id -> ID
stanf0rd Apr 12, 2018
949ca60
added namespace
eadium Apr 12, 2018
b91667f
Merge branch 'test' of github.com:Rasseki-Studios/rasseki.game into m…
eadium Apr 12, 2018
ce5db1e
Добавлены const к Get ф-циям.
Moleque Apr 12, 2018
24de712
slightly code refactored, removed namespace and added statics
eadium Apr 12, 2018
7d8b3e3
basic event reading added, base improved
stanf0rd Apr 12, 2018
8c18fe4
JV: add Qt project to Develop branch
Apr 12, 2018
a4d3713
save before move
Apr 12, 2018
3719cc5
Separate Qt project from Base, Map and Subjects
Apr 12, 2018
725f248
Remove .DS_Store from main folder
Apr 12, 2018
01ce70e
EventFabric can now read and use all event jsons
stanf0rd Apr 12, 2018
ccda882
libs were taken to libs folder
stanf0rd Apr 12, 2018
dc6ee0d
Merge branch 'stanford' into develop
stanf0rd Apr 12, 2018
c2a28d5
salman and develop branches merged
stanf0rd Apr 13, 2018
68ee06b
definition of class Movable was taken to individual file
stanf0rd Apr 13, 2018
a92b10d
fixed a small spelling error
stanf0rd Apr 13, 2018
e45f7b8
method getFromJson getting filename replaced method create
stanf0rd Apr 13, 2018
408afe4
catching exceptions in jsons, invalid events are skipping now
stanf0rd Apr 14, 2018
22b296a
Merge branch 'test' of github.com:Rasseki-Studios/rasseki.game into s…
stanf0rd Apr 14, 2018
c18fe16
fixed small spelling error
stanf0rd Apr 14, 2018
5c25f1a
EasyBMP library added
stanf0rd Apr 14, 2018
8def7a7
base transformed to item, movable and location parts
stanf0rd Apr 14, 2018
cd596b0
events support new base headers now
stanf0rd Apr 14, 2018
0d40f96
map renamed to mapdata
stanf0rd Apr 14, 2018
9246da3
mapdata updated for work with new base
stanf0rd Apr 14, 2018
3a70dea
stanford, test and mouseartiom branches are synchronized
stanf0rd Apr 14, 2018
68ddc13
updated .gitignore
eadium Apr 15, 2018
cb07a42
added eventsList but compilation fails
eadium Apr 17, 2018
b883c88
modified mapdata structure and added EventData class
eadium Apr 19, 2018
b4fa607
EventData -> EventsMapData and appropriate changes are made but this …
eadium Apr 20, 2018
e3e8bfb
added class EntityData but compilation fails though
eadium Apr 21, 2018
867879d
class EntityData made up to an end, small refactoring also
eadium Apr 21, 2018
38e25b1
removed files not corresponding to me
eadium Apr 21, 2018
116a39e
removed Qt
eadium May 1, 2018
47238a3
started work at sessions
eadium May 3, 2018
2854e54
code edited according to Google Style
eadium May 5, 2018
cbc78ac
small style improvements, new includes
stanf0rd May 7, 2018
02074f6
added GameData interfaces
eadium May 7, 2018
09bd86b
mapdata work comments for Artem
stanf0rd May 8, 2018
dfdf850
added MapScanner class
eadium May 8, 2018
f91d0e8
magic numbers were replaced ny enums
eadium May 9, 2018
11c583c
released alpha ver. of SessionData
eadium May 13, 2018
39d7b1c
Delete entitydata.cpp
eadium May 13, 2018
47bec5a
Delete entitydata.h
eadium May 13, 2018
b666d90
added validators for point and radius, removed unnecessary comments
eadium May 14, 2018
53c17c6
Merge branch 'mouseartiom' of github.com:Rasseki-Studios/rasseki.game…
eadium May 14, 2018
891f9fb
SurfaceData is now in surface.h. Namespace SessionData added.
eadium May 15, 2018
ea9832c
SurfaceData moved back to session_data.h
eadium May 15, 2018
1f5d458
added IsWalkable & GameData::Init(). Small fixes.
eadium May 15, 2018
3ffbe3b
Revert "added IsWalkable & GameData::Init(). Small fixes."
eadium May 16, 2018
615791c
session_data revived
eadium May 16, 2018
c346a49
renamed validators
eadium May 16, 2018
3985fb4
refactored code to be compilable
eadium May 16, 2018
ca6425c
changed project sructure for easier navigation
eadium May 31, 2018
3e7fa1d
synchronized with test
eadium Jun 13, 2018
7a508ea
synched with test
eadium Jun 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.[oa]
*vgcore*
.vscode/**
*.txt
*.out
*.exe
*test*
*.gch
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

11 changes: 11 additions & 0 deletions configs/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* sometimes it will be a beautiful yaml config... */

#ifndef CONFIGURATION
#define CONFIGURATION

const int step_delay = 1000000;
const int timer_delay = 50;
const int hero_icon_size = 50;
const int hero_offset = hero_icon_size/2;

#endif // CONFIGURATION
163 changes: 163 additions & 0 deletions database/items_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#include <algorithm>
#include <vector>

#include "session_data.h"
// #include "event_factory.h"
#include "artifact_factory.h"
#include "mapscanner.h"
#include "config.h"

using namespace SessionData;
using std::vector;
using std::cout;

//---------------------------------------------------------
//----------------- EventsData ----------------------------
//---------------------------------------------------------

EventsData::EventsData()
: eventMatrix(gameData.mapWidth, gameData.mapHeight, true) {
EventFactory eFactory;
eFactory.InitAll(systemData.eventsPath.u8string(), currentEventList);
PulverizeEvents(currentEventList);
}

EventsData::~EventsData() {
Coord temp;
int counter = 0;
for (temp.y = 0; temp.y < eventMatrix.getHeight(); temp.y++) {
for (temp.x = 0; temp.x < eventMatrix.getHeight(); temp.x++) {
if (eventMatrix[temp]) {
counter++;
delete eventMatrix[temp];
}
}
}
cout << counter << " events were deleted by destructor" << endl;
}

Event* EventsData::getEvent(const str key) {
return &currentEventList.at(key);
}

Event* EventsData::getEvent(Coord point) {
if (!surfaceData.CoordIsValid(point)) return NULL;
if (!eventMatrix[point]) return NULL;
if (!eventMatrix[point]->empty())
// return eventMatrix[point]->front();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

коммент

return getEvent(eventMatrix[point]->front());
else return NULL;
}

bool ComparePriorities(str lvalue, str rvalue) {
Event* left = eventsData.getEvent(lvalue);
Event* right = eventsData.getEvent(rvalue);
return left->getPriority() < right->getPriority();
};

void EventsData::PulverizeEvents(std::unordered_map<str, Event>& list) {
/*
parsing map - getting event and spraying it at the map.
get event
add event to map
*/
for (auto i : list) {
Event &event = i.second;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему reference. Вместо auto i. Можно использовать const auto& i, чтобы не копировать

int counter = 0;

Coord eventCenter = event.GetCoord();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно использовать auto, чтобы не писать лишнего. Тип сам выведется

Coord current;

for (current.x = eventCenter.x - event.getRadius();
current.x <= eventCenter.x + event.getRadius();
current.x++) {
for (current.y = eventCenter.y - event.getRadius();
current.y <= eventCenter.y + event.getRadius();
current.y++) {
counter++;
if (!eventMatrix[current]) {
eventMatrix[current] = new std::vector<str>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему, raw указатель на контейнер. Это же фиаско. Используй умные указатели

eventMatrix[current]->push_back(event.GetId());
} else {
eventMatrix[current]->push_back(event.GetId());
std::push_heap(
eventMatrix[current]->begin(),
eventMatrix[current]->end(),
ComparePriorities
);
}
}
}
cout << "event " << event.GetName() << " was sprayed " << counter << " times" << endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать логгер

}
}

void EventsData::RemoveFrontEvent(Coord point) {
Event* event = getEvent(point);
if (!event) return;
Coord center = event->GetCoord();
int radius = event->getRadius();
int counter = 0;
Coord startPos;

for (startPos.x = center.x - radius; startPos.x <= center.x + radius; startPos.x++) {
for (startPos.y = center.y - radius; startPos.y <= center.y + radius; startPos.y++) {
if ( surfaceData.CoordIsValid( startPos ) ) {
std::pop_heap(eventMatrix[startPos]->begin(),
eventMatrix[startPos]->end(),
ComparePriorities
);
eventMatrix[startPos]->pop_back();
counter++;
};
}
}
cout << counter << " events were deleted" << endl;
}

bool EventsData::EventExists(str ID) {
return currentEventList.count(ID);
}

//---------------------------------------------------------
//---------------- ArtifactsData --------------------------
//---------------------------------------------------------

ArtifactsData::ArtifactsData() {
ArtifactFactory aFactory;
aFactory.InitAll(systemData.artifactsPath.u8string(), currentArtifactsList);
}

std::shared_ptr<Artifact> ArtifactsData::getArtifact(const str key) {
return std::make_shared<Artifact> (currentArtifactsList.at(key));
}

bool ArtifactsData::ArtifactExists(str ID) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const метод

return currentArtifactsList.find(ID) != currentArtifactsList.end();
}

//---------------------------------------------------------
//--------------------- GameData --------------------------
//---------------------------------------------------------

GameData::GameData() : hero(heroID, heroName, 1, 10, heroStart) {
mapHeight = surfaceData.getHeight();
mapWidth = surfaceData.getWidth();
}

void GameData::WriteToDiary(str note) {
diaryString = note;
}

//---------------------------------------------------------
//--------------------- SystemData ------------------------
//---------------------------------------------------------

SystemData::SystemData(str _nextLocationName)
: nextLocationName(_nextLocationName) {
cout << "systemData initialized" << endl;
resourcesPath = resourcesDirectory;
artifactsPath = resourcesPath / nextLocationName / "artifacts";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут точно деление?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventsPath = resourcesPath / nextLocationName / "events";
mapPath = resourcesPath / nextLocationName / mapName;
}
70 changes: 70 additions & 0 deletions database/items_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef ITEMSDATA
#define ITEMSDATA

#include <string>
#include <experimental/filesystem>
#include <unordered_map>
#include <memory>

#include "hero.h"
#include "event_factory.h"
#include "artifact.h"
#include "surface.h"
#include "matrix.hpp"
#include "paths.h"

namespace fs = std::experimental::filesystem;

class SystemData {
public:
SystemData(str nextLocationName = defaultLocation);
fs::path resourcesPath;
fs::path artifactsPath;
fs::path eventsPath;
fs::path mapPath;

str nextLocationName; // ID of a map going to be loaded
str currentLocationName; // ID of a map loaded
};

class GameData {
// stores finished events and other stuff
public:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если это public class, то лучше использовать struct...

GameData();
Hero hero;
void WriteToDiary(str);
int mapHeight;
int mapWidth;
str diaryString; // what we are writin'
str writer; // who is writin'
bool changeInventory = true;
bool tdWorking = false;
};

class EventsData {
public:
EventsData();
~EventsData();
Event* getEvent(const str);
Event* getEvent(Coord);
bool EventExists(str);
void RemoveFrontEvent(Coord);
// more methods coming in future
private:
void PulverizeEvents(std::unordered_map<str, Event>&); //pulverizes events from eventList
Matrix<std::vector<str>*> eventMatrix;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем Матрица raw указателей? Используй умные указатели

std::unordered_map<str, Event> currentEventList;
// std::unordered_map<str, Event> globalEventList;
};

class ArtifactsData {
public:
ArtifactsData();
bool ArtifactExists(str);
std::shared_ptr<Artifact> getArtifact(const str);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const метод. 63-64

private:
std::unordered_map<str, Artifact> currentArtifactsList;
// std::unordered_map<str, Artifact> globalArtifactsList;
};

#endif
10 changes: 10 additions & 0 deletions database/session_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "session_data.h"
#include <iostream>

namespace SessionData {
SystemData systemData;
SurfaceData surfaceData;
GameData gameData;
ArtifactsData artifactsData;
EventsData eventsData;
}
14 changes: 14 additions & 0 deletions database/session_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef SESSIONDATA
#define SESSIONDATA

#include "items_data.h"

namespace SessionData {
extern SurfaceData surfaceData;
extern GameData gameData;
extern SystemData systemData;
extern ArtifactsData artifactsData;
extern EventsData eventsData;
}

#endif // SESSIONDATA
Loading