Skip to content

Commit 848c60d

Browse files
committed
Reformat: xrPhysics
1 parent b2244e6 commit 848c60d

File tree

146 files changed

+21668
-23074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+21668
-23074
lines changed

src/xrPhysics/ActorCameraCollision.cpp

Lines changed: 272 additions & 286 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#pragma once
1+
#pragma once
22
class CPhysicsShell;
33
class CCameraBase;
44
class IPhysicsShellHolder;
5-
extern XRPHYSICS_API CPhysicsShell* actor_camera_shell;
5+
extern XRPHYSICS_API CPhysicsShell* actor_camera_shell;
66
#ifdef DEBUG
77
extern XRPHYSICS_API BOOL dbg_draw_camera_collision;
8-
extern XRPHYSICS_API float camera_collision_character_skin_depth ;
9-
extern XRPHYSICS_API float camera_collision_character_shift_z ;
8+
extern XRPHYSICS_API float camera_collision_character_skin_depth;
9+
extern XRPHYSICS_API float camera_collision_character_shift_z;
1010
#endif
11-
XRPHYSICS_API bool test_camera_box( const Fvector &box_size, const Fmatrix &xform, IPhysicsShellHolder* l_actor );
12-
XRPHYSICS_API void collide_camera( CCameraBase & camera, float _viewport_near , IPhysicsShellHolder *l_actor );
11+
XRPHYSICS_API bool test_camera_box(const Fvector& box_size, const Fmatrix& xform, IPhysicsShellHolder* l_actor);
12+
XRPHYSICS_API void collide_camera(CCameraBase& camera, float _viewport_near, IPhysicsShellHolder* l_actor);

src/xrPhysics/BlockAllocator.h

Lines changed: 76 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,87 @@
11
#ifndef BLOCK_ALLOCATOR_H
22
#define BLOCK_ALLOCATOR_H
3-
template<class T,u32 block_size>
3+
template <class T, u32 block_size>
44
class CBlockAllocator
55
{
6-
u32 block_count;
7-
u32 block_position;
8-
T* current_block;
9-
xr_vector<T*> blocks;
10-
public:
11-
IC T* add()
12-
{
13-
if(block_position==block_size)next_block();
14-
++block_position;
15-
return &current_block[block_position-1];
16-
}
17-
IC void empty()
18-
{
19-
block_count=0;
20-
if(blocks.size())
21-
{
22-
block_position=0;
23-
current_block=blocks[0];
24-
}
25-
else
26-
{
27-
block_position=block_size;
28-
}
29-
}
30-
CBlockAllocator()
31-
{
32-
init();
33-
}
34-
~CBlockAllocator()
35-
{
36-
clear();
37-
}
38-
IC void init ()
39-
{
40-
block_position=block_size;
41-
block_count=0;
42-
current_block=NULL;
43-
}
44-
IC void clear()
45-
{
46-
xr_vector<T*>::iterator i=blocks.begin(),e=blocks.end();
47-
for(;i!=e;++i) xr_free(*i);
48-
blocks.clear();
49-
init();
50-
}
51-
private:
52-
/////////////////////////////////////////////////////////////////
53-
IC void add_block()
54-
{
55-
blocks.push_back(xr_alloc<T>(block_size));
56-
};
57-
IC void next_block()
58-
{
6+
u32 block_count;
7+
u32 block_position;
8+
T* current_block;
9+
xr_vector<T*> blocks;
5910

60-
if(block_count==blocks.size()) add_block();
61-
current_block=blocks[block_count];
62-
++block_count;
63-
block_position=0;
64-
}
65-
////////////////////////////////////////////////////////////////
6611
public:
67-
template <typename _Predicate>
68-
IC void for_each(const _Predicate &pred)
69-
{
70-
if(! current_block) return;
71-
xr_vector<T*>::iterator i = blocks.begin();
72-
xr_vector<T*>::iterator e = blocks.begin()+block_count;
73-
u32 j;
74-
for ( ; i != e; ++i)
75-
{
76-
for(j=0;j<block_size;++j)
77-
pred.operator()((*i)+j);
78-
}
79-
for(j=0;j<block_position;++j)
80-
{
81-
pred.operator()(current_block+j);
82-
}
83-
//for_each(blocks.begin(),block.end(),pred);
84-
}
85-
private:
86-
IC T* pointer (u32 position)
87-
{
88-
return blocks[position/block_size]+position%block_size;
89-
}
90-
91-
IC T& back()
92-
{
93-
return current_block[block_position-1];
94-
}
95-
96-
IC T& back_pointer()
97-
{
98-
return current_block+block_position-1;
99-
}
12+
IC T* add()
13+
{
14+
if (block_position == block_size) next_block();
15+
++block_position;
16+
return &current_block[block_position - 1];
17+
}
18+
IC void empty()
19+
{
20+
block_count = 0;
21+
if (blocks.size()) {
22+
block_position = 0;
23+
current_block = blocks[0];
24+
}
25+
else
26+
{
27+
block_position = block_size;
28+
}
29+
}
30+
CBlockAllocator() { init(); }
31+
~CBlockAllocator() { clear(); }
32+
IC void init()
33+
{
34+
block_position = block_size;
35+
block_count = 0;
36+
current_block = NULL;
37+
}
38+
IC void clear()
39+
{
40+
xr_vector<T *>::iterator i = blocks.begin(), e = blocks.end();
41+
for (; i != e; ++i)
42+
xr_free(*i);
43+
blocks.clear();
44+
init();
45+
}
10046

101-
IC T& operator[](u32 position)
102-
{
103-
return *pointer(position);
104-
}
105-
106-
IC void construct(u32 position)
107-
{
108-
xr_allocator_t <T> ().construct(pointer(position));
109-
}
47+
private:
48+
/////////////////////////////////////////////////////////////////
49+
IC void add_block() { blocks.push_back(xr_alloc<T>(block_size)); };
50+
IC void next_block()
51+
{
52+
if (block_count == blocks.size()) add_block();
53+
current_block = blocks[block_count];
54+
++block_count;
55+
block_position = 0;
56+
}
57+
////////////////////////////////////////////////////////////////
58+
public:
59+
template <typename _Predicate>
60+
IC void for_each(const _Predicate& pred)
61+
{
62+
if (!current_block) return;
63+
xr_vector<T*>::iterator i = blocks.begin();
64+
xr_vector<T*>::iterator e = blocks.begin() + block_count;
65+
u32 j;
66+
for (; i != e; ++i)
67+
{
68+
for (j = 0; j < block_size; ++j)
69+
pred.operator()((*i) + j);
70+
}
71+
for (j = 0; j < block_position; ++j)
72+
{
73+
pred.operator()(current_block + j);
74+
}
75+
// for_each(blocks.begin(),block.end(),pred);
76+
}
11077

111-
IC void construct_back()
112-
{
113-
xr_allocator_t <T> ().construct(back_pointer());
114-
}
78+
private:
79+
IC T* pointer(u32 position) { return blocks[position / block_size] + position % block_size; }
80+
IC T& back() { return current_block[block_position - 1]; }
81+
IC T& back_pointer() { return current_block + block_position - 1; }
82+
IC T& operator[](u32 position) { return *pointer(position); }
83+
IC void construct(u32 position) { xr_allocator_t<T>().construct(pointer(position)); }
84+
IC void construct_back() { xr_allocator_t<T>().construct(back_pointer()); }
11585
};
11686

117-
11887
#endif

0 commit comments

Comments
 (0)