Advertisement
Kitomas

globals.hpp as of 2024-05-03

May 3rd, 2024
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.85 KB | None | 0 0
  1. #ifndef _GLOBALS_HPP
  2. #define _GLOBALS_HPP
  3.  
  4. #include <kit/all.hpp>
  5. #include <kit/xmp_sfx.hpp>
  6.  
  7. /* notes:
  8. always use a mutex when accessing soundengine, as it's used by >1 thread
  9. player should be able to step up on a half tile as if they were stairs
  10. scene states should be able to change tiles
  11. text boxes should appear when close to certain objects
  12. have thread that manages music and sfx
  13. add in cutscene image slideshow things
  14. be able to change scene after cutscene
  15. if ambient track fails to start, (while locked) stop a track to make space for it (use forced stop!)
  16. have player animation frame override
  17. add customizable friction coefficients for tilesets
  18. */
  19.  
  20.  
  21. #ifdef _DEBUG
  22. #include <stdio.h>
  23. #define _printf(_fmt, ...) printf(_fmt, __VA_ARGS__)
  24.  
  25. #else
  26. #define _printf(_fmt, ...)
  27.  
  28. #endif /* _DEBUG */
  29.  
  30. #define _getnumallocs _printf("line %i: %llu\n",__LINE__,memory::getNumAllocations()-2);
  31.  
  32.  
  33. #define WINDOW_TITLE "platformer prototype"
  34. #define CANVSIZ_X 768 //32 tiles wide (assuming tiles are 24x24)
  35. #define CANVSIZ_Y 432 //18 tiles tall
  36. #define TILESIZ_X 32
  37. #define TILESIZ_Y 18
  38. #define lengthof(_array, _type) (sizeof(_array)/sizeof(_type))
  39. #define memset0( _array       ) kit::memory::set((_array), 0, sizeof(_array))
  40. #define memset0s(_array, _size) kit::memory::set((_array), 0, (_size)       )
  41. #define NULLDELETE(_ptr_to_thing) { delete _ptr_to_thing;  _ptr_to_thing = nullptr; }
  42. #define PTR_OFFSET(_ptr, _offset, _type)       ( \
  43.   (_type*)( ((kit::u64)(_ptr)) + ((kit::s64)(_offset)) )   )
  44.  
  45. //#define GRAVITY (0.0175f)
  46. #define GRAVITY (0.0195f)
  47. #define PLAYER_JUMP_STRENGTH (2.0f)
  48. #define PLAYER_JUMP_CANCEL (0.33f) //multiplier of vel.y when canceling a jump while ascending
  49. #define PLAYER_SPEED (0.020f)
  50. #define PLAYER_SCALE (2.0f)
  51. #define PLAYER_HALF ( (s32)((8*PLAYER_SCALE)/2) ) //half of the character's size, in pixels
  52. #define PLAYER_NEUTRAL (0.1f) //'what +/- range should be considered neutral for vel/acc'
  53. #define PLAYER_AIR_FRICTION (0.5f) //multiplier for acc.x when in mid-air
  54. #define PLAYER_GND_FRICTION (1.0f) //multiplier of PLAYER_SPEED for on-ground deceleration
  55. #define PLAYER_RUN_MUL (0.075f) //vel.x's multiplier when adding to runningState
  56.  
  57.  
  58.  
  59.  
  60. extern char falseStr[]; // = "false"
  61. extern char trueStr[];  // = "true"
  62. #define boolStr(_bool_value) ((_bool_value) ? trueStr : falseStr )
  63.  
  64. //(gl_ as in [gl]obal, not open[gl])
  65. extern kit::TimerSimple* gl_frameTimer;
  66. extern kit::SoundEngine* gl_snd;
  67. extern kit::MutexSimple* gl_snd_lock;
  68. extern kit::Window*      gl_win;
  69. extern kit::BitmapFont*  gl_text;
  70. extern kit::FStr*        gl_fstr;
  71. #define gl_textf(_x, _y, _fmt,           ...) \
  72.     gl_text->print((_x), (_y), gl_fstr->fmt(_fmt, __VA_ARGS__), 0)
  73. #define gl_textfs(_x, _y, _fmt, _maxLen, ...) \
  74.     gl_text->print((_x), (_y), gl_fstr->fmt(_fmt, __VA_ARGS__), (_maxLen))
  75. extern kit::Bitmap* gl_spritesheetPlayer;
  76.  
  77.  
  78. struct Scene;
  79. struct SceneDescriptor;
  80. struct Object;
  81. typedef void (*Object_TickCallback)(Object* obj_a);
  82.  
  83. #define                    gl_scenes_len 1
  84. #define                    gl_backgrounds_len 1
  85. #define                    gl_tilesets_len 1
  86. #define                    gl_ambience_len 0
  87. #define                    gl_music_len 1
  88. #define                    gl_objCallbacks_len 0
  89. //+1 for the length, since the first valid id is 1, not 0
  90. extern Scene               gl_scene;
  91. extern SceneDescriptor*    gl_scenes[gl_scenes_len+1];
  92. extern kit::Bitmap*        gl_backgrounds[gl_backgrounds_len+1];
  93. extern kit::Bitmap*        gl_tileset_missing;
  94. extern kit::Bitmap*        gl_tilesets[gl_tilesets_len+1];
  95. extern kit::AudioData*     gl_ambience[gl_ambience_len+1];
  96. extern char                gl_music[gl_music_len+1][32]; //the music's file paths
  97. extern Object_TickCallback gl_objCallbacks[gl_objCallbacks_len+1];
  98.  
  99.  
  100.  
  101.  
  102.  
  103. kit::f64 frand();
  104. kit::f32 frandf();
  105.  
  106. kit::f64 frandRange(kit::f64 start, kit::f64 maxDeviation);
  107.  
  108.  
  109.  
  110.  
  111.  
  112. struct SoundEffect { //40B (not including the size of the AudioData class)
  113.   kit::AudioData* sfx = nullptr;
  114.   kit::f32       volL = 1.0f;
  115.   kit::f32       volR = 1.0f;
  116.   kit::f64  speedBase = 1.0 ;
  117.   kit::f64 speedRange = 0.0 ;
  118.   kit::f32        pan = 0.0f;
  119.   kit::u32 _padding32;
  120.  
  121.   SoundEffect(const char* filePath, kit::f32 volume = 1.0f,
  122.                                     kit::f64 _speedRange = 0.0)
  123.   {
  124.     sfx = new kit::AudioData(filePath, gl_snd);
  125.     volL = volume,  volR = volume;
  126.     speedRange = _speedRange;
  127.   }
  128.  
  129.   ~SoundEffect(){ delete sfx; }
  130.  
  131.   kit::s32 play(){
  132.     if(sfx != nullptr){
  133.       gl_snd_lock->lock(true);
  134.  
  135.       if(speedRange < 0.0) speedRange = -speedRange;
  136.       if(!speedRange) return gl_snd->sfxPlay(sfx, volL, volR, 1.0, pan);
  137.       else return gl_snd->sfxPlay(sfx, volL, volR, frandRange(speedBase,speedRange), pan);
  138.  
  139.       gl_snd_lock->lock(false);
  140.  
  141.     } else {
  142.       return -1;
  143.     }
  144.   }
  145. };
  146.  
  147.  
  148.  
  149.  
  150. #endif /* _GLOBALS_HPP */
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement