Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "Headers/Camera.h"

#include "Core/Headers/Console.h"
#include "Utility/Headers/Localization.h"

#include "Rendering/Camera/Headers/FreeFlyCamera.h"
#include "Rendering/Camera/Headers/FirstPersonCamera.h"
#include "Rendering/Camera/Headers/OrbitCamera.h"
#include "Rendering/Camera/Headers/ScriptedCamera.h"
#include "Rendering/Camera/Headers/ThirdPersonCamera.h"

namespace Divide {

Camera* Camera::_activeCamera = nullptr;
Camera* Camera::_previousCamera = nullptr;

vectorImpl<DELEGATE_CBK<void, const Camera&> > Camera::_changeCameralisteners;
vectorImpl<DELEGATE_CBK<void, const Camera&> > Camera::_updateCameralisteners;

SharedLock Camera::_cameraPoolLock;
Camera::CameraPool Camera::_cameraPool;

void Camera::update(const U64 deltaTime) {
    ReadLock r_lock(_cameraPoolLock);
    for (CameraPool::value_type& it : _cameraPool) {
        it.second->updateInternal(deltaTime);
    }
}

void Camera::onUpdate(const Camera& cam) {
    for (const DELEGATE_CBK<void, const Camera&>& listener : _updateCameralisteners) {
        listener(cam);
    }
}

void Camera::activeCamera(Camera* cam) {
    if (_activeCamera) {
        if (cam && _activeCamera->getGUID() == cam->getGUID()) {
            return;
        }
        _activeCamera->setActiveInternal(false);
    }

    _previousCamera = _activeCamera;
    _activeCamera = cam;
    if (cam) {
        _activeCamera->setActiveInternal(true);
        for (const DELEGATE_CBK<void, Camera&>& listener : _changeCameralisteners) {
            listener(*_activeCamera);
        }
    }
}

void Camera::activeCamera(U64 cam) {
    activeCamera(findCamera(cam));
}

Camera* Camera::previousCamera() {
    return _previousCamera;
}

Camera* Camera::activeCamera() {
    assert(_activeCamera != nullptr);

    return _activeCamera;
}

void Camera::destroyPool() {
    Console::printfn(Locale::get(_ID("CAMERA_MANAGER_DELETE")));
    Console::printfn(Locale::get(_ID("CAMERA_MANAGER_REMOVE_CAMERAS")));

    WriteLock w_lock(_cameraPoolLock);
    for (CameraPool::value_type& it : _cameraPool) {
        it.second->unload();
    }
    MemoryManager::DELETE_HASHMAP(_cameraPool);
}

Camera* Camera::createCamera(const stringImpl& cameraName, CameraType type) {
    Camera* camera = nullptr;
    switch (type) {
    case Camera::CameraType::FIRST_PERSON:
        camera = MemoryManager_NEW FirstPersonCamera(cameraName);
        break;
    case Camera::CameraType::FREE_FLY:
        camera = MemoryManager_NEW FreeFlyCamera(cameraName);
        break;
    case Camera::CameraType::ORBIT:
        camera = MemoryManager_NEW OrbitCamera(cameraName);
        break;
    case Camera::CameraType::SCRIPTED:
        camera = MemoryManager_NEW ScriptedCamera(cameraName);
        break;
    case Camera::CameraType::THIRD_PERSON:
        camera = MemoryManager_NEW ThirdPersonCamera(cameraName);
        break;
    }

    if (camera != nullptr) {
        WriteLock w_lock(_cameraPoolLock);
        hashAlg::emplace(_cameraPool, _ID_RT(camera->getName()), camera);
    }

    return camera;
}

bool Camera::destroyCamera(Camera*& camera) {
    if (camera != nullptr) {
        if (_activeCamera && _activeCamera->getGUID() == camera->getGUID()) {
            activeCamera(nullptr);
        }

        if (camera->unload()) {
            WriteLock w_lock(_cameraPoolLock);
            _cameraPool.erase(_ID_RT(camera->getName()));
            MemoryManager::DELETE(camera);
            return true;
        }
    }

    return false;
}

Camera* Camera::findCamera(U64 nameHash) {
    ReadLock r_lock(_cameraPoolLock);
    const CameraPool::const_iterator& it = _cameraPool.find(nameHash);
    if (it != std::end(_cameraPool)) {
        return it->second;
    }

    return nullptr;
}

void Camera::addChangeListener(const DELEGATE_CBK<void, const Camera&>& f) {
    _changeCameralisteners.push_back(f);
}

void Camera::addUpdateListener(const DELEGATE_CBK<void, const Camera&>& f) {
    _updateCameralisteners.push_back(f);
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Rendering/Camera/CameraPool.cpp

Diff revisions: vs.
Revision Author Commited Message
842 Diff Diff IonutCava picture IonutCava Wed 01 Feb, 2017 17:25:15 +0000

[IonutCava]
- Start to implement scripting support via ChaiScript: http://chaiscript.com/
- Cleanup DELEGATE_CBK alias

823 Diff Diff IonutCava picture IonutCava Wed 18 Jan, 2017 17:11:00 +0000

[IonutCava]
- Fix some issues with Camera initialisation code.
- ToDo: Cleanup camera class. (e.g. setRotation / setGlobalRotation calls)

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

816 Diff Diff IonutCava picture IonutCava Fri 13 Jan, 2017 17:05:20 +0000

[IonutCava]
- Allow per player scene state and input source
— Add SceneStatePerPlayer class
— Add device index to InputParams objects.
— ToDo: map players to devide indices

815 Diff Diff IonutCava picture IonutCava Thu 12 Jan, 2017 23:33:01 +0000

[IonutCava]
- Fixed viewport alignment issue
- Added per-player RenderTargets (added index support to GFXRTPool)
- Initial implementation of per-player cameras
— Removed defaultCamera
— Scenes now use a baseCamera as a template for new player cameras

801 Diff Diff IonutCava picture IonutCava Sun 27 Nov, 2016 21:28:01 +0000

[IonutCava]
- More performance analysis guided optimizations.
- Some refactoring to allow later removal of Singletons status for: GFXDevice, SFXDevice, PXDevice, GUI and Input.
— Pass a PlatformContext around objects to access these classes.

795 Diff Diff IonutCava picture IonutCava Wed 23 Nov, 2016 17:14:33 +0000

[IonutCava]
- Remove ULL. Use U64 instead
- Various small bug fixes and typos.

784 IonutCava picture IonutCava Mon 17 Oct, 2016 16:20:49 +0000

[IonutCava]
- Removed the CameraManager and move most of its functionality into static members of the Camera class
- Removed Camera push/pop system in favour of a stateless ptr based system to better fit the RenderPass structure