absence_thelab

annotate src/demo.cpp @ 0:1cffe3409164

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 01:46:07 +0300
parents
children
rev   line source
nuclear@0 1 #include "nwt/startup.h"
nuclear@0 2 #include "nwt/nucwin.h"
nuclear@0 3 #include "3deng/3deng.h"
nuclear@0 4 #include "demosystem/demosys.h"
nuclear@0 5 #include "fmod.h"
nuclear@0 6
nuclear@0 7 // parts
nuclear@0 8 #include "beginpart.h"
nuclear@0 9 #include "dungeonpart.h"
nuclear@0 10 #include "treepart.h"
nuclear@0 11 #include "tunnelpart.h"
nuclear@0 12 #include "hellpart.h"
nuclear@0 13 #include "greetspart.h"
nuclear@0 14 #include "demonpart.h"
nuclear@0 15
nuclear@0 16 int ScreenX;
nuclear@0 17 int ScreenY;
nuclear@0 18
nuclear@0 19 Widget *win;
nuclear@0 20 Engine3D eng3d;
nuclear@0 21 GraphicsContext *gc;
nuclear@0 22 DemoSystem *demo;
nuclear@0 23 FMUSIC_MODULE *mod;
nuclear@0 24
nuclear@0 25
nuclear@0 26 // parts
nuclear@0 27 DungeonPart *dungeonpart;
nuclear@0 28 BeginPart *beginpart;
nuclear@0 29 TreePart *treepart;
nuclear@0 30 TunnelPart *tunnelpart;
nuclear@0 31 HellPart *hellpart;
nuclear@0 32 GreetsPart *greetspart;
nuclear@0 33 DemonPart *demonpart;
nuclear@0 34
nuclear@0 35 bool Init();
nuclear@0 36 void MainLoop();
nuclear@0 37 void CleanUp();
nuclear@0 38 int KeyHandler(Widget *win, int key);
nuclear@0 39 int CloseHandler(Widget *win, int arg);
nuclear@0 40 int MouseHandler(Widget *win, int x, int y, bool left, bool middle, bool right);
nuclear@0 41 int WheelHandler(Widget *win, int x, int y, int rot);
nuclear@0 42
nuclear@0 43
nuclear@0 44 int main() {
nuclear@0 45
nuclear@0 46 win = NWCreateWindow("The Lab Demos", NWT_CENTERX, NWT_CENTERY, 100, 50, 0);
nuclear@0 47 SetMainLoopFunc(MainLoop);
nuclear@0 48 SetHandler(HANDLER_KEY, KeyHandler);
nuclear@0 49 SetHandler(HANDLER_CLOSE, CloseHandler);
nuclear@0 50
nuclear@0 51 SetHandler(HANDLER_MOUSE, (HandlerFunctionPtr)MouseHandler);
nuclear@0 52 SetHandler(HANDLER_WHEEL, (HandlerFunctionPtr)WheelHandler);
nuclear@0 53
nuclear@0 54
nuclear@0 55 if(!Init()) return 0;
nuclear@0 56
nuclear@0 57 return NWMainLoop(RealTimeLoop);
nuclear@0 58 }
nuclear@0 59
nuclear@0 60 bool Init() {
nuclear@0 61
nuclear@0 62 ContextInitParameters cip;
nuclear@0 63 try {
nuclear@0 64 cip = eng3d.LoadContextParamsConfigFile("n3dinit.conf");
nuclear@0 65 gc = eng3d.CreateGraphicsContext(win, 0, &cip);
nuclear@0 66 }
nuclear@0 67 catch(EngineInitException except) {
nuclear@0 68 MessageBox(win, except.GetReason().c_str(), "Fatal Error", MB_OK | MB_ICONSTOP);
nuclear@0 69 return false;
nuclear@0 70 }
nuclear@0 71 ScreenX = cip.x;
nuclear@0 72 ScreenY = cip.y;
nuclear@0 73 NWResize(win, ScreenX, ScreenY);
nuclear@0 74 NWResizeClientArea(win, WS_OVERLAPPEDWINDOW);
nuclear@0 75
nuclear@0 76 ShowCursor(false);
nuclear@0 77
nuclear@0 78 // Loading pics....
nuclear@0 79 Texture *loading[9];
nuclear@0 80 loading[0] = gc->texman->AddTexture("data/textures/Loading/loading0.jpg");
nuclear@0 81 loading[1] = gc->texman->AddTexture("data/textures/Loading/loading1.jpg");
nuclear@0 82 loading[2] = gc->texman->AddTexture("data/textures/Loading/loading2.jpg");
nuclear@0 83 loading[3] = gc->texman->AddTexture("data/textures/Loading/loading3.jpg");
nuclear@0 84 loading[4] = gc->texman->AddTexture("data/textures/Loading/loading4.jpg");
nuclear@0 85 loading[5] = gc->texman->AddTexture("data/textures/Loading/loading5.jpg");
nuclear@0 86 loading[6] = gc->texman->AddTexture("data/textures/Loading/loading6.jpg");
nuclear@0 87 loading[7] = gc->texman->AddTexture("data/textures/Loading/loading7.jpg");
nuclear@0 88 loading[8] = gc->texman->AddTexture("data/textures/Loading/loading8.jpg");
nuclear@0 89
nuclear@0 90 demo = new DemoSystem(gc);
nuclear@0 91 SceneLoader::SetGraphicsContext(gc);
nuclear@0 92
nuclear@0 93 Object *quad = new Object(gc);
nuclear@0 94 quad->CreatePlane(4.0f, 0);
nuclear@0 95 quad->Scale(1.3333f, 1.0f, 1.0f);
nuclear@0 96 quad->material = Material(1.0f, 1.0f, 1.0f);
nuclear@0 97
nuclear@0 98 Matrix4x4 ViewMat;
nuclear@0 99 ViewMat.Translate(0.0f, 0.0f, 3.6f);
nuclear@0 100 gc->SetViewMatrix(ViewMat);
nuclear@0 101
nuclear@0 102 gc->SetZBuffering(false);
nuclear@0 103 gc->SetLighting(false);
nuclear@0 104
nuclear@0 105 quad->material.SetTexture(loading[0], TextureMap);
nuclear@0 106 quad->Render();
nuclear@0 107 gc->Flip();
nuclear@0 108 beginpart = new BeginPart(gc);
nuclear@0 109 beginpart->SetTimingRel(0, 11000);
nuclear@0 110 demo->AddPart(beginpart);
nuclear@0 111
nuclear@0 112 quad->material.SetTexture(loading[1], TextureMap);
nuclear@0 113 quad->Render();
nuclear@0 114 gc->Flip();
nuclear@0 115 dungeonpart = new DungeonPart(gc);
nuclear@0 116 dungeonpart->SetTimingRel(11000, 75000);
nuclear@0 117 demo->AddPart(dungeonpart);
nuclear@0 118
nuclear@0 119 quad->material.SetTexture(loading[2], TextureMap);
nuclear@0 120 quad->Render();
nuclear@0 121 gc->Flip();
nuclear@0 122 treepart = new TreePart(gc);
nuclear@0 123 treepart->SetTimingRel(85900, 40000);
nuclear@0 124 demo->AddPart(treepart);
nuclear@0 125
nuclear@0 126 quad->material.SetTexture(loading[3], TextureMap);
nuclear@0 127 quad->Render();
nuclear@0 128 gc->Flip();
nuclear@0 129 tunnelpart = new TunnelPart(gc);
nuclear@0 130 tunnelpart->SetTimingRel(125900, 30000);
nuclear@0 131 demo->AddPart(tunnelpart);
nuclear@0 132
nuclear@0 133 quad->material.SetTexture(loading[4], TextureMap);
nuclear@0 134 quad->Render();
nuclear@0 135 gc->Flip();
nuclear@0 136 hellpart = new HellPart(gc);
nuclear@0 137 hellpart->SetTimingRel(155900, 40000);
nuclear@0 138 demo->AddPart(hellpart);
nuclear@0 139
nuclear@0 140 quad->material.SetTexture(loading[5], TextureMap);
nuclear@0 141 quad->Render();
nuclear@0 142 gc->Flip();
nuclear@0 143 greetspart = new GreetsPart(gc);
nuclear@0 144 greetspart->SetTimingRel(196000, 12000);
nuclear@0 145 demo->AddPart(greetspart);
nuclear@0 146
nuclear@0 147 quad->material.SetTexture(loading[6], TextureMap);
nuclear@0 148 quad->Render();
nuclear@0 149 gc->Flip();
nuclear@0 150 demonpart = new DemonPart(gc);
nuclear@0 151 demonpart->SetTimingRel(208000, 2000);
nuclear@0 152 demo->AddPart(demonpart);
nuclear@0 153
nuclear@0 154 quad->material.SetTexture(loading[7], TextureMap);
nuclear@0 155 quad->Render();
nuclear@0 156 gc->Flip();
nuclear@0 157 FSOUND_SetHWND(win);
nuclear@0 158 FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
nuclear@0 159 FSOUND_SetBufferSize(200);
nuclear@0 160 FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS);
nuclear@0 161 mod = FMUSIC_LoadSong("data/GOTH03.XM");
nuclear@0 162 FMUSIC_SetMasterVolume(mod, 250);
nuclear@0 163
nuclear@0 164 quad->material.SetTexture(loading[8], TextureMap);
nuclear@0 165 quad->Render();
nuclear@0 166 gc->Flip();
nuclear@0 167 gc->SetBackfaceCulling(true);
nuclear@0 168 gc->SetZBuffering(true);
nuclear@0 169 gc->SetLighting(true);
nuclear@0 170
nuclear@0 171 Sleep(800);
nuclear@0 172
nuclear@0 173 demo->Run();
nuclear@0 174
nuclear@0 175 FMUSIC_PlaySong(mod);
nuclear@0 176
nuclear@0 177 return true;
nuclear@0 178 }
nuclear@0 179
nuclear@0 180 void MainLoop() {
nuclear@0 181 demo->Update();
nuclear@0 182 gc->Flip();
nuclear@0 183 }
nuclear@0 184
nuclear@0 185 void CleanUp() {
nuclear@0 186 ShowCursor(true);
nuclear@0 187 FMUSIC_FreeSong(mod);
nuclear@0 188 FSOUND_Close();
nuclear@0 189 delete demo;
nuclear@0 190 }
nuclear@0 191
nuclear@0 192 ///////// handlers /////////
nuclear@0 193 int KeyHandler(Widget *win, int key) {
nuclear@0 194 switch(key) {
nuclear@0 195 case VK_ESCAPE:
nuclear@0 196 NWCloseWindow(win);
nuclear@0 197 break;
nuclear@0 198
nuclear@0 199 }
nuclear@0 200 return 0;
nuclear@0 201 }
nuclear@0 202
nuclear@0 203 int CloseHandler(Widget *win, int arg) {
nuclear@0 204 CleanUp();
nuclear@0 205 return 0;
nuclear@0 206 }
nuclear@0 207
nuclear@0 208 int WheelHandler(Widget *win, int x, int y, int rot) {
nuclear@0 209 /* float tr = rot > 0 ? 0.05f : -0.05f;
nuclear@0 210
nuclear@0 211 Camera *cam = const_cast<Camera*>(demo->GetActivePath()->GetScene()->GetActiveCamera());
nuclear@0 212 cam->SetCameraPath(0, 0, 0, 0);
nuclear@0 213
nuclear@0 214 cam->Zoom(tr);
nuclear@0 215 */
nuclear@0 216 return 0;
nuclear@0 217 }
nuclear@0 218
nuclear@0 219
nuclear@0 220 int MouseHandler(Widget *win, int x, int y, bool left, bool middle, bool right) {
nuclear@0 221 /* static POINT PrevPos;
nuclear@0 222 POINT MoveDiff;
nuclear@0 223
nuclear@0 224 if(right) {
nuclear@0 225 MoveDiff.x = x - PrevPos.x;
nuclear@0 226 MoveDiff.y = y - PrevPos.y;
nuclear@0 227 float xangle = (float)MoveDiff.x / 50.0f;
nuclear@0 228 float dy = (float)MoveDiff.y;
nuclear@0 229
nuclear@0 230 Camera *cam = const_cast<Camera*>(demo->GetActivePath()->GetScene()->GetActiveCamera());
nuclear@0 231 cam->SetCameraPath(0, 0, 0, 0);
nuclear@0 232
nuclear@0 233 cam->Rotate(0.0f, xangle, 0.0f);
nuclear@0 234 cam->SetPosition(cam->GetPosition() + Vector3(0.0f, dy, 0.0f));
nuclear@0 235 }
nuclear@0 236
nuclear@0 237
nuclear@0 238 PrevPos.x = x;
nuclear@0 239 PrevPos.y = y;
nuclear@0 240 */
nuclear@0 241 return 0;
nuclear@0 242 }