Commit 7ca340cd by beoran

Keep the repo up to date at least once in a while...

parent 7c4cab6b
......@@ -499,6 +499,7 @@ def eruta_on_bump(t1, t2, h1, h2, kind = nil)
if kind == 1 # Begin of collision
# puts "Begin collision!"
elsif kind == 2 # Collision active
puts "Colliding! #{t1}<->#{t2} (#{h1}<->#{h2})"
thing1 = Thing[t1]
thing2 = Thing[t2]
if thing1 && thing2
......
......@@ -14,6 +14,7 @@ o Play
1 implement player and foe data such as HP, MP; LP, and stats.
o GUI:
1 Reimplement gui engine wholly in C, not split over C and Mruby.
1 game HUD / current HP, MP and LP display
* All sorts of widgets for status screens, menus, etc.
* Keyboard input.
......
#ifndef MIAO_H_INCLUDED
#define MIAO_H_INCLUDED
/* MIAO Minimalistic Array Operations, inspired by kvec->h-> */
#include <stdlib.h>
#ifndef miao_realloc
#define miao_realloc(PTR, SIZE) realloc((PTR), (SIZE))
#endif
#define miao_of_type(TYPE) { TYPE * a; TYPE * aux; size_t n; size_t m; }
#define miao_t(TYPE) struct miao_of_type(TYPE)
#define miao_struct(NAME, TYPE) struct NAME miao_of_type(TYPE)
#define miao_init(ARR) ((ARR)->n = (ARR)->m = 0, (ARR)->a = NULL, (ARR))
#define miao_done(ARR) do { free((ARR)->a); miao_init((ARR)); } while (0)
#define miao_unsafe_get_ptr(ARR, I) (((ARR)->a)+(I))
#define miao_unsafe_get(ARR, I) (((ARR)->a)[(I)])
#define miao_elsize(ARR) (sizeof *((ARR)->a))
#define miao_cap(ARR) ((ARR)->m)
#define miao_size(ARR) ((ARR)->n)
#define miao_size_for(ARR, AMOUNT) (miao_elsize(ARR) * (AMOUNT))
#define miao_total_size(ARR) miao_size_for(ARR, miao_size(ARR))
#define miao_out_of_bounds(ARR, I) ((size_t)(I) >= (ARR)->m)
#define miao_get_ptr(ARR, I) (miao_out_of_bounds(ARR, I) ? NULL: miao_unsafe_get_ptr(ARR, I))
#define miao_get(ARR, I, DEFAULT) (miao_out_of_bounds(ARR, I) ? DEFAULT : miao_unsafe_get(ARR, I))
#define miao_resize(ARR, CAP) \
( \
(ARR)->m = (CAP), \
(ARR)->aux = miao_realloc((ARR)->a, miao_size_for(ARR, (ARR)->m)), \
(ARR)->aux ? ((ARR)->a = ARR->aux) : NULL \
)
#define miao_grow(ARR, SIZE) \
(SIZE >= miao_cap(ARR) ? miao_resize(ARR, SIZE) : (ARR)->a )
#define miao_unsafe_pop_ptr(ARR) ((ARR)->n--, ((ARR)->a + (ARR)->n))
#define miao_unsafe_pop(ARR) ((ARR)->n--, (ARR)->a[(ARR)->n])
#define miao_pop(ARR, DEFAULT) (((ARR)->n > 0) ? miao_unsafe_pop(ARR) : DEFAULT)
#define miao_pop_ptr(ARR) (((ARR)->n > 0) ? miao_unsafe_pop_ptr(ARR) : NULL)
#define miao_unsafe_push(ARR, VAL) ((ARR)->n++, (ARR)->a[(ARR)->n] = (VAL))
#define miao_push(ARR, VAL) \
(miao_grow(ARR, ((ARR)->n + 1)) ? miao_unsafe_push(ARR, VAL) : NULL)
#define miao_push_ptr(ARR) \
( \
(miao_grow(ARR, ((ARR)->n + 1))) ? \
((ARR)->n++, miao_get_ptr(ARR, (ARR)->n - 1)) \
: NULL \
)
#define miao_copy(DEST, SRC) \
( \
miao_grow(DEST, miao_size(SRC)) ? \
( (DEST)->n = miao_size(SRC), \
memcpy((DEST)->a, (SRC)->a, miao_total_size(DEST)) \
, DEST \
) : NULL \
)
#define miao_qsort(ARR, COMPARE) \
( \
(ARR)->a ? \
( qsort((ARR)->a, miao_size(ARR), miao_elsize(ARR), COMPARE) \
, (ARR)->a ) \
: NULL \
)
#define miao_bsearch(ARR, COMPARE, KEY) \
(bsearch(KEY, (ARR)->a, miao_size(ARR), miao_elsize(ARR), COMPARE))
#define miao_each_ptr(ARR, ACTION, DATA) \
{ size_t miao_i__ ; \
for (miao_i__ = 0; miao_i__ < miao_size(ARR) ; miao_i__ ++) { \
if(ACTION(miao_i__, miao_unsafe_get_ptr(ARR, miao_i__), DATA)) break; \
} \
} while(0);
#define miao_each(ARR, ACTION, DATA) \
{ size_t miao_i__ ; \
for (miao_i__ = 0; miao_i__ < miao_size(ARR) ; miao_i__ ++) { \
if(ACTION(miao_i__, miao_unsafe_get(ARR, miao_i__), DATA)) break; \
} \
} while(0);
#define miao_each_with_result(ARR, ACTION, RESULT, CHECK, DATA) \
{ size_t miao_i__ ; \
for (miao_i__ = 0; miao_i__ < miao_size(ARR) ; miao_i__ ++) { \
(RESULT) = ACTION(miao_i__, miao_unsafe_get(ARR, miao_i__), DATA); \
if (CHECK(RESULT, DATA)) break; \
} \
} while(0);
#define miao_each_ptr_with_result(ARR, ACTION, RESULT, CHECK, DATA) \
{ size_t miao_i__ ; \
for (miao_i__ = 0; miao_i__ < miao_size(ARR) ; miao_i__ ++) { \
(RESULT) = ACTION(miao_i__, miao_unsafe_get_ptr(ARR, miao_i__), DATA); \
if (CHECK(RESULT, DATA)) break; \
} \
} while(0);
#endif
#ifndef zori_H_INCLUDED
#define zori_H_INCLUDED
/* This file was generated with:
'cfunctions -c -aoff -n -w zori_proto src/zori.c' */
#ifndef CFH_ZORI_PROTO
#define CFH_ZORI_PROTO
#include "eruta.h"
#include "rebox.h"
#include "miao.h"
/* Typedefs for possible later portability. */
typedef ALLEGRO_COLOR zori_color ;
typedef ALLEGRO_BITMAP zori_bitmap ;
typedef ALLEGRO_FONT zori_font ;
typedef ALLEGRO_EVENT zori_system_event;
typedef ALLEGRO_EVENT_TYPE zori_event_type;
typedef ALLEGRO_DISPLAY zori_display;
typedef Point zori_point;
typedef Rebox zori_rebox;
typedef int zori_id;
#define ZORI_ID_OK_P(ID) ((ID) > -1)
#define ZORI_ID_OK ((zori_id)(0))
#define ZORI_ID_ERROR ((zori_id)(-1))
#define ZORI_ID_ENOMEM ((zori_id)(-2))
#define ZORI_ID_EINVAL ((zori_id)(-3))
struct zori_widget;
struct zori_event {
zori_system_event sysev;
struct zori_widget * widget;
void * data;
};
struct zori_stylepart {
zori_color color;
zori_bitmap * image;
zori_font * font;
};
struct zori_style {
struct zori_stylepart fore;
struct zori_stylepart back;
struct zori_stylepart text;
};
struct zori_widget;
typedef int zori_handler_func(struct zori_event * event);
struct zori_handler {
zori_event_type type;
zori_handler_func * handler;
void * data;
};
/* System event handlers. */
struct zori_handlers miao_of_type(struct zori_handler);
/*
struct zori_handlers {
size_t size;
struct zori_handler * handlers;
};
*/
/* Mouse or keyboard/joystick cursor. */
struct zori_cursor {
zori_point p;
struct zori_widget * hover;
struct zori_widget * focus;
zori_bitmap * bitmap;
};
/* Support multiple cursors... */
struct zori_cursors {
struct zori_cursor mouse;
struct zori_cursor keyjoy;
};
/*
on_enter
on_enter(data = {})
on_event(*args)
on_event(*data)
on_key_down(*args)
on_leave(name=nil)
on_mouse_axes(t, x, y, z, w, dx, dy, dz, dw)
on_mouse_button_down(t, x, y, z, w, b)
on_mouse_button_up(t, x, y, z, w, b)
on_mouse_in(x, y, from)
on_mouse_out(x, y, to)
on_resize
*/
struct zori_widget {
/* ID of the widget, used in most external API's. */
zori_id id;
/* Root level widget under which this widget is active. */
struct zori_widget * root;
/* Position and size of the widget. */
zori_rebox box;
/* Z ordering. */
int z;
/* Style. */
struct zori_style style;
/* Handlers. */
struct zori_handlers handlers;
/* Related widgets. */
struct zori_widget * parent;
struct zori_widget * child;
struct zori_widget * sibling;
};
/* An array of widget pointers. */
struct zori_widget_array {
struct zori_widget * array;
size_t size;
};
/* Root level widget. */
struct zori_root {
/* A root is a widget. */
struct zori_widget widget;
/* It also manages the cursors*/
struct zori_cursors cursors;
/* It has an array of all widgets it manages. */
struct zori_widget_array * widgets;
/* It is linked to a particular display. */
zori_display * display;
};
zori_id zori_set_background_color(zori_id id, zori_color color);
zori_id zori_set_foreground_color(zori_id id, zori_color color);
zori_id zori_new_root_widget(const struct zori_style * style);
zori_id zori_new_frame_widget(zori_id parent);
zori_id zori_register(zori_id id, zori_event_type type, zori_handler_func handler, void * extra);
/* From 'src/zori.c': */
#endif /* CFH_ZORI_PROTO */
#endif
......
#include "zori.h"
#include "miao.h"
/*
* Pardon the pun name, but Zori is the submodule that handles the user
* interface and the menus.
*/
int zori_handler_compare(const void * v1, const void * v2) {
const struct zori_handler * h1 = v1;
const struct zori_handler * h2 = v2;
if (h1->type < h2->type) return -1;
if (h1->type > h2->type) return 1;
return 0;
}
struct zori_handler * zori_handlers_add(struct zori_handlers * me, zori_event_type type, zori_handler_func * handler, void * data) {
struct zori_handler * result = NULL;
result = miao_push_ptr(me);
if (result) {
result->type = type;
result->handler = handler;
result->data = data;
}
miao_qsort(me, zori_handler_compare);
return result;
}
void zori_handlers_done(struct zori_handlers * me) {
miao_done(me);
}
void zori_handlers_init(struct zori_handlers * me) {
miao_init(me);
}
struct zori_handler * zori_handlers_search(struct zori_handlers * me, zori_event_type type) {
struct zori_handler * result;
struct zori_handler key;
key.type = type;
key.handler = NULL;
key.data = NULL;
if (!me) return NULL;
result = miao_bsearch(me, zori_handler_compare, &key);
return result;
}
int zori_handlers_handle(struct zori_handlers * me, struct zori_event * event, struct zori_widget * widget) {
struct zori_handler * handler = zori_handlers_search(me, event->sysev.type);
if (!handler) return 0;
return handler->handler(event);
}
struct zori_root zori_the_root = {0};
int zori_init() {
return 0;
}
......
......@@ -43,7 +43,7 @@ TEST_FUNC(bxml) {
TEST_FUNC(bxml_parse) {
Bxml * xml;
xml = bxml_parse_filename("data/map/map_0001.tmx");
xml = bxmlparser_parse_filename("data/map/map_0001.tmx");
TEST_NOTNULL(xml);
bxml_free(xml);
TEST_DONE();
......
......@@ -2,7 +2,7 @@
* This is a test for collide in $package$
*/
#include "si_test.h"
#include "collide.h"
/* #include "collide.h" */
TEST_FUNC(collide) {
......
/**
* This is a test for miao in $package$
*/
#include "si_test.h"
#include "miao.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct foo {
char * s;
};
struct foo_array miao_of_type(struct foo);
int foo_compare(const void * v1, const void * v2)
{
const struct foo * f1, * f2;
f1 = v1;
f2 = v2;
return strcmp(f1->s, f2->s);
}
int foo_each_ptr(size_t i, const struct foo * f, FILE * extra) {
fprintf(extra, "%u => %s\n", i, f->s);
return 0;
}
int foo_each(size_t i, struct foo f, FILE * extra) {
fprintf(extra, "%u => %s\n", i, f.s);
return 0;
}
struct foo * foo_each_ptr_with_result(size_t i, struct foo * f, char * extra) {
printf("%u => %s\n", i, f->s);
return f;
}
int foo_check_ptr(const struct foo * f, char * extra) {
return (strcmp(f->s, extra) == 0);
}
struct foo foo_each_with_result(size_t i, struct foo f, char * extra) {
printf("%u => %s\n", i, f.s);
return f;
}
int foo_check(const struct foo f, char * extra) {
return (strcmp(f.s, extra) == 0);
}
TEST_FUNC(miao) {
struct foo f1, f2 , f3;
struct foo * e1, * e2, *e3;
struct foo_array a[1];
struct foo_array d[1];
miao_init(a);
miao_init(d);
e1 = miao_push_ptr(a);
TEST_NOTNULL(e1);
e1->s = "world";
e1 = miao_push_ptr(a);
TEST_NOTNULL(e1);
e1->s = "hello";
miao_qsort(a, foo_compare);
TEST_INTEQ(2, miao_size(a));
TEST_PTREQ(e1, miao_get_ptr(a, 1));
TEST_PTREQ(e1, miao_unsafe_get_ptr(a, 1));
TEST_NULL(miao_get_ptr(a, 77));
TEST_ASSERT(miao_out_of_bounds(a, 2));
TEST_ASSERT(miao_cap(a) >= 2);
TEST_ASSERT(miao_size(a) == 2);
TEST_NOTNULL(miao_resize(a, 64));
TEST_ASSERT(miao_cap(a) >= 64);
TEST_ASSERT(miao_size(a) == 2);
e1 = miao_get_ptr(a, 1);
TEST_STREQ("world", e1->s);
TEST_PTREQ(e1, miao_unsafe_get_ptr(a, 1));
TEST_NULL(miao_get_ptr(a, 77));
TEST_ASSERT(miao_out_of_bounds(a, 77));
TEST_INTEQ(sizeof(struct foo), miao_elsize(a));
TEST_NOTNULL(miao_copy(d, a));
TEST_MEMEQ(a->a, miao_size(a) * miao_elsize(a), d->a);
miao_push_ptr(a)->s = "foo";
miao_push_ptr(a)->s = "bar";
TEST_NOTNULL(miao_qsort(a, foo_compare));
miao_each(a, foo_each , stdout);
miao_each_ptr(a, foo_each_ptr, stdout);
miao_each_with_result(a, foo_each_with_result, f3, foo_check, "foo");
TEST_STREQ("foo", f3.s);
miao_each_ptr_with_result(a, foo_each_ptr_with_result, e3, foo_check_ptr, "foo");
TEST_STREQ("foo", e3->s);
f1.s = "hello";
e3 = miao_bsearch(a, foo_compare, &f1);
TEST_STREQ(f1.s, e3->s);
e2 = miao_pop_ptr(a);
TEST_STREQ("world", e2->s);
miao_done(a);
TEST_ZERO(miao_size(a));
TEST_DONE();
}
int main(void) {
TEST_INIT();
TEST_RUN(miao);
TEST_REPORT();
}
......@@ -2,7 +2,7 @@
* This is a test for pachi in $package$
*/
#include "si_test.h"
#include "pachi.h"
/* #include "pachi.h" */
TEST_FUNC(pachi) {
......
......@@ -7,6 +7,7 @@
TEST_FUNC(sprite) {
#ifdef COMMENT
SpriteList * list;
Sprite * sprite;
SpriteAction * act;
......@@ -69,7 +70,8 @@ TEST_FUNC(sprite) {
}
spritelist_free(list);
sprite_free(sprite);
TEST_DONE();
#endif
TEST_DONE();
}
......
......@@ -2,7 +2,7 @@
* This is a test for spritelayout in $package$
*/
#include "si_test.h"
#include "spritelayout.h"
/* #include "spritelayout.h" */
TEST_FUNC(spritelayout) {
......
......@@ -2,6 +2,7 @@
* This is a test for spritelist in $package$
*/
#include "si_test.h"
#include "sprite.h"
#include "spritelist.h"
......
......@@ -2,6 +2,7 @@
* This is a test for spritestate in $package$
*/
#include "si_test.h"
#include "sprite.h"
#include "spritestate.h"
......
......@@ -2,6 +2,7 @@
* This is a test for tr_audio in $package$
*/
#include "si_test.h"
#include <mruby.h>
#include "tr_audio.h"
......
......@@ -2,6 +2,7 @@
* This is a test for tr_graph in $package$
*/
#include "si_test.h"
#include <mruby.h>
#include "tr_graph.h"
......
......@@ -2,6 +2,7 @@
* This is a test for tr_path in $package$
*/
#include "si_test.h"
#include <mruby.h>
#include "tr_path.h"
......
......@@ -2,6 +2,7 @@
* This is a test for tr_sprite in $package$
*/
#include "si_test.h"
#include <mruby.h>
#include "tr_sprite.h"
......
......@@ -2,6 +2,7 @@
* This is a test for tr_store in $package$
*/
#include "si_test.h"
#include <mruby.h>
#include "tr_store.h"
......
......@@ -2,6 +2,7 @@
* This is a test for tr_thing in $package$
*/
#include "si_test.h"
#include <mruby.h>
#include "tr_thing.h"
......
......@@ -2,7 +2,7 @@
* This is a test for xml in $package$
*/
#include "si_test.h"
#include "xml.h"
/* #include "xml.h" */
TEST_FUNC(xml) {
......
#include "$file$.h"
#ifndef $file$_H_INCLUDED
#define $file$_H_INCLUDED
#endif
/**
* This is a test for $file$ in $package$
*/
#include "si_test.h"
#include "$file$.h"
TEST_FUNC($file$) {
TEST_DONE();
}
int main(void) {
TEST_INIT();
TEST_RUN($file$);
TEST_REPORT();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment