absence_thelab

view src/demo.cpp @ 1:4d5933c261c3

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