#ifndef TWN_UTIL_H #define TWN_UTIL_H #include "twn_types.h" #include "twn_api.h" #include #include #include /* here as it's not part of standard C */ #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 /**< pi */ #endif /* read data from virtual filesystem, with assumption that you know what that underlying data is */ /* this routine supports commands, which define operations performed on filepaths */ /* empty result is returned when something goes wrong or file doesn't exist, with an error logged */ /* defined commands: */ /* -- reads utf8 encoded file to null terminated string */ /* -- reads arbitrary binary file, resulted encoding depends on environment (could be base64, for example) */ /* -- returns "yes" or "no" ascii string */ /* -- returns newline separated utf8 list of image files in given path */ TWN_API String file_read(char const *file, const char *operation); /* commit write to a file, which meaning depends on interpretation */ /* file_read should not be affected for current frame by this, operation is pending */ /* defined commands: */ /* -- save utf8 file */ /* -- save binary file */ /* -- write image data to a PNG file, potentially updating running textures used */ /* -- format is: [width:2b][height:2][alpha:1][data:(3+alpha)*width*height] */ TWN_API void file_write(char const *file, const char *operation, String string); /* TODO: move to external templated lib */ /* calculates the overlap of two rectangles */ TWN_API Rect rect_overlap(Rect a, Rect b); /* returns true if two rectangles are intersecting */ TWN_API bool rect_intersects(Rect a, Rect b); /* TODO: move to external templated lib */ /* decrements a floating point second-based timer, stopping at 0.0f */ /* meant for poll based real time logic in game logic */ /* note that it should be decremented only on the next tick after its creation */ TWN_API float timer_tick_seconds(float seconds_left); typedef struct TimerElapseSecondsResult { float seconds_left; float interval; bool elapsed; } TimerElapseSecondsResult; TWN_API TimerElapseSecondsResult timer_elapse_seconds(float seconds_left, float interval); TWN_API void log_string(char const *value, char const *identity); TWN_API void log_float(float value, char const *identity); TWN_API void log_vec2(Vec2 value, char const *identity); TWN_API void log_vec3(Vec3 value, char const *identity); TWN_API void log_rect(Rect value, char const *identity); /* IDEA: NES debugger style frame slices that show for how long and when certain profile range takes place */ TWN_API void profile_start(char const *profile); TWN_API void profile_end(char const *profile); #endif