diff --git a/__pycache__/remake_config.cpython-312.pyc b/__pycache__/remake_config.cpython-312.pyc new file mode 100644 index 0000000..38e003f Binary files /dev/null and b/__pycache__/remake_config.cpython-312.pyc differ diff --git a/build.log b/build.log index 4126992..c231ec6 100644 --- a/build.log +++ b/build.log @@ -1,14 +1,3 @@ -[COMPILE] g++ -std=c++20 -Wall -Isrc/include -Isrc/vendor -Isrc/vendor/imgui -IC:/msys64/mingw64/include -MMD -MP -c src\src\Components\SpriteComponent.cpp -o src\build\src\Components\SpriteComponent.oIn file included from C:/msys64/mingw64/include/yaml-cpp/parser.h:13, - from C:/msys64/mingw64/include/yaml-cpp/yaml.h:10, - from src\src\Components\Component.h:5, - from src\src\Components\SpriteComponent.h:3, - from src\src\Components\SpriteComponent.cpp:1: -C:/msys64/mingw64/include/yaml-cpp/dll.h:22:65: note: '#pragma message: Defining YAML_CPP_API for DLL import' - 22 | # pragma message( "Defining YAML_CPP_API for DLL import" ) - | ^ - -[LINK] g++ src\build\src\Engine.o src\build\src\main.o src\build\src\Renderer.o src\build\src\Components\CameraComponent.o src\build\src\Components\LightComponent.o src\build\src\Components\SpriteComponent.o src\build\src\Entitys\Object.o src\build\src\utils\FileDialog.o src\build\src\utils\Logging.o src\build\src\utils\Shader.o src\build\src\utils\utils.o src\build\vendor\imgui\imgui.o src\build\vendor\imgui\imgui_demo.o src\build\vendor\imgui\imgui_draw.o src\build\vendor\imgui\imgui_impl_glfw.o src\build\vendor\imgui\imgui_impl_opengl3.o src\build\vendor\imgui\imgui_tables.o src\build\vendor\imgui\imgui_widgets.o -o src\build\app.exe -LC:/msys64/mingw64/lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto - -[TIME] Build duration: 3.58s -[RUN] Executed app.exe successfully. -[TIME] Total runtime: 114.21s +[LINK] g++ src\build\src\Engine.o src\build\src\main.o src\build\src\Renderer.o src\build\src\Components\CameraComponent.o src\build\src\Components\LightComponent.o src\build\src\Components\SpriteComponent.o src\build\src\Entitys\Object.o src\build\src\utils\FileDialog.o src\build\src\utils\Logging.o src\build\src\utils\Shader.o src\build\src\utils\utils.o src\build\vendor\imgui\imgui.o src\build\vendor\imgui\imgui_demo.o src\build\vendor\imgui\imgui_draw.o src\build\vendor\imgui\imgui_impl_glfw.o src\build\vendor\imgui\imgui_impl_opengl3.o src\build\vendor\imgui\imgui_tables.o src\build\vendor\imgui\imgui_widgets.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto +[ERROR] Runtime crash +Command 'src\build\app.exe' returned non-zero exit status 3221225477. diff --git a/imgui.ini b/imgui.ini index cfd5086..ec42917 100644 --- a/imgui.ini +++ b/imgui.ini @@ -52,8 +52,8 @@ DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=X DockNode ID=0x00000003 Parent=0x11111111 SizeRef=1406,1158 Split=X DockNode ID=0x00000001 Parent=0x00000003 SizeRef=263,701 HiddenTabBar=1 Selected=0x12EF0F59 DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1141,701 Split=Y Selected=0xC450F867 - DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,869 CentralNode=1 Selected=0xC450F867 - DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,287 Selected=0xEA83D666 + DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,869 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867 + DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,287 HiddenTabBar=1 Selected=0xEA83D666 DockNode ID=0x00000004 Parent=0x11111111 SizeRef=512,1158 Split=Y Selected=0x36DC96AB DockNode ID=0x00000005 Parent=0x00000004 SizeRef=407,835 HiddenTabBar=1 Selected=0x36DC96AB DockNode ID=0x00000006 Parent=0x00000004 SizeRef=407,321 HiddenTabBar=1 Selected=0x3FC1A724 diff --git a/remake/.remake_cache.json b/remake/.remake_cache.json new file mode 100644 index 0000000..c59484a --- /dev/null +++ b/remake/.remake_cache.json @@ -0,0 +1,11 @@ +{ + "glfw3": "C:\\msys64\\mingw64\\lib\\libglfw3.a", + "glew32": "C:\\msys64\\mingw64\\lib\\libglew32.a", + "opengl32": "C:\\msys64\\mingw64\\lib\\libopengl32.a", + "gdi32": "C:\\msys64\\mingw64\\lib\\libgdi32.a", + "yaml-cpp": "C:\\msys64\\mingw64\\lib\\libyaml-cpp.a", + "comdlg32": "C:\\msys64\\mingw64\\lib\\libcomdlg32.a", + "ssl": "C:\\msys64\\mingw64\\lib\\libssl.a", + "crypto": "C:\\msys64\\mingw64\\lib\\libcrypto.a", + "imgui": "src\\vendor\\imgui" +} \ No newline at end of file diff --git a/remake/__pycache__/remake_config.cpython-312.pyc b/remake/__pycache__/remake_config.cpython-312.pyc new file mode 100644 index 0000000..5f24616 Binary files /dev/null and b/remake/__pycache__/remake_config.cpython-312.pyc differ diff --git a/build.py b/remake/build.py similarity index 52% rename from build.py rename to remake/build.py index a2cd7c7..cbb1665 100644 --- a/build.py +++ b/remake/build.py @@ -4,47 +4,8 @@ from pathlib import Path import sys import shutil import time - -# ========== CONFIG ========== -SRC_DIRS = ["src/src", "src/vendor"] - - -INCLUDE_DIRS = [ - "src/include", - "src/vendor", - "src/vendor/imgui", - "C:/msys64/mingw64/include" -] - - - -LIB_DIRS = ["C:/msys64/mingw64/lib"] -BUILD_DIR = Path("src/build") -TARGET = BUILD_DIR / "app.exe" -LOG_FILE = Path("build.log") -LIBS = ["glfw3", "glew32", "opengl32", "gdi32", "yaml-cpp", "comdlg32", "ssl", "crypto"] - - -CXX = "g++" -CXXFLAGS = ["-std=c++20", "-Wall"] + [f"-I{inc}" for inc in INCLUDE_DIRS] -LDFLAGS = [f"-L{lib}" for lib in LIB_DIRS] + [f"-l{lib}" for lib in LIBS] - - - - - - - - - - - - - - - - - +import json +from remake_config import * # ========== COLOR UTILS ========== class Colors: @@ -68,6 +29,80 @@ def log(msg: str): with LOG_FILE.open("a", encoding="utf-8") as f: f.write(msg + "\n") +# ========== CACHE ========== +def load_cache(): + try: + if CACHE_FILE.exists(): + return json.loads(CACHE_FILE.read_text()) + except json.decoder.JSONDecodeError: + error("Failed to Read Cache File.") + return {} + +def save_cache(data): + CACHE_FILE.write_text(json.dumps(data, indent=2)) + +# ========== PACKAGE DISCOVERY ========== +class AutoLib: + def __init__(self, name): + self.name = name + self.path = None + + def find(self, search_paths, cache): + if self.name in cache: + self.path = Path(cache[self.name]) + return self.path.exists() + + for path in search_paths: + for root, _, files in os.walk(path): + for ext in [".lib", ".a"]: + fname = f"lib{self.name}{ext}" + if fname in files: + self.path = Path(root) / fname + cache[self.name] = str(self.path) + info(f"Found {self.name} at {self.path}") + return True + return False + +class AutoInclude: + def __init__(self, name): + self.name = name + self.path = None + + def find(self, search_paths, cache): + if self.name in cache: + self.path = Path(cache[self.name]) + return self.path.exists() + + for path in search_paths: + for root, _, files in os.walk(path): + if f"{self.name}.h" in files or Path(root).name == self.name: + self.path = Path(root) + cache[self.name] = str(self.path) + info(f"Found header {self.name} at {self.path}") + return True + return False + +def resolve_packages(): + cache = load_cache() + extra_link_paths, resolved_libs, extra_includes = [], [], [] + + for name in AUTO_LIBS: + lib = AutoLib(name) + if lib.find(LIB_DIRS, cache): + extra_link_paths.append(str(lib.path.parent)) + resolved_libs.append(f"-l{lib.name}") + else: + error(f"Library {lib.name} not found.") + sys.exit(1) + + for name in AUTO_INCLUDES: + inc = AutoInclude(name) + if inc.find(INCLUDE_DIRS, cache): + extra_includes.append(str(inc.path)) + + save_cache(cache) + return list(set(extra_link_paths)), resolved_libs, list(set(extra_includes)) + # ========== BUILD SYSTEM ========== def find_cpp_files(): cpp_files = [] @@ -80,8 +115,7 @@ def obj_path(source): return BUILD_DIR / source.relative_to("src").with_suffix(" def dep_path(obj): return obj.with_suffix(".d") def parse_dep_file(dep_file): - if not dep_file.exists(): - return [] + if not dep_file.exists(): return [] deps = [] with dep_file.open() as f: for line in f: @@ -91,13 +125,13 @@ def parse_dep_file(dep_file): deps.extend(line.strip().split()) return deps -def compile_source(source, obj): +def compile_source(source, obj, includes): obj.parent.mkdir(parents=True, exist_ok=True) - cmd = [CXX, *CXXFLAGS, "-MMD", "-MP", "-c", str(source), "-o", str(obj)] + cmd = [CXX, *CXXFLAGS, *[f"-I{inc}" for inc in includes], "-MMD", "-MP", "-c", str(source), "-o", str(obj)] try: print(f"{color('๐Ÿ”จ Compiling:', Colors.OKCYAN)} {source}") - result = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - log(f"[COMPILE] {' '.join(cmd)}{result.stdout.decode()}{result.stderr.decode()}") + subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + log(f"[COMPILE] {' '.join(cmd)}") except subprocess.CalledProcessError as e: error(f"Failed to compile {source}") print("๐Ÿ”ง Command:", " ".join(cmd)) @@ -105,12 +139,12 @@ def compile_source(source, obj): log(f"[ERROR] {' '.join(cmd)}\n{e.stderr.decode()}") sys.exit(1) -def link_objects(obj_files): - cmd = [CXX, *map(str, obj_files), "-o", str(TARGET), *LDFLAGS] +def link_objects(obj_files, link_dirs, libs): + cmd = [CXX, *map(str, obj_files), "-o", str(TARGET), *[f"-L{p}" for p in link_dirs], *libs] try: print(f"{color('๐Ÿ“ฆ Linking:', Colors.OKBLUE)} {TARGET}") - result = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - log(f"[LINK] {' '.join(cmd)}\n{result.stdout.decode()}{result.stderr.decode()}") + subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + log(f"[LINK] {' '.join(cmd)}") except subprocess.CalledProcessError as e: error("Linking failed.") print("๐Ÿ”ง Command:", " ".join(cmd)) @@ -118,27 +152,21 @@ def link_objects(obj_files): log(f"[ERROR] {' '.join(cmd)}\n{e.stderr.decode()}") sys.exit(1) - - def build(): build_start = time.time() banner("๐Ÿš€ Building Project") - cpp_files = find_cpp_files() obj_files = [] + link_dirs, libs, extra_includes = resolve_packages() + all_includes = INCLUDE_DIRS + extra_includes + for source in cpp_files: obj = obj_path(source) dep = dep_path(obj) - obj_mtime = obj.stat().st_mtime if obj.exists() else 0 - needs_build = not obj.exists() + needs_build = not obj.exists() or source.stat().st_mtime > obj_mtime - # If source is newer than object - if not needs_build and source.stat().st_mtime > obj_mtime: - needs_build = True - - # If any dependencies are newer than object if not needs_build and dep.exists(): for dep_file in parse_dep_file(dep): try: @@ -150,27 +178,21 @@ def build(): break if needs_build: - compile_source(source, obj) + compile_source(source, obj, all_includes) else: print(f"{color('๐Ÿ‘Œ Up-to-date:', Colors.GRAY)} {source}") obj_files.append(obj) - link_objects(obj_files) + link_objects(obj_files, link_dirs, libs) banner("โœ… Build Complete") - build_end = time.time() - log(f"[TIME] Build duration: {build_end - build_start:.2f}s") - print(color(f"โฑ Build time: {build_end - build_start:.2f}s", Colors.OKCYAN)) - - - - + print(color(f"โฑ Build time: {time.time() - build_start:.2f}s", Colors.OKCYAN)) def run(): build() if TARGET.exists(): banner("๐Ÿš€ Running") try: - result = subprocess.run(str(TARGET), check=True) + subprocess.run(str(TARGET), check=True) log("[RUN] Executed app.exe successfully.") except subprocess.CalledProcessError as e: error("Program exited with error.") @@ -178,26 +200,22 @@ def run(): sys.exit(e.returncode) else: error("Executable not found.") - log("[ERROR] Executable not found.") def clean(): banner("๐Ÿงน Cleaning") if BUILD_DIR.exists(): shutil.rmtree(BUILD_DIR) info("Build directory removed.") - log("[CLEAN] Build directory removed.") - else: - warn("Nothing to clean.") - log("[CLEAN] No build directory found.") if LOG_FILE.exists(): LOG_FILE.unlink() info("Log file cleared.") + if CACHE_FILE.exists(): + CACHE_FILE.unlink() + info("Cache file cleared.") # ========== ENTRY ========== if __name__ == "__main__": - total_start = time.time() - - # Clear old log + start = time.time() LOG_FILE.write_text("", encoding="utf-8") try: @@ -209,9 +227,7 @@ if __name__ == "__main__": build() except KeyboardInterrupt: error("Interrupted by user.") - log("[ERROR] Build interrupted by user.") + log("[ERROR] Interrupted by user.") sys.exit(1) - total_end = time.time() - print(color(f"\nโฑ Total time: {total_end - total_start:.2f}s", Colors.BOLD + Colors.OKGREEN)) - log(f"[TIME] Total runtime: {total_end - total_start:.2f}s") + print(color(f"\nโฑ Total time: {time.time() - start:.2f}s", Colors.BOLD + Colors.OKGREEN)) \ No newline at end of file diff --git a/remake/remake_config.py b/remake/remake_config.py new file mode 100644 index 0000000..4837fa3 --- /dev/null +++ b/remake/remake_config.py @@ -0,0 +1,34 @@ +from pathlib import Path + +# Source and header directories +SRC_DIRS = ["src/src", "src/vendor"] +INCLUDE_DIRS = [ + "src/include", + "src/vendor", + "src/vendor/imgui", + "C:/msys64/mingw64/include" +] + +# Default library search paths +LIB_DIRS = [ + "C:/msys64/mingw64/lib", + "C:/Program Files", + "C:/Program Files (x86)", + "C:/libs", +] + +# Compiler and build options +BUILD_DIR = Path("src/build") +TARGET = BUILD_DIR / "app.exe" +LOG_FILE = Path("build.log") +CACHE_FILE = Path("./remake/.remake_cache.json") +CXX = "g++" +CXXFLAGS = ["-std=c++20", "-Wall"] + [f"-I{inc}" for inc in INCLUDE_DIRS] + +# Libraries and includes to auto-discover +AUTO_LIBS = [ + "glfw3", "glew32", "opengl32", "gdi32", + "yaml-cpp", "comdlg32", "ssl", "crypto" +] + +AUTO_INCLUDES = ["imgui", "yaml-cpp"] diff --git a/src/assets/scenes/test.cene b/src/assets/scenes/test.cene index 89dc2c9..5b80b8b 100644 --- a/src/assets/scenes/test.cene +++ b/src/assets/scenes/test.cene @@ -1,6 +1,6 @@ engine_version: 0.1.0 scene_name: test -scene_hash: c964933c59e665a145e853a714b47d1c39c80a3a91394f974e8e4dd4542e9e82 +scene_hash: b4b8f6fe7881b1b5183673450e9a2b43fff7f5d24e88fbedf920edf09cd63fd2 format_version: 1 objects: - name: Sprite Object @@ -32,33 +32,84 @@ objects: texture: C:\Users\spenc\OneDrive\Pictures\49555.jpg normalMap: "" children: [] - - name: NewObject - position: [0, 444] - layer: 0 + - name: Bark + position: [1024, 0] + layer: -1 components: - type: SpriteComponent - texture: C:\Users\spenc\OneDrive\Pictures\49555.jpg - normalMap: C:\Users\spenc\OneDrive\Pictures\images.jpg + texture: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_nor_gl_1k.png children: [] - - name: Light + - name: Sun position: [-5000, -5000] layer: 1 components: - type: LightComponent color: - - 0.996078432 - - 1 - - 1 - intensity: 0.800000012 + - 0.990196049 + - 0.943370163 + - 0.791186035 + intensity: 2.0999999 radius: 100000000 falloff: 0.100000001 type: 0 children: [] - - name: NewSprite - position: [-667, 194] + - name: Rocks + position: [0, 0] layer: -1 components: - type: SpriteComponent texture: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_diff_1k.png normalMap: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_nor_gl_1k.png - children: [] \ No newline at end of file + children: [] + - name: World + position: [-436, 248] + layer: 0 + components: [] + children: + - name: Rocks + position: [0, 0] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_nor_gl_1k.png + children: [] + - name: Bark + position: [1024, 0] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_nor_gl_1k.png + children: [] + - name: Planks + position: [0, 1024] + layer: 0 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\wood_floor_worn_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\wood_floor_worn_nor_gl_1k.png + children: [] + - name: Metal + position: [1024, 1024] + layer: 0 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\metal_plate_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\metal_plate_nor_gl_1k.png + children: [] + - name: Sun + position: [-5000, -5000] + layer: 1 + components: + - type: LightComponent + color: + - 0.990196049 + - 0.943370163 + - 0.791186035 + intensity: 2.0999999 + radius: 100000000 + falloff: 0.100000001 + type: 0 + children: [] \ No newline at end of file diff --git a/src/assets/scenes/world.cene b/src/assets/scenes/world.cene new file mode 100644 index 0000000..08fe5aa --- /dev/null +++ b/src/assets/scenes/world.cene @@ -0,0 +1,123 @@ +engine_version: 0.1.0 +scene_name: Normal Map Test +scene_hash: 2aa0652450eaf2aa838b1a49c8c5e1ee27a0412c93b25e3c213d5b23f1d96e5a +format_version: 1 +objects: + - name: Face1 + position: [258, 0] + layer: 0 + components: + - type: CameraComponent + fov: 45 + aspect: 1.76999998 + zoom: 1 + primary: true + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\49555.jpg + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\circuits_normal.jpg + children: + - name: Face2 + position: [403, 189] + layer: 0 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\49555.jpg + normalMap: C:\Users\spenc\OneDrive\Pictures\brick-normal.jpg + children: [] + - name: Logo (+normal) + position: [1686, 929] + layer: 0 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\blue_logo.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\circuits_normal.jpg + children: + - name: NewObject + position: [1080, 0] + layer: 0 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\blue_logo.png + normalMap: C:\Users\spenc\OneDrive\Pictures\images.jpg + children: [] + - name: Bark + position: [1024, 0] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_nor_gl_1k.png + children: [] + - name: Sun + position: [-5000, -5000] + layer: 1 + components: + - type: LightComponent + color: + - 0.992156863 + - 0.984313726 + - 0.827450991 + intensity: 1.25 + radius: 100000000 + falloff: 0.100000001 + type: 0 + children: [] + - name: Rocks + position: [0, 0] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_nor_gl_1k.png + children: [] + - name: World + position: [-436, 248] + layer: 0 + components: [] + children: + - name: Rocks + position: [0, 0] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\ganges_river_pebbles_nor_gl_1k.png + children: [] + - name: Bark + position: [1024, 0] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\bark_willow_02_nor_gl_1k.png + children: [] + - name: Planks + position: [0, 1024] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\wood_floor_worn_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\wood_floor_worn_nor_gl_1k.png + children: [] + - name: Metal + position: [1024, 1024] + layer: -1 + components: + - type: SpriteComponent + texture: C:\Users\spenc\OneDrive\Pictures\textures\metal_plate_diff_1k.png + normalMap: C:\Users\spenc\OneDrive\Pictures\textures\metal_plate_nor_gl_1k.png + children: [] + - name: Sun + position: [-5000, -5000] + layer: 1 + components: + - type: LightComponent + color: + - 0.992156863 + - 0.984313726 + - 0.827450991 + intensity: 1.25 + radius: 100000000 + falloff: 0.100000001 + type: 0 + children: [] \ No newline at end of file