-/* $Id: main.c,v 1.13 2007/01/09 21:30:28 mmondor Exp $ */
+/* $Id: main.c,v 1.14 2007/01/12 12:21:08 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#define FADEOUT_DELAY 1000
#define TEXT_WIDTH 185
-#define TEXT_LINE_SIZE 256
+#define TEXT_LINE_SIZE 64
struct scene {
const char *img, *mus;
static TTF_Font *font_next(void);
static char *text_tok(char *, char *);
+static char *text_alloc(text_t *);
static text_t *text_create(TTF_Font *, const char *);
static void text_free(text_t *);
/* These will actually be provided via dynamic configuration, but to test */
static const struct scene scenes[] = {
- { "gardens_smallbridge", "adventure1", 128,
+ { "gardens_smallbridge", "adventure1", 80,
"You discover a fantastic landscape. A very calm water bed "
"contains various fish species. On the water floats leaves "
"near the other side. The floor on this side is covered "
"bridge. On the other side in front of you can be seen the "
"beginning of a dense forest."
},
- { "forest_entry", "forest", 128,
+ { "forest_entry", "forest", 80,
"You are at the entrance of a deep forest. A wooden smell "
"now dominates. The forest is so dense that you can hardly "
"see inside, but a dark hole."
},
- { "dungeon_deadend", "cavern", 128,
+ { "dungeon_deadend", "cavern", 80,
"You reached a deadly dungeon dead-end! You realize that "
"you also are locked on all sides. 'How will I ever get out "
"of here?' you wonder. 'Well, I guess that there's nothing "
"else to do here than trying to find a way out', you say."
},
- { "gardens_house", "castle", 128,
+ { "cavern_stairs", "cavern", 80,
+ "Some text here"
+ },
+ { "cavern_gold", "cavern2", 128,
+ "Some more text here"
+ },
+ { "gardens_house", "castle", 80,
"Here can be seen a quiet asian-style castle behind a wooden "
"gate. Trees of various colors enhance the landscape. "
"At the far west can be seen stone stairs leading up to what "
"appears to be ruins."
},
- { "mountains_landscape", "aria_prima", 85,
+ { "mountains_landscape", "aria_prima", 45,
"What a marvelous mountain landscape! A spring runs between "
"you and the range of high rocky tops. These appear very "
"inviting to visit and may very well hide interesting things. "
return str;
}
+static char *
+text_alloc(text_t *text)
+{
+ char *line = NULL;
+
+ if (text->numlines == text->alloclines) {
+ char **a;
+
+ if ((a = realloc(text->lines, sizeof(char *) *
+ (text->alloclines * 2))) == NULL)
+ goto err;
+ text->lines = a;
+ text->alloclines *= 2;
+ }
+ if ((line = malloc(sizeof(char) * TEXT_LINE_SIZE)) == NULL)
+ goto err;
+ *line = '\0';
+
+err:
+ return line;
+}
+
+static text_t *
+text_create_new(TTF_Font *font, const char *string)
+{
+ text_t *text = NULL;
+ char *str, *lptr, *olptr, *word, term;
+
+ if ((str = strdup(string)) == NULL)
+ return NULL;
+ if ((text = malloc(sizeof(text_t))) == NULL)
+ goto err;
+ text->numlines = 0;
+ if ((text->lines = malloc(sizeof(char *) * 16)) == NULL)
+ goto err;
+ text->alloclines = 16;
+ text->fnt = font;
+
+ if ((lptr = text_alloc(text)) == NULL)
+ goto err;
+ olptr = lptr;
+
+ for (word = text_tok(str, &term); word != NULL;
+ word = text_tok(NULL, &term)) {
+ int l, w;
+
+ }
+
+err:
+ free(str);
+ if (text != NULL)
+ text_free(text);
+ return NULL;
+}
+
static text_t *
text_create(TTF_Font *font, const char *string)
{
* in which case we delete the last word from it and create a new
* line, adding it to it.
*/
- /*
- for (ptr = strtok(str, " \t"); ptr != NULL;
- ptr = strtok(NULL, " \t")) {
- */
+ /* XXX Bug: when '\n' found, last word may exceed allowed width */
for (ptr = text_tok(str, &term); ptr != NULL;
ptr = text_tok(NULL, &term)) {
int l, w;
(text->alloclines * 2))) == NULL)
goto err;
text->lines = a;
+ text->alloclines *= 2;
}
if ((olptr = malloc(sizeof(char) * TEXT_LINE_SIZE)) == NULL)
goto err;