From 63ceea60d8d37300fed71971ab83976816f3b68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Sat, 18 Feb 2017 16:53:08 -0300 Subject: [PATCH] Demo fixes. --HG-- branch : dev --- src/examples/empty_window/empty_window.cpp | 4 +- .../external_shader/external_shader.cpp | 4 +- src/examples/fonts/fonts.cpp | 18 ++- src/examples/physics/physics.cpp | 108 +++++++++--------- src/examples/sound/sound.cpp | 8 +- src/examples/sprites/sprites.cpp | 53 ++++----- src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp | 4 +- src/test/eetest.cpp | 4 +- 8 files changed, 97 insertions(+), 106 deletions(-) diff --git a/src/examples/empty_window/empty_window.cpp b/src/examples/empty_window/empty_window.cpp index 973f6a3d6..7f23adb2d 100644 --- a/src/examples/empty_window/empty_window.cpp +++ b/src/examples/empty_window/empty_window.cpp @@ -10,7 +10,7 @@ EE::Window::Window * win = NULL; float circ = 0, circ2 = 0; int op = 1; -void MainLoop() +void mainLoop() { // Clear the screen buffer win->clear(); @@ -105,7 +105,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) // { // MainLoop(); // } - win->runMainLoop( &MainLoop ); + win->runMainLoop( &mainLoop ); } // Destroy the engine instance. Destroys all the windows and engine singletons. diff --git a/src/examples/external_shader/external_shader.cpp b/src/examples/external_shader/external_shader.cpp index 13dbc2096..d49532f71 100644 --- a/src/examples/external_shader/external_shader.cpp +++ b/src/examples/external_shader/external_shader.cpp @@ -91,7 +91,7 @@ void videoResize( EE::Window::Window * w ) { } using namespace Demo_ExternalShader; -void MainLoop() +void mainLoop() { win->clear(); @@ -272,7 +272,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) } #endif - win->runMainLoop( &MainLoop ); + win->runMainLoop( &mainLoop ); eeSAFE_DELETE_ARRAY( vertices ); eeSAFE_DELETE_ARRAY( velocities ); diff --git a/src/examples/fonts/fonts.cpp b/src/examples/fonts/fonts.cpp index a2b7f568e..d10d970b2 100644 --- a/src/examples/fonts/fonts.cpp +++ b/src/examples/fonts/fonts.cpp @@ -6,9 +6,9 @@ TTFFont * TTFO = NULL; TTFFont * TTF2 = NULL; TextureFont * TexF = NULL; TextureFont * TexF2 = NULL; -TextCache * TxtCache = NULL; +TextCache TxtCache; -void MainLoop() +void mainLoop() { // Clear the screen buffer win->clear(); @@ -36,7 +36,7 @@ void MainLoop() TexF2->draw( win->getWidth() * 0.5f - TexF2->getTextWidth() * 0.5f, ( YPos += TexF->getTextHeight() + 24 ) ); // Draw the cached text - TxtCache->draw( 48, ( YPos += TexF2->getTextHeight() + 24 ) ); + TxtCache.draw( 48, ( YPos += TexF2->getTextHeight() + 24 ) ); // Text rotated and scaled TTF->draw( win->getWidth() * 0.5f - TTF->getTextWidth() * 0.5f, 512, FONT_DRAW_LEFT, Vector2f( 0.75f, 0.75f ), 12.5f ); @@ -109,26 +109,24 @@ EE_MAIN_FUNC int main (int argc, char * argv []) // Create a new text cache to draw on screen // The cached text will - TxtCache = eeNew( TextCache, ( TTF2, Txt, ColorA(0,0,0,255) ) ); + TxtCache.create( TTF2, Txt, ColorA(0,0,0,255) ); // Set the text cache to be centered - TxtCache->setFlags( FONT_DRAW_CENTER ); + TxtCache.setFlags( FONT_DRAW_CENTER ); // Set the font color to a substring of the text // To be able to set the color of the font, create the font as white // Create a gradient - size_t size = TxtCache->getText().size(); + size_t size = TxtCache.getText().size(); for ( size_t i = 0; i < size; i++ ) { - TxtCache->setColor( ColorA(255*i/size,0,0,255), i, i+1 ); + TxtCache.setColor( ColorA(255*i/size,0,0,255), i, i+1 ); } // Application loop - win->runMainLoop( &MainLoop ); + win->runMainLoop( &mainLoop ); } - eeSAFE_DELETE( TxtCache ); - // Destroy the engine instance. Destroys all the windows and engine singletons. // Fonts are autoreleased by the engine Engine::destroySingleton(); diff --git a/src/examples/physics/physics.cpp b/src/examples/physics/physics.cpp index ce40b6d28..3aceb32b5 100644 --- a/src/examples/physics/physics.cpp +++ b/src/examples/physics/physics.cpp @@ -25,7 +25,7 @@ Constraint * mMouseJoint; #define GRABABLE_MASK_BIT (1<<31) #define NOT_GRABABLE_MASK (~GRABABLE_MASK_BIT) -void CreateJointAndBody() { +void createJointAndBody() { mMouseJoint = NULL; mMouseBody = eeNew( Body, ( INFINITY, INFINITY ) ); } @@ -33,7 +33,7 @@ void CreateJointAndBody() { EE::Window::Window * mWindow; Input * KM; -void DefaultDrawOptions() { +void defaultDrawOptions() { PhysicsManager::DrawSpaceOptions * DSO = PhysicsManager::instance()->getDrawOptions(); DSO->DrawBBs = false; DSO->DrawShapes = true; @@ -43,7 +43,7 @@ void DefaultDrawOptions() { DSO->LineThickness = 1; } -void DestroyDemo() { +void destroyDemo() { eeSAFE_DELETE( mMouseBody ); eeSAFE_DELETE( mSpace ); } @@ -108,10 +108,10 @@ Shape * make_ball( cpFloat x, cpFloat y ) { static int bodyCount = 0; -void Demo1Create() { - DefaultDrawOptions(); +void demo1Create() { + defaultDrawOptions(); - CreateJointAndBody(); + createJointAndBody(); mWindow->setCaption( "eepp - Physics - Logo Smash" ); @@ -156,17 +156,17 @@ void Demo1Create() { bodyCount++; } -void Demo1Update(){ +void demo1Update(){ } -void Demo1Destroy() { - DestroyDemo(); +void demo1Destroy() { + destroyDemo(); } -void Demo2Create() { - DefaultDrawOptions(); +void demo2Create() { + defaultDrawOptions(); - CreateJointAndBody(); + createJointAndBody(); mWindow->setCaption( "eepp - Physics - Pyramid Stack" ); @@ -222,11 +222,11 @@ void Demo2Create() { shape->u( 0.9f ); } -void Demo2Update() { +void demo2Update() { } -void Demo2Destroy() { - DestroyDemo(); +void demo2Destroy() { + destroyDemo(); } enum CollisionTypes { @@ -289,10 +289,10 @@ cpBool catcherBarBegin(Arbiter *arb, Space *space, void *unused) { return cpFalse; } -void Demo3Create() { - DefaultDrawOptions(); +void demo3Create() { + defaultDrawOptions(); - CreateJointAndBody(); + createJointAndBody(); mWindow->setCaption( "eepp - Physics - Sensor" ); @@ -335,7 +335,7 @@ void Demo3Create() { mSpace->addCollisionHandler( handler ); } -void Demo3Update() { +void demo3Update() { if( !emitterInstance.blocked && emitterInstance.queue ){ emitterInstance.queue--; @@ -348,8 +348,8 @@ void Demo3Update() { } } -void Demo3Destroy() { - DestroyDemo(); +void demo3Destroy() { + destroyDemo(); } enum { @@ -358,13 +358,13 @@ enum { #define STICK_SENSOR_THICKNESS 2.5f -void PostStepAddJoint(Space *space, void *key, void *data) +void postStepAddJoint(Space *space, void *key, void *data) { Constraint *joint = (Constraint *)key; space->addConstraint( joint ); } -cpBool StickyPreSolve( Arbiter *arb, Space *space, void *data ) +cpBool stickyPreSolve( Arbiter *arb, Space *space, void *data ) { // We want to fudge the collisions a bit to allow shapes to overlap more. // This simulates their squishy sticky surface, and more importantly @@ -405,7 +405,7 @@ cpBool StickyPreSolve( Arbiter *arb, Space *space, void *data ) joint->maxForce( 3e3 ); // Schedule a post-step() callback to add the joint. - space->addPostStepCallback( cb::Make3( &PostStepAddJoint ), joint, NULL ); + space->addPostStepCallback( cb::Make3( &postStepAddJoint ), joint, NULL ); // Store the joint on the arbiter so we can remove it later. arb->userData(joint); @@ -423,14 +423,14 @@ cpBool StickyPreSolve( Arbiter *arb, Space *space, void *data ) // * Track a joint for each contact point. (more complicated since you only get one data pointer). } -void PostStepRemoveJoint(Space *space, void *key, void *data) +void postStepRemoveJoint(Space *space, void *key, void *data) { Constraint *joint = (Constraint *)key; space->removeConstraint( joint ); Constraint::Free( joint ); } -void StickySeparate(Arbiter *arb, Space *space, void *data) +void stickySeparate(Arbiter *arb, Space *space, void *data) { Constraint *joint = (Constraint *)arb->userData(); @@ -441,7 +441,7 @@ void StickySeparate(Arbiter *arb, Space *space, void *data) joint->maxForce( 0.0f ); // Perform the removal in a post-step() callback. - space->addPostStepCallback( cb::Make3( &PostStepRemoveJoint ), joint, NULL ); + space->addPostStepCallback( cb::Make3( &postStepRemoveJoint ), joint, NULL ); // NULL out the reference to the joint. // Not required, but it's a good practice. @@ -449,7 +449,7 @@ void StickySeparate(Arbiter *arb, Space *space, void *data) } } -void Demo4Create() { +void demo4Create() { PhysicsManager::DrawSpaceOptions * DSO = PhysicsManager::instance()->getDrawOptions(); DSO->DrawBBs = false; DSO->DrawShapes = true; @@ -458,7 +458,7 @@ void Demo4Create() { DSO->BodyPointSize = 0; DSO->LineThickness = 0; - CreateJointAndBody(); + createJointAndBody(); mWindow->setCaption( "eepp - Physics - Sticky collisions using the Arbiter data pointer." ); @@ -514,17 +514,17 @@ void Demo4Create() { Space::CollisionHandler c; c.a = COLLIDE_STICK_SENSOR; c.b = COLLIDE_STICK_SENSOR; - c.preSolve = cb::Make3( &StickyPreSolve ); - c.separate = cb::Make3( &StickySeparate ); + c.preSolve = cb::Make3( &stickyPreSolve ); + c.separate = cb::Make3( &stickySeparate ); mSpace->addCollisionHandler( c ); } -void Demo4Update() { +void demo4Update() { } -void Demo4Destroy() { - DestroyDemo(); +void demo4Destroy() { + destroyDemo(); } void ChangeDemo( int num ) { @@ -538,7 +538,7 @@ void ChangeDemo( int num ) { } } -void PhysicsCreate() { +void physicsCreate() { // Initialize the physics engine PhysicsManager::createSingleton(); @@ -547,30 +547,30 @@ void PhysicsCreate() { // Add the demos physicDemo demo; - demo.init = cb::Make0( &Demo1Create ); - demo.update = cb::Make0( &Demo1Update ); - demo.destroy = cb::Make0( &Demo1Destroy ); + demo.init = cb::Make0( &demo1Create ); + demo.update = cb::Make0( &demo1Update ); + demo.destroy = cb::Make0( &demo1Destroy ); mDemo.push_back( demo ); - demo.init = cb::Make0( &Demo2Create ); - demo.update = cb::Make0( &Demo2Update ); - demo.destroy = cb::Make0( &Demo2Destroy ); + demo.init = cb::Make0( &demo2Create ); + demo.update = cb::Make0( &demo2Update ); + demo.destroy = cb::Make0( &demo2Destroy ); mDemo.push_back( demo ); - demo.init = cb::Make0( &Demo3Create ); - demo.update = cb::Make0( &Demo3Update ); - demo.destroy = cb::Make0( &Demo3Destroy ); + demo.init = cb::Make0( &demo3Create ); + demo.update = cb::Make0( &demo3Update ); + demo.destroy = cb::Make0( &demo3Destroy ); mDemo.push_back( demo ); - demo.init = cb::Make0( &Demo4Create ); - demo.update = cb::Make0( &Demo4Update ); - demo.destroy = cb::Make0( &Demo4Destroy ); + demo.init = cb::Make0( &demo4Create ); + demo.update = cb::Make0( &demo4Update ); + demo.destroy = cb::Make0( &demo4Destroy ); mDemo.push_back( demo ); ChangeDemo( 0 ); } -void PhysicsUpdate() { +void physicsUpdate() { // Creates a joint to drag any grabable object on the scene mMousePoint = cVectNew( KM->getMousePosf().x, KM->getMousePosf().y ); cVect newPoint = tovect( cpvlerp( tocpv( mMousePoint_last ), tocpv( mMousePoint ), 0.25 ) ); @@ -601,11 +601,11 @@ void PhysicsUpdate() { mSpace->draw(); } -void PhysicsDestroy() { +void physicsDestroy() { mDemo[ mCurDemo ].destroy(); } -void MainLoop() +void mainLoop() { mWindow->clear(); @@ -615,7 +615,7 @@ void MainLoop() mWindow->close(); } - PhysicsUpdate(); + physicsUpdate(); if ( KM->isKeyUp( KEY_LEFT ) || KM->isKeyUp( KEY_A ) ) { ChangeDemo( mCurDemo - 1 ); @@ -635,11 +635,11 @@ EE_MAIN_FUNC int main (int argc, char * argv []) mWindow->setBackColor( RGB( 255, 255, 255 ) ); - PhysicsCreate(); + physicsCreate(); - mWindow->runMainLoop( &MainLoop ); + mWindow->runMainLoop( &mainLoop ); - PhysicsDestroy(); + physicsDestroy(); } Engine::destroySingleton(); diff --git a/src/examples/sound/sound.cpp b/src/examples/sound/sound.cpp index 9a6b40334..de2cb4b75 100644 --- a/src/examples/sound/sound.cpp +++ b/src/examples/sound/sound.cpp @@ -4,7 +4,7 @@ std::string AppPath = Sys::getProcessPath(); /// Play a sound -void PlaySound() { +void playSound() { // The sound manager class simplyfies the load of a SoundBuffer and the creation of the Sound // It manages the sound playing, if the sound channel is already playing, it will open a new channel to play the sound SoundManager SoundManager; @@ -25,7 +25,7 @@ void PlaySound() { } /// Play a music -void PlayMusic() { +void playMusic() { // Load an ogg music file Music music; @@ -58,10 +58,10 @@ void PlayMusic() { EE_MAIN_FUNC int main (int argc, char * argv []) { // Play a sound - PlaySound(); + playSound(); // Play a music - PlayMusic(); + playMusic(); // Wait until the user presses 'enter' key std::cout << "Press enter to exit..." << std::endl; diff --git a/src/examples/sprites/sprites.cpp b/src/examples/sprites/sprites.cpp index 253168cc8..298af55a6 100644 --- a/src/examples/sprites/sprites.cpp +++ b/src/examples/sprites/sprites.cpp @@ -9,9 +9,9 @@ Interpolation PlanetAngle; // Create a primitive drawer instance to draw the AABB of the Rock Primitives P; -Sprite * Rock = NULL; -Sprite * Planet = NULL; -Sprite * Blindy = NULL; +Sprite Rock; +Sprite Planet; +Sprite Blindy; // Define a user sprite event static const Uint32 USER_SPRITE_EVENT = Sprite::SPRITE_EVENT_USER + 1; @@ -39,7 +39,7 @@ void spriteCallback( Uint32 Event, Sprite * Sprite, void * UserData ) { } } -void MainLoop() +void mainLoop() { // Clear the screen buffer win->clear(); @@ -56,7 +56,7 @@ void MainLoop() // Check if the D key was pressed if ( win->getInput()->isKeyUp( KEY_D ) ) { // Reverse the Rock animation - Rock->setReverseAnimation( !Rock->getReverseAnimation() ); + Rock.setReverseAnimation( !Rock.getReverseAnimation() ); } // Update the angle interpolation @@ -64,25 +64,25 @@ void MainLoop() RockAngle.update( win->getElapsed() ); // Set the Planet and Rock angle from the interpolation - Planet->setRotation( PlanetAngle.getPos() ); - Rock->setRotation( RockAngle.getPos() ); + Planet.setRotation( PlanetAngle.getPos() ); + Rock.setRotation( RockAngle.getPos() ); // Draw the static planet sprite - Planet->draw(); + Planet.draw(); // Draw the animated Rock sprite - Rock->draw(); + Rock.draw(); // Draw the blindy animation - Blindy->draw(); + Blindy.draw(); // Draw the Rock Axis-Aligned Bounding Box P.setColor( ColorA( 255, 255, 255, 255 ) ); - P.drawRectangle( Rock->getAABB() ); + P.drawRectangle( Rock.getAABB() ); // Draw the Rock Quad P.setColor( ColorA( 255, 0, 0, 255 ) ); - P.drawQuad( Rock->getQuad() ); + P.drawQuad( Rock.getQuad() ); // Draw frame win->display(); @@ -106,35 +106,32 @@ EE_MAIN_FUNC int main (int argc, char * argv []) TextureAtlasLoader Blindies( AppPath + "assets/atlases/bnb.eta" ); // Create the animated rock spriteR - Rock = eeNew( Sprite, () ); - // Load the rock frames from the texture, adding the frames manually for ( Int32 my = 0; my < 4; my++ ) { for( Int32 mx = 0; mx < 8; mx++ ) { // DestSize as 0,0 will use the SubTexture size - Rock->addFrame( RockId, Sizef( 0, 0 ), Vector2i( 0, 0 ), Recti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); + Rock.addFrame( RockId, Sizef( 0, 0 ), Vector2i( 0, 0 ), Recti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); } } // Create a static sprite - Planet = eeNew( Sprite, ( PlanetId ) ); + Planet.createStatic( PlanetId ); - // This constructor is the same that creating sprite and calling Sprite.AddFramesByPattern. // It will look for a SubTexture ( in any Texture Atlas loaded, or the GlobalTextureAtlas ) animation by its name, it will search // for "gn00" to "gnXX" to create a new animation // see TextureAtlasManager::GetSubTexturesByPattern for more information. // This is the easiest way to load animated sprites. - Blindy = eeNew( Sprite, ( "gn" ) ); + Blindy.addFramesByPattern( "gn" ); // Set the sprite animation speed, set in Frames per Second // Sprites are auto-animated by default. - Rock->setAnimationSpeed( 32 ); + Rock.setAnimationSpeed( 32 ); // Set the render mode of the sprite - Blindy->setRenderMode( RN_MIRROR ); + Blindy.setRenderMode( RN_MIRROR ); // Set the Blend Mode of the sprite - Blindy->setBlendMode( ALPHA_BLENDONE ); + Blindy.setBlendMode( ALPHA_BLENDONE ); // Set the primitive fill mode P.setFillMode( DRAW_LINE ); @@ -142,11 +139,11 @@ EE_MAIN_FUNC int main (int argc, char * argv []) // Set the sprites position to the screen center Vector2i ScreenCenter( Engine::instance()->getWidth() / 2, Engine::instance()->getHeight() / 2 ); - Planet->setPosition( ScreenCenter.x - Planet->getAABB().getSize().getWidth() / 2, ScreenCenter.y - Planet->getAABB().getSize().getHeight() / 2 ); + Planet.setPosition( ScreenCenter.x - Planet.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Planet.getAABB().getSize().getHeight() / 2 ); - Rock->setPosition( ScreenCenter.x - Rock->getAABB().getSize().getWidth() / 2, ScreenCenter.y - Rock->getAABB().getSize().getHeight() / 2 ); + Rock.setPosition( ScreenCenter.x - Rock.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Rock.getAABB().getSize().getHeight() / 2 ); - Blindy->setPosition( ScreenCenter.x - Blindy->getAABB().getSize().getWidth() / 2, ScreenCenter.y - Blindy->getAABB().getSize().getHeight() / 2 ); + Blindy.setPosition( ScreenCenter.x - Blindy.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Blindy.getAABB().getSize().getHeight() / 2 ); // Set the planet angle interpolation PlanetAngle.addWaypoint( 0 ); @@ -156,16 +153,12 @@ EE_MAIN_FUNC int main (int argc, char * argv []) PlanetAngle.start(); // Create a Event callback for the rock sprite - Rock->setEventsCallback( cb::Make3( &spriteCallback ), &RockAngle ); + Rock.setEventsCallback( cb::Make3( &spriteCallback ), &RockAngle ); // Application loop - win->runMainLoop( &MainLoop ); + win->runMainLoop( &mainLoop ); } - eeSAFE_DELETE( Rock ); - eeSAFE_DELETE( Planet ); - eeSAFE_DELETE( Blindy ); - // Destroy the engine instance. Destroys all the windows and engine singletons. Engine::destroySingleton(); diff --git a/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp b/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp index 021089d50..8f08f1365 100644 --- a/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp +++ b/src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp @@ -14,7 +14,7 @@ BatchRenderer * Batch = eeNew( BatchRenderer, () ); Float ang = 0, scale = 1; bool side = false; -void MainLoop() +void mainLoop() { // Clear the screen buffer win->clear(); @@ -150,7 +150,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) FBO = FrameBuffer::New( 200, 200 ); // Application loop - win->runMainLoop( &MainLoop ); + win->runMainLoop( &mainLoop ); // Release the allocated objects ( VBOs and FBOs need to be released manually ) eeSAFE_DELETE( VBO ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index cb8a02002..806d7e8cb 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -2,7 +2,7 @@ Demo_Test::EETest * TestInstance = NULL; -static void MainLoop() { +static void mainLoop() { TestInstance->update(); } @@ -1528,7 +1528,7 @@ void EETest::process() { if ( NULL != mWindow && mWindow->isOpen() ) { TestInstance = this; - mWindow->runMainLoop( &MainLoop ); + mWindow->runMainLoop( &mainLoop ); } end();