Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Turned the ReloadSprite() function back to a c++ one.

Linked to #112:
As shirish reported having 'virtual function called' based segfault,
and as the bug happens within the function that reload the sprite,
I've suspected the map sprite reference badly taken has a map object
one, or something similar.

If it's not the case, at least this will be a cause less to see that
bug, or it will throw the error from within a c++ function, which
is more talkative with gdb.

A more general global variable hunt is also to be made also to
possibly get rid of that bug as well as the others.
  • Loading branch information...
commit 410391c2d706f8b231155504a2fee48fa74302ab 1 parent 183ff6f
Yohann Ferreira authored
View
35 dat/actors/map_sprites.lua
@@ -452,41 +452,6 @@ function CreateSprite(Map, name, x, y)
return sprite;
end
--- Used to reload (or change) the graphic animations of an existing sprite.
-function ReloadSprite(sprite_ref, name)
- if (sprites[name] == nil) then
- print("Error: No object named: "..name.." found!!");
- return;
- end
-
- if (sprite_ref == nil) then
- print("Error: Function called with invalid sprite object");
- return;
- end
-
- sprite_ref:SetName(sprites[name].name);
- sprite_ref:SetSpriteName(name); -- The catalog reference
- sprite_ref:SetCollHalfWidth(sprites[name].coll_half_width);
- sprite_ref:SetCollHeight(sprites[name].coll_height);
- sprite_ref:SetImgHalfWidth(sprites[name].img_half_width);
- sprite_ref:SetImgHeight(sprites[name].img_height);
- if (sprites[name].face_portrait) then
- sprite_ref:LoadFacePortrait(sprites[name].face_portrait);
- end
-
- sprite_ref:ClearAnimations();
- sprite_ref:LoadStandingAnimations(sprites[name].standard_animations.idle);
- sprite_ref:LoadWalkingAnimations(sprites[name].standard_animations.walk);
- if (sprites[name].standard_animations.run ~= nil) then
- sprite_ref:LoadRunningAnimations(sprites[name].standard_animations.run);
- end
- -- Load custom animations
- if (sprites[name].custom_animations ~= nil) then
- for name,file in pairs(sprites[name].custom_animations) do
- sprite_ref:LoadCustomAnimation(name, file);
- end
- end
-end
-- Permit to setup a custom name
-- and reuse the npcs sprites more easily
View
4 dat/maps/layna_forest/layna_forest_cave1_1.lua
@@ -945,7 +945,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -963,7 +963,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
-- Set event as done
GlobalManager:SetEventValue("story", "kalya_speech_at_cave_entrance_done", 1);
View
4 dat/maps/layna_forest/layna_forest_cave1_2.lua
@@ -781,7 +781,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -812,7 +812,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
-- Set event as done
GlobalManager:SetEventValue("story", "kalya_stone_sign_dialogue_done", 1);
View
4 dat/maps/layna_forest/layna_forest_crystal.lua
@@ -1029,7 +1029,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
kalya_sprite:SetVisible(true);
@@ -1101,7 +1101,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
-- Set event as done
--GlobalManager:SetEventValue("story", "layna_forest_crystal_event_done", 1);
View
4 dat/maps/layna_forest/layna_forest_entrance.lua
@@ -793,7 +793,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -831,7 +831,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
-- Set event as done
GlobalManager:SetEventValue("story", "kalya_save_points_n_spring_speech_done", 1);
View
4 dat/maps/layna_forest/layna_forest_north_west.lua
@@ -1447,7 +1447,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -1468,7 +1468,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
AudioManager:FadeInAllMusic(1000);
View
4 dat/maps/layna_forest/layna_forest_south_west.lua
@@ -1077,7 +1077,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -1112,7 +1112,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
-- Set event as done
GlobalManager:SetEventValue("story", "kalya_speech_about_snakes_done", 1);
View
8 dat/maps/layna_forest/layna_forest_wolf_cave.lua
@@ -645,7 +645,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -664,7 +664,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
hero:SetDirection(hoa_map.MapMode.NORTH);
-- Set event as done
@@ -679,7 +679,7 @@ map_functions = {
main_sprite_name = hero:GetSpriteName();
-- Make the hero be Bronann for the event.
- ReloadSprite(hero, "Bronann");
+ hero:ReloadSprite("Bronann");
kalya_sprite:SetVisible(true);
kalya_sprite:SetPosition(hero:GetXPosition(), hero:GetYPosition());
@@ -719,7 +719,7 @@ map_functions = {
kalya_sprite:SetCollisionMask(hoa_map.MapMode.NO_COLLISION);
-- Reload the hero back to default
- ReloadSprite(hero, main_sprite_name);
+ hero:ReloadSprite(main_sprite_name);
hero:SetDirection(hoa_map.MapMode.NORTH);
Map:PopState();
View
3  src/common/global/global.cpp
@@ -198,7 +198,8 @@ bool GameGlobal::_LoadGlobalScripts()
}
_status_effects_script.OpenTable("status_effects");
- if(!_map_sprites_script.OpenFile("dat/actors/map_sprites.lua"))
+ if(!_map_sprites_script.OpenFile("dat/actors/map_sprites.lua")
+ || !_map_sprites_script.OpenTable("sprites"))
return false;
if(!_map_objects_script.OpenFile("dat/actors/map_objects.lua"))
View
22 src/modes/map/map_objects.cpp
@@ -1467,26 +1467,10 @@ void ObjectSupervisor::ReloadVisiblePartyMember()
// Get the front party member
GlobalActor *actor = GlobalManager->GetActiveParty()->GetActorAtIndex(0);
- // Update only if the actor has changed
- if(actor && actor->GetMapSpriteName() != _visible_party_member->GetSpriteName()) {
- hoa_script::ReadScriptDescriptor &script = GlobalManager->GetMapSpriteScript();
-
- ScriptObject function_ptr = script.ReadFunctionPointer("ReloadSprite");
-
- if(!function_ptr.is_valid()) {
- PRINT_WARNING << "Invalid 'ReloadSprite' function in the map sprite script file."
- << std::endl;
- return;
- }
- try {
- ScriptCallFunction<void>(function_ptr, _visible_party_member, actor->GetMapSpriteName());
- } catch(const luabind::error &e) {
- PRINT_ERROR << "Error while loading script function." << std::endl;
- ScriptManager->HandleLuaError(e);
- return;
- }
- }
+ // Update only if the actor has changed
+ if(actor && actor->GetMapSpriteName() != _visible_party_member->GetSpriteName())
+ _visible_party_member->ReloadSprite(actor->GetMapSpriteName());
}
void ObjectSupervisor::SetAllEnemyStatesToDead()
View
60 src/modes/map/map_sprites.cpp
@@ -20,6 +20,7 @@
#include "modes/map/map_events.h"
#include "modes/battle/battle.h"
+#include "common/global/global.h"
using namespace hoa_utils;
using namespace hoa_audio;
@@ -792,6 +793,65 @@ void MapSprite::SetCustomAnimation(const std::string &animation_name, uint32 tim
_custom_animation_on = true;
}
+void MapSprite::ReloadSprite(const std::string& sprite_name)
+{
+ // Don't reload if it's already the same map sprite
+ if (sprite_name == GetSpriteName())
+ return;
+
+ hoa_script::ReadScriptDescriptor& script = GlobalManager->GetMapSpriteScript();
+
+ if (!script.IsFileOpen())
+ return;
+
+ if (!script.OpenTable(sprite_name)) {
+ PRINT_WARNING << "No map sprite name: " << sprite_name << " found!!"
+ << std::endl;
+ return;
+ }
+
+ SetName(script.ReadString("name"));
+ SetSpriteName(sprite_name);
+ SetCollHalfWidth(script.ReadFloat("coll_half_width"));
+ SetCollHeight(script.ReadFloat("coll_height"));
+ SetImgHalfWidth(script.ReadFloat("img_half_width"));
+ SetImgHeight(script.ReadFloat("img_height"));
+ if (script.DoesStringExist("face_portrait"))
+ LoadFacePortrait(script.ReadString("face_portrait"));
+
+ if (!script.OpenTable("standard_animations")) {
+ PRINT_WARNING << "No 'standard_animations' table in: "
+ << sprite_name << std::endl;
+ script.CloseTable(); // sprite_name
+ return;
+ }
+
+ ClearAnimations();
+ LoadStandingAnimations(script.ReadString("idle"));
+ LoadWalkingAnimations(script.ReadString("walk"));
+ if (script.DoesStringExist("run"))
+ LoadRunningAnimations(script.ReadString("run"));
+
+ script.CloseTable(); // standard_animations
+
+ // Load potential custom animations
+ if (!script.DoesTableExist("custom_animations")) {
+ script.CloseTable(); // sprite_name
+ return;
+ }
+
+ std::vector<std::string> anim_names;
+ script.ReadTableKeys("custom_animations", anim_names);
+ script.OpenTable("custom_animations");
+
+ for (uint32 i = 0; i < anim_names.size(); ++i)
+ LoadCustomAnimation(anim_names[i], script.ReadString(anim_names[i]));
+
+ // Put the tabl in the state we found it.
+ script.CloseTable(); // custom_animations
+ script.CloseTable(); // sprite_name
+}
+
void MapSprite::LoadFacePortrait(const std::string &filename)
{
if(_face_portrait)
View
7 src/modes/map/map_sprites.h
@@ -402,6 +402,13 @@ class MapSprite : public VirtualSprite
const std::string &GetSpriteName() const {
return _sprite_name;
}
+
+ /** \brief Used to reload (or change) the graphic animations
+ *** of an existing sprite.
+ *** \param sprite_name The sprite name entry found in the map_sprites.lua
+ *** sprite table.
+ **/
+ void ReloadSprite(const std::string& sprite_name);
//@}
protected:
View
2  src/modes/mode_bindings.cpp
@@ -292,6 +292,7 @@ void BindModeCode()
luabind::class_<MapSprite, VirtualSprite>("MapSprite")
.def(luabind::constructor<>())
.def("SetName", (void(MapSprite:: *)(const std::string &))&MapSprite::SetName)
+ .def("SetName", (void(MapSprite:: *)(const hoa_utils::ustring &))&MapSprite::SetName)
.def("SetCurrentAnimationDirection", &MapSprite::SetCurrentAnimationDirection)
.def("GetCurrentAnimationDirection", &MapSprite::GetCurrentAnimationDirection)
.def("LoadFacePortrait", &MapSprite::LoadFacePortrait)
@@ -307,6 +308,7 @@ void BindModeCode()
.def("RemoveDialogueReference", (void(MapSprite:: *)(SpriteDialogue *))&MapSprite::RemoveDialogueReference)
.def("SetSpriteName", &MapSprite::SetSpriteName)
.def("GetSpriteName", &MapSprite::GetSpriteName)
+ .def("ReloadSprite", &MapSprite::ReloadSprite)
];
luabind::module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
Please sign in to comment.
Something went wrong with that request. Please try again.