diff options
| -rw-r--r-- | AnimationRender/AnimationRender.c | 4 | ||||
| -rw-r--r-- | AnimationRender/F_Draw.c | 5 | ||||
| -rw-r--r-- | AnimationRender/F_Draw.h | 2 | ||||
| -rw-r--r-- | AnimationRender/F_FrameRange.c | 18 | ||||
| -rw-r--r-- | AnimationRender/F_FrameRange.h | 15 | ||||
| -rw-r--r-- | graphics.c | 11 |
6 files changed, 44 insertions, 11 deletions
diff --git a/AnimationRender/AnimationRender.c b/AnimationRender/AnimationRender.c index 8974ba3..68bb7b7 100644 --- a/AnimationRender/AnimationRender.c +++ b/AnimationRender/AnimationRender.c @@ -16,10 +16,12 @@ void RenderAnimation(u32 width, u32 height, u32 totalFrames, const FrameCallback if (callbacks[i] == NULL) { fc.startFrame = 0; fc.endFrame = totalFrames; + fc.frame = f; } - else + else if (fc.startFrame <= fc.frame && fc.frame <= fc.endFrame) callbacks[i]->callback(callbacks[i]->callback_self, &fc); } + ppm6_write(stdout, frameBuffer); } RGBImage_delete(&frameBuffer); diff --git a/AnimationRender/F_Draw.c b/AnimationRender/F_Draw.c index fb90883..90b5986 100644 --- a/AnimationRender/F_Draw.c +++ b/AnimationRender/F_Draw.c @@ -4,10 +4,7 @@ #include <string.h> void Draw_callback(Draw* self, struct FrameContext* fc) { - if (self->startFrame <= fc->frame && fc->frame <= self->endFrame) { - RenderFrame(fc->frameBuffer, self->callbacks, self->sizeCallbacks); - ppm6_write(stdout, fc->frameBuffer); - } + RenderFrame(fc->frameBuffer, self->callbacks, self->sizeCallbacks); } FrameCallback* Draw_setup(Draw obj) { diff --git a/AnimationRender/F_Draw.h b/AnimationRender/F_Draw.h index 729cec9..5150347 100644 --- a/AnimationRender/F_Draw.h +++ b/AnimationRender/F_Draw.h @@ -6,8 +6,6 @@ #include "FrameCallback.h" typedef struct Draw { - u32 startFrame; - u32 endFrame; const PixelCallback** callbacks; usize sizeCallbacks; } Draw; diff --git a/AnimationRender/F_FrameRange.c b/AnimationRender/F_FrameRange.c new file mode 100644 index 0000000..0a1da6d --- /dev/null +++ b/AnimationRender/F_FrameRange.c @@ -0,0 +1,18 @@ +#include "F_FrameRange.h" +#include <stdlib.h> +#include <string.h> + +void FrameRange_callback(FrameRange* self, struct FrameContext* fc) { + fc->startFrame = self->startFrame; + fc->endFrame = self->endFrame; +} + +FrameCallback* FrameRange_setup(FrameRange obj) { + FrameCallback* fca = malloc(sizeof(struct FrameCallback)); + + fca->callback = (FrameCallback_callback)FrameRange_callback; + fca->callback_self = malloc(sizeof(obj)); + memcpy(fca->callback_self, &obj, sizeof(obj)); + + return fca; +} diff --git a/AnimationRender/F_FrameRange.h b/AnimationRender/F_FrameRange.h new file mode 100644 index 0000000..2eaa474 --- /dev/null +++ b/AnimationRender/F_FrameRange.h @@ -0,0 +1,15 @@ +#ifndef F_FRAME_RANGE +#define F_FRAME_RANGE + +#include "../global.h" +#include "../FrameRender/PixelCallback.h" +#include "FrameCallback.h" + +typedef struct FrameRange { + u32 startFrame; + u32 endFrame; +} FrameRange; + +FrameCallback* FrameRange_setup(FrameRange obj); + +#endif /* F_FRAME_RANGE */ @@ -4,6 +4,7 @@ #include "AnimationRender/AnimationRender.h" #include "AnimationRender/F_Draw.h" +#include "AnimationRender/F_FrameRange.h" #include "AnimationRender/F_Interpolate.h" #include "FrameRender/FrameRender.h" #include "FrameRender/P_Checker.h" @@ -63,15 +64,17 @@ main() { TransformCenter img1 = { .centerX = width / 8, .centerY = height * 3/5 }, img2 = { .centerX = height * 3/5, .centerY = width / 8 }; const FrameCallback* frameCallbacks[] = { + Draw_setup((Draw){ + .callbacks = (const PixelCallback**)callbacks, .sizeCallbacks = sizeCallbacks, + }), + FrameRange_setup((FrameRange){ + .startFrame = 25, .endFrame = 125, + }), Interpolate_setup((Interpolate){ .startValue = &img1, .endValue = &img2, .value = callbacks[10]->callback_self, .interpolate = (f_interpolate)Interpolate_TransformCenter, }), - Draw_setup((Draw){ - .startFrame = 0, .endFrame = 150, - .callbacks = (const PixelCallback**)callbacks, .sizeCallbacks = sizeCallbacks, - }), }; u32 sizeFrameCallbacks = sizeof(frameCallbacks) / sizeof(*frameCallbacks); |
