Silkworm/src/Silkworm.h

122 lines
3.3 KiB
C

/* Silkworm - Verlet cloth physics in C
*
* Copyright (c) 2021 Evan Hemsley
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Evan "cosmonaut" Hemsley <evan@moonside.games>
*
*/
#ifndef SILKWORM_H
#define SILKWORM_H
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef _WIN32
#define SILKWORMAPI __declspec(dllexport)
#define SILKWORMCALL __cdecl
#else
#define SILKWORMAPI
#define SILKWORMCALL
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Game Maker only lets us use doubles in the API. So we do type punning to get integers. It's legal in C99! */
typedef union {
int i;
double d;
} Silkworm_ID;
typedef struct Silkworm_Vector2
{
double x;
double y;
} Silkworm_Vector2;
typedef struct Silkworm_Node
{
Silkworm_ID id;
Silkworm_Vector2 position;
Silkworm_Vector2 previousPosition;
Silkworm_Vector2 velocity;
Silkworm_Vector2 acceleration;
double mass;
double friction;
double radius;
double pinned;
double pushFactor;
bool destroyable;
} Silkworm_Node;
typedef struct Silkworm_Link
{
Silkworm_ID id;
Silkworm_Node *a;
Silkworm_Node *b;
double distance;
double tearThreshold;
} Silkworm_Link;
typedef struct Silkworm_Group
{
Silkworm_ID id;
Silkworm_Node **nodes;
uint32_t nodeCount;
Silkworm_Link **links;
uint32_t linkCount;
} Silkworm_Group;
/* Version API */
#define SILKWORM_ABI_VERSION 0
#define SILKWORM_MAJOR_VERSION 0
#define SILKWORM_MINOR_VERSION 1
#define SILKWORM_PATCH_VERSION 0
#define SILKWORM_COMPILED_VERSION ( \
(REFRESH_ABI_VERSION * 100 * 100 * 100) + \
(REFRESH_MAJOR_VERSION * 100 * 100) + \
(REFRESH_MINOR_VERSION * 100) + \
(REFRESH_PATCH_VERSION) \
)
SILKWORMAPI void Silkworm_Init();
SILKWORMAPI void Silkworm_Update();
SILKWORMAPI double Silkworm_CreateGroup();
SILKWORMAPI double Silkworm_CreateNode(double groupId, double xPosition, double yPosition, double mass, double friction, double radius, double pushFactor);
SILKWORMAPI void Silkworm_NodeSetVelocity(double groupId, double nodeId, double xVelocity, double yVelocity);
SILKWORMAPI void Silkworm_NodeSetAcceleration(double groupId, double nodeId, double xAcceleration, double yAcceleration);
SILKWORMAPI void Silkworm_NodeSetDestroyable(double groupId, double nodeId);
SILKWORMAPI void Silkworm_NodePin(double groupId, double nodeId);
SILKWORMAPI void Silkworm_NodeUnpin(double groupId, double nodeId);
SILKWORMAPI double Silkworm_CreateLink(double groupId, double aId, double bId, double distance, double tearThreshold);
#endif /* SILKWORM_H */