-
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 90 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,151 @@ | ||
#include "session_data.h" | ||
// #include "event_factory.h" | ||
#include "mapscanner.h" | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
using std::vector; | ||
using namespace SessionData; | ||
|
||
//--------------------------------------------------------- | ||
//----------------- EventsData ---------------------------- | ||
//--------------------------------------------------------- | ||
|
||
bool EventsData::Init() { | ||
EventFactory eFactory; | ||
str path = systemData.resourcesDirectory + systemData.nextLocationName + "/events"; | ||
eFactory.InitAll(path, currentEventList); // hardcoded just for debugging | ||
// using unique_ptr for two-dim array isn't a good idea though | ||
// std::unique_ptr<Event[][]> eventMatrix (nullptr); | ||
|
||
eventMatrix = new std::vector<Event>** [gameData.mapHeight]; | ||
for (int i = 0; i != gameData.mapHeight; i++) { | ||
eventMatrix[i] = new std::vector<Event>*; | ||
for (int j = 0; j != gameData.mapWidth; j++) { | ||
eventMatrix[i][j] = NULL; | ||
} | ||
} | ||
|
||
PulverizeEvents(currentEventList); | ||
return true; | ||
} | ||
|
||
Event* EventsData::getEvent(const str key) { | ||
return ¤tEventList.at(key); | ||
} | ||
|
||
Event* EventsData::getEvent(Coord point) { | ||
if (!surfaceData.CoordIsValid(point)) return NULL; | ||
if (!eventMatrix[point.x][point.y]) return NULL; | ||
auto ev = eventMatrix[point.x][point.y]; | ||
if (!eventMatrix[point.x][point.y]->empty()) | ||
return &eventMatrix[point.x][point.y]->front(); | ||
else return NULL; | ||
} | ||
|
||
void EventsData::PulverizeEvents(std::unordered_map<str, Event>& list) { | ||
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. интересное название метода |
||
/* | ||
parsing map - getting event and spraying it at the map. | ||
get event | ||
add event to map | ||
*/ | ||
for (auto i : list) { | ||
Event event = i.second; | ||
|
||
int width = gameData.mapWidth; | ||
int height = gameData.mapHeight; | ||
|
||
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, чтобы не писать лишнего. Тип сам выведется |
||
if (eventCenter.x > width || eventCenter.y > height) throw "coordinates are out of range"; | ||
if (eventCenter.x < 0 || eventCenter.y < 0) throw "invalid coordinates"; | ||
|
||
for (int i = eventCenter.x - event.getRadius(); i <= eventCenter.x + event.getRadius(); i++) { | ||
for (int j = eventCenter.y - event.getRadius(); j <= eventCenter.y + event.getRadius(); j++) { | ||
|
||
if ( | ||
eventCenter.y + event.getRadius() > height || | ||
eventCenter.x + event.getRadius() > width || | ||
eventCenter.y - event.getRadius() < 0 || | ||
eventCenter.x - event.getRadius() < 0 | ||
) break; //total size of event mark exceeded the map | ||
|
||
// if (!SurfaceMap::getSurface(eventCenter)) break; | ||
|
||
if (!eventMatrix[eventCenter.x][eventCenter.y]) { | ||
eventMatrix[eventCenter.x][eventCenter.y] = new std::vector<Event>; | ||
eventMatrix[eventCenter.x][eventCenter.y]->push_back(event); | ||
} | ||
else { | ||
eventMatrix[eventCenter.x][eventCenter.y]->push_back(event); | ||
|
||
std::push_heap( // SIC! that wasn't tested | ||
eventMatrix[eventCenter.x][eventCenter.y]->begin(), | ||
eventMatrix[eventCenter.x][eventCenter.y]->end(), | ||
[](Event& a, Event& b) { | ||
return a.getPriority() < b.getPriority(); | ||
} | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void EventsData::RemoveFrontEvent(Coord point) { | ||
Event* event = getEvent(point); | ||
Coord center = event->GetCoord(); | ||
int radius = event->getRadius(); | ||
|
||
for (int i = center.x - radius ; i < center.x + radius; i++) { | ||
for (int j = center.y - radius ; j < center.y + radius; j++) { | ||
if ( surfaceData.CoordIsValid( {i, j} ) ) { | ||
std::pop_heap(eventMatrix[i][j]->begin(), | ||
eventMatrix[i][j]->end(), | ||
[](Event& a, Event& b) { | ||
return a.getPriority() < b.getPriority(); | ||
} ); | ||
}; | ||
} | ||
} | ||
} | ||
|
||
bool EventsData::EventExists(str ID) { | ||
return currentEventList.count(ID); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
//---------------- ArtifactsData -------------------------- | ||
//--------------------------------------------------------- | ||
|
||
bool ArtifactsData::Init() { | ||
ArtifactFactory aFactory; | ||
str path = systemData.resourcesDirectory + systemData.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. этот путь должен передаваться в конструкторе |
||
aFactory.InitAll(path, currentArtifactsList); | ||
return true; | ||
} | ||
|
||
Artifact* ArtifactsData::getArtifact(const str key) { | ||
return ¤tArtifactsList.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.count(ID); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
//--------------------- GameData -------------------------- | ||
//--------------------------------------------------------- | ||
|
||
|
||
|
||
//--------------------------------------------------------- | ||
//--------------------- SystemData ------------------------ | ||
//--------------------------------------------------------- | ||
|
||
SystemData::SystemData(str _nextLocationName) | ||
: | ||
resourcesDirectory("resources/"), | ||
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. это должно задаваться ещё выше |
||
nextLocationName(_nextLocationName), | ||
mapName("map") { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef ITEMSDATA | ||
#define ITEMSDATA | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include "hero.h" | ||
#include "event_factory.h" | ||
#include "artifact.h" | ||
// #include "artifact_factory.h" | ||
#include "surface.h" //here is SurfaceData, temporary solution. | ||
|
||
class SystemData { | ||
public: | ||
SystemData(str nextLocationName = "default_location"); | ||
str resourcesDirectory; // directory with all the resources | ||
str nextLocationName; // ID of a map going to be loaded | ||
str currentLocationName; // ID of a map loaded | ||
str mapName; // name of the .bmp file | ||
}; | ||
|
||
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... |
||
int mapHeight; | ||
int mapWidth; | ||
str diaryString; // what we are writin' | ||
str character; // who is writin' | ||
}; | ||
|
||
class EventsData { | ||
public: | ||
bool Init(); | ||
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 | ||
std::vector<Event> ***eventMatrix; | ||
// std::unique_ptr<Event[][]> eventMatrix; | ||
std::unordered_map<str, Event> currentEventList; | ||
// std::unordered_map<str, Event> globalEventList; | ||
}; | ||
|
||
class ArtifactsData { | ||
public: | ||
bool Init(); | ||
bool ArtifactExists(str); | ||
Artifact* getArtifact(const str); | ||
private: | ||
std::unordered_map<str, Artifact> currentArtifactsList; | ||
// std::unordered_map<str, Artifact> globalArtifactsList; | ||
}; | ||
|
||
#endif //SESSION |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "session_data.h" | ||
#include <iostream> | ||
|
||
namespace SessionData { | ||
SystemData systemData; | ||
GameData gameData; | ||
SurfaceData surfaceData; | ||
EventsData eventsData; | ||
ArtifactsData artifactsData; | ||
|
||
str diaryString; | ||
str writer; | ||
|
||
// hero initialization | ||
std::string name = "Moleque"; | ||
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. это не должно инициализироваться тут |
||
std::string id = "super_hero"; | ||
Coord start(200, 200); | ||
Hero hero(id, name, 1, 10, start); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef SESSIONDATA | ||
#define SESSIONDATA | ||
|
||
#include "items_data.h" | ||
|
||
namespace SessionData { | ||
extern SurfaceData surfaceData; | ||
extern GameData gameData; | ||
extern SystemData systemData; | ||
extern ArtifactsData artifactsData; | ||
// extern CreatureData creatureData; | ||
extern EventsData eventsData; | ||
// hero initialization | ||
extern Hero hero; | ||
extern str diaryString; | ||
extern str writer; | ||
} | ||
|
||
#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.
почему используется двойной указатель на вектор?
это же очень не очень