From 267310efd82fc493ac5b484d9e4584b250c6a0d5 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 14 Sep 2022 21:30:48 -0500 Subject: [PATCH] Async cutscene triggers implemented Co-authored-by: sigonasr2 --- C++ProjectTemplate | Bin 979904 -> 979904 bytes SeasonI.code-workspace | 77 +++++++++++++++++++++++++++++++++++++++++ cutscene.h | 58 +++++++++++++++++++++++++++---- main.cpp | 71 +++++++++++++++++++++++++++++++------ 4 files changed, 189 insertions(+), 17 deletions(-) create mode 100644 SeasonI.code-workspace diff --git a/C++ProjectTemplate b/C++ProjectTemplate index fbd6816fbadccf02843886f021fda545537f7c90..efaa7880d3a632dd799eb2fec79756c847721292 100755 GIT binary patch delta 99 zcmX@`-1@+C>kSpmA~SfMeXgC{6Es2Z#C)qn`@B}p8G)E-dk-_S?n1`Z o?YovR12GE_vjQ<25VHd@2M}`tF&7YX12GQ}^KRd@gpbW10H?kzBLDyZ delta 99 zcmX@`-1@+C>kSpmA~Id!o7kMso8R^Dsc5~+a;uGT&$Q+q=JprL-K+FQftU$~L#Oy%K0mPg@%mu{UK+FTgyxVsz;bZd$0De*{umAu6 diff --git a/SeasonI.code-workspace b/SeasonI.code-workspace new file mode 100644 index 0000000..500c8b2 --- /dev/null +++ b/SeasonI.code-workspace @@ -0,0 +1,77 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "../Seasons-Of-Loneliness" + } + ], + "settings": { + "files.associations": { + "map1": "plaintext", + "*.tcc": "cpp", + "istream": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "pixelgameengine.h": "c", + "animations.h": "c" + } + } +} \ No newline at end of file diff --git a/cutscene.h b/cutscene.h index 02b7b14..740f911 100644 --- a/cutscene.h +++ b/cutscene.h @@ -1,5 +1,4 @@ #include "pixelGameEngine.h" -#include #define CAMERA_MOVESPD 5 @@ -19,12 +18,24 @@ enum class ActionType{ SET_FLAG_WHEN_CUTSCENE_ENDS, FADE, DIALOG, - MOVE_CUTSCENE_OBJ + MOVE_CUTSCENE_OBJ, + PAN_CAMERA_ASYNC, + FADE_ASYNC, + DIALOG_ASYNC, + MOVE_CUTSCENE_OBJ_ASYNC + //TODO: Change Sprites Action Type. }; class CutsceneAction{ + bool queued=false; //Set to true when added to action asynchronous queue. public: virtual ActionType GetActionType(){}; + bool InQueue() { + return queued; + } + void SetQueued(bool queued=true) { + this->queued=queued; + } }; class Cleanup:public CutsceneAction{ @@ -35,7 +46,7 @@ class Cleanup:public CutsceneAction{ class Object; class CreateObjects:public CutsceneAction{ - private: + protected: std::vectorobjs; public: template @@ -52,7 +63,7 @@ class CreateObjects:public CutsceneAction{ }; class PanCamera:public CutsceneAction{ - private: + protected: vd2d targetPos; PriorityDirection dir; double cameraSpd; @@ -74,8 +85,15 @@ class PanCamera:public CutsceneAction{ } }; +class PanCameraAsync:public PanCamera{ + public: + PanCameraAsync(vd2d targetPos,PriorityDirection dir,double cameraSpd=CAMERA_MOVESPD) + :PanCamera(targetPos,dir,cameraSpd){} + ActionType GetActionType() override{return ActionType::PAN_CAMERA_ASYNC;} + }; + class MoveCutsceneObject:public CutsceneAction{ - private: + protected: int objID; vd2d targetPos; double moveSpd; @@ -101,6 +119,13 @@ class MoveCutsceneObject:public CutsceneAction{ PriorityDirection GetMovement() { return dir; } +}; + +class MoveCutsceneObjectAsync:public MoveCutsceneObject{ + public: + MoveCutsceneObjectAsync(int objID,vd2d targetPos,double moveSpd=CAMERA_MOVESPD,PriorityDirection dir=BOTH) + :MoveCutsceneObject(objID,targetPos,moveSpd){} + ActionType GetActionType() override{return ActionType::MOVE_CUTSCENE_OBJ_ASYNC;} }; class SetFlagWhenCutsceneEnds:public CutsceneAction{ @@ -122,7 +147,7 @@ class SetFlagWhenCutsceneEnds:public CutsceneAction{ }; class Fade:public CutsceneAction{ - private: + protected: bool fadeIn=true; //If false, it fades out instead. double fadeSpd=0; public: @@ -141,8 +166,16 @@ class Fade:public CutsceneAction{ } }; +class FadeAsync:public Fade{ + public: + //If false, it fades out instead. + FadeAsync(bool fadeIn=false,double fadeSpd=4) + :Fade(fadeIn,fadeSpd){} + ActionType GetActionType() override{return ActionType::FADE_ASYNC;} + }; + class DialogBox:public CutsceneAction{ - private: + protected: std::string message; bool messageBoxVisible=false; public: @@ -163,6 +196,14 @@ class DialogBox:public CutsceneAction{ } }; +class DialogBoxAsync:public DialogBox{ + public: + //If false, it fades out instead. + DialogBoxAsync(std::string message) + :DialogBox(message){} + ActionType GetActionType() override{return ActionType::DIALOG_ASYNC;} + }; + /* To use this class, specify multiple actions back-to-back, filling their appropriate arguments. @@ -212,6 +253,9 @@ class Cutscene{ void ResetCutscene(){ actionMarker=0; actionIsActive=false; + for (auto&action:actions) { + action->SetQueued(false); + } } Object*AddCutsceneObject(Object*obj) { this->cutsceneObjs.push_back(obj); diff --git a/main.cpp b/main.cpp index 1936bf4..5b52d88 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,13 @@ #define TILEMAP_EDITOR_DRAW_MULT 0.4375 #define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT) +#define AddAsyncCutsceneAction(AsyncClass) \ + if (!((AsyncClass*)CurrentCutscene->GetAction())->InQueue()) { \ + CUTSCENE_QUEUE.push_back(CurrentCutscene->GetAction()); \ + } \ + ((AsyncClass*)CurrentCutscene->GetAction())->SetQueued(); \ + CurrentCutscene->AdvanceAction(); \ + using namespace olc; namespace layer{ @@ -136,6 +143,7 @@ public: Cutscene*CurrentCutscene=nullptr; ActionType CurrentAction=ActionType::NONE; double CUTSCENE_FADE_VALUE=0; + std::vectorCUTSCENE_QUEUE; bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. @@ -195,7 +203,6 @@ public: (CutsceneAction*)new MoveCutsceneObject(1,{80,64}), (CutsceneAction*)new DialogBox(R"(Hello! This is a test message that lets us trigger straight from a cutscene! Cool!)"),}); - /*DisplayMessageBox(R"(Hello World! This is a rather long message, but I hope it reaches you well in some form or capacity or another. Even though it @@ -220,7 +227,7 @@ goes on a very long time, I hope you can understand this is only for testing pur Clear(MAGENTA); } else { Clear(BLANK); - } + } SetDrawTarget(layer::HIGH); Clear(BLANK); SetDrawTarget(layer::DYNAMIC); @@ -277,11 +284,17 @@ goes on a very long time, I hope you can understand this is only for testing pur CurrentCutscene->AdvanceAction(); } }break; + case ActionType::PAN_CAMERA_ASYNC:{ + AddAsyncCutsceneAction(PanCameraAsync); + }break; case ActionType::MOVE_CUTSCENE_OBJ:{ if (MoveObjectTowardsPoint(CurrentCutscene->GetCutsceneObjects()[((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetObjectID()],((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetTargetPos(),((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetMovement(),((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetMoveSpd())) { CurrentCutscene->AdvanceAction(); } }break; + case ActionType::MOVE_CUTSCENE_OBJ_ASYNC:{ + AddAsyncCutsceneAction(MoveCutsceneObjectAsync); + }break; case ActionType::CREATE_OBJECTS:{ for (auto&obj:((CreateObjects*)CurrentCutscene->GetAction())->GetObjects()) { obj->temp=true; @@ -290,16 +303,18 @@ goes on a very long time, I hope you can understand this is only for testing pur CurrentCutscene->AdvanceAction(); }break; case ActionType::CLEANUP:{ - for (int i=0;itemp) { - OBJECTS.erase(OBJECTS.begin()+i--); + if (CUTSCENE_QUEUE.size()==0) { + for (int i=0;itemp) { + OBJECTS.erase(OBJECTS.begin()+i--); + } } + CurrentCutscene->CleanupCutscene(); + CurrentCutscene->ResetCutscene(); + SetGameFlag(CurrentCutscene->GetEndingCutsceneFlag(),CurrentCutscene->GetEndingCutsceneVal()); + CurrentCutscene=nullptr; + CurrentAction=ActionType::NONE; } - CurrentCutscene->CleanupCutscene(); - CurrentCutscene->ResetCutscene(); - SetGameFlag(CurrentCutscene->GetEndingCutsceneFlag(),CurrentCutscene->GetEndingCutsceneVal()); - CurrentCutscene=nullptr; - CurrentAction=ActionType::NONE; }break; case ActionType::FADE:{ if (((Fade*)CurrentCutscene->GetAction())->FadeIn()&&CUTSCENE_FADE_VALUE>0) { @@ -315,6 +330,9 @@ goes on a very long time, I hope you can understand this is only for testing pur } } }break; + case ActionType::FADE_ASYNC:{ + AddAsyncCutsceneAction(FadeAsync); + }break; case ActionType::DIALOG:{ if (!((DialogBox*)CurrentCutscene->GetAction())->MessageHasBeenShown()) { DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage()); @@ -324,6 +342,39 @@ goes on a very long time, I hope you can understand this is only for testing pur CurrentCutscene->AdvanceAction(); } }break; + case ActionType::DIALOG_ASYNC:{ + DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage()); + CurrentCutscene->AdvanceAction(); + }break; + } + + for (int i=0;iGetActionType()) { + case ActionType::PAN_CAMERA_ASYNC:{ + if (MoveCameraTowardsPoint((PanCameraAsync*)CUTSCENE_QUEUE[i])) { + CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--); + } + }break; + case ActionType::MOVE_CUTSCENE_OBJ_ASYNC:{ + if (MoveObjectTowardsPoint(CurrentCutscene->GetCutsceneObjects()[((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetObjectID()],((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetTargetPos(),((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetMovement(),((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetMoveSpd())) { + CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--); + } + }break; + case ActionType::FADE_ASYNC:{ + if (((FadeAsync*)CUTSCENE_QUEUE[i])->FadeIn()&&CUTSCENE_FADE_VALUE>0) { + CUTSCENE_FADE_VALUE=std::clamp(CUTSCENE_FADE_VALUE-((FadeAsync*)CUTSCENE_QUEUE[i])->GetFadeSpd(),0.0,255.0); + if (CUTSCENE_FADE_VALUE==0) { + CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--); + } + } else + if (!((FadeAsync*)CUTSCENE_QUEUE[i])->FadeIn()&&CUTSCENE_FADE_VALUE<255) { + CUTSCENE_FADE_VALUE=std::clamp(CUTSCENE_FADE_VALUE+((FadeAsync*)CUTSCENE_QUEUE[i])->GetFadeSpd(),0.0,255.0); + if (CUTSCENE_FADE_VALUE==255) { + CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--); + } + } + }break; + } }