Skip to content

Commit

Permalink
Reformat: xrPhysics
Browse files Browse the repository at this point in the history
  • Loading branch information
invokr committed Jan 15, 2017
1 parent b2244e6 commit 848c60d
Show file tree
Hide file tree
Showing 146 changed files with 21,668 additions and 23,074 deletions.
558 changes: 272 additions & 286 deletions src/xrPhysics/ActorCameraCollision.cpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/xrPhysics/ActorCameraCollision.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once
#pragma once
class CPhysicsShell;
class CCameraBase;
class IPhysicsShellHolder;
extern XRPHYSICS_API CPhysicsShell* actor_camera_shell;
extern XRPHYSICS_API CPhysicsShell* actor_camera_shell;
#ifdef DEBUG
extern XRPHYSICS_API BOOL dbg_draw_camera_collision;
extern XRPHYSICS_API float camera_collision_character_skin_depth ;
extern XRPHYSICS_API float camera_collision_character_shift_z ;
extern XRPHYSICS_API float camera_collision_character_skin_depth;
extern XRPHYSICS_API float camera_collision_character_shift_z;
#endif
XRPHYSICS_API bool test_camera_box( const Fvector &box_size, const Fmatrix &xform, IPhysicsShellHolder* l_actor );
XRPHYSICS_API void collide_camera( CCameraBase & camera, float _viewport_near , IPhysicsShellHolder *l_actor );
XRPHYSICS_API bool test_camera_box(const Fvector& box_size, const Fmatrix& xform, IPhysicsShellHolder* l_actor);
XRPHYSICS_API void collide_camera(CCameraBase& camera, float _viewport_near, IPhysicsShellHolder* l_actor);
183 changes: 76 additions & 107 deletions src/xrPhysics/BlockAllocator.h
Original file line number Diff line number Diff line change
@@ -1,118 +1,87 @@
#ifndef BLOCK_ALLOCATOR_H
#define BLOCK_ALLOCATOR_H
template<class T,u32 block_size>
template <class T, u32 block_size>
class CBlockAllocator
{
u32 block_count;
u32 block_position;
T* current_block;
xr_vector<T*> blocks;
public:
IC T* add()
{
if(block_position==block_size)next_block();
++block_position;
return &current_block[block_position-1];
}
IC void empty()
{
block_count=0;
if(blocks.size())
{
block_position=0;
current_block=blocks[0];
}
else
{
block_position=block_size;
}
}
CBlockAllocator()
{
init();
}
~CBlockAllocator()
{
clear();
}
IC void init ()
{
block_position=block_size;
block_count=0;
current_block=NULL;
}
IC void clear()
{
xr_vector<T*>::iterator i=blocks.begin(),e=blocks.end();
for(;i!=e;++i) xr_free(*i);
blocks.clear();
init();
}
private:
/////////////////////////////////////////////////////////////////
IC void add_block()
{
blocks.push_back(xr_alloc<T>(block_size));
};
IC void next_block()
{
u32 block_count;
u32 block_position;
T* current_block;
xr_vector<T*> blocks;

if(block_count==blocks.size()) add_block();
current_block=blocks[block_count];
++block_count;
block_position=0;
}
////////////////////////////////////////////////////////////////
public:
template <typename _Predicate>
IC void for_each(const _Predicate &pred)
{
if(! current_block) return;
xr_vector<T*>::iterator i = blocks.begin();
xr_vector<T*>::iterator e = blocks.begin()+block_count;
u32 j;
for ( ; i != e; ++i)
{
for(j=0;j<block_size;++j)
pred.operator()((*i)+j);
}
for(j=0;j<block_position;++j)
{
pred.operator()(current_block+j);
}
//for_each(blocks.begin(),block.end(),pred);
}
private:
IC T* pointer (u32 position)
{
return blocks[position/block_size]+position%block_size;
}

IC T& back()
{
return current_block[block_position-1];
}

IC T& back_pointer()
{
return current_block+block_position-1;
}
IC T* add()
{
if (block_position == block_size) next_block();
++block_position;
return &current_block[block_position - 1];
}
IC void empty()
{
block_count = 0;
if (blocks.size()) {
block_position = 0;
current_block = blocks[0];
}
else
{
block_position = block_size;
}
}
CBlockAllocator() { init(); }
~CBlockAllocator() { clear(); }
IC void init()
{
block_position = block_size;
block_count = 0;
current_block = NULL;
}
IC void clear()
{
xr_vector<T *>::iterator i = blocks.begin(), e = blocks.end();
for (; i != e; ++i)
xr_free(*i);
blocks.clear();
init();
}

IC T& operator[](u32 position)
{
return *pointer(position);
}

IC void construct(u32 position)
{
xr_allocator_t <T> ().construct(pointer(position));
}
private:
/////////////////////////////////////////////////////////////////
IC void add_block() { blocks.push_back(xr_alloc<T>(block_size)); };
IC void next_block()
{
if (block_count == blocks.size()) add_block();
current_block = blocks[block_count];
++block_count;
block_position = 0;
}
////////////////////////////////////////////////////////////////
public:
template <typename _Predicate>
IC void for_each(const _Predicate& pred)
{
if (!current_block) return;
xr_vector<T*>::iterator i = blocks.begin();
xr_vector<T*>::iterator e = blocks.begin() + block_count;
u32 j;
for (; i != e; ++i)
{
for (j = 0; j < block_size; ++j)
pred.operator()((*i) + j);
}
for (j = 0; j < block_position; ++j)
{
pred.operator()(current_block + j);
}
// for_each(blocks.begin(),block.end(),pred);
}

IC void construct_back()
{
xr_allocator_t <T> ().construct(back_pointer());
}
private:
IC T* pointer(u32 position) { return blocks[position / block_size] + position % block_size; }
IC T& back() { return current_block[block_position - 1]; }
IC T& back_pointer() { return current_block + block_position - 1; }
IC T& operator[](u32 position) { return *pointer(position); }
IC void construct(u32 position) { xr_allocator_t<T>().construct(pointer(position)); }
IC void construct_back() { xr_allocator_t<T>().construct(back_pointer()); }
};


#endif
Loading

0 comments on commit 848c60d

Please sign in to comment.