aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-10-23 19:56:28 +0200
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-10-23 19:56:28 +0200
commitc9246515fe785563411e9170aedd0231165ab988 (patch)
treee3b713e1e1200b26861e951e0b1ac4ab64d4eab6 /src/crepe
parentadb7dfabec4811566308cd072e0542cd7eae8cc1 (diff)
rendering and assetmanager
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/CMakeLists.txt26
-rw-r--r--src/crepe/PhysicsSystem.cpp5
-rw-r--r--src/crepe/RenderSystem.cpp23
-rw-r--r--src/crepe/SdlContext.cpp2
-rw-r--r--src/crepe/Transform.cpp6
-rw-r--r--src/crepe/Transform.h22
-rw-r--r--src/crepe/api/Rigidbody.h2
-rw-r--r--src/crepe/api/Sprite.cpp6
-rw-r--r--src/crepe/api/Sprite.h2
-rw-r--r--src/crepe/api/Transform.cpp6
-rw-r--r--src/crepe/api/Transform.h3
11 files changed, 40 insertions, 63 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt
index 497423e..245df31 100644
--- a/src/crepe/CMakeLists.txt
+++ b/src/crepe/CMakeLists.txt
@@ -3,37 +3,35 @@ target_sources(crepe PUBLIC
Asset.cpp
Sound.cpp
SoundContext.cpp
- Particle.cpp
- ParticleEmitter.cpp
- ParticleSystem.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
+ #PhysicsSystem.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
+ #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
+ #PhysicsSystem.h
+ #Force.h
+ #CollisionSystem.h
RenderSystem.h
)
diff --git a/src/crepe/PhysicsSystem.cpp b/src/crepe/PhysicsSystem.cpp
index 7d16044..3ed84f8 100644
--- a/src/crepe/PhysicsSystem.cpp
+++ b/src/crepe/PhysicsSystem.cpp
@@ -1,11 +1,12 @@
#include "PhysicsSystem.h"
#include "ComponentManager.h"
-#include "Rigidbody.h"
-#include "Transform.h"
+#include "api/Rigidbody.h"
+#include "api/Transform.h"
#include "Force.h"
#include <iostream>
using namespace crepe;
+using namespace crepe::api;
PhysicsSystem::PhysicsSystem() {
diff --git a/src/crepe/RenderSystem.cpp b/src/crepe/RenderSystem.cpp
index 6aae3bb..b5503d3 100644
--- a/src/crepe/RenderSystem.cpp
+++ b/src/crepe/RenderSystem.cpp
@@ -6,7 +6,6 @@
#include "api/Sprite.h"
#include "api/Transform.h"
#include "util/log.h"
-#include <cstddef>
#include <functional>
#include <vector>
@@ -17,25 +16,27 @@ RenderSystem::RenderSystem() { dbg_trace(); }
RenderSystem::~RenderSystem() { dbg_trace(); }
-RenderSystem& RenderSystem::get_instance(){
+RenderSystem & RenderSystem::get_instance() {
static RenderSystem instance;
return instance;
}
void RenderSystem::update() {
- ComponentManager& mgr = ComponentManager::get_instance();
-
- std::vector<std::reference_wrapper<Sprite>> sprites = mgr.get_components_by_type<Sprite>();
- std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_type<Transform>();
+ ComponentManager & mgr = ComponentManager::get_instance();
- SdlContext& render = SdlContext::get_instance();
+ std::vector<std::reference_wrapper<Sprite>> sprites
+ = mgr.get_components_by_type<Sprite>();
+
+ SdlContext & render = SdlContext::get_instance();
render.clear_screen();
- for (size_t i = 0; i < sprites.size(); ++i) {
- render.draw(sprites[i].get(), transforms[i].get());
- }
+ for (const Sprite & sprite : sprites) {
+ std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(sprite.gameObjectId);
+ for (const Transform& transform : transforms) {
+ render.draw(sprite, transform);
+ }
+ }
render.present_screen();
-
}
diff --git a/src/crepe/SdlContext.cpp b/src/crepe/SdlContext.cpp
index cc5148c..09d9c9b 100644
--- a/src/crepe/SdlContext.cpp
+++ b/src/crepe/SdlContext.cpp
@@ -57,7 +57,7 @@ SdlContext::SdlContext() {
m_game_window = SDL_CreateWindow(
"Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
- 1920, 1080, SDL_WINDOW_HIDDEN);
+ 1920, 1080, SDL_WINDOW_SHOWN);
if (!m_game_window) {
std::cerr << "Window could not be created! SDL_Error: "
<< SDL_GetError() << std::endl;
diff --git a/src/crepe/Transform.cpp b/src/crepe/Transform.cpp
deleted file mode 100644
index 2c39523..0000000
--- a/src/crepe/Transform.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#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
deleted file mode 100644
index 3e8d142..0000000
--- a/src/crepe/Transform.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#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/Rigidbody.h b/src/crepe/api/Rigidbody.h
index 548650a..c16a300 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -3,7 +3,7 @@
#include "Component.h"
#include <cstdint>
-namespace crepe {
+namespace crepe::api{
enum class BodyType {
Static, // Does not move (e.g. walls, ground ...)
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp
index d9e26ab..3cc263e 100644
--- a/src/crepe/api/Sprite.cpp
+++ b/src/crepe/api/Sprite.cpp
@@ -1,8 +1,10 @@
#include "Sprite.h"
+#include "Component.h"
#include "api/Texture.h"
#include "util/log.h"
+#include <cstdint>
#include <memory>
#include <utility>
@@ -10,8 +12,8 @@ using namespace std;
using namespace crepe;
using namespace crepe::api;
-Sprite::Sprite(shared_ptr<Texture> image, const Color & color,
- const flip_settings & flip) : color(color), flip(flip), sprite_image(image) {
+Sprite::Sprite(uint32_t id, shared_ptr<Texture> image, const Color & color,
+ const flip_settings & flip) : Component(id), color(color), flip(flip), sprite_image(image) {
dbg_trace();
}
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 920f91e..3d9e911 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -17,7 +17,7 @@ struct flip_settings{
class Sprite : public Component {
public:
- Sprite(std::shared_ptr<Texture> image, const Color& color, const flip_settings& flip );
+ Sprite(uint32_t game_id, std::shared_ptr<Texture> image, const Color& color, const flip_settings& flip );
~Sprite();
std::shared_ptr<Texture> sprite_image;
Color color;
diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp
index c83461f..4f22843 100644
--- a/src/crepe/api/Transform.cpp
+++ b/src/crepe/api/Transform.cpp
@@ -1,13 +1,15 @@
#include "Transform.h"
+#include "Component.h"
#include "api/Point.h"
#include "util/log.h"
+#include <cstdint>
using namespace crepe::api;
-Transform::Transform(Point & point, double rot, double scale)
- : position(point), rotation(rot), scale(scale) {
+Transform::Transform(uint32_t game_id, Point & point, double rot, double scale)
+ : Component(game_id), position(point), rotation(rot), scale(scale) {
dbg_trace();
}
Transform::~Transform() { dbg_trace(); }
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
index a34ebb1..29e2a3d 100644
--- a/src/crepe/api/Transform.h
+++ b/src/crepe/api/Transform.h
@@ -2,11 +2,12 @@
#include "Component.h"
#include "api/Point.h"
+#include <cstdint>
namespace crepe::api {
class Transform : public Component {
public:
- Transform(Point&, double, double);
+ Transform(uint32_t id, Point&, double, double);
~Transform();
Point position; // Translation (shift)
double rotation; // Rotation, in radians