Compare commits
10 Commits
165073c36d
...
533cb940b7
Author | SHA1 | Date | |
---|---|---|---|
533cb940b7 | |||
86825103ee | |||
3f18601ffc | |||
a32222f22f | |||
ab917089b5 | |||
472cc6b147 | |||
faf9b67222 | |||
800d0eb8e4 | |||
bd7f52ae3d | |||
aa7aafe944 |
102
CMakeLists.txt
102
CMakeLists.txt
@ -1,6 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(CodingGame LANGUAGES C CXX)
|
project(CodingGame LANGUAGES C CXX)
|
||||||
|
|
||||||
|
set(ENGINE_TARGET engine)
|
||||||
|
|
||||||
# ---------- Build-type defaults (only affects single-config generators like Ninja/Make) ----------
|
# ---------- Build-type defaults (only affects single-config generators like Ninja/Make) ----------
|
||||||
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
||||||
@ -12,7 +14,7 @@ if (UNIX)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
glm
|
glm
|
||||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||||
GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e # refs/tags/1.0.1
|
GIT_TAG a532f5b1cf27d6a3c099437e6959cf7e398a0a67 # refs/tags/1.0.2
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(glm)
|
FetchContent_MakeAvailable(glm)
|
||||||
|
|
||||||
@ -34,99 +36,5 @@ elseif (MSVC) # vcpkg
|
|||||||
find_package(EnTT CONFIG REQUIRED)
|
find_package(EnTT CONFIG REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(CodingGame
|
add_subdirectory(engine)
|
||||||
src/IO/parser.cpp
|
add_subdirectory(sandbox)
|
||||||
src/IO/file_manager.cpp
|
|
||||||
|
|
||||||
src/window/window.cpp
|
|
||||||
|
|
||||||
src/components/batch.cpp
|
|
||||||
|
|
||||||
src/renderer/debug.cpp
|
|
||||||
src/renderer/mesh.cpp
|
|
||||||
src/renderer/shader.cpp
|
|
||||||
src/renderer/texture.cpp
|
|
||||||
src/renderer/wavefront.cpp
|
|
||||||
src/renderer/engine.cpp
|
|
||||||
src/renderer/renderer.cpp
|
|
||||||
|
|
||||||
src/main.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set_property(TARGET CodingGame PROPERTY CXX_STANDARD 17)
|
|
||||||
set_property(TARGET CodingGame PROPERTY CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
file(COPY src/shaders DESTINATION ${CMAKE_BINARY_DIR}/)
|
|
||||||
|
|
||||||
target_include_directories(CodingGame PRIVATE
|
|
||||||
${CMAKE_SOURCE_DIR}/include
|
|
||||||
${CMAKE_SOURCE_DIR}/contrib
|
|
||||||
)
|
|
||||||
target_link_libraries(CodingGame PRIVATE
|
|
||||||
SDL3::SDL3
|
|
||||||
OpenGL::GL
|
|
||||||
GLEW::GLEW
|
|
||||||
glm::glm
|
|
||||||
EnTT::EnTT
|
|
||||||
)
|
|
||||||
|
|
||||||
# ---------- Visibility (helps optimizer & smaller binaries on Release) ----------
|
|
||||||
# Only affects non-Windows compilers
|
|
||||||
set_target_properties(CodingGame PROPERTIES
|
|
||||||
CXX_VISIBILITY_PRESET hidden
|
|
||||||
VISIBILITY_INLINES_HIDDEN YES
|
|
||||||
)
|
|
||||||
|
|
||||||
# ---------- Per-config flags ----------
|
|
||||||
# Debug flags (your original intent, kept)
|
|
||||||
if (MSVC)
|
|
||||||
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
|
||||||
target_link_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
|
||||||
else()
|
|
||||||
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Release flags
|
|
||||||
if (MSVC)
|
|
||||||
# /O2: optimize speed, /GL: whole program opt (LTCG), /DNDEBUG: disable asserts
|
|
||||||
target_compile_options(CodingGame PRIVATE
|
|
||||||
$<$<CONFIG:Release>:/O2>
|
|
||||||
$<$<CONFIG:Release>:/DNDEBUG>
|
|
||||||
$<$<CONFIG:RelWithDebInfo>:/O2>
|
|
||||||
)
|
|
||||||
# Link-time codegen & extra linker opts for smaller/faster binaries
|
|
||||||
target_link_options(CodingGame PRIVATE
|
|
||||||
$<$<CONFIG:Release>:/LTCG /OPT:ICF /OPT:REF>
|
|
||||||
$<$<CONFIG:RelWithDebInfo>:/LTCG /OPT:ICF /OPT:REF>
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# GCC/Clang
|
|
||||||
# -O3 for max opts, -ffast-math optional but can be risky; we keep it OFF by default.
|
|
||||||
option(CODINGGAME_USE_MARCH_NATIVE "Enable -march=native on Release for this machine" ON)
|
|
||||||
target_compile_options(CodingGame PRIVATE
|
|
||||||
$<$<CONFIG:Release>:-O3>
|
|
||||||
$<$<AND:$<CONFIG:Release>,$<BOOL:${CODINGGAME_USE_MARCH_NATIVE}>>:-march=native>
|
|
||||||
$<$<CONFIG:Release>:-DNDEBUG>
|
|
||||||
$<$<CONFIG:RelWithDebInfo>:-O3 -g>
|
|
||||||
)
|
|
||||||
# Linker: enable LTO when available; optionally strip symbols on non-Apple
|
|
||||||
include(CheckIPOSupported) # IPO == LTO in CMake terms
|
|
||||||
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_msg)
|
|
||||||
if(ipo_supported)
|
|
||||||
set_property(TARGET CodingGame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
|
||||||
set_property(TARGET CodingGame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
|
|
||||||
# -s strips symbols at link stage (use only for pure Release)
|
|
||||||
target_link_options(CodingGame PRIVATE $<$<CONFIG:Release>:-s>)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ---------- Windows: copy runtime DLLs ----------
|
|
||||||
if (WIN32)
|
|
||||||
add_custom_command(TARGET CodingGame POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
$<TARGET_RUNTIME_DLLS:CodingGame> $<TARGET_FILE_DIR:CodingGame>
|
|
||||||
COMMAND_EXPAND_LISTS)
|
|
||||||
endif()
|
|
||||||
|
102
engine/CMakeLists.txt
Normal file
102
engine/CMakeLists.txt
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
option(ENGINE_BUILD_SHARED "Build the Engine library as a shared library" ON)
|
||||||
|
|
||||||
|
set(SOURCES
|
||||||
|
src/IO/parser.cpp
|
||||||
|
src/IO/file_manager.cpp
|
||||||
|
|
||||||
|
src/window/window.cpp
|
||||||
|
|
||||||
|
src/components/batch.cpp
|
||||||
|
|
||||||
|
src/renderer/debug.cpp
|
||||||
|
src/renderer/mesh.cpp
|
||||||
|
src/renderer/shader.cpp
|
||||||
|
src/renderer/texture.cpp
|
||||||
|
src/renderer/wavefront.cpp
|
||||||
|
src/renderer/core.cpp
|
||||||
|
src/renderer/renderer.cpp
|
||||||
|
|
||||||
|
# src/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#if (ENGINE_BUILD_SHARED)
|
||||||
|
# add_library(${ENGINE_TARGET} SHARED ${SOURCES})
|
||||||
|
#else()
|
||||||
|
# add_library(${ENGINE_TARGET} STATIC ${SOURCES})
|
||||||
|
#endif()
|
||||||
|
|
||||||
|
if(ENGINE_BUILD_SHARED)
|
||||||
|
add_library(${ENGINE_TARGET} SHARED ${SOURCES})
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(${ENGINE_TARGET} PRIVATE ENGINE_BUILD_SHARED ENGINE_EXPORTS)
|
||||||
|
else()
|
||||||
|
target_compile_definitions(${ENGINE_TARGET} PRIVATE ENGINE_BUILD_SHARED)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
add_library(${ENGINE_TARGET} STATIC ${SOURCES})
|
||||||
|
target_compile_definitions(${ENGINE_TARGET} PRIVATE ENGINE_STATIC)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(${ENGINE_TARGET} PROPERTIES
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
CXX_VISIBILITY_PRESET hidden
|
||||||
|
VISIBILITY_INLINES_HIDDEN YES
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${ENGINE_TARGET} PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/contrib
|
||||||
|
)
|
||||||
|
target_link_libraries(${ENGINE_TARGET} PUBLIC
|
||||||
|
SDL3::SDL3
|
||||||
|
OpenGL::GL
|
||||||
|
GLEW::GLEW
|
||||||
|
glm::glm
|
||||||
|
EnTT::EnTT
|
||||||
|
)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
||||||
|
target_link_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
||||||
|
else()
|
||||||
|
target_compile_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Release flags
|
||||||
|
if (MSVC)
|
||||||
|
# /O2: optimize speed, /GL: whole program opt (LTCG), /DNDEBUG: disable asserts
|
||||||
|
target_compile_options(${ENGINE_TARGET} PRIVATE
|
||||||
|
$<$<CONFIG:Release>:/O2>
|
||||||
|
$<$<CONFIG:Release>:/DNDEBUG>
|
||||||
|
$<$<CONFIG:RelWithDebInfo>:/O2>
|
||||||
|
)
|
||||||
|
# Link-time codegen & extra linker opts for smaller/faster binaries
|
||||||
|
target_link_options(${ENGINE_TARGET} PRIVATE
|
||||||
|
$<$<CONFIG:Release>:/LTCG /OPT:ICF /OPT:REF>
|
||||||
|
$<$<CONFIG:RelWithDebInfo>:/LTCG /OPT:ICF /OPT:REF>
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
# GCC/Clang
|
||||||
|
# -O3 for max opts, -ffast-math optional but can be risky; we keep it OFF by default.
|
||||||
|
option(CODINGGAME_USE_MARCH_NATIVE "Enable -march=native on Release for this machine" ON)
|
||||||
|
target_compile_options(${ENGINE_TARGET} PRIVATE
|
||||||
|
$<$<CONFIG:Release>:-O3>
|
||||||
|
$<$<AND:$<CONFIG:Release>,$<BOOL:${CODINGGAME_USE_MARCH_NATIVE}>>:-march=native>
|
||||||
|
$<$<CONFIG:Release>:-DNDEBUG>
|
||||||
|
$<$<CONFIG:RelWithDebInfo>:-O3 -g>
|
||||||
|
)
|
||||||
|
# Linker: enable LTO when available; optionally strip symbols on non-Apple
|
||||||
|
include(CheckIPOSupported) # IPO == LTO in CMake terms
|
||||||
|
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_msg)
|
||||||
|
if(ipo_supported)
|
||||||
|
set_property(TARGET ${ENGINE_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
||||||
|
set_property(TARGET ${ENGINE_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
|
||||||
|
# -s strips symbols at link stage (use only for pure Release)
|
||||||
|
target_link_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Release>:-s>)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
@ -1,7 +1,10 @@
|
|||||||
#ifndef APPLICATION_H_
|
#ifndef APPLICATION_H_
|
||||||
#define APPLICATION_H_
|
#define APPLICATION_H_
|
||||||
|
|
||||||
class IApplication {
|
#include "engine/window/events/window.h"
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
|
class ENGINE_API IApplication {
|
||||||
public:
|
public:
|
||||||
virtual ~IApplication() = default;
|
virtual ~IApplication() = default;
|
||||||
|
|
@ -1,10 +1,11 @@
|
|||||||
#ifndef COMPONENT_BATCH_H_
|
#ifndef COMPONENT_BATCH_H_
|
||||||
#define COMPONENT_BATCH_H_
|
#define COMPONENT_BATCH_H_
|
||||||
|
|
||||||
#include "renderer/renderer.h"
|
#include "engine/renderer/renderer.h"
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
// requires mesh component
|
// requires mesh component
|
||||||
struct batch {
|
struct ENGINE_API batch {
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
public:
|
public:
|
||||||
// requires transform component
|
// requires transform component
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef COMPONENTS_PLAYER_H_
|
#ifndef COMPONENTS_PLAYER_H_
|
||||||
#define COMPONENTS_PLAYER_H_
|
#define COMPONENTS_PLAYER_H_
|
||||||
|
|
||||||
struct camera {};
|
#include "engine/export.h"
|
||||||
|
|
||||||
|
struct ENGINE_API camera {};
|
||||||
|
|
||||||
#endif // COMPONENTS_PLAYER_H_
|
#endif // COMPONENTS_PLAYER_H_
|
@ -2,9 +2,11 @@
|
|||||||
#define COMPONENTS_LIGHT_H_
|
#define COMPONENTS_LIGHT_H_
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include "renderer/renderer.h"
|
|
||||||
|
|
||||||
struct light {
|
#include "engine/renderer/renderer.h"
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
|
struct ENGINE_API light {
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
public:
|
public:
|
||||||
enum LightType {
|
enum LightType {
|
@ -2,9 +2,11 @@
|
|||||||
#define COMPONENTS_MESH_H_
|
#define COMPONENTS_MESH_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "renderer/wavefront.h"
|
|
||||||
|
|
||||||
struct mesh {
|
#include "engine/renderer/wavefront.h"
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
|
struct ENGINE_API mesh {
|
||||||
std::shared_ptr<Object> object;
|
std::shared_ptr<Object> object;
|
||||||
};
|
};
|
||||||
|
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef COMPONENT_ROTATE_H_
|
#ifndef COMPONENT_ROTATE_H_
|
||||||
#define COMPONENT_ROTATE_H_
|
#define COMPONENT_ROTATE_H_
|
||||||
|
|
||||||
struct rotate {};
|
#include "engine/export.h"
|
||||||
|
|
||||||
|
struct ENGINE_API rotate {};
|
||||||
|
|
||||||
#endif // COMPONENT_ROTATE_H_
|
#endif // COMPONENT_ROTATE_H_
|
@ -2,8 +2,9 @@
|
|||||||
#define COMPONENTS_TRANSFORM_H_
|
#define COMPONENTS_TRANSFORM_H_
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
struct transform {
|
struct ENGINE_API transform {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 rotation;
|
glm::vec3 rotation;
|
||||||
glm::vec3 scale;
|
glm::vec3 scale;
|
17
engine/include/engine/engine.h
Normal file
17
engine/include/engine/engine.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <corecrt_math_defines.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "engine/app/app.h"
|
||||||
|
#include "engine/renderer/core.h"
|
||||||
|
|
||||||
|
extern IApplication* CreateApplication();
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Engine::Run(std::unique_ptr<IApplication>(CreateApplication()));
|
||||||
|
return 0;
|
||||||
|
}
|
20
engine/include/engine/export.h
Normal file
20
engine/include/engine/export.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// For static libs, ENGINE_API should be empty.
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if defined(ENGINE_BUILD_SHARED)
|
||||||
|
#if defined(ENGINE_EXPORTS)
|
||||||
|
#define ENGINE_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define ENGINE_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define ENGINE_API
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if defined(ENGINE_BUILD_SHARED)
|
||||||
|
#define ENGINE_API __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define ENGINE_API
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "renderer/mesh.h"
|
#include "engine/renderer/mesh.h"
|
||||||
|
|
||||||
class Vertex {
|
class Vertex {
|
||||||
friend class Mesh;
|
friend class Mesh;
|
@ -4,12 +4,13 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "window/window.h"
|
#include "engine/window/window.h"
|
||||||
#include "window/events/window.h"
|
#include "engine/window/events/window.h"
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "engine/app/app.h"
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
class Engine {
|
class ENGINE_API Engine {
|
||||||
public:
|
public:
|
||||||
static void Run(std::unique_ptr<IApplication> app);
|
static void Run(std::unique_ptr<IApplication> app);
|
||||||
private:
|
private:
|
@ -4,7 +4,7 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "texture.h"
|
#include "engine/renderer/texture.h"
|
||||||
|
|
||||||
class Material {
|
class Material {
|
||||||
private:
|
private:
|
@ -5,7 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "renderer/basics.h"
|
#include "engine/renderer/basics.h"
|
||||||
|
|
||||||
class Mesh {
|
class Mesh {
|
||||||
public: // TODO: abstract away
|
public: // TODO: abstract away
|
@ -4,10 +4,11 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <entt/entity/registry.hpp>
|
#include <entt/entity/registry.hpp>
|
||||||
|
|
||||||
#include "renderer/shader.h"
|
#include "engine/renderer/shader.h"
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
// TODO: make static or singleton
|
// TODO: make static or singleton
|
||||||
class Renderer {
|
class ENGINE_API Renderer {
|
||||||
public:
|
public:
|
||||||
Renderer(entt::registry& registry);
|
Renderer(entt::registry& registry);
|
||||||
|
|
@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class Shader
|
#include "engine/export.h"
|
||||||
|
|
||||||
|
class ENGINE_API Shader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Shader();
|
Shader();
|
@ -7,15 +7,17 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "shader.h"
|
#include "engine/renderer/shader.h"
|
||||||
#include "renderer/renderer.h"
|
#include "engine/renderer/renderer.h"
|
||||||
#include "renderer/material.h"
|
#include "engine/renderer/material.h"
|
||||||
#include "renderer/mesh.h"
|
#include "engine/renderer/mesh.h"
|
||||||
|
|
||||||
|
#include "engine/export.h"
|
||||||
|
|
||||||
enum ObjElement { OHASH, MTLLIB, USEMTL, O, V, VN, VT, F, OUNKNOWN };
|
enum ObjElement { OHASH, MTLLIB, USEMTL, O, V, VN, VT, F, OUNKNOWN };
|
||||||
enum MtlElement { MHASH, NEWMTL, NS, KA, KS, KD, NI, D, ILLUM, MAP_KD, MAP_KA, MUNKNOWN };
|
enum MtlElement { MHASH, NEWMTL, NS, KA, KS, KD, NI, D, ILLUM, MAP_KD, MAP_KA, MUNKNOWN };
|
||||||
|
|
||||||
class Object {
|
class ENGINE_API Object {
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
private:
|
private:
|
||||||
static inline int NormalizeIndex(int idx, int baseCount);
|
static inline int NormalizeIndex(int idx, int baseCount);
|
@ -3,7 +3,7 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "event.h"
|
#include "engine/window/event.h"
|
||||||
|
|
||||||
#define ENGINE_GL_MAJOR_VERSION 4
|
#define ENGINE_GL_MAJOR_VERSION 4
|
||||||
#define ENGINE_GL_MINOR_VERSION 6
|
#define ENGINE_GL_MINOR_VERSION 6
|
@ -1,4 +1,4 @@
|
|||||||
#include "IO/file_manager.h"
|
#include "engine/IO/file_manager.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
@ -2,7 +2,7 @@
|
|||||||
#include <cstdlib> // for strtof (fallback)
|
#include <cstdlib> // for strtof (fallback)
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "IO/parser.h"
|
#include "engine/IO/parser.h"
|
||||||
|
|
||||||
// Skip whitespace
|
// Skip whitespace
|
||||||
void Parser::SkipSpaces() {
|
void Parser::SkipSpaces() {
|
@ -1,6 +1,6 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "components/batch.h"
|
#include "engine/components/batch.h"
|
||||||
|
|
||||||
unsigned int batch::LastID = 0;
|
unsigned int batch::LastID = 0;
|
||||||
|
|
@ -1,9 +1,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "renderer/engine.h"
|
#include "engine/renderer/core.h"
|
||||||
#include "window/event.h"
|
#include "engine/window/event.h"
|
||||||
|
|
||||||
#include "renderer/wavefront.h"
|
#include "engine/renderer/wavefront.h"
|
||||||
|
|
||||||
std::unique_ptr<IApplication> Engine::s_app = nullptr;
|
std::unique_ptr<IApplication> Engine::s_app = nullptr;
|
||||||
std::shared_ptr<Window> Engine::s_window = nullptr;
|
std::shared_ptr<Window> Engine::s_window = nullptr;
|
@ -1,4 +1,4 @@
|
|||||||
#include "renderer/debug.h"
|
#include "engine/renderer/debug.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "renderer/mesh.h"
|
#include "engine/renderer/mesh.h"
|
||||||
|
|
||||||
Mesh::Mesh() {
|
Mesh::Mesh() {
|
||||||
m_vao = 0;
|
m_vao = 0;
|
@ -1,23 +1,22 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/ext/matrix_clip_space.hpp>
|
#include <glm/ext/matrix_clip_space.hpp>
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#include <corecrt_math_defines.h>
|
#include <corecrt_math_defines.h>
|
||||||
#endif
|
#endif
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/gtx/euler_angles.hpp>
|
#include <glm/gtx/euler_angles.hpp>
|
||||||
|
|
||||||
#include "renderer/renderer.h"
|
#include "engine/renderer/renderer.h"
|
||||||
#include "window/window.h"
|
#include "engine/window/window.h"
|
||||||
#include "IO/file_manager.h"
|
#include "engine/IO/file_manager.h"
|
||||||
|
|
||||||
#include "components/transform.h"
|
#include "engine/components/transform.h"
|
||||||
#include "components/camera.h"
|
#include "engine/components/camera.h"
|
||||||
#include "components/light.h"
|
#include "engine/components/light.h"
|
||||||
#include "components/mesh.h"
|
#include "engine/components/mesh.h"
|
||||||
#include "components/batch.h"
|
#include "engine/components/batch.h"
|
||||||
|
|
||||||
Renderer::Renderer(entt::registry& registry) : m_registry(registry)
|
Renderer::Renderer(entt::registry& registry) : m_registry(registry)
|
||||||
{
|
{
|
||||||
@ -29,13 +28,13 @@ Renderer::Renderer(entt::registry& registry) : m_registry(registry)
|
|||||||
);
|
);
|
||||||
|
|
||||||
m_shader.init(
|
m_shader.init(
|
||||||
FileManager::read("./src/shaders/main.vs"),
|
FileManager::read("./engine/src/shaders/main.vs"),
|
||||||
FileManager::read("./src/shaders/pbr.fs")
|
FileManager::read("./engine/src/shaders/pbr.fs")
|
||||||
);
|
);
|
||||||
|
|
||||||
m_depthShader.init(
|
m_depthShader.init(
|
||||||
FileManager::read("./src/shaders/depth.vs"),
|
FileManager::read("./engine/src/shaders/depth.vs"),
|
||||||
FileManager::read("./src/shaders/depth.fs")
|
FileManager::read("./engine/src/shaders/depth.fs")
|
||||||
);
|
);
|
||||||
|
|
||||||
m_model = glm::mat4(1.f);
|
m_model = glm::mat4(1.f);
|
@ -1,6 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include "renderer/shader.h"
|
#include "engine/renderer/shader.h"
|
||||||
|
|
||||||
Shader::Shader()
|
Shader::Shader()
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include "renderer/texture.h"
|
#include "engine/renderer/texture.h"
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
@ -5,9 +5,9 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "IO/parser.h"
|
#include "engine/IO/parser.h"
|
||||||
#include "renderer/mesh.h"
|
#include "engine/renderer/mesh.h"
|
||||||
#include "renderer/wavefront.h"
|
#include "engine/renderer/wavefront.h"
|
||||||
|
|
||||||
#define DEFAULT_MATERIAL_NAME "default"
|
#define DEFAULT_MATERIAL_NAME "default"
|
||||||
|
|
@ -1,12 +1,12 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include "window/window.h"
|
#include "engine/window/window.h"
|
||||||
#include "window/events/window.h"
|
#include "engine/window/events/window.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "renderer/debug.h"
|
#include "engine/renderer/debug.h"
|
||||||
|
|
||||||
std::shared_ptr<Window> Window::s_instance = nullptr;
|
std::shared_ptr<Window> Window::s_instance = nullptr;
|
||||||
|
|
||||||
@ -31,6 +31,8 @@ Window::Window(const char* title, int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_SetWindowRelativeMouseMode(m_handle, true);
|
SDL_SetWindowRelativeMouseMode(m_handle, true);
|
||||||
|
SDL_Rect boundaries = {0, 0, m_width, m_height};
|
||||||
|
SDL_SetWindowMouseRect(m_handle, &boundaries);
|
||||||
|
|
||||||
m_context = SDL_GL_CreateContext(m_handle);
|
m_context = SDL_GL_CreateContext(m_handle);
|
||||||
|
|
||||||
@ -121,6 +123,9 @@ void Window::ProcessEvents() {
|
|||||||
width,
|
width,
|
||||||
height);
|
height);
|
||||||
Dispatch(WindowResized{ m_width, m_height });
|
Dispatch(WindowResized{ m_width, m_height });
|
||||||
|
SDL_SetWindowRelativeMouseMode(m_handle, true);
|
||||||
|
SDL_Rect boundaries = {0, 0, m_width, m_height};
|
||||||
|
SDL_SetWindowMouseRect(m_handle, &boundaries);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
19
sandbox/CMakeLists.txt
Normal file
19
sandbox/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
set(SANDBOX_TARGET sandbox)
|
||||||
|
|
||||||
|
add_executable(${SANDBOX_TARGET} src/main.cpp)
|
||||||
|
|
||||||
|
set_target_properties(${SANDBOX_TARGET} PROPERTIES
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${SANDBOX_TARGET} PRIVATE ${ENGINE_TARGET})
|
||||||
|
|
||||||
|
# --- Copy engine.dll and all dependent DLLs next to sandbox.exe ---
|
||||||
|
if (WIN32)
|
||||||
|
add_custom_command(TARGET ${SANDBOX_TARGET} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
$<TARGET_RUNTIME_DLLS:${SANDBOX_TARGET}> $<TARGET_FILE_DIR:${SANDBOX_TARGET}>
|
||||||
|
COMMAND_EXPAND_LISTS
|
||||||
|
)
|
||||||
|
endif()
|
@ -1,30 +1,26 @@
|
|||||||
#ifndef WIN32
|
|
||||||
#define GLEW_STATIC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <corecrt_math_defines.h>
|
|
||||||
#endif
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/ext/matrix_clip_space.hpp>
|
#include <glm/gtc/constants.hpp>
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
|
||||||
|
|
||||||
#include "renderer/shader.h"
|
#ifdef _WIN32
|
||||||
#include "renderer/wavefront.h"
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include "renderer/engine.h"
|
#include <glm/gtx/extended_min_max.hpp>
|
||||||
#include "renderer/renderer.h"
|
#endif
|
||||||
|
|
||||||
#include "IO/file_manager.h"
|
#include "engine/renderer/wavefront.h"
|
||||||
|
#include "engine/renderer/renderer.h"
|
||||||
|
|
||||||
#include "components/transform.h"
|
#include "engine/app/app.h"
|
||||||
#include "components/light.h"
|
|
||||||
#include "components/camera.h"
|
#include "engine/components/transform.h"
|
||||||
#include "components/mesh.h"
|
#include "engine/components/light.h"
|
||||||
#include "components/rotate.h"
|
#include "engine/components/camera.h"
|
||||||
#include "components/batch.h"
|
#include "engine/components/mesh.h"
|
||||||
|
#include "engine/components/rotate.h"
|
||||||
|
#include "engine/components/batch.h"
|
||||||
|
|
||||||
|
#include "engine/engine.h"
|
||||||
|
|
||||||
class Game : public IApplication {
|
class Game : public IApplication {
|
||||||
public:
|
public:
|
||||||
@ -39,18 +35,18 @@ public:
|
|||||||
m_registry.emplace<transform>(cameraEntity, glm::vec3(0.f, 2.f, 2.f));
|
m_registry.emplace<transform>(cameraEntity, glm::vec3(0.f, 2.f, 2.f));
|
||||||
m_registry.emplace<camera>(cameraEntity);
|
m_registry.emplace<camera>(cameraEntity);
|
||||||
|
|
||||||
Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj");
|
Object* targetObj = Object::LoadFile("./assets/monkey.obj");
|
||||||
const auto targetEntity = m_registry.create();
|
const auto targetEntity = m_registry.create();
|
||||||
m_registry.emplace<transform>(targetEntity, glm::vec3(0.f, 0.0f, 0.f));
|
m_registry.emplace<transform>(targetEntity, glm::vec3(0.f, 0.0f, 0.f));
|
||||||
m_registry.emplace<mesh>(targetEntity, std::shared_ptr<Object>(targetObj));
|
m_registry.emplace<mesh>(targetEntity, std::shared_ptr<Object>(targetObj));
|
||||||
|
|
||||||
Object* grass = Object::LoadFile("./assets/grass_block/grass_block.obj");
|
Object* grass = Object::LoadFile("./assets/cube.obj");
|
||||||
const auto cubeEntity = m_registry.create();
|
const auto cubeEntity = m_registry.create();
|
||||||
m_registry.emplace<transform>(cubeEntity, glm::vec3(-1.5f, 0.4f, 0.f));
|
m_registry.emplace<transform>(cubeEntity, glm::vec3(-1.5f, 0.4f, 0.f));
|
||||||
m_registry.emplace<mesh>(cubeEntity, std::shared_ptr<Object>(grass));
|
m_registry.emplace<mesh>(cubeEntity, std::shared_ptr<Object>(grass));
|
||||||
|
|
||||||
// Cube template (use shared object to avoid reloading 1000 times)
|
// Cube template (use shared object to avoid reloading 1000 times)
|
||||||
std::shared_ptr<Object> cubeObj = std::shared_ptr<Object>(Object::LoadFile("./assets/grass_block/grass_block.obj"));
|
std::shared_ptr<Object> cubeObj = std::shared_ptr<Object>(Object::LoadFile("./assets/cube.obj"));
|
||||||
const auto batchEntt = m_registry.create();
|
const auto batchEntt = m_registry.create();
|
||||||
m_registry.emplace<batch>(batchEntt);
|
m_registry.emplace<batch>(batchEntt);
|
||||||
m_registry.emplace<mesh>(batchEntt, cubeObj);
|
m_registry.emplace<mesh>(batchEntt, cubeObj);
|
||||||
@ -166,7 +162,7 @@ public:
|
|||||||
glm::vec3 sunDir = glm::normalize(glm::vec3(0.0f, sin(sunAngle), cos(sunAngle)));
|
glm::vec3 sunDir = glm::normalize(glm::vec3(0.0f, sin(sunAngle), cos(sunAngle)));
|
||||||
|
|
||||||
// Compute intensity: bright at noon, dim at dusk/dawn, dark at night
|
// Compute intensity: bright at noon, dim at dusk/dawn, dark at night
|
||||||
float intensity = glm::max(sin(sunAngle), (double)0.0f); // 0 at night, 1 at noon
|
float intensity = glm::max(static_cast<double>(sin(sunAngle)), static_cast<double>(0.0f)); // 0 at night, 1 at noon
|
||||||
intensity = glm::mix(0.05f, 1.5f, intensity); // keep some ambient even at night
|
intensity = glm::mix(0.05f, 1.5f, intensity); // keep some ambient even at night
|
||||||
|
|
||||||
// Optional: tint color (warm at sunrise/sunset)
|
// Optional: tint color (warm at sunrise/sunset)
|
||||||
@ -232,7 +228,6 @@ private:
|
|||||||
Uint64 m_currentTicks;
|
Uint64 m_currentTicks;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
IApplication* CreateApplication() {
|
||||||
Engine::Run(std::make_unique<Game>());
|
return new Game();
|
||||||
return 0;
|
}
|
||||||
}
|
|
Reference in New Issue
Block a user