remove lots of things

This commit is contained in:
Benjamin Kyd
2023-09-28 13:29:39 +01:00
parent 923ff2fb65
commit 298fe984e3
4 changed files with 0 additions and 381 deletions

View File

@@ -1,185 +0,0 @@
#include "hart_directory.hpp"
#include "inferno_hart.hpp"
#include <yolo/yolo.hpp>
#include <iostream>
using namespace inferno;
HARTModuleDirectory::HARTModuleDirectory()
{
}
HARTModuleDirectory::~HARTModuleDirectory()
{
}
std::vector<HARTModuleDirectory::discoveryEntry> HARTModuleDirectory::discoverModules(std::filesystem::path folder, bool recurse)
{
if (!std::filesystem::exists(folder)) return { };
if (!std::filesystem::is_directory(folder))
{
return { this->registerModule(folder) };
}
std::error_code err;
if (recurse)
{
for (const auto& file : std::filesystem::recursive_directory_iterator(folder, err))
{
if (file.path().extension() == HART_EXTENSION)
{
this->registerModule(file);
}
}
} else
{
for (const auto& file : std::filesystem::directory_iterator(folder, err))
{
if (file.path().extension() == HART_EXTENSION)
{
this->registerModule(file);
}
}
}
return { };
}
HARTModuleDirectory::discoveryEntry HARTModuleDirectory::registerModule(std::filesystem::path file)
{
yolo::info("Registering module at {}", file.c_str());
discoveryEntry entry;
entry.Location = file;
#ifdef _WIN32
entry.Handle = LoadLibraryA(file.c_str());
if (entry.Handle == NULL)
{
yolo::error("Cannot load module at {}.", file.c_str());
entry.Handle = NULL; entry.DidLink = false;
return entry;
}
HART_CREDIT_F credit = (HART_CREDIT_F)GetProcAddress(entry.Handle, "_CREDIT");
entry.InitCallback = (HART_INIT_F)GetProcAddress(entry.Handle, "_GET");
entry.DestroyCallback = (HART_DESTROY_F)GetProcAddress(entry.Handle, "_DESTROY");
#else // UNIX-Like
entry.Handle = dlopen(file.c_str(), RTLD_NOW | RTLD_LOCAL);
if (entry.Handle == NULL)
{
yolo::error("Cannot load module at ", dlerror());
entry.Handle = NULL; entry.DidLink = false;
return entry;
}
HART_CREDIT_F credit = (HART_CREDIT_F)dlsym(entry.Handle, "_CREDIT");
entry.InitCallback = (HART_INIT_F)dlsym(entry.Handle, "_GET");
entry.DestroyCallback = (HART_DESTROY_F)dlsym(entry.Handle, "_DESTROY");
#endif
if (credit == NULL)
{
yolo::error("Cannot load module at {}... No credit...", file.c_str());
entry.Handle = NULL; entry.DidLink = false;
return entry;
}
if (entry.InitCallback == NULL)
{
yolo::error("Cannot load module at {}... No get...", file.c_str());
entry.Handle = NULL; entry.DidLink = false;
return entry;
}
if (entry.DestroyCallback == NULL)
{
yolo::error("Cannot load module at {}... No destroy...", file.c_str());
entry.Handle = NULL; entry.DidLink = false;
return entry;
}
entry.Credit = (ModuleCredit*)credit();
yolo::info("Module {} v{}.{}.{} by {}", entry.Credit->ModuleName,
entry.Credit->VersionMajor,
entry.Credit->VersionMinor,
entry.Credit->VersionBuild,
entry.Credit->AuthorName);
entry.DidLink = true;
mEntries[entry.Credit->ModuleName] = { entry, nullptr };
if (mEntries.size() == 1)
{
// this is the first, make it active - or else
mActiveModule = entry.Credit->ModuleName;
this->load(mActiveModule);
}
return entry;
}
std::vector<std::string> HARTModuleDirectory::getModules()
{
std::vector<std::string> keys;
for(auto kv : mEntries)
{
keys.push_back(kv.first);
}
return keys;
}
void HARTModuleDirectory::setActive(std::string moduleName)
{
if (moduleName == mActiveModule) return;
this->destroy(mActiveModule);
mActiveModule = moduleName;
this->load(mActiveModule);
}
void HARTModuleDirectory::setActiveIndex(int index)
{
std::vector<std::string> keys = this->getModules();
this->setActive(keys[index]);
}
HARTModule* HARTModuleDirectory::getActiveModule()
{
return mEntries[mActiveModule].Module;
}
std::string HARTModuleDirectory::getActive()
{
return mActiveModule;
}
int HARTModuleDirectory::getActiveIndex()
{
std::vector<std::string> keys = this->getModules();
for (int i = 0; i < keys.size(); i++)
{
if (keys[i] == mActiveModule) return i;
}
return -1; // this should never happen
}
ModuleCredit* HARTModuleDirectory::getActiveCredit()
{
return mEntries[mActiveModule].Discovery.Credit;
}
void HARTModuleDirectory::load(std::string moduleName)
{
HARTModule* mod = (HARTModule*)mEntries[moduleName].Discovery.InitCallback();
mEntries[moduleName].Module = mod;
mEntries[moduleName].Active = true;
}
void HARTModuleDirectory::destroy(std::string moduleName)
{
mEntries[moduleName].Discovery.DestroyCallback(mEntries[moduleName].Module);
mEntries[moduleName].Module = nullptr;
mEntries[moduleName].Active = false;
}

View File

@@ -1,71 +0,0 @@
#pragma once
// INFERNO-HART Modules
// _GET returns derived HARTModule
// _DESTROY returns void but takes derived HARTModule
// _CREDIT returns ModuleCredit
// THIS IS SHARED DO __NOT__ REINCLUDE libhart/thirdparty
#include <inferno_hart.hpp>
#include <filesystem>
#include <string>
#include <vector>
#include <unordered_map>
namespace inferno {
class HARTModule;
struct ModuleCredit;
class HARTModuleDirectory
{
public:
HARTModuleDirectory();
~HARTModuleDirectory();
struct discoveryEntry
{
std::filesystem::path Location;
bool DidLink = false;
#ifdef _WIN32
HMODULE Handle;
#else // UNIX-Like
void* Handle;
#endif
ModuleCredit* Credit;
HART_INIT_F InitCallback;
HART_DESTROY_F DestroyCallback;
};
struct moduleEntry
{
discoveryEntry Discovery;
HARTModule* Module;
bool Active;
};
// This can take a file or a directory, and inside the directory discover recursively or not
std::vector<discoveryEntry> discoverModules(std::filesystem::path path, bool recurse = false);
discoveryEntry registerModule(std::filesystem::path file);
std::vector<std::string> getModules();
void setActive(std::string moduleName);
void setActiveIndex(int index);
HARTModule* getActiveModule();
std::string getActive();
int getActiveIndex();
ModuleCredit* getActiveCredit();
void load(std::string moduleName);
void destroy(std::string moduleName);
private:
std::string mActiveModule;
std::unordered_map<std::string, moduleEntry> mEntries;
};
}

View File

@@ -1,83 +0,0 @@
#include "hart_module.hpp"
#include <renderer/ray_source.hpp>
#include <renderer/renderer.hpp>
#include <scene/scene.hpp>
#include <scene/mesh.hpp>
#include <yolo/yolo.hpp>
#include <vector>
using namespace inferno;
HHM::HHM()
: mDirectory()
{
mDirectory.discoverModules("./hart/", true);
}
HHM::~HHM()
{
}
HARTModuleDirectory* HHM::getModuleDirectory()
{
return &mDirectory;
}
HARTModule::EModuleState HHM::getModuleState()
{
HARTModule* mod = mDirectory.getActiveModule();
return mod->getState();
}
void HHM::newScene(Scene* scene)
{
HARTModule* mod = mDirectory.getActiveModule();
std::vector<Mesh*> meshs = scene->getRenderables();
// TODO: This may not be the way i want to approach it
// as submitTris should take maybe a mesh ID and then the mesh data
// as it is now, submitTris assumes it's getting the whole scene
// which would involve a lot of mesh copying (avoid!) if i were to chain them
for (auto* mesh : meshs) {
void* verticies; void* normals; void* indicies;
int vertexCount = mesh->getVerticies(&verticies, &normals);
int indexCount = mesh->getIndicies(&indicies);
yolo::debug("Mesh for module ready... {} {}", verticies, normals);
mod->submitTris(verticies, normals, vertexCount, indicies, indexCount);
}
}
void HHM::notifySceneUpdate()
{
HARTModule* mod = mDirectory.getActiveModule();
mod->updateTris();
}
void rayHitCallback(void* hhm, HitInfo* hit)
{
((HHM*)hhm)->rayReturn(hit);
}
void HHM::rayReturn(HitInfo* hit)
{
Renderer->computeHit(hit);
}
void HHM::bounce(Ray* newRay)
{
}
void HHM::startTrace(RayField sourceScatter)
{
// TODO: Signal start
HARTModule* mod = mDirectory.getActiveModule();
mod->passContext((void*)this, &rayHitCallback);
yolo::debug("SubmitQueue {}", sourceScatter.size());
mod->submitQueue(sourceScatter);
mod->start();
}

View File

@@ -1,42 +0,0 @@
#pragma once
// the HHM (Hamlin Hamlin McGill) aka the Head HART Module keeps track of the module
// and gives the renderer a cleaner interface to talk to a HART Module
#include <vector>
#include <graphics.hpp>
#include "hart_directory.hpp"
namespace inferno {
class Scene;
class Ray;
class HitInfo;
class HARTModule;
class RayRenderer;
class HHM
{
public:
HHM();
~HHM();
HARTModuleDirectory* getModuleDirectory();
HARTModule::EModuleState getModuleState();
void newScene(Scene* scene);
void notifySceneUpdate();
void rayReturn(HitInfo* hit);
void bounce(Ray* newRay);
void startTrace(RayField sourceScatter);
RayRenderer* Renderer;
private:
HARTModuleDirectory mDirectory;
};
}