2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
22 evanrinehart@gmail.com
25 /* messages and text */
42 struct treenode
* chartree
= NULL
;
45 int ptrcomp(void* k1
, void* k2
){
49 void set_message(char* str
){
51 int N
= unicode_getc(str
, &u
);
53 vwchar
* C
= tree_search(chartree
, ptrcomp
, (void*)u
);
55 /* append this character to the message
56 if the current word is too long,
57 move the current word to the next line
58 if the current word is longer than a whole line
59 then just break here (would happen with japanese).
61 //printf("%04lx[%lc] ",u, C->u);
65 character not found, so use a rectangle or something
66 use four tiny numbers to indicate the character
69 //printf("%04lx[???] ", u);
71 N
+= unicode_getc(str
+N
, &u
);
78 void advance_message(){
86 void complete_message(){
92 vwchar
* C
= xmalloc(sizeof(vwchar
));
100 chartree
= xmalloc(sizeof(treenode
));
104 chartree
->key
= (void*)' ';
111 vwchar
* load_vwchar(reader
* rd
, int gfx
){
115 int ret
= loader_scanline(rd
, "%256s %d %d %d %d %d\n",str
,&x
,&y
,&w
,&k1
,&k2
);
119 unicode_getc(str
,&u
);
120 vwchar
* C
= xmalloc(sizeof(vwchar
));
132 void print_tree(treenode
* node
){
133 printf("(%lx,",(utf32
)node
->key
);
151 void randomly_insert(vwchar
* C
[], int count
){
153 for(i
=0; i
<count
-1; i
++){
154 int j
= randi(0, count
-i
-1);
155 tree_insert(chartree
, ptrcomp
, (void*)C
[j
]->u
, C
[j
]);
162 int load_font(char* filename
){
163 printf("load_font: loading %s\n",filename
);
164 char buf
[256] = "fonts/";
165 strmcat(buf
, filename
, 256);
166 reader
* rd
= loader_open(buf
);
168 fatal_error("load_font: cannot open %s\n",filename
);
172 loader_scanline(rd
, "%256s", str
);
173 int gfx
= load_gfx(str
);
175 /* we read 64 characters at a time and insert them
176 randomly into the binary search tree. this is supposed
177 to help produce a more balanced tree. */
181 C
[ptr
] = load_vwchar(rd
, gfx
);
185 randomly_insert(C
, 64);
189 C
[++ptr
] = load_vwchar(rd
, gfx
);
193 randomly_insert(C
, ptr
);
195 printf(" loaded %d characters\n",N
);
197 printf(" character tree is the following\n");
198 print_tree(chartree
);