Пример #1
0
// ----------------------------------------------------------------------------
void Editor::writeStrc(FILE* fp, stringc str)
{
    u8 size;
    size = str.size() + 1;
    fwrite(&size, sizeof(u8), 1, fp);
    fwrite(str.c_str(), sizeof(c8), size, fp);
} // writeStrc
Пример #2
0
bool trimLine( stringc& line, u32 loop_count, const c8* char_list, const u32 char_count )
{
	u32 k_max = 3;
	bool result = false;

	/// find from start
	u32 k = 0;
	s32 pos = line.findFirstChar(char_list, char_count);
	if ( pos != -1 )
	{
		result = true;
		while ( (pos != -1) && (k<k_max) )
		{
			line.erase( k ); // more hackisch
			pos = line.findFirstChar(char_list, char_count);
			k++;
		}
	}

	/// find from back
	k = 0;
	pos = line.findLastChar(char_list, char_count);
	if ( pos != -1 )
	{
		result = true;
		while ( (pos != -1) && (k<k_max) )
		{
			line.erase( line.size()-1 ); // more hackisch
			pos = line.findLastChar(char_list, char_count);
			k++;
		}
	}
	return result;
}
Пример #3
0
// ----------------------------------------------------------------------------
stringc Editor::getLib(stringc s)
{
    u32 ix;
    ix = s.findLast('/');
    s = s.subString(0, ix);
    ix = s.findLast('/');
    s = s.subString(ix + 1, s.size() - ix - 1);
    return s;
} // getLib
Пример #4
0
 //-------------------------------------------------------------------------
 //                              l o g M e s s a g e 
 //-------------------------------------------------------------------------
 void CApplication::logMessage(stringc msg)
 {
     msg += "\n";
     fputs(msg.c_str(), stdout);
     if(m_logFile)
     {
         m_logFile->write(msg.c_str(),msg.size());
         m_logFile->write("\n",1);
     }
 }
Пример #5
0
    //-------------------------------------------------------------------------
    //                         _ e x t r a c t D i r 
    //-------------------------------------------------------------------------
    stringc _extractDir(stringc filename)
    {
        stringc result="";
        // find last forward or backslash
        s32 lastSlash = filename.findLast('/');
        const s32 lastBackSlash = filename.findLast('\\');
        lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;

        if ((u32)lastSlash < filename.size())
            return filename.subString(0, lastSlash+1);
        else
            return ".";
    }
Пример #6
0
/// @brief List all files of given extension-list
u32 FindFiles( Container& out, const stringc& rootDir, const Container& fileTypes )
{
	if (rootDir.size()==0)
		return 0;

	if (fileTypes.size()==0)
		return 0;

	const u32 old_size = out.size();

	for (u32 i=0; i<fileTypes.size(); i++)
	{
		core::stringc command;
		command = "find ";
		command += rootDir;
		command += " -iname '*.";
		command += fileTypes[i];
		command += "' | sort";
		AddLines( out, command );
	}
	return out.size() - old_size; // return Number of added lines(stringc) to container 'out'.
}
Пример #7
0
void puzzle_select(s4 &game_state, stringc &selected_file, s4 &puzzle_type)
{
    //ICameraSceneNode* camera = irrlicht->smgr->addCameraSceneNode();
    // matrix4 ortho;
    // ortho.buildProjectionMatrixOrthoLH(
    //     irrlicht->driver->getScreenSize().Width/ortho_scale,
    //     irrlicht->driver->getScreenSize().Height/ortho_scale,-1.0,1000.0);
    // camera->setProjectionMatrix(ortho);
    // camera->setPosition({0,0,-100});
    // camera->setTarget({0,0,0}); 

    IGUIEnvironment* env = irrlicht->device->getGUIEnvironment(); 
    IGUIFont* font = irrlicht->font;//device->getGUIEnvironment()->getFont(_DIRECTORY_ + "fontlucida.png");

    p("---- Menu loop start ----");

    d32         dt = 0;
    const d32   maxDelta = 1.0f/60.0f * 5; 
    const d32   tick_ms = 0.01666; // TODO: change this back to 30ms?
    d32         render_dt = 0;
    const d32   render_ms = 0.064; // TODO: change this back to 30ms?
    uint32      time_physics_prev = btclock->getTimeMicroseconds();

    IFileSystem* file_system = env->getFileSystem();
    irr::io::path prev_dir = file_system->getWorkingDirectory();
    file_system->changeWorkingDirectoryTo(_DIRECTORY_ + "levels/");
    IFileList* file_list = file_system->createFileList();
    s4 file_count = file_list->getFileCount();

    s4 selected_level = 2;

    stringc* found_levels = new stringc[file_count];
    for (s4 i = 0; i < file_count; i++)
    { 
        found_levels[i] = file_list->getFileName(i).c_str();
    }

    while(irrlicht->device->run() && game_state == GAME_STATE_MENU)
    {
        const uint32 time_physics_curr = btclock->getTimeMicroseconds();
        const d32 frameTime = ((d32)(time_physics_curr - time_physics_prev)) / 1000000.0; // todo: is this truncated correctly?
        time_physics_prev = time_physics_curr;
        d32 capped_dt = frameTime;
        if (capped_dt > maxDelta) { capped_dt = maxDelta; }

        render_dt += capped_dt;
        if ( render_dt >= render_ms )
        {
            render_dt = 0.0f;  
            
            irrlicht->driver->beginScene(true, true, SColor(255,100,100,140));            
            irrlicht->smgr->drawAll();

            irrlicht->driver->clearZBuffer();
            for (s4 i = 0; i < file_count; i++)
            {
                SColor color = SColor(255,150,150,230);
                if (i == selected_level)
                {
                    color = SColor(255,255,255,255);
                }
                font->draw(found_levels[i], rect<s32>(10,20 + 20 * i,300,50), color);
            }            

            stringc text = "How To Throw A Baseball Through Solid Wall";
            font->draw(text, rect<s32>(300,90,300,50), SColor(255,255,255,255));

            text = "Arrow keys to move.";
            font->draw(text, rect<s32>(300,120,300,50), SColor(255,255,255,255));
            text = "A and D rotate camera. W zooms in, S zooms out.";
            font->draw(text, rect<s32>(300,140,300,50), SColor(255,255,255,255));
            text = "R to reset back to menu.";
            font->draw(text, rect<s32>(300,160,300,50), SColor(255,255,255,255));
            text = "Esc to quit.";
            font->draw(text, rect<s32>(300,180,300,50), SColor(255,255,255,255));
            text = "00_levels.fixed.txt: spacebar, backspace adjusts layers. ";
            font->draw(text, rect<s32>(300,200,300,50), SColor(255,255,255,255));

            text = "Baseball Gates is the only puzzle with a solution.";
            font->draw(text, rect<s32>(300,240,300,50), SColor(255,255,255,255));
            text = "Black cubes are placeholders for watermills.";
            font->draw(text, rect<s32>(300,260,300,50), SColor(255,255,255,255));
            text = "Put water in front of them to turn them on.";
            font->draw(text, rect<s32>(300,280,300,50), SColor(255,255,255,255)); 

            text = "antithesis.ctr is an experiment. Use mouse to grab things.";
            font->draw(text, rect<s32>(300,320,300,50), SColor(255,255,255,255));

            irrlicht->driver->endScene();
        }

        dt += capped_dt;
        while( dt >= tick_ms ) // run 30 times per second
        {
            dt -= tick_ms;
            receiver->input();
            
            s4 prev_selected_level = selected_level;

            if (receiver->up.state)     selected_level--;
            if (receiver->down.state)   selected_level++;

            if (selected_level < 2)     selected_level = file_count - 1;
            if (selected_level >= file_count)    selected_level = 2; 

            if (receiver->enter.state)  game_state = GAME_STATE_PLAY;
            
            if (receiver->QUIT)         game_state = GAME_STATE_QUIT;
        }
    }

    selected_file = found_levels[selected_level];

    s4 string_size = selected_file.size() - 1;
    char file_type[3];
    file_type[2] = selected_file[string_size];
    file_type[1] = selected_file[string_size-1];
    file_type[0] = selected_file[string_size-2];

    //std::cout << file_type[0] << file_type[1] << file_type[2] << std::endl;

    if (file_type[0] == 't') {
        puzzle_type = 0;
    } else if (file_type[0] == 'c') {
        puzzle_type = 1;
    }

    delete [] found_levels;

    file_system->changeWorkingDirectoryTo(prev_dir);

    // irrlicht->smgr->setActiveCamera(0);   
    // camera->remove();
    //irrlicht->smgr->clear();
}