cccp.h
IntroductionCCCP - The C Create Coding Project DiscussionThis header defines the core data structures and function prototypes for the CCCP project.
Functions
CCCP_ApplyShaderApplies a shader to a surface. bool CCCP_ApplyShader( CCCP_Surface surface, CCCP_Shader *shader, void *userdata); ParametersReturn Valuetrue if the shader was applied successfully, false otherwise. CCCP_BlitSurfaceBlits one surface onto another at the specified position. void CCCP_BlitSurface( CCCP_Surface dest, CCCP_Surface src, int x, int y); ParametersCCCP_BlitSurfaceRectBlits a rectangular region from one surface to another. void CCCP_BlitSurfaceRect( CCCP_Surface dest, CCCP_Surface src, int srcX, int srcY, int srcW, int srcH, int destX, int destY); ParametersCCCP_ClearSurfaceClears the surface with the specified color. void CCCP_ClearSurface( CCCP_Surface surface, color_t clearColor); ParametersCCCP_ClipSurfaceClips a surface to a rectangular region. CCCP_Surface CCCP_ClipSurface( CCCP_Surface surface, int x, int y, int w, int h); ParametersReturn ValueA new clipped surface. CCCP_CopySurfaceCreates a copy of an existing surface. CCCP_Surface CCCP_CopySurface( CCCP_Surface surface); ParametersReturn ValueA new CCCP_Surface that is a copy of the input. CCCP_DebugPrintASCIIPrints ASCII text to a surface for debugging. void CCCP_DebugPrintASCII( CCCP_Surface surface, int x, int y, const char *text, color_t color); ParametersCCCP_DebugPrintUnicodePrints Unicode text to a surface for debugging. void CCCP_DebugPrintUnicode( CCCP_Surface surface, int x, int y, const wchar_t *text, color_t color); ParametersCCCP_DestroyFontDestroys a font. void CCCP_DestroyFont( CCCP_Font *font); ParametersCCCP_DestroyHashTableDestroys a hash table. void CCCP_DestroyHashTable( CCCP_HashTable *table); ParametersCCCP_DestroyMusicDestroys music. bool CCCP_DestroyMusic( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the music was destroyed successfully, false otherwise. CCCP_DestroyShaderDestroys a shader. void CCCP_DestroyShader( CCCP_Shader *shader); ParametersCCCP_DestroySoundDestroys a sound. bool CCCP_DestroySound( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the sound was destroyed successfully, false otherwise. CCCP_DestroySurfaceDestroys a surface and frees its memory. void CCCP_DestroySurface( CCCP_Surface surface); ParametersCCCP_DestroyTimerDestroys a timer. void CCCP_DestroyTimer( CCCP_Timer *timer); ParametersCCCP_DestroyWaveDestroys a wave. bool CCCP_DestroyWave( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the wave was destroyed successfully, false otherwise. CCCP_DrawCircleDraws a circle. void CCCP_DrawCircle( CCCP_Surface surface, int x, int y, int radius, color_t color, bool filled); ParametersCCCP_DrawLineDraws a line between two points. void CCCP_DrawLine( CCCP_Surface surface, int x1, int y1, int x2, int y2, color_t color); ParametersCCCP_DrawRectDraws a rectangle. void CCCP_DrawRect( CCCP_Surface surface, int x, int y, int w, int h, color_t color, bool filled); ParametersCCCP_DrawTextDraws text to a surface using a font. void CCCP_DrawText( CCCP_Surface surface, CCCP_Font *font, int x, int y, const char *text, color_t color, float size); ParametersCCCP_DrawTriangleDraws a triangle. void CCCP_DrawTriangle( CCCP_Surface surface, int x1, int y1, int x2, int y2, int x3, int y3, color_t color, bool filled); Parameters
CCCP_FlipSurfaceFlips a surface horizontally and/or vertically. CCCP_Surface CCCP_FlipSurface( CCCP_Surface surface, bool horizontal, bool vertical); ParametersReturn ValueA new flipped surface. CCCP_GetElapsedTimeGets the elapsed time of a timer. double CCCP_GetElapsedTime( CCCP_Timer *timer); ParametersReturn ValueThe elapsed time in seconds. CCCP_GetMasterVolumeGets the current master volume. float CCCP_GetMasterVolume( CCCP_AudioContext *ctx); ParametersReturn ValueThe current master volume (0.0 to 1.0). CCCP_GetMusicTimeLengthGets the total length of the music. float CCCP_GetMusicTimeLength( CCCP_AudioContext *ctx, const char *key); ParametersReturn ValueThe total length in seconds. CCCP_GetMusicTimePlayedGets the current playback position of the music. float CCCP_GetMusicTimePlayed( CCCP_AudioContext *ctx, const char *key); ParametersReturn ValueThe current position in seconds. CCCP_GetMusicVolumeGets the volume of music. float CCCP_GetMusicVolume( CCCP_AudioContext *ctx, const char *key); ParametersReturn ValueThe current volume level (0.0 to 1.0). CCCP_GetPixelGets the color of a pixel at the specified coordinates. color_t CCCP_GetPixel( CCCP_Surface surface, int x, int y); ParametersReturn ValueThe color of the pixel. CCCP_GetSoundVolumeGets the volume of a sound. float CCCP_GetSoundVolume( CCCP_AudioContext *ctx, const char *key); ParametersReturn ValueThe current volume level (0.0 to 1.0). CCCP_HashTableClearClears all entries from the hash table. void CCCP_HashTableClear( CCCP_HashTable *table); ParametersCCCP_HashTableGetGets a value from the hash table. void* CCCP_HashTableGet( CCCP_HashTable *table, const char *key); ParametersReturn ValueThe value pointer, or NULL if not found. CCCP_HashTableInsertInserts a key-value pair into the hash table. int CCCP_HashTableInsert( CCCP_HashTable *table, const char *key, void *value); ParametersReturn Value0 on success, non-zero on failure. CCCP_HashTableRemoveRemoves a key-value pair from the hash table. int CCCP_HashTableRemove( CCCP_HashTable *table, const char *key); ParametersReturn Value0 on success, non-zero on failure. CCCP_HashTableSizeGets the number of entries in the hash table. size_t CCCP_HashTableSize( CCCP_HashTable *table); ParametersReturn ValueThe number of entries. CCCP_IsMusicLoopingChecks if music is set to loop. bool CCCP_IsMusicLooping( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if looping is enabled, false otherwise. CCCP_IsMusicPlayingChecks if music is currently playing. bool CCCP_IsMusicPlaying( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the music is playing, false otherwise. CCCP_IsMusicReadyChecks if music is ready to use. bool CCCP_IsMusicReady( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the music is ready, false otherwise. CCCP_IsSoundPlayingChecks if a sound is currently playing. bool CCCP_IsSoundPlaying( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the sound is playing, false otherwise. CCCP_IsSoundReadyChecks if a sound is ready to use. bool CCCP_IsSoundReady( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the sound is ready, false otherwise. CCCP_IsWaveReadyChecks if a wave is ready to use. bool CCCP_IsWaveReady( CCCP_AudioContext *ctx, const char *key); ParametersReturn Valuetrue if the wave is ready, false otherwise. CCCP_LoadFontLoads a font from a file. CCCP_Font* CCCP_LoadFont( const char *filename); ParametersReturn ValueA new CCCP_Font, or NULL on failure. CCCP_NewHashTableCreates a new hash table. CCCP_HashTable* CCCP_NewHashTable( size_t capacity); ParametersReturn ValueA new CCCP_HashTable. CCCP_NewMusicFromFileCreates new music from a file. bool CCCP_NewMusicFromFile( CCCP_AudioContext *ctx, const char *key, const char *filename); ParametersReturn Valuetrue if the music was created successfully, false otherwise. CCCP_NewMusicFromMemoryCreates new music from data in memory. bool CCCP_NewMusicFromMemory( CCCP_AudioContext *ctx, const char *key, const void *data, int dataSize); ParametersReturn Valuetrue if the music was created successfully, false otherwise. CCCP_NewShaderCreates a new shader. CCCP_Shader CCCP_NewShader( CCCP_ShaderFunc func, int numThreads); ParametersReturn ValueA new CCCP_Shader. CCCP_NewSoundFromFileCreates a new sound from a file. bool CCCP_NewSoundFromFile( CCCP_AudioContext *ctx, const char *key, const char *filename); ParametersReturn Valuetrue if the sound was created successfully, false otherwise. CCCP_NewSoundFromWaveCreates a new sound from an existing wave. bool CCCP_NewSoundFromWave( CCCP_AudioContext *ctx, const char *key, const char *waveKey); ParametersReturn Valuetrue if the sound was created successfully, false otherwise. CCCP_NewSurfaceCreates a new surface with the specified dimensions and clear color. CCCP_Surface CCCP_NewSurface( unsigned int w, unsigned int h, color_t clearColor); ParametersReturn ValueA new CCCP_Surface. CCCP_NewTimerCreates a new timer. CCCP_Timer* CCCP_NewTimer( void); Return ValueA new CCCP_Timer. CCCP_NewWaveFromFileCreates a new wave from a file. bool CCCP_NewWaveFromFile( CCCP_AudioContext *ctx, const char *key, const char *filename); ParametersReturn Valuetrue if the wave was created successfully, false otherwise. CCCP_NewWaveFromMemoryCreates a new wave from data in memory. bool CCCP_NewWaveFromMemory( CCCP_AudioContext *ctx, const char *key, const void *data, int dataSize); ParametersReturn Valuetrue if the wave was created successfully, false otherwise. CCCP_PauseMusicPauses music. void CCCP_PauseMusic( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_PauseSoundPauses a sound. void CCCP_PauseSound( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_PauseTimerPauses a timer. void CCCP_PauseTimer( CCCP_Timer *timer); ParametersCCCP_PlayMusicPlays music. void CCCP_PlayMusic( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_PlaySoundPlays a sound. void CCCP_PlaySound( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_ResizeSurfaceResizes a surface to new dimensions. CCCP_Surface CCCP_ResizeSurface( CCCP_Surface surface, unsigned int w, unsigned int h); ParametersReturn ValueA new resized surface. CCCP_ResumeMusicResumes paused music. void CCCP_ResumeMusic( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_ResumeSoundResumes a paused sound. void CCCP_ResumeSound( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_ResumeTimerResumes a paused timer. void CCCP_ResumeTimer( CCCP_Timer *timer); ParametersCCCP_RotateSurfaceRotates a surface by the specified angle. CCCP_Surface CCCP_RotateSurface( CCCP_Surface surface, float angle); ParametersReturn ValueA new rotated surface. CCCP_SeekMusicSeeks to a position in the music. void CCCP_SeekMusic( CCCP_AudioContext *ctx, const char *key, float position); ParametersCCCP_SetMasterVolumeSets the master volume for all audio. void CCCP_SetMasterVolume( CCCP_AudioContext *ctx, float volume); ParametersCCCP_SetMusicLoopingSets whether music should loop. void CCCP_SetMusicLooping( CCCP_AudioContext *ctx, const char *key, bool looping); ParametersCCCP_SetMusicVolumeSets the volume of music. void CCCP_SetMusicVolume( CCCP_AudioContext *ctx, const char *key, float volume); ParametersCCCP_SetPixelSets the color of a pixel at the specified coordinates. bool CCCP_SetPixel( CCCP_Surface surface, int x, int y, color_t color); ParametersReturn Valuetrue if the pixel was set successfully, false otherwise. CCCP_SetSoundVolumeSets the volume of a sound. void CCCP_SetSoundVolume( CCCP_AudioContext *ctx, const char *key, float volume); ParametersCCCP_SleepSleeps for the specified number of seconds. void CCCP_Sleep( double seconds); ParametersCCCP_StartTimerStarts a timer. void CCCP_StartTimer( CCCP_Timer *timer); ParametersCCCP_StopMusicStops music. void CCCP_StopMusic( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_StopSoundStops a sound. void CCCP_StopSound( CCCP_AudioContext *ctx, const char *key); ParametersCCCP_StopTimerStops a timer. void CCCP_StopTimer( CCCP_Timer *timer); ParametersCCCP_SurfaceFromCheckerboardCreates a surface with a checkerboard pattern. CCCP_Surface CCCP_SurfaceFromCheckerboard( unsigned int width, unsigned int height, color_t color1, color_t color2, unsigned int squareSize); ParametersReturn ValueA new surface with checkerboard pattern. CCCP_SurfaceFromConcentricCirclesCreates a surface with concentric circles. CCCP_Surface CCCP_SurfaceFromConcentricCircles( unsigned int width, unsigned int height, color_t centerColor, color_t edgeColor, unsigned int numRings); ParametersReturn ValueA new surface with concentric circles. CCCP_SurfaceFromDiagonalGradientCreates a surface with a diagonal gradient. CCCP_Surface CCCP_SurfaceFromDiagonalGradient( unsigned int width, unsigned int height, color_t startColor, color_t endColor); ParametersReturn ValueA new surface with diagonal gradient. CCCP_SurfaceFromFBMNoiseCreates a surface filled with Fractional Brownian Motion noise. CCCP_Surface CCCP_SurfaceFromFBMNoise( unsigned int width, unsigned int height, float scale, float offsetX, float offsetY, float lacunarity, float gain, int octaves); ParametersReturn ValueA new surface with FBM noise. CCCP_SurfaceFromFileLoads a surface from an image file. CCCP_Surface CCCP_SurfaceFromFile( const char *filename); ParametersReturn ValueA new CCCP_Surface, or NULL on failure. CCCP_SurfaceFromHorizontalGradientCreates a surface with a horizontal gradient. CCCP_Surface CCCP_SurfaceFromHorizontalGradient( unsigned int width, unsigned int height, color_t startColor, color_t endColor); ParametersReturn ValueA new surface with horizontal gradient. CCCP_SurfaceFromHorizontalStripesCreates a surface with horizontal stripes. CCCP_Surface CCCP_SurfaceFromHorizontalStripes( unsigned int width, unsigned int height, color_t color1, color_t color2, unsigned int stripeWidth); ParametersReturn ValueA new surface with horizontal stripes. CCCP_SurfaceFromMemoryCreates a surface from raw pixel data in memory. CCCP_Surface CCCP_SurfaceFromMemory( const void *data, int width, int height, bitmap_format_t format); ParametersReturn ValueA new CCCP_Surface. CCCP_SurfaceFromPerlinNoiseCreates a surface filled with Perlin noise. CCCP_Surface CCCP_SurfaceFromPerlinNoise( unsigned int width, unsigned int height, float scale, float offsetX, float offsetY); ParametersReturn ValueA new surface with Perlin noise. CCCP_SurfaceFromRadialGradientCreates a surface with a radial gradient. CCCP_Surface CCCP_SurfaceFromRadialGradient( unsigned int width, unsigned int height, color_t centerColor, color_t edgeColor); ParametersReturn ValueA new surface with radial gradient. CCCP_SurfaceFromSimplexNoiseCreates a surface filled with Simplex noise. CCCP_Surface CCCP_SurfaceFromSimplexNoise( unsigned int width, unsigned int height, float scale, float offsetX, float offsetY); ParametersReturn ValueA new surface with Simplex noise. CCCP_SurfaceFromValueNoiseCreates a surface filled with value noise. CCCP_Surface CCCP_SurfaceFromValueNoise( unsigned int width, unsigned int height, float scale, float offsetX, float offsetY); ParametersReturn ValueA new surface with value noise. CCCP_SurfaceFromVerticalGradientCreates a surface with a vertical gradient. CCCP_Surface CCCP_SurfaceFromVerticalGradient( unsigned int width, unsigned int height, color_t startColor, color_t endColor); ParametersReturn ValueA new surface with vertical gradient. CCCP_SurfaceFromVerticalStripesCreates a surface with vertical stripes. CCCP_Surface CCCP_SurfaceFromVerticalStripes( unsigned int width, unsigned int height, color_t color1, color_t color2, unsigned int stripeWidth); ParametersReturn ValueA new surface with vertical stripes. CCCP_SurfaceFromWhiteNoiseCreates a surface filled with white noise. CCCP_Surface CCCP_SurfaceFromWhiteNoise( unsigned int width, unsigned int height, float scale, float offsetX, float offsetY); ParametersReturn ValueA new surface with white noise. CCCP_SurfaceFromWorleyNoiseCreates a surface filled with Worley noise. CCCP_Surface CCCP_SurfaceFromWorleyNoise( unsigned int width, unsigned int height, float scale, float offsetX, float offsetY); ParametersReturn ValueA new surface with Worley noise. CCCP_SurfaceHeightGets the height of a surface. int CCCP_SurfaceHeight( CCCP_Surface surface); ParametersReturn ValueThe height of the surface. CCCP_SurfaceWidthGets the width of a surface. int CCCP_SurfaceWidth( CCCP_Surface surface); ParametersReturn ValueThe width of the surface. CCCP_UnloadAllMusicUnloads all music from the audio context. void CCCP_UnloadAllMusic( CCCP_AudioContext *ctx); ParametersCCCP_UnloadAllSoundsUnloads all sounds from the audio context. void CCCP_UnloadAllSounds( CCCP_AudioContext *ctx); ParametersCCCP_UnloadAllWavesUnloads all waves from the audio context. void CCCP_UnloadAllWaves( CCCP_AudioContext *ctx); ParametersCCCP_UpdateMusicUpdates music data. void CCCP_UpdateMusic( CCCP_AudioContext *ctx, const char *key, const void *data, int sampleCount); ParametersCCCP_UpdateSoundUpdates sound data. void CCCP_UpdateSound( CCCP_AudioContext *ctx, const char *key, const void *data, int frameCount); ParametersTypedefs
CCCP_AudioContextContext for managing audio resources. typedef struct CCCP_AudioContext { float volume; CCCP_HashTable *waves; CCCP_HashTable *sounds; CCCP_HashTable *music; } CCCP_AudioContext; FieldsCCCP_EventRepresents an input event in the application. typedef struct { struct { int button; int down; struct { unsigned int x, y; float dx, dy; } position; struct { float dx, dy; } wheel; } mouse; struct { CCCP_Key key; int down; } keyboard; CCCP_ModifierKey modifier; struct { int focused, closed; struct { unsigned int width, height; } size; } window; CCCP_EventType type; } CCCP_Event; Fields
CCCP_EventTypeTypes of events that can occur in the application. typedef enum { #define X(NAME, ARGS) NAME##Event, CCCP_CALLBACKS #undef X } CCCP_EventType; Constants
CCCP_FontOpaque type representing a font. typedef struct CCCP_Font CCCP_Font; CCCP_HashEntryRepresents an entry in a hash table. typedef struct CCCP_HashEntry { const char *key; void *value; struct CCCP_HashEntry *next; } CCCP_HashEntry; FieldsCCCP_HashTableRepresents a hash table data structure. typedef struct { CCCP_HashEntry **buckets; size_t capacity; size_t size; void(*free_callback)( void*); } CCCP_HashTable; FieldsCCCP_KeyKey codes for keyboard input. typedef enum { KEY_PAD0=128, KEY_PAD1, KEY_PAD2, KEY_PAD3, KEY_PAD4, KEY_PAD5, KEY_PAD6, KEY_PAD7, KEY_PAD8, KEY_PAD9, KEY_PADMUL, KEY_PADADD, KEY_PADENTER, KEY_PADSUB, KEY_PADDOT, KEY_PADDIV, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_BACKSPACE, KEY_TAB, KEY_RETURN, KEY_SHIFT, KEY_CONTROL, KEY_ALT, KEY_PAUSE, KEY_CAPSLOCK, KEY_ESCAPE, KEY_SPACE, KEY_PAGEUP, KEY_PAGEDN, KEY_END, KEY_HOME, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_INSERT, KEY_DELETE, KEY_LWIN, KEY_RWIN, KEY_NUMLOCK, KEY_SCROLL, KEY_LSHIFT, KEY_RSHIFT, KEY_LCONTROL, KEY_RCONTROL, KEY_LALT, KEY_RALT, KEY_SEMICOLON, KEY_EQUALS, KEY_COMMA, KEY_MINUS, KEY_DOT, KEY_SLASH, KEY_BACKTICK, KEY_LSQUARE, KEY_BACKSLASH, KEY_RSQUARE, KEY_TICK } CCCP_Key; Constants
CCCP_ModifierKeyModifier key flags for keyboard input. typedef enum { KEY_MOD_SHIFT = 1 << 0, KEY_MOD_CONTROL = 1 << 1, KEY_MOD_ALT = 1 << 2, KEY_MOD_SUPER = 1 << 3, KEY_MOD_CAPS_LOCK = 1 << 4, KEY_MOD_NUM_LOCK = 1 << 5 } CCCP_ModifierKey; Constants
CCCP_SceneConfiguration structure for a scene in the application. typedef struct { int windowWidth; int windowHeight; const char *windowTitle; color_t clearColor; int targetFPS; CCCP_State *(*init)( CCCP_Surface, CCCP_AudioContext*); void(*deinit)( CCCP_State*, CCCP_AudioContext*); void(*reload)( CCCP_State*, CCCP_AudioContext*); void(*unload)( CCCP_State*, CCCP_AudioContext*); int(*event)( CCCP_State*, CCCP_Event*, CCCP_AudioContext*); int(*tick)( CCCP_State*, CCCP_Surface, CCCP_AudioContext*, double); } CCCP_Scene; Fields
CCCP_ShaderRepresents a shader for surface processing. typedef struct { CCCP_ShaderFunc func; int thread_count; // 0 = use hardware concurrency } CCCP_Shader; FieldsCCCP_ShaderFuncFunction pointer type for shader functions. typedef vec4( *CCCP_ShaderFunc)( vec2, vec2, float, void *); ParametersReturn ValueColor value (vec4). CCCP_StateOpaque type representing the application state. typedef struct CCCP_State CCCP_State; CCCP_TimerOpaque type representing a timer. typedef struct CCCP_Timer CCCP_Timer; CCCP_WindowFlagsFlags for configuring window properties. typedef enum { WINDOW_RESIZABLE = 1 << 0, WINDOW_FULLSCREEN = 1 << 1, WINDOW_FULLSCREEN_DESKTOP = 1 << 2, WINDOW_BORDERLESS = 1 << 3, WINDOW_ALWAYS_ON_TOP = 1 << 4 } CCCP_WindowFlags; Constants
|