*
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
#include <Windows.h>
|
||||
#include "LEditor.h"
|
||||
#include <tchar.h>
|
||||
#include "LEngine.h"
|
||||
#include "Ui.h"
|
||||
#include "Controls/UiHwndCoreWindow.h"
|
||||
#include "Controls/UiSwapChainWindow.h"
|
||||
#include "RenderTargetOutput.h"
|
||||
#include "SwapChainOutput.h"
|
||||
#include "Mesh.h"
|
||||
#include "GameObject.h"
|
||||
#include "SceneRenderer.h"
|
||||
#include "AssetManager.h"
|
||||
#include "ObjMeshLoader.h"
|
||||
#include "FreeCameraController.h"
|
||||
#include "Input.h"
|
||||
#include <chrono>
|
||||
#include "BoundsView.h"
|
||||
#include <objbase.h>
|
||||
#include "AssetDatabase.h"
|
||||
#include "AssetMetadata.h"
|
||||
#include "OutputArchive.h"
|
||||
#include "InputArchive.h"
|
||||
#include "Asset.h"
|
||||
#include "AssetFile.h"
|
||||
#include <sstream>
|
||||
|
||||
#pragma comment(lib, "lframework.lib")
|
||||
|
||||
GameObjectPtr CreateCube() {
|
||||
auto cubeObject = GameObject::create();
|
||||
cubeObject->AddComponent<MeshRenderer>()->SetMesh(Mesh::Create([](MeshPtr mesh) {MeshGenerator::Cube(mesh, true); }));
|
||||
return cubeObject;
|
||||
}
|
||||
|
||||
struct TestObject : public Object {
|
||||
uint8_t uint8_t_;
|
||||
uint16_t uint16_t_;
|
||||
uint32_t uint32_t_;
|
||||
uint64_t uint64_t_;
|
||||
std::string string_;
|
||||
std::wstring wstring_;
|
||||
|
||||
std::shared_ptr<TestObject> next;
|
||||
|
||||
virtual void serialize(Archive& archive) override {
|
||||
archive << uint8_t_ << uint16_t_ << uint32_t_;
|
||||
archive << uint64_t_ << string_ << wstring_;
|
||||
archive << std::static_pointer_cast<Object>(next);
|
||||
}
|
||||
};
|
||||
|
||||
void SaveScene(const std::wstring& path){
|
||||
AssetDatabase::get().open_asset_file(path);
|
||||
|
||||
AssetFile asset(Guid(1, 2, 3, 4), path);
|
||||
|
||||
//find all game objects
|
||||
auto scene_objects = Object::FindObjectsOfType<GameObject>();
|
||||
|
||||
//add all game objects and components to scene asset
|
||||
for(auto obj : scene_objects){
|
||||
asset.AddObject(obj);
|
||||
auto components = obj->GetComponents<Component>();
|
||||
for (auto component : components) {
|
||||
asset.AddObject(component);
|
||||
}
|
||||
}
|
||||
|
||||
asset.Save();
|
||||
}
|
||||
|
||||
void CreateTestScene(){
|
||||
auto cameraGo = GameObject::create();
|
||||
cameraGo->SetName(L"Main camera");
|
||||
cameraGo->AddComponent<Camera>()->fov = 45.0f;
|
||||
cameraGo->transform->SetLocalPosition(float3(0.0f, 4.0f, -4.0f));
|
||||
cameraGo->AddComponent<FreeCameraController>();
|
||||
}
|
||||
|
||||
void LoadScene(const std::wstring& path){
|
||||
auto archive = AssetDatabase::get().open_asset_file(path);
|
||||
}
|
||||
|
||||
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
|
||||
AllocConsole();
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
|
||||
auto ints = Input::Instance();
|
||||
AssetDatabase::get().set_root_path(L"D:\\lengine\\Assets");
|
||||
|
||||
auto editorWindow = UiSwapChainWindow::Create(L"LEngineEditorWindow");
|
||||
auto engine = LEngine::Instance();
|
||||
engine->Init(L"D:/lengine/LEngine/");
|
||||
engine->LoadScene("");
|
||||
|
||||
std::wstring scene = L"TestScene.asset";
|
||||
|
||||
CreateTestScene();
|
||||
//SaveScene(scene);
|
||||
|
||||
//LoadScene(scene);
|
||||
|
||||
auto outputs = engine->GetRenderer()->EnumOutputs();
|
||||
auto modes = engine->GetRenderer()->GetDisplayModes(DXGI_FORMAT_B8G8R8A8_UNORM, outputs[0]);
|
||||
|
||||
editorWindow->size = UiSize(640, 480);
|
||||
|
||||
|
||||
auto output = std::make_shared<SwapChainOutput>(engine->GetRenderer(), editorWindow->GetWindow()->GetHwnd(), 640, 480, false);
|
||||
engine->AddOutput(output);
|
||||
|
||||
auto sceneRenderer = std::make_shared<SceneRenderer>();
|
||||
|
||||
ObjMeshLoader loader;
|
||||
auto ob = loader.Load(L"D:\\lengine\\Assets\\Boxes.obj");
|
||||
//ob[0]->AddComponent<BoundsView>();
|
||||
|
||||
auto mat = Material::Create(Shader::Create(L"shaders/shader.fx"), "");
|
||||
auto tex = AssetManager::Instance()->LoadTexture(L"textures/1_store.dds");
|
||||
mat->GetParametersBlock().SetTexture("diffuse", tex);
|
||||
|
||||
|
||||
for(auto o : ob)
|
||||
{
|
||||
o->GetComponent<MeshRenderer>()->SetMaterial(mat, 0);
|
||||
}
|
||||
|
||||
/*AssetMetadata meta(L"D:\\lengine\\Assets\\Boxes.obj");
|
||||
meta.Save();
|
||||
|
||||
auto& factory = ObjectsFactory::instance();
|
||||
|
||||
*/
|
||||
auto cameras = Object::FindObjectsOfType<Camera>();
|
||||
|
||||
auto cameraGo = cameras[0]->gameObject;
|
||||
|
||||
cameraGo->transform->SetLocalPosition(float3(0.0f, 0.0f, -4.0f));
|
||||
|
||||
typedef std::chrono::high_resolution_clock clock;
|
||||
|
||||
auto last_time = clock::now();
|
||||
float delta_time = 0.0f;
|
||||
|
||||
float totalTime = 0;
|
||||
while (true) {
|
||||
auto now_time = clock::now();
|
||||
delta_time = (float)((double)std::chrono::duration_cast<std::chrono::microseconds>(now_time - last_time).count() / 1000000.0);
|
||||
last_time = now_time;
|
||||
totalTime += delta_time;
|
||||
if(totalTime >= 30.0f)
|
||||
{
|
||||
//sceneRenderer->createPSO = false;
|
||||
}
|
||||
std::chrono::high_resolution_clock::now();
|
||||
LEngine::Instance()->GetActiveScene()->tick(delta_time);
|
||||
sceneRenderer->RenderScene(engine->GetRenderer(), engine->GetActiveScene(), cameraGo->GetComponent<Camera>(), output);
|
||||
editorWindow->Update(1);
|
||||
Input::Instance()->strobe();
|
||||
//output->Present();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user