Skip to content

Commit a88e373

Browse files
committed
Pair API changes; Economy interface
1 parent 8b87621 commit a88e373

File tree

5 files changed

+122
-11
lines changed

5 files changed

+122
-11
lines changed

include/Langulus/Asset.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
///
88
#pragma once
99
#include "IO.hpp"
10-
#include <Langulus/Flow/Factory.hpp>
10+
#include <Langulus/Flow/Producible.hpp>
1111
#include <Langulus/Math/LOD.hpp>
1212

1313

include/Langulus/Economy.hpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
///
2+
/// Langulus::Entity
3+
/// Copyright (c) 2013 Dimo Markov <[email protected]>
4+
/// Part of the Langulus framework, see https://langulus.com
5+
///
6+
/// SPDX-License-Identifier: GPL-3.0-or-later
7+
///
8+
#pragma once
9+
#include "Entity/Thing.hpp"
10+
#include "Entity/Module.hpp"
11+
#include <Langulus/Math/Vector.hpp>
12+
13+
14+
namespace Langulus::A
15+
{
16+
17+
///
18+
/// Abstract economy module
19+
///
20+
struct Economy : virtual Module {
21+
LANGULUS_BASES(Module);
22+
Economy() : Resolvable {this}, Module {nullptr} {}
23+
};
24+
25+
///
26+
/// Abstract economy unit
27+
///
28+
struct EconomyUnit : virtual Unit {
29+
LANGULUS(PRODUCER) Economy;
30+
LANGULUS_BASES(Unit);
31+
EconomyUnit() : Resolvable {this} {}
32+
};
33+
34+
///
35+
/// Abstract resource
36+
///
37+
struct Resource : virtual EconomyUnit {
38+
LANGULUS(PRODUCER) Economy;
39+
LANGULUS_BASES(EconomyUnit);
40+
Resource() : Resolvable {this} {}
41+
42+
using Real = Langulus::Real;
43+
using Place = Math::Vec3;
44+
45+
virtual Count GetQuantity() const noexcept = 0;
46+
virtual Count GetQuantityLocal(const Place&, Real radius) const noexcept = 0;
47+
virtual Count GetInstanceCount() const noexcept = 0;
48+
virtual Count GetInstanceCountLocal(const Place&, Real radius) const noexcept = 0;
49+
50+
virtual Real GetSupply() const noexcept = 0;
51+
virtual Real GetSupplyLocal(const Place&, Real radius) const noexcept = 0;
52+
53+
virtual Real GetDemand() const noexcept = 0;
54+
virtual Real GetDemandLocal(const Place&, Real radius) const noexcept = 0;
55+
};
56+
57+
///
58+
/// Abstract resource instance
59+
///
60+
struct ResourceInstance : virtual EconomyUnit {
61+
LANGULUS(PRODUCER) Economy;
62+
LANGULUS_BASES(EconomyUnit);
63+
ResourceInstance() : Resolvable {this} {}
64+
65+
virtual Count GetQuantity() const noexcept = 0;
66+
virtual Count GetCapacity() const noexcept = 0;
67+
};
68+
69+
///
70+
/// Abstract converter
71+
///
72+
struct Converter : virtual EconomyUnit {
73+
LANGULUS(PRODUCER) Economy;
74+
LANGULUS_BASES(EconomyUnit);
75+
Converter() : Resolvable {this} {}
76+
77+
using Real = Langulus::Real;
78+
using Place = Math::Vec3;
79+
80+
virtual Count GetInstanceCount() const noexcept = 0;
81+
virtual Count GetInstanceCountLocal(const Place&, Real radius) const noexcept = 0;
82+
};
83+
84+
///
85+
/// Abstract converter instance
86+
///
87+
struct ConverterInstance : virtual EconomyUnit {
88+
LANGULUS(PRODUCER) Economy;
89+
LANGULUS_BASES(EconomyUnit);
90+
ConverterInstance() : Resolvable {this} {}
91+
};
92+
93+
///
94+
/// Abstract trader
95+
///
96+
struct Trader : virtual EconomyUnit {
97+
LANGULUS(PRODUCER) Economy;
98+
LANGULUS_BASES(EconomyUnit);
99+
Trader() : Resolvable {this} {}
100+
};
101+
102+
} // namespace Langulus::A

source/Runtime.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "../include/Langulus/Life.hpp"
2222
#include "../include/Langulus/Network.hpp"
2323
#include "../include/Langulus/User.hpp"
24+
#include "../include/Langulus/Economy.hpp"
2425

2526
#if LANGULUS_OS(WINDOWS)
2627
#include <Windows.h>
@@ -146,6 +147,14 @@ namespace Langulus::Entity
146147
(void)MetaDataOf<A::Ecosystem>();
147148
(void)MetaDataOf<A::Organism>();
148149

150+
(void)MetaDataOf<A::Economy>();
151+
(void)MetaDataOf<A::EconomyUnit>();
152+
(void)MetaDataOf<A::Resource>();
153+
(void)MetaDataOf<A::ResourceInstance>();
154+
(void)MetaDataOf<A::Converter>();
155+
(void)MetaDataOf<A::ConverterInstance>();
156+
(void)MetaDataOf<A::Trader>();
157+
149158
(void)MetaDataOf<A::Network>();
150159
(void)MetaDataOf<A::NetworkUnit>();
151160
(void)MetaDataOf<A::Client>();
@@ -165,7 +174,7 @@ namespace Langulus::Entity
165174
// First-stage destruction: tear down any potential circular
166175
// references
167176
for (auto list : mModules) {
168-
for (auto& mod : list.mValue)
177+
for (auto& mod : list.GetValue())
169178
mod->Teardown();
170179
}
171180

@@ -187,7 +196,7 @@ namespace Langulus::Entity
187196
if (mLibraries) {
188197
Logger::Error(this, ": Can't unload last module(s): ");
189198
for (auto library : mLibraries)
190-
Logger::Append(library.mKey, " ");
199+
Logger::Append(library.GetKey(), " ");
191200

192201
Logger::Error(this, ": This likely involves a memory leak "
193202
"that withholds managed data reflected by the given modules");
@@ -459,11 +468,11 @@ namespace Langulus::Entity
459468
// Test if the boundary conflicts with any of the previously
460469
// loaded libraries
461470
for (auto lib : mLibraries) {
462-
if (lib.mValue.mBoundary == library.mBoundary) {
471+
if (lib.GetValue().mBoundary == library.mBoundary) {
463472
Logger::Error(
464473
"The library `", path, "` boundary `", library.mBoundary,
465-
"` conflicts with already loaded library `", lib.mKey,
466-
"` boundary `", lib.mValue.mBoundary, '`'
474+
"` conflicts with already loaded library `", lib.GetKey(),
475+
"` boundary `", lib.GetValue().mBoundary, '`'
467476
);
468477
(void)UnloadSharedLibrary(library);
469478
return {};
@@ -606,8 +615,8 @@ namespace Langulus::Entity
606615
return {};
607616

608617
for (auto library : mLibraries) {
609-
if (library.mValue.mBoundary == type->mLibraryName)
610-
return library.mValue;
618+
if (library.GetValue().mBoundary == type->mLibraryName)
619+
return library.GetValue();
611620
}
612621
return {};
613622
}
@@ -646,7 +655,7 @@ namespace Langulus::Entity
646655
/// @return true if no exit was requested by any of the modules
647656
bool Runtime::Update(Time dt) {
648657
for (auto pair : mModules) {
649-
for (auto module : pair.mValue) {
658+
for (auto module : pair.GetValue()) {
650659
if (not module->Update(dt))
651660
return false;
652661
}

source/Thing-Gather.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Langulus::Entity
127127
if constexpr (SEEK & Seek::Here) {
128128
// Check dynamic traits in the entity
129129
for (auto traitGroup : mTraits) {
130-
for (auto trait : traitGroup.mValue) {
130+
for (auto trait : traitGroup.GetValue()) {
131131
try { results << trait.template AsCast<D>(); }
132132
catch (...) {}
133133
}

source/Thing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ namespace Langulus::Entity
261261
const auto tab2 = Logger::Section(Logger::White, Logger::Underline,
262262
"Traits (", mTraits.GetCount(), "):");
263263
for (auto traitpair : mTraits) {
264-
for (auto& trait : traitpair.mValue)
264+
for (auto& trait : traitpair.GetValue())
265265
Logger::Verbose(trait);
266266
}
267267
}

0 commit comments

Comments
 (0)