#ifndef STATE_H #define STATE_H #include "twn_game_api.h" #define POINTS_PER_METER 128 #define UNDO_STACK_SIZE 32 #define CAMERA_FOV ((float)M_PI_2 * 0.75f) #define POINT_LIMIT 65534 #define FACE_LIMIT 2048 #define OBJECT_LIMIT 16 #define TEXTURE_LIMIT 32 #define INVALID_POINT (POINT_LIMIT+1) #define INVALID_FACE (FACE_LIMIT+1) #define INVALID_OBJECT (OBJECT_LIMIT+1) #define INVALID_TEXTURE (TEXTURE_LIMIT+1) #define CAMERA_ROTATION_SPEED 0.04f #define CAMERA_TRANSLATION_SPEED 0.04f #define SELECTION_SPHERE_RADIUS 32 /* should be an odd number */ #define SNAP_LINES_SHOW 7 #define SNAP_LINES_WIDTH 1.0f #define SNAP_LINES_COLOR ((Color){200,200,200,150}) typedef struct Operation { enum { OPERATION_MOVE_POINT, OPERATION_SET_TEXTURE, OPERATION_TRIANGULATE, } kind; union { struct { uint16_t point; int16_t delta_x; int16_t delta_y; int16_t delta_z; uint8_t object; } move_point; struct { uint16_t face; int16_t delta_texture; uint8_t object; } set_texture; struct { uint16_t old_face; uint16_t new_face; uint8_t object; } triangulate; } data; bool chained; } Operation; typedef struct Point { int16_t x, y, z; } Point; /* TODO: store topology in terms on edge connections? might be bad, as it's stateful */ /* triangles have p3 = INVALID_POINT */ /* lines have p2, p3 = INVALID_POINT */ /* billboards have p1, p2, p3 = INVALID_POINT */ typedef struct Face { uint16_t p[4]; /* texture origin, as point on face plane, in absolute coordinates */ int16_t tex_x, tex_y; uint8_t texture; uint8_t tex_scale; } Face; typedef struct Object { char *name; bool is_invisible; Point position; char *textures[TEXTURE_LIMIT + 1]; uint8_t textures_sz; Point rotation; Face faces[FACE_LIMIT]; uint16_t faces_sz; } Object; typedef struct State { Operation op_stack[UNDO_STACK_SIZE]; uint32_t op_stack_ptr; bool op_active; Vec3 active_center; Vec3 camera_position; Vec3 camera_direction; float camera_zoom; bool camera_is_orthographic; /* defaults to wireframe */ bool solid_display_mode; /* positions skipped */ uint8_t grid_snap_granularity; Point points[POINT_LIMIT]; uint16_t points_sz; Object objects[OBJECT_LIMIT]; uint8_t objects_sz; /* which axes are blocked and which are not */ /* order: x, y, z */ bool axis_mask[3]; char *current_texture; uint8_t current_hovered_obj; uint16_t current_hovered_face; } State; #endif