Skip to content

Commit

Permalink
A lot of changes... mainly GDSC meta entity, ...
Browse files Browse the repository at this point in the history
Some changes include changing type of UNIT_TIME to chrono::seconds
instead of float, this actually saved a possible error, and also makes
much sense than previous float
Better language ettiquite 🥲
Dependency version upgrade
More CMakeLists changes, including now can access the 'db' directory
  • Loading branch information
adi-g15 committed Aug 30, 2021
1 parent 8486824 commit d4da09d
Show file tree
Hide file tree
Showing 21 changed files with 375 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ pkg/

worldlinesim
logs
.cache
25 changes: 19 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ project(WorldLineSim
)
include(CTest)

#cmake_policy(SET CMP0097 NEW)

# Later utilise features in C++20
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# add CPM
include(cmake/CPM.cmake)


file(GLOB SOURCES "src/Entities/*.cpp" "src/*.cpp")
file(GLOB CUSTOM_ENTITIES_SRC "src/Entities/Custom/*.cpp")
file(GLOB CUSTOM_ENTITIES_SRC "src/Entities/Custom/*.cpp" "src/Entities/Meta/Custom/*/*.cpp")
file(GLOB DISP_SOURCES "display/src/*.cpp")

add_executable(worldlinesim main.cpp ${SOURCES} ${DISP_SOURCES} ${CUSTOM_ENTITIES_SRC})

add_custom_command(TARGET worldlinesim POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/db $<TARGET_FILE_DIR:worldlinesim>/db
)

if(CMAKE_BUILD_TYPE EQUAL "Release")
add_compile_definitions(GRAPH_MAT_NO_COORD)
else()
Expand All @@ -30,10 +36,9 @@ include_directories(includes) # should also be available to display
include_directories(.)



# graphMat & utilpp
CPMAddPackage("gh:adi-g15/graphMat@1.0.1")
CPMAddPackage("gh:adi-g15/utilpp@1.0.1")
CPMAddPackage("gh:adi-g15/utilpp@1.0.3")
target_link_libraries(worldlinesim PRIVATE graphMat)
target_link_libraries(worldlinesim PRIVATE utilpp)

Expand All @@ -44,11 +49,19 @@ CPMAddPackage("gh:gabime/spdlog@1.8.5")
CPMAddPackage(
NAME "nanogui"
GITHUB_REPOSITORY "mitsuba-renderer/nanogui"
GIT_TAG "0146a88b2214cd5c5c29e6dfa8d3d3d0e9ab6d9d"
GIT_TAG "9371d845cbdeb548ac8677656669044fd3a3f2a2"
OPTIONS "NANOGUI_BUILD_EXAMPLES OFF" "NANOGUI_BUILD_SHARED OFF" "NANOGUI_BUILD_PYTHON OFF" "NANOGUI_INSTALL OFF"
)

target_link_libraries(worldlinesim PRIVATE nanogui spdlog::spdlog)
# yaml-cpp
CPMAddPackage(
GITHUB_REPOSITORY "jbeder/yaml-cpp"
GIT_TAG yaml-cpp-0.7.0
GIT_SUBMODULES ""
OPTIONS "YAML_CPP_BUILD_TESTS OFF" "YAML_CPP_INSTALL OFF"
)

target_link_libraries(worldlinesim PRIVATE nanogui spdlog::spdlog yaml-cpp)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# World Line Simulator

A BIG oberhaul on the way... ab is duniya me bolne, sun ne, dekhne, sochne wale log honge... :D
A BIG overhaul on the way... ab is duniya me bolne, sun ne, dekhne, sochne wale log honge... :D

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/652ba837de78439f90a144db9b6cf4ac)](https://app.codacy.com/gh/adi-g15/worldLineSim?utm_source=github.com&utm_medium=referral&utm_content=adi-g15/worldLineSim&utm_campaign=Badge_Grade)
[![deepcode](https://www.deepcode.ai/api/gh/badge?key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwbGF0Zm9ybTEiOiJnaCIsIm93bmVyMSI6ImFkaS1nMTUiLCJyZXBvMSI6IndvcmxkTGluZVNpbSIsImluY2x1ZGVMaW50IjpmYWxzZSwiYXV0aG9ySWQiOjIyMzM5LCJpYXQiOjE2MTM5OTgxMTN9.PrWhRLumHS9kjRO8KXnY3Yd-1bJJZ_-c07kptEyCQPs)](https://www.deepcode.ai/app/gh/adi-g15/worldLineSim/_/dashboard?utm_content=gh%2Fadi-g15%2FworldLineSim)
[![CodeFactor](https://www.codefactor.io/repository/github/adi-g15/worldlinesim/badge)](https://www.codefactor.io/repository/github/adi-g15/worldlinesim)
<div align="center">
<img src="https://api.codacy.com/project/badge/Grade/652ba837de78439f90a144db9b6cf4ac"/><!--(https://app.codacy.com/gh/adi-g15/worldLineSim?utm_source=github.com&utm_medium=referral&utm_content=adi-g15/worldLineSim&utm_campaign=Badge_Grade)-->
<img src="https://www.deepcode.ai/api/gh/badge?key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwbGF0Zm9ybTEiOiJnaCIsIm93bmVyMSI6ImFkaS1nMTUiLCJyZXBvMSI6IndvcmxkTGluZVNpbSIsImluY2x1ZGVMaW50IjpmYWxzZSwiYXV0aG9ySWQiOjIyMzM5LCJpYXQiOjE2MTM5OTgxMTN9.PrWhRLumHS9kjRO8KXnY3Yd-1bJJZ_-c07kptEyCQPs"/><!--)](https://www.deepcode.ai/app/gh/adi-g15/worldLineSim/_/dashboard?utm_content=gh%2Fadi-g15%2FworldLineSim)-->
<img src="https://www.codefactor.io/repository/github/adi-g15/worldlinesim/badge"/><!--)](https://www.codefactor.io/repository/github/adi-g15/worldlinesim)-->

[![Ubuntu Build Status](https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_ubuntu.yml/badge.svg)](https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_ubuntu.yml)
[![Windows Build Status](https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_win.yml/badge.svg)](https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_win.yml)
<br/>
<img src="https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_ubuntu.yml/badge.svg"/><!--)](https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_ubuntu.yml)-->
<img src="https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_win.yml/badge.svg"/><!--)](https://github.com/adi-g15/worldLineSim/actions/workflows/cmake_win.yml)-->
</div>

As of now, it `can` be said that it simulates a simple 3D multiverse

Expand Down Expand Up @@ -56,6 +59,8 @@ cmake --build .

## Class Diagram

> Many entities have been added after this, leaving it so, as it clarifies the base things
>
> Made with draw.io
![Class Diagram](class_diagram.png "WorldLine Sim")
Expand Down
1 change: 1 addition & 0 deletions future.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* Snake::grow and move don't modify tail

*Many entities, the new ones, may unknowingly not call addentity() on the box they are present,
* Use a consistent display 'API', which allows many options for display to be chosen from
1 change: 1 addition & 0 deletions includes/Entities/Meta/Custom/GDSC/README.md
70 changes: 70 additions & 0 deletions includes/Entities/Meta/Custom/GDSC/gdsc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include "entity.hpp"
#include "Entities/human.hpp"
#include "entity_types.hpp"
#include "world.hpp"
#include <optional>
#include <string>
#include <map>

using SamajdharHuman = Human; // @adi Hata dena baad me, jab Humans intelligent ho

class GDSC;

class Member: SamajdharHuman {
std::string role;
float talkative_factor;
float listening_factor;
std::string last_msg;
std::map<std::string, std::pair<uint64_t,float>>
interactions; // {"name" : {"total talk (bytes)", "inference score"} }

GDSC* /*const*/ gdsc;

std::string m_chose_member();

public:
// @adi Future C:2
void mouth_speak(/*const std::string prefix_name*/);
void refresh_metric();
void ears_listen(std::string sounds);
Member(World_Ptr const world, const std::string& name, Gender gender, const std::string& role = "Member", float talkative_factor = 0.5, float listening_factor = 0.6):
role(role),
// gdsc(gdsc),
talkative_factor(talkative_factor),
listening_factor(listening_factor),
Human (world, name, gender) {}

// Overloads
void _Action1() override {}
void _Action2() override {}

void simulateExistence() override;
void pauseExistence() override;

friend class GDSC;
};

class GDSC: public Entity {
std::string full_name;
std::map<std::string, Member> group;
bool pause_requested{false}, pause_acknowledged{false};
World_Ptr const parent_world;
std::map< std::string, Member > _get_members_from_file(const std::string& filepath);
public:
void broadcast(std::string msg);
const std::map<std::string, Member>& get_members_ref() const;
GDSC(World_Ptr const world, const std::string& full_name, const std::map<std::string, Member>& members);
GDSC(World_Ptr const world, const std::string& full_name, const std::string& member_details_yaml);

// Overloads
void _Action1() override {}
void _Action2() override {}
std::optional<Entity_Point> getPrimaryPos() const override { return std::nullopt; }
EntityState* _get_current_state() const { return new EntityState( Entity_Types::META ); }

void simulateExistence() override;
void pauseExistence() override;
};

4 changes: 3 additions & 1 deletion includes/Entities/human.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct HumanState : public EntityState {
};

class Human : public Entity {
protected:
Entity_Point curr_pos;
World* parent_world;
bool should_wander{ false };
Expand All @@ -27,7 +28,7 @@ class Human : public Entity {
public:
typedef World* World_Ptr;
Gender gender;
const std::string& mName;
std::string mName;

//static std::vector<std::vector<std::bitset>> > humanities_exploration;
//static GraphMatrix3D<bool> humanities_exploration;
Expand All @@ -38,6 +39,7 @@ class Human : public Entity {

HumanState* _get_current_state() const override;

Human(World_Ptr const world, const std::string& name, Gender);
Human(World_Ptr const world, Gender);
Human(World_Ptr const world, const HumanState& prev_state);
~Human();
Expand Down
14 changes: 10 additions & 4 deletions includes/config.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#pragma once

typedef uint64_t _timePoint;
typedef _timePoint _timeDiff;
#include <chrono>

using namespace std::chrono_literals;

using _timePoint = uint64_t;
using _timeDiff = _timePoint;
namespace statics
{
typedef int32_t dimen_t;
static constexpr const char* DATABASE_DIRNAME = "db"; // Relative to project root

using dimen_t = int32_t;
// static constexpr std::pair< uint16_t, uint16_t > MAX_BOUNDS{ 1000, 1000 }; //applicable to ALL WORLDS CREATED
// static constexpr std::pair< uint16_t, uint16_t > init_Max_Bound{ 40, 40 }; //applicable to A NEW WORLD
// Currently using square matrix as parent, since it will be equally expanding later
Expand All @@ -15,7 +21,7 @@ namespace statics
static constexpr float min_free_space = 10.0f; //if it falls below this, in a particular worlPlot, the expansion rate will be increased

static constexpr _timePoint BIG_BANG_TIME = 0; //can be time::now() later too
static constexpr float UNIT_TIME = 1.0f; //in terms of human world seconds
static constexpr std::chrono::seconds UNIT_TIME = 1s;

static constexpr uint8_t init_expansion_speed{ 1 }; // @future - allow negative growths too

Expand Down
4 changes: 3 additions & 1 deletion includes/entity_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ enum class Entity_Types {
SNAKE = 0,
ROCK,
HUMAN,
META, // NEW: currently only GDSC exists as a meta entity
CUSTOM
// more can be added later, it's made to be expandible, though do see the member declarations as for what ANY entity must have
};

const std::array<const std::string, 4> Entity_Type_Map = {
const std::array<const std::string, 5> Entity_Type_Map = {
"Snake",
"Rock",
"Human",
"META",
"Custom"
};
4 changes: 2 additions & 2 deletions src/Entities/Custom/aliens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ long Equation::eval(int x) const {
current_coord.mY = std::get<1>(position_equations).eval(this->current_var);
current_coord.mZ = std::get<2>(position_equations).eval(this->current_var);

// 800 millisecond sleep
std::this_thread::sleep_for( std::chrono::milliseconds( static_cast<int>(statics::UNIT_TIME * 800) ));
// 0.8 unit time
std::this_thread::sleep_for( statics::UNIT_TIME * 0.8 );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Entities/Custom/cheems_vidhayak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void VidhayakJi::simulateExistence()
const Direction curr_dir = statics::directions[i % statics::directions.size()];

if (rand_box == nullptr) break;
LOGGER::log_msg("Vidhayak Ji #${} rabin ko dhundh rahe hai... [{}]", this->_id, this->curr_pos );
LOGGER::log_msg("Chacha Vidhayak Ji #${} 🤝🤝 rabin ko dhundh rahe hai... [{}]", this->_id, this->curr_pos );

graphMat::LinearIterator<Box> linear_iter(rand_box, curr_dir);

Expand Down Expand Up @@ -50,7 +50,7 @@ void VidhayakJi::simulateExistence()
while (neighbour_iter)
{
if (neighbour_iter->getData().hasEntities()) {
LOGGER::log_msg("Bakra mil gaya hai... Vidhayak ${} action time", this->_id);
LOGGER::log_msg("Rabin 🥲🥲... Vidhayak ${} action time", this->_id);
flag = true;
}
++neighbour_iter;
Expand All @@ -61,7 +61,7 @@ void VidhayakJi::simulateExistence()
while (neighbour_iter)
{
if (neighbour_iter->getData().hasEntities()) {
LOGGER::log_msg("Bakra mil gaya hai... Vidhayak ${} action time", this->_id);
LOGGER::log_msg("Mai bole to Cheems Vidhayak ${} 😎", this->_id);
flag = true;
}
++neighbour_iter;
Expand All @@ -72,7 +72,7 @@ void VidhayakJi::simulateExistence()
#ifndef GRAPH_MAT_NO_COORD
this->curr_pos = rand_box != nullptr ? rand_box->get_coordinate() : coord{0, 0, 0};
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(statics::UNIT_TIME * 1000)));
std::this_thread::sleep_for(statics::UNIT_TIME);
}

LOGGER::log_msg("VidhayakJi #{} ka career khatm... ab koi aur dal me judenge :-)", this->_id );
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Custom/mathematicians.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Mathematician::simulateExistence() {
}

// 2 second sleep
std::this_thread::sleep_for( std::chrono::milliseconds( static_cast<int>(statics::UNIT_TIME * 2000) ));
std::this_thread::sleep_for( statics::UNIT_TIME * 2 );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Custom/rabin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void Rabin::simulateExistence()

rand_box = linear_iter.curr_box;

std::this_thread::sleep_for( std::chrono::milliseconds( static_cast<int>(statics::UNIT_TIME * 1000) ));
std::this_thread::sleep_for( statics::UNIT_TIME );
}

LOGGER::log_msg("Rabin #{} ruk gaya", this->_id);
Expand Down
5 changes: 5 additions & 0 deletions src/Entities/Meta/Custom/GDSC/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## GDSC - Meta Entity

GDSC is the first Meta Entity in the worldline simulation, in it's whole history... :D

> **Meta Entity** - Entities that aren't actually living beings (etc..), but instead a group of individual entities, think of like the solar system, where we friends/entities are the planets, we have most interactions inside, but not 'isolated', can interact with outside too
Loading

0 comments on commit d4da09d

Please sign in to comment.