proclib/ktkStructure.h

105 lines
4.3 KiB
C

#ifndef KTK_STRUCTURE_H
#define KTK_STRUCTURE_H
#include <stddef.h> // size_t
extern unsigned long ktk_RANDOM_SEED;
unsigned long ktk_randomizeSeed();
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktk_getRandom
This function returns a random number (based on ktk_RANDOM_SEED) from min to max (including max).
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` */
int ktk_getRandom(int min, int max);
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktkNumber
ktkNumbers are structures to allow for a single type of data to be used for: single integers, integer ranges, and percentages
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` */
#define ktk_ISSET 1 << 1
#define ktk_RANGE 1 << 2
#define ktk_PERCENT 1 << 3
#define ktk_DIGIT 1 << 4
struct ktkNumber {
int a, b; // min/max
short type; // ktk_NUMBER, ktk_NUMBER_RANGE, ktk_NUMBER_PERCENT
};
int ktk_rollNumber(struct ktkNumber number);
struct ktkNumberSet {
struct ktkNumber *sets; // sets of numbers
size_t count; // count of sets
};
int ktk_rollNumberSet(struct ktkNumberSet set);
int ktk_deleteNumberSet(struct ktkNumberSet *set);
int ktk_copyNumberSet(struct ktkNumberSet *set_1, struct ktkNumberSet *set_2);
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktkStructure
Structures are ultimately a set of operations and relations used for building a map. Structures are stored and used via a Program.
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` */
#define ktk_STRUCTURE_WORLD 1 << 1
#define ktk_STRUCTURE_CIRCLE 1 << 2
#define ktk_STRUCTURE_RECT 1 << 3
#define ktk_STRUCTURE_FILL 1 << 4
#define ktk_STRUCTURE_BORDER 1 << 5
#define ktk_STRUCTURE_REPLACE 1 << 6
#define ktk_STRUCTURE_ORIGIN 1 << 7
#define ktk_STRUCTURE_CONSTRAIN 1 << 8
#define ktk_STRUCTURE_OVERLAP 1 << 9
struct ktkStructure {
unsigned int flags; // flags for this structure
char *name; // name of this structure
struct ktkNumber x, y;
struct ktkNumber size_x, size_y;
struct ktkNumberSet id_1; // id_1
struct ktkNumberSet id_2; // id_2
struct ktkNumberSet replace_id_1; // id_1 replace rules
struct ktkNumberSet replace_id_2; // id_2 replace rules
void *data; // user data (?)
struct ktkRelation *relations; // behavioral relations to other Structures
size_t relation_count; // count of said relations
struct ktkStructure *live; // live sub structures
size_t live_count; // count of sub structures
}; extern const struct ktkStructure ktk_STRUCTURE_DEFAULT;
void ktk_dumpStructure(struct ktkStructure *structure);
// field table for ktkStructure
/*#define S struct ktkStructure
#define FIELD(m) #m,offsetof(S, m)
typedef struct {
const char *name;
size_t offset;
} ktkField_t;
extern ktkField_t ktkStructureTable[];*/
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktk_explodeString
params: search *string, char delimiter, int search depth, *** results
returns: count of search finds
This function explodes the passed string by a delimiter up to a depth. Passed pointer to pointers of char* is used to store the words found (and is allocated accordingly). User _must_ free results manually, on results[n] and results.
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` */
int ktk_explodeString(const char *string, char delim, int depth, char ***results);
/* ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ktkRelation
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` */
struct ktkRelation {
unsigned int flags; // operating flags
char *name;
struct ktkNumber x, y; // x and y of the relation
struct ktkNumber size_x, size_y; // size of created structure (generally)
struct ktkNumber count; // count of times to run this relation
struct ktkStructure *from; // from this type of structure
char *from_name; // name of this structure
unsigned int from_flags; // from operating flags
struct ktkStructure *to; // to this type of structure
char *to_name; // name of this structure
unsigned int to_flags; // to operating flags
struct ktkStructure *path; // pathing Structure
char *path_name; // name of this structure
unsigned int path_flags; // pathing operating flags
}; extern const struct ktkRelation ktk_RELATION_DEFAULT;
#endif