Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

love.video support #175

Merged
merged 20 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build
distribute
.vscodecounter
logs
distribute

*.log

Expand Down
75 changes: 0 additions & 75 deletions .vscode/settings.json

This file was deleted.

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ export LOVE_VERSION = 11.4.0
#-----------------------------------
export LOVE_PORTLIBS = -lmodplug -lvorbisidec -lFLAC -lvorbisidec -logg
LOVE_PORTLIBS += -lphysfs -llz4 -lz -lbox2d -ljpeg -lpng `curl-config --libs`
LOVE_PORTLIBS += -ltheora

#------------------------------------
# Common configuration for consoles
#------------------------------------
export APP_TITLE := LÖVE Potion
export APP_AUTHOR := lövebrew team
export APP_VERSION := 2.3.2
export APP_VERSION := 2.4.0
export APP_TITLEID := 1043

export DEFINES := -D__DEBUG__=$(DEBUG) -D__APP_VERSION__=\"$(APP_VERSION)\" \
Expand Down
6 changes: 6 additions & 0 deletions include/common/delay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace love
{
void Sleep(float ms);
}
1 change: 1 addition & 0 deletions include/common/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace love
M_TIMER,
M_TOUCH,
M_WINDOW,
M_VIDEO,
M_MAX_ENUM
};

Expand Down
9 changes: 9 additions & 0 deletions include/common/pixelformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ namespace love
PIXELFORMAT_TEX3DS_RGBA8,

// "regular" formats
PIXELFORMAT_RGB8,

PIXELFORMAT_RGBA8,
PIXELFORMAT_RGBA16,

PIXELFORMAT_R8,

PIXELFORMAT_RGBA4,
PIXELFORMAT_RGB565,

PIXELFORMAT_LA8,

// depth/stencil
PIXELFORMAT_STENCIL8,
PIXELFORMAT_DEPTH16,
Expand Down
8 changes: 8 additions & 0 deletions include/modules/graphics/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

#include "objects/imagedata/imagedata.h"

#include "objects/video/video.h"
#include "objects/videostream/videostream.h"

#include "common/lmath.h"
#include <optional>
#include <vector>
Expand Down Expand Up @@ -268,6 +271,9 @@ namespace love
const Texture::Filter& filter = Texture::defaultFilter) = 0;
#endif

Image* NewImage(Texture::TextureType t, PixelFormat format, int width, int height,
int slices);

Quad* NewQuad(Quad::Viewport v, double sw, double sh);

Text* NewText(Font* font, const std::vector<Font::ColoredString>& text = {});
Expand All @@ -276,6 +282,8 @@ namespace love

Font* GetFont();

Video* NewVideo(VideoStream* stream, float dpiscale);

float GetPointSize() const;

LineStyle GetLineStyle() const;
Expand Down
2 changes: 2 additions & 0 deletions include/modules/graphics/wrap_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ namespace Wrap_Graphics

int NewCanvas(lua_State* L);

int NewVideo(lua_State* L);

int SetDefaultFilter(lua_State* L);

int SetLineWidth(lua_State* L);
Expand Down
2 changes: 2 additions & 0 deletions include/modules/timer/timerc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace love::common
class Timer : public Module
{
public:
static constexpr auto SLEEP_DURATION = 1000000ULL;

Timer();

ModuleType GetModuleType() const
Expand Down
33 changes: 33 additions & 0 deletions include/modules/video/videomodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "common/module.h"
#include "objects/file/file.h"
#include "objects/videostream/videostream.h"

namespace love
{
class Worker;

class VideoModule : public Module
{
public:
VideoModule();

virtual ~VideoModule();

virtual const char* GetName() const
{
return "love.video";
}

virtual ModuleType GetModuleType() const
{
return M_VIDEO;
}

VideoStream* NewVideoStream(File* file);

private:
Worker* workerThread;
};
} // namespace love
34 changes: 34 additions & 0 deletions include/modules/video/worker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "modules/thread/types/conditional.h"
#include "modules/thread/types/threadable.h"

#include "objects/videostream/theorastream.h"
#include "objects/videostream/utility/stream.h"

#include <vector>

namespace love
{
class Worker : public Threadable
{
public:
Worker();

virtual ~Worker();

void ThreadFunction();

void AddStream(TheoraStream* stream);

void Stop();

private:
std::vector<StrongReference<TheoraStream>> streams;

thread::MutexRef mutex;
thread::ConditionalRef condition;

bool stopping;
};
} // namespace love
11 changes: 11 additions & 0 deletions include/modules/video/wrap_videomodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "common/luax.h"
#include "modules/video/videomodule.h"

namespace Wrap_VideoModule
{
int NewVideoStream(lua_State* L);

int Register(lua_State* L);
} // namespace Wrap_VideoModule
2 changes: 0 additions & 2 deletions include/objects/image/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ namespace love
std::vector<std::vector<StrongReference<ImageDataBase>>> data;
};

#if defined(__SWITCH__)
void ReplacePixels(const void* data, size_t size, const Rect& rect);
#endif

~Image();

Expand Down
60 changes: 60 additions & 0 deletions include/objects/video/videoc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include "objects/drawable/drawable.h"

#include "objects/source/source.h"
#include "objects/videostream/videostream.h"

#include "objects/image/image.h"
#include "objects/texture/texture.h"

namespace love
{
class Graphics;

namespace common
{
class Video : public Drawable
{
public:
static love::Type type;

Video(Graphics* graphics, VideoStream* stream, float dpiScale = 1.0f);

virtual ~Video();

virtual void Draw(Graphics* graphics, const Matrix4& matrix) = 0;

VideoStream* GetStream();

love::Source* GetSource();

void SetSource(love::Source* source);

int GetWidth() const;

int GetHeight() const;

int GetPixelWidth() const;

int GetPixelHeight() const;

void SetFilter(const Texture::Filter& filter);

const Texture::Filter& GetFilter() const;

protected:
virtual void Update() = 0;

StrongReference<VideoStream> stream;

int width;
int height;

Texture::Filter filter;

StrongReference<love::Source> source;
StrongReference<Image> images[3];
};
} // namespace common
} // namespace love
33 changes: 33 additions & 0 deletions include/objects/video/wrap_video.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "common/luax.h"
#include "objects/video/video.h"

namespace Wrap_Video
{
int GetStream(lua_State* L);

int GetSource(lua_State* L);

int SetSource(lua_State* L);

int GetWidth(lua_State* L);

int GetHeight(lua_State* L);

int GetDimensions(lua_State* L);

int GetPixelWidth(lua_State* L);

int GetPixelHeight(lua_State* L);

int GetPixelDimensions(lua_State* L);

int SetFilter(lua_State* L);

int GetFilter(lua_State* L);

love::Video* CheckVideo(lua_State* L, int index);

int Register(lua_State* L);
} // namespace Wrap_Video
Loading