Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 35.62 KB | None | 0 0
  1. Index: src/fpsgame/game.h
  2. ===================================================================
  3. --- src/fpsgame/game.h  (revision 3611)
  4. +++ src/fpsgame/game.h  (working copy)
  5. @@ -46,6 +46,7 @@
  6.      PLATFORM,                   // attr1 = angle, attr2 = idx, attr3 = tag, attr4 = speed
  7.      ELEVATOR,                   // attr1 = angle, attr2 = idx, attr3 = tag, attr4 = speed
  8.      FLAG,                       // attr1 = angle, attr2 = team
  9. +    CAMERA,
  10.      MAXENTTYPES
  11.  };
  12.  
  13. @@ -789,5 +790,14 @@
  14.      extern bool delayspawn(int type);
  15.  }
  16.  
  17. +namespace camera
  18. +{
  19. +    extern bool cutscene;
  20. +
  21. +    extern void cleanup();
  22. +    extern void update();
  23. +    extern void render(int w, int h);
  24. +}
  25. +
  26.  #endif
  27.  
  28. Index: src/fpsgame/entities.cpp
  29. ===================================================================
  30. --- src/fpsgame/entities.cpp    (revision 3611)
  31. +++ src/fpsgame/entities.cpp    (working copy)
  32. @@ -62,7 +62,7 @@
  33.              "checkpoint",
  34.              NULL, NULL,
  35.              NULL, NULL,
  36. -            NULL
  37. +            NULL, NULL
  38.          };
  39.          return entmdlnames[type];
  40.      }
  41. @@ -628,7 +628,7 @@
  42.              "base", "respawnpoint",
  43.              "box", "barrel",
  44.              "platform", "elevator",
  45. -            "flag",
  46. +            "flag", "camera",
  47.              "", "", "", "",
  48.          };
  49.          return i>=0 && size_t(i)<sizeof(entnames)/sizeof(entnames[0]) ? entnames[i] : "";
  50. Index: src/fpsgame/fps.cpp
  51. ===================================================================
  52. --- src/fpsgame/fps.cpp (revision 3611)
  53. +++ src/fpsgame/fps.cpp (working copy)
  54. @@ -249,6 +249,7 @@
  55.          gets2c();
  56.          updatemovables(curtime);
  57.          updatemonsters(curtime);
  58. +        camera::update();
  59.          if(player1->state==CS_DEAD)
  60.          {
  61.              if(player1->ragdoll) moveragdoll(player1);
  62. @@ -448,7 +449,7 @@
  63.  
  64.              showscores(true);
  65.              disablezoom();
  66. -
  67. +
  68.              if(identexists("intermission")) execute("intermission");
  69.          }
  70.      }
  71. @@ -583,13 +584,14 @@
  72.      {
  73.          ai::savewaypoints();
  74.          ai::clearwaypoints(true);
  75. +        camera::cleanup();
  76.  
  77.          respawnent = -1; // so we don't respawn at an old spot
  78.          if(!m_mp(gamemode)) spawnplayer(player1);
  79.          else findplayerspawn(player1, -1);
  80.          entities::resetspawns();
  81.          copystring(clientmap, name ? name : "");
  82. -
  83. +
  84.          sendmapinfo();
  85.      }
  86.  
  87. @@ -808,30 +810,45 @@
  88.  
  89.      void gameplayhud(int w, int h)
  90.      {
  91. -        glPushMatrix();
  92. -        glScalef(h/1800.0f, h/1800.0f, 1);
  93. +        if(camera::cutscene)
  94. +        {
  95. +            glPushMatrix();
  96. +            float scale = min (w / 1600.0f, h / 1200.0f);
  97. +            glScalef(scale, scale, 1);
  98.  
  99. -        if(player1->state==CS_SPECTATOR)
  100. +            float right = w / scale, bottom = h / scale; // top and left are ALWAYS 0
  101. +
  102. +            camera::render(ceil(right), ceil(bottom));
  103. +            glPopMatrix();
  104. +            return;
  105. +        }
  106. +        else
  107.          {
  108. -            int pw, ph, tw, th, fw, fh;
  109. -            text_bounds("  ", pw, ph);
  110. -            text_bounds("SPECTATOR", tw, th);
  111. -            th = max(th, ph);
  112. -            fpsent *f = followingplayer();
  113. -            text_bounds(f ? colorname(f) : " ", fw, fh);
  114. -            fh = max(fh, ph);
  115. -            draw_text("SPECTATOR", w*1800/h - tw - pw, 1650 - th - fh);
  116. -            if(f) draw_text(colorname(f), w*1800/h - fw - pw, 1650 - fh);
  117. -        }
  118. +            glPushMatrix();
  119. +            glScalef(h/1800.0f, h/1800.0f, 1);
  120.  
  121. -        fpsent *d = hudplayer();
  122. -        if(d->state!=CS_EDITING)
  123. -        {
  124. -            if(d->state!=CS_SPECTATOR) drawhudicons(d);
  125. -            if(cmode) cmode->drawhud(d, w, h);
  126. +            if(player1->state==CS_SPECTATOR)
  127. +            {
  128. +                int pw, ph, tw, th, fw, fh;
  129. +                text_bounds("  ", pw, ph);
  130. +                text_bounds("SPECTATOR", tw, th);
  131. +                th = max(th, ph);
  132. +                fpsent *f = followingplayer();
  133. +                text_bounds(f ? colorname(f) : " ", fw, fh);
  134. +                fh = max(fh, ph);
  135. +                draw_text("SPECTATOR", w*1800/h - tw - pw, 1650 - th - fh);
  136. +                if(f) draw_text(colorname(f), w*1800/h - fw - pw, 1650 - fh);
  137. +            }
  138. +
  139. +            fpsent *d = hudplayer();
  140. +            if(d->state!=CS_EDITING)
  141. +            {
  142. +                if(d->state!=CS_SPECTATOR) drawhudicons(d);
  143. +                if(cmode) cmode->drawhud(d, w, h);
  144. +            }
  145. +
  146. +            glPopMatrix();
  147.          }
  148. -
  149. -        glPopMatrix();
  150.      }
  151.  
  152.      int clipconsole(int w, int h)
  153. Index: src/fpsgame/camera.cpp
  154. ===================================================================
  155. --- src/fpsgame/camera.cpp  (revision 0)
  156. +++ src/fpsgame/camera.cpp  (revision 0)
  157. @@ -0,0 +1,778 @@
  158. +#include "game.h"
  159. +
  160. +namespace camera
  161. +{
  162. +    struct action
  163. +    {
  164. +        int startmillis;
  165. +        int duration;
  166. +        const uint *successors;
  167. +
  168. +        action(int d = 0, const char *s = NULL) : startmillis(lastmillis), duration(d), successors(s && *s ? compilecode(s) : NULL) {}
  169. +        virtual ~action() {delete[] successors;}
  170. +
  171. +        float multiplier(bool total = false)
  172. +        {
  173. +            if(!duration)
  174. +                return 1;
  175. +
  176. +            if(total)
  177. +                return min<float>(1, (lastmillis - startmillis) / (float)duration);
  178. +            else
  179. +            {
  180. +                int elapsed = curtime;
  181. +                if(startmillis + duration - lastmillis < curtime)
  182. +                    elapsed = startmillis + duration - lastmillis;
  183. +                return (float) elapsed / duration;
  184. +
  185. +            }
  186. +        }
  187. +        virtual bool update()
  188. +        {
  189. +            if(startmillis + duration <= lastmillis)
  190. +            {
  191. +                if(successors)
  192. +                    execute(successors);
  193. +                return false;
  194. +            }
  195. +            return true;
  196. +        }
  197. +        virtual void render(int w, int h) {}
  198. +        virtual void debug(int w, int h, int &hoffset, bool type = false)
  199. +        {
  200. +            if(type)
  201. +            {
  202. +                draw_text("Type: action/delay", 100, 0 + hoffset);
  203. +                hoffset += 64;
  204. +            }
  205. +
  206. +            draw_textf("Duration: %i (%f%%)", 100, 0 + hoffset, duration, (lastmillis - startmillis) / (float)duration);
  207. +            draw_textf("Children: %p", 100, 64 + hoffset, successors);
  208. +
  209. +            hoffset += 64 * 3;
  210. +        }
  211. +    };
  212. +
  213. +    vector <action *> pending;
  214. +    int suboffset = 0;
  215. +    vector <action *> subtitles; //subtitles are tracked independantly, and rendered in reverse, always on top
  216. +    physent camera;
  217. +    physent *attached = NULL;
  218. +    bool cutscene = false;
  219. +    bool cancelled = false;
  220. +
  221. +    void cleanup()
  222. +    {
  223. +        cutscene = false;
  224. +        pending.deletecontents();
  225. +        subtitles.deletecontents();
  226. +    }
  227. +
  228. +    void update()
  229. +    {
  230. +        if((subtitles.length() || pending.length()) && !cutscene) cutscene = true;
  231. +        if(cutscene)
  232. +        {
  233. +            attached = NULL;
  234. +            loopv(pending)
  235. +            {
  236. +                if(!pending[i]->update())
  237. +                {
  238. +                    delete pending[i];
  239. +                    pending.remove(i);
  240. +                    i--;
  241. +                }
  242. +            }
  243. +            loopv(subtitles)
  244. +            {
  245. +                if(!subtitles[i]->update())
  246. +                {
  247. +                    delete subtitles[i];
  248. +                    subtitles.remove(i);
  249. +                    i--;
  250. +                }
  251. +            }
  252. +            if(!pending.length() && !subtitles.length())
  253. +            {
  254. +                camera = *game::player1;
  255. +                cutscene = false;
  256. +            }
  257. +        }
  258. +    }
  259. +
  260. +    VARP(dbgcamera, 0, 0, 1);
  261. +
  262. +    void render(int w, int h)
  263. +    {
  264. +        loopv(pending)
  265. +            pending[i]->render(w, h);
  266. +        suboffset = 0;
  267. +        loopvrev(subtitles)
  268. +            subtitles[i]->render(w, h);
  269. +
  270. +        glPushMatrix();
  271. +        glScalef(.3, .3, 1);
  272. +
  273. +        int offset = 128;
  274. +        if(dbgcamera)
  275. +        {
  276. +            loopv(pending)
  277. +                pending[i]->debug(w, h, offset, true);
  278. +            loopv(subtitles)
  279. +                subtitles[i]->debug(w, h, offset, true);
  280. +        }
  281. +        glPopMatrix();
  282. +    }
  283. +
  284. +    struct cond : action
  285. +    {
  286. +        const uint *test;
  287. +
  288. +        cond(const char *t, const char *s) : action(0, s), test(t && *t ? compilecode(t) : NULL) {}
  289. +        ~cond() { delete[] test;}
  290. +
  291. +        bool update()
  292. +        {
  293. +            if(!test || execute(test))
  294. +            {
  295. +                if(successors) execute(successors);
  296. +                return false;
  297. +            }
  298. +
  299. +            return true;
  300. +        }
  301. +
  302. +        void debug(int w, int h, int &hoffset, bool type)
  303. +        {
  304. +            if(type)
  305. +            {
  306. +                draw_text("Type: Test", 100, 0 + hoffset);
  307. +                hoffset += 64;
  308. +            }
  309. +
  310. +            draw_textf("Test: %p", 100, 0 + hoffset, test);
  311. +            draw_textf("Children: %p", 100, 64 + hoffset, successors);
  312. +            hoffset += 192;
  313. +        }
  314. +    };
  315. +
  316. +    struct iterate : cond
  317. +    {
  318. +        int limit;
  319. +        int i;
  320. +
  321. +        iterate(const char *t, int l, int d, const char *s) : cond(t, s), limit(l), i(0) { duration = d;}
  322. +        ~iterate() {}
  323. +
  324. +        bool update()
  325. +        {
  326. +            if(lastmillis - startmillis >= duration)
  327. +            {
  328. +                if(limit)
  329. +                    i++;
  330. +
  331. +                bool res = cond::update();
  332. +
  333. +                if(res || (limit && i == limit))
  334. +                    return false;
  335. +
  336. +                startmillis += duration;
  337. +            }
  338. +
  339. +            return true;
  340. +        }
  341. +
  342. +        void debug(int w, int h, int &hoffset, bool type)
  343. +        {
  344. +            if(type)
  345. +            {
  346. +                draw_text("Type: Loop", 100, 0 + hoffset);
  347. +                hoffset += 64;
  348. +            }
  349. +
  350. +            draw_textf("Test: %p", 100, 0 + hoffset);
  351. +            draw_textf("Loop: %i/%i", 100, 64 + hoffset, i, limit);
  352. +            hoffset += 128;
  353. +
  354. +            action::debug(w, h, hoffset);
  355. +        }
  356. +    };
  357. +
  358. +    struct subtitle : action
  359. +    {
  360. +        const char *text;
  361. +        vec color;
  362. +
  363. +        subtitle(const char *t, float r, float g, float b, int d, const char *s) : action(d, s), text(t && *t ? newstring(t) : newstring("No Text")), color(vec(r, g, b)) {}
  364. +        ~subtitle() {delete[] text;}
  365. +
  366. +        void render(int w, int h)
  367. +        {
  368. +            float alpha = 1;
  369. +            if(duration > 500)
  370. +            {
  371. +                if(startmillis + 100 > lastmillis)
  372. +                    alpha = 1 - (startmillis + 100 - lastmillis) / 100.0f;
  373. +                else if(startmillis - 100 + duration < lastmillis)
  374. +                    alpha = (startmillis + duration - lastmillis) / 100.0f;
  375. +            }
  376. +            int th, tw;
  377. +            text_bounds(text, tw, th, w * 0.9);
  378. +
  379. +            draw_text(text, w / 2 - tw / 2, h * 0.85 - th - suboffset, color.x * 255, color.y * 255, color.z * 255, alpha * 255, -1, w * 0.9);
  380. +            suboffset += th * alpha;
  381. +        }
  382. +        void debug(int w, int h, int &hoffset, bool type)
  383. +        {
  384. +            if(type)
  385. +            {
  386. +                draw_text("Type: subtitle", 100, 0 + hoffset);
  387. +                hoffset += 64;
  388. +            }
  389. +
  390. +            draw_textf("Colour: (%f, %f, %f)", 100, 0 + hoffset, color.x, color.y, color.z);
  391. +            hoffset += 64;
  392. +            action::debug(w, h, hoffset);
  393. +        }
  394. +    };
  395. +
  396. +    struct move : action
  397. +    {
  398. +        float dx, dy, dz;
  399. +        vec start;
  400. +
  401. +        move(float x, float y, float z, int d, const char *s) : action(d, s), dx(x), dy(y), dz(z), start(camera.o) {}
  402. +        move(vec dest, int d, const char *s) : action(d, s), start(camera.o)
  403. +        {
  404. +            dest.sub(start);
  405. +            dx = dest.x;
  406. +            dy = dest.y;
  407. +            dz = dest.z;
  408. +        }
  409. +        ~move() {}
  410. +
  411. +        bool update()
  412. +        {
  413. +            camera.o = vec(dx, dy, dz).mul(multiplier(true)).add(start);
  414. +
  415. +            return action::update();
  416. +        }
  417. +        void debug(int w, int h, int &hoffset, bool type)
  418. +        {
  419. +            if(type)
  420. +            {
  421. +                draw_text("Type: Move", 100, 0 + hoffset);
  422. +                hoffset += 64;
  423. +            }
  424. +
  425. +            draw_textf("Start: (%f, %f, %f)", 100, 0 + hoffset, start.x, start.y, start.z);
  426. +            draw_textf("Delta: (%f, %f, %f)", 100, 64 + hoffset, dx, dy, dz);
  427. +            hoffset += 64 * 2;
  428. +            action::debug(w, h, hoffset);
  429. +        }
  430. +    };
  431. +
  432. +    struct moveaccel : move
  433. +    {
  434. +        moveaccel(float x, float y, float z, int d, const char *s) : move(x, y, z, d, s) {}
  435. +        moveaccel(vec dest, int d, const char *s) : move(dest, d, s) {}
  436. +        ~moveaccel() {}
  437. +
  438. +        bool update()
  439. +        {
  440. +            if(!duration)
  441. +                return move::update();
  442. +
  443. +            int elapsed = min(duration, lastmillis - startmillis);
  444. +            float mult = 0.5f + sinf((elapsed - duration/2.0f) * M_PI / duration) / 2.0f;
  445. +
  446. +            camera.o = vec(dx, dy, dz).mul(mult).add(start);
  447. +
  448. +            return action::update();
  449. +        }
  450. +        void debug(int w, int h, int &hoffset, bool type)
  451. +        {
  452. +            if(type)
  453. +            {
  454. +                draw_text("Type: Move Accel", 100, 0 + hoffset);
  455. +                hoffset += 64;
  456. +            }
  457. +
  458. +            draw_textf("Progress: %f", 100, 0 + hoffset, 0.5f + sinf((min(duration, lastmillis - startmillis) - duration / 2.0f) * M_PI / duration));
  459. +            hoffset += 64;
  460. +            move::debug(w, h, hoffset, false);
  461. +        }
  462. +    };
  463. +
  464. +    struct view : action
  465. +    {
  466. +        float yaw, pitch, roll;
  467. +        float iyaw, ipitch, iroll;
  468. +
  469. +        view(float y, float p, float r, int d, const char *s) : action(d, s), yaw(y), pitch(p), roll(r), iyaw(camera.yaw), ipitch(camera.pitch), iroll(camera.roll)
  470. +        {
  471. +            if(duration && (yaw - iyaw == 180 || yaw - iyaw == -180))
  472. +            {
  473. +                conoutf("Warning: viewspecific/viewcamera was called from two points with a 180 degree delta. iyaw was adjusted slightly to avoid funkiness and possible division by 0");
  474. +                iyaw += 1;
  475. +            }
  476. +        }
  477. +        ~view() {}
  478. +
  479. +        bool update()
  480. +        {
  481. +            vec old = vec(iyaw * RAD, ipitch * RAD).mul(1-multiplier(true));
  482. +            vec next = vec(yaw * RAD, pitch * RAD).mul(multiplier(true)).add(old);
  483. +
  484. +            vectoyawpitch(next, camera.yaw, camera.pitch);
  485. +            camera.roll = iroll * (1 - multiplier(true)) + roll * multiplier(true);
  486. +
  487. +            return action::update();
  488. +        }
  489. +        void debug(int w, int h, int &hoffset, bool type)
  490. +        {
  491. +            if(type)
  492. +            {
  493. +                draw_text("Type: View", 100, 0 + hoffset);
  494. +                hoffset += 64;
  495. +            }
  496. +
  497. +            draw_textf("Initial: %f %f %f", 100, 0 + hoffset, iyaw, ipitch, iroll);
  498. +            draw_textf("Post: %f %f %f", 100, 64 + hoffset, yaw, pitch, roll);
  499. +            hoffset += 64 * 2;
  500. +            action::debug(w, h, hoffset);
  501. +        }
  502. +    };
  503. +
  504. +    struct viewaccel : view
  505. +    {
  506. +        viewaccel(float y, float p, float r, int d, const char *s) : view(y, p, r, d, s) {}
  507. +        ~viewaccel() {}
  508. +
  509. +        bool update()
  510. +        {
  511. +            if(!duration)
  512. +                return view::update();
  513. +
  514. +            int elapsed = min(duration, lastmillis - startmillis);
  515. +            float mult = 0.5f + sinf((elapsed - duration/2.0f) * M_PI / duration) / 2.0f;
  516. +
  517. +            vec old = vec(iyaw * RAD, ipitch * RAD).mul(1-mult);
  518. +            vec next = vec(yaw * RAD, pitch * RAD).mul(mult).add(old);
  519. +
  520. +            vectoyawpitch(next, camera.yaw, camera.pitch);
  521. +            camera.roll = iroll * (1 - mult) + roll * mult;
  522. +
  523. +            return action::update();
  524. +        }
  525. +        void debug(int w, int h, int &hoffset, bool type)
  526. +        {
  527. +            if(type)
  528. +            {
  529. +                draw_text("Type: View Accel", 100, 0 + hoffset);
  530. +                hoffset += 64;
  531. +            }
  532. +
  533. +            draw_textf("Progress: %f", 100, 0 + hoffset, 0.5f + sinf((min(duration, lastmillis - startmillis) - duration / 2.0f) * M_PI / duration));
  534. +            hoffset += 64;
  535. +            view::debug(w, h, hoffset, false);
  536. +        }
  537. +    };
  538. +
  539. +    struct viewspin : action
  540. +    {
  541. +        float yaw, pitch, roll;
  542. +
  543. +        viewspin(float y, float p, float r, int d, const char *s) : action(d, s), yaw(y), pitch(p), roll(r) {}
  544. +        ~viewspin() {}
  545. +
  546. +        bool update()
  547. +        {
  548. +            float mult = multiplier();
  549. +            camera.yaw += yaw * mult;
  550. +            camera.pitch += pitch * mult;
  551. +            camera.roll += roll * mult;
  552. +
  553. +            return action::update();
  554. +        }
  555. +        void debug(int w, int h, int &hoffset, bool type)
  556. +        {
  557. +            if(type)
  558. +            {
  559. +                draw_text("Type: View Spin", 100, 0 + hoffset);
  560. +                hoffset += 64;
  561. +            }
  562. +
  563. +            draw_textf("Delta: %f %f %f", 100, 0 + hoffset, yaw, pitch, roll);
  564. +            hoffset += 64;
  565. +            action::debug(w, h, hoffset);
  566. +        }
  567. +    };
  568. +
  569. +    struct sound : action
  570. +    {
  571. +        int ind;
  572. +
  573. +        sound(int i, int d, const char *s) : action(d, s), ind(i)
  574. +        {
  575. +            playsound(ind, NULL, NULL, 0, 0, -1, 0, d);
  576. +        }
  577. +        ~sound() {}
  578. +
  579. +        void debug(int w, int h, int &hoffset, bool type)
  580. +        {
  581. +            if(type)
  582. +            {
  583. +                draw_text("Type: Sound", 100, 0 + hoffset);
  584. +                hoffset += 64;
  585. +            }
  586. +
  587. +            draw_textf("Index: %i", 100, 0 + hoffset, ind);
  588. +            hoffset += 64;
  589. +            action::debug(w, h, hoffset);
  590. +        }
  591. +    };
  592. +
  593. +    struct soundfile : action
  594. +    {
  595. +        const char *path;
  596. +
  597. +        soundfile(const char *p, int d, const char *s) : action(d, s), path(newstring(p))
  598. +        {
  599. +            playsoundname(path, NULL, 0, 0, 0, -1, 0, d);
  600. +        }
  601. +        ~soundfile() {delete[] path;}
  602. +
  603. +        void debug(int w, int h, int &hoffset, bool type)
  604. +        {
  605. +            if(type)
  606. +            {
  607. +                draw_text("Type: Sound File", 100, 0 + hoffset);
  608. +                hoffset += 64;
  609. +            }
  610. +
  611. +            draw_textf("Path: %s", 100, 0 + hoffset, path);
  612. +            hoffset += 64;
  613. +            action::debug(w, h, hoffset);
  614. +        }
  615. +    };
  616. +
  617. +    struct overlay : action
  618. +    {
  619. +        Texture *img;
  620. +        vec4 color;
  621. +        int fade;
  622. +
  623. +        overlay(Texture *i, float r, float g, float b, float a, int f, int d, const char *s) : action(d, s), img(i), color(vec4(r, g, b, a)), fade(f) {}
  624. +        ~overlay() {}
  625. +
  626. +        void render(int w, int h)
  627. +        {
  628. +            float alpha = 1;
  629. +            if(fade && duration >= fade * 2)
  630. +            {
  631. +                if(startmillis + fade > lastmillis)
  632. +                    alpha = 1 - (startmillis + 150 - lastmillis) / (float) fade;
  633. +                else if(startmillis -fade + duration < lastmillis)
  634. +                    alpha = (startmillis + duration - lastmillis) / (float) fade;
  635. +            }
  636. +
  637. +            glColor4f(color.x, color.y, color.z, color.w * alpha);
  638. +            settexture(img);
  639. +
  640. +            glBegin(GL_TRIANGLE_STRIP);
  641. +
  642. +            glTexCoord2f(0, 0); glVertex2i(0, 0);
  643. +            glTexCoord2f(1, 0); glVertex2i(w, 0);
  644. +            glTexCoord2f(0, 1); glVertex2i(0, h);
  645. +            glTexCoord2f(1, 1); glVertex2i(w, h);
  646. +
  647. +            glEnd();
  648. +
  649. +            glColor3f(1, 1, 1);
  650. +        }
  651. +        void debug(int w, int h, int &hoffset, bool type)
  652. +        {
  653. +            if(type)
  654. +            {
  655. +                draw_text("Type: Overlay", 100, 0 + hoffset);
  656. +                hoffset += 64;
  657. +            }
  658. +
  659. +            draw_textf("Color: (%f, %f, %f, %f)", 100, 0 + hoffset, color.x, color.y, color.z, color.w);
  660. +            draw_textf("Fade: %i", 100, 64 + hoffset, fade);
  661. +            hoffset += 64 * 2;
  662. +            action::debug(w, h, hoffset);
  663. +        }
  664. +    };
  665. +
  666. +    struct solid : action
  667. +    {
  668. +        bool modulate;
  669. +        vec4 color;
  670. +        int fade;
  671. +
  672. +        solid(bool m, float r, float g, float b, float a, int f, int d, const char *s) : action(d, s), modulate(m), color(vec4(r, g, b, a)), fade(f) {}
  673. +
  674. +        void render(int w, int h)
  675. +        {
  676. +            float alpha = 1;
  677. +            if(fade && duration >= fade * 2)
  678. +            {
  679. +                if(startmillis + fade > lastmillis)
  680. +                    alpha = 1 - (startmillis + fade - lastmillis) / (float) fade;
  681. +                else if(startmillis -fade + duration < lastmillis)
  682. +                    alpha = (startmillis + duration - lastmillis) / (float) fade;
  683. +            }
  684. +
  685. +            if(modulate)
  686. +            {
  687. +                glBlendFunc(GL_ZERO, GL_SRC_COLOR);
  688. +                vec col = vec(color).mul(alpha).add(vec(1, 1, 1).mul(1-alpha));
  689. +                glColor3fv(col.v);
  690. +            }
  691. +            else
  692. +                glColor4f(color.x, color.y, color.z, color.w * alpha);
  693. +
  694. +            glDisable(GL_TEXTURE_2D);
  695. +            setnotextureshader();
  696. +            glBegin(GL_TRIANGLE_STRIP);
  697. +
  698. +            glVertex2i(0, 0);
  699. +            glVertex2i(w, 0);
  700. +            glVertex2i(0, h);
  701. +            glVertex2i(w, h);
  702. +
  703. +            glEnd();
  704. +            setdefaultshader();
  705. +            glEnable(GL_TEXTURE_2D);
  706. +
  707. +            if(modulate)
  708. +                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  709. +            glColor3f(1, 1, 1);
  710. +        }
  711. +
  712. +        void debug(int w, int h, int &hoffset, bool type)
  713. +        {
  714. +            if(type)
  715. +            {
  716. +                draw_text("Type: Solid", 100, 0 + hoffset);
  717. +                hoffset += 64;
  718. +            }
  719. +
  720. +            draw_textf("Modulate: %s", 100, 0 + hoffset, modulate ? "Yes": "No");
  721. +            draw_textf("Color: (%f, %f, %f, %f)", 100, 64 + hoffset, color.x, color.y, color.z, color.w);
  722. +            draw_textf("Fade: %i", 100, 128 + hoffset, fade);
  723. +            hoffset += 64 * 3;
  724. +            action::debug(w, h, hoffset);
  725. +        }
  726. +    };
  727. +
  728. +    struct viewport : action
  729. +    {
  730. +        int cn;
  731. +        float height;
  732. +        float tail;
  733. +
  734. +        viewport(int e, float h, float t, int d, const char *s) : action(d, s), cn(e), height(h), tail(t) {}
  735. +        ~viewport() {}
  736. +
  737. +        bool update()
  738. +        {
  739. +            fpsent *ent = game::getclient(cn);
  740. +            if(ent)
  741. +            {
  742. +                camera = *ent;
  743. +                camera.o.z += height;
  744. +                camera.o.add(vec(camera.yaw * RAD, camera.pitch * RAD).mul(tail));
  745. +
  746. +                vec delta = vec(camera.o).sub(ent->o);
  747. +                if(delta.z > ent->aboveeye || delta.z + ent->eyeheight < 0 || (fabs(delta.x) < ent->radius && fabs(delta.y) < ent->radius))
  748. +                    attached = ent;
  749. +            }
  750. +
  751. +            return action::update();
  752. +        }
  753. +        void debug(int w, int h, int &hoffset, bool type)
  754. +        {
  755. +            if(type)
  756. +            {
  757. +                draw_text("Type: Viewport", 100, 0 + hoffset);
  758. +                hoffset += 64;
  759. +            }
  760. +
  761. +            fpsent *ent = game::getclient(cn);
  762. +
  763. +            draw_textf("Entity: %p", 100, 0 + hoffset, ent);
  764. +            draw_textf("Height + tail: %f %f", 100, 64 + hoffset, height, tail);
  765. +            draw_textf("View: %f %f %f", 100, 128 + hoffset, ent->yaw, ent->pitch, ent->roll);
  766. +            draw_textf("Pos: (cam) %f %f %f (ent) %f %f %f", 100, 192 + hoffset, camera.o.x, camera.o.y, camera.o.z, ent->o.x, ent->o.y, ent->o.z);
  767. +
  768. +            hoffset += 256;
  769. +            action::debug(w, h, hoffset);
  770. +        }
  771. +    };
  772. +
  773. +    struct focus : action
  774. +    {
  775. +        int cn;
  776. +        float interp;
  777. +        float lead;
  778. +
  779. +        focus(int e, float i, float l, int d, const char *s) : action(d, s), cn(e), interp(i), lead(l) {}
  780. +        ~focus() {}
  781. +
  782. +        bool update()
  783. +        {
  784. +            fpsent *ent = game::getclient(cn);
  785. +            if(ent)
  786. +            {
  787. +                int mult = interp ? min(1.0f, interp * curtime / 1000.0f) : 1;
  788. +                vec view = vec(camera.yaw * RAD, camera.pitch * RAD).mul(1 - mult).add(vec(camera.o).sub(ent->o).sub(vec(ent->vel).mul(lead)).normalize().mul(mult));
  789. +                vectoyawpitch(view, camera.yaw, camera.pitch);
  790. +            }
  791. +
  792. +            return action::update();
  793. +        }
  794. +        void debug(int w, int h, int &hoffset, bool type)
  795. +        {
  796. +            if(type)
  797. +            {
  798. +                draw_text("Type: Focus", 100, 0 + hoffset);
  799. +                hoffset += 64;
  800. +            }
  801. +
  802. +            fpsent *ent = game::getclient(cn);
  803. +            vec ideal = ent ? vec(camera.o).sub(ent->o).sub(vec(ent->vel).mul(lead)) : vec(1, 0, 0);
  804. +
  805. +            float iyaw, ipitch;
  806. +            vectoyawpitch(ideal, iyaw, ipitch);
  807. +
  808. +            draw_textf("Interp + Lead: %f %f", 100, 0 + hoffset, interp, lead);
  809. +            draw_textf("Current: %f %f", 100, 64 + hoffset, camera.yaw, camera.pitch);
  810. +            draw_textf("Ideal: %f %f", 100, 128 + hoffset, iyaw, ipitch);
  811. +            hoffset += 192;
  812. +
  813. +            return action::debug(w, h, hoffset);
  814. +        }
  815. +    };
  816. +
  817. +    #define GETCAM \
  818. +        extentity *cam = NULL; \
  819. +        loopv(entities::ents) \
  820. +        { \
  821. +            if(entities::ents[i]->type == CAMERA && entities::ents[i]->attr1 == *tag) \
  822. +                cam = entities::ents[i]; \
  823. +        }
  824. +
  825. +    ICOMMAND(cutscene_delay, "is", (int *d, const char *s),
  826. +        pending.add(new action(*d, s));
  827. +    )
  828. +    ICOMMAND(cutscene_cond, "ss", (const char *c, const char *s),
  829. +        pending.add(new cond(c, s));
  830. +    )
  831. +    ICOMMAND(cutscene_loop, "siis", (const char *t, int *l, int *d, const char *s),
  832. +        pending.add(new iterate(t, *l, *d, s));
  833. +    )
  834. +
  835. +    ICOMMAND(cutscene_subtitle, "sfffis", (const char *text, float *r, float *g, float *b, int *d, const char *s),
  836. +        subtitles.add(new subtitle(text, *r, *g, *b, *d, s));
  837. +    )
  838. +    ICOMMAND(cutscene_movecamera, "iis", (int *tag, int *d, const char *s),
  839. +        GETCAM
  840. +        if(cam)
  841. +            pending.add(new move(cam->o, *d, s));
  842. +        else
  843. +        {
  844. +            conoutf("warning: unable to find a camera entity with tag %i", *tag);
  845. +            pending.add(new action(*d, s));
  846. +        }
  847. +    )
  848. +    ICOMMAND(cutscene_movespecific, "fffis", (float *x, float *y, float *z, int *d, const char *s),
  849. +        pending.add(new move(*x, *y, *z, *d, s));
  850. +    )
  851. +    ICOMMAND(cutscene_moveaccelcamera, "iis", (int *tag, int *d, const char *s),
  852. +        GETCAM
  853. +        if(cam)
  854. +            pending.add(new moveaccel(cam->o, *d, s));
  855. +        else
  856. +        {
  857. +            conoutf("warning: unable to find a camera entity with tag %i", *tag);
  858. +            pending.add(new action(*d, s));
  859. +        }
  860. +    )
  861. +    ICOMMAND(cutscene_moveaccelspecific, "fffis", (float *x, float *y, float *z, int *d, const char *s),
  862. +        pending.add(new moveaccel(*x, *y, *z, *d, s));
  863. +    )
  864. +    ICOMMAND(cutscene_viewcamera, "iis", (int *tag, int *d, const char *s),
  865. +        GETCAM
  866. +        if(cam)
  867. +            pending.add(new view(cam->attr2, cam->attr3, cam->attr4, *d, s));
  868. +        else
  869. +        {
  870. +            conoutf("warning: unable to find a camera entity with tag %i", *tag);
  871. +            pending.add(new action(*d, s));
  872. +        }
  873. +    )
  874. +    ICOMMAND(cutscene_viewspecific, "fffis", (float *y, float *p, float *r, int *d, const char *s),
  875. +        pending.add(new view(*y, *p, *r, *d, s));
  876. +    )
  877. +    ICOMMAND(cutscene_viewaccelcamera, "iis", (int *tag, int *d, const char *s),
  878. +        GETCAM
  879. +        if(cam)
  880. +            pending.add(new viewaccel(cam->attr2, cam->attr3, cam->attr4, *d, s));
  881. +        else
  882. +        {
  883. +            conoutf("warning: unable to find a camera entity with tag %i", *tag);
  884. +            pending.add(new action(*d, s));
  885. +        }
  886. +    )
  887. +    ICOMMAND(cutscene_viewaccelspecific, "fffis", (float *y, float *p, float *r, int *d, const char *s),
  888. +        pending.add(new viewaccel(*y, *p, *r, *d, s));
  889. +    )
  890. +    ICOMMAND(cutscene_viewspin, "fffis", (float *y, float *p, float *r, int *d, const char *s),
  891. +        pending.add(new viewspin(*y, *p, *r, *d, s));
  892. +    )
  893. +    ICOMMAND(cutscene_sound, "iis", (int *ind, int *d, const char *s),
  894. +        pending.add(new sound(*ind, *d, s));
  895. +    )
  896. +    ICOMMAND(cutscene_soundfile, "sis", (const char *p, int *d, const char *s),
  897. +        pending.add(new soundfile(p, *d, s));
  898. +    )
  899. +    ICOMMAND(cutscene_overlay, "sffffiis", (const char *p, float *r, float *g, float *b, float *a, int *f, int *d, const char *s),
  900. +        pending.add(new overlay(textureload(p, 3), *r, *g, *b, *a, *f, *d, s));
  901. +    )
  902. +    ICOMMAND(cutscene_solid, "iffffiis", (int *m, float *r, float *g, float *b, float *a, int *f, int *d, const char *s),
  903. +        pending.add(new solid(*m != 0, *r, *g, *b, *a, *f, *d, s));
  904. +    )
  905. +    ICOMMAND(cutscene_viewport, "sffis", (const char *ref, float *h, float *t, int *d, const char *s),
  906. +        if(*ref) ///THIS DEPENDS ON GAME SPECIFIC STUFF
  907. +        {
  908. +            int ent = game::parseplayer(ref);
  909. +            if(ent >= 0)   pending.add(new viewport(ent, *h, *t, *d, s));
  910. +        }
  911. +    )
  912. +    ICOMMAND(cutscene_focus, "sffis", (const char *ref, float *i, float *l, int *d, const char *s),
  913. +        if(*ref) ///THIS DEPENDS ON GAME SPECIFIC STUFF
  914. +        {
  915. +            int ent = game::parseplayer(ref);
  916. +            if(ent >= 0) pending.add(new focus(ent, *i, *l, *d, s));
  917. +        }
  918. +    )
  919. +}
  920. +
  921. +namespace game
  922. +{
  923. +    bool recomputecamera(physent *&camera1, physent &tempcamera, bool &detachedcamera, float &thirdpersondistance)
  924. +    {
  925. +        if(camera::cutscene)
  926. +        {
  927. +            camera1 = &tempcamera;
  928. +            tempcamera = camera::camera;
  929. +            detachedcamera = true;
  930. +
  931. +            return true;
  932. +        }
  933. +        return false;
  934. +    }
  935. +}
  936. Index: src/engine/engine.h
  937. ===================================================================
  938. --- src/engine/engine.h (revision 3611)
  939. +++ src/engine/engine.h (working copy)
  940. @@ -140,7 +140,6 @@
  941.  // texture
  942.  extern int hwtexsize, hwcubetexsize, hwmaxaniso, maxtexsize;
  943.  
  944. -extern Texture *textureload(const char *name, int clamp = 0, bool mipit = true, bool msg = true);
  945.  extern int texalign(void *data, int w, int bpp);
  946.  extern void cleanuptexture(Texture *t);
  947.  extern void loadalphamask(Texture *t);
  948. Index: src/engine/texture.cpp
  949. ===================================================================
  950. --- src/engine/texture.cpp  (revision 3611)
  951. +++ src/engine/texture.cpp  (working copy)
  952. @@ -1152,6 +1152,15 @@
  953.      return t != notexture;
  954.  }
  955.  
  956. +bool settexture(Texture *&tex)
  957. +{
  958. +    if(!tex)
  959. +        tex = notexture;
  960. +
  961. +    glBindTexture(GL_TEXTURE_2D, tex->id);
  962. +    return tex != notexture;
  963. +}
  964. +
  965.  vector<VSlot *> vslots;
  966.  vector<Slot *> slots;
  967.  MSlot materialslots[MATF_VOLUME+1];
  968. Index: src/engine/rendergl.cpp
  969. ===================================================================
  970. --- src/engine/rendergl.cpp (revision 3611)
  971. +++ src/engine/rendergl.cpp (working copy)
  972. @@ -863,37 +863,41 @@
  973.  {
  974.      game::setupcamera();
  975.      computezoom();
  976. +    static physent tempcamera;
  977.  
  978. -    bool shoulddetach = thirdperson > 1 || game::detachcamera();
  979. -    if(!thirdperson && !shoulddetach)
  980. +    if(!game::recomputecamera(camera1, tempcamera, detachedcamera, thirdpersondistance))
  981.      {
  982. -        camera1 = player;
  983. -        detachedcamera = false;
  984. -    }
  985. -    else
  986. -    {
  987. -        static physent tempcamera;
  988. -        camera1 = &tempcamera;
  989. -        if(detachedcamera && shoulddetach) camera1->o = player->o;
  990. -        else
  991. +        bool shoulddetach = thirdperson > 1 || game::detachcamera();
  992. +        if(!thirdperson && !shoulddetach)
  993.          {
  994. -            *camera1 = *player;
  995. -            detachedcamera = shoulddetach;
  996. +            camera1 = player;
  997. +            detachedcamera = false;
  998.          }
  999. -        camera1->reset();
  1000. -        camera1->type = ENT_CAMERA;
  1001. -        camera1->collidetype = COLLIDE_AABB;
  1002. -        camera1->move = -1;
  1003. -        camera1->eyeheight = camera1->aboveeye = camera1->radius = camera1->xradius = camera1->yradius = 2;
  1004. -
  1005. -        vec dir;
  1006. -        vecfromyawpitch(camera1->yaw, camera1->pitch, -1, 0, dir);
  1007. -        if(game::collidecamera())
  1008. +        else
  1009.          {
  1010. -            movecamera(camera1, dir, thirdpersondistance, 1);
  1011. -            movecamera(camera1, dir, clamp(thirdpersondistance - camera1->o.dist(player->o), 0.0f, 1.0f), 0.1f);
  1012. +
  1013. +            camera1 = &tempcamera;
  1014. +            if(detachedcamera && shoulddetach) camera1->o = player->o;
  1015. +            else
  1016. +            {
  1017. +                *camera1 = *player;
  1018. +                detachedcamera = shoulddetach;
  1019. +            }
  1020. +            camera1->reset();
  1021. +            camera1->type = ENT_CAMERA;
  1022. +            camera1->collidetype = COLLIDE_AABB;
  1023. +            camera1->move = -1;
  1024. +            camera1->eyeheight = camera1->aboveeye = camera1->radius = camera1->xradius = camera1->yradius = 2;
  1025. +
  1026. +            vec dir;
  1027. +            vecfromyawpitch(camera1->yaw, camera1->pitch, -1, 0, dir);
  1028. +            if(game::collidecamera())
  1029. +            {
  1030. +                movecamera(camera1, dir, thirdpersondistance, 1);
  1031. +                movecamera(camera1, dir, clamp(thirdpersondistance - camera1->o.dist(player->o), 0.0f, 1.0f), 0.1f);
  1032. +            }
  1033. +            else camera1->o.add(vec(dir).mul(thirdpersondistance));
  1034.          }
  1035. -        else camera1->o.add(vec(dir).mul(thirdpersondistance));
  1036.      }
  1037.  
  1038.      setviewcell(camera1->o);
  1039. @@ -2327,4 +2331,18 @@
  1040.      glDisable(GL_TEXTURE_2D);
  1041.  }
  1042.  
  1043. +void setnotextureshader()
  1044. +{
  1045. +    notextureshader->set();
  1046. +}
  1047.  
  1048. +void setdefaultshader()
  1049. +{
  1050. +    defaultshader->set();
  1051. +}
  1052. +
  1053. +void setlineshader()
  1054. +{
  1055. +    lineshader->set();
  1056. +}
  1057. +
  1058. Index: src/shared/iengine.h
  1059. ===================================================================
  1060. --- src/shared/iengine.h    (revision 3611)
  1061. +++ src/shared/iengine.h    (working copy)
  1062. @@ -217,6 +217,10 @@
  1063.  extern vec minimapcenter, minimapradius, minimapscale;
  1064.  extern void bindminimap();
  1065.  
  1066. +extern void setnotextureshader();
  1067. +extern void setdefaultshader();
  1068. +extern void setlineshader();
  1069. +
  1070.  // renderparticles
  1071.  enum
  1072.  {
  1073. @@ -395,6 +399,8 @@
  1074.  // 3dgui
  1075.  struct Texture;
  1076.  struct VSlot;
  1077. +extern Texture *textureload(const char *name, int clamp = 0, bool mipit = true, bool msg = true);
  1078. +extern bool settexture(Texture *&tex);
  1079.  
  1080.  enum { G3D_DOWN = 1, G3D_UP = 2, G3D_PRESSED = 4, G3D_ROLLOVER = 8, G3D_DRAGGED = 16 };
  1081.  
  1082. Index: src/shared/igame.h
  1083. ===================================================================
  1084. --- src/shared/igame.h  (revision 3611)
  1085. +++ src/shared/igame.h  (working copy)
  1086. @@ -87,8 +87,10 @@
  1087.      extern void serverinfoendcolumn(g3d_gui *g, int i);
  1088.      extern bool serverinfoentry(g3d_gui *g, int i, const char *name, int port, const char *desc, const char *map, int ping, const vector<int> &attr, int np);
  1089.      extern bool needminimap();
  1090. -}
  1091. -
  1092. +
  1093. +    extern bool recomputecamera(physent *&camera1, physent &tempcamera, bool &detachedcamera, float &thirdpersondistance); //camera hack
  1094. +}
  1095. +
  1096.  namespace server
  1097.  {
  1098.      extern void *newclientinfo();
  1099. Index: src/Makefile
  1100. ===================================================================
  1101. --- src/Makefile    (revision 3611)
  1102. +++ src/Makefile    (working copy)
  1103. @@ -72,6 +72,7 @@
  1104.     engine/worldio.o \
  1105.     fpsgame/ai.o \
  1106.     fpsgame/client.o \
  1107. +   fpsgame/camera.o \
  1108.     fpsgame/entities.o \
  1109.     fpsgame/fps.o \
  1110.     fpsgame/monster.o \
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement