//=========================================== // Entity::onParentTransformation //=========================================== void Entity::onParentTransformation(float32_t a, const Vec2f& s) { Range bounds = m_boundary; recomputeBoundary(); float32_t x = m_transl.x * cos(DEG_TO_RAD(a)) - m_transl.y * sin(DEG_TO_RAD(a)); float32_t y = m_transl.x * sin(DEG_TO_RAD(a)) + m_transl.y * cos(DEG_TO_RAD(a)); Vec2f oldTransl(x, y); Vec2f oldTransl_abs = s + oldTransl; float32_t oldRot_abs = a + m_rot; if (!m_silent) { float32_t rot_abs = getRotation_abs(); Vec2f transl_abs = getTranslation_abs(); EEvent* event1 = new EEntityBoundingBox(shared_from_this(), bounds, m_boundary); EEvent* event2 = new EEntityRotation(shared_from_this(), m_rot, oldRot_abs, m_rot, rot_abs); EEvent* event3 = new EEntityTranslation(shared_from_this(), m_transl, oldTransl_abs, m_transl, transl_abs); onEvent(event1); onEvent(event2); onEvent(event3); m_eventManager.queueEvent(event1); m_eventManager.queueEvent(event2); m_eventManager.queueEvent(event3); } for (set<pEntity_t>::iterator i = m_children.begin(); i != m_children.end(); ++i) (*i)->onParentTransformation(oldRot_abs, oldTransl_abs); }
QString OffEvent::toMessage(){ if(onEvent()){ return onEvent()->offEventMessage(); } else { return QString(); } }
QByteArray OffEvent::save(){ if(onEvent()){ return onEvent()->saveOffEvent(); } else { return QByteArray(); } }
//=========================================== // Entity::setShape //=========================================== void Entity::setShape(std::unique_ptr<Shape> shape) { Range bounds = m_boundary; Shape* oldShape = m_shape ? dynamic_cast<Shape*>(m_shape->clone()) : NULL; float32_t oldRot_abs = getRotation_abs(); m_shape = std::move(shape); if (m_shape) { m_shape->rotate(m_rot); m_shape->scale(m_scale); m_shape->setLineWidth(m_lineWidth); m_shape->setFillColour(m_fillColour); m_shape->setLineColour(m_lineColour); } recomputeBoundary(); if (!m_silent) { EEvent* event1 = new EEntityBoundingBox(shared_from_this(), bounds, m_boundary); EEvent* event2 = new EEntityShape(shared_from_this(), pShape_t(oldShape), oldRot_abs, pShape_t(dynamic_cast<Shape*>(m_shape->clone())), getRotation_abs()); onEvent(event1); onEvent(event2); m_eventManager.queueEvent(event1); m_eventManager.queueEvent(event2); } }
void InputManager::getInput() { int c = getch(); if (c != ERR) { MEVENT m_event; if ((c == KEY_MOUSE) && (getmouse(&m_event) != ERR)) { if (m_event.bstate & BUTTON1_CLICKED) { int y = m_event.y; int x = m_event.x; EventMouse m; m.setMouseY(y); m.setMouseX(x); m.setMouseAction(LEFT_BUTTON_CLICK); onEvent((Event*) &m); } } else { EventKeyboard k; k.setKey(c); onEvent((Event*) &k); } } }
//=========================================== // Entity::translate //=========================================== void Entity::translate(float32_t x, float32_t y) { Range bounds = m_boundary; float32_t oldRot = getRotation_abs(); Vec2f oldTransl = getTranslation_abs(); m_transl = m_transl + Vec2f(x, y); recomputeBoundary(); if (!m_silent) { Vec2f t = getTranslation_abs(); EEvent* event1 = new EEntityBoundingBox(shared_from_this(), bounds, m_boundary); EEvent* event2 = new EEntityTranslation(shared_from_this(), m_transl - Vec2f(x, y), oldTransl, m_transl, t); onEvent(event1); onEvent(event2); m_eventManager.queueEvent(event1); m_eventManager.queueEvent(event2); } for (set<pEntity_t>::iterator i = m_children.begin(); i != m_children.end(); ++i) (*i)->onParentTransformation(oldRot, oldTransl); }
bool FlyingCamera::processEvent(const SimEvent *event) { switch (event->type) { case SimActionEventType : { const SimActionEvent *action = dynamic_cast<const SimActionEvent *>(event); if (false == handleAction(action->action, action->fValue, action->device)) { return (Parent::processEvent(event)); } return (true); } onEvent(SimGainFocusEvent); onEvent(SimLoseFocusEvent); onEvent(SimFrameEndNotifyEvent); onEvent(SimObjectTransformEvent); default : return (false); } }
bool SimExplosionCloud::processEvent(const SimEvent * event) { switch (event->type) { onEvent(SimTimerEvent); onEvent(SimMessageEvent); } return false; }
bool SimInterior::processEvent(const SimEvent* event) { switch (event->type) { onEvent(SimObjectTransformEvent); onEvent(SimTimerEvent); default: return Parent::processEvent(event); } }
//=========================================== // Entity::rotate // // Pivot is in model space //=========================================== void Entity::rotate(float32_t deg, const Vec2f& pivot) { float32_t oldRot = m_rot; float32_t oldRot_abs = getRotation_abs(); Vec2f oldTransl = m_transl; Vec2f oldTransl_abs = getTranslation_abs(); // - Find model's origin (bottom-left corner) in parent's model space (o) // - This is just m_transl (despite any prior rotations) // - Find pivot in parent's model space (p) // - p = (pivot rotated by m_rot) + o // - Compute value of o rotated about p by deg degrees // - Set m_transl to o // - Add deg to m_rot // Pivot in parent's model space (or world space if this is root) float32_t px = pivot.x * cos(DEG_TO_RAD(m_rot)) - pivot.y * sin(DEG_TO_RAD(m_rot)); float32_t py = pivot.x * sin(DEG_TO_RAD(m_rot)) + pivot.y * cos(DEG_TO_RAD(m_rot)); Vec2f p(px + m_transl.x, py + m_transl.y); // Rotate bottom-left corner around pivot Vec2f o = m_transl - p; o.x = o.x * cos(DEG_TO_RAD(deg)) - o.y * sin(DEG_TO_RAD(deg)); o.y = o.x * sin(DEG_TO_RAD(deg)) + o.y * cos(DEG_TO_RAD(deg)); m_transl.x = p.x + o.x; m_transl.y = p.y + o.y; m_rot += deg; rotateShapes_r(deg); Range bounds = m_boundary; recomputeBoundary(); Vec2f ds = m_transl - oldTransl; if (!m_silent) { EEvent* event1 = new EEntityBoundingBox(shared_from_this(), bounds, m_boundary); EEvent* event2 = new EEntityRotation(shared_from_this(), oldRot, oldRot_abs, m_rot, getRotation_abs()); EEvent* event3 = new EEntityTranslation(shared_from_this(), oldTransl, oldTransl_abs, m_transl, oldTransl_abs + ds); onEvent(event1); onEvent(event2); onEvent(event3); m_eventManager.queueEvent(event1); m_eventManager.queueEvent(event2); m_eventManager.queueEvent(event3); } for (set<pEntity_t>::iterator i = m_children.begin(); i != m_children.end(); ++i) (*i)->onParentTransformation(oldRot_abs, oldTransl_abs); }
void init() { onEvent(Device::onNetwork, [this] (const Event *ev) { if (Device::getInstance()->isNetworkOnline()) { this->updateProducts(); } }); onEvent(Device::onBackground, [this] (const Event *ev) { if (!Device::getInstance()->isInBackground()) { this->restorePurchases(); } }); onSetupCompleted(true); }
Int App::run() { if(init() == false) { return -1; } SDL_Event event; _currentTime = SDL_GetTicks(); while(_running) { _oldTime = _currentTime; _currentTime = SDL_GetTicks(); Float dt = (_currentTime - _oldTime) / 1000.0f; while(SDL_PollEvent(&event)) { onEvent(&event); } loop(dt); render(); } cleanup(); return 0; }
//////////////////////////////////////////////////////////// // Send event //////////////////////////////////////////////////////////// void CSNAPIClient::sendEvent(CNF_EVENT event,int handle) { eLogLevel level=LOG_INF; // Check severity switch(event){ // Error case CNF_HOSTERROR: case CNF_USERERROR: level = LOG_ERR; break; // Warning case CNF_NOTANSWERED: level = LOG_WRN; break; // Debug case CNF_SUBMODIFIED: level = LOG_DBG; break; } if(!events[event]){ int brk = 1; } // Default to information logf(level,"Event","Sending event - %s",events[event]); // Pass on event onEvent(event,handle); }
int AppBase::run() { if (!onInit()) { return -1; } frame_timer.reset(); // game main loop begin . SDL_Event evnt; leave_main_loop = false; while (!leave_main_loop) { if (SDL_PollEvent(&evnt)) { processGlobalEvent(evnt); if (onEvent(evnt) == false) { processUnhandleEvent(evnt); } } if (!leave_main_loop) { onUpdate(); onRender(); } frame_timer.update(); } onExit(); return 0; }
bool NetlinkListener::onDataAvailable(SocketClient *cli) { int socket = cli->getSocket(); ssize_t count; uid_t uid = -1; count = TEMP_FAILURE_RETRY(uevent_kernel_multicast_uid_recv( socket, mBuffer, sizeof(mBuffer), &uid)); if (count < 0) { if (uid > 0) LOG_EVENT_INT(65537, uid); SLOGE("recvmsg failed (%s)", strerror(errno)); return false; } NetlinkEvent *evt = new NetlinkEvent(); if (!evt->decode(mBuffer, count, mFormat)) { SLOGE("Error decoding NetlinkEvent"); } else { onEvent(evt); } delete evt; return true; }
int CDotWars::onExecute() { currentTime = SDL_GetTicks(); if(onInit() == false) { return -1; } a.setColor(0, 0, 0xff); a.setPosition(50, 100); a.velocity.x = 0; a.velocity.y = 0; b.color = 0x00FF00FF; a.gravity = false; gravityOverlord.playerDot = &a; //da_overlord.mouseDot = &b; SDL_Event Event; while(running) { while(SDL_PollEvent(&Event)) { onEvent(&Event); } onLoop(); onRender(); } onCleanup(); return 0; }
int Menu::Execute() { Init(); while(running) { while(SDL_PollEvent(&Event)) { onEvent(&Event); } SDL_RenderClear(Renderer); SDL_RenderCopy(Renderer, Background, NULL, NULL); int pos = (WINDOW_HEIGHT - (3 * 116)) / 3; single_Player.render(Renderer, (WINDOW_WIDTH - single_Player.rect.w) / 2, pos / 2); two_Players.render(Renderer, (WINDOW_WIDTH - two_Players.rect.w) / 2, single_Player.rect.y + single_Player.rect.h + pos); exit.render(Renderer, (WINDOW_WIDTH - single_Player.rect.w) / 2, two_Players.rect.y + single_Player.rect.h + pos); SDL_RenderPresent(Renderer); } Cleanup(); return exit_status; }
void GameManager::run(int fr_time) { frame_time = fr_time; long int loop_time; Clock clock; WorldManager &worldmanager = WorldManager::getInstance(); GraphicsManager &graphicsmanager = GraphicsManager::getInstance(); InputManager &inputmanager = InputManager::getInstance(); LogManager &logmanager = LogManager::getInstance(); //MAIN GAME LOOP int i = 0; int sleep_time; logmanager.writeLog("GameManager::run: Game loop begins\n"); while (!game_over) { clock.delta(); inputmanager.getInput(); EventStep s = EventStep(); onEvent(&s); worldmanager.update(); worldmanager.draw(); graphicsmanager.swapBuffers(); loop_time = clock.split(); usleep((frame_time-loop_time)*1000); } logmanager.writeLog("GameManager::run: Game loop ends\n"); shutDown(); }
bool NetlinkListener::onDataAvailable(SocketClient *cli) { int socket = cli->getSocket(); ssize_t count; uid_t uid = -1; bool require_group = true; if (mFormat == NETLINK_FORMAT_BINARY_UNICAST) { require_group = false; } count = TEMP_FAILURE_RETRY(uevent_kernel_recv(socket, mBuffer, sizeof(mBuffer), require_group, &uid)); if (count < 0) { if (uid > 0) LOG_EVENT_INT(65537, uid); SLOGE("recvmsg failed (%s)", strerror(errno)); return false; } NetlinkEvent *evt = new NetlinkEvent(); if (evt->decode(mBuffer, count, mFormat)) { onEvent(evt); } else if (mFormat != NETLINK_FORMAT_BINARY) { // Don't complain if parseBinaryNetlinkMessage returns false. That can // just mean that the buffer contained no messages we're interested in. SLOGE("Error decoding NetlinkEvent"); } delete evt; return true; }
/*swap the buffers*/ void Gewy::update() { SDL_Event event; //creates a new event while (SDL_PollEvent(&event)) onEvent(&event); //polls the events SDL_GL_SwapBuffers(); glClearColor(br, bg, bb, ba); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
bool SmackerCtrl::processEvent(const SimEvent *event) { switch (event->type) { onEvent(SimMessageEvent); } return Parent::processEvent(event); }
bool SimMagnet::processEvent(const SimEvent *event) { switch (event->type) { onEvent(SimTriggerEvent); } return Parent::processEvent(event); }
void Actor::happen(Actor* initiator, unsigned int eventId, void* eventData) { onEvent( initiator, eventId, eventData ); for( ActorI actorI = _children.begin(); actorI != _children.end(); actorI++ ) { (*actorI)->happen( initiator, eventId, eventData ); } }
bool SimSmoke::processEvent(const SimEvent *event) { switch (event->type) { onEvent(SimTimerEvent); } return false; }
void App::onExecute() { // run the main loop while (running) { onEvent(); onLoop(); onRender(); } }
bool EventListenerGesture::init() { auto func = [this](EventCustom* event) -> void { onEvent(event); }; return EventListenerCustom::init((std::string)(GESTURE_EVENT_NAME), func); }
bool EventListenerPhysicsContact::init() { auto func = [this](EventCustom* event) -> void { onEvent(event); }; return EventListenerCustom::init(PHYSICSCONTACT_EVENT_NAME, func); }
void Game::run() { init(); SDL_Event event; //Timing Variables double msPerFrame = 1000.0 / 60.0; double unprocessed = 0.0; Uint32 lastTime = SDL_GetTicks(); Uint32 lastFPSTime = SDL_GetTicks(); int frames = 0; int ticks = 0; bool vSync = false; bool ticked = false; // while(keepGoing) { ticked = false; while(SDL_PollEvent(&event)) { onEvent(&event); } //Do timing (keep us running at 60 ticks per second) Uint32 now = SDL_GetTicks(); unprocessed += (now - lastTime) / msPerFrame; lastTime = now; while(unprocessed > 1) { tick(); unprocessed--; ticked = true; ticks++; } if((ticked && vSync) || !vSync) { draw(); frames++; } if(now > lastFPSTime + 1000) { //Put the FPS and ticks in the window title std::stringstream ss; ss << baseWindowTitle << "FPS: "<< frames << " Ticks: " << ticks << " # of Lights: " << curScene->lights.size(); SDL_SetWindowTitle(window, ss.str().c_str()); lastFPSTime += 1000; frames = 0; ticks = 0; } //Lets let the computer rest SDL_Delay(1); } deinit(); }
bool playDelegate::processEvent(const SimEvent* event) { switch (event->type) { onEvent (SimActionEvent); default: return Parent::processEvent (event); } }
void Diabolical::onExecute() { while (!eventQueue.empty()) { onEvent(eventQueue.front()); eventQueue.pop_front(); } onLoop(); onRender(); }