Changeset 2772 for trunk


Ignore:
Timestamp:
Jun 23, 2013, 3:38:56 PM (7 years ago)
Author:
sam
Message:

scene: use a global g_scene object instead of Scene::GetDefault().

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debug/lines.cpp

    r2511 r2772  
    2020void Debug::DrawLine(vec3 a, vec3 b, vec4 color)
    2121{
    22     Scene::GetDefault()->AddLine(a, b, color);
     22    g_scene->AddLine(a, b, color);
    2323}
    2424
     
    3737        int j = ((i & 1) << 1) | ((i >> 1) ^ 1);
    3838
    39         Scene::GetDefault()->AddLine(v[i], v[i + 4], color);
    40         Scene::GetDefault()->AddLine(v[i], v[j], color);
    41         Scene::GetDefault()->AddLine(v[i + 4], v[j + 4], color);
     39        g_scene->AddLine(v[i], v[i + 4], color);
     40        g_scene->AddLine(v[i], v[j], color);
     41        g_scene->AddLine(v[i + 4], v[j + 4], color);
    4242    }
    4343}
  • trunk/src/easymesh/easymesh.cpp

    r2587 r2772  
    134134void DefaultShaderData::SetupShaderDatas(mat4 const &model)
    135135{
    136     mat4 proj = Scene::GetDefault()->GetCamera()->GetProjection();
    137     mat4 view = Scene::GetDefault()->GetCamera()->GetView();
     136    mat4 proj = g_scene->GetCamera()->GetProjection();
     137    mat4 view = g_scene->GetCamera()->GetView();
    138138    mat4 modelview = view * model;
    139139    mat3 normalmat = transpose(inverse(mat3(modelview)));
     
    142142    /* FIXME: the 4th component of the position can be used for other things */
    143143    /* FIXME: GetUniform("blabla") is costly */
    144     Array<Light *> const lights = Scene::GetDefault()->GetLights();
     144    Array<Light *> const lights = g_scene->GetLights();
    145145    Array<vec4> light_data;
    146146    for (int i = 0; i < lights.Count(); ++i)
  • trunk/src/emitter.cpp

    r2216 r2772  
    7474
    7575    for (int i = 0; i < data->nparticles; i++)
    76         Scene::GetDefault()->AddTile(data->tileset, data->particles[i],
    77                                      data->positions[i], 0, vec2(1.0f));
     76        g_scene->AddTile(data->tileset, data->particles[i],
     77                         data->positions[i], 0, vec2(1.0f));
    7878}
    7979
  • trunk/src/font.cpp

    r2588 r2772  
    7070void Font::Print(vec3 pos, char const *str, vec2 scale)
    7171{
    72     Scene *scene = Scene::GetDefault();
    73 
    7472    while (*str)
    7573    {
     
    7775
    7876        if (ch != ' ')
    79             scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
     77            g_scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
    8078
    8179        pos.x += data->size.x * scale.x;
  • trunk/src/gpu/rendercontext.cpp

    r2768 r2772  
    5353
    5454private:
    55     Scene *m_scene;
    56 
    5755    TrackedState<ibox2> m_viewport;
    5856    TrackedState<vec4> m_clear_color;
     
    7270  : m_data(new RenderContextData())
    7371{
    74     m_data->m_scene = Scene::GetDefault();
    7572}
    7673
  • trunk/src/gpu/renderer.cpp

    r2770 r2772  
    4545 * The global g_renderer object, initialised by Video::Init
    4646 */
    47 Renderer *g_renderer;
     47
     48Renderer *g_renderer = nullptr;
    4849
    4950/*
    5051 * Private RendererData class
    5152 */
     53
    5254class RendererData
    5355{
  • trunk/src/gradient.cpp

    r2754 r2772  
    9595
    9696    uni_mat = data->shader->GetUniformLocation("proj_matrix");
    97     data->shader->SetUniform(uni_mat, Scene::GetDefault()->GetCamera()->GetProjection());
     97    data->shader->SetUniform(uni_mat, g_scene->GetCamera()->GetProjection());
    9898    uni_mat = data->shader->GetUniformLocation("view_matrix");
    99     data->shader->SetUniform(uni_mat, Scene::GetDefault()->GetCamera()->GetView());
     99    data->shader->SetUniform(uni_mat, g_scene->GetCamera()->GetView());
    100100    uni_mat = data->shader->GetUniformLocation("model_matrix");
    101101    data->shader->SetUniform(uni_mat, model_matrix);
  • trunk/src/layer.cpp

    r2183 r2772  
    5252        Log::Error("FIXME: Layer::Render no longer works\n");
    5353#if 0
    54     Scene *scene = Scene::GetDefault();
    5554    for (int j = 0; j < height; j++)
    5655        for (int i = 0; i < width; i++)
    5756            if (data[j * width + i])
    58                 scene->AddTile(data[j * width + i],
    59                                vec3(x + i * 32,
    60                                      y + j * 32 - altitude,
    61                                      altitude + z),
    62                                orientation);
     57                g_scene->AddTile(data[j * width + i],
     58                                 vec3(x + i * 32,
     59                                       y + j * 32 - altitude,
     60                                       altitude + z),
     61                                 orientation);
    6362#endif
    6463}
  • trunk/src/light.cpp

    r2289 r2772  
    6565    WorldEntity::TickDraw(seconds);
    6666
    67     Scene::GetDefault()->AddLight(this);
     67    g_scene->AddLight(this);
    6868}
    6969
  • trunk/src/scene.cpp

    r2764 r2772  
    2929{
    3030
     31/*
     32 * The global g_scene object, initialised by Video::Init
     33 */
     34
     35Scene *g_scene = nullptr;
     36
     37/*
     38 * A quick and dirty Tile structure for 2D blits
     39 */
     40
    3141struct Tile
    3242{
     
    7282    Camera *m_default_cam;
    7383    Array<Camera *> m_camera_stack;
    74 
    75     static Scene *scene;
    7684};
    77 
    78 Scene *SceneData::scene = nullptr;
    7985
    8086/*
     
    8288 */
    8389
    84 Scene::Scene()
     90Scene::Scene(ivec2 size)
    8591  : data(new SceneData())
    8692{
    8793    /* Create a default orthographic camera, in case the user doesn’t. */
    8894    data->m_default_cam = new Camera();
    89     mat4 proj = mat4::ortho(0, Video::GetSize().x, 0, Video::GetSize().y,
    90                             -1000.f, 1000.f);
     95    mat4 proj = mat4::ortho(0, size.x, 0, size.y, -1000.f, 1000.f);
    9196    data->m_default_cam->SetProjection(proj);
    9297    PushCamera(data->m_default_cam);
     
    113118    delete data->m_tile_vdecl;
    114119    delete data;
    115 }
    116 
    117 Scene *Scene::GetDefault()
    118 {
    119     if (!SceneData::scene)
    120         SceneData::scene = new Scene();
    121     return SceneData::scene;
    122120}
    123121
  • trunk/src/scene.h

    r2500 r2772  
    3030class Scene
    3131{
    32 public:
    33     Scene();
     32    friend class Video;
     33
     34private:
     35    Scene(ivec2 size);
    3436    ~Scene();
    3537
    36     static Scene *GetDefault();
    37 
     38public:
    3839    Camera *GetCamera();
    3940    void PushCamera(Camera *cam);
     
    5556};
    5657
     58extern Scene *g_scene;
     59
    5760} /* namespace lol */
    5861
  • trunk/src/sprite.cpp

    r2216 r2772  
    5151    Entity::TickDraw(seconds);
    5252
    53     Scene::GetDefault()->AddTile(data->tileset, data->id, m_position,
    54                                  0, vec2(1.0f));
     53    g_scene->AddTile(data->tileset, data->id, m_position, 0, vec2(1.0f));
    5554}
    5655
  • trunk/src/ticker.cpp

    r2769 r2772  
    387387        {
    388388        case Entity::DRAWGROUP_BEGIN:
    389             Scene::GetDefault()->Reset();
     389            g_scene->Reset();
    390390            g_renderer->Clear(ClearMask::All);
    391391            break;
     
    413413
    414414        /* Do this render step */
    415         Scene::GetDefault()->Render();
     415        g_scene->Render();
    416416    }
    417417
  • trunk/src/video.cpp

    r2770 r2772  
    5252{
    5353    g_renderer = new Renderer(size);
     54    g_scene = new Scene(size);
    5455
    5556    /* Initialise reasonable scene default properties */
     
    115116void Video::Destroy()
    116117{
     118    delete g_scene;
     119    g_scene = nullptr;
     120
    117121    delete g_renderer;
    118122    g_renderer = nullptr;
  • trunk/test/btphystest.cpp

    r2756 r2772  
    5757                      vec3(0, 1, 0));
    5858    m_camera->SetProjection(mat4::perspective(45.f, 1280.f, 960.f, .1f, 1000.f));
    59     Scene::GetDefault()->PushCamera(m_camera);
     59    g_scene->PushCamera(m_camera);
    6060
    6161    m_ready = false;
     
    422422BtPhysTest::~BtPhysTest()
    423423{
    424     Scene::GetDefault()->PopCamera(m_camera);
     424    g_scene->PopCamera(m_camera);
    425425    Ticker::Unref(m_light1);
    426426    Ticker::Unref(m_light2);
  • trunk/test/meshviewer.cpp

    r2769 r2772  
    6262    {
    6363        if (new_fov > MIN_FOV)
    64             Scene::GetDefault()->GetCamera()->SetProjection(mat4::perspective(new_fov, video_size.x, video_size.y, .1f, 1000.f));
     64            g_scene->GetCamera()->SetProjection(mat4::perspective(new_fov, video_size.x, video_size.y, .1f, 1000.f));
    6565        else
    66             Scene::GetDefault()->GetCamera()->SetProjection(mat4::ortho(video_size.x, video_size.y, .1f, 1000.f));
     66            g_scene->GetCamera()->SetProjection(mat4::ortho(video_size.x, video_size.y, .1f, 1000.f));
    6767    }
    6868
     
    108108                          vec3(0.f, 0.f, 0.f),
    109109                          vec3(0.f, 1.f, 0.f));
    110         Scene::GetDefault()->PushCamera(m_camera);
     110        g_scene->PushCamera(m_camera);
    111111
    112112        //Lights setup
     
    145145    ~MeshViewer()
    146146    {
    147         Scene::GetDefault()->PopCamera(m_camera);
     147        g_scene->PopCamera(m_camera);
    148148        for (int i = 0; i < m_lights.Count(); ++i)
    149149            Ticker::Unref(m_lights[i]);
     
    179179                break;
    180180
    181         mat4 world_cam = Scene::GetDefault()->GetCamera()->GetView();
    182         mat4 cam_screen = Scene::GetDefault()->GetCamera()->GetProjection();
     181        mat4 world_cam = g_scene->GetCamera()->GetView();
     182        mat4 cam_screen = g_scene->GetCamera()->GetProjection();
    183183
    184184        if (m_meshes.Count() && mesh_id >= 0)
     
    251251
    252252        //Move modification
    253         vec3 campos = Scene::GetDefault()->GetCamera()->GetPosition();
     253        vec3 campos = g_scene->GetCamera()->GetPosition();
    254254        if (m_fov_damp < MIN_FOV)
    255             Scene::GetDefault()->GetCamera()->SetView(vec3(campos.xy, 10.f), quat(1.f));
     255            g_scene->GetCamera()->SetView(vec3(campos.xy, 10.f), quat(1.f));
    256256        else if (fov_ratio > .0f)
    257             Scene::GetDefault()->GetCamera()->SetView(vec3(campos.xy, campos.z * fov_ratio * 1.1f), quat(1.f));
     257            g_scene->GetCamera()->SetView(vec3(campos.xy, campos.z * fov_ratio * 1.1f), quat(1.f));
    258258#else
    259         Camera* cur_cam = Scene::GetDefault()->GetCamera();
     259        Camera* cur_cam = g_scene->GetCamera();
    260260        vec3 min_max_diff = (cam_min_max[1] - cam_min_max[0]);
    261261        float screen_size = max(max(lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)),
     
    443443        g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
    444444
    445         mat4 default_proj = Scene::GetDefault()->GetCamera()->GetProjection();
     445        mat4 default_proj = g_scene->GetCamera()->GetProjection();
    446446        int max_drawn = m_meshes.Count() - m_mesh_shown;
    447447        for (int i = max_drawn; i < m_meshes.Count(); i++)
     
    462462                m_meshes[i].m4 = damp(m_meshes[i].m4, new_mesh_offset, .35f, seconds);
    463463
    464                 Scene::GetDefault()->GetCamera()->SetProjection(
     464                g_scene->GetCamera()->SetProjection(
    465465                                                                mat4::translate(m_meshes[i].m4) *
    466466                                                                mat4::translate(vec3(m_mesh_screen_offset_damp, .0f)) *
     
    476476            }
    477477        }
    478         Scene::GetDefault()->GetCamera()->SetProjection(default_proj);
     478        g_scene->GetCamera()->SetProjection(default_proj);
    479479    }
    480480
  • trunk/tutorial/05_easymesh.cpp

    r2753 r2772  
    5252                                       vec3(0.f, -1.f, 0.f),
    5353                                       vec3(0.f, 1.f, 0.f)));
    54         Scene::GetDefault()->PushCamera(m_camera);
     54        g_scene->PushCamera(m_camera);
    5555
    5656        /* Add a white directional light */
     
    7171    ~EasyMeshTutorial()
    7272    {
    73         Scene::GetDefault()->PopCamera(m_camera);
     73        g_scene->PopCamera(m_camera);
    7474        Ticker::Unref(m_light1);
    7575        Ticker::Unref(m_light2);
  • trunk/tutorial/06_sprite.cpp

    r2753 r2772  
    2727        m_camera->SetView(mat4(1.f));
    2828        m_camera->SetProjection(mat4::ortho(0.f, 640.f, 0.f, 480.f, -100.f, 100.f));
    29         Scene::GetDefault()->PushCamera(m_camera);
     29        g_scene->PushCamera(m_camera);
    3030        Ticker::Ref(m_camera);
    3131
     
    4747        Tiler::Deregister(m_tileset);
    4848
    49         Scene::GetDefault()->PopCamera(m_camera);
     49        g_scene->PopCamera(m_camera);
    5050        Ticker::Unref(m_camera);
    5151    }
     
    7878            int frame = (int)(m_sprites[i].m2 * FRAME_COUNT);
    7979//            m_sprites[i].m1.z = frame;
    80             Scene::GetDefault()->AddTile(m_tileset, frame,
    81                                          (ivec3)m_sprites[i].m1, 0, vec2(2.f));
     80            g_scene->AddTile(m_tileset, frame,
     81                             (ivec3)m_sprites[i].m1, 0, vec2(2.f));
    8282        }
    8383    }
Note: See TracChangeset for help on using the changeset viewer.