absence_thelab

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/demo.cpp	Thu Oct 23 01:46:07 2014 +0300
     1.3 @@ -0,0 +1,242 @@
     1.4 +#include "nwt/startup.h"
     1.5 +#include "nwt/nucwin.h"
     1.6 +#include "3deng/3deng.h"
     1.7 +#include "demosystem/demosys.h"
     1.8 +#include "fmod.h"
     1.9 +
    1.10 +// parts
    1.11 +#include "beginpart.h"
    1.12 +#include "dungeonpart.h"
    1.13 +#include "treepart.h"
    1.14 +#include "tunnelpart.h"
    1.15 +#include "hellpart.h"
    1.16 +#include "greetspart.h"
    1.17 +#include "demonpart.h"
    1.18 +
    1.19 +int ScreenX;
    1.20 +int ScreenY;
    1.21 +
    1.22 +Widget *win;
    1.23 +Engine3D eng3d;
    1.24 +GraphicsContext *gc;
    1.25 +DemoSystem *demo;
    1.26 +FMUSIC_MODULE *mod;
    1.27 +
    1.28 +
    1.29 +// parts
    1.30 +DungeonPart *dungeonpart;
    1.31 +BeginPart *beginpart;
    1.32 +TreePart *treepart;
    1.33 +TunnelPart *tunnelpart;
    1.34 +HellPart *hellpart;
    1.35 +GreetsPart *greetspart;
    1.36 +DemonPart *demonpart;
    1.37 +
    1.38 +bool Init();
    1.39 +void MainLoop();
    1.40 +void CleanUp();
    1.41 +int KeyHandler(Widget *win, int key);
    1.42 +int CloseHandler(Widget *win, int arg);
    1.43 +int MouseHandler(Widget *win, int x, int y, bool left, bool middle, bool right);
    1.44 +int WheelHandler(Widget *win, int x, int y, int rot);
    1.45 +
    1.46 +
    1.47 +int main() {
    1.48 +
    1.49 +	win = NWCreateWindow("The Lab Demos", NWT_CENTERX, NWT_CENTERY, 100, 50, 0);
    1.50 +	SetMainLoopFunc(MainLoop);
    1.51 +	SetHandler(HANDLER_KEY, KeyHandler);
    1.52 +	SetHandler(HANDLER_CLOSE, CloseHandler);
    1.53 +	
    1.54 +	SetHandler(HANDLER_MOUSE, (HandlerFunctionPtr)MouseHandler);
    1.55 +	SetHandler(HANDLER_WHEEL, (HandlerFunctionPtr)WheelHandler);
    1.56 +
    1.57 +
    1.58 +	if(!Init()) return 0;
    1.59 +
    1.60 +	return NWMainLoop(RealTimeLoop);
    1.61 +}
    1.62 +
    1.63 +bool Init() {
    1.64 +
    1.65 +	ContextInitParameters cip;
    1.66 +	try {
    1.67 +		cip = eng3d.LoadContextParamsConfigFile("n3dinit.conf");
    1.68 +		gc = eng3d.CreateGraphicsContext(win, 0, &cip);
    1.69 +	}
    1.70 +	catch(EngineInitException except) {
    1.71 +		MessageBox(win, except.GetReason().c_str(), "Fatal Error", MB_OK | MB_ICONSTOP);
    1.72 +		return false;
    1.73 +	}
    1.74 +	ScreenX = cip.x;
    1.75 +	ScreenY = cip.y;
    1.76 +	NWResize(win, ScreenX, ScreenY);
    1.77 +	NWResizeClientArea(win, WS_OVERLAPPEDWINDOW);
    1.78 +
    1.79 +	ShowCursor(false);
    1.80 +
    1.81 +	// Loading pics....
    1.82 +	Texture *loading[9];
    1.83 +	loading[0] = gc->texman->AddTexture("data/textures/Loading/loading0.jpg");
    1.84 +	loading[1] = gc->texman->AddTexture("data/textures/Loading/loading1.jpg");
    1.85 +	loading[2] = gc->texman->AddTexture("data/textures/Loading/loading2.jpg");
    1.86 +	loading[3] = gc->texman->AddTexture("data/textures/Loading/loading3.jpg");
    1.87 +	loading[4] = gc->texman->AddTexture("data/textures/Loading/loading4.jpg");
    1.88 +	loading[5] = gc->texman->AddTexture("data/textures/Loading/loading5.jpg");
    1.89 +	loading[6] = gc->texman->AddTexture("data/textures/Loading/loading6.jpg");
    1.90 +	loading[7] = gc->texman->AddTexture("data/textures/Loading/loading7.jpg");
    1.91 +	loading[8] = gc->texman->AddTexture("data/textures/Loading/loading8.jpg");
    1.92 +
    1.93 +	demo = new DemoSystem(gc);
    1.94 +	SceneLoader::SetGraphicsContext(gc);
    1.95 +
    1.96 +	Object *quad = new Object(gc);
    1.97 +	quad->CreatePlane(4.0f, 0);
    1.98 +	quad->Scale(1.3333f, 1.0f, 1.0f);
    1.99 +	quad->material = Material(1.0f, 1.0f, 1.0f);
   1.100 +
   1.101 +	Matrix4x4 ViewMat;
   1.102 +	ViewMat.Translate(0.0f, 0.0f, 3.6f);
   1.103 +	gc->SetViewMatrix(ViewMat);
   1.104 +	
   1.105 +	gc->SetZBuffering(false);
   1.106 +	gc->SetLighting(false);
   1.107 +
   1.108 +	quad->material.SetTexture(loading[0], TextureMap);
   1.109 +	quad->Render();
   1.110 +	gc->Flip();
   1.111 +	beginpart = new BeginPart(gc);
   1.112 +	beginpart->SetTimingRel(0, 11000);
   1.113 +	demo->AddPart(beginpart);
   1.114 +
   1.115 +	quad->material.SetTexture(loading[1], TextureMap);
   1.116 +	quad->Render();
   1.117 +	gc->Flip();
   1.118 +	dungeonpart = new DungeonPart(gc);
   1.119 +	dungeonpart->SetTimingRel(11000, 75000);
   1.120 +	demo->AddPart(dungeonpart);
   1.121 +
   1.122 +	quad->material.SetTexture(loading[2], TextureMap);
   1.123 +	quad->Render();
   1.124 +	gc->Flip();
   1.125 +	treepart = new TreePart(gc);
   1.126 +	treepart->SetTimingRel(85900, 40000);
   1.127 +    demo->AddPart(treepart);
   1.128 +
   1.129 +	quad->material.SetTexture(loading[3], TextureMap);
   1.130 +	quad->Render();
   1.131 +	gc->Flip();
   1.132 +	tunnelpart = new TunnelPart(gc);
   1.133 +	tunnelpart->SetTimingRel(125900, 30000);
   1.134 +	demo->AddPart(tunnelpart);
   1.135 +
   1.136 +	quad->material.SetTexture(loading[4], TextureMap);
   1.137 +	quad->Render();
   1.138 +	gc->Flip();
   1.139 +	hellpart = new HellPart(gc);
   1.140 +	hellpart->SetTimingRel(155900, 40000);
   1.141 +	demo->AddPart(hellpart);
   1.142 +
   1.143 +	quad->material.SetTexture(loading[5], TextureMap);
   1.144 +	quad->Render();
   1.145 +	gc->Flip();
   1.146 +	greetspart = new GreetsPart(gc);
   1.147 +	greetspart->SetTimingRel(196000, 12000);
   1.148 +	demo->AddPart(greetspart);
   1.149 +
   1.150 +	quad->material.SetTexture(loading[6], TextureMap);
   1.151 +	quad->Render();
   1.152 +	gc->Flip();
   1.153 +	demonpart = new DemonPart(gc);
   1.154 +	demonpart->SetTimingRel(208000, 2000);
   1.155 +	demo->AddPart(demonpart);
   1.156 +
   1.157 +	quad->material.SetTexture(loading[7], TextureMap);
   1.158 +	quad->Render();
   1.159 +	gc->Flip();
   1.160 +	FSOUND_SetHWND(win);
   1.161 +	FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
   1.162 +	FSOUND_SetBufferSize(200);
   1.163 +	FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS);
   1.164 +	mod = FMUSIC_LoadSong("data/GOTH03.XM");
   1.165 +	FMUSIC_SetMasterVolume(mod, 250);
   1.166 +
   1.167 +	quad->material.SetTexture(loading[8], TextureMap);
   1.168 +	quad->Render();
   1.169 +	gc->Flip();
   1.170 +	gc->SetBackfaceCulling(true);
   1.171 +	gc->SetZBuffering(true);
   1.172 +	gc->SetLighting(true);
   1.173 +
   1.174 +	Sleep(800);
   1.175 +	
   1.176 +	demo->Run();
   1.177 +
   1.178 +	FMUSIC_PlaySong(mod);
   1.179 +
   1.180 +	return true;
   1.181 +}
   1.182 +
   1.183 +void MainLoop() {
   1.184 +	demo->Update();
   1.185 +	gc->Flip();
   1.186 +}
   1.187 +
   1.188 +void CleanUp() {
   1.189 +	ShowCursor(true);
   1.190 +	FMUSIC_FreeSong(mod);
   1.191 +	FSOUND_Close();
   1.192 +	delete demo;
   1.193 +}
   1.194 +
   1.195 +///////// handlers /////////
   1.196 +int KeyHandler(Widget *win, int key) {
   1.197 +	switch(key) {
   1.198 +	case VK_ESCAPE:
   1.199 +		NWCloseWindow(win);
   1.200 +		break;
   1.201 +
   1.202 +	}
   1.203 +	return 0;
   1.204 +}
   1.205 +
   1.206 +int CloseHandler(Widget *win, int arg) {
   1.207 +	CleanUp();
   1.208 +	return 0;
   1.209 +}
   1.210 +
   1.211 +int WheelHandler(Widget *win, int x, int y, int rot) {
   1.212 +/*	float tr = rot > 0 ? 0.05f : -0.05f;
   1.213 +
   1.214 +	Camera *cam = const_cast<Camera*>(demo->GetActivePath()->GetScene()->GetActiveCamera());
   1.215 +	cam->SetCameraPath(0, 0, 0, 0);
   1.216 +
   1.217 +	cam->Zoom(tr);
   1.218 +*/	
   1.219 +	return 0;
   1.220 +}
   1.221 +
   1.222 +
   1.223 +int MouseHandler(Widget *win, int x, int y, bool left, bool middle, bool right) {
   1.224 +/*	static POINT PrevPos;
   1.225 +	POINT MoveDiff;
   1.226 +
   1.227 +	if(right) {
   1.228 +		MoveDiff.x = x - PrevPos.x;
   1.229 +		MoveDiff.y = y - PrevPos.y;
   1.230 +		float xangle = (float)MoveDiff.x / 50.0f;
   1.231 +		float dy = (float)MoveDiff.y;
   1.232 +
   1.233 +		Camera *cam = const_cast<Camera*>(demo->GetActivePath()->GetScene()->GetActiveCamera());
   1.234 +		cam->SetCameraPath(0, 0, 0, 0);
   1.235 +
   1.236 +		cam->Rotate(0.0f, xangle, 0.0f);
   1.237 +		cam->SetPosition(cam->GetPosition() + Vector3(0.0f, dy, 0.0f));
   1.238 +	}
   1.239 +
   1.240 +
   1.241 +	PrevPos.x = x;
   1.242 +	PrevPos.y = y;
   1.243 +*/
   1.244 +	return 0;
   1.245 +}
   1.246 \ No newline at end of file