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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "Headers/PhysXScene.h"

#include "Managers/Headers/SceneManager.h"
#include "Rendering/RenderPass/Headers/RenderQueue.h"
#include "Core/Headers/ApplicationTimer.h"
#include "Core/Headers/ParamHandler.h"

namespace Divide {

REGISTER_SCENE(PhysXScene);

enum PhysXStateEnum{
    STATE_ADDING_ACTORS = 0,
    STATE_IDLE = 2,
    STATE_LOADING = 3
};

static std::atomic<PhysXStateEnum > s_sceneState;

//begin copy-paste
void PhysXScene::preRender(){
    _currentSky->getNode<Sky>()->setSunProperties(_sunvector, _sun->getDiffuseColor());
}
//<<end copy-paste

void PhysXScene::processGUI(const U64 deltaTime){
    D32 FpsDisplay = getSecToMs(0.3);
    if (_guiTimers[0] >= FpsDisplay){
        _GUI->modifyText("fpsDisplay", "FPS: %3.0f. FrameTime: %3.1f", 
                         ApplicationTimer::getInstance().getFps(), ApplicationTimer::getInstance().getFrameTime());
        _GUI->modifyText("RenderBinCount", "Number of items in Render Bin: %d", GFX_RENDER_BIN_SIZE);
        _guiTimers[0] = 0.0;
    }
    Scene::processGUI(deltaTime);
}

void PhysXScene::processInput(const U64 deltaTime){

}

bool PhysXScene::load(const stringImpl& name, CameraManager* const cameraMgr, GUI* const gui){
    s_sceneState = STATE_LOADING;
    //Load scene resources
    bool loadState = SCENE_LOAD(name,cameraMgr,gui,true,true);
    //Add a light
    vec2<F32> sunAngle(0.0f, RADIANS(45.0f));
    _sunvector = vec3<F32>(-cosf(sunAngle.x) * sinf(sunAngle.y),-cosf(sunAngle.y),-sinf(sunAngle.x) * sinf(sunAngle.y));
    _sun = addLight(LIGHT_TYPE_DIRECTIONAL)->getNode<DirectionalLight>();
    _sun->setDirection(_sunvector);
    _currentSky = addSky(CreateResource<Sky>(ResourceDescriptor("Default Sky")));
    s_sceneState = STATE_IDLE;
    return loadState;
}

bool PhysXScene::loadResources(bool continueOnErrors){
    _GUI->addText("fpsDisplay",               //Unique ID
                  vec2<I32>(60,20),           //Position
                  Font::DIVIDE_DEFAULT,       //Font
                  vec3<F32>(0.0f,0.2f, 1.0f), //Color
                  "FPS: %s",0);               //Text and arguments
    _GUI->addText("RenderBinCount",
                  vec2<I32>(60,30),
                  Font::DIVIDE_DEFAULT,
                  vec3<F32>(0.6f,0.2f,0.2f),
                  "Number of items in Render Bin: %d",0);

    _guiTimers.push_back(0.0); //Fps
    renderState().getCamera().setFixedYawAxis(false);
    renderState().getCamera().setRotation(-45/*yaw*/,10/*pitch*/);
    renderState().getCamera().setEye(vec3<F32>(0,30,-40));
    renderState().getCamera().setFixedYawAxis(true);
    ParamHandler::getInstance().setParam("rendering.enableFog",false);
    ParamHandler::getInstance().setParam("postProcessing.bloomFactor",0.1f);
    return true;
}

bool PhysXScene::unload(){
    return Scene::unload();
}

void PhysXScene::createStack(U32 size){
    F32 stackSize = size;
    F32 CubeSize = 1.0f;
    F32 Spacing = 0.0001f;
    vec3<F32> Pos(0, 10 + CubeSize,0);
    F32 Offset = -stackSize * (CubeSize * 2.0f + Spacing) * 0.5f + 0;

    while(s_sceneState == STATE_ADDING_ACTORS);

    s_sceneState = STATE_ADDING_ACTORS;

    while(stackSize){
        for(U16 i=0;i<stackSize;i++){
            Pos.x = Offset + i * (CubeSize * 2.0f + Spacing);
            PHYSICS_DEVICE.createBox(Pos,CubeSize);
        }
        Offset += CubeSize;
        Pos.y += (CubeSize * 2.0f + Spacing);
        stackSize--;
    }

    s_sceneState = STATE_IDLE;
}

void PhysXScene::createTower(U32 size){
    while(s_sceneState == STATE_ADDING_ACTORS);
    s_sceneState = STATE_ADDING_ACTORS;

    for(U8 i = 0 ; i < size; i++)
        PHYSICS_DEVICE.createBox(vec3<F32>(0,5.0f+5*i,0),0.5f);
    
    s_sceneState = STATE_IDLE;
}


bool PhysXScene::onKeyUp(const Input::KeyEvent& key){
    switch(key._key)    {
        default: break;
        case Input::KeyCode::KC_5:{
            _paramHandler.setParam("simSpeed", IS_ZERO(_paramHandler.getParam<F32>("simSpeed")) ? 1.0f : 0.0f);
            PHYSICS_DEVICE.updateTimeStep();
            }break;
        case Input::KeyCode::KC_1:{
            static bool hasGroundPlane = false;
            if(!hasGroundPlane){
                PHYSICS_DEVICE.createPlane(vec3<F32>(0,0,0),random(100.0f, 200.0f));
                hasGroundPlane = true;
            }
            }break;
        case Input::KeyCode::KC_2:
            PHYSICS_DEVICE.createBox(vec3<F32>(0,random(10,30),0),random(0.5f,2.0f));
            break;
        case Input::KeyCode::KC_3:{
            Kernel* kernel = Application::getInstance().getKernel();
            Task_ptr e(kernel->AddTask(0, 1, DELEGATE_BIND(&PhysXScene::createTower, this, (U32)random(5, 20))));
            registerTask(e);
            e->startTask();
            }break;
        case Input::KeyCode::KC_4:{
            Kernel* kernel = Application::getInstance().getKernel();
            Task_ptr e(kernel->AddTask(0, 1, DELEGATE_BIND(&PhysXScene::createStack, this, (U32)random(5, 10))));
            registerTask(e);
            e->startTask();
        } break;
    }
    return Scene::onKeyUp(key);
}

bool PhysXScene::mouseMoved(const Input::MouseEvent& key){
    return Scene::mouseMoved(key);
}

bool PhysXScene::mouseButtonReleased(const Input::MouseEvent& key, Input::MouseButton button){
    return Scene::mouseButtonReleased(key,button);;
}

};

Commits for Divide-Framework/trunk/Source Code/Scenes/PhysXScene/PhysXScene.cpp

Diff revisions: vs.
Revision Author Commited Message
337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

333 Diff Diff IonutCava picture IonutCava Tue 09 Dec, 2014 16:15:44 +0000

[Ionut]
- Removed “core.h” and moved everything to their appropriate header files
- Renamed MathClasses to MathMatrices (finally)
- Renamed “-Inl.h” files to ".inl"
- Some String wrapper refactoring
- Update “InstallLibraries.bat” so that it still offers valid options

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

320 Diff Diff IonutCava picture IonutCava Sun 31 Aug, 2014 21:45:33 +0000

[Ionut]
- More AI work (entity captures flag and returns it to base)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

309 Diff Diff IonutCava picture IonutCava Sat 16 Aug, 2014 22:57:33 +0000

[Ionut]
- Added an InputAggregator interface to standardize input event handling

307 IonutCava picture IonutCava Tue 12 Aug, 2014 19:45:12 +0000

[Ionut]
- More editor work:
— Per object skeleton rendering, bounding box rendering and shadow map toggling
— Full screen depth preview toggle
— Text entry based transforms