Browse Source

added a dll loading test

vlod 3 years ago
parent
commit
52714171b9

+ 40 - 4
Pika/CMakeLists.txt

@@ -10,7 +10,8 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
 
 #declare projects
 project(pikaCore)
-
+project(pikaGameplay)
+project(pikaProduction)
 
 
 #set glfw to NOT use dynamic runtime and not build unnecessary stuff
@@ -37,16 +38,15 @@ file(GLOB_RECURSE PIKA_SOURCES_CORE_CONFIG	CONFIGURE_DEPENDS "${CMAKE_CURRENT_SO
 file(GLOB_RECURSE PIKA_SOURCES_CORE_EDITOR	CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaEditor/*.cpp")
 file(GLOB_RECURSE PIKA_SOURCES_CORE_RUNTIME CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/*.cpp")
 file(GLOB_RECURSE PIKA_SOURCES_CORE_STD		CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/*.cpp")
+file(GLOB_RECURSE PIKA_SOURCES_GAMEPLAY		CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gameplay/*.cpp")
 
 
 
-#pikaCore
+#pikaCore ############################################
 add_executable(pikaCore)
 
-#add defines
 target_compile_definitions(pikaCore PUBLIC PIKA_DEVELOPMENT)
 
-
 set_property(TARGET pikaCore PROPERTY CXX_STANDARD 17)
 target_sources(pikaCore PRIVATE 
 	"${PIKA_SOURCES_CORE_CONFIG}" "${PIKA_SOURCES_CORE_EDITOR}" "${PIKA_SOURCES_CORE_RUNTIME}" "${PIKA_SOURCES_CORE_STD}")
@@ -55,4 +55,40 @@ target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pik
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/")
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
 target_link_libraries(pikaCore PRIVATE glad glfw gl2d glm stb_image stb_truetype)
+#################^^^^^^^^#############################
+
+
+#pikaGameplay ###########################################
+add_library(pikaGameplay SHARED)
+
+target_compile_definitions(pikaGameplay PUBLIC PIKA_DEVELOPMENT)
+set_property(TARGET pikaGameplay PROPERTY CXX_STANDARD 17)
+target_sources(pikaGameplay PRIVATE "${PIKA_SOURCES_CORE_CONFIG}" 
+	"${PIKA_SOURCES_CORE_STD}" "${PIKA_SOURCES_GAMEPLAY}")
+target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
+target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/coreConfig/")
+target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gameplay/")
+#################^^^^^^^^^^^^^^############################
+
+
+
+#pikaProduction ###########################################
+add_executable(pikaProduction)
+
+target_compile_definitions(pikaProduction PUBLIC PIKA_PRODUCTION)
+set_property(TARGET pikaProduction PROPERTY CXX_STANDARD 17)
+
+target_sources(pikaProduction PRIVATE 
+	"${PIKA_SOURCES_CORE_CONFIG}" "${PIKA_SOURCES_CORE_EDITOR}" 
+	"${PIKA_SOURCES_CORE_RUNTIME}" "${PIKA_SOURCES_CORE_STD}" "${PIKA_SOURCES_GAMEPLAY}")
+target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/coreConfig/")
+target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaEditor/")
+target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/")
+target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
+target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gameplay/")
+
+target_link_libraries(pikaProduction PRIVATE glad glfw gl2d glm stb_image stb_truetype)
+
+
 
+#################^^^^^^^^^^^^^^############################

+ 7 - 2
Pika/core/coreConfig/pikaConfig.h

@@ -21,6 +21,13 @@
 //  
 //////////////////////////////////////////
 //
+//macros
+// 
+//PIKA_API
+// 
+//////////////////////////////////////////
+// 
+// 
 //functions
 //
 // PIKA_PERMA_ASSERT
@@ -41,6 +48,4 @@
 
 
 
-
-
 #include <pikaConfigInternal.h>

+ 6 - 0
Pika/core/coreConfig/pikaConfigInternal.h

@@ -19,3 +19,9 @@
 #endif
 
 #pragma endregion
+
+#ifdef PIKA_DEVELOPMENT
+#define PIKA_API extern "C" __declspec(dllexport)
+#elif defined(PIKA_PRODUCTION)
+#define PIKA_API
+#endif

+ 53 - 0
Pika/core/pikaRuntime/dllLoader/dllLoader.cpp

@@ -0,0 +1,53 @@
+#include "dllLoader.h"
+#include "pikaConfig.h"
+
+#ifdef PIKA_DEVELOPMENT
+
+	#ifdef PIKA_WINDOWS
+	
+	#define NOMINMAX
+	#define WIN32_LEAN_AND_MEAN
+	#include <Windows.h>
+	
+	
+	static HMODULE dllHand;
+	
+	
+	//todo error reporting with strings
+	bool pika::loadDll(std::filesystem::path path, testPrint_t **testPrint)
+	{
+		path /= "pikaGameplay.dll";
+	
+		dllHand = LoadLibraryA(path.string().c_str());
+	
+		if (!dllHand) { return false; }
+	
+		*testPrint = (testPrint_t *)GetProcAddress(dllHand, "testPrint");
+	
+		if (!testPrint) { return false; }
+	
+	
+		return	true;
+	}
+	
+	
+	#else
+	#error "pika load dll works only on windows."
+	#endif
+
+
+#elif defined(PIKA_PRODUCTION)
+
+	#include <dllMain.h>
+
+	bool pika::loadDll(std::filesystem::path path, testPrint_t **testPrint_)
+	{
+		
+		*testPrint_ = testPrint;
+	
+		return	true;
+	}
+
+
+#endif
+

+ 16 - 0
Pika/core/pikaRuntime/dllLoader/dllLoader.h

@@ -0,0 +1,16 @@
+#pragma once
+#include <filesystem>
+
+#define TESTPRINT(x) void x()
+typedef TESTPRINT(testPrint_t);
+//extern "C" __declspec(dllexport) TESTPRINT(gameLogic);
+#undef TESTPRINT
+
+
+namespace pika
+{
+
+
+bool loadDll(std::filesystem::path path, testPrint_t** testPrint);
+
+};

+ 11 - 1
Pika/core/pikaRuntime/pikaMain.cpp

@@ -1,5 +1,6 @@
 #include <iostream>
 #include <cstdio>
+#include <filesystem>
 
 #include <glad/glad.h>
 #include <GLFW/glfw3.h>
@@ -8,9 +9,19 @@
 gl2d::Renderer2D renderer;
 
 #include "assert/assert.h"
+#include "dllLoader/dllLoader.h"
+
 
 int main()
 {
+	std::filesystem::path currentPath = std::filesystem::current_path();
+	
+	
+	testPrint_t *testPrint = {};
+
+	PIKA_PERMA_ASSERT(pika::loadDll(currentPath, &testPrint), "Couldn't load dll");
+	
+	testPrint();
 
 	if (!glfwInit())
 	{
@@ -35,7 +46,6 @@ int main()
 	gl2d::init();
 	renderer.create();
 
-	PIKA_PERMA_ASSERT(0, "abc");
 
 	while (!glfwWindowShouldClose(window))
 	{

+ 3 - 3
Pika/core/pikaSTD/assert/assert.h

@@ -39,7 +39,7 @@ namespace pika
 
 #define PIKA_PERMA_ASSERT(expression, comment) (void)(			\
 			(!!(expression)) ||									\
-			(PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION(expression,			\
+			(PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION(#expression,			\
 				__FILE__, __LINE__, comment), 0)				\
 )
 
@@ -48,7 +48,7 @@ namespace pika
 
 #define PIKA_DEVELOPMENT_ONLY_ASSERT(expression, comment) (void)(			\
 			(!!(expression)) ||												\
-			(pika::assert::assertFunctionDevelopment(expression,			\
+			(pika::assert::assertFunctionDevelopment(#expression,			\
 				__FILE__, __LINE__, comment), 0)							\
 )
 
@@ -56,4 +56,4 @@ namespace pika
 
 #define PIKA_DEVELOPMENT_ONLY_ASSERT(expression, comment)
 
-#endif
+#endif

+ 10 - 0
Pika/gameplay/dllMain.cpp

@@ -0,0 +1,10 @@
+#include <iostream>
+#include "dllMain.h"
+
+
+PIKA_API void testPrint()
+{
+	std::cout << "testPrint\n";
+}
+
+

+ 4 - 0
Pika/gameplay/dllMain.h

@@ -0,0 +1,4 @@
+#pragma once
+#include <pikaConfig.h>
+
+PIKA_API void testPrint();