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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty.  In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would be
//    appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
//    misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//

#include <string.h>
#include <new>
#include "DetourProximityGrid.h"
#include "DetourCommon.h"
#include "DetourMath.h"
#include "DetourAlloc.h"
#include "DetourAssert.h"


dtProximityGrid* dtAllocProximityGrid()
{
    void* mem = dtAlloc(sizeof(dtProximityGrid), DT_ALLOC_PERM);
    if (!mem) return 0;
    return new(mem) dtProximityGrid;
}

void dtFreeProximityGrid(dtProximityGrid* ptr)
{
    if (!ptr) return;
    ptr->~dtProximityGrid();
    dtFree(ptr);
}


inline int hashPos2(int x, int y, int n)
{
    return ((x*73856093) ^ (y*19349663)) & (n-1);
}


dtProximityGrid::dtProximityGrid() :
    m_maxItems(0),
    m_cellSize(0),
    m_pool(0),
    m_poolHead(0),
    m_poolSize(0),
    m_buckets(0),
    m_bucketsSize(0)
{
}

dtProximityGrid::~dtProximityGrid()
{
    dtFree(m_buckets);
    dtFree(m_pool);
}

bool dtProximityGrid::init(const int poolSize, const float cellSize)
{
    dtAssert(poolSize > 0);
    dtAssert(cellSize > 0.0f);
    
    m_cellSize = cellSize;
    m_invCellSize = 1.0f / m_cellSize;
    
    // Allocate hashs buckets
    m_bucketsSize = dtNextPow2(poolSize);
    m_buckets = (unsigned short*)dtAlloc(sizeof(unsigned short)*m_bucketsSize, DT_ALLOC_PERM);
    if (!m_buckets)
        return false;
    
    // Allocate pool of items.
    m_poolSize = poolSize;
    m_poolHead = 0;
    m_pool = (Item*)dtAlloc(sizeof(Item)*m_poolSize, DT_ALLOC_PERM);
    if (!m_pool)
        return false;
    
    clear();
    
    return true;
}

void dtProximityGrid::clear()
{
    memset(m_buckets, 0xff, sizeof(unsigned short)*m_bucketsSize);
    m_poolHead = 0;
    m_bounds[0] = 0xffff;
    m_bounds[1] = 0xffff;
    m_bounds[2] = -0xffff;
    m_bounds[3] = -0xffff;
}

void dtProximityGrid::addItem(const unsigned short id,
                              const float minx, const float miny,
                              const float maxx, const float maxy)
{
    const int iminx = (int)dtMathFloorf(minx * m_invCellSize);
    const int iminy = (int)dtMathFloorf(miny * m_invCellSize);
    const int imaxx = (int)dtMathFloorf(maxx * m_invCellSize);
    const int imaxy = (int)dtMathFloorf(maxy * m_invCellSize);
    
    m_bounds[0] = dtMin(m_bounds[0], iminx);
    m_bounds[1] = dtMin(m_bounds[1], iminy);
    m_bounds[2] = dtMax(m_bounds[2], imaxx);
    m_bounds[3] = dtMax(m_bounds[3], imaxy);
    
    for (int y = iminy; y <= imaxy; ++y)
    {
        for (int x = iminx; x <= imaxx; ++x)
        {
            if (m_poolHead < m_poolSize)
            {
                const int h = hashPos2(x, y, m_bucketsSize);
                const unsigned short idx = (unsigned short)m_poolHead;
                m_poolHead++;
                Item& item = m_pool[idx];
                item.x = (short)x;
                item.y = (short)y;
                item.id = id;
                item.next = m_buckets[h];
                m_buckets[h] = idx;
            }
        }
    }
}

int dtProximityGrid::queryItems(const float minx, const float miny,
                                const float maxx, const float maxy,
                                unsigned short* ids, const int maxIds) const
{
    const int iminx = (int)dtMathFloorf(minx * m_invCellSize);
    const int iminy = (int)dtMathFloorf(miny * m_invCellSize);
    const int imaxx = (int)dtMathFloorf(maxx * m_invCellSize);
    const int imaxy = (int)dtMathFloorf(maxy * m_invCellSize);
    
    int n = 0;
    
    for (int y = iminy; y <= imaxy; ++y)
    {
        for (int x = iminx; x <= imaxx; ++x)
        {
            const int h = hashPos2(x, y, m_bucketsSize);
            unsigned short idx = m_buckets[h];
            while (idx != 0xffff)
            {
                Item& item = m_pool[idx];
                if ((int)item.x == x && (int)item.y == y)
                {
                    // Check if the id exists already.
                    const unsigned short* end = ids + n;
                    unsigned short* i = ids;
                    while (i != end && *i != item.id)
                        ++i;
                    // Item not found, add it.
                    if (i == end)
                    {
                        if (n >= maxIds)
                            return n;
                        ids[n++] = item.id;
                    }
                }
                idx = item.next;
            }
        }
    }
    
    return n;
}

int dtProximityGrid::getItemCountAt(const int x, const int y) const
{
    int n = 0;
    
    const int h = hashPos2(x, y, m_bucketsSize);
    unsigned short idx = m_buckets[h];
    while (idx != 0xffff)
    {
        Item& item = m_pool[idx];
        if ((int)item.x == x && (int)item.y == y)
            n++;
        idx = item.next;
    }
    
    return n;
}

Commits for Divide-Framework/trunk/Source Code/Libs/src/ReCast/DetourCrowd/Source/DetourProximityGrid.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)

315 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 15:23:33 +0000

[Ionut]
- Update ReCast to the latest version available on GitHub
- Improved nav mesh target point selection
- Added basic “go to enemy flag” logic for the WarScene teams

152 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]

151 k1ngp1n picture k1ngp1n Tue 07 May, 2013 00:00:52 +0000

[Ionut] [[BR]]
- Better ReCast integration [[BR]]
— Any entity can be used as an obstacle in the NavMesh if that’s specified in each scene’s assets.xml file for said entity [[BR]]
— New console command, “createNavMesh”, that passes geometry data to ReCast [[BR]]
-— NavMesh generation is not yet complete [[BR]]
- Better PhysX integration [[BR]]
— Each scene passes data to and gets data from the Physics API better and safer[[BR]]
- Multi-threaded support extended: [[BR]]
— Event class replaced with Task [[BR]]
— Kernel uses a threadpool for scene tasks [[BR]]
— Each task can be added to a different threadpool if needed [[BR]]
— Most critical sections use the new boost::atomic wrapper for thread safety [[BR]]
- Rendering system updated [[BR]]
— VBO’s keep track of the geometry type internally [[BR]]
— Rendering by specific element list is internal to the VBO [[BR]]
— VBO’s can draw a “lite” version that doesn’t send Tangent, BiTangent and TexCoord data for depth rendering (disabled) [[BR]]
- Reflectors now offer a preview of the generated reflective texture if needed [[BR]]
- Buttons are now added and rendered by CEGUI [[BR]]
[[BR]]
Deprecation: [[BR]]
- Removed fixed pipeline material system [[BR]]
- Removed BoundingBox late update system [[BR]]
- Shadow references in the material system are now depth references [[BR]]
[[BR]]
Bug fixes: [[BR]]
- Problematic FBO double bind check removed [[BR]]
- Faster terrain rendering via chunk size selection through each scene’s terrain.xml[[BR]]
- Rendering is paused when the window is minimized [[BR]]
- CEGUI and impostors now render properly in deferred rendering mode [[BR]]
- Fixed various level 4 (VS2008) warnings [[BR]]
- Better state management and cleaning [[BR]]
- Better SceneGraph node management and trasformation/AABB update calls [[BR]]
- AITenisScene has proper collisions now [[BR]]