Cristianwolf712 Posted October 18, 2013 Share Posted October 18, 2013 With the last Evaluation update we got access to c++ Api to implement our own plugins. I want to implement libnoise for a procedural terrain generation, but generating the chunks in c++ code. I created a class, members and function, and the main() as well. But I don't know how to access them in unigine script? I red the documentation and all I have found is the complete article about the Dynamic Link Library. Should I compile my code to an .dll file and import that? Because I didn't need any init,update or flush-functions, just access to my Generator-class.It would be nice, if you can help me with that little problem.Best Regards, Christian Link to comment
binstream Posted October 18, 2013 Share Posted October 18, 2013 https://developer.unigine.com/en/docs/1.0/cpp_api/usage/classes Link to comment
Cristianwolf712 Posted October 18, 2013 Author Share Posted October 18, 2013 I know that topic. I try to register my code with that help. Main-function etc. is already included in my plugin. So it will be enough to extend my .bat-file with "-extern_plugin /data/project/plugins/lib/TerrainGenerator" ? Link to comment
Cristianwolf712 Posted October 21, 2013 Author Share Posted October 21, 2013 Okay, I decided to create a plugin instead, because libnoise have a lot ot namespaces in different files (and the interpreter seems to have some problems with angle brackets and double quotes). I compiled a .dll of my code with visual studio and create the "extern_plugin" at my .bat-file. Finally the plugin seems to be noticed but I got a message that "libnoise.dll" is not installed on my computer. But the file is located in the same folder as my plugin-file. Any ideas? Link to comment
ulf.schroeter Posted October 21, 2013 Share Posted October 21, 2013 Maybe putting all of your dll's including libnoise.dll into the UNIGINE bin folder might do the trick? Link to comment
binstream Posted October 21, 2013 Share Posted October 21, 2013 Make sure to set path to the plugin lib, i.e. -extern_plugin ../path/to/plugin Link to comment
Cristianwolf712 Posted October 21, 2013 Author Share Posted October 21, 2013 @ulf Many thanks. A copy in the bin-folder will do the trick. Link to comment
Cristianwolf712 Posted October 22, 2013 Author Share Posted October 22, 2013 Okay. After Unigine successfully noticed my Plugin.dll with my libnoise.dll, it crashed at function Interpreter::addExternClass() without any hints. ("Unigine has stopped working."). My code: class TerrainGeneratorPlugin : public Plugin { private: public: TerrainGeneratorPlugin(); virtual ~TerrainGeneratorPlugin(){}; virtual int init(); virtual int shutdown(); virtual void update(); }; TerrainGeneratorPlugin::TerrainGeneratorPlugin() { Log::warning("Generator-Plugin constructed!"); } int TerrainGeneratorPlugin::init() { Log::warning("Try register Terrain Generator Class!\n"); ExternClass<TerrainGenerator> *terGenerator = MakeExternClass<TerrainGenerator>(); Log::warning("Terrain Generator Class registered!\n"); //terGenerator->addConstructor<int,int>(); terGenerator->addConstructor(); terGenerator->addFunction("CalculateTerrain",&TerrainGenerator::CalculateTerrain); terGenerator->addFunction("BuildTerrain",&TerrainGenerator::BuildTerrain); terGenerator->addFunction("GetHeight",&TerrainGenerator::GetHeight); terGenerator->addFunction("SetBoundSize",&TerrainGenerator::SetBoundSize); terGenerator->addFunction("SetChunk",&TerrainGenerator::SetChunk); terGenerator->addFunction("GetBoundSize",&TerrainGenerator::GetBoundSize); terGenerator->addFunction("SetWorldSize",&TerrainGenerator::SetWorldSize); terGenerator->addFunction("GetWorldSize",&TerrainGenerator::GetWorldSize); terGenerator->addFunction("GetHeightMapSizeX",&TerrainGenerator::GetHeightMapSizeX); terGenerator->addFunction("GetHeightMapSizeY",&TerrainGenerator::GetHeightMapSizeY); Log::warning("AddTerrainGenerator Class\n"); Interpreter::addExternClass("TerrainGenerator",terGenerator); Log::warning("TerrainGenerator-Plugin successfully initialized!"); return 1; } int TerrainGeneratorPlugin::shutdown() { return 1; } //Update-Funktion, die jedes Frame aufgerufen wird void TerrainGeneratorPlugin::update() { } // 4. Expose the created implementation of the plugin interface. // 4.1. The engine will search for this function to add the plugin library. // It returns a new instance of the custom plugin. extern "C" UNIGINE_API void *CreatePlugin() { return new TerrainGeneratorPlugin(); } // 4.2. The engine will search for this function to release the plugin library. // For that, a void pointer should be casted to the custom plugin type and then // deleted. extern "C" UNIGINE_API void ReleasePlugin(void *plugin) { delete static_cast<TerrainGeneratorPlugin*>(plugin); } Link to comment
ulf.schroeter Posted October 22, 2013 Share Posted October 22, 2013 It's always a good idea to also post log.html file from UNIGINE bin directory after crash to provide some more information. As a next step I would place breakpoint in TerrainGeneratorPlugin::init and step through the code with C++ Debugger. Maybe debugger callstack on exception reveals some additional information on problem cause. Link to comment
Cristianwolf712 Posted October 22, 2013 Author Share Posted October 22, 2013 @ulf log.html file doesn't say any useful. Pathfind: Multi-Thread is the last point, the engine logged. Nevertheless, I attached the log-file. I tried the debugger-file at home, because I only have a Express-Version at my laptop. log.html Link to comment
Cristianwolf712 Posted October 22, 2013 Author Share Posted October 22, 2013 Still have the same issue at home: "Unigine has stopped working". I can't debug the code even with my professional version of visual studio, so sorry, no callstack. I uploaded my both .dll-files, mybe someone can try it on another machine. libnoise.rar Link to comment
Cristianwolf712 Posted October 23, 2013 Author Share Posted October 23, 2013 After creating a new and clean project with the sample code frome the documentation, I got still the same issue. I can't debug all code, so visual studio give me an error with reading at position .... After that, in the command window (unigine-log) I got following message: "AL lib: DSoundPlaybackProc: WaitForSingleObjectEx error 0x102". It seems, that there are an issue with the Interpreter::addExternClass() in unigine itself. I used the latest evaluation kit. EDIT: After playing a little bit around with plugin and visual studio I got the exception at Interpreter-class 3564. I found a post with the same problem. I adding the preprocessor information, but that doesn't solve the problem. Nevertheless I can wait until the next evaluation kit will be released, but if anyone other have an idea, than asolution is much appreciated. :) Link to comment
steve3d Posted October 28, 2013 Share Posted October 28, 2013 it seems you have my problem, and please make sure you are using debug configure to compile the plugin, which means /MDd and use Unigine_x64d.lib/Unigine_x86d.lib, If you use debug version of plugin to link with release version of engine, or use release version of plugin with debug version of engine it will crash. Link to comment
Cristianwolf712 Posted October 28, 2013 Author Share Posted October 28, 2013 Thanks steve, I got it worked. I noticed, that I have to add NDEBUG in preprocessor definitions manually. Now, I can compile successfully my code and load it in unigine without any engine crash. Nevertheless I can't get access to my code (see this post). Maybe you have although any tipps for me about that. Link to comment
unclebob Posted November 8, 2013 Share Posted November 8, 2013 Hi Christian! Sorry for late reply, have you used EXPORT_EXTERN define to log your plugin functions? If so, can you upload latest version of your plugins so I can check what is going on? Link to comment
Cristianwolf712 Posted November 8, 2013 Author Share Posted November 8, 2013 Hi bob, I already got my two problems worked. I used the visual studio project from samples/api/plugin. Link to comment
Recommended Posts