JugiMap Framework
jmGlobal.h
1 #ifndef JUGIMAP_GLOBAL_H
2 #define JUGIMAP_GLOBAL_H
3 
4 #include <chrono>
5 #include "jmCommon.h"
6 
7 
8 
9 namespace jugimap {
10 
11 
14 
15 
17 enum class FileKind
18 {
19  SINGLE_IMAGE,
22  SPINE_FILE,
23  SPRITER_FILE,
26 };
27 
28 
30 enum class SpriteKind
31 {
32  STANDARD,
33  COMPOSED,
34  TEXT,
35  SPINE,
36  SPRITER,
38 };
39 
40 
42 enum class MapType
43 {
44  WORLD,
45  PARALLAX,
46  SCREEN,
47 };
48 
49 
51 enum class LayerKind
52 {
53  SPRITE,
54  VECTOR,
55  DRAWING,
56  //TEXT, ///< %Text layer - TextLayer object.
57  CUSTOM,
59 };
60 
61 
62 
64 enum class LayerType
65 {
66  WORLD,
67  PARALLAX,
68  PARALLAX_STRETCHING_SINGLE_SPRITE,
69  SCREEN,
70  SCREEN_STRETCHING_SINGLE_SPRITE
71 };
72 
73 
74 
77 {
78  XY_TO_WORLD_SIZE,
79  XY_TO_VIEWPORT_SIZE
80 };
81 
82 
84 enum class AlignX
85 {
86  LEFT,
87  MIDDLE,
88  RIGHT
89 };
90 
92 enum class AlignY
93 {
94  TOP,
95  MIDDLE,
96  BOTTOM
97 };
98 
99 
101 enum class Blend
102 {
103  SOLID,
104  ALPHA,
105  MULTIPLY,
106  ADDITIVE,
107  NOT_DEFINED
108 };
109 
110 
113 {
115  NORMAL,
116  MULTIPLY,
117  LINEAR_DODGE,
118  COLOR,
119  NOT_DEFINED
120 };
121 
122 
124 enum class FontKind
125 {
126  TRUE_TYPE,
127  BITMAP_FONT__FNT,
128  NOT_DEFINED
129 };
130 
131 
133 enum class ShapeKind
134 {
135  POLYLINE,
137  ELLIPSE,
138  SINGLE_POINT,
139  NOT_DEFINED
140 };
141 
142 
143 
145 enum class AnimationKind
146 {
147  FRAME_ANIMATION = 0,
148  TIMELINE_ANIMATION = 1,
149  NOT_DEFINED = -1
150 };
151 
152 
153 //==================================================================================
154 
155 
158 {
159  TRANSLATION,
160  SCALING,
161  ROTATION,
162  ALPHA_CHANGE,
164  PATH_MOVEMENT,
165  FRAME_CHANGE,
168  FLIP_HIDE,
169  META,
170  NOT_DEFINED
171 
172 };
173 
174 
175 
176 
179 {
180  IDLE,
181  PLAYING,
182  STALLED,
183  PAUSED,
186 };
187 
188 
189 
193 {
194 
195  static const int NONE = 0;
196 
197  // Play
198  static const int DISCARD_ANIMATION_QUEUE = 1;
199  static const int SKIP_SUBPLAYER_UPDATING = 2;
200 
201 
202 
203  // Return flags
204  static const int PLAYER_STARTED = 1;
205  static const int PLAYER_UPDATED = 2;
206  static const int PLAYER_STOPPED = 4;
207  static const int ANIMATION_INSTANCE_UPDATED = 8;
208  static const int ANIMATED_PROPERTIES_CHANGED = 16;
209  static const int META_KEY_CHANGED = 32;
210 
211 };
212 
213 
214 
216 enum class GuiWidgetKind
217 {
218  NOT_DEFINED,
219  BUTTON,
220  SLIDER,
221  BAR,
222  TEXT_FIELD,
223  TEXT_INPUT
224 };
225 
226 
227 
230 {
231  CENTER = 0,
232  LEFT_TOP = 1,
233  TOP = 2,
234  RIGHT_TOP = 3,
235  RIGHT = 4,
236  RIGHT_BOTTOM = 5,
237  BOTTOM = 6,
238  LEFT_BOTTOM = 7,
239  LEFT = 8
240 };
241 
242 
243 TextHandleVariant GetTextHandleVariantFromInt(int _id);
244 
245 
248 
249 
251 enum class Engine
252 {
253  NOT_DEFINED,
254  AGK,
255  SFML,
256  Cocos2Dx,
257  nCine,
258 };
259 
260 
261 
265 class Settings
266 {
267 public:
268 
269 
270  void SetEngine(Engine _engine){ engine = _engine; }
271  Engine GetEngine(){ return engine; }
272 
273 
274 
281  void SetScreenSize(Vec2i _screenSize){ screenSize = _screenSize; }
282 
283 
289  Vec2i GetScreenSize(){ return screenSize; }
290 
291  //---------------
292 
301  void SetYCoordinateUp(bool _yCoordinateUp){ yCoordinateUp = _yCoordinateUp;}
302 
303 
309  bool IsYCoordinateUp(){ return yCoordinateUp; }
310 
311  //---------------
312 
326  void EnableSpriteColliders(bool _spriteCollidersEnabled){ spriteCollidersEnabled = _spriteCollidersEnabled; }
327 
328 
334  bool SpriteCollidersEnabled(){ return spriteCollidersEnabled; }
335 
336  //---------------
337 
347  void EnableEnginePhysics(bool _enginePhysicsEnabled){ enginePhysicsEnabled = _enginePhysicsEnabled; }
348 
349 
355  bool EnginePhysicsEnabled(){ return enginePhysicsEnabled; }
356 
357  //---------------
358 
366 
384  //void EnableLerpDrawing(bool _lerpDrawingEnabled){ lerpDrawingEnabled = _lerpDrawingEnabled; }
385 
386 
392  //bool LerpDrawingEnabled(){ return lerpDrawingEnabled; }
393 
394  //---------------
395 
404  //void SetLerpDrawingFactor(float _lerpDrawingFactor){ lerpDrawingFactor = _lerpDrawingFactor; }
405 
406 
412  //float GetLerpDrawingFactor(){ return lerpDrawingFactor; }
413 
414 
415 
416  //---------------
417 
419  void SetErrorMessage(const std::string &_errorMessage){ errorMessage = _errorMessage; }
420 
421 
423  std::string &GetErrorMessage(){ return errorMessage; }
424 
425 
426 
427  //---------------
429  void SetZOrderStep(int _zOrderStep){ zOrderStep = _zOrderStep; }
430 
432  int GetZOrderStep(){ return zOrderStep; }
433 
434 
435 
436  //---------------
438  void SetMapZOrderStart(int _mapZOrderStart){ mapZOrderStart = _mapZOrderStart; }
439 
441  int GetMapZOrderStart(){ return mapZOrderStart; }
442 
443 
444  //---------------
446  void SetMapZOrderStep(int _mapZOrderStep){ mapZOrderStep = _mapZOrderStep; }
447 
449  int GetMapZOrderStep(){ return mapZOrderStep; }
450 
451 
453  void SetAppTerminated(bool _appTerminated){ appTerminated = _appTerminated;}
454 
455 
457  bool IsAppTerminated(){ return appTerminated; }
458 
459 
460  //---------------
462  int GetRotationSignForYdir(){ return (yCoordinateUp)? 1 : -1; }
463 
464 
465 private:
466 
467  Engine engine = Engine::NOT_DEFINED;
468 
469  Vec2i screenSize;
470  bool yCoordinateUp;
471  bool spriteCollidersEnabled = true;
472  //bool lerpDrawingEnabled = false;
473  bool enginePhysicsEnabled = true;
474  std::string errorMessage;
475  //float lerpDrawingFactor = 1.0;
476  int zOrderStep = 10;
477  int mapZOrderStart = 10000;
478  int mapZOrderStep = 1000;
479 
480  bool appTerminated = false;
481 
482 };
483 
484 
486 extern Settings settings;
487 
488 
492 class Time
493 {
494 public:
495 
496 
502  {
503  if(started==false){
504  initTimePoint = std::chrono::high_resolution_clock::now();
505  started = true;
506  }
507  passedMicroseconds = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - initTimePoint).count();
508  return passedMicroseconds/1000.0;
509  }
510 
511 
515  void AddSuspendedTimeMS(int _suspendedTimeMS)
516  {
517  suspendedTimeMS += _suspendedTimeMS;
518  }
519 
520 
521 
528  int GetPassedNetTimeMS(){ return passedMicroseconds/1000.0 - suspendedTimeMS; }
529 
530 
531 
539  void SetLogicTimeMS(float _logicTimeStepMS){ logicTimeStepMS = _logicTimeStepMS; }
540 
541 
547  float GetLogicTimeMS(){ return logicTimeStepMS; }
548 
549 
550 
551 
552 private:
553  std::chrono::high_resolution_clock::time_point initTimePoint;
554  unsigned long long passedMicroseconds = 0;
555 
556  int suspendedTimeMS = 0;
557  bool started = false;
558  float logicTimeStepMS;
559 
560 };
561 
562 extern Time time;
563 
564 
565 
566 
570 void DeleteGlobalObjects();
571 
572 
573 
575 
576 
577 
578 }
579 
580 #endif
581 
582 
jugimap::FileKind::NOT_DEFINED
The file kind not defined.
jugimap::AnimationKind::TIMELINE_ANIMATION
Timeline animation - TimelineAnimation object.
jugimap::AnimationTrackKind::ROTATION
Rotation.
jugimap::AnimationPlayerFlags::PLAYER_UPDATED
static const int PLAYER_UPDATED
The return flag for AnimationQueuePlayer::Update command. If the player is in the in the idle state t...
Definition: jmGlobal.h:205
jugimap::MapType::SCREEN
Screen map.
jugimap::Settings::GetErrorMessage
std::string & GetErrorMessage()
Returns the global error message.
Definition: jmGlobal.h:423
jugimap::AnimationTrackKind::TRANSLATION
Translation.
jugimap::ShapeKind::BEZIER_POLYCURVE
Bezier polycurve - BezierShape object.
jugimap::Time::AddSuspendedTimeMS
void AddSuspendedTimeMS(int _suspendedTimeMS)
Add suspended time in milliseconds.
Definition: jmGlobal.h:515
jugimap::AnimationPlayerFlags::PLAYER_STARTED
static const int PLAYER_STARTED
The return flag for AnimationQueuePlayer::Play command. If the player already plays the given animati...
Definition: jmGlobal.h:204
jugimap::AlignY::TOP
Align top.
jugimap::settings
Settings settings
The Settings object.
Definition: jmGlobal.cpp:88
jugimap::Settings::GetZOrderStep
int GetZOrderStep()
Returns the z-order step.
Definition: jmGlobal.h:432
jugimap::Blend::ADDITIVE
Additive (lighten) blend.
jugimap::DeleteGlobalObjects
void DeleteGlobalObjects()
Definition: jmGlobal.cpp:93
jugimap::SpriteKind
SpriteKind
The kinds of sprite. Used as identifier for Sprite objects.
Definition: jmGlobal.h:30
jugimap::AnimationTrackKind::OVERLAY_COLOR_CHANGE
Overlay color change.
jugimap::GuiWidgetKind::TEXT_FIELD
Text field - GuiTextField object.
jugimap::ColorOverlayBlend::LINEAR_DODGE
Linear dodge mode.
jugimap::MapType::PARALLAX
Parallax map.
jugimap::ShapeKind::POLYLINE
Polyline - PolyLineShape object.
jugimap::Settings::IsAppTerminated
bool IsAppTerminated()
Returns true if application is marked as terminated; otherwise returns false.
Definition: jmGlobal.h:457
jugimap::Settings::GetMapZOrderStep
int GetMapZOrderStep()
Returns the map z-order step.
Definition: jmGlobal.h:449
jugimap::Settings::IsYCoordinateUp
bool IsYCoordinateUp()
Returns true if the y coordinate points up; if it points down returns false.
Definition: jmGlobal.h:309
jugimap::Settings::EnableEnginePhysics
void EnableEnginePhysics(bool _enginePhysicsEnabled)
Set to false if the engine physics are available in the used engine but disabled.
Definition: jmGlobal.h:347
jugimap::AnimationTrackKind::FRAME_CHANGE
Frame change.
jugimap::ColorOverlayBlend::COLOR
Color mode.
jugimap::AnimationTrackKind::FRAME_ANIMATION
Frame animation.
jugimap::Settings::SetMapZOrderStep
void SetMapZOrderStep(int _mapZOrderStep)
Set the map z-order step. Used by engines which use a z-order factor for drawing order of sprites.
Definition: jmGlobal.h:446
jugimap::AnimationPlayerFlags::DISCARD_ANIMATION_QUEUE
static const int DISCARD_ANIMATION_QUEUE
Stop and discard animations in queue and start the new animation immediately. This is an input flag f...
Definition: jmGlobal.h:198
jugimap::LayerKind::CUSTOM
Custom layer.
jugimap::AnimationPlayerFlags::ANIMATED_PROPERTIES_CHANGED
static const int ANIMATED_PROPERTIES_CHANGED
The return flag for AnimationQueuePlayer::Play and AnimationQueuePlayer::Update commands when the ani...
Definition: jmGlobal.h:208
jugimap::Settings::EnableSpriteColliders
void EnableSpriteColliders(bool _spriteCollidersEnabled)
Set to true if the Collider objects should be used for the sprites collision detection.
Definition: jmGlobal.h:326
jugimap::Settings::SetYCoordinateUp
void SetYCoordinateUp(bool _yCoordinateUp)
Set to true if the y coordinate in the used game engine points up.
Definition: jmGlobal.h:301
jugimap::StretchingVariant
StretchingVariant
The stretching variants.
Definition: jmGlobal.h:76
jugimap::SpriteKind::STANDARD
Standard sprite - StandardSprite object.
jugimap::ColorOverlayBlend::NORMAL
Normal mode.
jugimap::LayerKind
LayerKind
The kinds of layer. Used as identifier for Layer objects.
Definition: jmGlobal.h:51
jugimap::Time::UpdatePassedTimeMS
double UpdatePassedTimeMS()
Updates and returns the passed time in milliseconds.
Definition: jmGlobal.h:501
jugimap::AnimationPlayerState::IDLE
The player is idle and has assigned no animation instance.
jugimap::AnimationPlayerState::PAUSED
The player has been paused.
jugimap::Blend::MULTIPLY
Multiply (darken) blend.
jugimap::AnimationPlayerFlags::PLAYER_STOPPED
static const int PLAYER_STOPPED
The return flag for AnimationQueuePlayer::Stop command. If the player is already in the idle state th...
Definition: jmGlobal.h:206
jugimap::Blend::ALPHA
Alpha blend.
jugimap::ShapeKind::ELLIPSE
Ellipse - EllipseShape object.
jugimap::AnimationKind::FRAME_ANIMATION
Frame animation - FrameAnimation object.
jugimap::Settings::EnginePhysicsEnabled
bool EnginePhysicsEnabled()
Returns true if the engine physics system is enabled; otherwise returns false.
Definition: jmGlobal.h:355
jugimap::LayerKind::SPRITE
Sprite layer - SpriteLayer object.
jugimap::ShapeKind::NOT_DEFINED
The shape kind not defined.
jugimap::AnimationTrackKind
AnimationTrackKind
The kinds of animation track. Used as identifier for AnimationTrack and AnimationKey classes.
Definition: jmGlobal.h:157
jugimap::FileKind::SPRITER_FILE
Spriter file.
jugimap::Settings::SetZOrderStep
void SetZOrderStep(int _zOrderStep)
Set the z-order step. Used by engines which use a z-order factor for drawing order of sprites.
Definition: jmGlobal.h:429
jugimap::AnimationPlayerState::WAITING_TO_REPEAT
The player is waiting to repeat animation due to the repeat parameter.
jugimap::AnimationPlayerFlags::NONE
static const int NONE
None.
Definition: jmGlobal.h:195
jugimap::AnimationTrackKind::SCALING
Scaling.
jugimap::Settings::GetScreenSize
Vec2i GetScreenSize()
Returns the screen size.
Definition: jmGlobal.h:289
jugimap::Settings::SetScreenSize
void SetScreenSize(Vec2i _screenSize)
Set the screen size to the given *_screenSize*.
Definition: jmGlobal.h:281
jugimap::FileKind::SPRITE_TEXT_CONTAINER
Container of text sprite source items.
jugimap::LayerKind::DRAWING
Drawing layer - DrawingLayer object.
jugimap::Time::GetLogicTimeMS
float GetLogicTimeMS()
Returns the frame time in milliseconds.
Definition: jmGlobal.h:547
jugimap::ColorOverlayBlend::NOT_DEFINED
The blend not defined.
jugimap::GetRelativeHandleFromTextHandleVariant
Vec2f GetRelativeHandleFromTextHandleVariant(TextHandleVariant _thv)
Convert TextHandleVariant to relative handle with coordinates in range 0 - 1.0.
Definition: jmGlobal.cpp:50
jugimap::SpriteKind::NOT_DEFINED
The sprite kind not defined.
jugimap::AnimationPlayerFlags
The bit-mask flags of animation player.
Definition: jmGlobal.h:192
jugimap::FileKind
FileKind
The kinds of file.
Definition: jmGlobal.h:17
jugimap::FontKind
FontKind
The kinds of font.
Definition: jmGlobal.h:124
jugimap::AnimationPlayerFlags::META_KEY_CHANGED
static const int META_KEY_CHANGED
The return flag for AnimationQueuePlayer::Play and AnimationQueuePlayer::Update commands when the met...
Definition: jmGlobal.h:209
jugimap::FileKind::SINGLE_IMAGE
Single image file.
jugimap::AnimationTrackKind::ALPHA_CHANGE
Alpha change.
jugimap::LayerKind::NOT_DEFINED
The layer kind not defined.
jugimap::Blend::NOT_DEFINED
The blend not defined.
jugimap::Settings::GetRotationSignForYdir
int GetRotationSignForYdir()
Returns the sign of rotation. This sign depends of the direction of y coordinate.
Definition: jmGlobal.h:462
jugimap::Settings
Settings.
Definition: jmGlobal.h:265
jugimap::AnimationTrackKind::FLIP_HIDE
Flip, hide.
jugimap::Engine
Engine
Engine identification value.
Definition: jmGlobal.h:251
jugimap::Settings::SetMapZOrderStart
void SetMapZOrderStart(int _mapZOrderStart)
Set the starting map z-order. Used by engines which use a z-order factor for drawing order of sprites...
Definition: jmGlobal.h:438
jugimap::Time::GetPassedNetTimeMS
int GetPassedNetTimeMS()
Returns passed net time in milliseconds.
Definition: jmGlobal.h:528
jugimap::FileKind::TILE_SHEET_IMAGE
Tile sheet image file.
jugimap::Vec2f
Vec2< float > Vec2f
Vec2 struct in float precision.
Definition: jmCommon.h:167
jugimap::ShapeKind
ShapeKind
The kinds of geometric shape. Used as identifier for GeometricShape and VectorShape objects.
Definition: jmGlobal.h:133
jugimap::AnimationPlayerState
AnimationPlayerState
The states of animation player.
Definition: jmGlobal.h:178
jugimap::Settings::SetAppTerminated
void SetAppTerminated(bool _appTerminated)
Mark application as terminated on exit.
Definition: jmGlobal.h:453
jugimap::MapType
MapType
The types of map.
Definition: jmGlobal.h:42
jugimap::Blend::SOLID
Solid (cover) blend.
jugimap::Settings::SpriteCollidersEnabled
bool SpriteCollidersEnabled()
Returns true if the Collider objects are used for the sprites collision detection; otherwise returns ...
Definition: jmGlobal.h:334
jugimap::FileKind::SPRITE_SHEET_IMAGE
Sprite sheet image file.
jugimap::GuiWidgetKind::SLIDER
Slider - GuiSlider object.
jugimap::AnimationTrackKind::PATH_MOVEMENT
Path movement.
jugimap::AnimationPlayerFlags::SKIP_SUBPLAYER_UPDATING
static const int SKIP_SUBPLAYER_UPDATING
Not available.
Definition: jmGlobal.h:199
jugimap::AlignX::LEFT
Align left.
jugimap::Time
Time.
Definition: jmGlobal.h:492
jugimap::AnimationPlayerState::STALLED
The player is playing but animation instance is not being updated. This a case when an animation is n...
jugimap::ShapeKind::SINGLE_POINT
Single point - SinglePointShape object.
jugimap::GuiWidgetKind::BAR
Bar - GuiBar object.
jugimap::Blend
Blend
The blend modes for the openGL pixel blending.
Definition: jmGlobal.h:101
jugimap::AlignX::RIGHT
Align right.
jugimap::SpriteKind::TEXT
Text sprite - TextSprite object.
jugimap::AlignX
AlignX
The align factors for the X direction.
Definition: jmGlobal.h:84
jugimap::AnimationPlayerFlags::ANIMATION_INSTANCE_UPDATED
static const int ANIMATION_INSTANCE_UPDATED
The return flag for AnimationQueuePlayer::Play and AnimationQueuePlayer::Update commands when the ani...
Definition: jmGlobal.h:207
jugimap::LayerType
LayerType
The types of layer. Used to distinguish layers for world, parallax and screen maps.
Definition: jmGlobal.h:64
jugimap::AlignY::BOTTOM
Align bottom.
jugimap::Vec2< int >
jugimap::ColorOverlayBlend::SIMPLE_MULTIPLY
Simple multiply (not a real blending).
jugimap::Settings::SetErrorMessage
void SetErrorMessage(const std::string &_errorMessage)
Set to true to enable the lerp drawing technique; otherwsie set to false.
Definition: jmGlobal.h:419
jugimap::Time::SetLogicTimeMS
void SetLogicTimeMS(float _logicTimeStepMS)
Set the logic time step in milliseconds.
Definition: jmGlobal.h:539
jugimap::SpriteKind::SPRITER
Spriter sprite - SkeletonSprite object.
jugimap::TextHandleVariant
TextHandleVariant
Predefined handles for TextSprite objects.
Definition: jmGlobal.h:229
jugimap::LayerKind::VECTOR
Vector layer - VectorLayer object.
jugimap::AnimationTrackKind::NOT_DEFINED
Not defined.
jugimap::GuiWidgetKind
GuiWidgetKind
The kinds of widget. Used as identifier for GuiWidget objects.
Definition: jmGlobal.h:216
jugimap::AlignY
AlignY
The align factors for the Y direction.
Definition: jmGlobal.h:92
jugimap::Settings::GetMapZOrderStart
int GetMapZOrderStart()
Returns the starting map z-order.
Definition: jmGlobal.h:441
jugimap::SpriteKind::COMPOSED
Composed sprite - ComposedSprite object.
jugimap::AlignX::MIDDLE
Align to middle.
jugimap::AnimationKind
AnimationKind
The kinds of animation. Used as identifier for Animation objects.
Definition: jmGlobal.h:145
jugimap::AnimationPlayerState::WAITING_TO_START
The player is waiting to start animation due to the startDelay parameter.
jugimap::GuiWidgetKind::BUTTON
Button - GuiButton object.
jugimap::FontKind::TRUE_TYPE
True type font.
jugimap::MapType::WORLD
World map.
jugimap::GuiWidgetKind::TEXT_INPUT
Text input - GuiTextInput object.
jugimap::AnimationTrackKind::META
Meta.
jugimap::FontKind::NOT_DEFINED
The font kind not defined.
jugimap::FileKind::SPINE_FILE
Spine file.
jugimap::ColorOverlayBlend
ColorOverlayBlend
The blend modes for the shader based pixel blending which simulate photoshop blending modes.
Definition: jmGlobal.h:112
jugimap::AnimationTrackKind::TIMELINE_ANIMATION
Timeline animation.
jugimap::SpriteKind::SPINE
Spine sprite - SkeletonSprite object.
jugimap::AnimationPlayerState::PLAYING
The player is playing and updating animation instance.