yet another api rework, removal of integer types in public api, optionals at the end, some cleaning
This commit is contained in:
@ -16,7 +16,7 @@ TWN_API void audio_play(const char *path,
|
||||
float panning); /* default: 0.0f, range: -1.0 to 1.0f */
|
||||
|
||||
/* possible parameter options: "volume", "panning", "repeat" */
|
||||
TWN_API void audio_set_parameter(const char *channel, const char *parameter, float value);
|
||||
TWN_API void audio_parameter(const char *channel, const char *parameter, float value);
|
||||
|
||||
/* TODO */
|
||||
// TWN_API bool audio_ended(const char *channel);
|
||||
|
@ -25,9 +25,9 @@ typedef struct Context {
|
||||
|
||||
/* resolution is set from config and dictates both logical and drawing space, as they're related */
|
||||
/* even if scaling is done, game logic should never change over that */
|
||||
Vec2i resolution;
|
||||
Vec2i mouse_position;
|
||||
Vec2i mouse_movement;
|
||||
Vec2 resolution;
|
||||
Vec2 mouse_position;
|
||||
Vec2 mouse_movement;
|
||||
|
||||
/* is set on startup, should be used as source of randomness */
|
||||
uint64_t random_seed;
|
||||
|
@ -8,14 +8,14 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
/* pushes a sprite onto the sprite render queue */
|
||||
TWN_API void draw_sprite(char const *path,
|
||||
TWN_API void draw_sprite(char const *texture,
|
||||
Rect rect,
|
||||
Rect const *texture_region, /* optional, default: NULL */
|
||||
Color color, /* optional, default: all 255 */
|
||||
float rotation, /* optional, default: 0 */
|
||||
bool flip_x, /* optional, default: false */
|
||||
bool flip_y, /* optional, default: false */
|
||||
bool stretch); /* optional, default: false */
|
||||
bool stretch); /* optional, default: true */
|
||||
|
||||
/* pushes a filled rectangle onto the rectangle render queue */
|
||||
TWN_API void draw_rectangle(Rect rect, Color color);
|
||||
@ -27,26 +27,24 @@ TWN_API void draw_circle(Vec2 position, float radius, Color color);
|
||||
/* TODO: have font optional, with something minimal coming embedded */
|
||||
TWN_API void draw_text(char const *string,
|
||||
Vec2 position,
|
||||
int height_px, /* optional, default: 22 */
|
||||
Color color, /* optional, default: all 0 */
|
||||
char const *font);
|
||||
float height, /* optional, default: 22 */
|
||||
Color color, /* optional, default: all 0 */
|
||||
char const *font); /* optional, default: NULL */
|
||||
|
||||
|
||||
TWN_API int draw_text_width(char const *string,
|
||||
int height_px, /* TODO: make optional */
|
||||
char const *font);
|
||||
TWN_API float draw_text_width(char const *string,
|
||||
float height, /* optional, default: 22 */
|
||||
char const *font); /* optional, default: NULL */
|
||||
|
||||
TWN_API void draw_nine_slice(char const *texture_path,
|
||||
int texture_w,
|
||||
int texture_h,
|
||||
int border_thickness,
|
||||
TWN_API void draw_nine_slice(char const *texture,
|
||||
Vec2 corners,
|
||||
Rect rect,
|
||||
Color color); /* TODO: make optional */
|
||||
float border_thickness, /* optional, default: 0 */
|
||||
Color color); /* optional, default: all 255 */
|
||||
|
||||
/* pushes a textured 3d triangle onto the render queue */
|
||||
/* vertices are in absolute coordinates, relative to world origin */
|
||||
/* texture coordinates are in pixels */
|
||||
TWN_API void draw_triangle(char const *path,
|
||||
TWN_API void draw_triangle(char const *texture,
|
||||
Vec3 v0,
|
||||
Vec3 v1,
|
||||
Vec3 v2,
|
||||
@ -68,12 +66,9 @@ TWN_API void draw_triangle(char const *path,
|
||||
// Color c1,
|
||||
// Color c2);
|
||||
|
||||
// TODO:
|
||||
// http://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat2
|
||||
// void unfurl_billboard(const char *path,
|
||||
// Vec2 position,
|
||||
// Vec2 scaling,
|
||||
// Rect uvs);
|
||||
TWN_API void draw_billboard(const char *path,
|
||||
Vec3 position,
|
||||
Vec2 size);
|
||||
|
||||
/* sets a perspective 3d camera to be used for all 3d commands */
|
||||
TWN_API void draw_camera(Vec3 position, float fov, Vec3 up, Vec3 direction);
|
||||
@ -100,7 +95,7 @@ TWN_API void draw_fog(float start, float end, float density, Color color);
|
||||
#ifndef TWN_NOT_C
|
||||
|
||||
typedef struct DrawSpriteArgs {
|
||||
char const *path;
|
||||
char const *texture;
|
||||
Rect rect;
|
||||
|
||||
m_option_list(
|
||||
|
@ -3,11 +3,11 @@
|
||||
#define TWN_GAME_API_H
|
||||
|
||||
#include "twn_input.h"
|
||||
#include "twn_context.h"
|
||||
#include "twn_draw.h"
|
||||
#include "twn_audio.h"
|
||||
#include "twn_engine_api.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_context.h"
|
||||
|
||||
#ifndef TWN_NOT_C
|
||||
|
||||
|
@ -10,11 +10,11 @@
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
TWN_API void input_bind_action_control(const char *action_name, Control control);
|
||||
TWN_API bool input_is_action_pressed(const char *action_name);
|
||||
TWN_API bool input_is_action_just_pressed(const char *action_name);
|
||||
TWN_API bool input_is_action_just_released(const char *action_name);
|
||||
TWN_API Vec2 input_get_action_position(const char *action_name);
|
||||
TWN_API void input_set_mouse_captured(bool enabled);
|
||||
TWN_API void input_action(const char *name, Control control);
|
||||
TWN_API bool input_action_pressed(const char *name);
|
||||
TWN_API bool input_action_just_pressed(const char *name);
|
||||
TWN_API bool input_action_just_released(const char *name);
|
||||
TWN_API Vec2 input_action_position(const char *name);
|
||||
TWN_API void input_mouse_captured(bool enabled);
|
||||
|
||||
#endif
|
||||
|
@ -6,13 +6,6 @@
|
||||
/* plain data aggregates that are accepted between public procedure boundaries */
|
||||
|
||||
|
||||
/* a point in some space (integer) */
|
||||
typedef struct Vec2i {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
} Vec2i;
|
||||
|
||||
|
||||
/* a point in some space (floating point) */
|
||||
typedef struct Vec2 {
|
||||
float x;
|
||||
@ -48,15 +41,6 @@ typedef struct Color {
|
||||
} Color;
|
||||
|
||||
|
||||
/* a rectangle with the origin at the upper left (integer) */
|
||||
typedef struct Recti {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t w;
|
||||
int32_t h;
|
||||
} Recti;
|
||||
|
||||
|
||||
/* a rectangle with the origin at the upper left (floating point) */
|
||||
typedef struct Rect {
|
||||
float x;
|
||||
|
@ -52,19 +52,10 @@
|
||||
#endif /* TWN_NOT_C */
|
||||
|
||||
/* calculates the overlap of two rectangles */
|
||||
TWN_API Recti overlap_recti(const Recti a, const Recti b);
|
||||
TWN_API Rect overlap_rect(const Rect a, const Rect b);
|
||||
|
||||
TWN_API Rect rect_overlap(Rect a, Rect b);
|
||||
/* returns true if two rectangles are intersecting */
|
||||
TWN_API bool intersect_recti(const Recti a, const Recti b);
|
||||
TWN_API bool intersect_rect(const Rect a, const Rect b);
|
||||
|
||||
/* TODO: generics and specials (see m_vec2_from() for an example)*/
|
||||
TWN_API Recti to_recti(Rect rect);
|
||||
TWN_API Rect to_rect(Recti rect);
|
||||
|
||||
TWN_API Vec2i center_recti(Recti rect);
|
||||
TWN_API Vec2 center_rect(Rect rect);
|
||||
TWN_API bool rect_intersects(Rect a, Rect b);
|
||||
TWN_API Vec2 rect_center(Rect rect);
|
||||
|
||||
/* decrements an integer value, stopping at 0 */
|
||||
/* meant for tick-based timers in game logic */
|
||||
|
@ -9,15 +9,6 @@
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/* aren't macros to prevent double evaluation with side effects */
|
||||
/* maybe could be inlined? i hope LTO will resolve this */
|
||||
static inline Vec2 vec2_from_vec2i(Vec2i vec) {
|
||||
return (Vec2) {
|
||||
.x = (float)vec.x,
|
||||
.y = (float)vec.y,
|
||||
};
|
||||
}
|
||||
|
||||
static inline Vec3 vec3_add(Vec3 a, Vec3 b) {
|
||||
return (Vec3) { a.x + b.x, a.y + b.y, a.z + b.z };
|
||||
}
|
||||
|
Reference in New Issue
Block a user