commit c8b6287b763e7a8adea601fd828eb5a25298d032 Author: Пригарин Олег Юрьевич Date: Thu Jul 3 21:51:21 2025 +0300 Economy ECS API base diff --git a/ECSAPI/.gitignore b/ECSAPI/.gitignore new file mode 100644 index 0000000..d63cff4 --- /dev/null +++ b/ECSAPI/.gitignore @@ -0,0 +1,527 @@ + +out/ +build/ + +# Created by https://www.toptal.com/developers/gitignore/api/clion,cmake,visualstudio,visualstudiocode,c++ +# Edit at https://www.toptal.com/developers/gitignore?templates=clion,cmake,visualstudio,visualstudiocode,c++ + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### CLion ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CLion Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.iobj +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# End of https://www.toptal.com/developers/gitignore/api/clion,cmake,visualstudio,visualstudiocode,c++ \ No newline at end of file diff --git a/ECSAPI/.vscode/launch.json b/ECSAPI/.vscode/launch.json new file mode 100644 index 0000000..e8338f2 --- /dev/null +++ b/ECSAPI/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "configurations": [ + { + "type": "cmake", + "request": "launch", + "name": "Debug portfile(s)", + "cmakeDebugType": "external", + "pipeName": "\\\\.\\pipe\\vcpkg_ext_portfile_dbg", + "preLaunchTask": "Debug vcpkg commands" + } + ] +} \ No newline at end of file diff --git a/ECSAPI/CMakeLists.txt b/ECSAPI/CMakeLists.txt new file mode 100644 index 0000000..0df532a --- /dev/null +++ b/ECSAPI/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required (VERSION 3.8) + +if (POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") +endif() + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +project ("ECSAPI") + +add_subdirectory ("Economy") +add_subdirectory ("Economy/test") + +add_subdirectory ("ECS") \ No newline at end of file diff --git a/ECSAPI/CMakePresets.json b/ECSAPI/CMakePresets.json new file mode 100644 index 0000000..fb4ca42 --- /dev/null +++ b/ECSAPI/CMakePresets.json @@ -0,0 +1,62 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "windows-base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64-debug", + "displayName": "x64 Debug", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x64-release", + "displayName": "x64 Release", + "inherits": "x64-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "x86-debug", + "displayName": "x86 Debug", + "inherits": "windows-base", + "architecture": { + "value": "x86", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x86-release", + "displayName": "x86 Release", + "inherits": "x86-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ] +} diff --git a/ECSAPI/CMakeUserPresets.json b/ECSAPI/CMakeUserPresets.json new file mode 100644 index 0000000..15fa6aa --- /dev/null +++ b/ECSAPI/CMakeUserPresets.json @@ -0,0 +1,12 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "DEBUG", + "inherits": "x64-debug", + "environment": { + "VCPKG_ROOT": "E:/vcpkg/vcpkg" + } + } + ] +} \ No newline at end of file diff --git a/ECSAPI/ECS/CMakeLists.txt b/ECSAPI/ECS/CMakeLists.txt new file mode 100644 index 0000000..c4c80cf --- /dev/null +++ b/ECSAPI/ECS/CMakeLists.txt @@ -0,0 +1,26 @@ +project(ECS) + +# List sources + +set(HEADERS "ECS.h" "world.h") +set(SOURCES "ECS.cpp" "world.cpp") + +list(TRANSFORM HEADERS PREPEND "include/") +list(TRANSFORM SOURCES PREPEND "src/") + +# Find dependencies +find_package(EnTT CONFIG REQUIRED) + +# Link library + +add_library (ECS SHARED ${HEADERS} ${SOURCES}) + +target_link_libraries(ECS PRIVATE Economy::Economy) +target_link_libraries(ECS PRIVATE EnTT::EnTT) + +target_include_directories(ECS PUBLIC include/) + + +if (CMAKE_VERSION VERSION_GREATER 3.12) + set_property(TARGET ECS PROPERTY CXX_STANDARD 20) +endif() \ No newline at end of file diff --git a/ECSAPI/ECS/include/ECS.h b/ECSAPI/ECS/include/ECS.h new file mode 100644 index 0000000..77fae46 --- /dev/null +++ b/ECSAPI/ECS/include/ECS.h @@ -0,0 +1,11 @@ +// API to control world multithreaded processing in real time +#pragma once + +namespace ee_ecs +{ + + void init(); + void start(); + void stop(); + +} \ No newline at end of file diff --git a/ECSAPI/ECS/include/world.h b/ECSAPI/ECS/include/world.h new file mode 100644 index 0000000..58bd5d9 --- /dev/null +++ b/ECSAPI/ECS/include/world.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include "defines.h" +#include "enterprise_defaults.h" + +namespace ee_ecs +{ + class world + { + + private: + entt::registry registry; + + public: + /// + /// Run every registered system + /// + void update(); + + /// + /// Register new enterprise entity in specified state + /// + /// represents type of activity that enterprise do every tick + /// is ID of state entity where enterprise will be placed + /// is initial properties of enterprise + void spawn_enterprise(const bool is_building, const ACTION_TYPE action, const entt::entity state, const enterprise_defaults defaults); + }; +} \ No newline at end of file diff --git a/ECSAPI/ECS/src/ECS.cpp b/ECSAPI/ECS/src/ECS.cpp new file mode 100644 index 0000000..d687c9d --- /dev/null +++ b/ECSAPI/ECS/src/ECS.cpp @@ -0,0 +1,20 @@ +#include "ECS.h" +#include "world.h" + + +static ee_ecs::world world; + +void ee_ecs::init() +{ + +} + +void ee_ecs::start() +{ + +} + +void ee_ecs::stop() +{ + +} diff --git a/ECSAPI/ECS/src/world.cpp b/ECSAPI/ECS/src/world.cpp new file mode 100644 index 0000000..14b0c1c --- /dev/null +++ b/ECSAPI/ECS/src/world.cpp @@ -0,0 +1,36 @@ +#include "world.h" +#include "systems.h" +#include "components/enterprise.h" +#include "components/miner.h" + +void ee_ecs::world::update() +{ + mining(this->registry); +} + +void ee_ecs::world::spawn_enterprise(const bool is_building, const ACTION_TYPE action, const entt::entity state, const enterprise_defaults defaults) +{ + entt::entity entity = this->registry.create(); + + auto &enterprise_c = this->registry.emplace(entity); + enterprise_c.is_building = is_building; + enterprise_c.state = state; + + auto &container_c = this->registry.emplace(entity); + container_c = defaults.container; + + switch (action) + { + case ACTION_TYPE::MINING: + { + auto& miner_c = this->registry.emplace(entity); + miner_c.resource = defaults.resource_target; + miner_c.value = defaults.base_efficiency_flat; + + break; + } + + default: + break; + } +} diff --git a/ECSAPI/Economy/CMakeLists.txt b/ECSAPI/Economy/CMakeLists.txt new file mode 100644 index 0000000..7bba6a7 --- /dev/null +++ b/ECSAPI/Economy/CMakeLists.txt @@ -0,0 +1,32 @@ +project(Economy) + +# List sources + +set(HEADERS "defines.h" "enterprise_defaults.h" "systems.h") +set(HEADERS_COMPONENTS "container.h" "enterprise.h" "miner.h" "producer.h" "tags.h") + +set(SOURCES "Economy.cpp") +set(SOURCES_SYSTEMS "mining.cpp") + +list(TRANSFORM HEADERS PREPEND "include/") +list(TRANSFORM HEADERS_COMPONENTS PREPEND "include/components/") + +list(TRANSFORM SOURCES PREPEND "src/") +list(TRANSFORM SOURCES_SYSTEMS PREPEND "src/systems/") + +# Find dependencies + +find_package(EnTT CONFIG REQUIRED) + +# Link library + +add_library(Economy SHARED ${HEADERS} ${HEADERS_COMPONENTS} ${SOURCES} ${SOURCES_SYSTEMS}) +add_library(Economy::Economy ALIAS Economy) + +target_link_libraries(Economy PRIVATE EnTT::EnTT) + +target_include_directories(Economy PUBLIC include/) + +if (CMAKE_VERSION VERSION_GREATER 3.12) + set_property(TARGET Economy PROPERTY CXX_STANDARD 20) +endif() \ No newline at end of file diff --git a/ECSAPI/Economy/include/components/container.h b/ECSAPI/Economy/include/components/container.h new file mode 100644 index 0000000..fd800a3 --- /dev/null +++ b/ECSAPI/Economy/include/components/container.h @@ -0,0 +1,19 @@ +#pragma once +#include "../defines.h" +#include + +namespace ee_ecs +{ + struct container + { + double capacity = 0.; + double total = 0.; + std::unordered_map content; + + void add(RESOURCE_TYPE type, double delta) + { + content[type] += delta; + total += delta; + } + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/components/enterprise.h b/ECSAPI/Economy/include/components/enterprise.h new file mode 100644 index 0000000..7392c89 --- /dev/null +++ b/ECSAPI/Economy/include/components/enterprise.h @@ -0,0 +1,12 @@ +#pragma once +#include + +namespace ee_ecs +{ + struct enterprise + { + bool is_building = false; + + entt::entity state; + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/components/miner.h b/ECSAPI/Economy/include/components/miner.h new file mode 100644 index 0000000..63fea0b --- /dev/null +++ b/ECSAPI/Economy/include/components/miner.h @@ -0,0 +1,12 @@ +#pragma once +#include "../defines.h" +#include + +namespace ee_ecs +{ + struct miner + { + RESOURCE_TYPE resource = RESOURCE_TYPE::NONE; + double value = 0.; + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/components/producer.h b/ECSAPI/Economy/include/components/producer.h new file mode 100644 index 0000000..83dcd82 --- /dev/null +++ b/ECSAPI/Economy/include/components/producer.h @@ -0,0 +1,9 @@ +#pragma once + +namespace ee_ecs +{ + struct producer + { + + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/components/tags.h b/ECSAPI/Economy/include/components/tags.h new file mode 100644 index 0000000..0e8e63b --- /dev/null +++ b/ECSAPI/Economy/include/components/tags.h @@ -0,0 +1,8 @@ +#pragma once + +namespace ee_ecs +{ + + struct state {}; + +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/defines.h b/ECSAPI/Economy/include/defines.h new file mode 100644 index 0000000..a23a67d --- /dev/null +++ b/ECSAPI/Economy/include/defines.h @@ -0,0 +1,82 @@ +#pragma once + +namespace ee_ecs +{ + const double TOLERANCE = 0.001; + + enum struct ACTION_TYPE : unsigned char + { + MINING, + PRODUCTION, + DELIVERY, + CONTAIN, + DESTRUCTION, + BUILD, + TRADE + }; + + enum struct CONTAINABLE_TYPE : unsigned char + { + RESOURCE, + GOODS, + SERVICE + }; + + enum struct RESOURCE_TYPE : unsigned char + { + NONE, + + AGRICULTURE, + MEAT, + COTTON, + LEATHER, + WOOL, + TIMBER, + COAL, + OIL, + GAS, + IRON, + COPPER, + LITHIUM, + URANIUM, + GOLD, + + FERTILIZER, + FABRIC, + FURNITURE, + LUXURY, + CLOTHING, + ALCOHOL, + PAPER, + GLASS, + PLASTIC, + CEMENT, + STEEL, + FUEL, + AVIATION_FUEL, + ROCKET_FUEL, + ENGINES, + ELECTRICITY, + AUTOMOBILE, + AIRPLANE, + HELICOPTER, + PHONE, + TRUCK, + CONSTRUCTION_EQUIPMENT, + PROCESSOR, + COMPUTER, + ELECTRONIC, + SEMICONDUCTOR, + BATTERY, + SYNTHETIC_RUBBER, + SYNTHETIC_FABRIC, + MACHINE_TOOLS, + MODERN_MACHINE_TOOLS, + POLYMERS, + MILITARY_EQUIPMENT, + MEDICINES, + TACTICAL_MISSILES, + NUCLEAR_MISSILES, + OIL_GAS + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/enterprise_defaults.h b/ECSAPI/Economy/include/enterprise_defaults.h new file mode 100644 index 0000000..fe994a6 --- /dev/null +++ b/ECSAPI/Economy/include/enterprise_defaults.h @@ -0,0 +1,13 @@ +#pragma once +#include "components/container.h" + +namespace ee_ecs +{ + struct enterprise_defaults + { + container container; + + RESOURCE_TYPE resource_target; + double base_efficiency_flat; + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/resources_exchange.h b/ECSAPI/Economy/include/resources_exchange.h new file mode 100644 index 0000000..0a402e3 --- /dev/null +++ b/ECSAPI/Economy/include/resources_exchange.h @@ -0,0 +1,27 @@ +// Rules for resources exchange in base before modifiers applying + +#pragma once +#include +#include "defines.h" + +namespace ee_ecs +{ + struct exchange_rule + { + double out_value; + + std::unordered_map consume; + }; + + const std::unordered_map resources_exchange = { + { + RESOURCE_TYPE::FABRIC, + exchange_rule { + .out_value = 2., + .consume = { + {RESOURCE_TYPE::WOOL, 3.} + } + } + } + }; +} \ No newline at end of file diff --git a/ECSAPI/Economy/include/systems.h b/ECSAPI/Economy/include/systems.h new file mode 100644 index 0000000..7be0e0f --- /dev/null +++ b/ECSAPI/Economy/include/systems.h @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace ee_ecs +{ + void mining(entt::registry& registry); +} \ No newline at end of file diff --git a/ECSAPI/Economy/src/Economy.cpp b/ECSAPI/Economy/src/Economy.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ECSAPI/Economy/src/systems/mining.cpp b/ECSAPI/Economy/src/systems/mining.cpp new file mode 100644 index 0000000..5c41ca3 --- /dev/null +++ b/ECSAPI/Economy/src/systems/mining.cpp @@ -0,0 +1,26 @@ +#include "systems.h" +#include "components/miner.h" +#include "components/container.h" +#include "components/enterprise.h" + +void ee_ecs::mining(entt::registry ®istry) +{ + auto miners = registry.view(); + + for (auto [entity, enterprise, miner, local_storage]: miners.each()) + { + container& state = registry.get(enterprise.state); + + if (!state.content.contains(miner.resource) || state.content[miner.resource] < TOLERANCE) + continue; + + double mined_value = miner.value; + if (local_storage.total + mined_value > local_storage.capacity) + mined_value = local_storage.capacity - local_storage.total; + if (mined_value > state.content[miner.resource]) + mined_value = state.content[miner.resource]; + + local_storage.add(miner.resource, mined_value); + state.add(miner.resource, -mined_value); + } +} \ No newline at end of file diff --git a/ECSAPI/Economy/test/CMakeLists.txt b/ECSAPI/Economy/test/CMakeLists.txt new file mode 100644 index 0000000..5f86290 --- /dev/null +++ b/ECSAPI/Economy/test/CMakeLists.txt @@ -0,0 +1,27 @@ +# List sources + +set(SOURCES "test_conf.h" "main.cpp" "systems/mining.cpp") + +# Find dependencies + +find_package(GTest CONFIG REQUIRED) + +# Link + +include(GoogleTest) + +add_executable(economy_tests ${SOURCES}) +target_link_libraries(economy_tests PRIVATE GTest::gtest_main) +target_link_libraries(economy_tests PRIVATE Economy::Economy) + +# Test + +if (WIN32) + add_custom_command( + TARGET economy_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND_EXPAND_LISTS + ) +endif () + +gtest_discover_tests(economy_tests) \ No newline at end of file diff --git a/ECSAPI/Economy/test/main.cpp b/ECSAPI/Economy/test/main.cpp new file mode 100644 index 0000000..45acf01 --- /dev/null +++ b/ECSAPI/Economy/test/main.cpp @@ -0,0 +1,8 @@ +#include + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/ECSAPI/Economy/test/systems/mining.cpp b/ECSAPI/Economy/test/systems/mining.cpp new file mode 100644 index 0000000..20b3dca --- /dev/null +++ b/ECSAPI/Economy/test/systems/mining.cpp @@ -0,0 +1,89 @@ +#include +#include "components/container.h" +#include "components/miner.h" +#include "defines.h" +#include "../test_conf.h" +#include "systems.h" + +TEST_F(SystemsTest, MiningNormal) +{ + ee_ecs::container &state_container = registry.get(state); + ee_ecs::container &miner_container = registry.get(miner); + ee_ecs::miner &miner_miner = registry.get(miner); + + state_container.capacity = 15.0; + state_container.add(ee_ecs::RESOURCE_TYPE::COAL, 10.0); + + miner_container.capacity = 5.0; + miner_miner.resource = ee_ecs::RESOURCE_TYPE::COAL; + miner_miner.value = 0.1; + + ee_ecs::mining(registry); + + ASSERT_DOUBLE_EQ(state_container.total, 9.9); + ASSERT_DOUBLE_EQ(state_container.content[ee_ecs::RESOURCE_TYPE::COAL], 9.9); + ASSERT_DOUBLE_EQ(miner_container.total, 0.1); + ASSERT_DOUBLE_EQ(miner_container.content[ee_ecs::RESOURCE_TYPE::COAL], 0.1); +} + +TEST_F(SystemsTest, MiningEmptyState) +{ + ee_ecs::container &state_container = registry.get(state); + ee_ecs::container &miner_container = registry.get(miner); + ee_ecs::miner &miner_miner = registry.get(miner); + + state_container.capacity = 15.0; + + miner_container.capacity = 5.0; + miner_miner.resource = ee_ecs::RESOURCE_TYPE::COAL; + miner_miner.value = 0.1; + + ee_ecs::mining(registry); + + ASSERT_DOUBLE_EQ(state_container.total, 0.0); + ASSERT_DOUBLE_EQ(state_container.content[ee_ecs::RESOURCE_TYPE::COAL], 0.0); + ASSERT_DOUBLE_EQ(miner_container.total, 0.0); + ASSERT_DOUBLE_EQ(miner_container.content[ee_ecs::RESOURCE_TYPE::COAL], 0.0); +} + +TEST_F(SystemsTest, MiningPoorState) +{ + ee_ecs::container &state_container = registry.get(state); + ee_ecs::container &miner_container = registry.get(miner); + ee_ecs::miner &miner_miner = registry.get(miner); + + state_container.capacity = 15.0; + state_container.add(ee_ecs::RESOURCE_TYPE::COAL, 0.05); + + miner_container.capacity = 5.0; + miner_miner.resource = ee_ecs::RESOURCE_TYPE::COAL; + miner_miner.value = 0.1; + + ee_ecs::mining(registry); + + ASSERT_DOUBLE_EQ(state_container.total, 0.0); + ASSERT_DOUBLE_EQ(state_container.content[ee_ecs::RESOURCE_TYPE::COAL], 0.0); + ASSERT_DOUBLE_EQ(miner_container.total, 0.05); + ASSERT_DOUBLE_EQ(miner_container.content[ee_ecs::RESOURCE_TYPE::COAL], 0.05); +} + +TEST_F(SystemsTest, MiningReachCap) +{ + ee_ecs::container &state_container = registry.get(state); + ee_ecs::container &miner_container = registry.get(miner); + ee_ecs::miner &miner_miner = registry.get(miner); + + state_container.capacity = 15.0; + state_container.add(ee_ecs::RESOURCE_TYPE::COAL, 10.0); + + miner_container.capacity = 0.05; + miner_miner.resource = ee_ecs::RESOURCE_TYPE::COAL; + miner_miner.value = 0.1; + + ee_ecs::mining(registry); + + ASSERT_DOUBLE_EQ(state_container.total, 9.95); + ASSERT_DOUBLE_EQ(state_container.content[ee_ecs::RESOURCE_TYPE::COAL], 9.95); + ASSERT_DOUBLE_EQ(miner_container.total, 0.05); + ASSERT_DOUBLE_EQ(miner_container.content[ee_ecs::RESOURCE_TYPE::COAL], 0.05); +} \ No newline at end of file diff --git a/ECSAPI/Economy/test/test_conf.h b/ECSAPI/Economy/test/test_conf.h new file mode 100644 index 0000000..0402822 --- /dev/null +++ b/ECSAPI/Economy/test/test_conf.h @@ -0,0 +1,33 @@ +#include "components/container.h" +#include "components/enterprise.h" +#include "components/miner.h" +#include "components/tags.h" +#include +#include + +struct SystemsTest : testing::Test +{ + entt::registry registry; + + entt::entity state; + + entt::entity miner; + + void SetUp() + { + // Create state + state = registry.create(); + registry.emplace(state); + registry.emplace(state); + + // Create miner enterprise + miner = registry.create(); + registry.emplace(miner, false, state); + registry.emplace(miner); + registry.emplace(miner); + } + + void TearDown() + { + } +}; \ No newline at end of file diff --git a/ECSAPI/vcpkg-configuration.json b/ECSAPI/vcpkg-configuration.json new file mode 100644 index 0000000..a5f781c --- /dev/null +++ b/ECSAPI/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "0cb95c860ea83aafc1b24350510b30dec535989a", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/ECSAPI/vcpkg.json b/ECSAPI/vcpkg.json new file mode 100644 index 0000000..efd46db --- /dev/null +++ b/ECSAPI/vcpkg.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ + "entt", + "gtest" + ] +}