Ejemplo n.º 1
0
void System::runEdit(const char *startupBas) {
  logEntered();
  _mainBas = false;
  _loadPath = startupBas;

  while (true) {
    if (loadSource(_loadPath)) {
      setupPath(_loadPath);
      editSource(_loadPath);
      if (isBack() || isClosing()) {
        break;
      } else {
        do {
          execute(_loadPath);
        } while (isRestart());
      }
    } else {
      FILE *fp = fopen(_loadPath, "w");
      if (fp) {
        fprintf(fp, "rem Welcome to SmallBASIC\n");
        fclose(fp);
      } else {
        alert("Failed to load file", strerror(errno));
        break;
      }
    }
  }
}
Ejemplo n.º 2
0
//contains init functions and the main loop
int main(int argc, char **argv) {
	//create window
	glfwInit();

	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	mainWindow = glfwCreateWindow(800, 600, "Rome graphics", NULL, NULL);
	
	glfwMakeContextCurrent(mainWindow);

	std::cout << glfwGetWindowAttrib(mainWindow, GLFW_CONTEXT_VERSION_MAJOR) << "." << glfwGetWindowAttrib(mainWindow, GLFW_CONTEXT_VERSION_MINOR) << std::endl;

	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
	if (err != GLEW_OK) {
		std::cout << "GLEW failed to initialize" << std::endl;
	}


	sceneGraphMatrixStack = new MatrixStack();
	projectionMatrixStack = new MatrixStack();

	//gets perspective correct
	reshape(mainWindow, 800, 600);

	//set ROME_PATH to the main project directory
	setupPath();

	//load and compile shaders
	initShaders();

	//move to SimState or Renderer?
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

	//creates each state and gives it the main window
	manager = new StateManager(mainWindow);

	//GLFW doesn't accept object member functions, so use local ones that redirect
	glfwSetWindowSizeCallback(mainWindow, reshape);
	glfwSetKeyCallback(mainWindow, keyCallback);
	glfwSetCursorPosCallback(mainWindow, mousePosCallback);
	glfwSetScrollCallback(mainWindow, mouseWheelCallback);

	//state management loop
	manager->run();

	glfwDestroyWindow(mainWindow);
	glfwTerminate();
}
Ejemplo n.º 3
0
void OpenFileWidget::onItemClicked(QListWidgetItem *item)
{
    if(item->type() == QListWidgetItem::UserType)
    {
        setupPath(item);
        startTraverse();
    }
    else
    {
        m_fileList->setCurrentItem(item);
    }
}
Ejemplo n.º 4
0
int extractFileFromArchive(char * fileName, int arkiv, off_t nbytes){
#ifdef DEBUG
    printf("extractFileFromArchive(%s)\n", fileName);
#endif
    // Set up required paths for fileName
    if(setupPath(fileName) != 0){
	return -1;
    }
    
    if(isDir(fileName) == 1){
	// setupPath already took care of it for us
#ifdef DEBUG
	printf("     %s is already a directory\n", fileName);
#endif
	return 0;
    }

    // Check if file is read-only
    if(clearFile(fileName) == 0){
	snprintf(errDesc, ERR_STATUS_LENGTH, "removing read-only %s", fileName);
	return -1;
    }

    // File descriptor for file to extract
    int outputFile;

    if ((outputFile= open(fileName, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1){
	snprintf(errDesc, ERR_STATUS_LENGTH, "opening initial %s", fileName);
	return -1;
    }
    
    // Write to file
    if(copyBytes(fileName, arkiv, outputFile, nbytes) == -1){
	return -1;
    }

    return 0;
}
Ejemplo n.º 5
0
void System::runMain(const char *mainBasPath) {
  logEntered();

  // activePath provides the program name after termination
  String activePath = mainBasPath;
  _loadPath = mainBasPath;
  _mainBas = true;
  strcpy(opt_command, "welcome");

  bool started = execute(_loadPath);
  if (!started) {
    alert("Error", gsb_last_errmsg);
    _state = kClosingState;
  }

  while (!isClosing() && started) {
    if (isRestart()) {
      _loadPath = activePath;
      _state = kActiveState;
    } else {
      if (fileExists(_loadPath)) {
        _mainBas = false;
        activePath = _loadPath;
        if (!isEditReady()) {
          setupPath(_loadPath);
        }
      } else {
        _mainBas = true;
        _loadPath = mainBasPath;
        activePath = mainBasPath;
      }
    }

    if (!_mainBas && isEditReady() && loadSource(_loadPath)) {
      editSource(_loadPath);
      if (isBack()) {
        _loadPath.clear();
        _state = kActiveState;
        continue;
      } else if (isClosing()) {
        break;
      }
    }

    bool success = execute(_loadPath);
    bool networkFile = isNetworkLoad();
    if (!isBack() && !isClosing() &&
        (success || networkFile || !isEditEnabled())) {
      // when editing, only pause here when successful, otherwise the editor shows
      // the error. load the next network file without displaying the previous result
      if (!_mainBas && !networkFile) {
        // display an indication the program has completed
        showCompletion(success);
      }
      if (!success) {
        if (_mainBas) {
          // unexpected error in main.bas
          alert("", gsb_last_errmsg);
          _state = kClosingState;
        } else {
          // don't reload
          _loadPath.clear();
          _state = kActiveState;
        }
      }
      if (!_mainBas && !networkFile) {
        waitForBack();
      }
    }
  }
}
VesselConnectionView::VesselConnectionView(VesselView::Type type, int gen, int idx, double ysplit)
        : VesselView(0, 0, type, gen, idx), y_split(ysplit)
{
	setupPath();
}
Ejemplo n.º 7
0
/* doctor strategy:
     wait around for hero to request services;
     occasionally advertise

   returns ms elapsed, -2 if the monster dies
*/
int
shMonster::doDoctor ()
{
    int elapsed;
    int res = -1;
    int retry = 3;

    while (-1 == res) {
        if (!retry--) {
            return 200;
        }

        switch (mTactic) {

        case kNewEnemy:
            mStrategy = kWander;
            mTactic = kNewEnemy;
            return doWander ();
        case kMoveTo:
            res = doMoveTo ();
            continue;
        case kReady:
            if (Level->getRoomID (mX, mY) != mDoctor.mRoomID) {
                /* somehow, we're not in our hospital! */
                mDestX = mDoctor.mHomeX;
                mDestY = mDoctor.mHomeY;

                if (setupPath ()) {
                    mTactic = kMoveTo;
                    continue;
                } else {
                    return 2000;
                }
            }

            if (canSee (&Hero) and
                mDoctor.mRoomID == Level->getRoomID (Hero.mX, Hero.mY))
            {
                if (0 == RNG (12)) {
                    /* move to an empty square near the home square */
                    mDestX = mDoctor.mHomeX;
                    mDestY = mDoctor.mHomeY;
                    if (!mLevel ->
                        findAdjacentUnoccupiedSquare (&mDestX, &mDestY))
                    {
                        elapsed = doQuickMoveTo ();
                        if (-1 == elapsed) elapsed = 800;
                        return elapsed;
                    }
                    return RNG (300, 1000); /* nowhere to go, let's wait... */
                } else if (0 == RNG (50)) {
                    const char *quips[] = {
                        "\"Dammit, %s! I'm a docbot, not %s!\"",
                        "\"Your second amputation is half off!\"",
                        "\"Galaxy-class health care services!\"",
                        "\"I've been through much experience, you're dealing with an expert!\""
                    };
                    const unsigned int NUMQUIPS = sizeof (quips) / sizeof (char *);
                    const char *nouns[] = {
                        "a magician",
                        "a psychiatrist",
                        "a bartender",
                        "a bricklayer",
                        "a mechanic",
                        "a priest",
                        "a lawyer",
                        "a prostitute",
                        "a toaster oven",
                        "a warbot"
                    };
                    const unsigned int NUMNOUNS = sizeof (nouns) / sizeof (char *);
                    if (Hero.tryToTranslate (this)) {
                        I->p (quips[RNG (NUMQUIPS)],
                              Hero.mName, nouns[RNG (NUMNOUNS)]);
                        Hero.interrupt ();
                    }
                    return RNG (500, 1000);
                }
                return RNG (500, 1000);
            } else {
                return RNG (800, 1600);
            }
        case kFight:
        case kShoot:
            mTactic = kReady;
            debug.log ("Unexpected doctor tactic!");
        }
    }

    return RNG (300, 1000); /* keep on lurking */
}