Major update - Architecture Rework
This commit is contained in:
46
enginecustom/src/inc/system/Cameraclass.h
Normal file
46
enginecustom/src/inc/system/Cameraclass.h
Normal file
@@ -0,0 +1,46 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: cameraclass.h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _CAMERACLASS_H_
|
||||
#define _CAMERACLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <directxmath.h>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: CameraClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class CameraClass
|
||||
{
|
||||
public:
|
||||
CameraClass();
|
||||
CameraClass(const CameraClass&);
|
||||
~CameraClass();
|
||||
|
||||
void SetPosition(float, float, float);
|
||||
void SetRotation(float, float, float);
|
||||
|
||||
XMFLOAT3 GetPosition();
|
||||
XMFLOAT3 GetRotation();
|
||||
|
||||
|
||||
void Render();
|
||||
XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix) const;
|
||||
|
||||
void RenderReflection(float);
|
||||
void GetReflectionViewMatrix(XMMATRIX&) const;
|
||||
|
||||
private:
|
||||
float m_positionX, m_positionY, m_positionZ;
|
||||
float m_rotationX, m_rotationY, m_rotationZ;
|
||||
XMMATRIX m_viewMatrix;
|
||||
XMMATRIX m_reflectionViewMatrix;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
226
enginecustom/src/inc/system/Logger.h
Normal file
226
enginecustom/src/inc/system/Logger.h
Normal file
@@ -0,0 +1,226 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <Windows.h>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
#include <deque>
|
||||
#include <unordered_set>
|
||||
#include <imgui.h>
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
|
||||
static Logger& Get()
|
||||
{
|
||||
static Logger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
Logger(Logger const&) = delete;
|
||||
void operator=(Logger const&) = delete;
|
||||
|
||||
enum class LogLevel
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Shutdown,
|
||||
Initialize,
|
||||
Update,
|
||||
Render,
|
||||
Input,
|
||||
Physics,
|
||||
Audio,
|
||||
Network,
|
||||
Scripting,
|
||||
AI,
|
||||
Resource,
|
||||
Memory,
|
||||
Debug,
|
||||
Count // Do not use this, it's just to get the number of log levels it must at the end
|
||||
};
|
||||
|
||||
// Return the size of the enum class LogLevel as a constant integer
|
||||
static constexpr int LogLevelCount = static_cast<int>(LogLevel::Count);
|
||||
|
||||
struct LogEntry
|
||||
{
|
||||
std::string message;
|
||||
LogLevel level;
|
||||
};
|
||||
|
||||
struct LogLevelInfo
|
||||
{
|
||||
const char* name;
|
||||
int value;
|
||||
ImVec4 color;
|
||||
};
|
||||
|
||||
static const LogLevelInfo GetLogLevelInfo(LogLevel level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case LogLevel::Info: return LogLevelInfo{ "Info", 0, ImVec4(0.0f, 1.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Warning: return LogLevelInfo{ "Warning", 1, ImVec4(1.0f, 1.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Error: return LogLevelInfo{ "Error", 2, ImVec4(1.0f, 0.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Shutdown: return LogLevelInfo{ "Shutdown", 3, ImVec4(0.5f, 0.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Initialize: return LogLevelInfo{ "Initialize", 4, ImVec4(0.0f, 1.0f, 1.0f, 1.0f) };
|
||||
case LogLevel::Update: return LogLevelInfo{ "Update", 5, ImVec4(1.0f, 0.0f, 1.0f, 1.0f) };
|
||||
case LogLevel::Render: return LogLevelInfo{ "Render", 6, ImVec4(1.0f, 1.0f, 1.0f, 1.0f) };
|
||||
case LogLevel::Input: return LogLevelInfo{ "Input", 7, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Physics: return LogLevelInfo{ "Physics", 8, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Audio: return LogLevelInfo{ "Audio", 9, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Network: return LogLevelInfo{ "Network", 10, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Scripting: return LogLevelInfo{ "Scripting", 11, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::AI: return LogLevelInfo{ "AI", 12, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Resource: return LogLevelInfo{ "Resource", 13, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Memory: return LogLevelInfo{ "Memory", 14, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
case LogLevel::Debug: return LogLevelInfo{ "Debug", 15, ImVec4(0.5f, 0.5f, 0.5f, 1.0f) };
|
||||
default: return LogLevelInfo{ "Unknown", 16, ImVec4(1.0f, 1.0f, 1.0f, 1.0f) };
|
||||
}
|
||||
}
|
||||
|
||||
Logger()
|
||||
{
|
||||
char* appdata = nullptr;
|
||||
size_t len;
|
||||
_dupenv_s(&appdata, &len, "APPDATA");
|
||||
if (appdata == nullptr)
|
||||
{
|
||||
m_appdataPath = "log.log";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_appdataPath = appdata;
|
||||
}
|
||||
free(appdata);
|
||||
std::string directoryPath = m_appdataPath + "\\Khaotic Engine";
|
||||
CreateDirectoryA(directoryPath.c_str(), NULL);
|
||||
|
||||
ManageLogFiles(directoryPath);
|
||||
|
||||
m_logFilePath = directoryPath + "\\" + m_logFileName;
|
||||
|
||||
// Enable only the Error warning and shutdown log levels
|
||||
for (int i = 0; i < LogLevelCount; i++)
|
||||
{
|
||||
m_disabledLogLevels[i] = true;
|
||||
|
||||
if (i == static_cast<int>(LogLevel::Error) || i == static_cast<int>(LogLevel::Warning) || i == static_cast<int>(LogLevel::Shutdown))
|
||||
{
|
||||
m_disabledLogLevels[i] = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ecrit un message dans le fichier de log et le stocke dans le buffer
|
||||
void Log(const std::string& message, const std::string& fileName, int lineNumber, LogLevel level = LogLevel::Info)
|
||||
{
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto in_time_t = std::chrono::system_clock::to_time_t(now);
|
||||
|
||||
std::tm buf;
|
||||
localtime_s(&buf, &in_time_t);
|
||||
|
||||
// Obtenez les millisecondes <20> partir de maintenant
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
||||
|
||||
// Utilisez LogLevelToString pour obtenir la cha<68>ne de caract<63>res du niveau de log
|
||||
std::string levelStr = GetLogLevelInfo(level).name;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "[" << std::put_time(&buf, "%Y-%m-%d") << "] "
|
||||
<< "[" << std::put_time(&buf, "%X") << "." << std::setfill('0') << std::setw(3) << ms.count() << "] "
|
||||
<< "[" << levelStr << "] "
|
||||
<< "[" << fileName << ":" << lineNumber << "] "
|
||||
<< message;
|
||||
|
||||
Log(ss.str(), level);
|
||||
|
||||
std::ofstream file(m_logFilePath, std::ios::app);
|
||||
if (file.is_open())
|
||||
{
|
||||
file << ss.str() << std::endl;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
// ecrit un message dans la console
|
||||
void Log(const std::string& message, LogLevel level)
|
||||
{
|
||||
|
||||
// Si le niveau de log est d<>sactiv<69>, ne faites rien
|
||||
if (m_disabledLogLevels[GetLogLevelInfo(level).value])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (logBuffer.size() >= logBufferSize)
|
||||
{
|
||||
logBuffer.pop_front();
|
||||
}
|
||||
logBuffer.push_back({ message, level });
|
||||
}
|
||||
|
||||
const std::deque<LogEntry>& GetLogBuffer() const { return logBuffer; }
|
||||
|
||||
void ManageLogFiles(const std::string& directoryPath)
|
||||
{
|
||||
std::vector<std::filesystem::path> logFiles;
|
||||
|
||||
// Parcourez tous les fichiers dans le dossier
|
||||
for (const auto& entry : std::filesystem::directory_iterator(directoryPath))
|
||||
{
|
||||
// Si le fichier est un fichier de log, ajoutez-le <20> la liste
|
||||
if (entry.path().extension() == ".log")
|
||||
{
|
||||
logFiles.push_back(entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
// Si nous avons plus de trois fichiers de log, supprimez le plus ancien
|
||||
while (logFiles.size() >= 3)
|
||||
{
|
||||
// Triez les fichiers par date de modification, le plus ancien en premier
|
||||
std::sort(logFiles.begin(), logFiles.end(), [](const std::filesystem::path& a, const std::filesystem::path& b)
|
||||
{
|
||||
return std::filesystem::last_write_time(a) < std::filesystem::last_write_time(b);
|
||||
});
|
||||
|
||||
// Supprimez le fichier le plus ancien
|
||||
std::filesystem::remove(logFiles[0]);
|
||||
|
||||
// Supprimez-le de la liste
|
||||
logFiles.erase(logFiles.begin());
|
||||
}
|
||||
|
||||
// Cr<43>ez un nouveau fichier de log pour cette ex<65>cution
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto in_time_t = std::chrono::system_clock::to_time_t(now);
|
||||
std::tm buf;
|
||||
localtime_s(&buf, &in_time_t);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Khaotic_log_" << std::put_time(&buf, "%Y_%m_%d_%Hh%Mm%Ss") << ".log";
|
||||
m_logFileName = ss.str();
|
||||
}
|
||||
|
||||
bool m_disabledLogLevels[LogLevelCount];
|
||||
std::string m_logFilePath;
|
||||
|
||||
private:
|
||||
std::string m_filename;
|
||||
std::string m_appdataPath;
|
||||
std::string m_logFileName;
|
||||
|
||||
std::deque<LogEntry> logBuffer;
|
||||
const size_t logBufferSize = 100;
|
||||
|
||||
};
|
39
enginecustom/src/inc/system/Modellistclass.h
Normal file
39
enginecustom/src/inc/system/Modellistclass.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef _MODELLISTCLASS_H_
|
||||
#define _MODELLISTCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: ModelListClass
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class ModelListClass
|
||||
{
|
||||
private:
|
||||
struct ModelInfoType
|
||||
{
|
||||
float positionX, positionY, positionZ;
|
||||
};
|
||||
|
||||
public:
|
||||
ModelListClass();
|
||||
ModelListClass(const ModelListClass&);
|
||||
~ModelListClass();
|
||||
|
||||
void Initialize(int);
|
||||
void Shutdown();
|
||||
|
||||
int GetModelCount();
|
||||
void GetData(int, float&, float&, float&);
|
||||
|
||||
private:
|
||||
int m_modelCount;
|
||||
ModelInfoType* m_ModelInfoList;
|
||||
};
|
||||
|
||||
#endif
|
37
enginecustom/src/inc/system/Positionclass.h
Normal file
37
enginecustom/src/inc/system/Positionclass.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef _POSITIONCLASS_H_
|
||||
#define _POSITIONCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <math.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: PositionClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class PositionClass
|
||||
{
|
||||
public:
|
||||
PositionClass();
|
||||
PositionClass(const PositionClass&);
|
||||
~PositionClass();
|
||||
|
||||
void SetFrameTime(float);
|
||||
void GetRotation(float&, float&) const;
|
||||
void GetPosition(float&, float&, float&) const;
|
||||
|
||||
void TurnLeft(bool);
|
||||
void TurnRight(bool);
|
||||
void TurnMouse(float, float, float, bool);
|
||||
void MoveCamera(bool, bool, bool, bool, bool, bool, bool, bool, bool);
|
||||
|
||||
private:
|
||||
float m_frameTime;
|
||||
float m_rotationY, m_rotationX;
|
||||
float m_positionX, m_positionY, m_positionZ;
|
||||
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed, m_cameraSpeed, m_speed;
|
||||
};
|
||||
|
||||
#endif
|
63
enginecustom/src/inc/system/Spriteclass.h
Normal file
63
enginecustom/src/inc/system/Spriteclass.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef _SPRITECLASS_H_
|
||||
#define _SPRITECLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <directxmath.h>
|
||||
#include <fstream>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "textureclass.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: SpriteClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class SpriteClass
|
||||
{
|
||||
private:
|
||||
struct VertexType
|
||||
{
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 texture;
|
||||
};
|
||||
|
||||
public:
|
||||
SpriteClass();
|
||||
SpriteClass(const SpriteClass&);
|
||||
~SpriteClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, int, int, char*, int, int);
|
||||
void Shutdown();
|
||||
bool Render(ID3D11DeviceContext*);
|
||||
void Update(float);
|
||||
|
||||
int GetIndexCount();
|
||||
ID3D11ShaderResourceView* GetTexture();
|
||||
|
||||
void SetRenderLocation(int, int);
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*);
|
||||
void ShutdownBuffers();
|
||||
bool UpdateBuffers(ID3D11DeviceContext*);
|
||||
void RenderBuffers(ID3D11DeviceContext*);
|
||||
|
||||
bool LoadTextures(ID3D11Device*, ID3D11DeviceContext*, char*);
|
||||
void ReleaseTextures();
|
||||
|
||||
private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount, m_screenWidth, m_screenHeight, m_bitmapWidth, m_bitmapHeight, m_renderX, m_renderY, m_prevPosX, m_prevPosY;
|
||||
TextureClass* m_Textures;
|
||||
float m_frameTime, m_cycleTime;
|
||||
int m_currentTexture, m_textureCount;
|
||||
};
|
||||
|
||||
#endif
|
34
enginecustom/src/inc/system/Timerclass.h
Normal file
34
enginecustom/src/inc/system/Timerclass.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _TIMERCLASS_H_
|
||||
#define _TIMERCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: TimerClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class TimerClass
|
||||
{
|
||||
public:
|
||||
TimerClass();
|
||||
TimerClass(const TimerClass&);
|
||||
~TimerClass();
|
||||
|
||||
bool Initialize();
|
||||
void Frame();
|
||||
|
||||
float GetTime();
|
||||
|
||||
private:
|
||||
float m_frequency;
|
||||
INT64 m_startTime;
|
||||
float m_frameTime;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
270
enginecustom/src/inc/system/applicationclass.h
Normal file
270
enginecustom/src/inc/system/applicationclass.h
Normal file
@@ -0,0 +1,270 @@
|
||||
#ifndef _APPLICATIONCLASS_H_
|
||||
#define _APPLICATIONCLASS_H_
|
||||
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "d3dclass.h"
|
||||
#include "cameraclass.h"
|
||||
#include "object.h"
|
||||
#include "lightclass.h"
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
#include "bitmapclass.h"
|
||||
#include "spriteclass.h"
|
||||
#include "timerclass.h"
|
||||
#include "fontshaderclass.h"
|
||||
#include "fontclass.h"
|
||||
#include "textclass.h"
|
||||
#include "fpsclass.h"
|
||||
#include "inputclass.h"
|
||||
#include "shadermanagerclass.h"
|
||||
#include "modellistclass.h"
|
||||
#include "positionclass.h"
|
||||
#include "frustumclass.h"
|
||||
#include "rendertextureclass.h"
|
||||
#include "displayplaneclass.h"
|
||||
#include "translateshaderclass.h"
|
||||
#include "reflectionshaderclass.h"
|
||||
#include "physics.h"
|
||||
#include "frustum.h"
|
||||
|
||||
#include <WICTextureLoader.h>
|
||||
#include <comdef.h> // Pour _com_error
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
/////////////
|
||||
const bool FULL_SCREEN = false;
|
||||
const float SCREEN_DEPTH = 1000.0f;
|
||||
const float SCREEN_NEAR = 0.3f;
|
||||
|
||||
struct Input
|
||||
{
|
||||
bool m_KeyLeft = false;
|
||||
bool m_KeyRight = false;
|
||||
bool m_KeyUp = false;
|
||||
bool m_KeyDown = false;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: ApplicationClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ApplicationClass
|
||||
{
|
||||
public:
|
||||
ApplicationClass();
|
||||
~ApplicationClass();
|
||||
D3DClass* GetDirect3D();
|
||||
RenderTextureClass* GetRenderTexture() const { return m_SceneTexture; };
|
||||
|
||||
bool Initialize(int, int, HWND);
|
||||
void Shutdown();
|
||||
bool Frame(InputClass*);
|
||||
void PhysicsThreadFunction();
|
||||
int GetPhysicsTickRate() const { return m_PhysicsTickRate; };
|
||||
void SetPhysicsTickRate(int physicsTickRate) { m_PhysicsTickRate = physicsTickRate; };
|
||||
|
||||
int GetScreenWidth() const;
|
||||
void SetScreenWidth(int screenWidth);
|
||||
int GetScreenHeight() const;
|
||||
void SetScreenHeight(int screenHeight);
|
||||
|
||||
float GetSpeed() const { return m_speed; };
|
||||
void SetSpeed(float speed) { this->m_speed = speed; };
|
||||
|
||||
void AddCube();
|
||||
void DeleteKobject(int index);
|
||||
size_t GetCubeCount() const { return m_cubes.size(); };
|
||||
size_t GetTerrainCubeCount() const { return m_terrainChunk.size(); };
|
||||
std::vector<Object*> GetCubes() const { return m_cubes; };
|
||||
std::vector<Object*> GetTerrainCubes() const { return m_terrainChunk; };
|
||||
std::vector<Object*> GetKobjects() const { return m_object; };
|
||||
void AddKobject(WCHAR* filepath);
|
||||
void SetPath(WCHAR* path) { m_path = path; };
|
||||
void SetWFolder(std::filesystem::path WFolder) { m_WFolder = WFolder; };
|
||||
|
||||
void GenerateTerrain();
|
||||
void DeleteTerrain();
|
||||
|
||||
XMVECTOR GetLightPosition(int index);
|
||||
XMVECTOR GetLightColor(int index);
|
||||
void SetLightPosition(int index, XMVECTOR color);
|
||||
void SetLightColor(int index, XMVECTOR color);
|
||||
void DeleteLight(int index);
|
||||
void AddLight();
|
||||
std::vector<LightClass*> GetLights() const { return m_Lights; };
|
||||
LightClass* GetSunLight() const { return m_SunLight; };
|
||||
|
||||
bool GetShouldQuit() const { return m_ShouldQuit; };
|
||||
void SetShouldQuit(bool shouldQuit) { m_ShouldQuit = shouldQuit; };
|
||||
|
||||
void SetCelShading(bool enable) { m_enableCelShading = enable; };
|
||||
|
||||
void SetVsync(bool vsync);
|
||||
bool GetVsync() const { return VSYNC_ENABLED; };
|
||||
|
||||
HWND GetHwnd() const;
|
||||
void SetHwnd(HWND hwnd);
|
||||
|
||||
bool IsWindowed() const;
|
||||
void SetWindowed(bool windowed);
|
||||
|
||||
void SetWindowSize(ImVec2 size) { windowSize = size; };
|
||||
ImVec2 GetWindowSize() const { return windowSize; };
|
||||
|
||||
Physics* GetPhysics() const { return m_Physics; };
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- Culling ------------- //
|
||||
// ----------------------------------- //
|
||||
|
||||
Frustum GetFrustum() const { return m_FrustumCulling; };
|
||||
void SetFrustum(Frustum frustum) { m_FrustumCulling = frustum; };
|
||||
|
||||
void ConstructFrustum();
|
||||
int GetRenderCount() const { return m_renderCount; };
|
||||
void SetRenderCount(int renderCount) { m_renderCount = renderCount; };
|
||||
float GetFrustumTolerance() const { return m_FrustumCullingTolerance; };
|
||||
void SetFrustumTolerance(float frustumTolerance) { m_FrustumCullingTolerance = frustumTolerance; };
|
||||
|
||||
bool GetCanFixedUpdate() const { return CanFixedUpdate; };
|
||||
void SetCanFixedUpdate(bool canFixedUpdate) { CanFixedUpdate = canFixedUpdate; };
|
||||
|
||||
|
||||
private:
|
||||
bool Render(float, float, float, float, float);
|
||||
bool RenderPhysics(bool keyLeft, bool keyRight, bool keyUp, bool keyDown, float deltaTime);
|
||||
bool UpdateMouseStrings(int, int, bool);
|
||||
bool UpdateFps();
|
||||
bool UpdateRenderCountString(int);
|
||||
bool RenderSceneToTexture(float);
|
||||
bool RenderRefractionToTexture();
|
||||
bool RenderReflectionToTexture();
|
||||
bool RenderPass(const std::vector<std::reference_wrapper<std::vector<Object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
||||
|
||||
void ConstructSkybox(); // Construct the skybox
|
||||
void UpdateSkyboxPosition(); // Update the skybox position
|
||||
bool RenderSkybox(XMMATRIX view, XMMATRIX projection); // Render the skybox
|
||||
|
||||
public :
|
||||
std::vector<ID3D11ShaderResourceView*> textures;
|
||||
std::vector<ID3D11ShaderResourceView*> m_SkyboxTextures;
|
||||
|
||||
private :
|
||||
|
||||
// ------------------------------------- //
|
||||
// ------------- DIRECT3D -------------- //
|
||||
// ------------------------------------- //
|
||||
|
||||
D3DClass* m_Direct3D;
|
||||
IDXGISwapChain* m_swapChain;
|
||||
ModelClass* m_Model,* m_GroundModel, * m_WallModel, * m_BathModel, * m_WaterModel;
|
||||
ModelListClass* m_ModelList;
|
||||
bool VSYNC_ENABLED = true;
|
||||
|
||||
HWND m_hwnd;
|
||||
bool m_windowed;
|
||||
|
||||
// ------------------------------------- //
|
||||
// ------------- RENDERING ------------- //
|
||||
// ------------------------------------- //
|
||||
|
||||
XMMATRIX m_baseViewMatrix;
|
||||
RenderTextureClass* m_RenderTexture, * m_RefractionTexture, * m_ReflectionTexture, * m_SceneTexture;
|
||||
DisplayPlaneClass* m_DisplayPlane;
|
||||
int m_screenWidth, m_screenHeight;
|
||||
CameraClass* m_Camera;
|
||||
PositionClass* m_Position;
|
||||
std::vector<XMMATRIX> m_SkyboxInitialTranslations;
|
||||
|
||||
// ------------------------------------ //
|
||||
// ------------- OBJECTS -------------- //
|
||||
// ------------------------------------ //
|
||||
|
||||
Object* m_SelectedObject;
|
||||
std::vector<Object*> m_cubes;
|
||||
std::vector<Object*> m_terrainChunk;
|
||||
float m_speed = 0.1f; // speed for the demo spinning object
|
||||
std::vector<Object*> m_object;
|
||||
int m_ObjectId = 0;
|
||||
std::vector<std::reference_wrapper<std::vector<Object*>>> m_RenderQueues;
|
||||
std::vector<Object*> m_Skybox;
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- LIGHTS -------------- //
|
||||
// ----------------------------------- //
|
||||
|
||||
LightClass* m_Light;
|
||||
std::vector<LightClass*> m_Lights;
|
||||
int m_numLights;
|
||||
LightClass* m_SunLight;
|
||||
|
||||
XMFLOAT3 TrueLightPosition;
|
||||
ModelClass* m_LightModel;
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- SHADERS ------------- //
|
||||
// ----------------------------------- //
|
||||
|
||||
ShaderManagerClass* m_ShaderManager;
|
||||
FontShaderClass* m_FontShader;
|
||||
BitmapClass* m_Bitmap;
|
||||
SpriteClass* m_Sprite;
|
||||
|
||||
bool m_enableCelShading;
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------ VARIABLES ------------ //
|
||||
// ----------------------------------- //
|
||||
|
||||
float m_waterHeight, m_waterTranslation;
|
||||
wchar_t* m_path;
|
||||
std::filesystem::path m_WFolder;
|
||||
|
||||
// ------------------------------------------------- //
|
||||
// ------------- FPS AND INFO ON SCREEN ------------ //
|
||||
// ------------------------------------------------- //
|
||||
|
||||
TimerClass* m_Timer;
|
||||
TextClass* m_MouseStrings;
|
||||
TextClass* m_RenderCountString;
|
||||
FontClass* m_Font;
|
||||
FpsClass* m_Fps;
|
||||
TextClass* m_FpsString;
|
||||
int m_previousFps;
|
||||
|
||||
// ------------------------------------------------- //
|
||||
// ------------------- OTHER ----------------------- //
|
||||
// ------------------------------------------------- //
|
||||
|
||||
bool m_ShouldQuit;
|
||||
Physics* m_Physics;
|
||||
float m_gravity;
|
||||
XMVECTOR m_previousPosition;
|
||||
ImVec2 windowSize;
|
||||
int m_PhysicsTickRate = 50;
|
||||
bool CanFixedUpdate = false;
|
||||
std::thread m_PhysicsThread;
|
||||
|
||||
// ------------------------------------------------- //
|
||||
// ------------------- Culling --------------------- //
|
||||
// ------------------------------------------------- //
|
||||
|
||||
Frustum m_FrustumCulling;
|
||||
int m_renderCount;
|
||||
float m_FrustumCullingTolerance = 5.f;
|
||||
|
||||
// ------------------------------------------------- //
|
||||
// -------------------- Input ---------------------- //
|
||||
// ------------------------------------------------- //
|
||||
|
||||
Input m_Inputs;
|
||||
};
|
||||
|
||||
#endif
|
59
enginecustom/src/inc/system/bitmapclass.h
Normal file
59
enginecustom/src/inc/system/bitmapclass.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef _BITMAPCLASS_H_
|
||||
#define _BITMAPCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <directxmath.h>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "textureclass.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: BitmapClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class BitmapClass
|
||||
{
|
||||
private:
|
||||
struct VertexType
|
||||
{
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 texture;
|
||||
};
|
||||
|
||||
public:
|
||||
BitmapClass();
|
||||
BitmapClass(const BitmapClass&);
|
||||
~BitmapClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, int, int, char*, int, int);
|
||||
void Shutdown();
|
||||
bool Render(ID3D11DeviceContext*);
|
||||
|
||||
int GetIndexCount();
|
||||
ID3D11ShaderResourceView* GetTexture();
|
||||
|
||||
void SetRenderLocation(int, int);
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*);
|
||||
void ShutdownBuffers();
|
||||
bool UpdateBuffers(ID3D11DeviceContext*);
|
||||
void RenderBuffers(ID3D11DeviceContext*);
|
||||
|
||||
bool LoadTexture(ID3D11Device*, ID3D11DeviceContext*, char*);
|
||||
void ReleaseTexture();
|
||||
private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount, m_screenWidth, m_screenHeight, m_bitmapWidth, m_bitmapHeight, m_renderX, m_renderY, m_prevPosX, m_prevPosY;
|
||||
TextureClass* m_Texture;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
90
enginecustom/src/inc/system/d3dclass.h
Normal file
90
enginecustom/src/inc/system/d3dclass.h
Normal file
@@ -0,0 +1,90 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: d3dclass.h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _D3DCLASS_H_
|
||||
#define _D3DCLASS_H_
|
||||
|
||||
|
||||
/////////////
|
||||
// LINKING //
|
||||
/////////////
|
||||
#pragma comment(lib, "d3d11.lib")
|
||||
#pragma comment(lib, "dxgi.lib")
|
||||
#pragma comment(lib, "d3dcompiler.lib")
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "imguiManager.h"
|
||||
#include "d3d11.h"
|
||||
#include "fontshaderclass.h"
|
||||
#include "fontclass.h"
|
||||
#include "textclass.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: D3DClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class D3DClass
|
||||
{
|
||||
public:
|
||||
D3DClass();
|
||||
D3DClass(const D3DClass&);
|
||||
~D3DClass();
|
||||
|
||||
bool Initialize(int, int, bool, HWND, bool, float, float);
|
||||
void Shutdown();
|
||||
|
||||
void BeginScene(float, float, float, float);
|
||||
void EndScene();
|
||||
|
||||
ID3D11Device* GetDevice();
|
||||
ID3D11DeviceContext* GetDeviceContext();
|
||||
//XMMATRIX GetProjectionMatrix(XMMATRIX& projectionMatrix);
|
||||
IDXGISwapChain* m_swapChain;
|
||||
IDXGISwapChain* GetSwapChain();
|
||||
void ResizeSwapChain(int, int);
|
||||
void SetVsync(bool vsync);
|
||||
|
||||
|
||||
XMMATRIX GetProjectionMatrix() const { return m_projectionMatrix; };
|
||||
XMMATRIX GetWorldMatrix() const { return m_worldMatrix;};
|
||||
XMMATRIX GetOrthoMatrix() const { return m_orthoMatrix; };
|
||||
|
||||
void GetVideoCardInfo(char*, int&);
|
||||
|
||||
void SetBackBufferRenderTarget();
|
||||
void ResetViewport();
|
||||
|
||||
void ReleaseResources();
|
||||
void ResetResources(int newWidth, int newHeight);
|
||||
|
||||
void TurnZBufferOn();
|
||||
void TurnZBufferOff();
|
||||
|
||||
void EnableAlphaBlending();
|
||||
void DisableAlphaBlending();
|
||||
|
||||
private:
|
||||
bool m_vsync_enabled;
|
||||
int m_videoCardMemory;
|
||||
char m_videoCardDescription[128];
|
||||
ID3D11Device* m_device;
|
||||
ID3D11DeviceContext* m_deviceContext;
|
||||
ID3D11RenderTargetView* m_renderTargetView;
|
||||
ID3D11Texture2D* m_depthStencilBuffer;
|
||||
ID3D11DepthStencilState* m_depthStencilState;
|
||||
ID3D11DepthStencilView* m_depthStencilView;
|
||||
ID3D11RasterizerState* m_rasterState;
|
||||
XMMATRIX m_projectionMatrix;
|
||||
XMMATRIX m_worldMatrix;
|
||||
XMMATRIX m_orthoMatrix;
|
||||
D3D11_VIEWPORT m_viewport;
|
||||
ID3D11DepthStencilState* m_depthDisabledStencilState;
|
||||
ID3D11BlendState* m_alphaEnableBlendingState;
|
||||
ID3D11BlendState* m_alphaDisableBlendingState;
|
||||
};
|
||||
|
||||
#endif
|
45
enginecustom/src/inc/system/displayplaneclass.h
Normal file
45
enginecustom/src/inc/system/displayplaneclass.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef _DISPLAYPLANECLASS_H_
|
||||
#define _DISPLAYPLANECLASS_H_
|
||||
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "d3dclass.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: DisplayPlaneClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class DisplayPlaneClass
|
||||
{
|
||||
private:
|
||||
struct VertexType
|
||||
{
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 texture;
|
||||
};
|
||||
|
||||
public:
|
||||
DisplayPlaneClass();
|
||||
DisplayPlaneClass(const DisplayPlaneClass&);
|
||||
~DisplayPlaneClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, float, float);
|
||||
void Shutdown();
|
||||
void Render(ID3D11DeviceContext*);
|
||||
|
||||
int GetIndexCount();
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*, float, float);
|
||||
void ShutdownBuffers();
|
||||
void RenderBuffers(ID3D11DeviceContext*);
|
||||
|
||||
private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
64
enginecustom/src/inc/system/fontclass.h
Normal file
64
enginecustom/src/inc/system/fontclass.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _FONTCLASS_H_
|
||||
#define _FONTCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <directxmath.h>
|
||||
#include <fstream>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "textureclass.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: FontClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class FontClass
|
||||
{
|
||||
private:
|
||||
struct FontType
|
||||
{
|
||||
float left, right;
|
||||
int size;
|
||||
};
|
||||
|
||||
struct VertexType
|
||||
{
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 texture;
|
||||
};
|
||||
|
||||
public:
|
||||
FontClass();
|
||||
FontClass(const FontClass&);
|
||||
~FontClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, int);
|
||||
void Shutdown();
|
||||
|
||||
ID3D11ShaderResourceView* GetTexture();
|
||||
|
||||
void BuildVertexArray(void*, char*, float, float);
|
||||
int GetSentencePixelLength(char*);
|
||||
int GetFontHeight();
|
||||
|
||||
private:
|
||||
bool LoadFontData(char*);
|
||||
void ReleaseFontData();
|
||||
bool LoadTexture(ID3D11Device*, ID3D11DeviceContext*, char*);
|
||||
void ReleaseTexture();
|
||||
|
||||
private:
|
||||
FontType* m_Font;
|
||||
TextureClass* m_Texture;
|
||||
float m_fontHeight;
|
||||
int m_spaceSize;
|
||||
};
|
||||
|
||||
#endif
|
36
enginecustom/src/inc/system/fpsclass.h
Normal file
36
enginecustom/src/inc/system/fpsclass.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _FPSCLASS_H_
|
||||
#define _FPSCLASS_H_
|
||||
|
||||
|
||||
/////////////
|
||||
// LINKING //
|
||||
/////////////
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: FpsClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class FpsClass
|
||||
{
|
||||
public:
|
||||
FpsClass();
|
||||
FpsClass(const FpsClass&);
|
||||
~FpsClass();
|
||||
|
||||
void Initialize();
|
||||
void Frame();
|
||||
int GetFps();
|
||||
|
||||
private:
|
||||
int m_fps, m_count;
|
||||
unsigned long m_startTime;
|
||||
};
|
||||
|
||||
#endif
|
12
enginecustom/src/inc/system/frustum.h
Normal file
12
enginecustom/src/inc/system/frustum.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <DirectXMath.h>
|
||||
using namespace DirectX;
|
||||
|
||||
class Frustum
|
||||
{
|
||||
public:
|
||||
void ConstructFrustum(float screenDepth, XMMATRIX projectionMatrix, XMMATRIX viewMatrix);
|
||||
bool CheckCube(float xCenter, float yCenter, float zCenter, float radius, float tolerance);
|
||||
|
||||
private:
|
||||
XMVECTOR m_planes[6];
|
||||
};
|
33
enginecustom/src/inc/system/frustumclass.h
Normal file
33
enginecustom/src/inc/system/frustumclass.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _FRUSTUMCLASS_H_
|
||||
#define _FRUSTUMCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <directxmath.h>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: FrustumClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class FrustumClass
|
||||
{
|
||||
public:
|
||||
FrustumClass();
|
||||
FrustumClass(const FrustumClass&);
|
||||
~FrustumClass();
|
||||
|
||||
void ConstructFrustum(XMMATRIX, XMMATRIX, float);
|
||||
|
||||
bool CheckPoint(float, float, float);
|
||||
bool CheckCube(float, float, float, float);
|
||||
bool CheckSphere(float, float, float, float);
|
||||
bool CheckRectangle(float, float, float, float, float, float);
|
||||
|
||||
private:
|
||||
XMFLOAT4 m_planes[6];
|
||||
};
|
||||
|
||||
#endif
|
69
enginecustom/src/inc/system/imguiManager.h
Normal file
69
enginecustom/src/inc/system/imguiManager.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
#ifndef _IMGUI_MANAGER_H_
|
||||
#define _IMGUI_MANAGER_H_
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_dx11.h>
|
||||
#include <imgui_impl_win32.h>
|
||||
#include <windows.h>
|
||||
#include <deque>
|
||||
|
||||
class ApplicationClass;
|
||||
|
||||
class imguiManager
|
||||
{
|
||||
public:
|
||||
imguiManager();
|
||||
~imguiManager();
|
||||
|
||||
bool Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext);
|
||||
void Shutdown();
|
||||
void Render();
|
||||
void NewFrame();
|
||||
void SetupDockspace();
|
||||
|
||||
// Widgets
|
||||
void WidgetSpeedSlider(float* speed);
|
||||
void WidgetButton();
|
||||
void WidgetFPS();
|
||||
void WidgetAddObject(ApplicationClass* app);
|
||||
|
||||
void WidgetObjectWindow(ApplicationClass* app);
|
||||
void WidgetTerrainWindow(ApplicationClass* app);
|
||||
void WidgetLightWindow(ApplicationClass* app);
|
||||
void WidgetShaderWindow(ApplicationClass* app);
|
||||
void WidgetEngineSettingsWindow(ApplicationClass* app);
|
||||
void WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize);
|
||||
void WidgetLogWindow(ApplicationClass* app);
|
||||
|
||||
bool ImGuiWidgetRenderer(ApplicationClass* app);
|
||||
|
||||
void SetWindowSize(ImVec2 size) { windowSize = size; }
|
||||
ImVec2 GetWindowSize() const { return windowSize; }
|
||||
|
||||
// Shader toggles
|
||||
|
||||
bool m_EnableCelShading;
|
||||
|
||||
private:
|
||||
bool showObjectWindow;
|
||||
bool showTerrainWindow;
|
||||
bool showLightWindow;
|
||||
bool showShaderWindow;
|
||||
bool showEngineSettingsWindow;
|
||||
bool showLogWindow;
|
||||
|
||||
bool m_isPhyiscsEnabled = false;
|
||||
|
||||
ImGuiIO* io;
|
||||
|
||||
ID3D11Device* m_device;
|
||||
ID3D11DeviceContext* m_deviceContext;
|
||||
ImVec2 windowSize;
|
||||
|
||||
const std::deque<Logger::LogEntry>& logBuffer = Logger::Get().GetLogBuffer();
|
||||
};
|
||||
|
||||
#endif
|
75
enginecustom/src/inc/system/inputclass.h
Normal file
75
enginecustom/src/inc/system/inputclass.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef _INPUTCLASS_H_
|
||||
#define _INPUTCLASS_H_
|
||||
|
||||
///////////////////////////////
|
||||
// PRE-PROCESSING DIRECTIVES //
|
||||
///////////////////////////////
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
|
||||
/////////////
|
||||
// LINKING //
|
||||
/////////////
|
||||
#pragma comment(lib, "dinput8.lib")
|
||||
#pragma comment(lib, "dxguid.lib")
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <dinput.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: InputClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class InputClass
|
||||
{
|
||||
public:
|
||||
InputClass();
|
||||
InputClass(const InputClass&);
|
||||
~InputClass();
|
||||
|
||||
bool Initialize(HINSTANCE, HWND, int, int);
|
||||
void Shutdown();
|
||||
bool Frame();
|
||||
|
||||
bool IsEscapePressed() const;
|
||||
void GetMouseLocation(int&, int&) const;
|
||||
bool IsLeftMousePressed() const;
|
||||
bool IsRightMousePressed() const;
|
||||
void KeyDown(unsigned int);
|
||||
void KeyUp(unsigned int);
|
||||
bool IsLeftArrowPressed() const;
|
||||
bool IsRightArrowPressed() const;
|
||||
bool IsScrollUp() const;
|
||||
bool IsScrollDown() const;
|
||||
bool IsUpArrowPressed() const;
|
||||
bool IsDownArrowPressed() const;
|
||||
bool IsAPressed() const;
|
||||
bool IsDPressed() const;
|
||||
bool IsWPressed() const;
|
||||
bool IsSPressed() const;
|
||||
bool IsQPressed() const;
|
||||
bool IsEPressed()const;
|
||||
|
||||
bool IsKeyDown(unsigned int) const;
|
||||
|
||||
private:
|
||||
bool m_keys[256];
|
||||
|
||||
bool ReadKeyboard();
|
||||
bool ReadMouse();
|
||||
void ProcessInput();
|
||||
|
||||
private:
|
||||
IDirectInput8* m_directInput;
|
||||
IDirectInputDevice8* m_keyboard;
|
||||
IDirectInputDevice8* m_mouse;
|
||||
|
||||
unsigned char m_keyboardState[256];
|
||||
DIMOUSESTATE m_mouseState;
|
||||
|
||||
int m_screenWidth, m_screenHeight, m_mouseX, m_mouseY;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
53
enginecustom/src/inc/system/lightclass.h
Normal file
53
enginecustom/src/inc/system/lightclass.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: lightclass.h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _LIGHTCLASS_H_
|
||||
#define _LIGHTCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include <directxmath.h>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: LightClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class LightClass
|
||||
{
|
||||
public:
|
||||
LightClass();
|
||||
LightClass(const LightClass&);
|
||||
~LightClass();
|
||||
|
||||
void SetAmbientColor(float, float, float, float);
|
||||
void SetDiffuseColor(float, float, float, float);
|
||||
void SetDirection(float, float, float);
|
||||
void SetSpecularColor(float, float, float, float);
|
||||
void SetSpecularPower(float);
|
||||
void SetPosition(float, float, float);
|
||||
|
||||
XMFLOAT4 GetAmbientColor();
|
||||
XMFLOAT4 GetDiffuseColor();
|
||||
XMFLOAT3 GetDirection();
|
||||
XMFLOAT4 GetSpecularColor();
|
||||
float GetSpecularPower();
|
||||
XMFLOAT4 GetPosition();
|
||||
|
||||
void SetIntensity(float intensity) { m_intensity = intensity; }
|
||||
float GetIntensity() const { return m_intensity; }
|
||||
|
||||
private:
|
||||
XMFLOAT4 m_ambientColor;
|
||||
XMFLOAT4 m_diffuseColor;
|
||||
XMFLOAT3 m_direction;
|
||||
XMFLOAT4 m_specularColor;
|
||||
float m_intensity;
|
||||
float m_specularPower;
|
||||
XMFLOAT4 m_position;
|
||||
};
|
||||
|
||||
#endif
|
117
enginecustom/src/inc/system/modelclass.h
Normal file
117
enginecustom/src/inc/system/modelclass.h
Normal file
@@ -0,0 +1,117 @@
|
||||
#ifndef _MODELCLASS_H_
|
||||
#define _MODELCLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <directxmath.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <WICTextureLoader.h>
|
||||
using namespace DirectX;
|
||||
using namespace std;
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "textureclass.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: ModelClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class ModelClass
|
||||
{
|
||||
protected:
|
||||
|
||||
struct VertexType
|
||||
{
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 texture;
|
||||
XMFLOAT3 normal;
|
||||
XMFLOAT3 tangent;
|
||||
XMFLOAT3 binormal;
|
||||
};
|
||||
|
||||
struct ModelType
|
||||
{
|
||||
float x, y, z;
|
||||
float tu, tv;
|
||||
float nx, ny, nz;
|
||||
float tx, ty, tz;
|
||||
float bx, by, bz;
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
float u, v;
|
||||
};
|
||||
|
||||
struct Normal {
|
||||
float nx, ny, nz;
|
||||
};
|
||||
|
||||
struct TempVertexType
|
||||
{
|
||||
float x, y, z;
|
||||
float tu, tv;
|
||||
float nx, ny, nz;
|
||||
};
|
||||
|
||||
struct VectorType
|
||||
{
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
struct Face {
|
||||
int v1, v2, v3;
|
||||
int t1, t2, t3;
|
||||
int n1, n2, n3;
|
||||
};
|
||||
|
||||
public:
|
||||
ModelClass();
|
||||
ModelClass(const ModelClass&);
|
||||
~ModelClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, std::vector<ID3D11ShaderResourceView*>);
|
||||
|
||||
void Shutdown();
|
||||
void Render(ID3D11DeviceContext*);
|
||||
|
||||
int GetIndexCount();
|
||||
ID3D11ShaderResourceView* GetTexture(int index) const;
|
||||
bool ChangeTexture(ID3D11Device*, ID3D11DeviceContext*, std::wstring filename, int index);
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*);
|
||||
void ShutdownBuffers();
|
||||
void RenderBuffers(ID3D11DeviceContext*);
|
||||
bool LoadTextures(ID3D11Device*, ID3D11DeviceContext*, vector<string> filename);
|
||||
void ReleaseTextures();
|
||||
|
||||
bool LoadModel(char*);
|
||||
bool LoadObjModel(char*);
|
||||
bool LoadTxtModel(char*);
|
||||
void ReleaseModel();
|
||||
|
||||
void CalculateModelVectors();
|
||||
void CalculateTangentBinormal(TempVertexType, TempVertexType, TempVertexType, VectorType&, VectorType&);
|
||||
|
||||
private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount;
|
||||
std::vector<ID3D11ShaderResourceView*> m_Textures;
|
||||
ModelType* m_model;
|
||||
};
|
||||
|
||||
#endif
|
112
enginecustom/src/inc/system/object.h
Normal file
112
enginecustom/src/inc/system/object.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
#include "modelclass.h"
|
||||
#include <WICTextureLoader.h>
|
||||
#include <SimpleMath.h>
|
||||
|
||||
enum class ObjectType
|
||||
{
|
||||
Sphere,
|
||||
Cube,
|
||||
Unknown
|
||||
};
|
||||
|
||||
class Object : public ModelClass
|
||||
{
|
||||
public:
|
||||
Object();
|
||||
~Object();
|
||||
|
||||
void SetScaleMatrix(XMMATRIX scaleMatrix);
|
||||
void SetRotateMatrix(XMMATRIX rotateMatrix);
|
||||
void SetTranslateMatrix(XMMATRIX translateMatrix);
|
||||
void SetSRMatrix(XMMATRIX srMatrix);
|
||||
void SetWorldMatrix(XMMATRIX worldMatrix);
|
||||
|
||||
void SetPosition(XMVECTOR position);
|
||||
void SetRotation(XMVECTOR rotation);
|
||||
void SetScale(XMVECTOR scale);
|
||||
|
||||
XMMATRIX GetScaleMatrix() const;
|
||||
XMMATRIX GetRotateMatrix() const;
|
||||
XMMATRIX GetTranslateMatrix() const;
|
||||
XMMATRIX GetSRMatrix() const;
|
||||
XMMATRIX GetWorldMatrix() const;
|
||||
|
||||
XMVECTOR GetPosition();
|
||||
XMVECTOR GetRotation();
|
||||
XMVECTOR GetScale();
|
||||
|
||||
void SetVelocity(XMVECTOR);
|
||||
void AddVelocity(float deltaTime);
|
||||
XMVECTOR GetVelocity() const;
|
||||
void SetAcceleration(XMVECTOR);
|
||||
XMVECTOR GetAcceleration() const;
|
||||
void SetMass(float);
|
||||
float GetMass() const;
|
||||
void SetGrounded(bool);
|
||||
bool IsGrounded() const;
|
||||
bool IsPhysicsEnabled() const;
|
||||
void SetPhysicsEnabled(bool state);
|
||||
|
||||
|
||||
void UpdateWorldMatrix();
|
||||
void UpdateSRMatrix();
|
||||
void UpdateScaleMatrix();
|
||||
void UpdateRotateMatrix();
|
||||
void UpdateTranslateMatrix();
|
||||
|
||||
void UpdatePosition(float deltaTime);
|
||||
|
||||
void Update();
|
||||
|
||||
std::string GetName();
|
||||
void SetName(std::string name);
|
||||
int SetId(int id);
|
||||
int GetId() const;
|
||||
void SetType(ObjectType type) { m_type = type; };
|
||||
ObjectType GetType() const { return m_type; };
|
||||
|
||||
|
||||
enum ShaderType
|
||||
{
|
||||
CEL_SHADING,
|
||||
LIGHTING,
|
||||
NORMAL_MAPPING,
|
||||
SPECULAR_MAPPING,
|
||||
REFLECTION,
|
||||
REFRACTION,
|
||||
TEXTURE,
|
||||
SKYBOX,
|
||||
SUNLIGHT
|
||||
};
|
||||
|
||||
ShaderType GetActiveShader() const { return m_activeShader; };
|
||||
void SetActiveShader(ShaderType activeShader) { m_activeShader = activeShader; };
|
||||
|
||||
float GetBoundingRadius() const;
|
||||
|
||||
public :
|
||||
bool m_demoSpinning = false;
|
||||
XMVECTOR m_previousPosition;
|
||||
XMVECTOR m_velocity;
|
||||
int m_id;
|
||||
|
||||
private:
|
||||
XMMATRIX m_scaleMatrix;
|
||||
XMMATRIX m_rotateMatrix;
|
||||
XMMATRIX m_translateMatrix;
|
||||
XMMATRIX m_srMatrix;
|
||||
XMMATRIX m_worldMatrix;
|
||||
|
||||
XMVECTOR m_acceleration;
|
||||
float m_mass;
|
||||
bool m_isGrounded;
|
||||
bool m_isPhysicsEnabled;
|
||||
|
||||
std::string m_name;
|
||||
ObjectType m_type = ObjectType::Unknown;
|
||||
|
||||
ShaderType m_activeShader = LIGHTING;
|
||||
|
||||
float m_boundingRadius;
|
||||
};
|
27
enginecustom/src/inc/system/physics.h
Normal file
27
enginecustom/src/inc/system/physics.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _PHYSICS_H_
|
||||
#define _PHYSICS_H_
|
||||
|
||||
#include "object.h"
|
||||
#include "math.h"
|
||||
|
||||
class Physics : public Object
|
||||
{
|
||||
public:
|
||||
Physics();
|
||||
explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
|
||||
~Physics();
|
||||
|
||||
XMVECTOR GetGravity() const; // Get the gravity value
|
||||
void SetGravity(XMVECTOR gravity); // Define the gravity value
|
||||
void ApplyGravity(Object*, float); // Apply gravity to an object
|
||||
void AddForce(Object*, XMVECTOR);
|
||||
bool IsColliding(Object*, Object*);
|
||||
bool CubesOverlap(Object*, Object*);
|
||||
bool SpheresOverlap(Object*, Object*);
|
||||
bool SphereCubeOverlap(Object*, Object*);
|
||||
|
||||
private:
|
||||
XMVECTOR m_gravity;
|
||||
};
|
||||
|
||||
#endif
|
53
enginecustom/src/inc/system/rendertextureclass.h
Normal file
53
enginecustom/src/inc/system/rendertextureclass.h
Normal file
@@ -0,0 +1,53 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: rendertextureclass.h
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _RENDERTEXTURECLASS_H_
|
||||
#define _RENDERTEXTURECLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <directxmath.h>
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: RenderTextureClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class RenderTextureClass
|
||||
{
|
||||
public:
|
||||
RenderTextureClass();
|
||||
RenderTextureClass(const RenderTextureClass&);
|
||||
~RenderTextureClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, int, int, float, float, int);
|
||||
void Shutdown();
|
||||
|
||||
void SetRenderTarget(ID3D11DeviceContext*);
|
||||
void ClearRenderTarget(ID3D11DeviceContext*, float, float, float, float);
|
||||
ID3D11ShaderResourceView* GetShaderResourceView();
|
||||
|
||||
void GetProjectionMatrix(XMMATRIX&);
|
||||
void GetOrthoMatrix(XMMATRIX&);
|
||||
|
||||
int GetTextureWidth();
|
||||
int GetTextureHeight();
|
||||
|
||||
private:
|
||||
int m_textureWidth, m_textureHeight;
|
||||
ID3D11Texture2D* m_renderTargetTexture;
|
||||
ID3D11RenderTargetView* m_renderTargetView;
|
||||
ID3D11ShaderResourceView* m_shaderResourceView;
|
||||
ID3D11Texture2D* m_depthStencilBuffer;
|
||||
ID3D11DepthStencilView* m_depthStencilView;
|
||||
D3D11_VIEWPORT m_viewport;
|
||||
XMMATRIX m_projectionMatrix;
|
||||
XMMATRIX m_orthoMatrix;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
65
enginecustom/src/inc/system/systemclass.h
Normal file
65
enginecustom/src/inc/system/systemclass.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef _SYSTEMCLASS_H_
|
||||
#define _SYSTEMCLASS_H_
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include "inputclass.h"
|
||||
#include "applicationclass.h"
|
||||
#include "imguiManager.h"
|
||||
#include <mutex>
|
||||
#include "../resources.h"
|
||||
#include <chrono>
|
||||
|
||||
class SystemClass
|
||||
{
|
||||
public:
|
||||
SystemClass();
|
||||
SystemClass(const SystemClass&);
|
||||
~SystemClass();
|
||||
|
||||
bool Initialize();
|
||||
void Shutdown();
|
||||
void Run();
|
||||
|
||||
LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
void SendPath(wchar_t* path, std::filesystem::path WFolder);
|
||||
|
||||
private:
|
||||
bool Frame();
|
||||
void InitializeWindows(int&, int&);
|
||||
void ShutdownWindows();
|
||||
|
||||
private:
|
||||
LPCWSTR m_applicationName;
|
||||
HINSTANCE m_hinstance;
|
||||
HWND m_hwnd;
|
||||
|
||||
InputClass* m_Input;
|
||||
ApplicationClass* m_Application;
|
||||
imguiManager* m_imguiManager;
|
||||
|
||||
int m_initialWindowWidth;
|
||||
int m_initialWindowHeight;
|
||||
bool m_isDirect3DInitialized;
|
||||
bool m_isResizing = false;
|
||||
|
||||
std::mutex renderMutex;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////
|
||||
// FUNCTION PROTOTYPES //
|
||||
/////////////////////////
|
||||
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
/////////////
|
||||
static SystemClass* ApplicationHandle = 0;
|
||||
|
||||
|
||||
#endif
|
48
enginecustom/src/inc/system/textclass.h
Normal file
48
enginecustom/src/inc/system/textclass.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef _TEXTCLASS_H_
|
||||
#define _TEXTCLASS_H_
|
||||
|
||||
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "fontclass.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: TextClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class TextClass
|
||||
{
|
||||
private:
|
||||
struct VertexType
|
||||
{
|
||||
XMFLOAT3 position;
|
||||
XMFLOAT2 texture;
|
||||
};
|
||||
|
||||
public:
|
||||
TextClass();
|
||||
TextClass(const TextClass&);
|
||||
~TextClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, int, int, int, FontClass*, char*, int, int, float, float, float);
|
||||
void Shutdown();
|
||||
void Render(ID3D11DeviceContext*);
|
||||
|
||||
int GetIndexCount();
|
||||
|
||||
bool UpdateText(ID3D11DeviceContext*, FontClass*, char*, int, int, float, float, float);
|
||||
XMFLOAT4 GetPixelColor();
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*, ID3D11DeviceContext*, FontClass*, char*, int, int, float, float, float);
|
||||
void ShutdownBuffers();
|
||||
void RenderBuffers(ID3D11DeviceContext*);
|
||||
|
||||
private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_screenWidth, m_screenHeight, m_maxLength, m_vertexCount, m_indexCount;
|
||||
XMFLOAT4 m_pixelColor;
|
||||
};
|
||||
|
||||
#endif
|
52
enginecustom/src/inc/system/textureclass.h
Normal file
52
enginecustom/src/inc/system/textureclass.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef _TEXTURECLASS_H_
|
||||
#define _TEXTURECLASS_H_
|
||||
|
||||
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: TextureClass
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class TextureClass
|
||||
{
|
||||
private:
|
||||
struct TargaHeader
|
||||
{
|
||||
unsigned char data1[12];
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned char bpp;
|
||||
unsigned char data2;
|
||||
};
|
||||
|
||||
public:
|
||||
TextureClass();
|
||||
TextureClass(const TextureClass&);
|
||||
~TextureClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, std::string);
|
||||
void Shutdown();
|
||||
|
||||
ID3D11ShaderResourceView* GetTexture();
|
||||
|
||||
int GetWidth();
|
||||
int GetHeight();
|
||||
|
||||
private:
|
||||
bool LoadTarga(std::string);
|
||||
|
||||
private:
|
||||
unsigned char* m_targaData;
|
||||
ID3D11Texture2D* m_texture;
|
||||
ID3D11ShaderResourceView* m_textureView;
|
||||
int m_width, m_height;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user