void Container::run()
		{
			Messages::registerRecipient(Subject::KEYBOARD_BUTTON, bind(&Container::onKeyboardButton, this,
																	   placeholders::_1));

			globalContext.init();
			editContext.init();
			playContext.init();

			// Play one frame so the initial scene displays correctly.
			globalContext.enter();
			playContext.enter();
			playContext.advance();

			switchContext();

			while (Simplicity::getState() != Simplicity::State::STOPPING)
			{
				globalContext.advance();

				if (Simplicity::getState() == Simplicity::State::PLAYING)
				{
					playContext.advance();
				}
				else
				{
					editContext.advance();
				}
			}

			playContext.dispose();
			editContext.dispose();
			globalContext.dispose();
		}
Ejemplo n.º 2
0
void kThread::switchContext(void* args) {

    uThread* ut = scheduler->nonBlockingSwitch(*this);
    if(ut == nullptr)
        return;
    switchContext(ut, args);
}
		bool Container::onKeyboardButton(const Message& message)
		{
			const KeyboardButtonEvent* event = static_cast<const KeyboardButtonEvent*>(message.body);
			if (event->button == Keyboard::Button::GRAVE && event->buttonState == Button::State::UP)
			{
				switchContext();
			}

			return false;
		}
Ejemplo n.º 4
0
void delay(unsigned long delayTime)
{
	unsigned long start = getLssClock();
	unsigned long end = start + delayTime;

	if(end < 86400000)
	{
		while(getLssClock() <= end)
		{
			switchContext();
		}
	}
	else
	{
		unsigned long today = runningDay;
		end -= 86400000;
		while(today != runningDay && getLssClock() <= end)
		{
			switchContext();
		}
	}
}
Ejemplo n.º 5
0
static void jumpToTask()
{
	// switch kernel stack
	ASM("cli");
	_tss.rsp0 = ((uint64_t) currentThread->stack + currentThread->stackSize) & (uint64_t)~0xF;

	// reload the TSS
	reloadTR();

	// switch address space
	if (currentThread->pm != NULL) SetProcessMemory(currentThread->pm);
	ASM("cli");

	// make sure IF is set
	currentThread->regs.rflags |= (1 << 9);

	// switch context
	fpuLoad(&currentThread->fpuRegs);
	apic->timerInitCount = quantumTicks;
	switchContext(&currentThread->regs);
};
Ejemplo n.º 6
0
void initSched()
{
	nextPid = 1;
	spinlockRelease(&schedLock);

	// create a new stack for this initial process
	firstThread.stack = kmalloc(DEFAULT_STACK_SIZE);
	firstThread.stackSize = DEFAULT_STACK_SIZE;

	// the value of registers do not matter except RSP and RIP,
	// also the startup function should never return.
	memset(&firstThread.fpuRegs, 0, 512);
	memset(&firstThread.regs, 0, sizeof(Regs));
	firstThread.regs.rip = (uint64_t) &startupThread;
	firstThread.regs.rsp = (uint64_t) firstThread.stack + firstThread.stackSize;
	firstThread.regs.cs = 8;
	firstThread.regs.ds = 16;
	firstThread.regs.ss = 0;
	firstThread.regs.rflags = getFlagsRegister() | (1 << 9);		// enable interrupts

	// other stuff
	strcpy(firstThread.name, "Startup thread");
	firstThread.flags = 0;
	firstThread.pm = NULL;
	firstThread.pid = 0;
	firstThread.ftab = NULL;
	firstThread.rootSigHandler = 0;
	firstThread.sigput = 0;
	firstThread.sigfetch = 0;
	firstThread.sigcnt = 0;

	// UID/GID stuff
	firstThread.euid = 0;
	firstThread.suid = 0;
	firstThread.ruid = 0;
	firstThread.egid = 0;
	firstThread.sgid = 0;
	firstThread.rgid = 0;

	// set the working directory to /initrd by default.
	strcpy(firstThread.cwd, "/initrd");

	// no executable
	firstThread.fpexec = NULL;

	// no error ptr
	firstThread.errnoptr = NULL;

	// no wakeing
	firstThread.wakeTime = 0;

	// no umask
	firstThread.umask = 0;

	// no supplementary groups
	firstThread.numGroups = 0;
	
	// linking
	firstThread.prev = &firstThread;
	firstThread.next = &firstThread;

	// switch to this new thread's context
	currentThread = &firstThread;
	apic->timerInitCount = quantumTicks;
	switchContext(&firstThread.regs);
};
Ejemplo n.º 7
0
void SpaceshipGame::onStart()
{
  _canvas.clear();
  switchContext(&_game_context);
  _screen_timer.start();
}
Ejemplo n.º 8
0
int Editor::handle(int event)
{
	
	if (Fl_Gl_Window::handle(event) != 0)
		return 1;
	int key = Fl::event_key();
	switch(event) {
		case FL_SHORTCUT:
		case FL_KEYBOARD:
			switch(key) {
				case 'j':
					placeHero();
					break;
				case 'd':
					placeDoor();
					break;
				case ' ':
					hold_place = true;
					hold_del = false;
					break;
				case FL_Enter:
					switchContext();
					break;
				case FL_Left:
					advancePosition(false, false, true, false);
					frame = 20;
					hold_left = true;
					hold_right = false;
					break;
				case FL_Right:
					advancePosition(false, false, false, true);
					frame = 20;
					hold_right= true;
					hold_left = false;
					break;
				case FL_Up:
					advancePosition(true, false, false, false);
					frame = 20;
					hold_up = true;
					hold_down = false;
					break;
				case FL_Down:
					advancePosition(false, true, false, false);
					frame = 20;
					hold_down = true;
					hold_up = false;
					break;
				case 'a':
					m_UI->startAnimating();
					break;
				case 's':
					m_UI->stopAnimating();
					break;
				case FL_Shift_L:
				case FL_Shift_R:
					hold_del = true;
					hold_place = false;
					break;
			}
			break;
		case FL_KEYUP:
			switch(key) {
				case ' ':
					hold_place = false;
					if (Fl::event_key(FL_Shift_L) || Fl::event_key(FL_Shift_R))
						hold_del = true;
					break;	
				case FL_Left:
					hold_left = false;
					if (Fl::event_key(FL_Right))
						hold_right = true;
					break;
				case FL_Right:
					hold_right = false;
					if (Fl::event_key(FL_Left))
						hold_left = true;
					break;
				case FL_Up:
					hold_up = false;
					if (Fl::event_key(FL_Down))
						hold_down = true;
					break;
				case FL_Down:
					hold_down = false;
					if (Fl::event_key(FL_Up))
						hold_up = true;
					break;
				case FL_Shift_L:
				case FL_Shift_R:
					hold_del = false;
					if (Fl::event_key(' '))
						hold_place = true;
					break;
			}
			break;
		case FL_ENTER:
		case FL_MOVE:
		case FL_FOCUS:
		case FL_UNFOCUS:
			break;
		default:
			return 0;
			break;
		}
	return 1;
}