Implemented basic game dll interaction
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
add_subdirectory(System/)
|
||||
add_subdirectory(Platform/)
|
||||
add_subdirectory(Window/)
|
||||
|
||||
target_sources(Editor
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(Windows/)
|
||||
@@ -0,0 +1,4 @@
|
||||
target_sources(Editor
|
||||
PRIVATE
|
||||
GameInterface.h
|
||||
GameInterface.cpp)
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "GameInterface.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
GameInterface::GameInterface(std::string dllPath)
|
||||
: dllPath(dllPath)
|
||||
{
|
||||
reloadGame();
|
||||
}
|
||||
|
||||
GameInterface::~GameInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Game* GameInterface::reloadGame()
|
||||
{
|
||||
if(lib != NULL)
|
||||
{
|
||||
destroyInstance(game);
|
||||
FreeLibrary(lib);
|
||||
}
|
||||
lib = LoadLibraryA(dllPath.c_str());
|
||||
createInstance = (decltype(createInstance))GetProcAddress(lib, "createInstance");
|
||||
destroyInstance = (decltype(destroyInstance))GetProcAddress(lib, "destroyInstance");
|
||||
game = createInstance();
|
||||
return game;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "Game.h"
|
||||
#include "Windows.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class GameInterface
|
||||
{
|
||||
public:
|
||||
GameInterface(std::string dllPath);
|
||||
~GameInterface();
|
||||
Game* reloadGame();
|
||||
private:
|
||||
HMODULE lib = NULL;
|
||||
std::string dllPath;
|
||||
Game* game;
|
||||
Game* (*createInstance)() = nullptr;
|
||||
void (*destroyInstance)(Game*) = nullptr;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1,2 +0,0 @@
|
||||
target_sources(Editor
|
||||
PRIVATE)
|
||||
@@ -1,5 +1,7 @@
|
||||
target_sources(Editor
|
||||
PRIVATE
|
||||
GameView.h
|
||||
GameView.cpp
|
||||
InspectorView.h
|
||||
InspectorView.cpp
|
||||
SceneView.h
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
#include "GameView.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Component/KeyboardInput.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
|
||||
: View(graphics, window, createInfo, "Game")
|
||||
, gameInterface("C:\\Users\\Dynamitos\\TrackClear\\bin\\TrackCleard.dll")
|
||||
, renderGraph(RenderGraphBuilder::build(
|
||||
DepthPrepass(graphics),
|
||||
LightCullingPass(graphics),
|
||||
BasePass(graphics),
|
||||
#ifdef EDITOR
|
||||
DebugPass(graphics),
|
||||
#endif
|
||||
SkyboxRenderPass(graphics)
|
||||
))
|
||||
{
|
||||
scene = new Scene(graphics);
|
||||
systemGraph = new SystemGraph();
|
||||
gameInterface.reloadGame()->setupScene(scene, systemGraph);
|
||||
renderGraph.updateViewport(viewport);
|
||||
}
|
||||
|
||||
GameView::~GameView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameView::beginUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
void GameView::update()
|
||||
{
|
||||
static auto startTime = std::chrono::high_resolution_clock::now();
|
||||
systemGraph->run(threadPool, updateTime);
|
||||
scene->update(updateTime);
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<float> duration = (endTime - startTime);
|
||||
updateTime = duration.count();
|
||||
startTime = endTime;
|
||||
}
|
||||
|
||||
void GameView::commitUpdate()
|
||||
{
|
||||
depthPrepassData.staticDrawList = scene->getStaticMeshes();
|
||||
depthPrepassData.sceneDataBuffer = scene->getSceneDataBuffer();
|
||||
lightCullingData.lightEnv = scene->getLightBuffer();
|
||||
basePassData.staticDrawList = scene->getStaticMeshes();
|
||||
basePassData.sceneDataBuffer = scene->getSceneDataBuffer();
|
||||
#ifdef EDITOR
|
||||
if(showDebug)
|
||||
{
|
||||
debugPassData.vertices = Seele::gDebugVertices;
|
||||
}
|
||||
#endif
|
||||
Seele::gDebugVertices.clear();
|
||||
}
|
||||
|
||||
void GameView::prepareRender()
|
||||
{
|
||||
#ifdef EDITOR
|
||||
renderGraph.updatePassData(depthPrepassData, lightCullingData, basePassData, debugPassData, skyboxData);
|
||||
#else
|
||||
renderGraph.updatePassData(depthPrepassData, lightCullingData, basePassData, skyboxData);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GameView::render()
|
||||
{
|
||||
scene->view<Component::Camera>([&](Component::Camera& cam)
|
||||
{
|
||||
if(cam.mainCamera)
|
||||
{
|
||||
renderGraph.render(cam);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
||||
{
|
||||
scene->view<Component::KeyboardInput>([=](Component::KeyboardInput& input)
|
||||
{
|
||||
//if(code == KeyCode::KEY_R && action == InputAction::PRESS)
|
||||
//{
|
||||
// auto cubeMesh = AssetRegistry::findMesh("cube");
|
||||
// PEntity cube2 = new Entity(scene);
|
||||
// Component::Transform& cube2Transform = cube2->attachComponent<Component::Transform>();
|
||||
// cube2Transform.setPosition(Vector(0, 20, 0));
|
||||
// cube2Transform.setRotation(Quaternion(Vector(0.f, 90.f, 90.f)));
|
||||
// cube2Transform.setScale(Vector(2.f, 2.f, 2.f));
|
||||
// cubeMesh->physicsMesh.type = Component::ColliderType::DYNAMIC;
|
||||
// cube2->attachComponent<Component::Collider>(cubeMesh->physicsMesh);
|
||||
// cube2->attachComponent<Component::StaticMesh>(cubeMesh);
|
||||
// Component::RigidBody& physics2 = cube2->attachComponent<Component::RigidBody>();
|
||||
// physics2.linearMomentum = Vector(0, -10, 0);
|
||||
// physics2.angularMomentum = Vector(0, 0, 0);
|
||||
//}
|
||||
//
|
||||
//if(code == KeyCode::KEY_B && action == InputAction::PRESS)
|
||||
//{
|
||||
// showDebug = !showDebug;
|
||||
// debugPassData.vertices.clear();
|
||||
//}
|
||||
|
||||
input.keys[code] = action != InputAction::RELEASE;
|
||||
});
|
||||
}
|
||||
|
||||
void GameView::mouseMoveCallback(double xPos, double yPos)
|
||||
{
|
||||
scene->view<Component::KeyboardInput>([=](Component::KeyboardInput& input)
|
||||
{
|
||||
input.mouseX = static_cast<float>(xPos);
|
||||
input.mouseY = static_cast<float>(yPos);
|
||||
});
|
||||
}
|
||||
|
||||
void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier)
|
||||
{
|
||||
scene->view<Component::KeyboardInput>([=](Component::KeyboardInput& input)
|
||||
{
|
||||
if (button == MouseButton::MOUSE_BUTTON_1)
|
||||
{
|
||||
input.mouse1 = action != InputAction::RELEASE;
|
||||
}
|
||||
if (button == MouseButton::MOUSE_BUTTON_2)
|
||||
{
|
||||
input.mouse2 = action != InputAction::RELEASE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GameView::scrollCallback(double, double)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameView::fileCallback(int, const char**)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include "Window/View.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Graphics/RenderPass/DepthPrepass.h"
|
||||
#include "Graphics/RenderPass/LightCullingPass.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
#include "Graphics/RenderPass/DebugPass.h"
|
||||
#include "Graphics/RenderPass/SkyboxRenderPass.h"
|
||||
#include "Platform/Windows/GameInterface.h" // TODO
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class GameView : public View
|
||||
{
|
||||
public:
|
||||
GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
|
||||
virtual ~GameView();
|
||||
virtual void beginUpdate() override;
|
||||
virtual void update() override;
|
||||
virtual void commitUpdate() override;
|
||||
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
private:
|
||||
GameInterface gameInterface;
|
||||
RenderGraph<
|
||||
DepthPrepass,
|
||||
LightCullingPass,
|
||||
BasePass,
|
||||
#ifdef EDITOR
|
||||
DebugPass,
|
||||
#endif
|
||||
SkyboxRenderPass
|
||||
> renderGraph;
|
||||
|
||||
DepthPrepassData depthPrepassData;
|
||||
LightCullingPassData lightCullingData;
|
||||
BasePassData basePassData;
|
||||
SkyboxPassData skyboxData;
|
||||
#ifdef EDITOR
|
||||
DebugPassData debugPassData;
|
||||
#endif
|
||||
|
||||
PScene scene;
|
||||
PSystemGraph systemGraph;
|
||||
dp::thread_pool<> threadPool;
|
||||
float updateTime = 0;
|
||||
#ifdef EDITOR
|
||||
bool showDebug = true;
|
||||
#endif
|
||||
|
||||
virtual void keyCallback(Seele::KeyCode code, Seele::InputAction action, Seele::KeyModifier modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(Seele::MouseButton button, Seele::InputAction action, Seele::KeyModifier modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
};
|
||||
DEFINE_REF(GameView)
|
||||
} // namespace Seele
|
||||
@@ -22,19 +22,6 @@ SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreat
|
||||
))
|
||||
, cameraSystem(createInfo.dimensions, Vector(0, 0, 10))
|
||||
{
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Tex_FaceLightmap.png");
|
||||
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Ayaka.fbx");
|
||||
auto meshAsset = AssetRegistry::findMesh("Ayaka");
|
||||
for(auto mesh : meshAsset->getMeshes())
|
||||
{
|
||||
PActor actor = new Actor(scene);
|
||||
actor->attachComponent<Component::StaticMesh>(mesh->vertexInput, mesh->indexBuffer, mesh->referencedMaterial);
|
||||
}
|
||||
|
||||
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
|
||||
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
|
||||
@@ -51,14 +38,12 @@ SceneView::~SceneView()
|
||||
|
||||
void SceneView::beginUpdate()
|
||||
{
|
||||
scene->beginUpdate(Gfx::currentFrameDelta);
|
||||
//co_return;
|
||||
}
|
||||
|
||||
void SceneView::update()
|
||||
{
|
||||
cameraSystem.update(viewportCamera, static_cast<float>(Gfx::currentFrameDelta));
|
||||
scene->commitUpdate();
|
||||
//co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ void ViewportControl::update(Component::Camera& camera, float deltaTime)
|
||||
sin(pitch),
|
||||
sin(yaw) * cos(pitch)));
|
||||
camera.viewMatrix = glm::lookAt(position, position + springArm, Vector(0, 1, 0));
|
||||
camera.projectionMatrix = glm::perspective(fieldOfView, aspectRatio, 0.1f, 1000.0f);
|
||||
std::cout << yaw << " " << pitch << std::endl;
|
||||
}
|
||||
|
||||
|
||||
+12
-5
@@ -1,15 +1,20 @@
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Window/SceneView.h"
|
||||
#include "Window/GameView.h"
|
||||
#include "Window/InspectorView.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Graphics/Vulkan/VulkanGraphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Editor;
|
||||
|
||||
int main()
|
||||
{
|
||||
Gfx::PGraphics graphics = new Vulkan::Graphics();
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
PWindowManager windowManager = new WindowManager();
|
||||
AssetRegistry::init("C:\\Users\\Dynamitos\\TestSeeleProject");
|
||||
AssetRegistry::init(std::string("C:\\Users\\Dynamitos\\TrackClear"), graphics);
|
||||
WindowCreateInfo mainWindowInfo;
|
||||
mainWindowInfo.title = "SeeleEngine";
|
||||
mainWindowInfo.width = 1280;
|
||||
@@ -17,24 +22,26 @@ int main()
|
||||
mainWindowInfo.bFullscreen = false;
|
||||
mainWindowInfo.numSamples = 1;
|
||||
mainWindowInfo.pixelFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM;
|
||||
auto window = windowManager->addWindow(mainWindowInfo);
|
||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
||||
ViewportCreateInfo sceneViewInfo;
|
||||
sceneViewInfo.dimensions.size.x = 1280;
|
||||
sceneViewInfo.dimensions.size.y = 720;
|
||||
sceneViewInfo.dimensions.offset.x = 0;
|
||||
sceneViewInfo.dimensions.offset.y = 0;
|
||||
PSceneView sceneView = new SceneView(windowManager->getGraphics(), window, sceneViewInfo);
|
||||
window->addView(sceneView);
|
||||
PGameView sceneView = new GameView(graphics, window, sceneViewInfo);
|
||||
|
||||
ViewportCreateInfo inspectorViewInfo;
|
||||
inspectorViewInfo.dimensions.size.x = 640;
|
||||
inspectorViewInfo.dimensions.size.y = 720;
|
||||
inspectorViewInfo.dimensions.offset.x = 640;
|
||||
inspectorViewInfo.dimensions.offset.y = 0;
|
||||
PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
|
||||
PInspectorView inspectorView = new InspectorView(graphics, window, inspectorViewInfo);
|
||||
//window->addView(inspectorView);
|
||||
sceneView->setFocused();
|
||||
|
||||
window->render();
|
||||
//export game
|
||||
std::string outputPath = "C:\\Users\\Dynamitos\\TrackClearGame";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user