Added access to the loaded textures on the texture group loader.

Added live write option to the log, to force non-delayed writing to the file.
Added a try catch to the cWindowAl window creation.
Fixed a mayor bug on the SOIL texture loading, that caused to segfault when tried to resize a non-power of two texture.
Fixed a minor bug on the VBO.
Fixed a minor bug on cUIWinMenu.
Fixed how the SDL version is consulted on SDL 1.2 backend.
Updated chipmunk.
Updated Windows eetest cbp project.
This commit is contained in:
spartanj
2011-05-27 03:11:15 -03:00
parent 18e4c925bd
commit 772bae4768
41 changed files with 504 additions and 239 deletions

View File

@@ -168,7 +168,7 @@ SRCCHIPMUNK = $(wildcard ./src/helper/chipmunk/*.c) $(wildcard ./src/helper/ch
SRCHAIKUTTF = $(wildcard ./src/helper/haikuttf/*.cpp)
SRCBASE = $(wildcard ./src/base/*.cpp)
SRCAUDIO = $(wildcard ./src/audio/*.cpp)
SRCGAMING = $(wildcard ./src/gaming/*.cpp)
SRCGAMING = $(wildcard ./src/gaming/*.cpp) $(wildcard ./src/gaming/mapeditor/*.cpp)
SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp) $(wildcard ./src/graphics/renderer/*.cpp)
SRCMATH = $(wildcard ./src/math/*.cpp)
SRCSYSTEM = $(wildcard ./src/system/*.cpp)
@@ -243,6 +243,7 @@ dirs:
@mkdir -p $(OBJDIR)/src/base
@mkdir -p $(OBJDIR)/src/audio
@mkdir -p $(OBJDIR)/src/gaming
@mkdir -p $(OBJDIR)/src/gaming/mapeditor
@mkdir -p $(OBJDIR)/src/graphics
@mkdir -p $(OBJDIR)/src/graphics/renderer
@mkdir -p $(OBJDIR)/src/math

View File

@@ -36,6 +36,7 @@
<Add option="-std=gnu99 -fno-strict-aliasing -ffast-math -DSTBI_FAILURE_USERMSG -Wno-unknown-pragmas -Wno-unknown-pragmas -DEE_BACKEND_ALLEGRO_ACTIVE -DEE_BACKEND_SDL_ACTIVE" />
<Add directory=".\src\helper\chipmunk" />
<Add directory=".\src\helper\zlib" />
<Add directory="C:\MinGW\include\freetype2" />
</Compiler>
<Linker>
<Add option="-mwindows" />
@@ -84,12 +85,33 @@
<Unit filename="src\base\string.cpp" />
<Unit filename="src\base\string.hpp" />
<Unit filename="src\base\utf.hpp" />
<Unit filename="src\base\utf.inl" />
<Unit filename="src\ee.h" />
<Unit filename="src\gaming\base.hpp" />
<Unit filename="src\gaming\cgameobject.cpp" />
<Unit filename="src\gaming\cgameobject.hpp" />
<Unit filename="src\gaming\cgameobjectshape.cpp" />
<Unit filename="src\gaming\cgameobjectshape.hpp" />
<Unit filename="src\gaming\cgameobjectshapeex.cpp" />
<Unit filename="src\gaming\cgameobjectshapeex.hpp" />
<Unit filename="src\gaming\cgameobjectsprite.cpp" />
<Unit filename="src\gaming\cgameobjectsprite.hpp" />
<Unit filename="src\gaming\cisomap.cpp" />
<Unit filename="src\gaming\cisomap.hpp" />
<Unit filename="src\gaming\clayer.cpp" />
<Unit filename="src\gaming\clayer.hpp" />
<Unit filename="src\gaming\clight.cpp" />
<Unit filename="src\gaming\clight.hpp" />
<Unit filename="src\gaming\cmap.cpp" />
<Unit filename="src\gaming\cmap.hpp" />
<Unit filename="src\gaming\cobjectlayer.cpp" />
<Unit filename="src\gaming\cobjectlayer.hpp" />
<Unit filename="src\gaming\ctilelayer.cpp" />
<Unit filename="src\gaming\ctilelayer.hpp" />
<Unit filename="src\gaming\mapeditor\base.hpp" />
<Unit filename="src\gaming\mapeditor\cmapeditor.cpp" />
<Unit filename="src\gaming\mapeditor\cmapeditor.hpp" />
<Unit filename="src\gaming\maphelper.hpp" />
<Unit filename="src\graphics\base.hpp" />
<Unit filename="src\graphics\cbatchrenderer.cpp" />
<Unit filename="src\graphics\cbatchrenderer.hpp" />
@@ -310,6 +332,9 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="src\helper\chipmunk\cpSpatialIndex.h" />
<Unit filename="src\helper\chipmunk\cpSweep1D.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src\helper\chipmunk\cpVect.c">
<Option compilerVar="CC" />
</Unit>
@@ -691,6 +716,8 @@
<Unit filename="src\ui\cuicheckbox.hpp" />
<Unit filename="src\ui\cuicombobox.cpp" />
<Unit filename="src\ui\cuicombobox.hpp" />
<Unit filename="src\ui\cuicommondialog.cpp" />
<Unit filename="src\ui\cuicommondialog.hpp" />
<Unit filename="src\ui\cuicomplexcontrol.cpp" />
<Unit filename="src\ui\cuicomplexcontrol.hpp" />
<Unit filename="src\ui\cuicontrol.cpp" />
@@ -739,6 +766,8 @@
<Unit filename="src\ui\cuiradiobutton.hpp" />
<Unit filename="src\ui\cuiscrollbar.cpp" />
<Unit filename="src\ui\cuiscrollbar.hpp" />
<Unit filename="src\ui\cuiselectbutton.cpp" />
<Unit filename="src\ui\cuiselectbutton.hpp" />
<Unit filename="src\ui\cuiseparator.cpp" />
<Unit filename="src\ui\cuiseparator.hpp" />
<Unit filename="src\ui\cuiskin.cpp" />
@@ -771,6 +800,8 @@
<Unit filename="src\ui\cuitooltip.hpp" />
<Unit filename="src\ui\cuiwindow.cpp" />
<Unit filename="src\ui\cuiwindow.hpp" />
<Unit filename="src\ui\cuiwinmenu.cpp" />
<Unit filename="src\ui\cuiwinmenu.hpp" />
<Unit filename="src\ui\tuiitemcontainer.hpp" />
<Unit filename="src\ui\uihelper.cpp" />
<Unit filename="src\ui\uihelper.hpp" />
@@ -797,6 +828,22 @@
<Unit filename="src\utils\utils.hpp" />
<Unit filename="src\utils\vector2.hpp" />
<Unit filename="src\utils\vector3.hpp" />
<Unit filename="src\window\backend\SDL13\base.hpp" />
<Unit filename="src\window\backend\SDL13\cbackendsdl.hpp" />
<Unit filename="src\window\backend\SDL13\cclipboardsdl.cpp" />
<Unit filename="src\window\backend\SDL13\cclipboardsdl.hpp" />
<Unit filename="src\window\backend\SDL13\ccursormanagersdl.cpp" />
<Unit filename="src\window\backend\SDL13\ccursormanagersdl.hpp" />
<Unit filename="src\window\backend\SDL13\ccursorsdl.cpp" />
<Unit filename="src\window\backend\SDL13\ccursorsdl.hpp" />
<Unit filename="src\window\backend\SDL13\cinputsdl.cpp" />
<Unit filename="src\window\backend\SDL13\cinputsdl.hpp" />
<Unit filename="src\window\backend\SDL13\cjoystickmanagersdl.cpp" />
<Unit filename="src\window\backend\SDL13\cjoystickmanagersdl.hpp" />
<Unit filename="src\window\backend\SDL13\cjoysticksdl.cpp" />
<Unit filename="src\window\backend\SDL13\cjoysticksdl.hpp" />
<Unit filename="src\window\backend\SDL13\cwindowsdl.cpp" />
<Unit filename="src\window\backend\SDL13\cwindowsdl.hpp" />
<Unit filename="src\window\backend\SDL\cbackendsdl.hpp" />
<Unit filename="src\window\backend\SDL\cclipboardsdl.cpp" />
<Unit filename="src\window\backend\SDL\cclipboardsdl.hpp" />

View File

@@ -6,11 +6,11 @@ namespace EE { namespace Gaming {
class GObjFlags {
public:
enum EE_GAMEOBJECT_FLAGS {
GAMEOBJECT_STATIC = 0,
GAMEOBJECT_ANIMATED,
GAMEOBJECT_MIRRORED,
GAMEOBJECT_FLIPED,
GAMEOBJECT_BLOCKED
GAMEOBJECT_STATIC = ( 1 << 0 ),
GAMEOBJECT_ANIMATED = ( 1 << 1 ),
GAMEOBJECT_MIRRORED = ( 1 << 2 ),
GAMEOBJECT_FLIPED = ( 1 << 3 ),
GAMEOBJECT_BLOCKED = ( 1 << 4 )
};
};

View File

@@ -176,11 +176,14 @@ void cTextureGroupLoader::CreateShapes() {
Int32 pos = StrStartsWith( mAppPath, path );
// Removes the app path part
if ( -1 != pos && (Uint32)(pos + 1) < path.size() )
path = path.substr( pos + 1 );
cTexture * tTex = cTextureFactory::instance()->GetByName( path );
mTexuresLoaded.push_back( tTex );
// Create the Shape Group with the name of the real texture, not the Childs ( example load 1.png and not 1_ch1.png )
if ( 0 == z ) {
if ( mTexGrHdr.Flags & HDR_TEXTURE_GROUP_REMOVE_EXTENSION )
@@ -236,6 +239,15 @@ const bool& cTextureGroupLoader::IsLoading() const {
return mIsLoading;
}
cTexture * cTextureGroupLoader::GetTexture( const Uint32& texnum ) const {
eeASSERT( texnum < mTexuresLoaded.size() );
return mTexuresLoaded[ texnum ];
}
Uint32 cTextureGroupLoader::GetTexturesLoadedCount() {
return mTexuresLoaded.size();
}
bool cTextureGroupLoader::UpdateTextureAtlas( std::string TextureAtlasPath, std::string ImagesPath ) {
if ( !TextureAtlasPath.size() || !ImagesPath.size() || !FileExists( TextureAtlasPath ) || !IsDirectory( ImagesPath ) )
return false;

View File

@@ -41,15 +41,20 @@ class EE_API cTextureGroupLoader {
/** Will check if the texture atlas is updated ( all the image of the path are inside the texture atlas, and are the same version, otherwise it will recreate or update the texture atlas. */
bool UpdateTextureAtlas( std::string TextureAtlasPath, std::string ImagesPath );
cTexture * GetTexture( const Uint32& texnum = 0 ) const;
Uint32 GetTexturesLoadedCount();
protected:
cResourceLoader mRL;
std::string mTextureGroupPath;
bool mThreaded;
bool mLoaded;
std::string mAppPath;
cPack * mPack;
bool mSkipResourceLoad;
bool mIsLoading;
cResourceLoader mRL;
std::string mTextureGroupPath;
bool mThreaded;
bool mLoaded;
std::string mAppPath;
cPack * mPack;
bool mSkipResourceLoad;
bool mIsLoading;
std::vector<cTexture*> mTexuresLoaded;
typedef struct sTempTexGroupS {
sTextureHdr Texture;

View File

@@ -76,7 +76,7 @@ bool cVertexBufferVBO::Compile() {
}
}
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBufferARB( GL_ARRAY_BUFFER, 0 );
//Create the VBO index array
if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) ) {

View File

@@ -115,7 +115,8 @@ void cGL::Init() {
WriteExtension( EEGL_EXT_framebuffer_object , GLEW_EXT_framebuffer_object );
WriteExtension( EEGL_ARB_multitexture , GLEW_ARB_multitexture );
WriteExtension( EEGL_EXT_texture_compression_s3tc , GLEW_EXT_texture_compression_s3tc );
WriteExtension( EEGL_ARB_vertex_buffer_object , GLEW_ARB_vertex_buffer_object );
WriteExtension( EEGL_ARB_vertex_buffer_object , GLEW_ARB_vertex_buffer_object );
WriteExtension( EEGL_ARB_vertex_array_object , GLEW_ARB_vertex_array_object );
}
else
#endif
@@ -130,7 +131,8 @@ void cGL::Init() {
WriteExtension( EEGL_EXT_framebuffer_object , IsExtension( "GL_EXT_framebuffer_object" ) );
WriteExtension( EEGL_ARB_multitexture , IsExtension( "GL_ARB_multitexture" ) );
WriteExtension( EEGL_EXT_texture_compression_s3tc , IsExtension( "GL_EXT_texture_compression_s3tc" ) );
WriteExtension( EEGL_ARB_vertex_buffer_object , IsExtension( "GL_ARB_vertex_buffer_object" ) );
WriteExtension( EEGL_ARB_vertex_buffer_object , IsExtension( "GL_ARB_vertex_buffer_object" ) );
WriteExtension( EEGL_ARB_vertex_array_object , IsExtension( "GL_ARB_vertex_array_object" ) );
glewOn = false; /// avoid compiler warning
}
@@ -343,12 +345,14 @@ std::string cGL::GetVersion() {
return std::string( reinterpret_cast<const char*> ( cGL::instance()->GetString( GL_VERSION ) ) );
}
std::string cGL::GetShadingLanguageVersion() {
#ifdef GL_SHADING_LANGUAGE_VERSION
return std::string( reinterpret_cast<const char*> ( cGL::instance()->GetString( GL_SHADING_LANGUAGE_VERSION ) ) );
#else
return std::string( "0" );
#endif
std::string cGL::GetShadingLanguageVersion() {
if ( ShadersSupported() ) {
#ifdef GL_SHADING_LANGUAGE_VERSION
return std::string( reinterpret_cast<const char*> ( cGL::instance()->GetString( GL_SHADING_LANGUAGE_VERSION ) ) );
#endif
}
return std::string( "Shaders not supported" );
}
}}

View File

@@ -17,7 +17,8 @@ enum EEGL_extensions {
EEGL_EXT_framebuffer_object,
EEGL_ARB_multitexture,
EEGL_EXT_texture_compression_s3tc,
EEGL_ARB_vertex_buffer_object
EEGL_ARB_vertex_buffer_object,
EEGL_ARB_vertex_array_object
};
enum EEGL_version {

View File

@@ -1043,6 +1043,14 @@ unsigned int
}
}
/* if the user can't support NPOT textures, make sure we force the POT option */
if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) &&
!(flags & SOIL_FLAG_TEXTURE_RECTANGLE) )
{
/* add in the POT flag */
flags |= SOIL_FLAG_POWER_OF_TWO;
}
needCopy = ( ( flags & SOIL_FLAG_INVERT_Y ) || ( flags & SOIL_FLAG_NTSC_SAFE_RGB ) || ( flags & SOIL_FLAG_MULTIPLY_ALPHA ) || ( ( flags & SOIL_FLAG_POWER_OF_TWO ) || ( flags & SOIL_FLAG_MIPMAPS ) || ( iwidth > max_supported_size ) || ( iheight > max_supported_size ) ) || ( flags & SOIL_FLAG_CoCg_Y ) || ( flags & SOIL_FLAG_COMPRESS_TO_DXT ) );
/* create a copy the image data
@@ -1102,13 +1110,6 @@ unsigned int
break;
}
}
/* if the user can't support NPOT textures, make sure we force the POT option */
if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) &&
!(flags & SOIL_FLAG_TEXTURE_RECTANGLE) )
{
/* add in the POT flag */
flags |= SOIL_FLAG_POWER_OF_TWO;
}
/* do I need to make it a power of 2? */
if(

View File

@@ -58,7 +58,6 @@ void cpMessage(const char *message, const char *condition, const char *file, int
#define CP_BUFFER_BYTES (32*1024)
//TODO allow redifinition
#define cpmalloc malloc
#define cpcalloc calloc
#define cprealloc realloc
#define cpfree free

View File

@@ -103,6 +103,11 @@ void cpArbiterPreStep(cpArbiter *arb, cpFloat dt, cpFloat bias, cpFloat slop);
void cpArbiterApplyCachedImpulse(cpArbiter *arb, cpFloat dt_coef);
void cpArbiterApplyImpulse(cpArbiter *arb);
#pragma mark Body Functions
void cpBodyAddShape(cpBody *body, cpShape *shape);
void cpBodyRemoveShape(cpBody *body, cpShape *shape);
#pragma mark Shape/Collision Functions
cpShape* cpShapeInit(cpShape *shape, const cpShapeClass *klass, cpBody *body);

View File

@@ -40,7 +40,7 @@ preStep(cpDampedRotarySpring *spring, cpFloat dt)
cpAssert(moment != 0.0, "Unsolvable spring.");
spring->iSum = 1.0f/moment;
spring->w_coef = 1.0f - cpfexp(-spring->damping*dt*moment*0.25f/(cpFloat)M_E);
spring->w_coef = 1.0f - cpfexp(-spring->damping*dt*moment);
spring->target_wrn = 0.0f;
// apply spring torque
@@ -62,13 +62,13 @@ applyImpulse(cpDampedRotarySpring *spring)
// compute velocity loss from drag
// not 100% certain this is derived correctly, though it makes sense
cpFloat w_damp = wrn*spring->w_coef;
spring->target_wrn = wrn - w_damp;
cpFloat w_damp = (spring->target_wrn - wrn)*spring->w_coef;
spring->target_wrn = wrn + w_damp;
//apply_impulses(a, b, spring->r1, spring->r2, cpvmult(spring->n, v_damp*spring->nMass));
cpFloat j_damp = w_damp*spring->iSum;
a->w -= j_damp*a->i_inv;
b->w += j_damp*b->i_inv;
a->w += j_damp*a->i_inv;
b->w -= j_damp*b->i_inv;
}
static cpFloat
@@ -88,7 +88,7 @@ CP_DefineClassGetter(cpDampedRotarySpring)
cpDampedRotarySpring *
cpDampedRotarySpringAlloc(void)
{
return (cpDampedRotarySpring *)cpmalloc(sizeof(cpDampedRotarySpring));
return (cpDampedRotarySpring *)cpcalloc(1, sizeof(cpDampedRotarySpring));
}
cpDampedRotarySpring *

View File

@@ -48,7 +48,7 @@ preStep(cpDampedSpring *spring, cpFloat dt)
spring->nMass = 1.0f/k;
spring->target_vrn = 0.0f;
spring->v_coef = 1.0f - cpfexp(-spring->damping*dt*k*0.5f/(cpFloat)M_E);
spring->v_coef = 1.0f - cpfexp(-spring->damping*dt*k);
// apply spring force
cpFloat f_spring = spring->springForceFunc((cpConstraint *)spring, dist);
@@ -68,10 +68,10 @@ applyImpulse(cpDampedSpring *spring)
cpVect r2 = spring->r2;
// compute relative velocity
cpFloat vrn = normal_relative_velocity(a, b, r1, r2, n) - spring->target_vrn;
cpFloat vrn = normal_relative_velocity(a, b, r1, r2, n);
// compute velocity loss from drag
cpFloat v_damp = -vrn*spring->v_coef;
cpFloat v_damp = (spring->target_vrn - vrn)*spring->v_coef;
spring->target_vrn = vrn + v_damp;
apply_impulses(a, b, spring->r1, spring->r2, cpvmult(spring->n, v_damp*spring->nMass));
@@ -94,7 +94,7 @@ CP_DefineClassGetter(cpDampedSpring)
cpDampedSpring *
cpDampedSpringAlloc(void)
{
return (cpDampedSpring *)cpmalloc(sizeof(cpDampedSpring));
return (cpDampedSpring *)cpcalloc(1, sizeof(cpDampedSpring));
}
cpDampedSpring *

View File

@@ -90,7 +90,7 @@ CP_DefineClassGetter(cpGearJoint)
cpGearJoint *
cpGearJointAlloc(void)
{
return (cpGearJoint *)cpmalloc(sizeof(cpGearJoint));
return (cpGearJoint *)cpcalloc(1, sizeof(cpGearJoint));
}
cpGearJoint *

View File

@@ -121,7 +121,7 @@ CP_DefineClassGetter(cpGrooveJoint)
cpGrooveJoint *
cpGrooveJointAlloc(void)
{
return (cpGrooveJoint *)cpmalloc(sizeof(cpGrooveJoint));
return (cpGrooveJoint *)cpcalloc(1, sizeof(cpGrooveJoint));
}
cpGrooveJoint *

View File

@@ -97,7 +97,7 @@ CP_DefineClassGetter(cpPinJoint);
cpPinJoint *
cpPinJointAlloc(void)
{
return (cpPinJoint *)cpmalloc(sizeof(cpPinJoint));
return (cpPinJoint *)cpcalloc(1, sizeof(cpPinJoint));
}
cpPinJoint *

View File

@@ -93,7 +93,7 @@ CP_DefineClassGetter(cpPivotJoint)
cpPivotJoint *
cpPivotJointAlloc(void)
{
return (cpPivotJoint *)cpmalloc(sizeof(cpPivotJoint));
return (cpPivotJoint *)cpcalloc(1, sizeof(cpPivotJoint));
}
cpPivotJoint *

View File

@@ -110,7 +110,7 @@ CP_DefineClassGetter(cpRatchetJoint)
cpRatchetJoint *
cpRatchetJointAlloc(void)
{
return (cpRatchetJoint *)cpmalloc(sizeof(cpRatchetJoint));
return (cpRatchetJoint *)cpcalloc(1, sizeof(cpRatchetJoint));
}
cpRatchetJoint *

View File

@@ -107,7 +107,7 @@ CP_DefineClassGetter(cpRotaryLimitJoint)
cpRotaryLimitJoint *
cpRotaryLimitJointAlloc(void)
{
return (cpRotaryLimitJoint *)cpmalloc(sizeof(cpRotaryLimitJoint));
return (cpRotaryLimitJoint *)cpcalloc(1, sizeof(cpRotaryLimitJoint));
}
cpRotaryLimitJoint *

View File

@@ -86,7 +86,7 @@ CP_DefineClassGetter(cpSimpleMotor)
cpSimpleMotor *
cpSimpleMotorAlloc(void)
{
return (cpSimpleMotor *)cpmalloc(sizeof(cpSimpleMotor));
return (cpSimpleMotor *)cpcalloc(1, sizeof(cpSimpleMotor));
}
cpSimpleMotor *

View File

@@ -112,7 +112,7 @@ CP_DefineClassGetter(cpSlideJoint)
cpSlideJoint *
cpSlideJointAlloc(void)
{
return (cpSlideJoint *)cpmalloc(sizeof(cpSlideJoint));
return (cpSlideJoint *)cpcalloc(1, sizeof(cpSlideJoint));
}
cpSlideJoint *

View File

@@ -153,7 +153,7 @@ PairFromPool(cpBBTree *tree)
int count = CP_BUFFER_BYTES/sizeof(Pair);
cpAssert(count, "Buffer size is too small.");
Pair *buffer = (Pair *)cpmalloc(CP_BUFFER_BYTES);
Pair *buffer = (Pair *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(tree->allocatedBuffers, buffer);
// push all but the first one, return the first instead
@@ -242,7 +242,7 @@ NodeFromPool(cpBBTree *tree)
int count = CP_BUFFER_BYTES/sizeof(Node);
cpAssert(count, "Buffer size is too small.");
Node *buffer = (Node *)cpmalloc(CP_BUFFER_BYTES);
Node *buffer = (Node *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(tree->allocatedBuffers, buffer);
// push all but the first one, return the first instead
@@ -578,7 +578,7 @@ cpBBTreeDestroy(cpBBTree *tree)
{
cpHashSetFree(tree->leaves);
cpArrayFreeEach(tree->allocatedBuffers, cpfree);
if(tree->allocatedBuffers) cpArrayFreeEach(tree->allocatedBuffers, cpfree);
cpArrayFree(tree->allocatedBuffers);
}

View File

@@ -32,14 +32,12 @@ cpBody cpStaticBodySingleton;
cpBody*
cpBodyAlloc(void)
{
return (cpBody *)cpmalloc(sizeof(cpBody));
return (cpBody *)cpcalloc(1, sizeof(cpBody));
}
cpBody *
cpBodyInit(cpBody *body, cpFloat m, cpFloat i)
{
bzero(body, sizeof(cpBody));
body->space = NULL;
body->shapeList = NULL;
body->arbiterList = NULL;
@@ -48,14 +46,13 @@ cpBodyInit(cpBody *body, cpFloat m, cpFloat i)
body->velocity_func = cpBodyUpdateVelocity;
body->position_func = cpBodyUpdatePosition;
cpBodySetMass(body, m);
cpBodySetMoment(body, i);
cpComponentNode node = {NULL, NULL, 0.0f};
body->node = node;
body->p = cpvzero;
body->v = cpvzero;
body->f = cpvzero;
cpBodySetAngle(body, 0.0f);
body->w = 0.0f;
body->t = 0.0f;
@@ -65,11 +62,13 @@ cpBodyInit(cpBody *body, cpFloat m, cpFloat i)
body->v_limit = (cpFloat)INFINITY;
body->w_limit = (cpFloat)INFINITY;
cpComponentNode node = {NULL, NULL, 0.0f};
body->node = node;
body->data = NULL;
// Setters must be called after full initialization so the sanity checks don't assert on garbage data.
cpBodySetMass(body, m);
cpBodySetMoment(body, i);
cpBodySetAngle(body, 0.0f);
return body;
}
@@ -145,6 +144,27 @@ cpBodySetMoment(cpBody *body, cpFloat moment)
body->i_inv = 1.0f/moment;
}
void
cpBodyAddShape(cpBody *body, cpShape *shape)
{
shape->next = body->shapeList; body->shapeList = shape;
}
void
cpBodyRemoveShape(cpBody *body, cpShape *shape)
{
cpShape **prev_ptr = &body->shapeList;
cpShape *node = body->shapeList;
while(node && node != shape){
prev_ptr = &node->next;
node = node->next;
}
cpAssert(node, "Attempted to remove a shape from a body it was never attached to.");
(*prev_ptr) = node->next;
}
static inline void
updateShapes(cpBody *body){
cpSpace *space = body->space;

View File

@@ -137,7 +137,7 @@ getUnusedBin(cpHashSet *set)
int count = CP_BUFFER_BYTES/sizeof(cpHashSetBin);
cpAssert(count, "Buffer size is too small.");
cpHashSetBin *buffer = (cpHashSetBin *)cpmalloc(CP_BUFFER_BYTES);
cpHashSetBin *buffer = (cpHashSetBin *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(set->allocatedBuffers, buffer);
// push all but the first one, return it instead

View File

@@ -75,10 +75,8 @@ cpPolyShapeCacheData(cpPolyShape *poly, cpVect p, cpVect rot)
}
static void
cpPolyShapeDestroy(cpShape *shape)
cpPolyShapeDestroy(cpPolyShape *poly)
{
cpPolyShape *poly = (cpPolyShape *)shape;
cpfree(poly->verts);
cpfree(poly->tVerts);
@@ -227,6 +225,6 @@ void
cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset)
{
cpAssert(shape->klass == &polyClass, "Shape is not a poly shape.");
cpPolyShapeDestroy(shape);
cpPolyShapeDestroy((cpPolyShape *)shape);
setUpVerts((cpPolyShape *)shape, numVerts, verts, offset);
}

View File

@@ -69,7 +69,7 @@ cpShapeInit(cpShape *shape, const cpShapeClass *klass, cpBody *body)
void
cpShapeDestroy(cpShape *shape)
{
if(shape->klass->destroy) shape->klass->destroy(shape);
if(shape->klass && shape->klass->destroy) shape->klass->destroy(shape);
}
void
@@ -81,6 +81,19 @@ cpShapeFree(cpShape *shape)
}
}
void
cpShapeSetBody(cpShape *shape, cpBody *body)
{
// This is a little tricky, but was requested by a user.
// Changing the body on an active shape swapping out the shape lists on the bodies
if(shape->next){
cpBodyRemoveShape(shape->body, shape);
cpBodyAddShape(body, shape);
}
shape->body = body;
}
cpBB
cpShapeCacheBB(cpShape *shape)
{

View File

@@ -121,8 +121,9 @@ static inline void cpShapeSet##name(cpShape *shape, type value){ \
CP_DefineShapeStructGetter(type, member, name) \
CP_DefineShapeStructSetter(type, member, name, activates)
// TODO the properties
CP_DefineShapeStructProperty(cpBody *, body, Body, cpTrue);
CP_DefineShapeStructGetter(cpBody *, body, Body);
void cpShapeSetBody(cpShape *shape, cpBody *body);
CP_DefineShapeStructGetter(cpBB, bb, BB);
CP_DefineShapeStructProperty(cpBool, sensor, IsSensor, cpTrue);
CP_DefineShapeStructProperty(cpFloat, e, Elasticity, cpFalse);

View File

@@ -51,7 +51,7 @@ handlerSetEql(cpCollisionHandler *check, cpCollisionHandler *pair)
static void *
handlerSetTrans(cpCollisionHandler *handler, void *unused)
{
cpCollisionHandler *copy = (cpCollisionHandler *)cpmalloc(sizeof(cpCollisionHandler));
cpCollisionHandler *copy = (cpCollisionHandler *)cpcalloc(1, sizeof(cpCollisionHandler));
(*copy) = (*handler);
return copy;
@@ -155,15 +155,11 @@ cpSpaceDestroy(cpSpace *space)
cpArrayFree(space->allocatedBuffers);
}
if(space->postStepCallbacks){
cpHashSetEach(space->postStepCallbacks, freeWrap, NULL);
cpHashSetFree(space->postStepCallbacks);
}
if(space->postStepCallbacks) cpHashSetEach(space->postStepCallbacks, freeWrap, NULL);
cpHashSetFree(space->postStepCallbacks);
if(space->collisionHandlers){
cpHashSetEach(space->collisionHandlers, freeWrap, NULL);
cpHashSetFree(space->collisionHandlers);
}
if(space->collisionHandlers) cpHashSetEach(space->collisionHandlers, freeWrap, NULL);
cpHashSetFree(space->collisionHandlers);
}
void
@@ -175,6 +171,12 @@ cpSpaceFree(cpSpace *space)
}
}
#define cpAssertSpaceUnlocked(space) \
cpAssert(!space->locked, \
"This addition/removal cannot be done safely during a call to cpSpaceStep() or during a query. " \
"Put these calls into a post-step callback." \
);
#pragma mark Collision Handler Function Management
void
@@ -187,6 +189,8 @@ cpSpaceAddCollisionHandler(
cpCollisionSeparateFunc separate,
void *data
){
cpAssertSpaceUnlocked(space);
// Remove any old function so the new one will get added.
cpSpaceRemoveCollisionHandler(space, a, b);
@@ -205,6 +209,8 @@ cpSpaceAddCollisionHandler(
void
cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b)
{
cpAssertSpaceUnlocked(space);
struct { cpCollisionType a, b; } ids = {a, b};
cpCollisionHandler *old_handler = (cpCollisionHandler *) cpHashSetRemove(space->collisionHandlers, CP_HASH_PAIR(a, b), &ids);
cpfree(old_handler);
@@ -219,6 +225,8 @@ cpSpaceSetDefaultCollisionHandler(
cpCollisionSeparateFunc separate,
void *data
){
cpAssertSpaceUnlocked(space);
cpCollisionHandler handler = {
0, 0,
begin ? begin : alwaysCollide,
@@ -233,28 +241,6 @@ cpSpaceSetDefaultCollisionHandler(
}
#pragma mark Body, Shape, and Joint Management
#define cpAssertSpaceUnlocked(space) \
cpAssert(!space->locked, \
"This addition/removal cannot be done safely during a call to cpSpaceStep() or during a query. " \
"Put these calls into a post-step callback." \
);
static void
cpBodyRemoveShape(cpBody *body, cpShape *shape)
{
cpShape **prev_ptr = &body->shapeList;
cpShape *node = body->shapeList;
while(node && node != shape){
prev_ptr = &node->next;
node = node->next;
}
cpAssert(node, "Attempted to remove a shape from a body it was never attached to.");
(*prev_ptr) = node->next;
}
cpShape *
cpSpaceAddShape(cpSpace *space, cpShape *shape)
{
@@ -266,9 +252,7 @@ cpSpaceAddShape(cpSpace *space, cpShape *shape)
cpAssertSpaceUnlocked(space);
cpBodyActivate(body);
// Push onto the head of the body's shape list
shape->next = body->shapeList; body->shapeList = shape;
cpBodyAddShape(body, shape);
cpShapeUpdate(shape, body->p, body->rot);
cpSpatialIndexInsert(space->activeShapes, shape, shape->hashid);
@@ -284,6 +268,7 @@ cpSpaceAddStaticShape(cpSpace *space, cpShape *shape)
cpAssertSpaceUnlocked(space);
cpBody *body = shape->body;
cpBodyAddShape(body, shape);
cpShapeUpdate(shape, body->p, body->rot);
cpSpaceActivateShapesTouchingShape(space, shape);
cpSpatialIndexInsert(space->staticShapes, shape, shape->hashid);
@@ -392,20 +377,19 @@ cpSpaceRemoveShape(cpSpace *space, cpShape *shape)
cpBody *body = shape->body;
if(cpBodyIsStatic(body)){
cpSpaceRemoveStaticShape(space, shape);
return;
} else {
cpBodyActivate(body);
cpAssert(cpSpaceContainsShape(space, shape),
"Cannot remove a shape that was not added to the space. (Removed twice maybe?)");
cpAssertSpaceUnlocked(space);
cpBodyRemoveShape(body, shape);
arbiterRemovalContext context = {space, shape};
cpHashSetFilter(space->cachedArbiters, (cpHashSetFilterFunc)arbiterSetFilterRemovedShape, &context);
cpSpatialIndexRemove(space->activeShapes, shape, shape->hashid);
}
cpBodyActivate(body);
cpAssert(cpSpaceContainsShape(space, shape),
"Cannot remove a shape that was not added to the space. (Removed twice maybe?)");
cpAssertSpaceUnlocked(space);
cpBodyRemoveShape(body, shape);
arbiterRemovalContext context = {space, shape};
cpHashSetFilter(space->cachedArbiters, (cpHashSetFilterFunc)arbiterSetFilterRemovedShape, &context);
cpSpatialIndexRemove(space->activeShapes, shape, shape->hashid);
}
void
@@ -415,6 +399,8 @@ cpSpaceRemoveStaticShape(cpSpace *space, cpShape *shape)
"Cannot remove a static or sleeping shape that was not added to the space. (Removed twice maybe?)");
cpAssertSpaceUnlocked(space);
cpBodyRemoveShape(shape->body, shape);
arbiterRemovalContext context = {space, shape};
cpHashSetFilter(space->cachedArbiters, (cpHashSetFilterFunc)arbiterSetFilterRemovedShape, &context);
cpSpatialIndexRemove(space->staticShapes, shape, shape->hashid);

View File

@@ -91,7 +91,7 @@ cpSpaceDeactivateBody(cpSpace *space, cpBody *body)
// Save contact values to a new block of memory so they won't time out
size_t bytes = arb->numContacts*sizeof(cpContact);
cpContact *contacts = (cpContact *)cpmalloc(bytes);
cpContact *contacts = (cpContact *)cpcalloc(1, bytes);
memcpy(contacts, arb->contacts, bytes);
arb->contacts = contacts;
}

View File

@@ -82,7 +82,7 @@ handleSetTrans(void *obj, cpSpaceHash *hash)
int count = CP_BUFFER_BYTES/sizeof(cpHandle);
cpAssert(count, "Buffer size is too small.");
cpHandle *buffer = (cpHandle *)cpmalloc(CP_BUFFER_BYTES);
cpHandle *buffer = (cpHandle *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(hash->allocatedBuffers, buffer);
for(int i=0; i<count; i++) cpArrayPush(hash->pooledHandles, buffer + i);
@@ -144,7 +144,7 @@ getEmptyBin(cpSpaceHash *hash)
int count = CP_BUFFER_BYTES/sizeof(cpSpaceHashBin);
cpAssert(count, "Buffer size is too small.");
cpSpaceHashBin *buffer = (cpSpaceHashBin *)cpmalloc(CP_BUFFER_BYTES);
cpSpaceHashBin *buffer = (cpSpaceHashBin *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(hash->allocatedBuffers, buffer);
// push all but the first one, return the first instead
@@ -210,15 +210,14 @@ cpSpaceHashNew(cpFloat celldim, int cells, cpSpatialIndexBBFunc bbfunc, cpSpatia
static void
cpSpaceHashDestroy(cpSpaceHash *hash)
{
clearTable(hash);
if(hash->table) clearTable(hash);
cpfree(hash->table);
cpHashSetFree(hash->handleSet);
cpArrayFreeEach(hash->allocatedBuffers, cpfree);
cpArrayFree(hash->allocatedBuffers);
cpArrayFree(hash->pooledHandles);
cpfree(hash->table);
}
#pragma mark Helper Functions

View File

@@ -41,7 +41,7 @@ postStepFuncSetEql(cpPostStepCallback *a, cpPostStepCallback *b){
static void *
postStepFuncSetTrans(cpPostStepCallback *callback, void *ignored)
{
cpPostStepCallback *value = (cpPostStepCallback *)cpmalloc(sizeof(cpPostStepCallback));
cpPostStepCallback *value = (cpPostStepCallback *)cpcalloc(1, sizeof(cpPostStepCallback));
(*value) = (*callback);
return value;
@@ -137,7 +137,7 @@ typedef struct cpContactBuffer {
static cpContactBufferHeader *
cpSpaceAllocContactBuffer(cpSpace *space)
{
cpContactBuffer *buffer = (cpContactBuffer *)cpmalloc(sizeof(cpContactBuffer));
cpContactBuffer *buffer = (cpContactBuffer *)cpcalloc(1, sizeof(cpContactBuffer));
cpArrayPush(space->allocatedBuffers, buffer);
return (cpContactBufferHeader *)buffer;
}
@@ -208,7 +208,7 @@ cpSpaceArbiterSetTrans(cpShape **shapes, cpSpace *space)
int count = CP_BUFFER_BYTES/sizeof(cpArbiter);
cpAssert(count, "Buffer size too small.");
cpArbiter *buffer = (cpArbiter *)cpmalloc(CP_BUFFER_BYTES);
cpArbiter *buffer = (cpArbiter *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(space->allocatedBuffers, buffer);
for(int i=0; i<count; i++) cpArrayPush(space->pooledArbiters, buffer + i);
@@ -217,6 +217,13 @@ cpSpaceArbiterSetTrans(cpShape **shapes, cpSpace *space)
return cpArbiterInit((cpArbiter *)cpArrayPop(space->pooledArbiters), shapes[0], shapes[1]);
}
static inline cpCollisionHandler *
lookupCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b)
{
cpCollisionType types[] = {a, b};
return (cpCollisionHandler *)cpHashSetFind(space->collisionHandlers, CP_HASH_PAIR(a, b), types);
}
static inline cpBool
queryReject(cpShape *a, cpShape *b)
{
@@ -239,10 +246,7 @@ collideShapes(cpShape *a, cpShape *b, cpSpace *space)
// Reject any of the simple cases
if(queryReject(a,b)) return;
// Find the collision pair function for the shapes.
cpCollisionType types[] = {a->collision_type, b->collision_type};
cpHashValue collHashID = CP_HASH_PAIR(a->collision_type, b->collision_type);
cpCollisionHandler *handler = (cpCollisionHandler *)cpHashSetFind(space->collisionHandlers, collHashID, types);
cpCollisionHandler *handler = lookupCollisionHandler(space, a->collision_type, b->collision_type);
cpBool sensor = a->sensor || b->sensor;
if(sensor && handler == &cpDefaultCollisionHandler) return;
@@ -314,7 +318,9 @@ cpSpaceArbiterSetFilter(cpArbiter *arb, cpSpace *space)
// Arbiter was used last frame, but not this one
if(ticks >= 1 && arb->state != cpArbiterStateCached){
arb->handler->separate(arb, space, arb->handler->data);
// The handler needs to be looked up again as the handler cached on the arbiter may have been deleted since the last step.
cpCollisionHandler *handler = lookupCollisionHandler(space, arb->a->collision_type, arb->b->collision_type);
handler->separate(arb, space, handler->data);
arb->state = cpArbiterStateCached;
}

View File

@@ -159,7 +159,7 @@ void cpSpatialIndexCollideStatic(cpSpatialIndex *dynamicIndex, cpSpatialIndex *s
static inline void
cpSpatialIndexDestroy(cpSpatialIndex *index)
{
index->klass->destroy(index);
if(index->klass) index->klass->destroy(index);
}
/// Get the number of objects in the spatial index.

View File

@@ -4,7 +4,8 @@ namespace EE { namespace System {
cLog::cLog() :
mSave( false ),
mConsoleOutput( false )
mConsoleOutput( false ),
mLiveWrite( false )
{
Write("...::: Entropia Engine++ Loaded :::...");
Write( "Loaded on " + GetDateTimeStr() );
@@ -14,26 +15,22 @@ cLog::~cLog() {
Write( "\nUnloaded on " + GetDateTimeStr(), false );
Write( "...::: Entropia Engine++ Unloaded :::..." );
if ( !mFilePath.empty() )
mFilePath = GetProcessPath();
if ( mSave ) {
std::string str = mFilePath;
str += "log.log";
std::ofstream fs( str.c_str(), std::ios::app );
fs << mData << std::endl;
fs.close();
if ( mSave && !mLiveWrite ) {
openfs();
mFS << mData << std::endl;
}
if ( mFS.is_open() ) {
mFS.close();
}
}
void cLog::Save(const std::string& filepath) {
void cLog::Save( const std::string& filepath ) {
mFilePath = filepath;
mSave = true;
}
void cLog::Write(const std::string& Text, const bool& newLine) {
void cLog::Write( const std::string& Text, const bool& newLine ) {
mData += Text;
if ( newLine ) {
@@ -46,7 +43,22 @@ void cLog::Write(const std::string& Text, const bool& newLine) {
} else {
std::cout << Text;
}
}
if ( mLiveWrite ) {
openfs();
mFS << Text << std::endl;
}
}
void cLog::openfs() {
if ( !mFilePath.empty() )
mFilePath = GetProcessPath();
if ( !mFS.is_open() ) {
std::string str = mFilePath + "log.log";
mFS.open( str.c_str(), std::ios::app );
}
}
void cLog::Writef( const char* format, ... ) {
@@ -73,7 +85,12 @@ void cLog::Writef( const char* format, ... ) {
if ( mConsoleOutput ) {
std::cout << tstr << std::endl;
}
}
if ( mLiveWrite ) {
openfs();
mFS << tstr << std::endl;
}
return;
}
@@ -97,6 +114,14 @@ const bool& cLog::ConsoleOutput() const {
void cLog::ConsoleOutput( const bool& output ) {
mConsoleOutput = output;
}
const bool& cLog::LiveWrite() const {
return mLiveWrite;
}
void cLog::LiveWrite( const bool& lw ) {
mLiveWrite = lw;
}
}}

View File

@@ -19,7 +19,11 @@ class EE_API cLog : public tSingleton<cLog> {
const bool& ConsoleOutput() const;
void ConsoleOutput( const bool& output );
void ConsoleOutput( const bool& output );
const bool& LiveWrite() const;
void LiveWrite( const bool& lw );
~cLog();
protected:
@@ -27,7 +31,11 @@ class EE_API cLog : public tSingleton<cLog> {
private:
std::string mData, mFilePath;
bool mSave;
bool mConsoleOutput;
bool mConsoleOutput;
bool mLiveWrite;
std::ofstream mFS;
void openfs();
};
}}

View File

@@ -4,7 +4,8 @@ void cEETest::Init() {
EE = cEngine::instance();
#ifdef EE_DEBUG
cLog::instance()->ConsoleOutput( true );
cLog::instance()->ConsoleOutput( true );
cLog::instance()->LiveWrite( true );
#endif
run = false;
@@ -62,7 +63,9 @@ void cEETest::Init() {
run = ( mWindow->Created() && PAK.IsOpen() );
if ( run ) {
if ( run ) {
cLog::instance()->Write( "Running eepp" );
#ifdef EE_DEBUG
std::cout << "Size of Callback0: " << sizeof( cb::Callback0<void> ) << std::endl;
std::cout << "Size of cWaypoints: " << sizeof( cWaypoints ) << std::endl;
@@ -136,24 +139,31 @@ void cEETest::Init() {
if ( NULL != mFBO )
mFBO->ClearColor( eeColorAf( 0, 0, 0, 0.5f ) );
eePolygon2f Poly = CreateRoundedPolygon( 0.f, 0.f, 256.f, 50.f );
mVBO = cVertexBuffer::Create( VERTEX_FLAG_GET( VERTEX_FLAG_POSITION ) | VERTEX_FLAG_GET( VERTEX_FLAG_COLOR ), DM_POLYGON );
mVBO = cVertexBuffer::Create( VERTEX_FLAG_GET( VERTEX_FLAG_POSITION ) | VERTEX_FLAG_GET( VERTEX_FLAG_COLOR ), DM_POLYGON );
if ( NULL != mVBO ) {
for ( Uint32 i = 0; i < Poly.Size(); i++ ) {
mVBO->AddVertex( Poly[i] );
mVBO->AddColor( eeColorA( 100 + i, 255 - i, 150 + i, 200 ) );
}
for ( Uint32 i = 0; i < Poly.Size(); i++ ) {
mVBO->AddVertex( Poly[i] );
mVBO->AddColor( eeColorA( 100 + i, 255 - i, 150 + i, 200 ) );
}
mVBO->Compile();
mVBO->Compile();
}
PhysicsCreate();
Launch();
} else {
std::cout << "Failed to start EE++" << std::endl;
cEngine::DestroySingleton();
} else {
std::string err;
std::cout << err.c_str() << std::endl;
cLog::instance()->Write( err );
cEngine::DestroySingleton();
exit(0);
}
}
@@ -207,9 +217,9 @@ void cEETest::OnFontLoaded( cResourceLoader * ObjLoaded ) {
Map.Font( FF );
Con.Create( FF, true );
Con.IgnoreCharOnPrompt( 186 ); // 'º'
Con.IgnoreCharOnPrompt( 186 ); // '<EFBFBD>'
mBuda = String::FromUtf8( "El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde." );
mBuda = String::FromUtf8( "El mono ve el pez en el agua y sufre. Piensa que su mundo es el <EFBFBD>nico que existe, el mejor, el real. Sufre porque es bueno y tiene compasi<EFBFBD>n, lo ve y piensa: \"Pobre se est<EFBFBD> ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salv<EFBFBD>. Pero el pez se retuerce de dolor y muere. Por eso te mostr<EFBFBD> el sue<EFBFBD>o, es imposible meter el mar en tu cabeza, que es un balde." );
CreateUI();
@@ -239,9 +249,12 @@ void cEETest::CreateUI() {
Log->Writef( "Texture Atlas Loading Time: %f", TE.ElapsedSinceStart() );
cTextureGroupLoader tgl( MyPath + "data/aquatg/aqua.etg" );
TF->GetByName( "data/aquatg/aqua.png" )->TextureFilter( TEX_FILTER_NEAREST );
cUIThemeManager::instance()->Add( cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" ) );
tgl.GetTexture()->TextureFilter( TEX_FILTER_NEAREST );
cUITheme * Aqua = cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" );
Aqua->FontSelectedColor( eeColorA( 255, 255, 255, 255 ) );
cUIThemeManager::instance()->Add( Aqua );
cUIThemeManager::instance()->DefaultEffectsEnabled( true );
cUIThemeManager::instance()->DefaultFont( TTF );
cUIThemeManager::instance()->DefaultTheme( "aqua" );
@@ -399,7 +412,6 @@ void cEETest::CreateUI() {
LBParams.PosSet( 325, 8 );
LBParams.Size = eeSize( 200, 240-16 );
LBParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING; // | UI_MULTI_SELECT
LBParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 );
mListBox = eeNew( cUIListBox, ( LBParams ) );
mListBox->Visible( true );
mListBox->Enabled( true );
@@ -452,7 +464,6 @@ void cEETest::CreateUI() {
MenuParams.MinWidth = 100;
MenuParams.MinSpaceForIcons = 16;
MenuParams.PosSet( 0, 0 );
MenuParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 );
MenuParams.MinRightMargin = 8;
Menu = eeNew( cUIPopUpMenu, ( MenuParams ) );
Menu->Add( "New", cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) );
@@ -559,7 +570,7 @@ void cEETest::CreateUI() {
cUICommonDialog::CreateParams CDParams;
CDParams.Flags = UI_HALIGN_CENTER;
CDParams.WinFlags |= cUIWindow::UI_WIN_MAXIMIZE_BUTTON; // | cUIWindow::UI_WIN_MODAL
CDParams.Size = eeSize( 420, 267 );
CDParams.ButtonsPositionFixer.x = -2;
cUICommonDialog * CDialog = eeNew( cUICommonDialog, ( CDParams ) );
CDialog->AddFilePattern( "*.hpp;*.cpp", true );
CDialog->Center();
@@ -573,8 +584,6 @@ void cEETest::CreateWinMenu() {
WinMenuParams.Parent( mUIWindow->Container() );
WinMenuParams.ButtonMargin = 12;
WinMenuParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 );
WinMenuParams.Flags |= cUIWindow::UI_WIN_NO_BORDER;
cUIWinMenu * WinMenu = eeNew( cUIWinMenu, ( WinMenuParams ) );
@@ -585,7 +594,6 @@ void cEETest::CreateWinMenu() {
MenuParams.MinWidth = 100;
MenuParams.MinSpaceForIcons = 16;
MenuParams.PosSet( 0, 0 );
MenuParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 );
MenuParams.MinRightMargin = 8;
cUIPopUpMenu * PopMenu = eeNew( cUIPopUpMenu, ( MenuParams ) );
@@ -613,6 +621,7 @@ void cEETest::CreateDecoratedWindow() {
WinParams.PosSet( 200, 50 );
WinParams.Size = eeSize( 530, 400 );
WinParams.MinWindowSize = eeSize( 100, 200 );
WinParams.ButtonsPositionFixer.x = -2;
mUIWindow = eeNew( cUIWindow, ( WinParams ) );
mUIWindow->AddEventListener( cUIEvent::EventOnWindowCloseClick, cb::Make1( this, &cEETest::CloseClick ) );
@@ -1150,10 +1159,12 @@ void cEETest::Screen4() {
mBlindy.Position( 128-16, 128-16 );
mBlindy.Draw();
mVBO->Bind();
mVBO->Draw();
mVBO->Unbind();
if ( NULL != mVBO ) {
mVBO->Bind();
mVBO->Draw();
mVBO->Unbind();
}
mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER );

View File

@@ -4,6 +4,14 @@
#include "../graphics/ctexturefactory.hpp"
#include "../graphics/cshapegroupmanager.hpp"
#include "cuicheckbox.hpp"
#include "cuicombobox.hpp"
#include "cuidropdownlist.hpp"
#include "cuilistbox.hpp"
#include "cuipopupmenu.hpp"
#include "cuiprogressbar.hpp"
#include "cuipushbutton.hpp"
namespace EE { namespace UI {
static std::vector<std::string> UI_THEME_ELEMENTS;
@@ -261,6 +269,7 @@ cUITheme::cUITheme( const std::string& Name, const std::string& Abbr, cFont * De
mFontOverColor( 0, 0, 0, 255 ),
mFontSelectedColor( 0, 0, 0, 255 )
{
PostInit();
}
cUITheme::~cUITheme() {
@@ -330,4 +339,92 @@ void cUITheme::FontSelectedColor( const eeColorA& Color ) {
mFontSelectedColor = Color;
}
void cUITheme::PostInit() {
}
cUICheckBox * cUITheme::CreateCheckBox( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags ) {
cUITextBox::CreateParams CheckBoxParams;
CheckBoxParams.Parent( Parent );
CheckBoxParams.PosSet( Pos );
CheckBoxParams.SizeSet( Size );
CheckBoxParams.Flags = Flags;
return eeNew( cUICheckBox, ( CheckBoxParams ) );
}
cUIComboBox * cUITheme::CreateComboBox( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags, Uint32 MinNumVisibleItems, bool PopUpToMainControl, cUIListBox * ListBox ) {
cUIComboBox::CreateParams ComboParams;
ComboParams.Parent( Parent );
ComboParams.PosSet( Pos );
ComboParams.SizeSet( Size );
ComboParams.Flags = Flags;
ComboParams.MinNumVisibleItems = MinNumVisibleItems;
ComboParams.PopUpToMainControl = PopUpToMainControl;
ComboParams.ListBox = ListBox;
return eeNew( cUIComboBox, ( ComboParams ) );
}
cUIDropDownList * cUITheme::CreateDropDownList( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags, Uint32 MinNumVisibleItems, bool PopUpToMainControl, cUIListBox * ListBox ) {
cUIDropDownList::CreateParams DDLParams;
DDLParams.Parent( Parent );
DDLParams.PosSet( Pos );
DDLParams.SizeSet( Size );
DDLParams.Flags = Flags;
DDLParams.MinNumVisibleItems = MinNumVisibleItems;
DDLParams.PopUpToMainControl = PopUpToMainControl;
DDLParams.ListBox = ListBox;
return eeNew( cUIDropDownList, ( DDLParams ) );
}
cUIListBox * cUITheme::CreateListBox( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags, bool SmoothScroll, Uint32 RowHeight, UI_SCROLLBAR_MODE VScrollMode, UI_SCROLLBAR_MODE HScrollMode, eeRecti PaddingContainer ) {
cUIListBox::CreateParams LBParams;
LBParams.Parent( Parent );
LBParams.PosSet( Pos );
LBParams.SizeSet( Size );
LBParams.Flags = Flags;
LBParams.SmoothScroll = SmoothScroll;
LBParams.RowHeight = RowHeight;
LBParams.VScrollMode = VScrollMode;
LBParams.HScrollMode = HScrollMode;
LBParams.PaddingContainer = PaddingContainer;
return eeNew( cUIListBox, ( LBParams ) );
}
cUIPopUpMenu * cUITheme::CreatePopUpMenu( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags ) {
cUIPopUpMenu::CreateParams MenuParams;
MenuParams.Parent( Parent );
MenuParams.PosSet( Pos );
MenuParams.SizeSet( Size );
MenuParams.Flags = Flags;
/** Aqua Theme Stuff *//**
MenuParams.MinWidth = 100;
MenuParams.MinSpaceForIcons = 16;
MenuParams.MinRightMargin = 8;
*/
return eeNew( cUIPopUpMenu, ( MenuParams ) );
}
cUIProgressBar * cUITheme::CreateProgressBar( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags, bool DisplayPercent ) {
cUIProgressBar::CreateParams PBParams;
PBParams.Parent( Parent );
PBParams.PosSet( Pos );
PBParams.SizeSet( Size );
PBParams.Flags = Flags;
PBParams.DisplayPercent = DisplayPercent;
return eeNew( cUIProgressBar, ( PBParams ) );
}
cUIPushButton * cUITheme::CreatePushButton( cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags, cShape * Icon ) {
cUIPushButton::CreateParams ButtonParams;
ButtonParams.Parent( Parent );
ButtonParams.PosSet( Pos );
ButtonParams.SizeSet( Size );
ButtonParams.Flags = Flags;
if ( NULL != Icon )
ButtonParams.SetIcon( Icon );
return eeNew( cUIPushButton, ( ButtonParams ) );
}
}}

View File

@@ -2,12 +2,22 @@
#define EE_UICUITHEME_HPP
#include "base.hpp"
#include "uihelper.hpp"
#include "../graphics/cshapegroup.hpp"
#include "../graphics/cfont.hpp"
#include "cuiskin.hpp"
namespace EE { namespace UI {
class cUIControl;
class cUICheckBox;
class cUIComboBox;
class cUIDropDownList;
class cUIListBox;
class cUIPopUpMenu;
class cUIProgressBar;
class cUIPushButton;
class EE_API cUITheme : public tResourceManager<cUISkin> {
public:
static cUITheme * LoadFromPath( const std::string& Path, const std::string& Name, const std::string& NameAbbr, const std::string ImgExt = "png" );
@@ -49,6 +59,20 @@ class EE_API cUITheme : public tResourceManager<cUISkin> {
void FontOverColor( const eeColorA& Color );
void FontSelectedColor( const eeColorA& Color );
virtual cUICheckBox * CreateCheckBox( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT );
virtual cUIComboBox * CreateComboBox( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_VALIGN_CENTER | UI_HALIGN_LEFT, Uint32 MinNumVisibleItems = 6, bool PopUpToMainControl = false, cUIListBox * ListBox = NULL );
virtual cUIDropDownList * CreateDropDownList( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_VALIGN_CENTER | UI_HALIGN_LEFT, Uint32 MinNumVisibleItems = 6, bool PopUpToMainControl = false, cUIListBox * ListBox = NULL );
virtual cUIListBox * CreateListBox( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING, bool SmoothScroll = true, Uint32 RowHeight = 0, UI_SCROLLBAR_MODE VScrollMode = UI_SCROLLBAR_AUTO, UI_SCROLLBAR_MODE HScrollMode = UI_SCROLLBAR_AUTO, eeRecti PaddingContainer = eeRecti() );
virtual cUIPopUpMenu * CreatePopUpMenu( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_AUTO_SIZE | UI_AUTO_PADDING );
virtual cUIProgressBar * CreateProgressBar( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_HALIGN_LEFT | UI_VALIGN_CENTER, bool DisplayPercent = true );
virtual cUIPushButton * CreatePushButton( cUIControl * Parent, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER, cShape * Icon = NULL );
protected:
std::string mName;
Uint32 mNameHash;
@@ -62,6 +86,8 @@ class EE_API cUITheme : public tResourceManager<cUISkin> {
static bool SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, std::string Element, Uint32& IsComplex, const std::string ImgExt );
static bool SearchFilesInGroup( cShapeGroup * SG, std::string Element, Uint32& IsComplex );
virtual void PostInit();
};
}}

View File

@@ -31,7 +31,7 @@ class EE_API cUIWinMenu : public cUIComplexControl {
FontColor = Theme->FontColor();
FontShadowColor = Theme->FontShadowColor();
FontOverColor = Theme->FontOverColor();
FontSelectedColor = FontOverColor;
FontSelectedColor = Theme->FontSelectedColor();
}
if ( NULL == Font )

View File

@@ -131,9 +131,7 @@ bool cWindowSDL::Create( WindowSettings Settings, ContextSettings Context ) {
}
std::string cWindowSDL::GetVersion() {
SDL_version ver;
SDL_GetVersion( &ver );
SDL_version ver = mWMinfo.version;
return StrFormated( "SDL %d.%d.%d", ver.major, ver.minor, ver.patch );
}

View File

@@ -150,71 +150,73 @@ Uint32 cWindowAl::CreateFlags( const WindowSettings& Settings, const ContextSett
}
bool cWindowAl::Create( WindowSettings Settings, ContextSettings Context ) {
DestroyDisplay();
try {
DestroyDisplay();
mWindow.WindowConfig = Settings;
mWindow.ContextConfig = Context;
mWindow.WindowConfig = Settings;
mWindow.ContextConfig = Context;
al_set_new_display_flags( CreateFlags( Settings, Context ) );
al_set_new_display_option( ALLEGRO_STENCIL_SIZE , Context.StencilBufferSize , ALLEGRO_SUGGEST );
al_set_new_display_option( ALLEGRO_DEPTH_SIZE , Context.DepthBufferSize , ALLEGRO_SUGGEST );
al_set_new_display_flags( CreateFlags( Settings, Context ) );
al_set_new_display_option( ALLEGRO_STENCIL_SIZE , Context.StencilBufferSize , ALLEGRO_SUGGEST );
al_set_new_display_option( ALLEGRO_DEPTH_SIZE , Context.DepthBufferSize , ALLEGRO_SUGGEST );
if ( Context.VSync )
al_set_new_display_option( ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST );
if ( Context.VSync )
al_set_new_display_option( ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST );
ALLEGRO_MONITOR_INFO minfo;
ALLEGRO_MONITOR_INFO minfo;
if ( al_get_monitor_info( 0, &minfo ) ) {
mWindow.DesktopResolution = eeSize( minfo.x2, minfo.y2 );
if ( al_get_monitor_info( 0, &minfo ) ) {
mWindow.DesktopResolution = eeSize( minfo.x2, minfo.y2 );
if ( mWindow.WindowConfig.Style & WindowStyle::UseDesktopResolution ) {
mWindow.WindowConfig.Width = mWindow.DesktopResolution.Width();
mWindow.WindowConfig.Height = mWindow.DesktopResolution.Height();
if ( mWindow.WindowConfig.Style & WindowStyle::UseDesktopResolution ) {
mWindow.WindowConfig.Width = mWindow.DesktopResolution.Width();
mWindow.WindowConfig.Height = mWindow.DesktopResolution.Height();
}
} else {
mWindow.DesktopResolution = eeSize( Settings.Width, Settings.Height );
}
} else {
mWindow.DesktopResolution = eeSize( Settings.Width, Settings.Height );
mDisplay = al_create_display( Settings.Width, Settings.Height );
if ( NULL != mDisplay ) {
al_inhibit_screensaver( true );
Caption( mWindow.WindowConfig.Caption );
if ( NULL == cGL::ExistsSingleton() ) {
cGL::CreateSingleton( mWindow.ContextConfig.Version );
}
cGL::instance()->Init();
CreatePlatform();
GetMainContext();
CreateView();
Setup2D();
mWindow.Created = true;
if ( "" != mWindow.WindowConfig.Icon ) {
Icon( mWindow.WindowConfig.Icon );
}
LogSuccessfulInit( "Allegro 5" );
/// Init the clipboard after the window creation
reinterpret_cast<cClipboardAl*> ( mClipboard )->Init();
/// Init the input after the window creation
reinterpret_cast<cInputAl*> ( mInput )->Init();
return true;
}
} catch (...) {
LogFailureInit( "cWindowAl", "Allegro 5" );
}
mDisplay = al_create_display( Settings.Width, Settings.Height );
if ( NULL != mDisplay ) {
al_inhibit_screensaver( true );
Caption( mWindow.WindowConfig.Caption );
if ( NULL == cGL::ExistsSingleton() ) {
cGL::CreateSingleton( mWindow.ContextConfig.Version );
}
cGL::instance()->Init();
CreatePlatform();
GetMainContext();
CreateView();
Setup2D();
mWindow.Created = true;
if ( "" != mWindow.WindowConfig.Icon ) {
Icon( mWindow.WindowConfig.Icon );
}
LogSuccessfulInit( "Allegro 5" );
/// Init the clipboard after the window creation
reinterpret_cast<cClipboardAl*> ( mClipboard )->Init();
/// Init the input after the window creation
reinterpret_cast<cInputAl*> ( mInput )->Init();
return true;
}
LogFailureInit( "cWindowAl", "Allegro 5" );
return false;
}

View File

@@ -55,7 +55,7 @@ bool cWindow::Resizeable() const {
void cWindow::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height, const bool& UpdateProjectionMatrix ) {
GLi->Viewport( x, GetHeight() - Height - y, Width, Height );
if ( UpdateProjectionMatrix ) {
GLi->MatrixMode( GL_PROJECTION );
GLi->LoadIdentity();
@@ -101,7 +101,7 @@ void cWindow::Setup2D( const bool& KeepView ) {
if ( !KeepView )
SetView( mDefaultView );
cTextureFactory::instance()->SetPreBlendFunc( ALPHA_NORMAL, true );
if ( GLv_3 != GLi->Version() ) {