Finished rewrite of actor animation system
* Rewrote the actor animation system to work like sprites * Renamed a few functions * Added DeleteSpriteAnimation() and the delete queue to sprites * Removed transitions for the time being (they don't seem to work in irrlicht right now * Added PreUpdate() function * Added documentation for name changes and new functions
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2998,6 +2998,28 @@ int rc_canvasClip(int x, int y, int w, int h)
|
||||
|
||||
|
||||
|
||||
void rc_preUpdate()
|
||||
{
|
||||
//3D World Update
|
||||
rc_physics3D.DeltaTime = device->getTimer()->getTime() - rc_physics3D.TimeStamp;
|
||||
rc_physics3D.TimeStamp = device->getTimer()->getTime();
|
||||
rc_physics3D.world->stepSimulation(rc_physics3D.DeltaTime*0.001f, rc_physics3D.maxSubSteps, rc_physics3D.fixedTimeStep);
|
||||
|
||||
for(int i = 0; i < rc_canvas.size(); i++)
|
||||
{
|
||||
if(rc_canvas[i].type != RC_CANVAS_TYPE_SPRITE)
|
||||
continue;
|
||||
|
||||
float step = rc_canvas[i].physics2D.timeStep;
|
||||
int32 velocityIterations = rc_canvas[i].physics2D.velocityIterations;
|
||||
int32 positionIterations = rc_canvas[i].physics2D.positionIterations;
|
||||
|
||||
if(rc_canvas[i].physics2D.enabled)
|
||||
rc_canvas[i].physics2D.world->Step(step, velocityIterations, positionIterations);
|
||||
}
|
||||
|
||||
hasPreUpdated = true;
|
||||
}
|
||||
|
||||
bool rc_update()
|
||||
{
|
||||
@@ -3353,26 +3375,29 @@ bool rc_update()
|
||||
|
||||
for(int i = 0; i < rc_transition_actor.size();)
|
||||
{
|
||||
if((frame_current_time - rc_actor[i].transition_start_time) >= rc_actor[i].transition_time)
|
||||
int t_actor = rc_transition_actor[i];
|
||||
|
||||
if((frame_current_time - rc_actor[t_actor].transition_start_time) >= rc_actor[t_actor].transition_time)
|
||||
{
|
||||
irr::scene::IAnimatedMeshSceneNode* node = (irr::scene::IAnimatedMeshSceneNode*)rc_actor[i].mesh_node;
|
||||
irr::scene::IAnimatedMeshSceneNode* node = (irr::scene::IAnimatedMeshSceneNode*)rc_actor[t_actor].mesh_node;
|
||||
node->setTransitionTime(0);
|
||||
node->setJointMode(irr::scene::EJUOR_NONE);
|
||||
rc_actor[i].transition = false;
|
||||
rc_actor[i].transition_time = 0;
|
||||
rc_actor[i].transition_start_time = 0;
|
||||
rc_transition_actor.erase(i);
|
||||
rc_actor[t_actor].transition = false;
|
||||
rc_actor[t_actor].transition_time = 0;
|
||||
rc_actor[t_actor].transition_start_time = 0;
|
||||
rc_transition_actor.erase(t_actor);
|
||||
|
||||
rc_actor[i].animation[0].start_frame = (int)rc_actor[i].transition_frame;
|
||||
rc_actor[i].animation[0].end_frame = (int)rc_actor[i].transition_frame;
|
||||
rc_actor[i].animation[0].fps = 0;
|
||||
rc_actor[i].current_animation_loop = 0;
|
||||
rc_actor[i].isPlaying = true;
|
||||
rc_actor[i].current_animation = 0;
|
||||
rc_actor[t_actor].animation[0].start_frame = (int)rc_actor[t_actor].transition_frame;
|
||||
rc_actor[t_actor].animation[0].end_frame = (int)rc_actor[t_actor].transition_frame;
|
||||
rc_actor[t_actor].animation[0].fps = 0;
|
||||
rc_actor[t_actor].current_animation_loop = 0;
|
||||
rc_actor[t_actor].isPlaying = true;
|
||||
rc_actor[t_actor].current_animation = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
irr::scene::IAnimatedMeshSceneNode* node = (irr::scene::IAnimatedMeshSceneNode*)rc_actor[i].mesh_node;
|
||||
//std::cout << "Animate dammit" << std::endl;
|
||||
irr::scene::IAnimatedMeshSceneNode* node = (irr::scene::IAnimatedMeshSceneNode*)rc_actor[t_actor].mesh_node;
|
||||
node->animateJoints();
|
||||
i++;
|
||||
}
|
||||
@@ -3381,9 +3406,12 @@ bool rc_update()
|
||||
|
||||
VideoDriver->beginScene(true, true);
|
||||
|
||||
rc_physics3D.DeltaTime = device->getTimer()->getTime() - rc_physics3D.TimeStamp;
|
||||
rc_physics3D.TimeStamp = device->getTimer()->getTime();
|
||||
rc_physics3D.world->stepSimulation(rc_physics3D.DeltaTime*0.001f, rc_physics3D.maxSubSteps, rc_physics3D.fixedTimeStep);
|
||||
if(!hasPreUpdated)
|
||||
{
|
||||
rc_physics3D.DeltaTime = device->getTimer()->getTime() - rc_physics3D.TimeStamp;
|
||||
rc_physics3D.TimeStamp = device->getTimer()->getTime();
|
||||
rc_physics3D.world->stepSimulation(rc_physics3D.DeltaTime*0.001f, rc_physics3D.maxSubSteps, rc_physics3D.fixedTimeStep);
|
||||
}
|
||||
|
||||
for(int i = 0; i < rc_canvas.size(); i++)
|
||||
{
|
||||
@@ -3454,6 +3482,8 @@ bool rc_update()
|
||||
rc_setActiveCanvas(rc_active_canvas);
|
||||
}
|
||||
|
||||
hasPreUpdated = false; //Will be set to true if PreUpdate() is called
|
||||
|
||||
#ifdef RC_WEB
|
||||
emscripten_sleep(0);
|
||||
#else
|
||||
|
||||
@@ -562,7 +562,7 @@ bool rc_getActorCollision(int actor1, int actor2)
|
||||
|
||||
|
||||
//add mesh actor to scene
|
||||
int rc_createMeshActor(int mesh_id)
|
||||
int rc_createAnimatedActor(int mesh_id)
|
||||
{
|
||||
if(mesh_id < 0 || mesh_id >= rc_mesh.size())
|
||||
return -1;
|
||||
@@ -617,6 +617,7 @@ int rc_createMeshActor(int mesh_id)
|
||||
anim_callback->OnAnimationEnd(node);
|
||||
node->setAnimationEndCallback(anim_callback);
|
||||
node->setLoopMode(false);
|
||||
node->setFrameLoop(0, 0);
|
||||
anim_callback->drop();
|
||||
|
||||
|
||||
@@ -632,7 +633,7 @@ int rc_createMeshActor(int mesh_id)
|
||||
|
||||
|
||||
//add mesh actor to scene
|
||||
int rc_createMeshOctreeActor(int mesh_id)
|
||||
int rc_createOctreeActor(int mesh_id)
|
||||
{
|
||||
if(mesh_id < 0 || mesh_id >= rc_mesh.size())
|
||||
return -1;
|
||||
@@ -5156,7 +5157,7 @@ int rc_getActorAnimationEndFrame(int actor, int animation)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rc_getActorCurrentFrame(int actor)
|
||||
int rc_getActorFrame(int actor)
|
||||
{
|
||||
if(actor < 0 || actor >= rc_actor.size())
|
||||
return 0;
|
||||
@@ -5261,7 +5262,7 @@ void rc_startActorTransition(int actor, double frame, double transition_time)
|
||||
case RC_NODE_TYPE_MESH:
|
||||
irr::scene::IAnimatedMeshSceneNode* node = (irr::scene::IAnimatedMeshSceneNode*)rc_actor[actor].mesh_node;
|
||||
node->setTransitionTime(transition_time);
|
||||
node->setJointMode(irr::scene::EJUOR_CONTROL);
|
||||
//node->setJointMode(irr::scene::EJUOR_CONTROL); //This is actually called in setTransitionTime()
|
||||
node->setCurrentFrame(frame);
|
||||
rc_actor[actor].transition_frame = frame;
|
||||
rc_actor[actor].transition = true;
|
||||
@@ -6863,7 +6864,7 @@ double rc_getCameraNearValue()
|
||||
return rc_canvas[rc_active_canvas].camera.camera->getNearValue();
|
||||
}
|
||||
|
||||
void rc_setCameraProjectionMatrix(int proj_matrix, int proj_type)
|
||||
void rc_setProjectionMatrix(int proj_matrix, int proj_type)
|
||||
{
|
||||
if(!(rc_active_canvas > 0 && rc_active_canvas < rc_canvas.size()))
|
||||
return;
|
||||
@@ -6879,7 +6880,7 @@ void rc_setCameraProjectionMatrix(int proj_matrix, int proj_type)
|
||||
rc_canvas[rc_active_canvas].camera.camera->setProjectionMatrix(irr_mat, isOrtho);
|
||||
}
|
||||
|
||||
void rc_getCameraProjectionMatrix(int proj_matrix)
|
||||
void rc_getProjectionMatrix(int proj_matrix)
|
||||
{
|
||||
if(!(rc_active_canvas > 0 && rc_active_canvas < rc_canvas.size()))
|
||||
return;
|
||||
|
||||
@@ -355,6 +355,7 @@ struct rc_canvas_obj
|
||||
irr::core::array<rc_canvas_obj> rc_canvas;
|
||||
irr::core::array<u32> rc_canvas_zOrder;
|
||||
int rc_active_canvas = -1;
|
||||
bool hasPreUpdated = false;
|
||||
|
||||
irr::video::SColor rc_active_color(0,0,0,0);
|
||||
irr::video::SColor rc_clear_color(0,0,0,0);
|
||||
@@ -568,6 +569,7 @@ class rc_animEndCallBack : public IAnimationEndCallBack
|
||||
{
|
||||
if(ref_actor->current_animation_loop < ref_actor->num_animation_loops || ref_actor->num_animation_loops < 0)
|
||||
{
|
||||
//std::cout << "animating" << std::endl;
|
||||
irr::scene::IAnimatedMeshSceneNode* node = (irr::scene::IAnimatedMeshSceneNode*) ref_actor->mesh_node;
|
||||
int animation = ref_actor->current_animation;
|
||||
if(animation < 0 || animation >= ref_actor->animation.size())
|
||||
|
||||
@@ -51,6 +51,7 @@ struct rc_sprite2D_obj
|
||||
int num_animation_loops;
|
||||
int current_animation_loop;
|
||||
bool isPlaying;
|
||||
irr::core::array<int> deleted_sprites;
|
||||
irr::core::array<rc_sprite2D_animation_obj> animation;
|
||||
|
||||
int parent_canvas = -1;
|
||||
|
||||
@@ -32,11 +32,29 @@ int rc_createSpriteAnimation(int spr_id, int anim_length, double fps)
|
||||
animation.frames.push_back(0);
|
||||
|
||||
int animation_id = rc_sprite[spr_id].animation.size();
|
||||
rc_sprite[spr_id].animation.push_back(animation);
|
||||
if(rc_sprite[spr_id].deleted_sprites.size() > 0)
|
||||
{
|
||||
animation_id = rc_sprite[spr_id].deleted_sprites[0];
|
||||
rc_sprite[spr_id].deleted_sprites.erase(0);
|
||||
rc_sprite[spr_id].animation[animation_id] = animation;
|
||||
}
|
||||
else
|
||||
rc_sprite[spr_id].animation.push_back(animation);
|
||||
|
||||
return animation_id;
|
||||
}
|
||||
|
||||
void rc_deleteSpriteAnimation(int spr_id, int animation)
|
||||
{
|
||||
if(spr_id < 0 || spr_id >= rc_sprite.size())
|
||||
return;
|
||||
|
||||
if(!rc_sprite[spr_id].active)
|
||||
return;
|
||||
|
||||
rc_sprite[spr_id].deleted_sprites.push_back(animation);
|
||||
}
|
||||
|
||||
void rc_setSpriteFrame(int spr_id, int frame)
|
||||
{
|
||||
if(spr_id < 0 || spr_id >= rc_sprite.size())
|
||||
@@ -587,7 +605,7 @@ void rc_setSpriteScale(int spr_id, double x, double y)
|
||||
|
||||
rc_sprite[spr_id].scale.set(x, y);
|
||||
|
||||
if(rc_sprite[spr_id].isSolid)
|
||||
if(true) //(rc_sprite[spr_id].isSolid) //I probably originally planned on not having a fixture for non-solid sprites but then I discovered sensors
|
||||
{
|
||||
if(rc_sprite[spr_id].physics.fixture)
|
||||
{
|
||||
@@ -662,6 +680,19 @@ void rc_scaleSprite(int spr_id, double x, double y)
|
||||
rc_setSpriteScale(spr_id, scale_x, scale_y);
|
||||
}
|
||||
|
||||
|
||||
void rc_getSpriteScale(int spr_id, double* x, double* y)
|
||||
{
|
||||
if(spr_id < 0 || spr_id >= rc_sprite.size())
|
||||
return;
|
||||
|
||||
if(!rc_sprite[spr_id].active)
|
||||
return;
|
||||
|
||||
*x = rc_sprite[spr_id].scale.X;
|
||||
*y = rc_sprite[spr_id].scale.Y;
|
||||
}
|
||||
|
||||
double rc_spriteWidth(int spr_id)
|
||||
{
|
||||
if(spr_id < 0 || spr_id >= rc_sprite.size())
|
||||
@@ -760,7 +791,7 @@ void drawSprites(int canvas_id)
|
||||
int32 velocityIterations = rc_canvas[canvas_id].physics2D.velocityIterations;
|
||||
int32 positionIterations = rc_canvas[canvas_id].physics2D.positionIterations;
|
||||
|
||||
if(rc_canvas[canvas_id].physics2D.enabled)
|
||||
if(rc_canvas[canvas_id].physics2D.enabled && (!hasPreUpdated))
|
||||
rc_canvas[canvas_id].physics2D.world->Step(step, velocityIterations, positionIterations);
|
||||
|
||||
//Setting the render target to the current canvas. NOTE: I might change this target to a separate sprite layer later.
|
||||
|
||||
Reference in New Issue
Block a user