diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-12-20 12:05:52 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-12-20 12:05:52 +0100 |
commit | 74f70c61a37c94727e1411696f050cf588cf3446 (patch) | |
tree | 389c1e1a9b4b3a94dc9c10a94f00b28fe1e007ff | |
parent | 79d3a9f4311e6684b6df83a15ca7844f58c1959c (diff) |
Fix merge issues
-rw-r--r-- | game/main.cpp | 4 | ||||
-rw-r--r-- | src/example/FontExample.cpp | 55 | ||||
-rw-r--r-- | src/example/ForestParallaxScript.cpp | 2 | ||||
-rw-r--r-- | src/example/ForestParallaxScript.h | 2 | ||||
-rw-r--r-- | src/example/PlayerScript.cpp | 2 | ||||
-rw-r--r-- | src/example/PlayerScript.h | 2 | ||||
-rw-r--r-- | src/example/StartGameScript.cpp | 2 | ||||
-rw-r--r-- | src/example/StartGameScript.h | 2 | ||||
-rw-r--r-- | src/example/StartSubScene.cpp | 24 | ||||
-rw-r--r-- | src/example/game.cpp | 8 | ||||
-rw-r--r-- | src/example/loadfont.cpp | 49 | ||||
-rw-r--r-- | src/example/replay.cpp | 84 |
12 files changed, 23 insertions, 213 deletions
diff --git a/game/main.cpp b/game/main.cpp index af14ed5..237c8ce 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,3 +1 @@ -int main() { - -} +int main() {} diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp deleted file mode 100644 index 6a334b1..0000000 --- a/src/example/FontExample.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include <SDL2/SDL_ttf.h> -#include <chrono> -#include <crepe/api/Camera.h> -#include <crepe/api/Config.h> -#include <crepe/api/GameObject.h> -#include <crepe/api/LoopManager.h> -#include <crepe/api/Scene.h> -#include <crepe/api/Script.h> -#include <crepe/api/Text.h> -#include <crepe/facade/Font.h> -#include <crepe/facade/SDLContext.h> -#include <crepe/manager/EventManager.h> -#include <crepe/manager/Mediator.h> -#include <crepe/manager/ResourceManager.h> -#include <exception> -#include <iostream> -#include <memory> -using namespace crepe; -using namespace std; -using namespace std::chrono; -class TestScript : public Script { -public: - steady_clock::time_point start_time; - virtual void init() override { start_time = steady_clock::now(); } - virtual void update() override { - auto now = steady_clock::now(); - auto elapsed = duration_cast<seconds>(now - start_time).count(); - - if (elapsed >= 5) { - Mediator & med = mediator; - EventManager & event_mgr = med.event_manager; - event_mgr.trigger_event<ShutDownEvent>(); - } - } -}; -class TestScene : public Scene { -public: - void load_scene() override { - GameObject text_object = this->new_object("test", "test", vec2{0, 0}, 0, 1); - text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "OpenSymbol", - Text::Data{}); - text_object.add_component<BehaviorScript>().set_script<TestScript>(); - text_object.add_component<Camera>(ivec2{300, 300}, vec2{100, 100}, Camera::Data{}); - } - std::string get_name() const override { return "hey"; } -}; -int main() { - // Config& config = Config::get_instance(); - // config.log.level = Log::Level::TRACE; - LoopManager engine; - engine.add_scene<TestScene>(); - engine.start(); - - return 0; -} diff --git a/src/example/ForestParallaxScript.cpp b/src/example/ForestParallaxScript.cpp index 782cdf0..27e30eb 100644 --- a/src/example/ForestParallaxScript.cpp +++ b/src/example/ForestParallaxScript.cpp @@ -9,7 +9,7 @@ ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x, end_x(end_x), name(unique_bg_name) {} -void ForestParallaxScript::update() { +void ForestParallaxScript::fixed_update(crepe::duration_t dt) { RefVector<Transform> vec_2 = this->get_components_by_name<Transform>("forest_bg_2_" + name); RefVector<Transform> vec_3 diff --git a/src/example/ForestParallaxScript.h b/src/example/ForestParallaxScript.h index 39b7ecb..a65a684 100644 --- a/src/example/ForestParallaxScript.h +++ b/src/example/ForestParallaxScript.h @@ -6,7 +6,7 @@ class ForestParallaxScript : public crepe::Script { public: ForestParallaxScript(float begin_x, float end_x, std::string unique_bg_name); - void update(); + void fixed_update(crepe::duration_t dt); private: const float begin_x; diff --git a/src/example/PlayerScript.cpp b/src/example/PlayerScript.cpp index a147e06..1c388f5 100644 --- a/src/example/PlayerScript.cpp +++ b/src/example/PlayerScript.cpp @@ -5,7 +5,7 @@ using namespace crepe; using namespace std; -void PlayerScript::update() { +void PlayerScript::fixed_update(crepe::duration_t dt) { Rigidbody & rb = this->get_components_by_name<Rigidbody>("player").front(); if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); } diff --git a/src/example/PlayerScript.h b/src/example/PlayerScript.h index 254dd41..84c4f7f 100644 --- a/src/example/PlayerScript.h +++ b/src/example/PlayerScript.h @@ -4,5 +4,5 @@ class PlayerScript : public crepe::Script { public: - void update(); + void fixed_update(crepe::duration_t dt); }; diff --git a/src/example/StartGameScript.cpp b/src/example/StartGameScript.cpp index 00f419d..50ba86c 100644 --- a/src/example/StartGameScript.cpp +++ b/src/example/StartGameScript.cpp @@ -7,7 +7,7 @@ using namespace crepe; using namespace std; -void StartGameScript::update() { +void StartGameScript::fixed_update(crepe::duration_t dt) { Transform & player_transform = this->get_components_by_name<Transform>("player").front(); // Create hole in wall and activate panic lamp diff --git a/src/example/StartGameScript.h b/src/example/StartGameScript.h index f3534d0..ad62e1a 100644 --- a/src/example/StartGameScript.h +++ b/src/example/StartGameScript.h @@ -4,7 +4,7 @@ class StartGameScript : public crepe::Script { public: - void update(); + void fixed_update(crepe::duration_t dt); private: bool created_hole = false; diff --git a/src/example/StartSubScene.cpp b/src/example/StartSubScene.cpp index 9006dc7..e943396 100644 --- a/src/example/StartSubScene.cpp +++ b/src/example/StartSubScene.cpp @@ -161,7 +161,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.5, 0.6), .angular_velocity = 500, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_1_rb.active = false; frag_1.add_component<CircleCollider>(25); @@ -181,7 +181,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.35, 0.4), .angular_velocity = 400, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_2_rb.active = false; frag_2.add_component<CircleCollider>(55); @@ -201,7 +201,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.3, 0.3), .angular_velocity = 300, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_3_rb.active = false; frag_3.add_component<CircleCollider>(35); @@ -221,7 +221,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.2, 0.2), .angular_velocity = 200, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_4_rb.active = false; frag_4.add_component<CircleCollider>(60); @@ -241,7 +241,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.25, 0.15), .angular_velocity = 100, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_5_rb.active = false; frag_5.add_component<CircleCollider>(5); @@ -261,7 +261,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.35, 0.25), .angular_velocity = 100, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_6_rb.active = false; frag_6.add_component<CircleCollider>(30); @@ -281,7 +281,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.45, 0.6), .angular_velocity = 800, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_7_rb.active = false; frag_7.add_component<CircleCollider>(45); @@ -301,7 +301,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.5, 0.6), .angular_velocity = 500, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_8_rb.active = false; frag_8.add_component<CircleCollider>(25); @@ -321,7 +321,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.5, 0.25), .angular_velocity = 500, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_9_rb.active = false; frag_9.add_component<CircleCollider>(15); @@ -341,7 +341,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.35, 0.4), .angular_velocity = 300, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_10_rb.active = false; frag_10.add_component<CircleCollider>(60); @@ -361,7 +361,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.3, 0.3), .angular_velocity = 200, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_11_rb.active = false; frag_11.add_component<CircleCollider>(5); @@ -381,7 +381,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.25, 0.15), .angular_velocity = 100, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_12_rb.active = false; frag_12.add_component<CircleCollider>(50); diff --git a/src/example/game.cpp b/src/example/game.cpp index 378a64a..b9f98fc 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -1,13 +1,13 @@ #include "GameScene.h" -#include <crepe/api/LoopManager.h> +#include <crepe/api/Engine.h> using namespace crepe; using namespace std; int main(int argc, char * argv[]) { - LoopManager gameloop; + Engine gameloop; gameloop.add_scene<GameScene>(); - gameloop.start(); - return 0; + + return gameloop.main(); } diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp deleted file mode 100644 index e459332..0000000 --- a/src/example/loadfont.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include <SDL2/SDL_ttf.h> -#include <crepe/api/Asset.h> -#include <crepe/api/Text.h> -#include <crepe/facade/Font.h> -#include <crepe/facade/FontFacade.h> -#include <crepe/facade/SDLContext.h> -#include <crepe/manager/Mediator.h> -#include <crepe/manager/ResourceManager.h> -#include <exception> -#include <iostream> -#include <memory> -#include <optional> -using namespace crepe; -int main() { - - // SDLFontContext font_facade; - Mediator mediator; - FontFacade font_facade{}; - SDLContext sdl_context{mediator}; - // ComponentManager component_manager{mediator}; - ResourceManager resource_manager{mediator}; - try { - // Correct way to create a unique pointer for Text - std::unique_ptr<Text> label = std::make_unique<Text>( - 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text"); - // std::cout << "Path: " << label->font.get_path() << std::endl; - Asset asset1 = font_facade.get_font_asset("OpenSymbol"); - std::cout << asset1.get_path() << std::endl; - std::unique_ptr<Text> label2 = std::make_unique<Text>( - 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data{}); - Asset asset = Asset("test test"); - label->font.emplace(asset); - std::cout << label->font.value().get_path() << std::endl; - // label2->font = std::make_optional(asset); - // std::cout << "Path: " << label2->font.get_path() << std::endl; - ResourceManager & resource_mgr = mediator.resource_manager; - const Font & res = resource_manager.get<Font>(label->font.value()); - // TTF_Font * test_font = res.get_font(); - // if (test_font == NULL) { - // std::cout << "error with font" << std::endl; - // } else { - // std::cout << "correct font retrieved" << std::endl; - // } - } catch (const std::exception & e) { - std::cout << "Standard exception thrown: " << e.what() << std::endl; - } - - return 0; -} diff --git a/src/example/replay.cpp b/src/example/replay.cpp deleted file mode 100644 index 82fd478..0000000 --- a/src/example/replay.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include <crepe/api/Config.h> -#include <crepe/api/Engine.h> -#include <crepe/api/Script.h> - -using namespace crepe; -using namespace std; - -class AnimationScript : public Script { - Transform * transform; - float t = 0; - - void init() { transform = &get_component<Transform>(); } - - void update() { - t += 0.05; - transform->position = {sin(t), cos(t)}; - } -}; - -class Timeline : public Script { - unsigned i = 0; - recording_t recording; - - void update() { - switch (i++) { - default: - break; - case 10: - logf("record start"); - replay.record_start(); - break; - case 60: - logf("record end, playing recording"); - this->recording = replay.record_end(); - replay.play(this->recording); - break; - case 61: - logf("done, releasing recording"); - replay.release(this->recording); - break; - case 72: - logf("exit"); - queue_event<ShutDownEvent>(); - break; - }; - } -}; - -class TestScene : public Scene { -public: - using Scene::Scene; - - void load_scene() { - Mediator & mediator = this->mediator; - ComponentManager & mgr = mediator.component_manager; - - GameObject cam = mgr.new_object("cam"); - cam.add_component<Camera>(ivec2{640, 480}, vec2{3, 3}, - Camera::Data{ - .bg_color = Color::WHITE, - }); - - GameObject square = mgr.new_object("square"); - square.add_component<Sprite>(Asset{"asset/texture/square.png"}, Sprite::Data{ - .size = {0.5, 0.5}, - }); - square.add_component<BehaviorScript>().set_script<AnimationScript>(); - - GameObject scapegoat = mgr.new_object(""); - scapegoat.add_component<BehaviorScript>().set_script<Timeline>(); - } - - string get_name() const { return "scene1"; } -}; - -int main(int argc, char * argv[]) { - Config & cfg = Config::get_instance(); - cfg.log.level = Log::Level::DEBUG; - - Engine engine; - - engine.add_scene<TestScene>(); - return engine.main(); -} |