-
Notifications
You must be signed in to change notification settings - Fork 3
/
Storages.h
68 lines (60 loc) · 2.78 KB
/
Storages.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef _STORAGES_H_
#define _STORAGES_H_
#include "Factory.h"
struct StorageDrawer : public Storage {
std::vector<AccessInv> accesses;
std::vector<SharedItemFilter> filters;
StorageDrawer(Factory &factory, decltype(accesses) accesses, decltype(filters) filters)
:Storage(factory), accesses(std::move(accesses)), filters(std::move(filters)) {}
SharedPromise<std::monostate> update() override;
std::optional<int> sinkPriority(const Item&) override;
std::pair<int, SharedPromise<std::monostate>> sink(const ItemStack&, size_t slot) override;
};
struct ProviderDrawer : Provider {
StorageDrawer &drawer;
size_t slot;
ProviderDrawer(StorageDrawer &drawer, size_t slot, int size)
:Provider(drawer.factory, size, std::numeric_limits<int>::min()), drawer(drawer), slot(slot) {}
SharedPromise<std::monostate> extract(int size, size_t slot) override;
};
struct StorageChest : Storage {
std::vector<AccessInv> accesses;
std::vector<SharedItemStack> content;
size_t slotToSink;
StorageChest(Factory &factory, decltype(accesses) accesses)
:Storage(factory), accesses(std::move(accesses)) {}
void endOfCycle() override { content.clear(); }
SharedPromise<std::monostate> update() override;
std::optional<int> sinkPriority(const Item&) override;
std::pair<int, SharedPromise<std::monostate>> sink(const ItemStack&, size_t slot) override;
};
struct ProviderChest : Provider {
StorageChest &chest;
size_t slot;
ProviderChest(StorageChest &chest, size_t slot, int size)
:Provider(chest.factory, size, -size), chest(chest), slot(slot) {}
SharedPromise<std::monostate> extract(int size, size_t slot) override;
};
struct AccessME : AccessInv {
std::string me;
int entry;
AccessME(std::string client, std::string addr, int sideInv, int sideBus, int entry, std::string me = "me_interface")
:AccessInv(std::move(client), std::move(addr), sideInv, sideBus), me(std::move(me)), entry(entry) {}
};
struct StorageME : Storage {
std::vector<AccessME> accesses;
std::unordered_map<std::shared_ptr<Item>, const AccessME*, SharedItemHash, SharedItemEqual> accessForItem;
StorageME(Factory &factory, std::vector<AccessME> accesses) :Storage(factory), accesses(std::move(accesses)) {}
void endOfCycle() override { accessForItem.clear(); }
SharedPromise<std::monostate> update() override;
std::optional<int> sinkPriority(const Item&) override { return std::numeric_limits<int>::min(); }
std::pair<int, SharedPromise<std::monostate>> sink(const ItemStack&, size_t slot) override;
};
struct ProviderME : Provider {
StorageME &me;
SharedItem item;
ProviderME(StorageME &me, SharedItem item, int size)
:Provider(me.factory, size, std::numeric_limits<int>::max()), me(me), item(std::move(item)) {}
SharedPromise<std::monostate> extract(int size, size_t slot) override;
};
#endif