Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
chronos.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2024 Rahul Satish Vadhyar
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
23#pragma once
28#include "vulkanHeaders.hpp"
29#include "commonStructs.hpp"
30#include "engine.hpp"
31#include "animManager.hpp"
32#include "engineStructs.hpp"
33
34namespace Chronos {
35namespace Manager {
46 struct Initializer {
47 int WindowWidth = 800;
48 int WindowHeight = 600;
49 int BackgroundColor[3] = { 0, 0, 0 };
50#ifdef ENABLE_EDITOR
51 // function pointer for calling the function that will render the editor
52 // elements on the screen
53 void (*editorAddElements)();
54#endif
55 };
56
67 struct Text {
68 float x = 0.0;
69 float y = 0.0;
70 float rotation = 0.0;
71 float scale = 1.0;
72 std::string text = "";
73 };
74
91 std::string textureName;
92 std::string texturePath;
94 int width;
95 int height;
96#ifdef ENABLE_EDITOR
97 VkDescriptorSet descriptorSet;
98#endif
99 };
100
109 class Manager {
110 public:
117 Manager(Initializer initializer);
130 GLFWwindow* getWindow();
131
141 void drawFrame();
142
173 int addText(Chronos::Engine::TextParams params, std::string fontType,
174 int fontSize);
175
198 int addShape(Chronos::Manager::ShapeParams shapeParams, int texture);
199
221
239 void updateShape(
240 int objectNo, Chronos::Manager::ShapeParams shapeParams);
241 std::vector<std::pair<int, Chronos::Manager::ShapeParams>>
255 void updateText(int objectNo, Chronos::Engine::TextParams params);
256
267 std::vector<std::pair<int, Chronos::Engine::TextParams>>
269
270 void removeObject(int objectNo);
271
282 int changeBackgroundColor(float r, float g, float b);
283
297 int addTexture(std::string texturePath, std::string textureName);
298
307 void removeTexture(int textureNo);
308
319 std::vector<TextureDetails> getTextureDetails();
320
356 void changePresentMode(std::string presentMode)
357 {
358 engine.setPresentMode(presentMode);
359 }
360
361 std::vector<std::string> getMSAAModes()
362 {
364 }
365
366 void changeMSAA(std::string mode) { engine.changeMSAA(mode); }
367
368 int addRig(int x, int y) { return animManager.addRig(x, y); }
369
370 void removeRig(int rigNo) { animManager.removeRig(rigNo); }
371
372 void rigAddBone(int rigNo, int parentNo)
373 {
374 animManager.rigAddBone(rigNo, parentNo);
375 }
376
377 void rigRemoveBone(int rigNo, int boneNo)
378 {
379 animManager.rigRemoveBone(rigNo, boneNo);
380 }
381
382 void rigAddChild(int rigNo, int parentNo, int childNo)
383 {
384 animManager.rigAddChild(rigNo, parentNo, childNo);
385 }
386
387 void rigRemoveChild(int rigNo, int parentNo, int childNo)
388 {
389 animManager.rigRemoveChild(rigNo, parentNo, childNo);
390 }
391
392 void rigSetRelX(int rigNo, int boneNo, float relX)
393 {
394 animManager.rigSetRelX(rigNo, boneNo, relX);
395 }
396
397 void rigSetRelY(int rigNo, int boneNo, float relY)
398 {
399 animManager.rigSetRelY(rigNo, boneNo, relY);
400 }
401
402 void rigSetLength(int rigNo, int boneNo, float length)
403 {
404 animManager.rigSetLength(rigNo, boneNo, length);
405 }
406
407 void rigSetAngle(int rigNo, int boneNo, float angle)
408 {
409 animManager.rigSetAngle(rigNo, boneNo, angle);
410 }
411
412 void rigSetParent(int rigNo, int boneNo, int parentNo)
413 {
414 animManager.rigSetParent(rigNo, boneNo, parentNo);
415 }
416
417 float rigGetRelX(int rigNo, int boneNo)
418 {
419 return animManager.rigGetRelX(rigNo, boneNo);
420 }
421
422 float rigGetRelY(int rigNo, int boneNo)
423 {
424 return animManager.rigGetRelY(rigNo, boneNo);
425 }
426
427 float rigGetLength(int rigNo, int boneNo)
428 {
429 return animManager.rigGetLength(rigNo, boneNo);
430 }
431
432 float rigGetAngle(int rigNo, int boneNo)
433 {
434 return animManager.rigGetAngle(rigNo, boneNo);
435 }
436
437 float rigGetX(int rigNo, int boneNo)
438 {
439 return animManager.rigGetX(rigNo, boneNo);
440 }
441
442 float rigGetY(int rigNo, int boneNo)
443 {
444 return animManager.rigGetY(rigNo, boneNo);
445 }
446
447 int rigGetParent(int rigNo, int boneNo)
448 {
449 return animManager.rigGetParent(rigNo, boneNo);
450 }
451
452 std::vector<int> rigGetChildren(int rigNo, int boneNo)
453 {
454 return animManager.rigGetChildren(rigNo, boneNo);
455 }
456
457 int addKeyframeVariable(std::vector<std::pair<float, float>> keyframes)
458 {
459 return animManager.addKeyframeVariable(keyframes);
460 }
461
462 void removeKeyframeVariable(int keyframeNo)
463 {
464 animManager.removeKeyframeVariable(keyframeNo);
465 }
466
467 void keyframeSetTime(int keyframeNo, float time)
468 {
469 animManager.keyframeSetTime(keyframeNo, time);
470 }
471
472 void keyframeSetKeyframe(int keyframeNo, int keyframe)
473 {
474 animManager.keyframeSetKeyframe(keyframeNo, keyframe);
475 }
476
477 int keyframeGetKeyframe(int keyframeNo)
478 {
479 return animManager.keyframeGetKeyframe(keyframeNo);
480 }
481
482 std::vector<std::pair<float, float>> getKeyframes(int keyframeNo)
483 {
484 return animManager.getKeyframes(keyframeNo);
485 }
486
487 float keyframeGetVariable(int keyframeNo)
488 {
489 return animManager.keyframeGetVariable(keyframeNo);
490 }
491
492#ifdef CHRONOS_PROFILING
493 float getWaitTime() { return engine.getWaitTime() * 1e-6; }
494
495 float getUpdateTime() { return engine.getUpdateTime() * 1e-6; }
496
497 float getCpuTime() { return engine.getCpuTime() * 1e-6; }
498
499 float getTotalTime() { return engine.getTotalTime() * 1e-6; }
500
501 float getPresentTime() { return engine.getPresentTime() * 1e-6; }
502#endif
503
504 private:
510
511 Chronos::Animation::AnimationManager animManager;
512 };
513};
514};
void setPresentMode(std::string mode)
Changes the present mode of the swapchain.
Definition engine.cpp:452
void changeMSAA(std::string)
Definition engine.cpp:495
std::vector< std::string > getAvailableMSAAModes()
Definition engine.cpp:469
The main manager of chronos.
Definition chronos.hpp:109
Chronos::Engine::Engine engine
The backend Vulkan engine, used for rendering the desired shapes and text.s.
Definition chronos.hpp:509
int addText(Chronos::Engine::TextParams params, std::string fontType, int fontSize)
Adds text to the window.
std::vector< std::pair< int, Chronos::Engine::TextParams > > getTextDetails()
Returns the details of all text defined.
Chronos::Animation::AnimationManager animManager
Definition chronos.hpp:511
void removeObject(int objectNo)
Definition manager.cpp:68
int changeBackgroundColor(float r, float g, float b)
Changes the background color of the window.
Definition manager.cpp:57
void updateText(int objectNo, Chronos::Engine::TextParams params)
Updates the text with the new parameters.
void rigAddBone(int rigNo, int parentNo)
Definition chronos.hpp:372
void updateShape(int objectNo, Chronos::Manager::ShapeParams shapeParams)
Updates the polygon(any) with the new parameters.
GLFWwindow * getWindow()
Gets a reference to the GLFWWindow.
Definition manager.cpp:25
int keyframeGetKeyframe(int keyframeNo)
Definition chronos.hpp:477
int addShape(Chronos::Manager::ShapeParams shapeParams, int texture)
Adds a textured rectangle to the window.
void rigSetLength(int rigNo, int boneNo, float length)
Definition chronos.hpp:402
void rigSetAngle(int rigNo, int boneNo, float angle)
Definition chronos.hpp:407
void rigSetRelY(int rigNo, int boneNo, float relY)
Definition chronos.hpp:397
void removeTexture(int textureNo)
Removes the texture from the window.
void rigSetParent(int rigNo, int boneNo, int parentNo)
Definition chronos.hpp:412
float rigGetRelX(int rigNo, int boneNo)
Definition chronos.hpp:417
int addTexture(std::string texturePath, std::string textureName)
Loads a texture from file.
void rigRemoveChild(int rigNo, int parentNo, int childNo)
Definition chronos.hpp:387
void drawFrame()
Draws the current frame to the window.
Definition manager.cpp:52
void changePresentMode(std::string presentMode)
Changes the present mode of the swapchain.
Definition chronos.hpp:356
int addRig(int x, int y)
Definition chronos.hpp:368
std::vector< std::pair< int, Chronos::Manager::ShapeParams > > getShapeDetails()
std::vector< int > rigGetChildren(int rigNo, int boneNo)
Definition chronos.hpp:452
void rigAddChild(int rigNo, int parentNo, int childNo)
Definition chronos.hpp:382
int rigGetParent(int rigNo, int boneNo)
Definition chronos.hpp:447
int addKeyframeVariable(std::vector< std::pair< float, float > > keyframes)
Definition chronos.hpp:457
void keyframeSetTime(int keyframeNo, float time)
Definition chronos.hpp:467
float rigGetX(int rigNo, int boneNo)
Definition chronos.hpp:437
float keyframeGetVariable(int keyframeNo)
Definition chronos.hpp:487
void rigRemoveBone(int rigNo, int boneNo)
Definition chronos.hpp:377
void rigSetRelX(int rigNo, int boneNo, float relX)
Definition chronos.hpp:392
void removeRig(int rigNo)
Definition chronos.hpp:370
void removeKeyframeVariable(int keyframeNo)
Definition chronos.hpp:462
std::vector< std::string > getMSAAModes()
Definition chronos.hpp:361
float rigGetRelY(int rigNo, int boneNo)
Definition chronos.hpp:422
float rigGetLength(int rigNo, int boneNo)
Definition chronos.hpp:427
void changeMSAA(std::string mode)
Definition chronos.hpp:366
float rigGetAngle(int rigNo, int boneNo)
Definition chronos.hpp:432
std::vector< std::pair< float, float > > getKeyframes(int keyframeNo)
Definition chronos.hpp:482
void keyframeSetKeyframe(int keyframeNo, int keyframe)
Definition chronos.hpp:472
std::vector< TextureDetails > getTextureDetails()
Returns the details of all textures defined.
float rigGetY(int rigNo, int boneNo)
Definition chronos.hpp:442
Header file that contains common structs used in Chronos.
Contains ShapeParams and UniformBufferObject structs.
Contains the Engine class.
Parameters for rendering text.
This struct contains the details for initialing the manager.
Definition chronos.hpp:46
Parameters for creating a shape(any)
Text parameters for displaying text.
Definition chronos.hpp:67
Holds some details about the texture.
Definition chronos.hpp:90
Contains the common headers for the vulkan API.