diff options
Diffstat (limited to 'src')
36 files changed, 844 insertions, 20 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a47905..b60a0cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,4 +38,3 @@ target_link_libraries(test_main PRIVATE gtest_main PUBLIC crepe ) - diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index cc20f83..497423e 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,24 +1,39 @@ + target_sources(crepe PUBLIC Asset.cpp Sound.cpp SoundContext.cpp + Particle.cpp + ParticleEmitter.cpp + ParticleSystem.cpp SdlContext.cpp ComponentManager.cpp Component.cpp ScriptSystem.cpp RenderSystem.cpp + PhysicsSystem.cpp + Transform.cpp + Force.cpp + CollisionSystem.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES Asset.h Sound.h SoundContext.h + ParticleEmitter.h + ParticleSystem.h + Particle.h SdlContext.h ComponentManager.h ComponentManager.hpp Component.h System.h ScriptSystem.h + PhysicsSystem.h + Transform.h + Force.h + CollisionSystem.h RenderSystem.h ) diff --git a/src/crepe/CircleCollider.h b/src/crepe/CircleCollider.h new file mode 100644 index 0000000..922477b --- /dev/null +++ b/src/crepe/CircleCollider.h @@ -0,0 +1,12 @@ +#pragma once +#include "Collider.h" + +namespace crepe { + +class CircleCollider : public Collider { +public: + CircleCollider(uint32_t gameObjectId,int radius) : Collider(gameObjectId), radius(radius) {} + int radius; +}; + +} // namespace crepe diff --git a/src/crepe/CollisionSystem.cpp b/src/crepe/CollisionSystem.cpp new file mode 100644 index 0000000..a0c6dca --- /dev/null +++ b/src/crepe/CollisionSystem.cpp @@ -0,0 +1,13 @@ +#include "CollisionSystem.h" +#include "ComponentManager.h" +#include <iostream> + +using namespace crepe; + +CollisionSystem::CollisionSystem() { + +} + +void CollisionSystem::update() { + +} diff --git a/src/crepe/CollisionSystem.h b/src/crepe/CollisionSystem.h new file mode 100644 index 0000000..70d7237 --- /dev/null +++ b/src/crepe/CollisionSystem.h @@ -0,0 +1,15 @@ +#pragma once + +namespace crepe { + +class CollisionSystem +{ + private: + /* data */ + public: + CollisionSystem(/* args */); + void update(); +}; + +} + diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index bce90f1..e2cd7e0 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -1,3 +1,5 @@ #include "Component.h" using namespace crepe; + +Component::Component(uint32_t id) : gameObjectId(id), active(true) {} diff --git a/src/crepe/Component.h b/src/crepe/Component.h index 9cda177..8a42a45 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -1,4 +1,5 @@ #pragma once +#include <cstdint> namespace crepe { @@ -7,10 +8,13 @@ protected: Component() = default; public: - virtual ~Component() = default; - -public: - bool active = true; + Component(uint32_t id); + virtual ~Component() {} + // TODO: shouldn't this constructor be deleted because this class will never + // directly be instantiated? + //changed so it sets the id (jaro) + uint32_t gameObjectId; + bool active; }; } // namespace crepe diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 2377a94..22dbc66 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -30,7 +30,7 @@ T & ComponentManager::add_component(uint32_t id, Args &&... args) { // Create a new component of type T (arguments directly forwarded). The // constructor must be called by ComponentManager. - T * instance = new T(forward<Args>(args)...); + T * instance = new T(id,forward<Args>(args)...); // store its unique_ptr in the vector<> components[type][id].push_back(unique_ptr<T>(instance)); diff --git a/src/crepe/Force.cpp b/src/crepe/Force.cpp new file mode 100644 index 0000000..b314f49 --- /dev/null +++ b/src/crepe/Force.cpp @@ -0,0 +1,14 @@ +#include "Force.h" +#include <cmath> + +namespace crepe { + +Force::Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction): Component(gameObjectId) +{ + // Convert direction from degrees to radians + float radian_direction = static_cast<float>(direction) * (M_PI / 180.0f); + force_x = static_cast<int32_t>(std::round(forceMagnitude * std::cos(radian_direction))); + force_y = static_cast<int32_t>(std::round(forceMagnitude * std::sin(radian_direction))); +} + +} // namespace crepe diff --git a/src/crepe/Force.h b/src/crepe/Force.h new file mode 100644 index 0000000..a121ec2 --- /dev/null +++ b/src/crepe/Force.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Component.h" +#include <cstdint> +#include <utility> + +namespace crepe { + +class Force : public Component { +public: + Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction); + + int32_t force_x; + int32_t force_y; +}; + +} // namespace crepe diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp new file mode 100644 index 0000000..aa33606 --- /dev/null +++ b/src/crepe/Particle.cpp @@ -0,0 +1,25 @@ +#include "Particle.h" +#include <iostream> + +using namespace crepe; + +Particle::Particle() +{ + this->active = false; +} + +void Particle::reset(float lifespan, Position position, Position velocity) { + this->timeInLife = 0; + this->lifespan = lifespan; + this->position = position; + this->velocity = velocity; + this->active = true; +} + +void Particle::update(float deltaTime) { + timeInLife += deltaTime; + position.x += velocity.x * deltaTime; + position.y += velocity.y * deltaTime; + if(timeInLife >= lifespan)this->active = false; +} + diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h new file mode 100644 index 0000000..c408ed9 --- /dev/null +++ b/src/crepe/Particle.h @@ -0,0 +1,24 @@ +#pragma once + +namespace crepe { + +struct Position { + float x; + float y; + }; + +class Particle { +public: + + Position position; + Position velocity; + float lifespan; + bool active; + + Particle(); + void reset(float lifespan, Position position, Position velocity); + void update(float deltaTime); + float timeInLife; +}; + +} diff --git a/src/crepe/ParticleEmitter.cpp b/src/crepe/ParticleEmitter.cpp new file mode 100644 index 0000000..318c6db --- /dev/null +++ b/src/crepe/ParticleEmitter.cpp @@ -0,0 +1,28 @@ +#include "ParticleEmitter.h" +#include <ctime> +#include "Particle.h" +#include <iostream> + +using namespace crepe; + +ParticleEmitter::ParticleEmitter(uint32_t gameObjectId ,uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset, float m_beginLifespan, float m_endLifespan) + : Component(gameObjectId), m_maxParticles(maxParticles), m_emissionRate(emissionRate), m_speed(speed), m_speedOffset(speedOffset), m_position{0, 0}, m_beginLifespan(m_beginLifespan),m_endLifespan(m_endLifespan) { + std::srand(static_cast<uint32_t>(std::time(nullptr))); // initialize random seed + std::cout << "Create emitter" << std::endl; + m_minAngle = (360 + angle - (angleOffset % 360)) % 360; // calculate minAngle + m_maxAngle = (360 + angle + (angleOffset % 360)) % 360; // calculate maxAngle + m_position.x = 400; + m_position.y = 400; + for (size_t i = 0; i < m_maxParticles; i++) + { + this->particles.emplace_back(); + } + +} + +ParticleEmitter::~ParticleEmitter() { + std::vector<Particle>::iterator it = this->particles.begin(); + while (it != this->particles.end()) { + it = this->particles.erase(it); + } +} diff --git a/src/crepe/ParticleEmitter.h b/src/crepe/ParticleEmitter.h new file mode 100644 index 0000000..8cd78a9 --- /dev/null +++ b/src/crepe/ParticleEmitter.h @@ -0,0 +1,32 @@ +#pragma once + +#include <vector> +#include "Particle.h" +#include <cstdint> +#include "Component.h" +# + +namespace crepe { + +class ParticleEmitter : public Component { +public: + ParticleEmitter(uint32_t gameObjectId, uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset,float m_beginLifespan,float m_endLifespan); + ~ParticleEmitter(); + + Position m_position; //position of the emitter + uint32_t m_maxParticles; //maximum number of particles + uint32_t m_emissionRate; //rate of particle emission + uint32_t m_speed; //base speed of the particles + uint32_t m_speedOffset; //offset for random speed variation + uint32_t m_minAngle; //min angle of particle emission + uint32_t m_maxAngle; //max angle of particle emission + float m_beginLifespan; //begin Lifespan of particle (only visual) + float m_endLifespan; //begin Lifespan of particle + + std::vector<Particle> particles; //collection of particles + +}; + +} + + diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp new file mode 100644 index 0000000..0dad4cd --- /dev/null +++ b/src/crepe/ParticleSystem.cpp @@ -0,0 +1,59 @@ +#include "ParticleSystem.h" +#include <cmath> +#include <ctime> +#include "ParticleEmitter.h" +#include "Particle.h" +#include "ComponentManager.h" + +using namespace crepe; + +ParticleSystem::ParticleSystem() : m_elapsedTime(0.0f) {} // Initialize m_elapsedTime to 0 + +void ParticleSystem::update() { + ComponentManager& mgr = ComponentManager::get_instance(); + std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>(); + float deltaTime = 0.10; + for (ParticleEmitter& emitter : emitters) { + float updateAmount = 1/static_cast<float>(emitter.m_emissionRate); + for (float i = 0; i < deltaTime; i += updateAmount) + { + emitParticle(emitter); + } + for (size_t j = 0; j < emitter.particles.size(); j++) + { + if(emitter.particles[j].active) + { + emitter.particles[j].update(deltaTime); + } + } + } +} + +void ParticleSystem::emitParticle(ParticleEmitter& emitter) { + Position initialPosition = { emitter.m_position.x, emitter.m_position.y}; + float randomAngle = 0.0f; + if(emitter.m_maxAngle < emitter.m_minAngle) + { + randomAngle = ((emitter.m_minAngle + (std::rand() % (static_cast<uint32_t>(emitter.m_maxAngle + 360 - emitter.m_minAngle + 1))))%360); + } + else + { + randomAngle = emitter.m_minAngle + (std::rand() % (static_cast<uint32_t>(emitter.m_maxAngle - emitter.m_minAngle + 1))); + } + float angleInRadians = randomAngle * (M_PI / 180.0f); + float randomSpeedOffset = (static_cast<float>(std::rand()) / RAND_MAX) * (2 * emitter.m_speedOffset) - emitter.m_speedOffset; + float velocityX = (emitter.m_speed + randomSpeedOffset) * std::cos(angleInRadians); + float velocityY = (emitter.m_speed + randomSpeedOffset) * std::sin(angleInRadians); + Position initialVelocity = { + velocityX, + velocityY + }; + for (size_t i = 0; i < emitter.particles.size(); i++) + { + if(!emitter.particles[i].active) + { + emitter.particles[i].reset(emitter.m_endLifespan, initialPosition, initialVelocity); + break; + } + } +} diff --git a/src/crepe/ParticleSystem.h b/src/crepe/ParticleSystem.h new file mode 100644 index 0000000..c8777f5 --- /dev/null +++ b/src/crepe/ParticleSystem.h @@ -0,0 +1,19 @@ +#pragma once + +#include <vector> +#include "ParticleEmitter.h" + + +namespace crepe { + +class ParticleSystem { +public: + ParticleSystem(); + void update(); +private: + void emitParticle(ParticleEmitter &emitter); //emits a new particle + + float m_elapsedTime; //elapsed time since the last emission +}; + +} diff --git a/src/crepe/PhysicsSystem.cpp b/src/crepe/PhysicsSystem.cpp new file mode 100644 index 0000000..7d16044 --- /dev/null +++ b/src/crepe/PhysicsSystem.cpp @@ -0,0 +1,55 @@ +#include "PhysicsSystem.h" +#include "ComponentManager.h" +#include "Rigidbody.h" +#include "Transform.h" +#include "Force.h" +#include <iostream> + +using namespace crepe; + +PhysicsSystem::PhysicsSystem() { + +} + +void PhysicsSystem::update() { + ComponentManager& mgr = ComponentManager::get_instance(); + std::vector<std::reference_wrapper<Rigidbody>> rigidbodies = mgr.get_components_by_type<Rigidbody>(); + std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_type<Transform>(); + + for (Rigidbody& rigidbody : rigidbodies) { + + switch (rigidbody.body_type) + { + case BodyType::Dynamic : + for (Transform& transform : transforms) { + if(transform.gameObjectId == rigidbody.gameObjectId) + { + rigidbody.velocity_x = 0; + rigidbody.velocity_y = 0; + std::vector<std::reference_wrapper<Force>> Forces = mgr.get_components_by_id<Force>(rigidbody.gameObjectId); + rigidbody.velocity_y += rigidbody.gravity_scale * 1 * rigidbody.mass; + + for (Force& force : Forces) + { + rigidbody.velocity_x += force.force_x; + rigidbody.velocity_y += force.force_y; + } + + std::cout << "before transform.postion.x " << transform.postion.x << std::endl; + std::cout << "before transform.postion.y " << transform.postion.y << std::endl; + transform.postion.x += rigidbody.velocity_x; + transform.postion.y += rigidbody.velocity_y; + std::cout << "after transform.postion.x " << transform.postion.x << std::endl; + std::cout << "after transform.postion.y " << transform.postion.y << std::endl; + } + } + break; + case BodyType::Kinematic : + break; //(scripts) + case BodyType::Static : + break; //(unmoveable objects) + default: + break; + } + } +} diff --git a/src/crepe/PhysicsSystem.h b/src/crepe/PhysicsSystem.h new file mode 100644 index 0000000..1899089 --- /dev/null +++ b/src/crepe/PhysicsSystem.h @@ -0,0 +1,17 @@ +#pragma once + +namespace crepe { + +class PhysicsSystem +{ + private: + /* data */ + public: + PhysicsSystem(/* args */); + void update(); +}; + +} + + + diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp new file mode 100644 index 0000000..715dd6f --- /dev/null +++ b/src/crepe/SDLApp.cpp @@ -0,0 +1,78 @@ +#include "SDLApp.h" +#include <iostream> +#include <vector> +#include "Particle.h" +#include "ParticleEmitter.h" + +SDLApp::SDLApp(int windowWidth, int windowHeight) + : windowWidth(windowWidth), windowHeight(windowHeight), window(nullptr), renderer(nullptr) {} + +SDLApp::~SDLApp() { + cleanUp(); +} + +bool SDLApp::initialize() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + std::cerr << "SDL Initialization Error: " << SDL_GetError() << std::endl; + return false; + } + + window = SDL_CreateWindow("Particle System", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + windowWidth, + windowHeight, + SDL_WINDOW_SHOWN); + if (!window) { + std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl; + return false; + } + + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + std::cerr << "Renderer Creation Error: " << SDL_GetError() << std::endl; + return false; + } + + return true; +} + +void SDLApp::handleEvents(bool& running) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } +} + +void SDLApp::clearScreen() { + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); +} + +void SDLApp::presentScreen() { + SDL_RenderPresent(renderer); +} + +void SDLApp::drawSquare(int x, int y, int size) { + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_Rect rect = { x, y, size, size }; + SDL_RenderFillRect(renderer, &rect); +} + +SDL_Texture* squareTexture = nullptr; // Load this with an image or create it + + + + + +void SDLApp::cleanUp() { + if (renderer) { + SDL_DestroyRenderer(renderer); + } + if (window) { + SDL_DestroyWindow(window); + } + SDL_Quit(); +} diff --git a/src/crepe/SDLApp.h b/src/crepe/SDLApp.h new file mode 100644 index 0000000..8915d30 --- /dev/null +++ b/src/crepe/SDLApp.h @@ -0,0 +1,28 @@ +#ifndef SDLAPP_HPP +#define SDLAPP_HPP + +#include <SDL2/SDL.h> +#include "Particle.h" +#include "ParticleEmitter.h" + +class SDLApp { +public: + SDLApp(int windowWidth, int windowHeight); + ~SDLApp(); + + bool initialize(); + void handleEvents(bool& running); + void clearScreen(); + void presentScreen(); + void drawSquare(int x, int y, int size); + void cleanUp(); + void drawParticles(const std::vector<crepe::ParticleEmitter>& emitters); + void drawMultipleSquares(const std::vector<SDL_Rect>& squares); +private: + int windowWidth; + int windowHeight; + SDL_Window* window; + SDL_Renderer* renderer; +}; + +#endif diff --git a/src/crepe/Transform.cpp b/src/crepe/Transform.cpp new file mode 100644 index 0000000..2c39523 --- /dev/null +++ b/src/crepe/Transform.cpp @@ -0,0 +1,6 @@ +#include "Transform.h" + +using namespace crepe; + +Transform::Transform(uint32_t gameObjectId,Position position, int rotation, int scale) + : Component(gameObjectId), postion(postion), rotation(rotation), scale(scale) {} diff --git a/src/crepe/Transform.h b/src/crepe/Transform.h new file mode 100644 index 0000000..3e8d142 --- /dev/null +++ b/src/crepe/Transform.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Component.h" + +namespace crepe { + +struct Position +{ + int x; + int y; +}; + + +class Transform : public Component { +public: + Transform(uint32_t gameObjectId,Position position, int rotation, int scale); + Position postion; + int rotation; + int scale; +}; + +} // namespace crepe diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 84bfd4c..74788ec 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -4,4 +4,4 @@ using namespace crepe::api; -BehaviorScript::BehaviorScript() { dbg_trace(); } +BehaviorScript::BehaviorScript() : Component(gameObjectId) { dbg_trace(); } diff --git a/src/crepe/api/Collider.cpp b/src/crepe/api/Collider.cpp index 6370a42..c3e4929 100644 --- a/src/crepe/api/Collider.cpp +++ b/src/crepe/api/Collider.cpp @@ -2,4 +2,4 @@ using namespace crepe::api; -Collider::Collider(int size) : size(size) {} +Collider::Collider(uint32_t gameObjectId) : Component(gameObjectId){} diff --git a/src/crepe/api/Collider.h b/src/crepe/api/Collider.h index 72d8e77..1d540de 100644 --- a/src/crepe/api/Collider.h +++ b/src/crepe/api/Collider.h @@ -6,7 +6,7 @@ namespace crepe::api { class Collider : public Component { public: - Collider(int size); + Collider(uint32_t gameObjectId); int size; }; diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index 98d1d60..30a2cff 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -2,5 +2,6 @@ using namespace crepe::api; -Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} +Rigidbody::Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType) + : Component(gameObjectId), mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} + diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index 6cae579..548650a 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -1,16 +1,24 @@ #pragma once -#include "../Component.h" +#include "Component.h" +#include <cstdint> -namespace crepe::api { +namespace crepe { + +enum class BodyType { + Static, // Does not move (e.g. walls, ground ...) + Dynamic, // Moves and responds to forces (e.g. player, physics objects ...) + Kinematic // Moves but does not respond to forces (e.g. moving platforms ...) +}; class Rigidbody : public Component { public: - Rigidbody(int mass, int gravityScale, int bodyType); - + Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType); + int32_t velocity_x; + int32_t velocity_y; int mass; int gravity_scale; - int body_type; + BodyType body_type; }; } // namespace crepe::api diff --git a/src/crepe/crepe/CMakeFiles/CMakeDirectoryInformation.cmake b/src/crepe/crepe/CMakeFiles/CMakeDirectoryInformation.cmake new file mode 100644 index 0000000..8d03506 --- /dev/null +++ b/src/crepe/crepe/CMakeFiles/CMakeDirectoryInformation.cmake @@ -0,0 +1,16 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.28 + +# Relative path conversion top directories. +set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/jaro/crepe/src") +set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/jaro/crepe/src/crepe") + +# Force unix paths in dependencies. +set(CMAKE_FORCE_UNIX_PATHS 1) + + +# The C and CXX include file regular expressions for this directory. +set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") +set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") +set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) +set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) diff --git a/src/crepe/crepe/CMakeFiles/progress.marks b/src/crepe/crepe/CMakeFiles/progress.marks new file mode 100644 index 0000000..573541a --- /dev/null +++ b/src/crepe/crepe/CMakeFiles/progress.marks @@ -0,0 +1 @@ +0 diff --git a/src/crepe/crepe/Makefile b/src/crepe/crepe/Makefile new file mode 100644 index 0000000..094215a --- /dev/null +++ b/src/crepe/crepe/Makefile @@ -0,0 +1,140 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.28 + +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Disable VCS-based implicit rules. +% : %,v + +# Disable VCS-based implicit rules. +% : RCS/% + +# Disable VCS-based implicit rules. +% : RCS/%,v + +# Disable VCS-based implicit rules. +% : SCCS/s.% + +# Disable VCS-based implicit rules. +% : s.% + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Command-line flag to silence nested $(MAKE). +$(VERBOSE)MAKESILENT = -s + +#Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E rm -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/jaro/crepe/src + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/jaro/crepe/src/crepe + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "No interactive CMake dialog available..." + /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + cd /home/jaro/crepe/src/crepe && $(CMAKE_COMMAND) -E cmake_progress_start /home/jaro/crepe/src/crepe/CMakeFiles /home/jaro/crepe/src/crepe/crepe//CMakeFiles/progress.marks + cd /home/jaro/crepe/src/crepe && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 crepe/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/jaro/crepe/src/crepe/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + cd /home/jaro/crepe/src/crepe && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 crepe/clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + cd /home/jaro/crepe/src/crepe && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 crepe/preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + cd /home/jaro/crepe/src/crepe && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 crepe/preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + cd /home/jaro/crepe/src/crepe && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... rebuild_cache" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + cd /home/jaro/crepe/src/crepe && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/src/crepe/crepe/cmake_install.cmake b/src/crepe/crepe/cmake_install.cmake new file mode 100644 index 0000000..cd57803 --- /dev/null +++ b/src/crepe/crepe/cmake_install.cmake @@ -0,0 +1,44 @@ +# Install script for directory: /home/jaro/crepe/src/crepe + +# Set the install prefix +if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/usr/local") +endif() +string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + +# Set the install configuration name. +if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + if(BUILD_TYPE) + string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" + CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") + else() + set(CMAKE_INSTALL_CONFIG_NAME "Debug") + endif() + message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") +endif() + +# Set the component getting installed. +if(NOT CMAKE_INSTALL_COMPONENT) + if(COMPONENT) + message(STATUS "Install component: \"${COMPONENT}\"") + set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") + else() + set(CMAKE_INSTALL_COMPONENT) + endif() +endif() + +# Install shared libraries without execute permission? +if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) + set(CMAKE_INSTALL_SO_NO_EXE "1") +endif() + +# Is this installation the result of a crosscompile? +if(NOT DEFINED CMAKE_CROSSCOMPILING) + set(CMAKE_CROSSCOMPILING "FALSE") +endif() + +# Set default install directory permissions. +if(NOT DEFINED CMAKE_OBJDUMP) + set(CMAKE_OBJDUMP "/usr/bin/objdump") +endif() + diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h index 3e36f0a..e2776c9 100644 --- a/src/crepe/util/log.h +++ b/src/crepe/util/log.h @@ -9,7 +9,7 @@ #define _crepe_logf_here(fmt, ...) \ crepe::util::logf(util::log_level::DEBUG, "%s%s (%s:%d)%s" fmt "\n", \ crepe::util::color::FG_WHITE, __PRETTY_FUNCTION__, \ - __FILE_NAME__, __LINE__, crepe::util::color::RESET, \ + __FILE__, __LINE__, crepe::util::color::RESET, \ __VA_ARGS__) // very illegal global function-style macros diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 7c87afc..368aa2e 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -21,4 +21,7 @@ add_example(components_internal) add_example(script) add_example(rendering) add_example(asset_manager) - +add_example(particle) +add_example(Physics) +add_example(particle) +add_example(Physics) diff --git a/src/example/Physics.cpp b/src/example/Physics.cpp new file mode 100644 index 0000000..9ad6da0 --- /dev/null +++ b/src/example/Physics.cpp @@ -0,0 +1,25 @@ +#include <iostream> +#include <thread> +#include <chrono> +#include "Transform.h" +#include "Rigidbody.h" +#include "Force.h" +#include "PhysicsSystem.h" +#include <crepe/Component.h> +#include <crepe/ComponentManager.h> +#include <crepe/GameObject.h> + +using namespace crepe; +using namespace std; + + +int main(int argc, char* argv[]) { + PhysicsSystem physicsSystem; + GameObject * game_object[2]; + game_object[1] = new GameObject(2, "Name", "Tag", 0); // not found not used + game_object[0] = new GameObject(5, "Name", "Tag", 0); + game_object[0]->add_component<Rigidbody>(1, 1 , BodyType::Dynamic); + game_object[0]->add_component<Force>(1 , 0); + physicsSystem.update(); + return 0; +} diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp index e2169e1..ae6c765 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -42,8 +42,8 @@ int main() { auto stop_adding = chrono::high_resolution_clock::now(); auto sprites = mgr.get_components_by_type<Sprite>(); - for (auto sprite : sprites) { - assert(sprite.get().path == "test"); + for (auto & sprite : sprites) { + assert(sprite.path == "test"); } auto stop_looping = chrono::high_resolution_clock::now(); diff --git a/src/example/particle.cpp b/src/example/particle.cpp new file mode 100644 index 0000000..df1dbfd --- /dev/null +++ b/src/example/particle.cpp @@ -0,0 +1,102 @@ +#include <iostream> +#include <thread> +#include <chrono> +#include "SDLApp.h" +#include "ParticleEmitter.h" +#include "ParticleSystem.h" +#include "Particle.h" +#include <crepe/Component.h> +#include <crepe/ComponentManager.h> +#include <crepe/GameObject.h> +#include <chrono> + +using namespace crepe; +using namespace std; + +const int WINDOW_WIDTH = 800; +const int WINDOW_HEIGHT = 600; + +int main(int argc, char* argv[]) { + SDLApp app(WINDOW_WIDTH, WINDOW_HEIGHT); + + if (!app.initialize()) { + cerr << "Failed to initialize SDLApp." << endl; + return 1; + } + + + GameObject * game_object[1]; + game_object[0] = new GameObject(0, "Name", "Tag", 0); + + + ParticleSystem particleSystem; + + unsigned int maxParticles = 100; // maximum number of particles + unsigned int emissionRate = 10; // particles created per second + unsigned int speed = 50; // base speed of particles + unsigned int speedOffset = 10; // random offset for particle speed + unsigned int angle = 270; // base angle of particle emission + unsigned int angleOffset = 30; // random offset for particle angle + float beginLifespan = 0.0f; // beginning lifespan of particles + float endLifespan = 6.0f; // ending lifespan of particles + + // Vector to hold all the emitters + // vector<ParticleEmitter> emitters; + game_object[0]->add_component<ParticleEmitter>(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset, beginLifespan, endLifespan); + + + + + // Loop to create 1000 emitters + // for (unsigned int i = 0; i < 1000; ++i) { + // ParticleEmitter emitter(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset, beginLifespan, endLifespan); + + // // Set a position for each emitter, modifying the position for demonstration + // emitter.m_position = {static_cast<float>(200 + (i % 100)), static_cast<float>(200 + (i / 100) * 10)}; // Adjust position for each emitter + + // emitters.push_back(emitter); // Add the emitter to the vector + // } + float deltaTime = 0.1f; + bool running = true; + cout << "start loop " << endl; + while (running) { + app.handleEvents(running); + + // Start timing + auto start = chrono::high_resolution_clock::now(); + + + // POC CODE + particleSystem.update(); + // POC CODE + + // End timing + auto end = chrono::high_resolution_clock::now(); + chrono::duration<float, milli> duration = end - start; // get duration in milliseconds + + cout << "Update took " << duration.count() << " ms" << endl; + app.clearScreen(); + + start = chrono::high_resolution_clock::now(); + // render particles using the drawSquare method from SDLApp + ComponentManager& mgr = ComponentManager::get_instance(); + std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>(); + for (const ParticleEmitter& emitter : emitters) { + for (const Particle& particle : emitter.particles) { + if(particle.active)app.drawSquare(particle.position.x, particle.position.y, 5); // draw each particle + } + } + + + app.presentScreen(); + end = chrono::high_resolution_clock::now(); + duration = end - start; // get duration in milliseconds + + cout << "screen took " << duration.count() << " ms" << endl; + + this_thread::sleep_for(chrono::milliseconds(20)); // simulate ~50 FPS + } + + app.cleanUp(); + return 0; +} |