-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_main.h
These bit flags are used to indicate what platform libdarnit detected/was built for.
#define DARNIT_PLATFORM_DESKTOP 0x100000
#define DARNIT_PLATFORM_HANDHELD 0x200000
#define DARNIT_PLATFORM_LINUX 0x1
#define DARNIT_PLATFORM_WIN32 0x2
#define DARNIT_PLATFORM_PANDORA 0x4
#define DARNIT_PLATFORM_GCWZERO 0x8
#define DARNIT_PLATFORM_GPHCAANOO 0x10
#define DARNIT_PLATFORM_MACOSX 0x20
#define DARNIT_PLATFORM_FREEBSD 0x40
#define DARNIT_PLATFORM_MAEMO 0x80
#define DARNIT_PLATFORM_DBPYRA 0x100
#define DARNIT_PLATFORM_BIGENDIAN 0x80000000There's only one of the bit-flags < 0x10000 in a DARNIT_PLATFORMS field. There can be multiple ones of those with a larger value.
typedef struct {
DARNIT_PLATFORMS platform;
unsigned int screen_w;
unsigned int screen_h;
unsigned int fullscreen;
} DARNIT_PLATFORM;- platform - Is a series of flags indicating the platform the program is running on.
- screen_w - If fully initialized, this is the current screen/window width. If not fully initialized, it's the recommended screen width.
- screen_h - Same as above, but screen/window height
- fullscreen - Same as above, but wuth fullscreen. 1 if fullscreen, 0 if not.
typedef struct {
signed short x : 16;
signed short y : 16;
unsigned short w : 16;
unsigned short h : 16;
} DARNIT_VIDEOMODE;This is a direct wrapper of SDL_ListModes, with the exception that -1 is not returned if all modes are available. That's just silly. We use NULL instead.
- x - You can't do anything with it in libdarnit, ignore
- y - Same as above
- w - Screen width for the supported mode
- h - Screen height for the supported mode
- void *d_init(const char *wtitle, const char *data_dir, const char *icon);
- void *d_init_custom(const char *wtitle, int win_w, int win_h, int fullscreen, const char *data_dir, const * char *icon);
- void d_loop();
- unsigned int d_time_get();
- int d_fps();
- int d_last_frame_time();
- DARNIT_PLATFORM d_platform_get();
- void d_quit();
- void *d_init_partial(const char *data_dir);
- int d_init_rest(const char *wtitle, int win_w, int win_h, int fullscreen, const char *icon);
- DARNIT_VIDEOMODE **d_videomode_get();
- const char *d_platform_string();
void *d_init(const char *wtitle, const char *data_dir, const char *icon);
Initializes libdarnit and creates a window with values from platform defaults.
Arguments
- wtitle - A string that will be displayed as the windows title
- data_dir - The name of the directories that store data in data and write dir path. See platform defaults for more information.
- icon - Path for the window icon. Can be in any supported image format. Can be inside an LDI file, provided it's mounted. NULL means no icon.
Return value
Returns NULL on failure, anything else is success. You do not need to save this pointer, and you can't really do anything but trouble with it.
void *d_init_custom(const char *wtitle, int win_w, int win_h, int fullscreen, const char *data_dir, const char *icon);
Creates a window with all parameters specified by the program instead of with platform defaults.
Arguments
- wtitle - A string that will be displayed as the windows title
- win_w - The width of the window to create
- win_h - The height of the window to create
- fullscreen - 1 if you want it to be full screen, 0 if not
- data_dir - The name of the directories that store data in data and write dir path. See platform defaults for more information.
- icon - Path for the window icon. Can be in any supported image format. Can be inside an LDI file, provided it's mounted. NULL means no icon.
Return value
Returns NULL on failure, anything else is success. You do not need to save this pointer, and you can't really do anything but trouble with it.
void d_loop();
Flips the rendering buffer and does some various housekeeping. It also locks the framerate to 60 FPS. Must be called after you've rendered a frame.
Arguments None.
Return value None.
unsigned int d_time_get();
Just a wrapper for SDL_GetTicks. Returns the number of milliseconds since libdarnit was initialized.
Arguments None.
Return value
Returns the number of milliseconds since libdarnit was initialized.
int d_fps();
Returns the number of frames that was rendered last second (actual counted frames, updated once per second.)
Arguments None.
Return value
Returns the number of frames that was rendered last second.
int d_last_frame_time();
Returns the number of milliseconds it took to render last frame (the time between the last two calls to d_loop.)
Arguments None.
Return value
Number of milliseconds that elapsed while the last frame was rendered.
DARNIT_PLATFORM d_platform_get();
If libdarnit is only partially initialized, this function returns the detected platforms and recommended screen resolution. If libdarnit is fully initialized, it returns the detected platform and the screen resolution in use. Note: d_platform_get, as all other functions in libdarnit, can't be used before libdarnit has been at least partially initialized.
Arguments None.
Return value
Returns a DARNIT_PLATFORM struct with platfrom data as described above.
void d_quit();
Immediatly kills the application and de-initializes stuff to avoid crashing the system on platforms with buggy drivers.
Arguments None.
Return value None.
void *d_init_partial(const char *data_dir);
Initializes SDL, the filesystem wrapper and detects the platform. No rendering (not even loading textures) or sound playback can be done after this, as those subsystems aren't set up yet. The state this function leaves libdarnit in is mainly to allow for using the filesystem API to read a configfile or something before deciding what screen resolution etc. to use.
To initialize libdarnit into the full ready-to-use mode, use d_init_rest, nothing else!
Arguments
- data_dir - The name of the directories that store data in data and write dir path. See platform defaults for more information.
Return value
Returns NULL on failure, anything else is success. You do not need to save this pointer, and you can't really do anything but trouble with it.
int d_init_rest(const char *wtitle, int win_w, int win_h, int fullscreen, const char *icon);
Creates a window and initializes the sound and graphics subsystem.
Arguments
- wtitle - A string that will be displayed as the windows title
- win_w - The width of the window to create
- win_h - The height of the window to create
- fullscreen - 1 if you want it to be full screen, 0 if not
- icon - Path for the window icon. Can be in any supported image format. Can be inside an LDI file, provided it's mounted. NULL means no icon.
Return value
Returns -1 on failure, 0 on success.
DARNIT_VIDEOMODE **d_videomode_get();
Returns a list of supported video modes. The list is terminated with a NULL-pointer. Do not free any of the pointers, they are managed by SDL.
Arguments None.
Return value
Returns a NULL-terminated list of DARNIT_VIDEOMODE structs with all supported video modes.
const char *d_platform_string();
Returns a string describing the platform libdarnit was compiled for (for example, linux-amd64, windows-i386..)
Arguments None.
Return value
A constant string describing the platform libdarnit was compiled for.