aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaroWMR <jarorutjes07@gmail.com>2024-10-23 20:03:18 +0200
committerjaroWMR <jarorutjes07@gmail.com>2024-10-23 20:03:18 +0200
commit3789031ac520b393969bbedd55444e3fd2b7f1fa (patch)
tree212f78845ae1f8972a96636e8425b080a64c7e05
parentedbb6c892299e3b7f93638abcc9e55b2cfce2358 (diff)
parentc9246515fe785563411e9170aedd0231165ab988 (diff)
merge with niels/rendering
-rw-r--r--src/crepe/CMakeLists.txt5
-rw-r--r--src/crepe/RenderSystem.cpp23
-rw-r--r--src/crepe/SdlContext.cpp2
-rw-r--r--src/crepe/api/CMakeLists.txt6
-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
-rw-r--r--src/example/CMakeLists.txt7
-rw-r--r--src/example/rendering.cpp17
11 files changed, 40 insertions, 39 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt
index afaa74c..1b4b1c2 100644
--- a/src/crepe/CMakeLists.txt
+++ b/src/crepe/CMakeLists.txt
@@ -13,6 +13,7 @@ target_sources(crepe PUBLIC
CollisionSystem.cpp
Collider.cpp
SdlContext.cpp
+
RenderSystem.cpp
)
@@ -20,9 +21,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Asset.h
Sound.h
SoundContext.h
- ParticleSystem.h
- Particle.h
- SDLApp.h
+ SdlContext.h
ComponentManager.h
ComponentManager.hpp
Component.h
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/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index f6de96e..f2d45eb 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -4,13 +4,14 @@ target_sources(crepe PUBLIC
Script.cpp
GameObject.cpp
Rigidbody.cpp
- Sprite.cpp
Force.cpp
ParticleEmitter.cpp
Transform.cpp
Color.cpp
Texture.cpp
AssetManager.cpp
+ Collider.cpp
+ Sprite.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
@@ -21,9 +22,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
GameObject.hpp
Rigidbody.h
Sprite.h
- Force.h
- ParticleEmitter.h
- Transform.h
Point.h
Color.h
Texture.h
diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h
index b7a0064..e59e217 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -3,7 +3,7 @@
#include "../Component.h"
#include <cstdint>
-namespace crepe::api {
+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
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt
index 475d31c..4295d19 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -19,10 +19,7 @@ endfunction()
add_example(audio_internal)
add_example(components_internal)
add_example(script)
-add_example(particle)
-add_example(Physics)
-target_link_libraries(particle PUBLIC SDL2)
-target_link_libraries(Physics PUBLIC SDL2)
add_example(rendering)
add_example(asset_manager)
-
+add_example(particle)
+add_example(Physics)
diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp
index 34d9f66..1d83004 100644
--- a/src/example/rendering.cpp
+++ b/src/example/rendering.cpp
@@ -1,7 +1,7 @@
#include <crepe/ComponentManager.h>
-#include <crepe/GameObject.h>
+#include <crepe/api/GameObject.h>
#include <crepe/RenderSystem.h>
#include <crepe/util/log.h>
@@ -24,8 +24,8 @@ int main() {
dbg_trace();
auto obj = GameObject(0, "name", "tag", 0);
- auto obj1= GameObject(0, "name", "tag", 0);
- auto obj2 = GameObject(0, "name", "tag", 0);
+ auto obj1= GameObject(1, "name", "tag", 0);
+ auto obj2 = GameObject(2, "name", "tag", 0);
auto& mgr = AssetManager::get_instance();
// Normal adding components
@@ -40,17 +40,20 @@ int main() {
make_shared<Texture>("../asset/texture/img.png"), color,
flip_settings{true, true});
}
+
+
{
Color color(0, 0, 0, 0);
Point point = {
.x = 500,
.y = 0,
};
- obj.add_component<Transform>(point, 0, 0.1);
+ obj1.add_component<Transform>(point, 0, 0.1);
auto img = mgr.cache<Texture>("../asset/texture/second.png");
- obj.add_component<Sprite>(img, color,
+ obj1.add_component<Sprite>(img, color,
flip_settings{true, true});
}
+
{
Color color(0, 0, 0, 0);
Point point = {
@@ -59,13 +62,11 @@ int main() {
};
//obj.add_component<Transform>(point, 0, 0.1);
auto img = mgr.cache<Texture>("../asset/texture/second.png");
- obj.add_component<Sprite>(img, color,
+ obj2.add_component<Sprite>(img, color,
flip_settings{true, true});
}
-
-
auto & sys = crepe::RenderSystem::get_instance();
auto start = std::chrono::steady_clock::now();
while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) {