Entropie git · main
Entropie festival game; first steps
C 88.5% Markdown 9.1% GLSL 2.3%git clone https://git.christianimmanuel.de/games/Entropie.gitwget https://git.christianimmanuel.de/games/Entropie/archive/Entropie.tar.gzentropie/src/world/hose.h raw
#ifndef WORLD_HOSE_H
#define WORLD_HOSE_H
/*
* Garden hoses as a rope: a chain of points from the tap to the nozzle that
* falls, lies on the ground, and drapes over and round whatever is in the way
* (never through it). The length is fixed; pulled straight it goes taut.
*
* Too near a burning fire it gets hot, melts (it leaks there) and burns
* through (nothing comes out at the nozzle; the water runs out at the break).
* Duct tape mends a melted spot; a burnt-through bit is cut out with the
* shears and the ends joined: the hose is that much shorter.
*/
#include "world/object.h"
#include "render/renderer.h"
#define HOSE_LENGTH 25.0f /* meters of hose from the tap */
#define HOSE_NODES 51 /* points along it (half a meter apart) */
#define HOSE_MAX 4 /* hoses simulated at once */
#define HOSE_LEAKS 0.35f /* melted this far (0..1) it leaks; 1: burned through */
typedef struct {
const Object *nozzle;
Vec3 p[HOSE_NODES], prev[HOSE_NODES];
float melt[HOSE_NODES]; /* how far each bit is melted (1: burned through, between it and the next) */
float heat[HOSE_NODES]; /* how hot it is right now (0..1): it glows */
bool taped[HOSE_NODES]; /* mended with duct tape */
float length; /* meters (shorter once a bit is cut out) */
bool ready;
} HoseRope;
struct World;
/* Lets every hose fall, settle and slide round things (real seconds). */
void Hose_update(struct World *world, float dt);
/* Draws the hose of this nozzle, piece by piece. */
void Hose_draw(struct World *world, Renderer *renderer, const Object *nozzle);
/* The hose of this nozzle (NULL if it has none). */
HoseRope *Hose_of(struct World *world, const Object *nozzle);
/* How far it reaches from the tap (meters; shorter once mended). */
float Hose_length(struct World *world, const Object *nozzle);
/* Burned through somewhere (*at: where). */
bool Hose_burnedThrough(struct World *world, const Object *nozzle, Vec3 *at);
/* Turned on for dt: how much of the water gets to the nozzle (0..1). Where it
leaks or is burned through the water runs out onto the ground. */
float Hose_flow(struct World *world, const Object *nozzle, float dt);
/* The bit of any hose along a ray (within reach): its rope and node, or NULL. */
HoseRope *Hose_aimed(struct World *world, Vec3 eye, Vec3 dir, float reach, int *node);
/* The worst spot near node k: melted (or burned through) bits around it, or -1. */
int Hose_damageNear(const HoseRope *rope, int k);
/* Duct tape round the melted bits at spot k: no more leaking there. False if
burned through (tape won't hold that) or nothing to mend. */
bool Hose_tape(HoseRope *rope, int k);
/* Cuts out the melted bits at spot k and joins the ends. Meters it got shorter (0: nothing cut). */
float Hose_cutOut(HoseRope *rope, int k);
#endif /* WORLD_HOSE_H */