Skip to content

Commit

Permalink
Patched remaining issues, seems okay
Browse files Browse the repository at this point in the history
  • Loading branch information
alekasm committed Aug 3, 2020
1 parent 5c58e99 commit 1a72f06
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
3 changes: 1 addition & 2 deletions SC2KRender/AssetLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#include <iostream>
struct AssetLoader
{
static bool FindFiles(std::wstring directory, std::vector<std::wstring>& vector)
static void FindFiles(std::wstring directory, std::vector<std::wstring>& vector)
{
std::cout << "Current Path: " << std::filesystem::current_path() << std::endl;
for (const std::filesystem::directory_entry& entry :
std::filesystem::recursive_directory_iterator(directory))
{
Expand Down
32 changes: 15 additions & 17 deletions SC2KRender/SC2KRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
freopen_s(&p_file, "CONIN$", "r", stdin);
freopen_s(&p_file, "CONOUT$", "w", stdout);
freopen_s(&p_file, "CONOUT$", "w", stderr);
ShowWindow(GetConsoleWindow(), FALSE);

//Prevent Quick-Edit mode, issue with message passthrough
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
DWORD dwMode;
GetConsoleMode(hInput, &dwMode);
SetConsoleMode(hInput, dwMode & ENABLE_EXTENDED_FLAGS);
ShowWindow(GetConsoleWindow(), SW_HIDE);

printf("SC2KRender (Version 0.2) by Aleksander Krimsky | www.krimsky.net\n");
printf("Written with DirectX 11 - Modified DirectXTK\n");
printf("GitHub: https://github.com/alekasm/SC2KRender \n");
printf("\nControls:\nFree Cam: WASD\nStrafe Up/Down: RF\nScale: Up/Down Arrows\nAdjust Speed: +/-\n\n");
CoInitializeEx(nullptr, COINITBASE_MULTITHREADED);
scene = std::make_unique<Scene>();

Expand Down Expand Up @@ -95,16 +103,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance

MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
if (GetActiveWindow() == hWndClient)
{
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Sleep(10);
}
}

scene.reset();
Expand All @@ -117,11 +118,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_WINDOWPOSCHANGED:
if (scene->Initialized())
{
scene->UpdateWindow(hWnd);
}
case WM_WINDOWPOSCHANGED:
scene->UpdateWindow(hWnd);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
Expand All @@ -147,9 +145,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
std::string filename(ofn.lpstrFile);
if (!filename.empty() && MapLoader::LoadMap(filename, tiles))
{
scene->Initialize(tiles);
scene->SetFocus(true);
SetWindowTextA(hWndClient, std::string("SC2KRender - " + filename).c_str());
scene->Initialize(tiles);
scene->SetFocus(true);
}
}
break;
Expand All @@ -159,7 +157,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
mii.fMask = MIIM_STATE;
mii.fState = MFS_CHECKED | MFS_DISABLED;
SetMenuItemInfo(FileMenu, MENU_SHOW_CONSOLE, FALSE, &mii);
ShowWindow(GetConsoleWindow(), TRUE);
ShowWindow(GetConsoleWindow(), SW_SHOWNOACTIVATE);
break;
}
break;
Expand Down
28 changes: 14 additions & 14 deletions SC2KRender/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ using DirectX::SimpleMath::Vector2;
typedef SceneTile::VertexPos VPos;

void Scene::UpdateWindow(HWND hWnd)
{
{
if (m_d3dDevice.Get() == nullptr)
return; //Don't update window if not pre-initialized
RECT WindowRect;
RECT ClientRect;
GetWindowRect(hWnd, &WindowRect);
Expand Down Expand Up @@ -49,20 +51,20 @@ void Scene::PreInitialize(HWND window)
m_fxFactory = std::make_unique<DirectX::EffectFactory>(m_d3dDevice.Get());
AssetLoader::LoadModels(m_d3dDevice, m_fxFactory, L"assets/models");
#endif

initialized = true;
}

void Scene::Initialize(MapTile* map_tiles)
{
render_scene = false;
delete[] tiles;
delete[] sea_tiles;
fill_tiles.clear();
v_sprite3d.clear();
v_sprite2d.clear();
v_model3d.clear();
tiles = new MapSceneTile[TILES_DIMENSION * TILES_DIMENSION];
sea_tiles = new SceneTile[TILES_DIMENSION * TILES_DIMENSION];



for (unsigned int x = 0; x < TILES_DIMENSION; ++x)
{
for (unsigned int y = 0; y < TILES_DIMENSION; ++y)
Expand Down Expand Up @@ -153,8 +155,6 @@ void Scene::CreateDevice()
m_states = std::make_unique<DirectX::CommonStates>(m_d3dDevice.Get());
m_effect = std::make_unique<DirectX::BasicEffect>(m_d3dDevice.Get());
m_effect->SetVertexColorEnabled(true);
//m_effect->SetTextureEnabled(true);
//m_effect->SetVertexColorEnabled(true);

void const* shaderByteCode;
size_t byteCodeLength;
Expand Down Expand Up @@ -260,9 +260,6 @@ void Scene::CreateResources()
m_d3dDevice->CreateTexture2D(&depthStencilDesc, nullptr, depthStencil.GetAddressOf());
CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
m_d3dDevice->CreateDepthStencilView(depthStencil.Get(), &depthStencilViewDesc, m_depthStencilView.ReleaseAndGetAddressOf());



}

void Scene::Clear()
Expand All @@ -280,7 +277,13 @@ void Scene::Clear()


void Scene::Tick()
{
{
if (GetActiveWindow() != m_window)
{
Sleep(10);
return;
}

if (focused)
{
SetCursorPos(window_cx, window_cy);
Expand Down Expand Up @@ -363,9 +366,6 @@ void Scene::Update(DX::StepTimer const& timer)

void Scene::MouseClick()
{
if (!focused)
return;

float ray_x = + cos(yaw - (float)M_PI_2);
float ray_z = + sin(yaw - (float)M_PI_2);
float ray_y = - sin(pitch); // TODO not accurate
Expand Down
5 changes: 0 additions & 5 deletions SC2KRender/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ class Scene
{
return focused;
}
bool Initialized()
{
return initialized;
}

private:
void CreateDevice();
Expand All @@ -102,7 +98,6 @@ class Scene
float m_outputHeight;
bool render_scene = false;
bool focused = false;
bool initialized = false;

D3D_FEATURE_LEVEL m_featureLevel;
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Expand Down

0 comments on commit 1a72f06

Please sign in to comment.