From 64e45910a2b1fcbd107b302b9c490778faa5b9ac Mon Sep 17 00:00:00 2001 From: Stan44 Date: Sat, 28 Dec 2024 23:22:34 -0600 Subject: [PATCH] intergrations to new folder structure done now we need to fix perfomance in physics before merging / syncing / pushing anything to master --- main.py | 17 +- src/config/settings.py | 44 ++- src/part/coreparts/particles.json | 476 ------------------------------ src/physics/sim.py | 4 +- src/rendering/rendering.py | 5 +- src/sandpypi.py | 21 +- 6 files changed, 42 insertions(+), 525 deletions(-) delete mode 100644 src/part/coreparts/particles.json diff --git a/main.py b/main.py index d154e68..0fe95ab 100644 --- a/main.py +++ b/main.py @@ -1 +1,16 @@ -from core.loaders.particle_loader import ParticleLoader \ No newline at end of file +from src.config.settings import cProfile, pstats +from src.sandpypi import main + +if __name__ == "__main__": + # Profile the application + profiler = cProfile.Profile() + profiler.enable() + + main() + + profiler.disable() + # Write profiling results to file + with open('profile_results.log', 'w') as f: + stats = pstats.Stats(profiler, stream=f) + stats.sort_stats('cumulative') + stats.print_stats() diff --git a/src/config/settings.py b/src/config/settings.py index 0b0b589..e90710e 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -40,34 +40,30 @@ particles_path = os.path.join(os.path.dirname(__file__), '..', 'part', 'particle # Load particle properties from JSON file def load_particle_properties(): - # Load core particles particle_data = {} - print(f"Loading particles from {particles_path}") - # Core particles - try: - with open(particles_path, 'r') as f: - particle_data.update(json.load(f)) - print(f"Loaded {len(particle_data)} core particles") - except (FileNotFoundError, json.JSONDecodeError) as e: - print(f"Error loading core particles: {e}") + parts_path = os.path.join(os.path.dirname(__file__), '..', 'part') - # Load mods from mods directory - mods_path = os.path.join(os.path.dirname(__file__), '..', 'part', 'mods') - if os.path.exists(mods_path): - for filename in os.listdir(mods_path): - if filename.endswith('.json'): - mod_file = os.path.join(mods_path, filename) - try: - with open(mod_file, 'r') as f: - mod_data = json.load(f) - print(f"Loading mod: {filename}") - particle_data.update(mod_data) - print(f"Loaded {len(mod_data)} particles from {filename}") - except (FileNotFoundError, json.JSONDecodeError) as e: - print(f"Error loading mod {filename}: {e}") + def scan_directory(directory): + for root, dirs, files in os.walk(directory): + for file in files: + if file.endswith('.json'): + file_path = os.path.join(root, file) + try: + with open(file_path, 'r') as f: + mod_data = json.load(f) + relative_path = os.path.relpath(file_path, parts_path) + print(f"Loading particles from: {relative_path}") + particle_data.update(mod_data) + print(f"Loaded {len(mod_data)} particles from {relative_path}") + except (FileNotFoundError, json.JSONDecodeError) as e: + print(f"Error loading {file_path}: {e}") + + if os.path.exists(parts_path): + scan_directory(parts_path) + else: + print(f"Parts directory not found at {parts_path}") return particle_data - # Load particle properties once when module is imported particle_properties = load_particle_properties() __all__ = ['pygame', 'np', 'random', 'time', 'engine_settings', 'particle_properties', 'cProfile', 'pstats', 'sys', 'os'] diff --git a/src/part/coreparts/particles.json b/src/part/coreparts/particles.json deleted file mode 100644 index b4a2daa..0000000 --- a/src/part/coreparts/particles.json +++ /dev/null @@ -1,476 +0,0 @@ -{ - "sand": { - "name": "Sand", - "size": 1, - "hardness": 0.5, - "color": [255, 255, 0, 255], - "velocity": 0.5, - "wind": 1, - "mass": 0.5, - "conductivity": 0, - "heat_capacity": 1, - "flamability": 0.8, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0, - "pressure": 0, - "melt": "molten-glass", - "melt_temperature": 1700, - "conductive": false, - "liquid": false, - "solid": true, - "is_gas": false - }, - "water": { - "name": "Water", - "size": 1, - "hardness": 0.2, - "velocity": 0.3, - "conductivity": 1, - "heat_capacity": 1, - "color": [0, 0, 255, 255], - "mass": 1, - "flamability": 0, - "temperature": 22, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 1, - "viscosity": 1, - "pressure": 0.5, - "evaporate": "steam", - "evaporate_temperature": 100, - "freeze": "ice", - "freeze_temperature": 0, - "conductive": true, - "liquid": true, - "solid": false, - "is_gas": false - }, - "steam": { - "name": "Steam", - "size": 1, - "hardness": 0.0, - "velocity": 0.3, - "conductivity": 1, - "heat_capacity": 1, - "color": [255, 255, 255, 255], - "mass": 0.01, - "flamability": 0, - "temperature": 100, - "solidify_temperature": 98, - "solidify": "water", - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0.5, - "liquid": false, - "solid": false, - "is_gas": true, - "conductive": false - }, - "ice": { - "name": "Ice", - "size": 1, - "hardness": 1000, - "velocity": 0.0, - "conductivity": 0, - "heat_capacity": 0, - "color": [75, 75, 170, 255], - "mass": 1, - "flamability": 0.0, - "temperature": 0, - "melt": "water", - "melt_temperature": 0.05, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 1, - "viscosity": 1, - "liquid": false, - "solid": true, - "is_gas": false - }, - "mud": { - "name": "Mud", - "size": 1, - "hardness": 0.4, - "velocity": 0.5, - "conductivity": 1, - "heat_capacity": 1, - "color": [139, 69, 19, 255], - "mass": 0.5, - "flamability": 0, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 1, - "liquid": false, - "solid": true, - "is_gas": false - }, - "fire": { - "name": "Fire", - "size": 1, - "hardness": 0.1, - "velocity": 0.1, - "conductivity": 0, - "heat_capacity": 1, - "color": [255, 0, 0, 255], - "mass": 0.1, - "flamability": 1, - "temperature": 800, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.1, - "viscosity": 0.1, - "liquid": false, - "solid": false, - "is_gas": true - }, - "smoke": { - "name": "Smoke", - "size": 1, - "hardness": 0.1, - "velocity": 0.07, - "conductivity": 0, - "heat_capacity": 1, - "color": [115, 113, 95, 255], - "mass": 0.01, - "flamability": 0, - "temperature": 85, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.4, - "viscosity": 0.1, - "lifetime": 90, - "liquid": false, - "solid": false, - "is_gas": true - }, - "wall": { - "name": "Wall", - "size": 1, - "hardness": 1000, - "velocity": 0.0, - "conductivity": 0, - "heat_capacity": 0, - "color": [75, 75, 75, 255], - "mass": 1, - "flamability": 0, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 1, - "viscosity": 1, - "liquid": false, - "solid": true, - "is_gas": false - }, - "dirt": { - "name": "Dirt", - "size": 1, - "hardness": 0.5, - "velocity": 0.5, - "conductivity": 0, - "heat_capacity": 1, - "color": [139, 69, 19, 255], - "mass": 0.5, - "flamability": 0, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0.5, - "liquid": false, - "solid": true, - "is_gas": false - }, - "stone": { - "name": "Stone", - "size": 1, - "hardness": 0.7, - "velocity": 1.5, - "conductivity": 0, - "heat_capacity": 0, - "color": [128, 128, 128, 220], - "mass": 1, - "flamability": 0, - "melt": "molten-Stone", - "melt_temperature": 800, - "solidify": "stone", - "solidify_temperature": 799, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0.5, - "liquid": false, - "solid": true, - "is_gas": false - }, - "snow": { - "name": "Snow", - "size": 1, - "hardness": 0.1, - "velocity": 0.2, - "conductivity": 1, - "heat_capacity": 1, - "color": [255, 255, 255, 255], - "mass": 0.01, - "flamability": 0, - "melt": "water", - "melt_temperature": 1, - "temperature": 0, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.1, - "viscosity": 0.01, - "liquid": false, - "solid": true, - "is_gas": false - }, - "wood": { - "name": "Wood", - "size": 1, - "hardness": 0.5, - "velocity": 0.5, - "conductivity": 0, - "heat_capacity": 1, - "color": [139, 69, 19, 255], - "mass": 0.5, - "flamability": 0.8, - "burning_temperature": 250, - "burning_rate": 0.01, - "burning_color": [255, 69, 19, 255], - "burning": false, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0.5, - "liquid": false, - "solid": true, - "is_gas": false - }, - "burning-wood": { - "name": "Burning Wood", - "size": 1, - "hardness": 0.5, - "velocity": 0.5, - "conductivity": 0, - "heat_capacity": 1, - "color": [255, 69, 19, 255], - "mass": 0.5, - "flamability": 0.8, - "temperature": 251, - "burning": true, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0.5, - "liquid": false, - "solid": true, - "is_gas": false - }, - "air": { - "name": "Air", - "size": 1, - "hardness": 0.0, - "velocity": 0.0, - "conductivity": 0, - "heat_capacity": 1, - "color": [255, 255, 255, 25], - "mass": 0.0, - "flamability": 0, - "temperature": 0, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.0, - "viscosity": 0.0, - "liquid": false, - "solid": false, - "is_gas": true - }, - "lava": { - "name": "Lava", - "size": 1, - "hardness": 0.2, - "velocity": 0.5, - "conductivity": 0, - "heat_capacity": 1, - "color": [255, 45, 60, 255], - "mass": 0.3, - "flamability": 0, - "temperature": 1400, - "solidify": "molten-rock", - "solidify_temperature": 799, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.8, - "viscosity": 0.8, - "liquid": true, - "solid": false, - "is_gas": false - }, - "rock": { - "name": "Rock", - "size": 1, - "hardness": 0.2, - "velocity": 0.3, - "conductivity": 1, - "heat_capacity": 1, - "color": [128, 128, 128, 255], - "mass": 0.8, - "flamability": 0, - "melt": "molten-rock", - "melt_temperature": 600, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.5, - "viscosity": 0.5, - "liquid": false, - "solid": true, - "is_gas": false - }, - "molten-rock": { - "name": "Molten Rock", - "size": 1, - "hardness": 0.2, - "velocity": 0.3, - "conductivity": 1, - "heat_capacity": 1, - "color": [255, 140, 0, 255], - "mass": 0.8, - "flamability": 0, - "temperature": 600, - "melt": "lava", - "melt_temperature": 1300, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0,0,0], - "friction": 0.8, - "viscosity": 0.8, - "liquid": true, - "solid": false, - "is_gas": false, - "solidify": "rock", - "solidify_temperature": 200 - }, - "molten_stone": { - "name": "Molten Stone", - "size": 1, - "hardness": 0.2, - "velocity": 0.3, - "conductivity": 1, - "heat_capacity": 1, - "color": [255, 140, 0, 255], - "mass": 0.8, - "flamability": 0, - "temperature": 1200, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.8, - "viscosity": 0.8, - "liquid": true, - "solid": false, - "is_gas": false, - "solidify": "stone", - "solidify_temperature": 800 - }, - "molten_glass": { - "name": "Molten Glass", - "size": 1, - "hardness": 0.2, - "velocity": 0.4, - "conductivity": 0.8, - "heat_capacity": 1, - "color": [255, 200, 150, 200], - "mass": 0.6, - "flamability": 0, - "temperature": 600, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.7, - "viscosity": 0.9, - "liquid": true, - "solid": false, - "is_gas": false, - "solidify": "glass", - "solidify_temperature": 599 - }, - "glass": { - "name": "Glass", - "size": 1, - "hardness": 0.2, - "velocity": 0.4, - "conductivity": 0, - "heat_capacity": 1, - "color": [50, 45, 255, 100], - "mass": 0.6, - "flamability": 0, - "temperature": 20, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.7, - "viscosity": 0.9, - "liquid": false, - "solid": true, - "is_gas": false, - "melt": "molten-glass", - "melt_temperature": 600 - }, - "plasma": { - "name": "Plasma", - "size": 1, - "hardness": 0.0, - "velocity": 0.0, - "conductivity": 0, - "heat_capacity": 1, - "color": [255, 100, 200, 255], - "mass": 0.0, - "flamability": 0, - "temperature": 3600, - "explosive": false, - "explosion_radius": 0, - "explosion_color": [0, 0, 0], - "friction": 0.0, - "viscosity": 0.0, - "liquid": false, - "solid": false, - "is_gas": true - }, - "wind": { - "name": "Wind", - "color": [200, 200, 255, 128], - "mass": 0.01, - "is_wind": true, - "wind_strength": 2.0, - "wind_direction": [1, 0], - "radius": 50, - "special": true - } - -} - diff --git a/src/physics/sim.py b/src/physics/sim.py index 77493c8..04701d1 100644 --- a/src/physics/sim.py +++ b/src/physics/sim.py @@ -19,10 +19,8 @@ Key Components: """ #Load the imports. -from config.settings import random, time, particle_properties +from src.config.settings import random, time, particle_properties -from dataclasses import dataclass -import math # Load particle properties from json so we know what particles we got and how they should be simulated. class Particle: diff --git a/src/rendering/rendering.py b/src/rendering/rendering.py index 6b5d9eb..644e7f1 100644 --- a/src/rendering/rendering.py +++ b/src/rendering/rendering.py @@ -22,9 +22,8 @@ The `clear_screen` function is used to reset the simulation grid and clear the d """ -from config.settings import pygame, random, particle_properties, engine_settings -from typing import List, Dict -import colorsys +from src.config.settings import pygame, random, particle_properties, engine_settings + class Rendering: diff --git a/src/sandpypi.py b/src/sandpypi.py index 698ab84..9aa6661 100644 --- a/src/sandpypi.py +++ b/src/sandpypi.py @@ -15,10 +15,10 @@ The main loop runs at a target frame rate of 60 FPS (this fps varies on my mood """ # Import Require files for the Engine. -from config.settings import pygame, cProfile, pstats, engine_settings +from src.config.settings import pygame, engine_settings -from rendering.rendering import Rendering -from physics.sim import Simulation +from src.rendering.rendering import Rendering +from src.physics.sim import Simulation """ This is for the future physics engine until i figure out a better method used for testing right now. @@ -320,18 +320,3 @@ def main(): pygame.display.flip() pygame.quit() - - -if __name__ == "__main__": - # Profile the application - profiler = cProfile.Profile() - profiler.enable() - - main() - - profiler.disable() - # Write profiling results to file - with open('profile_results.log', 'w') as f: - stats = pstats.Stats(profiler, stream=f) - stats.sort_stats('cumulative') - stats.print_stats()