Example #1
0
MenuCharSelect::MenuCharSelect(RosalilaGraphics*painter,int x, int y,
                   int size_x,int size_y,
                   int size_cuadro_x,int size_cuadro_y,
                   int separacion_x,int separacion_y,
                   int max_locked_chars_pa,int max_locked_chars_pb,
                   int preview_pa_x,int preview_pa_y,
                   int preview_pb_x,int preview_pb_y,
                   std::vector<std::string>names,
                   int select_p1_x,int select_p1_y,
                   int select_p2_x,int select_p2_y)
{
    writeLogLine("Creating character selection menu");
    this->x=x;
    this->y=y;
    this->painter=painter;

    this->size_x=size_x;
    this->size_y=size_y;
    this->size_cuadro_x=size_cuadro_x;
    this->size_cuadro_y=size_cuadro_y;

    this->separacion_x=separacion_x;
    this->separacion_y=separacion_y;

    this->max_locked_chars_pa=max_locked_chars_pa;
    this->max_locked_chars_pb=max_locked_chars_pb;

    this->preview_pa_x=preview_pa_x;
    this->preview_pa_y=preview_pa_y;
    this->preview_pb_x=preview_pb_x;
    this->preview_pb_y=preview_pb_y;

    for(int i=0;i<(int)names.size();i++)
    {
        portraits.push_back(painter->getTexture(assets_directory+"chars/"+names[i]+std::string("/portrait.png")));
        previews.push_back(painter->getTexture(assets_directory+"chars/"+names[i]+std::string("/preview.png")));
    }
    this->names=names;

    this->select_p1_x=select_p1_x;
    this->select_p1_y=select_p1_y;
    this->select_p2_x=select_p2_x;
    this->select_p2_y=select_p2_y;

    selected_char_p1=painter->getTexture(assets_directory+"menu/selected_char_p1.png");
    locked_char_p1=painter->getTexture(assets_directory+"menu/locked_char_p1.png");

    if(max_locked_chars_pb>0)
    {
        locked_char_p2=painter->getTexture(assets_directory+"menu/locked_char_p2.png");
        selected_char_p2=painter->getTexture(assets_directory+"menu/selected_char_p2.png");
    }
    no_portrait=painter->getTexture(assets_directory+"menu/no_portrait.png");
    writeLogLine("Creating character selection menu");
}
int main()
{
	bool testsPassed = runTests();
	if (testsPassed)
	{
		writeLogLine("Tests all passed!");
	}
	else
	{
		writeLogLine("Tests failed");
	}

	pauseForClose();
	return 0;
}
Example #3
0
void Stage::loadDialogues(std::string file)
{
    writeLogLine("Loading dialogues from XML.");

    char *archivo=new char[255];
    strcpy(archivo,"stages/");
    strcat(archivo,file.c_str());
    strcat(archivo,"/dialogues.xml");
    TiXmlDocument doc_t( archivo );
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *dialogues_file=doc->FirstChild("DialoguesFile");

    if(dialogues_file==NULL)
        return;

    for(TiXmlNode *dialogue_node=dialogues_file->FirstChild("dialogue");
            dialogue_node!=NULL;
            dialogue_node=dialogue_node->NextSibling("dialogue"))
    {
        int frame=atoi(dialogue_node->ToElement()->Attribute("frame"));
        std::string text=dialogue_node->ToElement()->Attribute("text");
        std::string path=dialogue_node->ToElement()->Attribute("path");

        dialogues[frame]=new Dialogue(painter,sonido,receiver,text,painter->getTexture("stages/"+file+"/"+path));
    }
}
Example #4
0
//Stop the timer with an optional line in the log file
void Logger::endLogTimer(char logLetter, const std::wstring& logLine)
{
	//Stop timer
	filetimeStacks[logLetter].pop_back();

	//Write line
	if (!logLine.empty())
		writeLogLine(logLetter, logLine);
}
Example #5
0
void Font::setSize(int size)
{
    font_size=size;
    font = TTF_OpenFont( font_path.c_str(), font_size );

    if(font==NULL)
    {
        writeLogLine("Could not init font. Place it on /misc/"+font_path);
    }
}
Example #6
0
//Start the timer with an optional line in the log file
void Logger::startLogTimer(char logLetter, const std::wstring& logLine)
{
	//Write line
	if (!logLine.empty())
		writeLogLine(logLetter, logLine);

	//Start timer
	FILETIME time;
	GetSystemTimeAsFileTime(&time);
	filetimeStacks[logLetter].push_back(time);
}
Example #7
0
Stage::~Stage()
{
    writeLogLine("Deleting stage.");
    for(;!back.empty();)
    {
        Layer*layer=back.back();
        back.pop_back();
        delete layer;
    }
    for(;!front.empty();)
    {
        Layer*layer=front.back();
        front.pop_back();
        delete layer;
    }
}
Example #8
0
Font::Font(string path)
{
    font_path=assets_directory+"misc/"+path;
    font = TTF_OpenFont( font_path.c_str(), font_size );

    if(font==NULL)
    {
        writeLogLine("Could not init font. Place it on /misc/font.ttf .");
    }

    font_size=10;

    textColor.r = 255;
    textColor.g = 255;
    textColor.b = 255;
}
void RosalilaGraphics::updateScreen()
{
    //Write errors to the log
    std::string error= ">>>";
    error+=SDL_GetError();
    if(error!=">>>")
        writeLogLine(error);

    //Draw
    frameCap();

//    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
//    SDL_RenderClear(renderer);

    //SDL_RenderPresent(renderer);
    SDL_GL_SwapWindow(window);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
Example #10
0
//Mark a given time with a log line
void Logger::markLogTime(char logLetter, const std::wstring& logLine)
{
	//Generate a timed line
	std::wstringstream linePrefix;
	if (filetimeStacks[logLetter].empty())
		linePrefix <<L"<NULL> ms - ";
	else {
		//Time the event
		FILETIME endTime;
		GetSystemTimeAsFileTime(&endTime);
		FILETIME startTime = filetimeStacks[logLetter][filetimeStacks[logLetter].size()-1];
		DWORD timeMS = getTimeDifferenceMS(startTime, endTime);
		linePrefix <<timeMS <<L" ms - ";
		filetimeStacks[logLetter][filetimeStacks[logLetter].size()-1] = endTime;
	}

	//Write line
	writeLogLine(logLetter, linePrefix.str() + logLine);
}
void pauseForClose()
{
	writeLogLine("Hit enter to close");
	//Wait for input
	std::cin.get();
}
int main(int argc, char *argv[], char* envp[])
{
	// If this were a larger project, I'd set up a separate GTest project for this, but that's a lot of work to get a handful of unit tests implemented
	// and as such is a pretty excessive solution to my problem.

	writeLogLine("Starting boggle solver");

	char path_to_dictionary[kArbitraryMaxPath];
	char path_to_puzzle[kArbitraryMaxPath];
	char path_to_results[kArbitraryMaxPath];

	if (argc != 4)
	{
		writeLogLine("Boggle Solver Command Line Arguments:");
		writeLogLine("BoggleSolver.exe {PATH_TO_DICTIONARY} {PATH_TO_PUZZLE} {RESULTS_FILE}");
		pauseForClose();
		return 1;
	}

	strcpy_s(path_to_dictionary, argv[1]);
	writeLogLineFormatted("Path to dictionary: %s", path_to_dictionary);

	strcpy_s(path_to_puzzle, argv[2]);
	writeLogLineFormatted("Path to puzzle: %s", path_to_puzzle);
	
	strcpy_s(path_to_results, argv[3]);
	writeLogLineFormatted("Path to results file %s", path_to_results);

	CharIndexMap* theMap = new CharIndexMap();

	writeLogLine("Loading dictionary");
	DictionaryTrie theDictionary(theMap);
	bool dictLoaded = theDictionary.LoadFromFile(path_to_dictionary);

	if(!dictLoaded)
	{
		writeLogLine("Dictionary Load Failed");
		pauseForClose();
		return -1;
	}

	writeLogLine("Loading board");
	Board theBoard;
	bool boardLoaded = theBoard.LoadFromFile(path_to_puzzle);

	if(!boardLoaded)
	{
		writeLogLine("Failed board loading");
		pauseForClose();
		return -1;
	}

	ThreadsafeStack<char*> foundWords;
	ThreadsafeStack<std::pair<int, int>> taskStack;
	int columns = theBoard.ColumnCount();
	int rows = theBoard.RowCount();

	for (int thisRow = 0; thisRow < rows; thisRow++)
	{
		for (int thisColumn = 0; thisColumn < columns; thisColumn++)
		{
			taskStack.push(std::pair<int, int>(thisColumn, thisRow));
		}
	}

	clock_t timer;
	timer = clock();

	std::vector<std::thread> threadPool;
	for (int i = 0; i < kThreadPoolSize; i++)
	{
		threadPool.push_back(std::thread(threadBaseLevel, &theBoard, &theDictionary, &taskStack, &foundWords));
	}
	
	for (int i = 0; i < kThreadPoolSize; i++)
	{
		threadPool[i].join();
	}

	timer = clock() - timer;
	float timeSpent = static_cast<float>(timer) / CLOCKS_PER_SEC;

	writeLogLineFormatted("Took %f to solve", timeSpent);
	writeLogLineFormatted("Found %i words", foundWords.size());

	std::vector<char*> words;

	//We can sort a vector - we can't sort a threadsafestack - we don't care about speed at this point, so let's just make it a vector and go from there.
	while (!foundWords.empty())
	{
		char* word = foundWords.pop();
		words.push_back(word);
	}

	std::sort(words.begin(), words.end(), CompareStringsNoCase);

	std::ofstream outfp(path_to_results);
	if(outfp.is_open())
	{
		for(char* word : words)
		{
			outfp.write(word, strlen(word));
			outfp.write("\n", 1);
		}
	}

	
	//writeLogLine("All words:");
	//for(char* word : foundWords)
	//{
	//	writeLogLineFormatted("%s", word);
	//}

	pauseForClose();

	delete theMap;
	return 0;
}
Example #13
0
void Stage::loadFromXML(std::string path)
{
    writeLogLine("Loading stage from XML.");

    string xml_path=assets_directory+"stages/"+path+"/main.xml";

    TiXmlDocument doc_t(xml_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *stage_file=doc->FirstChild("StageFile");

    //Load settings
    music_path=assets_directory+"stages/"+path+"/music.ogg";

    TiXmlNode *nodo_ss=stage_file->FirstChild("StageSize");
    this->size=atoi(nodo_ss->ToElement()->Attribute("x"));

    TiXmlNode *nodo_floor=stage_file->FirstChild("Floor");
    this->pos_piso=atoi(nodo_floor->ToElement()->Attribute("position"));

    writeLogLine("Loading stage's BackLayers.");

    //Load back layer
    for(TiXmlNode *nodo_back=stage_file->FirstChild("BackLayer");
            nodo_back!=NULL;
            nodo_back=nodo_back->NextSibling("BackLayer"))
    {
        int frame_duration=atoi(nodo_back->ToElement()->Attribute("frame_duration"));
        int depth_effect_x=atoi(nodo_back->ToElement()->Attribute("depth_effect_x"));
        int depth_effect_y=atoi(nodo_back->ToElement()->Attribute("depth_effect_y"));
        int alignment_x=atoi(nodo_back->ToElement()->Attribute("alignment_x"));
        int alignment_y=atoi(nodo_back->ToElement()->Attribute("alignment_y"));

        int velocity_x=0;
        if(nodo_back->ToElement()->Attribute("velocity_x")!=NULL)
            velocity_x=atoi(nodo_back->ToElement()->Attribute("velocity_x"));

        int min_x=-999999;
        if(nodo_back->ToElement()->Attribute("min_x")!=NULL)
            min_x=atoi(nodo_back->ToElement()->Attribute("min_x"));

        int max_x=999999;
        if(nodo_back->ToElement()->Attribute("max_x")!=NULL)
            max_x=atoi(nodo_back->ToElement()->Attribute("max_x"));

        std::vector <Image*> textures;
        std::vector <int> textures_size_x;
        std::vector <int> textures_size_y;

        for(TiXmlNode* layer=nodo_back->FirstChild("frame");
                layer!=NULL;
                layer=layer->NextSibling("frame"))
        {
            string image_path=assets_directory+"stages/"+path+"/images/"+layer->ToElement()->Attribute("image_path");

            Image* image=painter->getTexture(image_path);
            textures.push_back(image);

            int size_x=image->getWidth();
            if(layer->ToElement()->Attribute("size_x")!=NULL)
                size_x=atoi(layer->ToElement()->Attribute("size_x"));

            int size_y=image->getHeight();
            if(layer->ToElement()->Attribute("size_y")!=NULL)
                size_y=atoi(layer->ToElement()->Attribute("size_y"));

            textures_size_x.push_back(size_x);
            textures_size_y.push_back(size_y);
        }

        back.push_back(new Layer(textures,textures_size_x,textures_size_y,frame_duration,depth_effect_x,depth_effect_y,alignment_x,alignment_y,velocity_x,min_x,max_x));
    }

    writeLogLine("Loading stage's FrontLayers.");

    //Load front layer
    for(TiXmlNode *nodo_back=stage_file->FirstChild("FrontLayer");
            nodo_back!=NULL;
            nodo_back=nodo_back->NextSibling("FrontLayer"))
    {
        int frame_duration=atoi(nodo_back->ToElement()->Attribute("frame_duration"));
        int depth_effect_x=atoi(nodo_back->ToElement()->Attribute("depth_effect_x"));
        int depth_effect_y=atoi(nodo_back->ToElement()->Attribute("depth_effect_y"));
        int alignment_x=atoi(nodo_back->ToElement()->Attribute("alignment_x"));
        int alignment_y=atoi(nodo_back->ToElement()->Attribute("alignment_y"));

        int velocity_x=0;
        if(nodo_back->ToElement()->Attribute("velocity_x")!=NULL)
            velocity_x=atoi(nodo_back->ToElement()->Attribute("velocity_x"));

        int min_x=-999999;
        if(nodo_back->ToElement()->Attribute("min_x")!=NULL)
            min_x=atoi(nodo_back->ToElement()->Attribute("min_x"));

        int max_x=999999;
        if(nodo_back->ToElement()->Attribute("max_x")!=NULL)
            max_x=atoi(nodo_back->ToElement()->Attribute("max_x"));

        std::vector <Image*> textures;
        std::vector <int> textures_size_x;
        std::vector <int> textures_size_y;

        for(TiXmlNode* layer=nodo_back->FirstChild("frame");
                layer!=NULL;
                layer=layer->NextSibling("frame"))
        {
            string image_path=assets_directory+"stages/"+path+"/images/"+layer->ToElement()->Attribute("image_path");

            Image* image=painter->getTexture(image_path);
            textures.push_back(image);

            int size_x=image->getWidth();
            if(layer->ToElement()->Attribute("size_x")!=NULL)
                size_x=atoi(layer->ToElement()->Attribute("size_x"));

            int size_y=image->getHeight();
            if(layer->ToElement()->Attribute("size_y")!=NULL)
                size_y=atoi(layer->ToElement()->Attribute("size_y"));

            textures_size_x.push_back(size_x);
            textures_size_y.push_back(size_y);
        }

        front.push_back(new Layer(textures,textures_size_x,textures_size_y,frame_duration,depth_effect_x,depth_effect_y,alignment_x,alignment_y,velocity_x,min_x,max_x));
    }
    writeLogLine("Stage loaded succesfully from XML.");
}
Image* RosalilaGraphics::getTexture(std::string filename)
{
    SDL_Surface *surface;
    GLenum texture_format;
    GLint  nOfColors;
    GLuint texture;

    if ( (surface = IMG_Load(filename.c_str())) ) {

            // get the number of channels in the SDL surface
            nOfColors = surface->format->BytesPerPixel;
            if (nOfColors == 4)     // contains an alpha channel
            {
                    if (surface->format->Rmask == 0x000000ff)
                            texture_format = GL_RGBA;
                    //else
                            //texture_format = GL_BGRA;
            } else if (nOfColors == 3)     // no alpha channel
            {
                    if (surface->format->Rmask == 0x000000ff)
                            texture_format = GL_RGB;
                    //else
                            //texture_format = GL_BGR;
            } else {
                writeLogLine("Warning: "+ filename+ " is not truecolor. This will probably break.");
                    // this error should not go unhandled
            }

        // Have OpenGL generate a texture object handle for us
        glGenTextures( 1, &texture );

        // Bind the texture object
        glBindTexture( GL_TEXTURE_2D, texture );

        // Set the texture's stretching properties
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

//for(int x=0;x<surface->w;x++)
//for(int y=0;y<surface->h;y++)
//((unsigned int*)surface->pixels)[y*(surface->pitch/sizeof(unsigned int)) + x]+=1;
        // Edit the texture object's image data using the information SDL_Surface gives us
#ifdef OSX
        glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
                          GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels );
#else
        glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
                          texture_format, GL_UNSIGNED_BYTE, surface->pixels );
#endif
    }
    else {
        std::string sdl_error=SDL_GetError();
        writeLogLine("SDL could not load "+filename+": "+sdl_error);
        SDL_Quit();
        return NULL;
    }


    Image*image=new Image();
    image->setTexture(texture);
    image->setWidth(surface->w);
    image->setHeight(surface->h);

    // Free the SDL_Surface only if it was successfully created
    if ( surface ) {
        SDL_FreeSurface( surface );
    }

    writeLogLine(filename+" loaded");

    return image;
}
Example #15
0
void Stage::loadFromXML(std::string name)
{
    this->name=name;

    //Load settings
    char *music=new char[255];
    strcpy(music,"stages/");
    strcat(music,name.c_str());
    strcat(music,"/music.ogg");
    music_path=(std::string)music;

    this->dialogue_x=0;
    this->dialogue_y=0;
    this->dialogue_padding_x=0;
    this->dialogue_padding_y=0;


    this->bound_x1=0;
    this->bound_y1=0;
    this->bound_x2=painter->screen_width;
    this->bound_y2=painter->screen_height;


    this->velocity=20;

    writeLogLine("Loading stage's BackLayers.");


	addLayer("fondo",1,40,0,0,0,0,0);
	addLayer("planetaguerra",1,40,120,0,300,350,2000-256+32);
	addLayer("explosion",7,5,120,0,300,350,2000);
	addLayer("explosion",7,3,120,0,350,375,2000);
	addLayer("explosion",7,4,120,0,400,445,2000);
	addLayer("explosion",7,9,120,0,450,415,2000);
	addLayer("explosion",7,7,120,0,350,405,2000);
	addLayer("explosion",7,4,120,0,320,410,2000);
	addLayer("explosion",7,8,120,0,463,423,2000);
	addLayer("explosion",7,5,120,0,435,395,2000);
	addLayer("explosion",7,7,120,0,427,393,2000);
	addLayer("explosion",7,9,120,0,421,405,2000);
	addLayer("explosion",7,4,120,0,413,403,2000);
	addLayer("restosbrillantes",1,5,3,0,300,440,0,3500,75);
	addLayer("city",3,21,80,0,900,350,1300);
	addLayer("restosnegros",1,2,10,0,100,575,0);
	addLayer("restosnegros",1,2,25,0,300,450,0);
	//addLayer("restosnegros",1,2,30,0,600,300,0);
	//addLayer("plataforma",1,100,1,0,0,0,0);


/*
    //Load back layer
    for(TiXmlNode *nodo_back=stage_file->FirstChild("BackLayer");
            nodo_back!=NULL;
            nodo_back=nodo_back->NextSibling("BackLayer"))
    {
        int frame_duration=0;
        if(nodo_back->ToElement()->Attribute("frame_duration")!=NULL)
            frame_duration=atoi(nodo_back->ToElement()->Attribute("frame_duration"));

        int depth_effect_x=0;
        if(nodo_back->ToElement()->Attribute("depth_effect_x")!=NULL)
            depth_effect_x=atoi(nodo_back->ToElement()->Attribute("depth_effect_x"));

        int depth_effect_y=0;
        if(nodo_back->ToElement()->Attribute("depth_effect_y")!=NULL)
            depth_effect_y=atoi(nodo_back->ToElement()->Attribute("depth_effect_y"));

        int align_x=0;
        if(nodo_back->ToElement()->Attribute("align_x")!=NULL)
            align_x=atoi(nodo_back->ToElement()->Attribute("align_x"));

        int align_y=0;
        if(nodo_back->ToElement()->Attribute("align_y")!=NULL)
            align_y=atoi(nodo_back->ToElement()->Attribute("align_y"));

        int separation_x=0;
        if(nodo_back->ToElement()->Attribute("separation_x")!=NULL)
            separation_x=atoi(nodo_back->ToElement()->Attribute("separation_x"));

        std::vector <Image*> textures;
        std::vector <int> textures_size_x;
        std::vector <int> textures_size_y;

        for(TiXmlNode* layer=nodo_back->FirstChild("frame");
                layer!=NULL;
                layer=layer->NextSibling("frame"))
        {
            char *image=new char[255];
            strcpy(image,"stages/");
            strcat(image,name.c_str());
            strcat(image,"/images/");
            strcat(image,layer->ToElement()->Attribute("image_path"));

            Image *image_temp=painter->getTexture(image);

            int size_x=image_temp->getWidth();
            int size_y=image_temp->getHeight();

            if(layer->ToElement()->Attribute("width")!=NULL)
                size_x=atoi(layer->ToElement()->Attribute("width"));
            if(layer->ToElement()->Attribute("height")!=NULL)
                size_y=atoi(layer->ToElement()->Attribute("height"));

            textures.push_back(image_temp);
            textures_size_x.push_back(size_x);
            textures_size_y.push_back(size_y);
        }

        back.push_back(new Layer(textures,textures_size_x,textures_size_y,frame_duration,depth_effect_x,depth_effect_y,align_x,align_y,separation_x));
    }

    writeLogLine("Loading stage's FrontLayers.");

    //Load front layer
    for(TiXmlNode *nodo_back=stage_file->FirstChild("FrontLayer");
            nodo_back!=NULL;
            nodo_back=nodo_back->NextSibling("FrontLayer"))
    {
        int frame_duration=0;
        if(nodo_back->ToElement()->Attribute("frame_duration")!=NULL)
            frame_duration=atoi(nodo_back->ToElement()->Attribute("frame_duration"));

        int depth_effect_x=0;
        if(nodo_back->ToElement()->Attribute("depth_effect_x")!=NULL)
            depth_effect_x=atoi(nodo_back->ToElement()->Attribute("depth_effect_x"));

        int depth_effect_y=0;
        if(nodo_back->ToElement()->Attribute("depth_effect_y")!=NULL)
            depth_effect_y=atoi(nodo_back->ToElement()->Attribute("depth_effect_y"));

        int align_x=0;
        if(nodo_back->ToElement()->Attribute("align_x")!=NULL)
            align_x=atoi(nodo_back->ToElement()->Attribute("align_x"));

        int align_y=0;
        if(nodo_back->ToElement()->Attribute("align_y")!=NULL)
            align_y=atoi(nodo_back->ToElement()->Attribute("align_y"));

        int separation_x=0;
        if(nodo_back->ToElement()->Attribute("separation_x")!=NULL)
            separation_x=atoi(nodo_back->ToElement()->Attribute("separation_x"));

        std::vector <Image*> textures;
        std::vector <int> textures_size_x;
        std::vector <int> textures_size_y;

        for(TiXmlNode* layer=nodo_back->FirstChild("frame");
                layer!=NULL;
                layer=layer->NextSibling("frame"))
        {
            char *image=new char[255];
            strcpy(image,"stages/");
            strcat(image,name.c_str());
            strcat(image,"/images/");
            strcat(image,layer->ToElement()->Attribute("image_path"));

            Image *image_temp=painter->getTexture(image);

            int size_x=image_temp->getWidth();
            int size_y=image_temp->getHeight();

            if(layer->ToElement()->Attribute("width")!=NULL)
                size_x=atoi(layer->ToElement()->Attribute("width"));
            if(layer->ToElement()->Attribute("height")!=NULL)
                size_y=atoi(layer->ToElement()->Attribute("height"));

            textures.push_back(image_temp);
            textures_size_x.push_back(size_x);
            textures_size_y.push_back(size_y);
        }

        front.push_back(new Layer(textures,textures_size_x,textures_size_y,frame_duration,depth_effect_x,depth_effect_y,align_x,align_y,separation_x
                                  ));
    }
    writeLogLine("Stage loaded succesfully from XML.");

    loadDialogues(name);
*/
}
RosalilaGraphics::RosalilaGraphics()
{
    //XML Initializations
    string configxml_path=assets_directory+"config.xml";
    TiXmlDocument doc_t( configxml_path.c_str() );
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    TiXmlNode *config_file=doc->FirstChild("ConfigFile");

    TiXmlElement *screensize_element=config_file->FirstChild("Resolution")->ToElement();
    screen_width=atoi(screensize_element->Attribute("x"));
    screen_height=atoi(screensize_element->Attribute("y"));

    TiXmlElement *resolution_element=config_file->FirstChild("ScreenSize")->ToElement();
    int screen_resized_width=atoi(resolution_element->Attribute("x"));
    int screen_resized_height=atoi(resolution_element->Attribute("y"));

    TiXmlElement *fullscreen_element=config_file->FirstChild("Fullscreen")->ToElement();
    fullscreen=strcmp(fullscreen_element->Attribute("enabled"),"yes")==0;

    TiXmlElement *font_element=config_file->FirstChild("Font")->ToElement();

    int font_size=10;
    if(font_element->Attribute("size")!=NULL)
    {
        font_size=atoi(font_element->Attribute("size"));
    }
    int font_red=0;
    if(font_element->Attribute("red")!=NULL)
    {
        font_red=atoi(font_element->Attribute("red"));
    }
    int font_green=0;
    if(font_element->Attribute("green")!=NULL)
    {
        font_green=atoi(font_element->Attribute("green"));
    }
    int font_blue=0;
    if(font_element->Attribute("blue")!=NULL)
    {
        font_blue=atoi(font_element->Attribute("blue"));
    }
    //Internal initializations
    joystick_1 = NULL;
    joystick_2 = NULL;

    screen_bpp = 32;
    camera_x=camera_y=0;

    //Initialize all SDL subsystems
    if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 )
    {
        writeLogLine(SDL_GetError());
        return;
    }

    //Initialize SDL_ttf
    if( TTF_Init() == -1 )
    {
        writeLogLine(SDL_GetError());
        return;
    }

    font = NULL;
    textColor.r = font_red;
    textColor.g = font_green;
    textColor.b = font_blue;

    string font_path=assets_directory+"misc/font.ttf";
    font = TTF_OpenFont( font_path.c_str(), font_size );

    if(font==NULL)
    {
        writeLogLine("Could not init font. Place it on /misc/font.ttf .");
    }

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*

    window = SDL_CreateWindow( "Rosalila Engine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                               screen_resized_width, screen_resized_height,
                               SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );

    if(fullscreen)
        SDL_SetWindowFullscreen(window,SDL_WINDOW_FULLSCREEN);

    renderer = SDL_CreateRenderer(window, -1, 0);

    //Set the openGL state?
    glEnable( GL_TEXTURE_2D );
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

    glViewport( 0, 0, screen_resized_width, screen_resized_height );

    glClear( GL_COLOR_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glOrtho(0.0f, screen_width, screen_height, 0.0f, -1.0f, 1.0f);

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    //Fps cap
    frames_per_seccond = 60;
    frame = 0;
    fps=new Timer();
    update=new Timer();
    fps->start();
    update->start();

    //Init joysticks
    if( SDL_NumJoysticks() == 1 )
    {
        writeLogLine("1 joystick was found.");
        joystick_1 = SDL_JoystickOpen( 0 );
        if(joystick_1 != NULL)
            writeLogLine("Joystick for player 1 initialized succesfully.");
        else
            writeLogLine("Error initializing joystick for player 1.");
    }
    if( SDL_NumJoysticks() == 2 )
    {
        writeLogLine("2 joysticks were found.");
        joystick_1 = SDL_JoystickOpen( 0 );
        if(joystick_1 != NULL)
            writeLogLine("Joystick for player 1 initialized succesfully.");
        else
            writeLogLine("Error initializing joystick for player 1.");
        joystick_2 = SDL_JoystickOpen( 1 );
        if(joystick_2 != NULL)
            writeLogLine("Joystick for player 2 initialized succesfully.");
        else
            writeLogLine("Error initializing joystick for player 2.");
    }

    //If everything initialized fine
    writeLogLine("Success! SDL initialized.");

     SDL_GL_CreateContext(window);
    GLenum error = GL_NO_ERROR;
    error = glGetError();
    if( error != GL_NO_ERROR ) {
/* Died as glu did
         printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
*/
         exit(12);
    }

    return;
}
Example #17
0
void Logger::writeLogLine(std::string LogLine) {
	writeLogLine(LogLine, true);
}