Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 KB | None | 0 0
  1. #if !defined(HANDMADE_H)
  2.  
  3. /*
  4.     HANDMADE_INTERNAL:
  5.     0 - Build for public release
  6.     1 - Developer only build
  7.    
  8.     HANDMADE_SLOW
  9.     0 - No slow code
  10.     1 - Slow code allowed
  11. */
  12.  
  13. #include <math.h>
  14. #include <stdint.h>
  15. #define PI32 3.14159265359f
  16.  
  17. #if HANDMADE_INTERNAL
  18. struct debug_read_file_result
  19. {
  20.     uint32_t contentSize;
  21.     void * contents;
  22. };
  23.  
  24. #define DEBUG_PLATFORM_READ_ENTIRE_FILE(name) debug_read_file_result name(char *fileName)
  25. typedef DEBUG_PLATFORM_READ_ENTIRE_FILE(debug_platform_read_entire_file);
  26.  
  27. #define DEBUG_PLATFORM_WRITE_ENTIRE_FILE(name) int name(char *fileName, void *memory, uint32_t memorySize)
  28. typedef DEBUG_PLATFORM_WRITE_ENTIRE_FILE(debug_platform_write_entire_file);
  29.  
  30. #define DEBUG_PLATFORM_FREE_FILE_MEMORY(name) void name(void *memory)
  31. typedef DEBUG_PLATFORM_FREE_FILE_MEMORY(debug_platform_free_file_memory);
  32.  
  33. #endif
  34.  
  35. #if HANDMADE_SLOW
  36. #define Assert(Expression) if(!(Expression)){*(int *)0 = 0;}
  37. #else
  38. #define Assert(Expression)
  39. #endif 
  40.  
  41. #define kiloBytes(num) ((num) * 1024LL)
  42. #define megaBytes(num) ((kiloBytes(num)) * 1024LL)
  43. #define gigaBytes(num) ((megaBytes(num)) * 1024LL)
  44. #define teraBytes(num) ((gigaBytes(num)) * 1024LL)
  45.  
  46. #define arrayCount(array) (sizeof(array) / sizeof((array)[0]))
  47.  
  48. inline uint32_t safeTruncateUint64(uint64_t value)
  49. {
  50.     Assert(value <= 0xFFFFFFFF);
  51.     return (uint32_t)value;
  52. }
  53.  
  54. struct game_offscreen_buffer
  55. {
  56.   void *memory;
  57.   int width;
  58.   int height;
  59.   int pitch;
  60.   int bytesPerPixel;
  61. };
  62.  
  63. struct game_sound_output_buffer
  64. {
  65.     int sampleCount;
  66.     int samplesPerSecond;
  67.     int16_t *samples;
  68. };
  69.  
  70. struct game_button_state
  71. {
  72.     int halfTransitionCount;
  73.     int endedDown;
  74. };
  75.  
  76. struct game_controller_input
  77. {
  78.     int isAnalog;
  79.     int isConnected;
  80.    
  81.     float stickAverageX;
  82.     float stickAverageY;
  83.    
  84.     union
  85.     {
  86.         game_button_state buttons[12];
  87.         struct{
  88.             game_button_state moveUp;
  89.             game_button_state moveDown;
  90.             game_button_state moveLeft;
  91.             game_button_state moveRight;
  92.            
  93.             game_button_state actionUp;
  94.             game_button_state actionDown;
  95.             game_button_state actionLeft;
  96.             game_button_state actionRight;
  97.            
  98.             game_button_state leftShoulder;
  99.             game_button_state rightShoulder;
  100.            
  101.             game_button_state back;
  102.             game_button_state start;
  103.         };
  104.     };
  105. };
  106.  
  107. struct game_input
  108. {
  109.     //float gameClock;
  110.     game_controller_input controllers[5];
  111. };
  112. inline game_controller_input *getController(game_input *input, int controllerIndex)
  113. {
  114.     Assert(controllerIndex < arrayCount(input->controllers));
  115.     game_controller_input *controller = &input->controllers[controllerIndex];
  116.     return controller;
  117. }
  118.  
  119. struct game_memory
  120. {
  121.     int isInitialized;
  122.     long long permanantStorageSize;
  123.     void *permanantStorage; //Required to be initialized to 0
  124.     long long transientStorageSize;
  125.     void* transientStorage; //Required to be initialized to 0
  126.    
  127.     debug_platform_read_entire_file *DEBUGPlatformReadEntireFile;
  128.     debug_platform_write_entire_file *DEBUGPlatformWriteEntireFile;
  129.     debug_platform_free_file_memory *DEBUGPlatformFreeFileMemory;
  130. };
  131.  
  132.  
  133. #define GAME_UPDATE_AND_RENDER(name) void name(game_memory *gameMemory, game_offscreen_buffer *buffer, game_input *input)
  134. typedef GAME_UPDATE_AND_RENDER(game_update_and_render);
  135. GAME_UPDATE_AND_RENDER(gameUpdateAndRenderStub)
  136. {
  137. }
  138. // Need timer, controler/keyboard input, bitmap buffer to use, sound buffer to use
  139. extern "C" void gameUpdateAndRender(game_memory *gameMemory, game_offscreen_buffer *buffer, game_input *input);
  140.  
  141. #define GAME_GET_SOUND_SAMPLES(name) void name(game_memory *gameMemory, game_sound_output_buffer *soundBuffer)
  142. typedef GAME_GET_SOUND_SAMPLES(game_get_sound_samples);
  143. GAME_GET_SOUND_SAMPLES(gameGetSoundSamplesStub)
  144. {
  145. }
  146. //Note: At the moment. this has to be a very fast function. It cannot take longer than 1 MS or so.
  147. extern "C" void gameGetSoundSamples(game_memory *gameMemory, game_sound_output_buffer *soundBuffer);
  148.  
  149. /////
  150.  
  151. struct game_state
  152. {
  153.     int toneHz;
  154.     int greenOffset;
  155.     int blueOffset;
  156.    
  157.     float tSine;
  158.    
  159.     int playerX;
  160.     int playerY;
  161.     float tJump;
  162. };
  163.  
  164.  
  165.  
  166.  
  167. #define HANDMADE_H
  168. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement