prosperon/source/engine/gameobject.h

71 lines
1.6 KiB
C
Raw Permalink Normal View History

2021-11-30 21:29:18 -06:00
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
2023-05-27 07:01:17 -05:00
#include "quickjs/quickjs.h"
2023-11-03 08:31:06 -05:00
#include "HandmadeMath.h"
2023-11-30 10:47:59 -06:00
#include "transform.h"
2023-12-11 08:36:45 -06:00
#include "script.h"
2024-01-04 08:14:37 -06:00
#include "warp.h"
2023-11-30 10:47:59 -06:00
#define dag_rm(p,c) do{\
for (int i = arrlen(p->children)-1; i--; i >=0) {\
if (p->children[i] == c) { \
arrdelswap(p->children,i);\
c->parent=NULL;\
break;\
}}}while(0)
#define dag_set(p,c) do{\
arrpush(p->children,c);\
if(c->parent) dag_rm(c->parent,c);\
c->parent=p;\
}while(0)
#define dag_clip(p) do{\
if (p->parent)\
dag_rm(p->parent,p);\
}while(0)
2021-11-30 21:29:18 -06:00
2023-12-11 08:36:45 -06:00
struct gameobject {
2023-11-30 16:24:26 -06:00
cpBody *body; /* NULL if this object is dead; has 2d position and rotation, relative to global 0 */
2024-01-14 10:24:31 -06:00
float damping;
2023-11-20 07:49:14 -06:00
float timescale;
float maxvelocity;
float maxangularvelocity;
2023-05-12 13:22:05 -05:00
unsigned int layer;
2024-04-12 13:53:00 -05:00
unsigned int warp_mask;
2023-05-27 07:01:17 -05:00
JSValue ref;
2024-05-17 04:23:03 -05:00
transform *t; // the transform this body controls
2023-12-11 08:36:45 -06:00
};
2021-11-30 21:29:18 -06:00
2024-01-14 10:24:31 -06:00
/*
Friction uses coulomb model. When shapes collide, their friction is multiplied. Some example values:
Steel on steel: 0.0005
Wood on steel: 0.0012
Wood on wood: 0.0015
=> steel = 0.025
=> wood = 0.04
=> hardrubber = 0.31
=> concrete = 0.05
=> rubber = 0.5
Hardrubber on steel: 0.0077
Hardrubber on concrete: 0.015
Rubber on concrete: 0.025
*/
2023-12-11 08:36:45 -06:00
typedef struct gameobject gameobject;
2022-08-26 09:19:17 -05:00
2023-12-11 08:36:45 -06:00
gameobject *MakeGameobject();
void gameobject_apply(gameobject *go);
void gameobject_free(gameobject *go);
2024-05-12 18:36:14 -05:00
transform go2t(gameobject *go);
2023-02-17 13:15:56 -06:00
2024-05-12 18:36:14 -05:00
HMM_Vec3 go_pos(gameobject *go);
2023-11-30 10:47:59 -06:00
2024-05-17 12:39:04 -05:00
gameobject *shape2go(cpShape *s);
gameobject *body2go(cpBody *b);
2022-12-19 18:15:38 -06:00
2023-12-11 08:36:45 -06:00
void go_shape_apply(cpBody *body, cpShape *shape, gameobject *go);
2021-11-30 21:29:18 -06:00
#endif