annotate xlovesys.cc @ 51:cbb301016a4e

* oops... finishing what was started and not said with the other patch: fixing memory leaks
author thib
date Fri, 17 Apr 2009 18:40:39 +0000
parents 4c832144b3f2
children 15a18fbe6f21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 // #define ROOTPATH "/mnt/KEY/CLANNAD"
223b71206888 Initial import
thib
parents:
diff changeset
29 // #define ROOTPATH "/home/uenok/pb"
223b71206888 Initial import
thib
parents:
diff changeset
30 // #define FONT "msgothic.ttc"
223b71206888 Initial import
thib
parents:
diff changeset
31 /* kochi-mincho-subst.ttf あるいは -*-*-*-r-*--24-*-*-*-*-*-jisx0208.1983-* など */
223b71206888 Initial import
thib
parents:
diff changeset
32 /* TrueType Font は /usr/X11R6/lib/X11/fonts/TrueType/ などに存在する必要がある */
223b71206888 Initial import
thib
parents:
diff changeset
33
223b71206888 Initial import
thib
parents:
diff changeset
34 #include<stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
35 #include<stdlib.h>
223b71206888 Initial import
thib
parents:
diff changeset
36 #include<unistd.h>
223b71206888 Initial import
thib
parents:
diff changeset
37 #include<locale.h>
223b71206888 Initial import
thib
parents:
diff changeset
38
223b71206888 Initial import
thib
parents:
diff changeset
39 #include<SDL.h>
223b71206888 Initial import
thib
parents:
diff changeset
40 #include<vector>
223b71206888 Initial import
thib
parents:
diff changeset
41 #include<getopt.h>
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 #include"system/file.h"
223b71206888 Initial import
thib
parents:
diff changeset
44 #include"system/system_config.h"
223b71206888 Initial import
thib
parents:
diff changeset
45 #include"window/widget.h"
223b71206888 Initial import
thib
parents:
diff changeset
46 #include"window/system.h"
223b71206888 Initial import
thib
parents:
diff changeset
47
223b71206888 Initial import
thib
parents:
diff changeset
48 #include"music2/music.h"
223b71206888 Initial import
thib
parents:
diff changeset
49
223b71206888 Initial import
thib
parents:
diff changeset
50 #include"scn2k/scn2k.h"
223b71206888 Initial import
thib
parents:
diff changeset
51 #include"scn2k/scn2k_impl.h"
223b71206888 Initial import
thib
parents:
diff changeset
52
223b71206888 Initial import
thib
parents:
diff changeset
53 const char key_lb_orig[] = {0x4b, 0x45, 0x59, 0x5c, 0x83, 0x8a, 0x83, 0x67, 0x83, 0x8b, 0x83, 0x6f, 0x83, 0x58, 0x83, 0x5e, 0x81, 0x5b, 0x83, 0x59, 0x81, 0x49, 0};
223b71206888 Initial import
thib
parents:
diff changeset
54
223b71206888 Initial import
thib
parents:
diff changeset
55 const char key_lb_new[] = "KEY\\LittleBusters";
223b71206888 Initial import
thib
parents:
diff changeset
56
223b71206888 Initial import
thib
parents:
diff changeset
57
223b71206888 Initial import
thib
parents:
diff changeset
58 extern "C" int main(int argc, char* argv[]); /* SDL.h で定義されるので必要ないはずなんだけど…… */
223b71206888 Initial import
thib
parents:
diff changeset
59
223b71206888 Initial import
thib
parents:
diff changeset
60 int main(int argc, char *argv[]) {
223b71206888 Initial import
thib
parents:
diff changeset
61 AyuSysConfig config;
223b71206888 Initial import
thib
parents:
diff changeset
62 int opt = 0, end = 0, screenmode = 0;
223b71206888 Initial import
thib
parents:
diff changeset
63 char rootPath[1024] = "/mnt/KEY/CLANNAD";
223b71206888 Initial import
thib
parents:
diff changeset
64 char font[1024] = "msgothic.ttc";
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
65 char* xor_key = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
66 Uint32 videoOptions = SDL_HWSURFACE;
223b71206888 Initial import
thib
parents:
diff changeset
67
223b71206888 Initial import
thib
parents:
diff changeset
68 while(1) {
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
69 opt = getopt(argc, argv, "fdt:c:r:k:vh?");
0
223b71206888 Initial import
thib
parents:
diff changeset
70 if(opt == -1) {break;}
223b71206888 Initial import
thib
parents:
diff changeset
71
223b71206888 Initial import
thib
parents:
diff changeset
72 switch(opt) {
223b71206888 Initial import
thib
parents:
diff changeset
73 case 'f':
223b71206888 Initial import
thib
parents:
diff changeset
74 videoOptions |= SDL_FULLSCREEN;
223b71206888 Initial import
thib
parents:
diff changeset
75 break;
223b71206888 Initial import
thib
parents:
diff changeset
76 case 'd':
223b71206888 Initial import
thib
parents:
diff changeset
77 videoOptions |= SDL_DOUBLEBUF;
223b71206888 Initial import
thib
parents:
diff changeset
78 break;
223b71206888 Initial import
thib
parents:
diff changeset
79 case 't':
223b71206888 Initial import
thib
parents:
diff changeset
80 strncpy(font, optarg, 1023);
223b71206888 Initial import
thib
parents:
diff changeset
81 break;
223b71206888 Initial import
thib
parents:
diff changeset
82 case 'r':
223b71206888 Initial import
thib
parents:
diff changeset
83 strncpy(rootPath, optarg, 1023);
223b71206888 Initial import
thib
parents:
diff changeset
84 break;
223b71206888 Initial import
thib
parents:
diff changeset
85 case 'v':
41
4c832144b3f2 OtakuNoRaifu is born! (Changed 'xclannad' to 'OtakuNoRaifu')
thib
parents: 35
diff changeset
86 printf("otakunoraifu %s\n", VERSION);
0
223b71206888 Initial import
thib
parents:
diff changeset
87 end = 1;
223b71206888 Initial import
thib
parents:
diff changeset
88 break;
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
89 case 'k':
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
90 if (xor_key == NULL)
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
91 xor_key = new char[33];
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
92 strncpy(xor_key, optarg, 32);
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
93 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
94 case 'h':
223b71206888 Initial import
thib
parents:
diff changeset
95 case '?':
223b71206888 Initial import
thib
parents:
diff changeset
96 printf("\nUsage: %s [OPTIONS]\n\n", argv[0]);
223b71206888 Initial import
thib
parents:
diff changeset
97 printf(" -f : full screen mode\n");
223b71206888 Initial import
thib
parents:
diff changeset
98 printf(" -d : double buffer mode\n");
223b71206888 Initial import
thib
parents:
diff changeset
99 printf(" -t : set font (typeface)\n");
223b71206888 Initial import
thib
parents:
diff changeset
100 printf(" -r : set root path (default /mnt/KEY/CLANNAD)\n");
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
101 printf(" -k : set xor key, if needed\n");
0
223b71206888 Initial import
thib
parents:
diff changeset
102 printf(" -v : show version and exit\n");
223b71206888 Initial import
thib
parents:
diff changeset
103 printf(" -h -? : show help and exit\n\n");
223b71206888 Initial import
thib
parents:
diff changeset
104 end = 1;
223b71206888 Initial import
thib
parents:
diff changeset
105 break;
223b71206888 Initial import
thib
parents:
diff changeset
106 }
223b71206888 Initial import
thib
parents:
diff changeset
107 }
223b71206888 Initial import
thib
parents:
diff changeset
108 if(end == 1) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
109
223b71206888 Initial import
thib
parents:
diff changeset
110 printf("Settings:\n");
223b71206888 Initial import
thib
parents:
diff changeset
111 printf(" Locale : %s\n", setlocale(LC_ALL, ""));
223b71206888 Initial import
thib
parents:
diff changeset
112 printf(" Root Path : %s\n", rootPath);
223b71206888 Initial import
thib
parents:
diff changeset
113 printf(" Font : %s\n", font);
223b71206888 Initial import
thib
parents:
diff changeset
114 printf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
115
223b71206888 Initial import
thib
parents:
diff changeset
116 file_searcher.InitRoot(rootPath);
223b71206888 Initial import
thib
parents:
diff changeset
117 config.LoadInitFile();
223b71206888 Initial import
thib
parents:
diff changeset
118 const char* regname = config.GetParaStr("#REGNAME");
223b71206888 Initial import
thib
parents:
diff changeset
119 if (strcmp(regname, key_lb_orig) == 0) { // "リトルバスターズ! -> LittleBustersに#REGNAMEを変更
223b71206888 Initial import
thib
parents:
diff changeset
120 config.SetParaStr("#REGNAME", key_lb_new);
223b71206888 Initial import
thib
parents:
diff changeset
121 }
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
122 if (xor_key == NULL)
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
123 key_holder.GuessKey((char*)regname);
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
124 else {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
125 key_holder.SetKey2(xor_key);
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
126 delete[] xor_key;
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
127 }
0
223b71206888 Initial import
thib
parents:
diff changeset
128 SetFont(font);
223b71206888 Initial import
thib
parents:
diff changeset
129
223b71206888 Initial import
thib
parents:
diff changeset
130 MuSys mu(config);
223b71206888 Initial import
thib
parents:
diff changeset
131 mu.InitMusic();
223b71206888 Initial import
thib
parents:
diff changeset
132
223b71206888 Initial import
thib
parents:
diff changeset
133 if(SDL_Init(SDL_INIT_VIDEO)) {
223b71206888 Initial import
thib
parents:
diff changeset
134 printf("Unable to init SDL: %s\n", SDL_GetError());
223b71206888 Initial import
thib
parents:
diff changeset
135 return 1;
223b71206888 Initial import
thib
parents:
diff changeset
136 }
223b71206888 Initial import
thib
parents:
diff changeset
137
223b71206888 Initial import
thib
parents:
diff changeset
138 config.GetParam("#SCREENSIZE_MOD", 1, &screenmode);
223b71206888 Initial import
thib
parents:
diff changeset
139 if (screenmode == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
140 SDL_SetVideoMode(800, 600, 0, videoOptions);
223b71206888 Initial import
thib
parents:
diff changeset
141 } else {
223b71206888 Initial import
thib
parents:
diff changeset
142 SDL_SetVideoMode(640, 480, 0, videoOptions);
223b71206888 Initial import
thib
parents:
diff changeset
143 }
223b71206888 Initial import
thib
parents:
diff changeset
144 // SDL_SetVideoMode(640, 480, 0, videoOptions);
223b71206888 Initial import
thib
parents:
diff changeset
145 // SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE /*| SDL_FULLSCREEN */);
223b71206888 Initial import
thib
parents:
diff changeset
146 {
223b71206888 Initial import
thib
parents:
diff changeset
147 System::Main main_sys;
223b71206888 Initial import
thib
parents:
diff changeset
148 PicContainer* main_panel = main_sys.root.create_node(Rect(0, 0, main_sys.root.width, main_sys.root.height), 0);
223b71206888 Initial import
thib
parents:
diff changeset
149 main_panel->show();
223b71206888 Initial import
thib
parents:
diff changeset
150 try {
223b71206888 Initial import
thib
parents:
diff changeset
151 Scn2k scn(main_sys.event, *main_panel, mu, config);
223b71206888 Initial import
thib
parents:
diff changeset
152 main_sys.Mainloop();
223b71206888 Initial import
thib
parents:
diff changeset
153 } catch(...) {
223b71206888 Initial import
thib
parents:
diff changeset
154 fprintf(stderr,"System faulted; exit now.\n");
223b71206888 Initial import
thib
parents:
diff changeset
155 }
223b71206888 Initial import
thib
parents:
diff changeset
156 delete main_panel;
223b71206888 Initial import
thib
parents:
diff changeset
157 }
223b71206888 Initial import
thib
parents:
diff changeset
158
223b71206888 Initial import
thib
parents:
diff changeset
159 mu.FinalizeMusic();
223b71206888 Initial import
thib
parents:
diff changeset
160
223b71206888 Initial import
thib
parents:
diff changeset
161 SDL_Quit();
223b71206888 Initial import
thib
parents:
diff changeset
162 }
223b71206888 Initial import
thib
parents:
diff changeset
163