TextureController::~TextureController() {
	IF_PRINT_DEBUG(VIDEO_DEBUG) << "Deleting all remaining ImageTextures, a total of: " << _images.size() << endl;

	// Invoking the ImageTexture destructor will erase the entry in the _images map that corresponds to that object
	// Thus the map will decrement in size by one on every iteration through this loop
	while (_images.empty() == false) {
		ImageTexture* img = (*_images.begin()).second;
		img->texture_sheet->RemoveTexture(img);
		delete img;
	}

	IF_PRINT_DEBUG(VIDEO_DEBUG) << "Deleting all remaining texture sheets, a total of: " << _tex_sheets.size() << endl;
	for (vector<TexSheet*>::iterator i = _tex_sheets.begin(); i != _tex_sheets.end(); i++) {
		delete *i;
	}
}
예제 #2
0
ScriptEngine::~ScriptEngine() {
    IF_PRINT_DEBUG(SCRIPT_DEBUG) << "ScriptEngine destructor invoked." << endl;

    _open_files.clear();
    lua_close(_global_state);
    _global_state = NULL;
}
예제 #3
0
SystemEngine::SystemEngine()
{
    IF_PRINT_DEBUG(SYSTEM_DEBUG) << "constructor invoked" << std::endl;

    _not_done = true;
    SetLanguage("en@quot"); //Default language is English
}
예제 #4
0
void VideoEngine::CreateWindow(unsigned int _width, unsigned int _height, string _title)
{
  if (!window)
  {
    screen_width = _width;
    screen_height = _height;
    window = new sf::RenderWindow(sf::VideoMode(screen_width, screen_height), _title);
    window->setFramerateLimit(60);
    IF_PRINT_DEBUG(VIDEO_DEBUG) << "Window created" << endl;
  }
  else
    IF_PRINT_DEBUG(VIDEO_DEBUG) << "Window already created" << endl;

  if (!screen_fader)
    screen_fader = new private_video::Fader();
}
예제 #5
0
ScriptEngine::ScriptEngine() {
    IF_PRINT_DEBUG(SCRIPT_DEBUG) << "ScriptEngine constructor invoked." << endl;

    // Initialize Lua and LuaBind
    _global_state = lua_open();
    luaL_openlibs(_global_state);
    luabind::open(_global_state);
}
예제 #6
0
MapMode::MapMode(const string& _map_name)
  : GameMode()
  , map_name(_map_name)
  , camera(nullptr)
  , delta_x(0)
  , delta_y(0)
  , tile_supervisor(nullptr)
  , temp(nullptr)
  , enemy(nullptr)
  , read_script(nullptr)
  , active(true)
{
  IF_PRINT_DEBUG(MAP_MODE_DEBUG) << "MapMode constructor called" << endl;

  current_instance = this;

  tile_supervisor = new private_map_mode::TileSupervisor();
  object_supervisor = new private_map_mode::ObjectSupervisor();
  event_supervisor = new private_map_mode::EventSupervisor();

  // temp = new private_map_mode::MapSprite(MapObjectDrawLayer::GROUND_OBJECT);
  // if (!temp->LoadAnimations("data/entities/actor0-walking.lua"))
  // {
  //   PRINT_ERROR << "Failed to load animations for character" << endl;
  //   delete temp;
  //   temp = nullptr;
  // }
  // temp->SetCurrentAnimation("idle-south");
  // temp->SetDirection(DIRECTION_SOUTH);
  // temp->SetCenterPosition(128, 128);
  // temp->SetDimensions(32, 32);
  // // object_supervisor->RegisterObject(temp);
  // camera = temp;

  // enemy = private_map_mode::EnemySprite::Create();
  // if (!enemy->LoadAnimations("data/entities/enemy0-walking.lua"))
  // {
  //   PRINT_ERROR << "Failed to load animations for character" << endl;
  //   delete enemy;
  //   enemy = nullptr;
  // }
  // enemy->SetCurrentAnimation("idle-south");
  // enemy->SetDirection(DIRECTION_SOUTH);
  // enemy->SetCenterPosition(320, 320);
  // enemy->SetDimensions(32, 32);
  // object_supervisor->RegisterObject(enemy);

  //camera_timer.InitTimer(0, 1);

  //camera = new private_map_mode::Camera(sf::Vector2i(32, 32));

  //camera->SetCenterPosition(128, 128);

  if (!LoadMap())
    PRINT_ERROR << "Failed to load Lua tilemap: " << map_name << endl;
}
예제 #7
0
ScriptEngine::~ScriptEngine()
{
    IF_PRINT_DEBUG(SCRIPT_DEBUG) << "ScriptEngine Destruction..." << std::endl;

    for (std::pair<std::string, vt_script::ScriptDescriptor*> openedFile : _open_files)
        PRINT_WARNING << "Script file still open when quitting application: " << openedFile.first << std::endl;

    lua_close(_global_state);
    _global_state = nullptr;
}
예제 #8
0
VideoEngine::~VideoEngine()
{
  IF_PRINT_DEBUG(VIDEO_DEBUG) << "VideoEngine destructor called" << endl;

  if (window->isOpen())
    window->close();
  if (window)
    delete window;
  if (screen_fader)
    delete screen_fader;
}
예제 #9
0
VideoEngine::VideoEngine()
  : window(nullptr)
  , screen_width(0)
  , screen_height(0)
  , debug(true)
  , screen_fader(nullptr)
{
  IF_PRINT_DEBUG(VIDEO_DEBUG) << "VideoEngine constructor called" << endl;

  if (!font.loadFromFile("data/fonts/default.ttf"))
    PRINT_ERROR << "Font failed to load" << endl;
  else
    fps_text.setFont(font);
  fps_text.setPosition(5, 5);
  fps_text.setColor(sf::Color::White);
  fps_text.setCharacterSize(24);
}
예제 #10
0
SystemEngine::SystemEngine():
    _last_update(0),
    _update_time(1), // Set to 1 to avoid hanging the system.
    _hours_played(0),
    _minutes_played(0),
    _seconds_played(0),
    _milliseconds_played(0),
    _not_done(true),
    _message_speed(vt_gui::DEFAULT_MESSAGE_SPEED),
    _battle_target_cursor_memory(true),
    _game_difficulty(2), // Normal
    _game_save_slots(10) // Default slot number to handle
{
    IF_PRINT_DEBUG(SYSTEM_DEBUG) << "constructor invoked" << std::endl;

    SetLanguageLocale(DEFAULT_LOCALE);
    _current_language_locale = DEFAULT_LOCALE; // In case no files were found.
    _default_language_locale = DEFAULT_LOCALE; // In case no files were found.
}
bool TextureController::_SaveTempTextures() {
	bool success = true;

	for (map<string, ImageTexture*>::iterator i = _images.begin(); i != _images.end(); i++) {
		ImageTexture *image = i->second;

		// Check that this is a temporary texture and if so, save it to disk as a .png file
		if (image->tags.find("<T>") != string::npos) {
			IF_PRINT_DEBUG(VIDEO_DEBUG) << " saving temporary texture " << image->filename << endl;
			ImageMemory buffer;
			buffer.CopyFromImage(image);
			string path = GetUserDataPath(true);
			if (buffer.SaveImage(path + image->filename + ".png", true) == false) {
				success = false;
				IF_PRINT_WARNING(VIDEO_DEBUG) << "call to ImageMemory::SaveImage() failed" << endl;
			}
		}
	}
	return success;
}
bool TextureController::_ReloadImagesToSheet(TexSheet* sheet) {
	// Delete images
	std::map<string, pair<ImageMemory, ImageMemory> > multi_image_info;

	bool success = true;
	for (map<string, ImageTexture*>::iterator i = _images.begin(); i != _images.end(); i++) {
		// Only operate on images which belong to the requested TexSheet
		if (i->second->texture_sheet != sheet) {
			continue;
		}

		ImageTexture* img = i->second;
		ImageMemory load_info;
		bool is_multi_image = (img->tags.find("<X", 0) != img->filename.npos);

		// Multi Images require a different reloading process
		if (is_multi_image) {
			ImageMemory image;

			if (multi_image_info.find(img->filename) == multi_image_info.end()) {
				// Load the image
				if (load_info.LoadImage(img->filename) == false) {
					IF_PRINT_WARNING(VIDEO_DEBUG) << "call to _LoadRawImage() failed" << endl;
					success = false;
					continue;
				}

				// Copy the part of the image in a buffer
				image.height = img->height;
				image.width = img->width;
				image.pixels = malloc(image.height * image.width * 4);

				if (image.pixels == NULL) {
					IF_PRINT_WARNING(VIDEO_DEBUG) << "call to malloc returned NULL" << endl;
					success = false;
					continue;
				}

				multi_image_info[img->filename] = make_pair(load_info, image);
			}
			else {
				load_info = multi_image_info[img->filename].first;
				image = multi_image_info[img->filename].second;
			}

			uint16 pos0, pos1; // Used to find the start and end positions of a sub-string
			uint32 x, y; //
			uint32 rows, cols;

			pos0 = img->tags.find("<X", 0);
			pos1 = img->tags.find('_', pos0);
			x = atoi(img->tags.substr(pos0 + 2, pos1).c_str());

			pos0 = img->tags.find("<Y", 0);
			pos1 = img->tags.find('_', pos0);
			y = atoi(img->tags.substr(pos0 + 2, pos1).c_str());

			rows = load_info.height / image.height;
			cols = load_info.width / image.width;

			for (int32 row = 0; row < image.height; row++) {
				memcpy((uint8*)image.pixels + 4 * image.width * row, (uint8*)load_info.pixels + (((x * load_info.height / rows) + row)
					* load_info.width + y * load_info.width / cols) * 4, 4 * image.width);
			}

			// Convert to grayscale if needed
			if (img->tags.find("<G>", 0) != img->filename.npos)
				image.ConvertToGrayscale();

			// Copy the image into the texture sheet
			if (sheet->CopyRect(img->x, img->y, image) == false) {
				IF_PRINT_WARNING(VIDEO_DEBUG) << "call to TexSheet::CopyRect() failed" << endl;
				success = false;
			}
		} // if (is_multi_image)

		// Reload a normal image file
		else {
			std::string fname = img->filename;
			IF_PRINT_DEBUG(VIDEO_DEBUG) << " Reloading image " << fname << endl;

			// Check if it is a temporary image, and if so retrieve it from the img/temp directory
			if (img->tags.find("<T>", 0) != img->tags.npos) {
				fname = "img/temp/" + fname + ".png";
			}

			if (load_info.LoadImage(fname) == false) {
				IF_PRINT_WARNING(VIDEO_DEBUG) << "call to _LoadRawImage() failed" << endl;
				success = false;
			}

			// Convert to grayscale if needed
			if (img->tags.find("<G>", 0) != img->filename.npos)
				load_info.ConvertToGrayscale();

			if (sheet->CopyRect(img->x, img->y, load_info) == false) {
				IF_PRINT_WARNING(VIDEO_DEBUG) << "call to TexSheet::CopyRect() failed" << endl;
				success = false;
			}

			if (load_info.pixels) {
				free(load_info.pixels);
				load_info.pixels = NULL;
			}
		}
	} // for (map<string, ImageTexture*>::iterator i = _images.begin(); i != _images.end(); i++)

	for (map<string, pair<ImageMemory, ImageMemory> >::iterator i = multi_image_info.begin(); i != multi_image_info.end(); ++i) {
		free(i->second.first.pixels);
		i->second.first.pixels = NULL;
		free(i->second.second.pixels);
		i->second.second.pixels = NULL;
	}

	// Regenerate all font textures
	for (set<TextTexture*>::iterator i = _text_images.begin(); i != _text_images.end(); i++) {
		if ((*i)->texture_sheet == sheet) {
			if ((*i)->Reload() == false) {
				IF_PRINT_WARNING(VIDEO_DEBUG) << "failed to reload a TextTexture" << endl;
				success = false;
			}
		}
	}

	return success;
} // bool TextureController::_ReloadImagesToSheet(TexSheet* sheet)
예제 #13
0
BootMode::BootMode() :
    _boot_state(BOOT_STATE_INTRO),
    _exiting_to_new_game(false),
    _has_modified_settings(false),
    _first_run(false),
    _key_setting_function(NULL),
    _joy_setting_function(NULL),
    _joy_axis_setting_function(NULL),
    _message_window(ustring(), 210.0f, 733.0f),
    _menu_bar_alpha(0.0f),
    _help_text_alpha(0.0f)
{
    // Remove potential previous ambient overlays
    VideoManager->DisableFadeEffect();

    IF_PRINT_DEBUG(BOOT_DEBUG) << "BootMode constructor invoked" << std::endl;
    mode_type = MODE_MANAGER_BOOT_MODE;

    // Note: Not translated on purpose.
    _version_text.SetStyle(TextStyle("text18"));
    std::string version_string = "Development Release - ";
    version_string.append(__DATE__);
    _version_text.SetText(MakeUnicodeString(version_string));

    // Get rid of the old table to make sure no old data is used.
    ScriptManager->DropGlobalTable("boot");

    // Test the existence and validity of the boot script.
    ReadScriptDescriptor boot_script;
    if(!boot_script.OpenFile("dat/config/boot.lua")) {
        PRINT_ERROR << "Failed to load boot data file" << std::endl;
        SystemManager->ExitGame();
        return;
    }

    // Open the boot table spacename
    if(boot_script.OpenTablespace().empty()) {
        PRINT_ERROR << "The boot script file has not set a correct tablespace" << std::endl;
        SystemManager->ExitGame();
        return;
    }
    boot_script.CloseTable(); // The namespace
    boot_script.CloseFile();

    // Trigger the Initialize functions in the scene script component
    GetScriptSupervisor().AddScript("dat/config/boot.lua");
    GetScriptSupervisor().Initialize(this);

    _options_window.Create(300.0f, 550.0f);
    _options_window.SetPosition(360.0f, 188.0f);
    _options_window.SetDisplayMode(VIDEO_MENU_INSTANT);
    _options_window.Hide();

    // Setup all boot menu options and properties
    _SetupMainMenu();
    _SetupOptionsMenu();
    _SetupVideoOptionsMenu();
    _SetupAudioOptionsMenu();
    _SetupLanguageOptionsMenu();
    _SetupKeySettingsMenu();
    _SetupJoySettingsMenu();
    _SetupResolutionMenu();
    _active_menu = &_main_menu;

    // make sure message window is not visible
    _message_window.Hide();

    // Load the menu bar and the help text
    _menu_bar.Load("img/menus/battle_bottom_menu.png", 1024, 128);

    _f1_help_text.SetStyle(TextStyle("text18"));

    // The timer that will be used to display the menu bar and the help text
    _boot_timer.Initialize(14000);
    _boot_timer.EnableManualUpdate();
    _boot_timer.Run();

    // Preload test sound
    AudioManager->LoadSound("snd/volume_test.wav", this);
    // Preload main sounds
    AudioManager->LoadSound("snd/confirm.wav", this);
    AudioManager->LoadSound("snd/cancel.wav", this);
    AudioManager->LoadSound("snd/bump.wav", this);
    AudioManager->LoadSound("snd/new_game.wav", this);
} // BootMode::BootMode()
예제 #14
0
bool TextureController::_ReloadImagesToSheet(TexSheet *sheet)
{
    // Delete images
    std::map<std::string, std::pair<ImageMemory, ImageMemory> > multi_image_info;

    bool success = true;
    for(std::map<std::string, ImageTexture *>::iterator i = _images.begin(); i != _images.end(); ++i) {
        // Only operate on images which belong to the requested TexSheet
        if(i->second->texture_sheet != sheet) {
            continue;
        }

        ImageTexture *img = i->second;
        ImageMemory load_info;
        bool is_multi_image = (img->tags.find("<X", 0) != img->filename.npos);

        // Multi Images require a different reloading process
        if(is_multi_image) {
            ImageMemory image;

            if(multi_image_info.find(img->filename) == multi_image_info.end()) {
                // Load the image
                if(load_info.LoadImage(img->filename) == false) {
                    IF_PRINT_WARNING(VIDEO_DEBUG) << "call to _LoadRawImage() failed" << std::endl;
                    success = false;
                    continue;
                }

                // Copy the part of the image in a buffer
                try {
                    image.Resize(img->width, img->height, false);
                }
                catch( std::exception &e ) {
                    IF_PRINT_WARNING(VIDEO_DEBUG) << "Resize failed." << std::endl;
                    success = false;
                    continue;
                }

                multi_image_info[img->filename] = std::make_pair(load_info, image);
            } else {
                load_info = multi_image_info[img->filename].first;
                image = multi_image_info[img->filename].second;
            }

            uint16_t pos0, pos1; // Used to find the start and end positions of a sub-string
            uint32_t x, y; //
            uint32_t rows, cols;

            pos0 = img->tags.find("<X", 0);
            pos1 = img->tags.find('_', pos0);
            x = std::stoi(img->tags.substr(pos0 + 2, pos1));

            pos0 = img->tags.find("<Y", 0);
            pos1 = img->tags.find('_', pos0);
            y = std::stoi(img->tags.substr(pos0 + 2, pos1));

            rows = load_info.GetHeight() / image.GetHeight();
            cols = load_info.GetWidth() / image.GetWidth();

            image.CopyFrom(load_info,
                           load_info.GetWidth() * (x * load_info.GetHeight() / rows)
                               + load_info.GetWidth() * y / cols);

            // Convert to grayscale if needed
            if(img->tags.find("<G>", 0) != img->filename.npos)
                image.ConvertToGrayscale();

            // Copy the image into the texture sheet
            if(sheet->CopyRect(img->x, img->y, image) == false) {
                IF_PRINT_WARNING(VIDEO_DEBUG) << "call to TexSheet::CopyRect() failed" << std::endl;
                success = false;
            }
        } // if (is_multi_image)

        // Reload a normal image file
        else {
            std::string fname = img->filename;

            IF_PRINT_DEBUG(VIDEO_DEBUG) << " Reloading image " << fname << std::endl;

            if(load_info.LoadImage(fname) == false) {
                IF_PRINT_WARNING(VIDEO_DEBUG) << "call to _LoadRawImage() failed" << std::endl;
                success = false;
            }

            // Convert to grayscale if needed
            if(img->tags.find("<G>", 0) != img->filename.npos)
                load_info.ConvertToGrayscale();

            if(sheet->CopyRect(img->x, img->y, load_info) == false) {
                IF_PRINT_WARNING(VIDEO_DEBUG) << "call to TexSheet::CopyRect() failed" << std::endl;
                success = false;
            }
        }
    } // for (std::map<string, ImageTexture*>::iterator i = _images.begin(); i != _images.end(); i++)

    // Regenerate all font textures
    for(std::set<TextTexture *>::iterator i = _text_images.begin(); i != _text_images.end(); ++i) {
        if((*i)->texture_sheet == sheet) {
            if((*i)->Reload() == false) {
                IF_PRINT_WARNING(VIDEO_DEBUG) << "failed to reload a TextTexture" << std::endl;
                success = false;
            }
        }
    }

    return success;
} // bool TextureController::_ReloadImagesToSheet(TexSheet* sheet)
예제 #15
0
bool MapMode::LoadMap()
{
  std::string script_name = "data/maps/" + map_name + "-map.lua";

  if (!read_script)
    read_script = new rpg_script::ReadScript();

  if (read_script->IsOpen())
    read_script->CloseFile();

  if (!read_script->OpenFile(script_name))
  {
    PRINT_ERROR << "Failed to open tilemap script: " << script_name << endl;
    return false;
  }

  // cout << "---------- Tilemap Information ----------" << endl;
  // cout << "| File: " << _lua_filepath << endl;

  read_script->OpenTable("map_data");

  string script_path = read_script->ReadData<string>("script_path", "");

  int map_width = read_script->ReadData<int>("num_cols", -1);
  int map_height = read_script->ReadData<int>("num_rows", -1);
  if (map_width < 0 || map_height < 0)
  {
    PRINT_ERROR << "Invalid map dimensions in map script." << endl;
    return false;
  }

  // string name = read_script->ReadData<string>("name", "");
  // cout << "| Name: " << name << endl;
  // cout << "|" << endl;
  //
  // cout << "| Dimensions: " << map_width << " x " << map_height << endl;
  // cout << "|\n---------- Tileset Information ----------" << endl;

  if (!tile_supervisor)
    tile_supervisor = new private_map_mode::TileSupervisor();

  read_script->OpenTable("tilesets");
  int num_tilesets = read_script->ReadData<int>("count", -1);

  // cout << "| Tileset Count: " << num_tilesets << endl;

  if (num_tilesets < 0)
  {
    PRINT_ERROR << "No tilesets found in map script." << endl;
    return false;
  }

  for (int i = 0; i < num_tilesets; ++i)
  {
    string path = read_script->ReadData<string>(i, "");
    // cout << "| " << i << ". " << path << endl;
    if (path.empty() || !LoadTileset(path))
    {
      PRINT_ERROR << "Failed to load tileset" << endl;
      return false;
    }
  }
  read_script->CloseTable();

  // cout << "|\n----------- Layer Information -----------" << endl;

  // Load in the layer data
  read_script->OpenTable("layers");
  int num_layers = read_script->ReadData<int>("num_layers", -1);

  // cout << "| Layer Count: " << num_layers << endl;
  if (num_layers < 0)
  {
    PRINT_ERROR << "No layers found in map script." << endl;
    return false;
  }

  if (read_script->HasError())
  {
    read_script->PrintErrors();
    return false;
  }

  for (int l = 0; l < num_layers; ++l)
  {
    read_script->OpenTableIntegers(l);

    MapLayerType type;
    string str_type = read_script->ReadData<string>("type", "");

    if (str_type == "ground")
      type = MapLayerType::GROUND;
    else if (str_type == "wall")
      type = MapLayerType::WALL;
    else if (str_type == "sky")
      type = MapLayerType::SKY;
    else
    {
      PRINT_WARNING << "Unknown type for layer" << endl;
      continue;
    }

    // cout << "| " << l << ". " << str_type << endl;

    private_map_mode::MapLayer layer(type);
    for (int row = 0; row < map_height; ++row)
    {
      read_script->OpenTableIntegers(row + 1);
      // cout << "|\t";
      vector<int> temp;
      for (int col = 0; col < map_width; ++col)
      {
        int id = read_script->ReadData<int>(col + 1, -1);
        // cout << setw(3) << id << " ";
        temp.push_back(id);
      }
      // cout << endl;
      layer.tiles.push_back(temp);
      read_script->CloseTable();
    }

    tile_supervisor->layers.push_back(layer);

    read_script->CloseTable();
  }
  read_script->CloseTable();

  // cout << "|\n--------- Collision Information ---------" << endl;
  // Load object data
  if (!object_supervisor)
    object_supervisor = new private_map_mode::ObjectSupervisor();

  // cout << "| " << "Static Collision Matrix" << endl;

  read_script->OpenTable("collision");

  if (read_script->HasError())
  {
    read_script->PrintErrors();
    return false;
  }

  for (int i = 0; i < map_height; ++i)
  {
    read_script->OpenTableIntegers(i + 1);
    // cout << "|\t";
    vector<int> temp;
    for (int j = 0; j < map_width; ++j)
    {
      int value = read_script->ReadData<int>(j + 1, -1);
      // cout << setw(2) << value << " ";
      temp.push_back(value);
    }
    object_supervisor->collision_grid.push_back(temp);
    // cout << endl;
    read_script->CloseTable();
  }

  if (read_script->HasError())
  {
      read_script->PrintErrors();
      return false;
  }

  read_script->CloseTable();
  read_script->CloseFile();

  // cout << "-----------------------------------------" << endl;

  if (script_path.empty())
    return false;

  if (!read_script->OpenFile(script_path))
  {
    PRINT_ERROR << "Failed to open tilemap script: " << script_path << endl;
    return false;
  }

  IF_PRINT_DEBUG(MAP_MODE_DEBUG) << "Loading tilemap functionality script" << endl;

  read_script->CallFunction("Load");
  if (read_script->HasError())
  {
      read_script->PrintErrors();
      return false;
  }

  // read_script->CloseFile();

  return true;
}
예제 #16
0
SystemEngine::~SystemEngine()
{
    IF_PRINT_DEBUG(SYSTEM_DEBUG) << "destructor invoked" << std::endl;
}