Skip to content

Commit

Permalink
Add a ResourceFile type
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jan 10, 2024
1 parent 1b61233 commit cbe5fe8
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2022, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -32,6 +32,7 @@ import nz.net.ultraq.redhorizon.filetypes.AnimationFile
import nz.net.ultraq.redhorizon.filetypes.ImageFile
import nz.net.ultraq.redhorizon.filetypes.ImagesFile
import nz.net.ultraq.redhorizon.filetypes.Palette
import nz.net.ultraq.redhorizon.filetypes.ResourceFile
import nz.net.ultraq.redhorizon.filetypes.SoundFile
import nz.net.ultraq.redhorizon.filetypes.VideoFile

Expand All @@ -57,7 +58,7 @@ class MediaPlayer extends Application {

private static final Logger logger = LoggerFactory.getLogger(MediaPlayer)

private final Object mediaFile
private final ResourceFile mediaFile
private final Palette palette
private MediaLoader mediaLoader

Expand All @@ -69,7 +70,7 @@ class MediaPlayer extends Application {
* @param graphicsConfig
* @param paletteType
*/
MediaPlayer(Object mediaFile, AudioConfiguration audioConfig, GraphicsConfiguration graphicsConfig, Palette palette) {
MediaPlayer(ResourceFile mediaFile, AudioConfiguration audioConfig, GraphicsConfiguration graphicsConfig, Palette palette) {

super('Media Player', audioConfig, graphicsConfig)
this.mediaFile = mediaFile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2022, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -17,24 +17,25 @@
package nz.net.ultraq.redhorizon.engine.media

import nz.net.ultraq.redhorizon.engine.scenegraph.Scene
import nz.net.ultraq.redhorizon.filetypes.ResourceFile

/**
* An object that can be used to create media types from media files, and attach
* them to existing game engines.
*
*
* @param <F> The type of file to load.
* @param <M> The type of media loaded from the file.
* @author Emanuel Rabina
*/
abstract class MediaLoader<F, M> {
abstract class MediaLoader<F extends ResourceFile, M> {

protected final F file
protected final Scene scene
protected M media

/**
* Constructor, create a new loader for the given media file.
*
*
* @param file
* @param scene
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nz.net.ultraq.redhorizon.engine.resources

/**
* Base type for all resources, usually loaded from a corresponding resource
* file, eg: a texture can be built from an image file.
*
* @author Emanuel Rabina
*/
interface Resource {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import nz.net.ultraq.redhorizon.engine.input.KeyEvent
import nz.net.ultraq.redhorizon.engine.media.AnimationLoader
import nz.net.ultraq.redhorizon.engine.media.ImageLoader
import nz.net.ultraq.redhorizon.engine.media.ImagesLoader
import nz.net.ultraq.redhorizon.engine.media.MediaLoader
import nz.net.ultraq.redhorizon.engine.media.Playable
import nz.net.ultraq.redhorizon.engine.media.ResourceLoader
import nz.net.ultraq.redhorizon.engine.media.SoundLoader
import nz.net.ultraq.redhorizon.engine.media.VideoLoader
import nz.net.ultraq.redhorizon.filetypes.AnimationFile
Expand Down Expand Up @@ -64,7 +64,7 @@ class Explorer extends Application {
private File currentDirectory
private InputStream selectedFileInputStream
private Object selectedFile
private MediaLoader selectedLoader
private ResourceLoader selectedLoader
private Palette palette

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2007, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -20,30 +20,30 @@ import java.nio.ByteBuffer

/**
* Interface for animation filetypes.
*
*
* @author Emanuel Rabina
*/
interface AnimationFile extends ImageBase {
interface AnimationFile extends ImageBase, ResourceFile {

/**
* Get the uncompressed data for each frame of the animation that can be used
* for rendering.
*
*
* @return Buffer for each frame.
*/
ByteBuffer[] getFrameData()

/**
* Returns the speed at which this animation should be run, in
* frames-per-second.
*
*
* @return
*/
float getFrameRate()

/**
* Return the number of frames that make up this animation.
*
*
* @return
*/
int getNumFrames()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2007 Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -20,14 +20,14 @@ import java.nio.ByteBuffer

/**
* Interface for image file formats.
*
*
* @author Emanuel Rabina
*/
interface ImageFile extends ImageBase {
interface ImageFile extends ImageBase, ResourceFile {

/**
* Return the image data of the file.
*
*
* @return Buffer of the bytes in RGB(A) order for the image.
*/
ByteBuffer getImageData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2007 Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,21 +22,21 @@ import java.nio.ByteBuffer
* Interface for files which contain multiple images, but not to be played in
* sequence like an animation. The images all share the same dimensions and
* colour format.
*
*
* @author Emanuel Rabina
*/
interface ImagesFile extends ImageBase {
interface ImagesFile extends ImageBase, ResourceFile {

/**
* Returns the image data for all of the images in this file.
*
*
* @return Image data for each image.
*/
ByteBuffer[] getImagesData()

/**
* Returns the number of images in this file.
*
*
* @return Number of images.
*/
int getNumImages()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nz.net.ultraq.redhorizon.filetypes

/**
* Base type for all files that contain data that can be used for a resource,
* eg: an image file can be loaded to build a texture.
*
* @author Emanuel Rabina
*/
interface ResourceFile {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2007, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -20,10 +20,10 @@ import java.nio.ByteBuffer

/**
* Interface for filetypes for sound data (eg: AUD, WAV, etc...).
*
*
* @author Emanuel Rabina
*/
interface SoundFile {
interface SoundFile extends ResourceFile {

/**
* Returns the number of bits used for each sound sample.
Expand All @@ -42,15 +42,15 @@ interface SoundFile {

/**
* Returns uncompressed sound data that can be used for playback.
*
*
* @return The buffer of sound data.
*/
ByteBuffer getSoundData()

/**
* Return whether this file is best read using a streaming strategy, best for
* larger sound files like music tracks.
*
*
* @return
*/
default boolean isForStreaming() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2007 Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,8 +18,8 @@ package nz.net.ultraq.redhorizon.filetypes

/**
* A video file format, containing both frames and an audio stream.
*
*
* @author Emanuel Rabina
*/
interface VideoFile extends AnimationFile, SoundFile, Streaming {
interface VideoFile extends AnimationFile, SoundFile, Streaming, ResourceFile {
}

0 comments on commit cbe5fe8

Please sign in to comment.