Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Project CodeName NightLight
- (C) 2011 NightLight Team
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any
- damages arising from the use of this software.
- Permission is granted to anyone to use this software for any
- purpose, including commercial applications, and to alter it and
- redistribute it freely, subject to the following restrictions:
- 1. The origin of this software must not be misrepresented; you
- must not claim that you wrote the original software. If you use
- this software in a product, an acknowledgment in the product
- documentation would be appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and
- must not be misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source
- distribution.
- Scorcher24
- */
- #include "stdafx.hpp"
- using namespace NightLight;
- #include "GameStateDemo.hpp"
- #include "Game.hpp"
- GameStateDemo::GameStateDemo( u32 id )
- : IGameState(id), m_controller(Controller())
- {}
- GameStateDemo::GameStateDemo( u32 id, boost::any usrdata )
- : IGameState(id, usrdata), m_controller(Controller())
- {
- boost::any_cast<Game>(m_usrdata).test();
- }
- GameStateDemo::~GameStateDemo()
- {
- delete m_batcher;
- }
- void GameStateDemo::onEnterGameState( s32 old_state )
- {
- // Load SpriteSheet
- SpriteSheet* SpriteSheet = m_controller.getResourceManager().getSpriteSheet("SpriteSheet");
- // Load Shader
- Shader* ShaderTexturedWithAlphaTest = m_controller.getResourceManager().getShader("TexturedWithAlphaTest");
- // Create Batcher
- m_batcher = new SpriteBatcher(ShaderTexturedWithAlphaTest, SpriteSheet->getTexture());
- m_batcher->insert(new BatchedSprite(glm::vec2(64, 64), glm::vec3(100, 100, LayerConstants::DYNAMIC_LAYER1), SpriteSheet->getTexCoordsByName("bohne_64") ));
- m_batcher->createBatch();
- // Connect Events
- m_controller.connectSignalRender(NLBindRenderSlot(GameStateDemo, renderObject));
- m_controller.getTimerController().connectSignalLogicUpdate(NLBindUpdateLogicSlot(GameStateDemo, update));
- }
- void GameStateDemo::onLeaveGameState( s32 new_state )
- {
- }
- void GameStateDemo::renderObject( u32 delta, u32 time )
- {
- m_batcher->renderObject();
- }
- void GameStateDemo::update( u32 delta, u32 time )
- {
- }
- ///------------------------------------------
- Game::Game()
- : m_controller(SystemController::getInstance())
- {
- m_controller.setAppName("NightLightSandBox");
- m_controller.setVendorName("Scorched Productions");
- m_data_dir = m_controller.getUserDataDir();
- if ( m_controller.createUserDataDir() )
- {
- m_controller.createLog(m_data_dir + "/SandboxLog.html", LL_VERBOSE, new HtmlWriter);
- }
- else
- {
- throw Exception("SystemController::createUserDataDir() failed!");
- }
- }
- Game::~Game()
- {
- }
- int Game::runGame()
- {
- // Create Window
- m_controller.createWindow(WINDOW_WINDOWED);
- m_controller.getOpenGLContext()->setClearColor(Color4f(0.0, 0.0, 0.4f, 1.0f));
- // Load Resource File
- m_controller.getResourceManager().loadResourceFile("../xml/examples.xml");
- // Create GameStateManager and add state
- m_statemgr = new Util::GameStateManager();
- m_statemgr->addGameState(new GameStateDemo(GS_DEMO, *this));
- m_statemgr->changeToGameState(GS_DEMO);
- // Connect Event
- m_controller.getWindow()->connectSignalQuit(NLBindQuitSlot(Game, quit));
- // Enter Loop
- m_controller.enterLoop();
- // return ok
- return 0;
- }
- bool Game::quit()
- {
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment