Browse Source

move some codes, fix bugs

Eduardo Bart 10 years ago
parent
commit
7ab8b17bf6

+ 1
- 19
src/framework/engine.cpp View File

@@ -44,35 +44,17 @@ Engine::~Engine()
44 44
 
45 45
 void Engine::init()
46 46
 {
47
-    Platform::init();
48
-
49
-    int width = g_config.getInteger("width");
50
-    int height = g_config.getInteger("height");
51
-
52
-    // create the window
53
-    Platform::createWindow(0, 0, width, height, 550, 450, false);
54
-    Platform::setWindowTitle(APP_NAME);
55
-    Platform::setVsync();
56
-
57 47
     // initialize graphics stuff
58 48
     g_graphics.init();
59 49
 
60 50
     // finally show the window
61
-    onResize(width, height);
62
-    Platform::showWindow();
63
-    //Platform::hideMouseCursor();
51
+    onResize(Platform::getWindowWidth(), Platform::getWindowHeight());
64 52
 }
65 53
 
66 54
 void Engine::terminate()
67 55
 {
68 56
     changeState(NULL);
69 57
 
70
-    // save configs
71
-    g_config.setValue("width", Platform::getWindowWidth());
72
-    g_config.setValue("height", Platform::getWindowHeight());
73
-
74
-    Platform::showMouseCursor();
75
-    Platform::terminate();
76 58
     g_graphics.terminate();
77 59
 }
78 60
 

+ 1
- 1
src/framework/platform.h View File

@@ -66,7 +66,7 @@ namespace Platform
66 66
     void swapBuffers();
67 67
 
68 68
     /// Get the app user directory, the place to save files configurations files
69
-    const char *getAppUserDir();
69
+    const char *getAppUserDir(const char *appName);
70 70
 }
71 71
 
72 72
 #endif // PLATFORM_H

+ 0
- 5
src/framework/prerequisites.h View File

@@ -25,11 +25,6 @@
25 25
 #ifndef PREREQUISITES_H
26 26
 #define PREREQUISITES_H
27 27
 
28
-// app name and version
29
-#define APP_NAME "OTClient"
30
-#define APP_LONGNAME APP_NAME " " APP_VERSION
31
-#define APP_VERSION "0.1.0"
32
-
33 28
 // easy typing
34 29
 #include <stdint.h>
35 30
 

+ 4
- 4
src/framework/resourcemanager.cpp View File

@@ -53,14 +53,14 @@ bool ResourceManager::setWriteDir(const std::string& path)
53 53
     bool ret = (bool)PHYSFS_setWriteDir(path.c_str());
54 54
 
55 55
     if(!ret)
56
-        error("Could not set the path %s as write directory, file write will not work.");
56
+        error("Could not set the path \"%s\" as write directory, file write will not work.", path.c_str());
57 57
     return ret;
58 58
 }
59 59
 
60 60
 bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront)
61 61
 {
62 62
     if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) {
63
-        error("Error while adding %s to resources search path: %s", PHYSFS_getLastError());
63
+        error("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());
64 64
         return false;
65 65
     }
66 66
     return true;
@@ -75,7 +75,7 @@ unsigned char *ResourceManager::loadFile(const std::string& fileName, unsigned i
75 75
 {
76 76
     PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());
77 77
     if(!file) {
78
-        error("Failed to load file %s: %s", fileName.c_str(), PHYSFS_getLastError());
78
+        error("Failed to load file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
79 79
         *fileSize = 0;
80 80
         return NULL;
81 81
     }
@@ -104,7 +104,7 @@ bool ResourceManager::saveFile(const std::string &fileName, const unsigned char
104 104
 {
105 105
     PHYSFS_file *file = PHYSFS_openWrite(fileName.c_str());
106 106
     if(!file) {
107
-        error("Failed to save file %s: %s", fileName.c_str(), PHYSFS_getLastError());
107
+        error("Failed to save file \"%s\": %s", fileName.c_str(), PHYSFS_getLastError());
108 108
         return false;
109 109
     }
110 110
 

+ 1
- 1
src/framework/win32platform.cpp View File

@@ -276,7 +276,7 @@ int Platform::getWindowHeight()
276 276
     return win32.height;
277 277
 }
278 278
 
279
-const char *Platform::getAppUserDir()
279
+const char *Platform::getAppUserDir(const char *appName)
280 280
 {
281 281
     /*std::stringstream sdir;
282 282
     sdir << PHYSFS_getUserDir() << "/." << APP_NAME << "/";

+ 2
- 2
src/framework/x11platform.cpp View File

@@ -717,10 +717,10 @@ int Platform::getWindowHeight()
717 717
     return x11.height;
718 718
 }
719 719
 
720
-const char *Platform::getAppUserDir()
720
+const char *Platform::getAppUserDir(const char *appName)
721 721
 {
722 722
     std::stringstream sdir;
723
-    sdir << PHYSFS_getUserDir() << "/." << APP_NAME << "/";
723
+    sdir << PHYSFS_getUserDir() << "/." << appName << "/";
724 724
     if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
725 725
         error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
726 726
     return sdir.str().c_str();

+ 28
- 9
src/main.cpp View File

@@ -52,16 +52,23 @@ void setDefaultConfigs()
52 52
     g_config.setValue("height", 480);
53 53
 }
54 54
 
55
+void saveConfigs()
56
+{
57
+    g_config.setValue("width", Platform::getWindowWidth());
58
+    g_config.setValue("height", Platform::getWindowHeight());
59
+    g_config.save();
60
+}
61
+
55 62
 int main(int argc, const char *argv[])
56 63
 {
57 64
     // install our signal handler
58 65
     signal(SIGTERM, signal_handler);
59 66
     signal(SIGINT, signal_handler);
60 67
 
61
-    // setup resources
68
+    // init resources
62 69
     g_resources.init(argv[0]);
63
-    if(g_resources.setWriteDir(Platform::getAppUserDir()))
64
-        g_resources.addToSearchPath(Platform::getAppUserDir());
70
+    if(g_resources.setWriteDir(Platform::getAppUserDir("OTClient")))
71
+        g_resources.addToSearchPath(Platform::getAppUserDir("OTClient"));
65 72
     g_resources.addToSearchPath("data");
66 73
 
67 74
     // before loading configurations set the default ones
@@ -71,23 +78,35 @@ int main(int argc, const char *argv[])
71 78
     if(!g_config.load("config.yml"))
72 79
         notice("Could not read configuration file, default configurations will be used.");
73 80
 
74
-    notice(APP_LONGNAME);
81
+    notice("OTClient 0.1.0");
75 82
 
76
-    // setup the engine
77
-    g_engine.init();
83
+    // init platform stuff
84
+    Platform::init();
78 85
 
79
-    // create initial state
86
+    // create the window
87
+    Platform::createWindow(0, 0, g_config.getInteger("width"), g_config.getInteger("height"), 640, 480, false);
88
+    Platform::setWindowTitle("OTClient");
89
+    Platform::setVsync();
90
+
91
+    // init engine
92
+    g_engine.init();
80 93
     boost::scoped_ptr<MenuState> menuState(new MenuState);
81 94
     g_engine.changeState(menuState.get());
82 95
 
83
-    // run
96
+    Platform::showWindow();
97
+    //Platform::hideMouseCursor();
98
+
99
+    // main loop, run everything
84 100
     g_engine.run();
85 101
 
86 102
     // terminate stuff
87 103
     g_engine.terminate();
88 104
 
105
+    //Platform::showMouseCursor();
106
+    Platform::terminate();
107
+
89 108
     // save configurations before exiting
90
-    g_config.save();
109
+    saveConfigs();
91 110
 
92 111
     // unload resources
93 112
     g_resources.terminate();

Loading…
Cancel
Save