source: trunk/games/ToukyDemo/ToukyDemo.cpp @ 1548

Last change on this file since 1548 was 1548, checked in by touky, 8 years ago

Added worldentity registration support.
Character now walks around.

File size: 2.5 KB
Line 
1//
2// ToukyDemo
3//
4// Copyright: (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
5//            (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
6//            (c) 2012 Sam Hocevar <sam@hocevar.net>
7//
8
9#if defined HAVE_CONFIG_H
10#   include "config.h"
11#endif
12
13#if defined _WIN32
14#   include <direct.h>
15#endif
16
17#if defined _XBOX
18#   define _USE_MATH_DEFINES /* for M_PI */
19#   include <xtl.h>
20#   undef near /* Fuck Microsoft */
21#   undef far /* Fuck Microsoft again */
22#elif defined _WIN32
23#   define _USE_MATH_DEFINES /* for M_PI */
24#   define WIN32_LEAN_AND_MEAN
25#   include <windows.h>
26#   undef near /* Fuck Microsoft */
27#   undef far /* Fuck Microsoft again */
28#else
29#   include <cmath>
30#endif
31
32#if USE_SDL && defined __APPLE__
33#   include <SDL_main.h>
34#endif
35
36#include "core.h"
37#include "loldebug.h"
38
39using namespace lol;
40
41#include "ToukyDemo.h"
42
43ToukyDemo::ToukyDemo(bool editor)
44{
45    /* Create a camera that matches the settings of XNA ToukyDemo */
46    m_camera = new Camera(vec3(0.f, 600.f, 0.f),
47                          vec3(0.f, 0.f, 0.f),
48                          vec3(0, 0, -1));
49    m_camera->SetRotation(quat::fromeuler_yxz(0.f, -30.f, 0.f));
50    //m_camera->SetPerspective(120.f, 1280.f, 960.f, -1000.f, 1000.f);
51        m_camera->SetOrtho(1280.f / 6, 960.f / 6, -1000.f, 1000.f);
52    Ticker::Ref(m_camera);
53
54        m_URO = new UserReactiveObject();
55        m_URO->m_position = vec3(.0f, -30.0f, .0f);
56        Ticker::Ref(m_URO);
57
58        m_Character = new Character();
59        m_Character->m_position = vec3(.0f, 10.0f, 40.0f);
60        Ticker::Ref(m_Character);
61        m_URO->InfluenceEntityRegistration(true, m_Character);
62
63    m_ready = false;
64}
65
66void ToukyDemo::TickGame(float seconds)
67{
68    WorldEntity::TickGame(seconds);
69
70    if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
71        Ticker::Shutdown();
72}
73
74void ToukyDemo::TickDraw(float seconds)
75{
76    WorldEntity::TickDraw(seconds);
77
78    if (!m_ready)
79    {
80        /* FIXME: this object never cleans up */
81        m_ready = true;
82    }
83
84    Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));
85}
86
87ToukyDemo::~ToukyDemo()
88{
89        m_URO->InfluenceEntityRegistration(false, m_Character);
90
91        Ticker::Unref(m_camera);
92    Ticker::Unref(m_URO);
93        Ticker::Unref(m_Character);
94}
95
96int main(int argc, char **argv)
97{
98    Application app("ToukyDemo", ivec2(800, 600), 60.0f);
99
100#if defined _MSC_VER && !defined _XBOX
101    _chdir("..");
102#elif defined _WIN32 && !defined _XBOX
103    _chdir("../..");
104#endif
105
106    new ToukyDemo(argc > 1);
107    app.ShowPointer(false);
108
109    app.Run();
110
111    return EXIT_SUCCESS;
112}
113
Note: See TracBrowser for help on using the repository browser.