Jump to content

INCBIN and LoadPlugins from Stream


klepto2
 Share

Recommended Posts

It would be nice to have the out of the box ability to include files into the main engine and load them from there.

Also it would be nice to have a LoadPlugins method with the ability to load from a stream. I know this is not possible with the default windows options, but maybe this lib will help for this: 

https://github.com/fancycode/MemoryModule

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

The thought has occurred to me, but what is the purpose of loading plugins from memory?

Here is something I wrote a while back that might be useful:

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto stream = ReadFile("Source/IncBinFiles.cpp");
    std::vector<String> sarr;
    bool pause = false;

    while (!stream->EOF())
    {
        auto s = stream->ReadLine();
        if (s.Trim() == "//begin incbin") pause = true;
        if (!pause) sarr.push_back(s);
        if (s.Trim() == "//end incbin")
        { 
            sarr.push_back("//begin incbin");
            auto j3 = LoadJSON("Source/IncBin.json");
            if (j3["IncBinFiles"].is_array())
            {
                for (int n = 0; n < j3["IncBinFiles"].size(); ++n)
                {
                    auto bin = ReadFile(std::string(j3["IncBinFiles"][n]));
                    if (bin == NULL)
                    {
                        continue;
                    }
                    sarr.push_back("       if (rpath == RealPath(\""+std::string(j3["IncBinFiles"][n])+"\"))");
                    sarr.push_back("        {");
                    uint64_t sz = Ceil(float(bin->GetSize()) / 8.0f) * 8;
                    String s = "            static const std::array<uint64_t, " + String(sz/8) + "> data = {";
                    s.reserve(bin->GetSize() * 4 + s.size());
                    auto buf = CreateBuffer(sz);
                    bin->Read(buf->Data(), bin->GetSize());
                    uint64_t v;
                    for (uint64_t n = 0; n < buf->GetSize() / 8; ++n)
                    {
                        memcpy(&v, buf->Data() + (n*8), 8);
                        if (n > 0) s += ",";
                        //s += "UINT64_C(" + String(v) + ")";
                        s += Hex(v) + "ULL";
                    }
                    //while (!bin->EOF())
                    //{
                    //    s += "," + String(int(bin->ReadByte()));
                    //}
                    s += "  };";
                    sarr.push_back(s);
                    sarr.push_back("            auto buffer = CreateBuffer(" +String(bin->GetSize())+ "); ");
                    sarr.push_back("            buffer->Poke(0,(const char*)data.data(),"+String(bin->GetSize())+");");
                    sarr.push_back("            return CreateBufferStream(buffer);");
                    sarr.push_back("        }");
                }
            }
            sarr.push_back("//end incbin");
            pause = false;
        }
    }

    stream->Close();

    stream = WriteFile("Source/IncBinFiles.cpp");
    for (auto s : sarr)
    {
        stream->WriteLine(s);
    }
    stream->Close();

    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

yeah, this https://github.com/graphitemaster/incbin is the same i want use now. 

19 hours ago, Josh said:

The thought has occurred to me, but what is the purpose of loading plugins from memory?

The idea is to supply a basic set of plugins (or directly needed) directly in the executable itself. The idea is to have the ability to include everything in the executable and provide single file tools. This would make distribution easier. Lets say you have a tools folder with a lot of tools. 

  1. every folder needs the plugins, but have different search pathes for the plugins (eg:plugins or plg)
  2. each tool might be dependend on a specific version of a plugin and is not updated to use the plugins which are there.
  3. the executable will be bigger, but it may be worth it.
  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...