Skip to content

Instantly share code, notes, and snippets.

View StefanoFiumara's full-sized avatar

Stefano Fiumara StefanoFiumara

  • Architect @ Slalom Build
  • Houston, TX
View GitHub Profile
@StefanoFiumara
StefanoFiumara / Player.cs
Created September 5, 2013 17:57
A small example of using player states to handle movement.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public enum PlayerState {MOVING_UP, MOVING_DOWN, MOVING_LEFT, MOVING_RIGHT};
public PlayerState state;
public float speed;
@StefanoFiumara
StefanoFiumara / MoveGrid.cs
Created September 6, 2013 06:03
Re-written movement script, old script still at the bottom just in case!
using UnityEngine;
using System.Collections;
public class GridMove : MonoBehaviour {
public enum PlayerState {MOVING, STOPPED, TURNING};
public enum Direction {UP, DOWN, LEFT, RIGHT};
public PlayerState state;
public Direction facing;
@StefanoFiumara
StefanoFiumara / GridMove.cs
Last active December 22, 2015 11:58
Movement Code v2.0!
using System.Collections;
using UnityEngine;
class GridMove : MonoBehaviour {
public float moveSpeed;
public float gridSize;
public enum PlayerState {MOVING, STOPPED};
public enum Direction {UP, DOWN, LEFT, RIGHT};
@StefanoFiumara
StefanoFiumara / gist:6849128
Last active December 24, 2015 19:19
Unix process initialization
void process_manager::create_processes(int n) {
int pid;
for(int i = 1; i <= n; ++i) {
//create pipes before forking
if(pipe(parent_to_child) == -1) {
cout << "Error creating pipe!" << endl;
exit();
}
@StefanoFiumara
StefanoFiumara / gist:6896016
Created October 9, 2013 04:02
Check safe procedure for banker's algorithm
bool process_manager::check_safe(int* _avail, int** _alloc, int** _max) {
int i, j; //loop counters
int* work = new int[num_resources];
bool* finish = new bool[num_processes];
//set finish[i] to false
for(i = 0; i < num_processes; i++) {
finish[i] = false;
}
int VirtualMemoryManager::convert_from_hex(string h) {
h = h.substr(2); //truncate the 0x portion
int result = 0;
//magic, converts to int, stores in result
sscanf(h.c_str(), "%x", &result);
return result;
}
int VirtualMemoryManager::get_mask(int last_x_bits) {
int mask = 0;
for(int i = 0; i < last_x_bits; i++) {
mask += pow(2, i);
}
return mask;
}
if(virtual_memory[index_to_access] == -1) {
//not in ram
//it's on the disk
//call page fault handler
int new_frame = page_fault_handler();
//clear out old frame info
if(ram[new_frame] != -1) {
virtual_memory[ ram[new_frame] ] = -1;
}
//mark page table entry
for(int i = 0; i < frames_per_process; i++) {
int cur_frame = frames_per_process*pid_offset + i;
if(ram[cur_frame] == -1) {
//empty slot found in ram
return cur_frame;
}
}
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <time.h>
#include "VirtualMemoryManager.h"
using namespace std;