Пример #1
0
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;
}
Пример #2
0
//............................................................................
void QF::stop(void) {
    QF_INT_LOCK_KEY_
    QF_INT_LOCK_();
    setvect(uCOS, l_dosSpareISR);           // restore the original DOS vector
    QF_INT_UNLOCK_();
    onCleanup();                                           // cleanup callback
}
Пример #3
0
void Flow::cleanUp() {
    _flowJointData.clear();
    _jointThreads.clear();
    _flowJointKeywords.clear();
    _collisionSystem.resetCollisions();
    _initialized = false;
    _isScaleSet = false;
    onCleanup();
 }
Пример #4
0
//------------------------------------------------------------------------------
// Main game loop inside the onExecute() method
//------------------------------------------------------------------------------
int Client::onExecute() {
    if(onInit() == false) {
        return -1;
    }

    SDL_Event event;
	Uint32 fps = 60;
	Uint32 frametime = 1000 / fps;
	Uint32 starttime, exectime;

    while(running) {
		starttime = SDL_GetTicks();

		// start by checking for OpenGL error
		GLenum error;
		while ((error = glGetError()) != GL_NO_ERROR) {
			printf("Error: %s\n", gluErrorString(error));
		}

		// check for input events
        while(SDL_PollEvent(&event)) {
            onEvent(&event);
        }

		// act on input events
        onInput();

		// TODO more game state updates here,
		// like applying velocity, gravity, etc
		p1->onUpdate();
		if (follow) {
			setXView(p1->getX());
			setYView(p1->getY());
		}

		// draw the screen
        onRender();

		// sleep time to make fps
		exectime = SDL_GetTicks() - starttime;
		if (exectime < frametime) {
			//SDL_Delay(SDL_GetTicks() % frametime);
			SDL_Delay(frametime - exectime);
		}
    }

    onCleanup();

    return 0;
}
Пример #5
0
int Core::onExecute()
{
   if(onInit() == false)
      return -1;

   SDL_Event event;

   //seed random
   srand(time(0));
  
   //For controlling framerate
   int dt_frame = 0;
   int dt_current = 0;
   int dt_previous = 0;
 
   while(running_)
   {
      //Process events
      while(SDL_PollEvent(&event))
      {
         //Quit game event
         if(event.type == SDL_QUIT)
         {
            running_ = false;
         }
         //Process game events
         pGame_->onEvent(&event);
      }
      
      //Regulate framerate;
      dt_previous = dt_current;
      dt_current = pDelta_->getTicks();
      dt_frame = dt_current - dt_previous;
      if(dt_frame < (FRAME_RATE))
      {
         SDL_Delay(FRAME_RATE - dt_frame);
      }
      
      //Process game loop
      pGame_->onLoop(pDelta_->getTicks());
      //Render game world
      pGame_->onRender();
      //Swap buffers
      SDL_GL_SwapBuffers();
   }
   
   onCleanup();
   
   return 0;
}//End onExecute()
Пример #6
0
//............................................................................
int16_t QF::run(void) {
    l_running = true;
    onStartup();                                           // startup callback

               // raise the priority of this (main) thread to tick more timely
    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);

    do {
        Sleep(l_tickMsec);                       // wait for the tick interval
        QF_onClockTick();        // clock tick callback (must call QF_TICKX())
    } while (l_running);
    onCleanup();                                           // cleanup callback
    QS_EXIT();                                  // cleanup the QSPY connection
    //DeleteCriticalSection(&l_win32CritSect);
    return static_cast<int16_t>(0);                          // return success
}
Пример #7
0
int CApp::onExecute() {
  if(onInit() == false) {
    return -1;
  }

  SDL_Event Event;

  Uint32 waitTime = 1000.0f/FPS;
  Uint32 frameStartTime = 0;
  Sint32 delayTime;
  Uint32 idleTime = 0;

  // kill any cursors that may be waiting in the beginning
  tuioClient->lockCursorList();
  map< int, GnmsCursor*>::iterator it;
  for (it=gnmsCursors.begin(); it!=gnmsCursors.end(); it++) {
    if (it->second != NULL) {
      it->second->killCursor();
    }
  }
  tuioClient->unlockCursorList();

  // polling loop... i know it's old fashioned,
  // but it's so easy to implement
  while(isRunning == true) {
    // get events, react accordingly
    while(SDL_PollEvent(&Event)) {
      onEvent(&Event);
    }

    delayTime = waitTime - (SDL_GetTicks() - frameStartTime);

    onLoop();

    if(delayTime > 0) {
      SDL_Delay((Uint32)delayTime);
    }
    frameStartTime = SDL_GetTicks();

    onRender();

  }

  onCleanup();

  return 0;
}
Пример #8
0
int GApp::onExecute(void)
{
    if (onInit() == false) {
        return -1;
    }

    SDL_Event event;

    while (isRunning) {
        while (SDL_PollEvent(&event)) {
            onEvent(&event);

            onLoop();
            onRender();
        }
    }

    onCleanup();
    return 0;
}
Пример #9
0
int BallGame::OnExecute() {
	if(onInit() == false) {
	        return -1;
	    }

	    SDL_Event Event;

	    while(running) {
	        while(SDL_PollEvent(&Event)) {
	            onEvent(&Event);
	        }

	        onLoop();
	        if (onRender() == false) {
	        	return -1;
	        }
	    }

	    onCleanup();

	    return 0;
}
Пример #10
0
int App::onExecute()
{
    if (onInit() == false)
    {
        return -1;
    }

    SDL_Event event;

    timespec start, end;
    double elapsed;
    long waitusec;
    while (m_running)
    {
        clock_gettime(CLOCK_MONOTONIC, &start);
        while(SDL_PollEvent(&event))
        {
            onEvent(&event);
        }

        onLoop();
        onRender();
        
        clock_gettime(CLOCK_MONOTONIC, &end);
        elapsed = double(end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec)/double(1000000000);
        
        if (elapsed < double(1/m_targetFps))
        {
            waitusec = (double(1/m_targetFps) - elapsed) * 1000000;
            usleep(waitusec);
        }
    }

    onCleanup();

    return 0;
}
Пример #11
0
Entity::~Entity(){
    onCleanup();
}
Пример #12
0
EntityEnemy::~EntityEnemy(){
    onCleanup();
}
Пример #13
0
//****************************************************************************
/// @description
/// This function stops the QF application. After calling this function,
/// QF attempts to gracefully stop the application. This graceful shutdown
/// might take some time to complete. The typical use of this function is
/// for terminating the QF application to return back to the operating
/// system or for handling fatal errors that require shutting down
/// (and possibly re-setting) the system.
///
/// @sa QF::onCleanup()
///
void QF::stop(void) {
    onCleanup(); // application-specific cleanup callback
    // nothing else to do for the preemptive QXK kernel
}
Пример #14
0
//............................................................................
void QF::stop(void) {
    onCleanup();  // cleanup callback
}
Пример #15
0
EntityPlayer::~EntityPlayer(){
    onCleanup();
}
Пример #16
0
CArea::~CArea()
{
	onCleanup();
}
Пример #17
0
void Flow::calculateConstraints(const std::shared_ptr<AnimSkeleton>& skeleton, 
                                AnimPoseVec& relativePoses, AnimPoseVec& absolutePoses) {
    cleanUp();
    if (!skeleton) {
        return;
    }
    auto flowPrefix = FLOW_JOINT_PREFIX.toUpper();
    auto simPrefix = SIM_JOINT_PREFIX.toUpper();
    std::vector<int> handsIndices;
    _groupSettings.clear();

    for (int i = 0; i < skeleton->getNumJoints(); i++) {
        auto name = skeleton->getJointName(i);
        if (std::find(HAND_COLLISION_JOINTS.begin(), HAND_COLLISION_JOINTS.end(), name) != HAND_COLLISION_JOINTS.end()) {
            handsIndices.push_back(i);
        }
        auto parentIndex = skeleton->getParentIndex(i);
        if (parentIndex == -1) {
            continue;
        }
        auto jointChildren = skeleton->getChildrenOfJoint(i);
        // auto childIndex = jointChildren.size() > 0 ? jointChildren[0] : -1;
        auto group = QStringRef(&name, 0, 3).toString().toUpper();
        auto split = name.split("_");
        bool isSimJoint = (group == simPrefix);
        bool isFlowJoint = split.size() > 2 && split[0].toUpper() == flowPrefix;
        if (isFlowJoint || isSimJoint) {
            group = "";
            if (isSimJoint) {
                for (int j = 1; j < name.size() - 1; j++) {
                    bool toFloatSuccess;
                    QStringRef(&name, (int)(name.size() - j), 1).toString().toFloat(&toFloatSuccess);
                    if (!toFloatSuccess && (name.size() - j) > (int)simPrefix.size()) {
                        group = QStringRef(&name, (int)simPrefix.size(), (int)(name.size() - j + 1) - (int)simPrefix.size()).toString();
                        break;
                    }
                }
                if (group.isEmpty()) {
                    group = QStringRef(&name, (int)simPrefix.size(), name.size() - (int)simPrefix.size()).toString();
                }
                qCDebug(animation) << "Sim joint added to flow: " << name;
            } else {
                group = split[1];
            }
            if (!group.isEmpty()) {
                _flowJointKeywords.push_back(group);
                FlowPhysicsSettings jointSettings;
                if (PRESET_FLOW_DATA.find(group) != PRESET_FLOW_DATA.end()) {
                    jointSettings = PRESET_FLOW_DATA.at(group);
                } else {
                    jointSettings = DEFAULT_JOINT_SETTINGS;
                }
                if (_flowJointData.find(i) ==  _flowJointData.end()) {
                    auto flowJoint = FlowJoint(i, parentIndex, -1, name, group, jointSettings);
                    _flowJointData.insert(std::pair<int, FlowJoint>(i, flowJoint));
                }
                updateGroupSettings(group, jointSettings);
            }
        } else {
            if (PRESET_COLLISION_DATA.find(name) != PRESET_COLLISION_DATA.end()) {
                _collisionSystem.addCollisionSphere(i, PRESET_COLLISION_DATA.at(name));
            }
        }
    }

    for (auto &jointData : _flowJointData) {
        int jointIndex = jointData.first;
        glm::vec3 jointPosition, parentPosition, jointTranslation;
        glm::quat jointRotation;
        getJointPositionInWorldFrame(absolutePoses, jointIndex, jointPosition, _entityPosition, _entityRotation);
        getJointTranslation(relativePoses, jointIndex, jointTranslation);
        getJointRotation(relativePoses, jointIndex, jointRotation);
        getJointPositionInWorldFrame(absolutePoses, jointData.second.getParentIndex(), parentPosition, _entityPosition, _entityRotation);

        jointData.second.setInitialData(jointPosition, jointTranslation, jointRotation, parentPosition);
    }

    std::vector<int> roots;

    for (auto &joint :_flowJointData) {
        if (_flowJointData.find(joint.second.getParentIndex()) == _flowJointData.end()) {
            joint.second.setAnchored(true);
            roots.push_back(joint.first);
        } else {
            _flowJointData[joint.second.getParentIndex()].setChildIndex(joint.first);
        }
    }
    int extraIndex = -1;
    for (size_t i = 0; i < roots.size(); i++) {
        FlowThread thread = FlowThread(roots[i], &_flowJointData);
        // add threads with at least 2 joints
        if (thread._joints.size() > 0) {
            if (thread._joints.size() == 1) {
                int jointIndex = roots[i];
                auto &joint = _flowJointData[jointIndex];
                auto &jointPosition = joint.getUpdatedPosition();
                auto newSettings = joint.getSettings();
                extraIndex = extraIndex > -1 ? extraIndex + 1 : skeleton->getNumJoints();
                joint.setChildIndex(extraIndex);
                auto newJoint = FlowJoint(extraIndex, jointIndex, -1, joint.getName(), joint.getGroup(), newSettings);
                newJoint.toHelperJoint(jointPosition, HELPER_JOINT_LENGTH);
                glm::vec3 translation = glm::vec3(0.0f, HELPER_JOINT_LENGTH, 0.0f);
                newJoint.setInitialData(jointPosition + translation, 100.0f * translation , Quaternions::IDENTITY, jointPosition);
                _flowJointData.insert(std::pair<int, FlowJoint>(extraIndex, newJoint));
                FlowThread newThread = FlowThread(jointIndex, &_flowJointData);
                if (newThread._joints.size() > 1) {
                    _jointThreads.push_back(newThread);
                }
            } else {
                _jointThreads.push_back(thread);
            }
        }
    }
    
    if (_jointThreads.size() == 0) {
        onCleanup();
    }
    if (handsIndices.size() > 0) {
        FlowCollisionSettings handSettings;
        handSettings._radius = HAND_COLLISION_RADIUS;
        for (size_t i = 0; i < handsIndices.size(); i++) {
            _collisionSystem.addCollisionSphere(handsIndices[i], handSettings, glm::vec3(), true, true);
        }
    }
    _initialized = _jointThreads.size() > 0;
}