| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /**
- Attention!
- This file initializes the Oxygine engine.
- If you just started here and don't understand the code completely, feel free to come back later.
- You can start from example.cpp and example.h, which main functions are called from here.
- */
- #include "core/oxygine.h"
- #include "Stage.h"
- #include "DebugActor.h"
- #include "example.h"
- using namespace oxygine;
- // This function is called each frame
- int mainloop()
- {
- // It gets passed to our example game implementation
- example_update();
- // Update our stage
- // Update all actors. Actor::update will also be called for all its children
- getStage()->update();
- if (core::beginRendering())
- {
- Color clearColor(32, 32, 32, 255);
- Rect viewport(Point(0, 0), core::getDisplaySize());
- // Render all actors inside the stage. Actor::render will also be called for all its children
- getStage()->render(clearColor, viewport);
- core::swapDisplayBuffers();
- }
- // Update engine-internal components
- // If input events are available, they are passed to Stage::instance.handleEvent
- // If the function returns true, it means that the user requested the application to terminate
- bool done = core::update();
- return done ? 1 : 0;
- }
- // Application entry point
- void run()
- {
- ObjectBase::__startTracingLeaks();
- // Initialize Oxygine's internal stuff
- core::init_desc desc;
- desc.title = "Oxygine Application";
- #if OXYGINE_SDL || OXYGINE_EMSCRIPTEN
- // The initial window size can be set up here on SDL builds
- desc.w = 960;
- desc.h = 640;
- // Marmalade settings can be modified from the emulator's menu
- #endif
- example_preinit();
- core::init(&desc);
- // Create the stage. Stage is a root node for all updateable and drawable objects
- Stage::instance = new Stage(true);
- Point size = core::getDisplaySize();
- getStage()->setSize(size);
- // DebugActor is a helper actor node. It shows FPS, memory usage and other useful stuff
- DebugActor::show();
- // Initializes our example game. See example.cpp
- example_init();
- #ifdef EMSCRIPTEN
- /*
- If you build for Emscripten, mainloop is called automatically and shouldn't be called here.
- See emscripten_set_main_loop in the EMSCRIPTEN section below
- */
- return;
- #endif
- // This is the main game loop.
- while (1)
- {
- int done = mainloop();
- if (done)
- break;
- }
- /*
- If we get here, the user has requested the Application to terminate.
- We dump and log all our created objects that have not been freed yet
- */
- ObjectBase::dumpCreatedObjects();
- /*
- Let's clean up everything right now and call ObjectBase::dumpObjects() again.
- We need to free all allocated resources and delete all created actors.
- All actors/sprites are smart-pointer objects and don't need to be removed by hand.
- But now we want to delete it by hand.
- */
- // See example.cpp for the shutdown function implementation
- example_destroy();
- //renderer.cleanup();
- // Releases all internal components and the stage
- core::release();
- // The dump list should be empty by now,
- // we want to make sure that there aren't any memory leaks, so we call it again.
- ObjectBase::dumpCreatedObjects();
- ObjectBase::__stopTracingLeaks();
- //end
- }
- #ifdef __S3E__
- int main(int argc, char* argv[])
- {
- run();
- return 0;
- }
- #endif
- #ifdef OXYGINE_SDL
- #include "SDL_main.h"
- extern "C"
- {
- int main(int argc, char* argv[])
- {
- run();
- return 0;
- }
- };
- #endif
- #ifdef EMSCRIPTEN
- #include <emscripten.h>
- void one() { mainloop(); }
- int main(int argc, char* argv[])
- {
- run();
- emscripten_set_main_loop(one, 0, 0);
- return 0;
- }
- #endif
|