131 lines
5.6 KiB
C
131 lines
5.6 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 ktkPath *paths; // paths
|
|
size_t path_count; // count of paths
|
|
}; extern const struct ktkStructure ktk_STRUCTURE_DEFAULT;
|
|
void ktk_dumpStructure(struct ktkStructure *structure);
|
|
// live structures are similar to structures, but contain the resulting Structure
|
|
struct ktkLive {
|
|
char *name; // the name of this structure
|
|
// relationship map
|
|
struct ktkLive *parent; // parent of this structure
|
|
struct ktkLive *children; // children of this structure
|
|
size_t child_count; // count of chillens
|
|
// structure placement/size/etc. data
|
|
int flags; // creation flags
|
|
int x, y; // result position, in relative-to-parent terms
|
|
int size_x, size_y; // result size
|
|
int id_1; // result id_1
|
|
int id_2; // result id_2
|
|
void *data; // ?
|
|
struct ktkMap *map; // likely unused, but a snapshot of the generated map
|
|
}; extern const struct ktkLive ktk_LIVE_DEFAULT;
|
|
|
|
int ktk_deleteLive(struct ktkLive *live);
|
|
// this function creates a shallow copy of child to parent - it retains pointers to the child's data. What this means is: DON'T deleteLive this child if you want to retain children.
|
|
int ktk_addLiveChild(struct ktkLive *parent, struct ktkLive *child);
|
|
int ktk_setLiveName(struct ktkLive *live, const char *name);
|
|
|
|
struct ktkPath {
|
|
char *name; // name of the structure to use?
|
|
struct ktkStructure *structure; // base structure to use
|
|
int flags; // path generation flags
|
|
char *to; // target structure in pathing syntax
|
|
int to_flags; // target behavior flags
|
|
struct ktkNumber to_x, to_y;
|
|
char *from; // from structure in pathing syntax
|
|
int from_flags; // from behavior flags
|
|
struct ktkNumber from_x, from_y;
|
|
struct ktkNumber x; // x offset
|
|
struct ktkNumber y; // y offset
|
|
}; extern const struct ktkPath ktk_PATH_DEFAULT;
|
|
// 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
|
|
}; extern const struct ktkRelation ktk_RELATION_DEFAULT;
|
|
|
|
#endif
|