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 */
41 struct treenode
* chartree
= NULL
;
44 int ptrcomp(void* k1
, void* k2
){
48 void set_message(char* str
){
50 int N
= unicode_getc(str
, &u
);
52 vwchar
* C
= tree_search(chartree
, ptrcomp
, (void*)u
);
54 /* append this character to the message
55 if the current word is too long,
56 move the current word to the next line
57 if the current word is longer than a whole line
58 then just break here (would happen with japanese).
60 //printf("%04lx[%lc] ",u, C->u);
64 character not found, so use a rectangle or something
65 use four tiny numbers to indicate the character
68 //printf("%04lx[???] ", u);
70 N
+= unicode_getc(str
+N
, &u
);
77 void advance_message(){
85 void complete_message(){
91 vwchar
* C
= xmalloc(sizeof(vwchar
));
99 chartree
= xmalloc(sizeof(treenode
));
103 chartree
->key
= (void*)' ';
110 vwchar
* load_vwchar(reader
* rd
, int gfx
){
114 int ret
= loader_scanline(rd
, "%256s %d %d %d %d %d\n",str
,&x
,&y
,&w
,&k1
,&k2
);
118 unicode_getc(str
,&u
);
119 vwchar
* C
= xmalloc(sizeof(vwchar
));
131 void print_tree(treenode
* node
){
132 printf("(%lx,",(utf32
)node
->key
);
150 void randomly_insert(vwchar
* C
[], int count
){
152 for(i
=0; i
<count
-1; i
++){
153 int j
= randi(0, count
-i
-1);
154 tree_insert(chartree
, ptrcomp
, (void*)C
[j
]->u
, C
[j
]);
161 int load_font(char* filename
){
162 printf("load_font: loading %s\n",filename
);
163 char buf
[256] = "fonts/";
164 strmcat(buf
, filename
, 256);
165 reader
* rd
= loader_open(buf
);
167 fatal_error("load_font: cannot open %s\n",filename
);
171 loader_scanline(rd
, "%256s", str
);
172 int gfx
= load_gfx(str
);
174 /* we read 64 characters at a time and insert them
175 randomly into the binary search tree. this is supposed
176 to help produce a more balanced tree. */
180 C
[ptr
] = load_vwchar(rd
, gfx
);
184 randomly_insert(C
, 64);
188 C
[++ptr
] = load_vwchar(rd
, gfx
);
192 randomly_insert(C
, ptr
);
194 printf(" loaded %d characters\n",N
);
196 printf(" character tree is the following\n");
197 print_tree(chartree
);