-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Changes from all commits
8d368e7
45851b5
3eec2bf
ae6d278
b03829f
1c9a669
b4ee6c1
c0b02ee
3d35bbf
47528ac
77e8c10
e598b20
1150164
14ab8f6
75405c8
094d958
fab1a91
866f45c
f0c9cff
2aedb01
13cc973
11a3566
359a41d
4c61732
ec1c69e
7a99dcc
728bab5
f6b95a0
291b5a7
4beb074
9bca0ee
806dc48
4a47cb9
117a12a
b35eb9f
a5ddf66
dac9c26
949ca60
b91667f
ce5db1e
24de712
7d8b3e3
8c18fe4
a4d3713
3719cc5
725f248
01ce70e
ccda882
dc6ee0d
c2a28d5
68ee06b
a92b10d
e45f7b8
408afe4
22b296a
c18fe16
5c25f1a
8def7a7
cd596b0
0d40f96
9246da3
3a70dea
68ddc13
cb07a42
b883c88
b4fa607
e3e8bfb
867879d
38e25b1
116a39e
47238a3
2854e54
cbc78ac
02074f6
09bd86b
dfdf850
f91d0e8
11c583c
39d7b1c
47bec5a
b666d90
53c17c6
891f9fb
ea9832c
1f5d458
3ffbe3b
615791c
c346a49
3985fb4
ca6425c
3e7fa1d
7a508ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.[oa] | ||
*vgcore* | ||
.vscode/** | ||
*.txt | ||
*.out | ||
*.exe | ||
*test* | ||
*.gch |
This file was deleted.
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 |
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 ¤tEventList.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(); | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут точно деление? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
eventsPath = resourcesPath / nextLocationName / "events"; | ||
mapPath = resourcesPath / nextLocationName / mapName; | ||
} |
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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; | ||
} |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
коммент