• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/cannonball/main.cpp

Go to the documentation of this file.
00001 #include "main.h"
00002 
00003 Log* logger = 0;
00004 RenderListener* RenderListener::m_instance = NULL;
00005 
00006 int __stdcall WinMain(HINSTANCE mainInstance, HINSTANCE prevInstance, char* args, int numargs){
00007         //#ifdef _DEBUG
00008         logger = new CmdLogger();
00009         //#else
00010         //logger = new DummyLogger();
00011         //#endif
00012 
00013         RenderDesc desc = {
00014                 131072, // maxVertices
00015                 262144, // maxIndices
00016                 16,     // maxTextures
00017                 512,    // colorTextureWidth
00018                 512,    // colorTextureHeight
00019                 256,    // detailTextureWidth
00020                 256     // detailTextureHeight
00021         };
00022 
00023         Camera camera;
00024         
00025 
00026         // TEST
00027         camera.setPosition(float3(0.f, 0.f, 0.f));
00028         camera.setRotation(float3(0.f, 0.f, 0.f));
00029 
00030         // open module files
00031         Module windowModule(MODULE("window"));
00032         Module renderModule(MODULE("render"));
00033         Module physicModule(MODULE("physic"));
00034         Module audioModule (MODULE("audio"));
00035 
00036         // create modules
00037         IWindow* window = windowModule.create<IWindow>();
00038         IPhysic* physic = physicModule.create<IPhysic>();
00039         IRender* render = renderModule.create<IRender>();
00040         IAudio*  audio  = audioModule .create<IAudio>();
00041 
00042         if(window == 0)
00043                 printf("%s", "Window module not created.");
00044         if(physic == 0)
00045                 printf("%s", "Physic module not created.");
00046         if(render == 0)
00047                 printf("%s", "Render module not created.");
00048         if(audio == 0)
00049                 printf("%s", "Audio module not created.");
00050 
00051         // initialize modules
00052         if(window->init(0, 0, 1024, 768, TEXT("Cannonball"), stateFullscreen, styleFullscreen) == false)
00053                 return printf("%s", "Window initialization failed.\n"), -1;
00054         if(physic->init() == false)
00055                 return printf("%s", "Physic initialization failed.\n"), -1;
00056         if(render->init((HWND)(window->getWindow()), window->getSize().width, window->getSize().height, desc) == false)
00057                 return printf("%s", "Render initialization failed.\n"), -1;
00058         if(audio->init() == false)
00059                 return printf("%s", "Audio initialization failed.\n"), -1;
00060 
00061         // activate device input
00062         window->activateInput(deviceMouse);
00063         window->activateInput(deviceKeyboard);
00064         window->showCursor(false);
00065         pMouseDevice mouse = window->activateDevice(deviceMouse)->asMouse();
00066         pKeyboardDevice keyboard = window->activateDevice(deviceKeyboard)->asKeyboard();
00067         
00068         Level level(*physic, *render);
00069         Gui gui(*render, *physic, mouse, window->getMouseMap());
00070         Player player(&gui, &level, audio, render, camera);
00071         
00072         // add listeners
00073         WindowListener windowListener(*render, camera);
00074         RenderListener renderListener(*physic, *render, camera, mouse, keyboard, window->getKeyboardMap(), &gui, &player, *window, *audio);
00075         window->addListener(&windowListener);
00076         window->addListener(&renderListener);
00077         RenderListener::setInstance(&renderListener);
00078 
00079         // audio data
00080         float3 explodePosition(0.f,0.f,0.f);
00081         float3 explodeVelocity(0.f,0.f,0.f);
00082         float3 explodeDirection(0.f,1.f,0.f);
00083         pBuffer explodeBuffer = audio->createBuffer(TEXT("../bin/sound/explosion.wav"), fileWAVE);
00084         pSound explodeSound = audio->createSound(explodeBuffer, true, &explodePosition, &explodeVelocity, &explodeDirection);
00085 
00086         // TEST
00087         //{
00088         //      struct SkyboxData {TextureData top, bottom, left, right, front, back;} skybox;
00089         //      loadTextureData(TEXT("../bin/textures/nightsky_up.bmp"), 0, 0, skybox.top);
00090         //      loadTextureData(TEXT("../bin/textures/nightsky_down.bmp"), 0, 0, skybox.bottom);
00091         //      loadTextureData(TEXT("../bin/textures/nightsky_west.bmp"), 0, 0, skybox.left);
00092         //      loadTextureData(TEXT("../bin/textures/nightsky_east.bmp"), 0, 0, skybox.right);
00093         //      loadTextureData(TEXT("../bin/textures/nightsky_south.bmp"), 0, 0, skybox.front);
00094         //      loadTextureData(TEXT("../bin/textures/nightsky_north.bmp"), 0, 0, skybox.back);
00095         //      render->createSkyBox(skybox.top, skybox.bottom, skybox.left, skybox.right, skybox.front, skybox.back);
00096         //}
00097         
00098         player.loadCannonball(physic);
00099         
00100 
00101         //level.load(TEXT("../bin/meshes/level1.rvl"), TEXT("../bin/textures/"));
00102         
00103         gui.setGuiTexture(TEXT("../bin/textures/guiTextures.bmp"));
00104         player.loadBallLabels();
00105 
00106         pIControl backgroundLabel = gui.createLabel(0,0, 384, 1024, 99);
00107         gui.addControl(backgroundLabel);
00108 
00109         pIControl closeButton = gui.createButton(64, 620, 256, 128, &RenderListener::guiCallback, 3);
00110         closeButton->setName(TEXT("close"));
00111         gui.addControl(closeButton);
00112 
00113         pIControl fastBallButton = gui.createButton(64, 20, 256, 128, &RenderListener::guiCallback, 0);
00114         fastBallButton->setName(TEXT("fast"));
00115         gui.addControl(fastBallButton);
00116 
00117         pIControl strongBallButton = gui.createButton(64, 190, 256, 128, &RenderListener::guiCallback, 1);
00118         strongBallButton->setName(TEXT("strong"));
00119         gui.addControl(strongBallButton);
00120 
00121         pIControl explosiveBallButton = gui.createButton(64, 360, 256, 128, &RenderListener::guiCallback, 2);
00122         explosiveBallButton->setName(TEXT("explosive"));
00123         gui.addControl(explosiveBallButton);
00124 
00125         pIControl shotsLeftLabel = gui.createLabel(820, 0, 176, 32, 98);
00126         shotsLeftLabel->setName(TEXT("HUD"));
00127         gui.addControl(shotsLeftLabel);
00128 
00129         pIControl winLabel = gui.createLabel(512, 150, 256, 128, 0);
00130         pIControl gameOver = gui.createLabel(512, 150, 256, 128, 0);
00131         pIControl ballsLeftLabel = gui.createLabel(1000, 0, 16, 32, 10);
00132         ballsLeftLabel->setName(TEXT("HUD"));
00133         gui.addControl(ballsLeftLabel);
00134 
00135         gui.setUpStatusLabels();
00136 
00137         player.setWinLabel(winLabel);
00138         player.setGameOver(gameOver);
00139         player.setBallsLeftLabel(ballsLeftLabel);
00140 
00141         render->keepCurrentGeometry();
00142         player.loadNewLevel(0);
00143 
00144         // start main loop
00145         window->loop();
00146 
00147         // deactivate device inputs
00148         window->deactivateDevice(mouse);
00149         window->deactivateDevice(keyboard);
00150 
00151         // free audio data
00152         audio->free(explodeSound);
00153         audio->free(explodeBuffer);
00154 
00155         // uninit modules
00156         audio ->uninit();
00157         render->uninit();
00158         physic->uninit();
00159         window->uninit();
00160 
00161         // free
00162         windowModule.free(window);
00163         renderModule.free(render);
00164         physicModule.free(physic);
00165         audioModule.free(audio);
00166 
00167         return 0;
00168 }

Generated on Fri Jun 18 2010 17:48:39 for Cannonball by  doxygen 1.7.0