Skip to content

Commit

Permalink
V3 (#53)
Browse files Browse the repository at this point in the history
* Optimize Pads sample even more

* Rework pads module to be a class

* Add fast OBJ loader

* Change custom OBJ parser to Fast OBJ loader

* Add per-vertex color support using mtl

* Make bounding box a fixed array

* Implement support for multiple renderes and offline buffer allocation

* Renderer: Assign to white if no material

* Add multitexturing support (up to 10 textures per model)

* Add a new render sample

* Update modules descriptions on README

* Add font render class

* Fix compilation (#43)

* Emergency fix

* [makefile] migrate from bin2s to bin2c (#42)

* [makefile] migrate from bin2s to bin2c

* Update .gitignore

* Update embed.make

* Change some socket funcs

---------

Co-authored-by: Matías Israelson <[email protected]>

* Use stat to get dir entry size

* Improve displayFunc functionality

* Add fast math functions

* Update compilation.yml

* Add vector basics

* Add second controller support

* Add more pad types support

* Add pad button events

* general path fixes

* feat: rework our 3D renderer to work under VU1 (#45)

* Add initial samples for VU1

* Add initial VU1 support

* Add batch logic to VU1 code

* Add workaround for waiting VU1

* Add printf again

* Add flush at the code start

* refactor: separate functions

* Change to use OpenVCL

* feat: add initial support for multiple mpgs

* Use VCL macros

* Add VU0 routines for lights

* change mpg name

* Add initial pipeline thing

* Do some general cleaning

* feat: diffuse and ambient lights

* perf: add normal math on VU1

* use dynamic batches

* feat: add no texture pipeline

* remove unused members

* feat: multitexturing on VU1

* clean temporary functions

* add linear filter support

* improve texture code readability

* improve bounding box calculation

* add multiple pipeline support

* add only color pipeline

* put obj in a class

* Add non-textured pipelines

* Update render.js

* change to not use image objects on render

* expose vertex access

* Add pipeline descriptors

* Add Render docs

* add screen docs

* add pads docs

* Update README.md

* Improve 3D camera

* optimize obj memory usage

* add optimize, size and bpp to image class

* add new image docs

* change render objects to hold js textures

* add get texture for render objects

* Update README.md

* optimize grayscale png loading

* expose vertex quantity

* Update README.md

* Add palette and pixels changing on Image

* add alpha support for models

* Update README.md

* fix file manager

* remove athena cli

* fix orbit camera

* add new camera functions

* change addvector to vu0

* add vector3 lib

* expose bounding boxes

* implement some 3d collision

* clean old unused code

* remove texture quantity limits for RenderObject

* remove fish model

* remove getFreeMemory

* remove leftover memory stuff

* save some kb with static functions

* remove vector leftovers

* Improve script post-run

* change some error types

* change athena error font

* dont preload fonts at start

* quantize dash icons

* optimize dash memory usage

* Add athena_restart for restart the sound without needed to reload, Add a workaround when sound end to just pause (to avoid stop working) (#48)

* Testing

* Try to never end wav reprodution (just pause)

* Implement restart on ath_sound, for restart a sound without reloading

* Fix build

* Fix build and rename function

* Implement athena_restart for ogg, fix arg count for athena_restart

* Introduze 'athena_get_position', 'athena_set_position', rename 'athena_duration' for 'athena_get_duration' (#49)

* Introduze 'athena_get_position', 'athena_set_position', rename 'athena_duration' for 'athena_get_duration'

* Update Music Player, Now uses the new functions

* Use resume instead of play, and only only go forward or backwards if sound is playing

* feat: add specular for light data

* fix: update for new GCC

* fix: process exceptions from callbacks

* feat: strip redundant functions/consts

---------

Co-authored-by: Matías Israelson <[email protected]>
Co-authored-by: KreitinnSoftware <[email protected]>
  • Loading branch information
3 people authored Jun 30, 2024
1 parent 756c119 commit dd31c9b
Show file tree
Hide file tree
Showing 107 changed files with 20,869 additions and 2,241 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
- name: Compile project
run: |
make clean
make CLI=1
make clean
make
- name: Get short SHA
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ src/main.js.c
.vscode/settings.json

obj/
asm/
embed/
bin/brew_data.json
54 changes: 33 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ EE_BIN_PKD = athena_pkd

EE_SRC_DIR = src/
EE_OBJS_DIR = obj/
EE_ASM_DIR = asm/
EE_ASM_DIR = embed/

RESET_IOP ?= 1
DEBUG ?= 0
Expand All @@ -49,13 +49,13 @@ KEYBOARD ?= 1
MOUSE ?= 1
CAMERA ?= 0

EE_LIBS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/lib/ -Lmodules/ds34bt/ee/ -Lmodules/ds34usb/ee/ -lmc -lpad -laudsrv -lpatches -ldebug -lmath3d -ljpeg -lfreetype -lgskit_toolkit -lgskit -ldmakit -lpng -lz -lds34bt -lds34usb -lnetman -lps2ip -lcurl -lwolfssl -lkbd -lmouse -lvorbisfile -lvorbis -logg -llzma -lzip -lfileXio -lelf-loader-nocolour
EE_LIBS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/lib/ -Lmodules/ds34bt/ee/ -Lmodules/ds34usb/ee/ -lmc -lpad -laudsrv -lpatches -ldebug -lmath3d -ljpeg -lfreetype -lgskit_toolkit -lgskit -ldmakit -lpng -lz -lds34bt -lds34usb -lnetman -lps2ip -lcurl -lwolfssl -lkbd -lmouse -lvorbisfile -lvorbis -logg -llzma -lzip -lfileXio -lelf-loader-nocolour -lerl

EE_INCS += -I$(PS2DEV)/gsKit/include -I$(PS2SDK)/ports/include -I$(PS2SDK)/ports/include/freetype2 -I$(PS2SDK)/ports/include/zlib

EE_INCS += -Imodules/ds34bt/ee -Imodules/ds34usb/ee

EE_CFLAGS += -Wno-sign-compare -fno-strict-aliasing -fno-exceptions -DCONFIG_VERSION=\"$(shell cat VERSION)\" -D__TM_GMTOFF=tm_gmtoff -DPATH_MAX=256 -DPS2
EE_CFLAGS += -Wno-sign-compare -fno-strict-aliasing -fno-exceptions -fpermissive -DCONFIG_VERSION=\"$(shell cat VERSION)\" -D__TM_GMTOFF=tm_gmtoff -DPATH_MAX=256 -DPS2
ifeq ($(RESET_IOP),1)
EE_CFLAGS += -DRESET_IOP
endif
Expand All @@ -64,16 +64,19 @@ ifeq ($(DEBUG),1)
EE_CFLAGS += -DDEBUG
endif

BIN2S = $(PS2SDK)/bin/bin2s
BIN2S = $(PS2SDK)/bin/bin2c
EE_DVP = dvp-as
EE_VCL = vcl
EE_VCLPP = vclpp

EXT_LIBS = modules/ds34usb/ee/libds34usb.a modules/ds34bt/ee/libds34bt.a

JS_CORE = quickjs/cutils.o quickjs/libbf.o quickjs/libregexp.o quickjs/libunicode.o \
quickjs/realpath.o quickjs/quickjs.o quickjs/quickjs-libc.o

APP_CORE = main.o memory.o ee_tools.o module_system.o taskman.o pad.o system.o strUtils.o
APP_CORE = main.o vif.o draw_3D_colors.o draw_3D_colors_notex.o draw_3D.o draw_3D_notex.o draw_3D_lights.o draw_3D_lights_notex.o athena_math.o memory.o ee_tools.o module_system.o taskman.o pad.o system.o strUtils.o

ATHENA_MODULES = ath_env.o ath_pads.o ath_system.o ath_archive.o ath_timer.o ath_task.o
ATHENA_MODULES = ath_env.o ath_physics.o ath_vector.o ath_pads.o ath_system.o ath_archive.o ath_timer.o ath_task.o

IOP_MODULES = iomanx.o filexio.o sio2man.o mcman.o mcserv.o padman.o \
usbd.o bdm.o bdmfs_fatfs.o usbmass_bd.o cdfs.o ds34bt.o \
Expand All @@ -82,17 +85,9 @@ IOP_MODULES = iomanx.o filexio.o sio2man.o mcman.o mcserv.o padman.o \

EMBEDDED_ASSETS = quicksand_regular.o

ifeq ($(CLI),1)
EE_BIN := $(EE_BIN)_cli
EE_BIN_PKD := $(EE_BIN_PKD)_cli
EE_CFLAGS += -DATHENA_CLI
ATHENA_MODULES += ath_cli.o
GRAPHICS = 0
endif

ifeq ($(GRAPHICS),1)
EE_CFLAGS += -DATHENA_GRAPHICS
APP_CORE += graphics.o atlas.o fntsys.o render.o calc_3d.o
APP_CORE += graphics.o atlas.o fntsys.o render.o calc_3d.o fast_obj/fast_obj.o
ATHENA_MODULES += ath_color.o ath_font.o ath_render.o ath_screen.o ath_image.o ath_imagelist.o ath_shape.o
endif

Expand Down Expand Up @@ -154,11 +149,13 @@ all: $(EXT_LIBS) $(EE_BIN) $(EE_ASM_DIR) $(EE_OBJS_DIR)
echo "Building $(EE_BIN)..."
$(EE_STRIP) $(EE_BIN)

echo "Compressing $(EE_BIN_PKD)...\n"
ps2-packer $(EE_BIN) $(EE_BIN_PKD) > /dev/null
# echo "Compressing $(EE_BIN_PKD)...\n"
# ps2-packer $(EE_BIN) $(EE_BIN_PKD) > /dev/null

mv $(EE_BIN) bin/
mv $(EE_BIN_PKD) bin/
# mv $(EE_BIN_PKD) bin/

#mpgs: src/draw_3D.vsm src/draw_3D_notex.vsm src/draw_3D_colors.vsm src/draw_3D_colors_notex.vsm src/draw_3D_lights.vsm src/draw_3D_lights_notex.vsm

debug: $(EXT_LIBS) $(EE_BIN)
echo "Building $(EE_BIN) with debug symbols..."
Expand Down Expand Up @@ -192,7 +189,22 @@ $(EE_OBJS_DIR)%.o: $(EE_SRC_DIR)%.c | $(EE_OBJS_DIR)
$(DIR_GUARD)
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@

$(EE_OBJS_DIR)%.o: $(EE_ASM_DIR)%.s | $(EE_OBJS_DIR)
@echo AS - $<
$(EE_OBJS_DIR)%.o: $(EE_SRC_DIR)%.vsm | $(EE_OBJS_DIR)
@echo DVP - $<
$(DIR_GUARD)
$(EE_DVP) $< -o $@

$(EE_SRC_DIR)%.vcl: $(EE_SRC_DIR)%.vclpp | $(EE_SRC_DIR)
@echo VCLPP - $<
$(DIR_GUARD)
$(EE_AS) $(EE_ASFLAGS) $< -o $@
$(EE_VCLPP) $< $@.vcl

$(EE_SRC_DIR)%.vsm: $(EE_SRC_DIR)%.vcl | $(EE_SRC_DIR)
@echo VCL - $<
$(DIR_GUARD)
$(EE_VCL) -Isrc -g -o$@ $<

$(EE_OBJS_DIR)%.o: $(EE_ASM_DIR)%.c | $(EE_OBJS_DIR)
@echo BIN2C - $<
$(DIR_GUARD)
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
143 changes: 91 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ AthenaEnv is a project that seeks to facilitate and at the same time brings a co
* Image: Image drawing.
* ImageList: Load and manage multiple images while your code is running, multithreaded loading!
* Draw: Shape drawing, triangles, circles etc.
* Render: Basic 3D support.
* Render: Basic 3D support powered by a VU1 renderer.
* Screen: The entire screen of your project (2D and 3D), being able to change the resolution, enable or disable parameters.
* Font: Functions that control the texts that appear on the screen, loading texts, drawing and unloading from memory.
* Pads: Above being able to draw and everything else, A human interface is important. Supports rumble and pressure sensitivity.
Expand Down Expand Up @@ -177,6 +177,7 @@ The std module provides wrappers to the libc stdlib.h and stdio.h and a few othe
* std.evalScript(str, options = undefined) - Evaluate the string str as a script (global eval). options is an optional object containing the following optional properties:
• std.backtrace_barrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
* std.loadScript(filename) - Evaluate the file filename as a script (global eval).
* let hasfile = std.exists(filename) - Returns a bool that determines whether the file exists or not.
* let fstr = std.loadFile(filename) - Load the file filename and return it as a string assuming UTF-8 encoding. Return null in case of I/O error.
* let file = std.open(filename, flags, errorObj = undefined) - Open a file (wrapper to the libc fopen()). Return the FILE object or null in case of I/O error. If errorObj is not undefined, set its errno property to the error code or to 0 if no error occured.
* std.fdopen(fd, flags, errorObj = undefined) - Open a file from a file handle (wrapper to the libc fdopen()). Return the FILE object or null in case of I/O error. If errorObj is not undefined, set its errno property to the error code or to 0 if no error occured.
Expand Down Expand Up @@ -330,11 +331,17 @@ Properties:
* endx, endy - End of the area that will be drawn from the image, the default value is the original image size.
* angle - Define image rotation angle, default value is 0.0.
* color - Define image tinting, default value is Color.new(255, 255, 255, 128).
* filter - Choose between **LINEAR** or **NEAREST**, default value is NEAREST.
* filter - Choose between **LINEAR** or **NEAREST**, default value is NEAREST.
* size - Returns image real size occupied in memory.
* bpp - Returns image bits per-pixel qantity.
* delayed - If true, your texture was loaded in RAM, else, VRAM.
* pixels - The image pixel ArrayBuffer.
* palette - If is a palette image, it has a palette ArrayBuffer right here.

Methods:

* draw(x, y) - Draw loaded image onscreen(call it every frame). Example: image.draw(15.0, 100.0);
* optimize() - If your image has 24 bits per-pixel (aka RGB), you can use this to make it 16 bits per-pixel, saving some memory!
* ready() - Returns true if an asynchronous image was successfully loaded in memory.
```js
var loaded = image.ready();
Expand Down Expand Up @@ -375,27 +382,63 @@ canvas.psmz = Z16S;
Screen.setMode(canvas);
```

* Render.init(aspect) - Initializes rendering routines. *default aspect is 4/3, widescreen is 16/9
* var model = Render.loadOBJ(path, *texture*) - Load simple obj 3d data files. MTL not supported yet. Actually it only supports a single texture that you have to load using Image class and pass as a second argument if you want to use it.
* Render.drawOBJ(model, pos_x, pos_y, pos_z, rot_x, rot_y, rot_z) - Draws the loaded OBJ on the screen.
* Render.freeOBJ(model) - Frees the model from memory.
* Render.setView(aspect, *fov*) - Initializes rendering routines. *default aspect is 4/3, widescreen is 16/9. FOV isn't mandatory, default: 0.2
* Render.vertex(x, y, z, n1, n2, n3, s, t, r, g, b, a) - Returns a vertex to build a 3D mesh. It should be used to create vertex arrays.
• x, y, z - Vertex position on 3D world.
• n1, n2, n3 - Vertex normal.
• s, t - Vertex texture coordinates.
• r, g, b, a - Vertex color.

### RenderObject module

Construction:

```js
var model = new RenderObject(mesh, *texture*)
/* Load simple WaveFront OBJ files or vertex arrays.
MTL is supported on OBJs (including per-vertex colors and multi-texturing).
If you don't have a MTL file but you want to bind a texture on it,
just pass the image as a second argument if you want to use it. */
```
Methods:

* draw(pos_x, pos_y, pos_z, rot_x, rot_y, rot_z) - Draws the object on screen.
* drawBounds(pos_x, pos_y, pos_z, rot_x, rot_y, rot_z) - Draws object bounding box.
* getTexture(id) - Gets the nth texture object from the model.
* setTexture(id, texture, *range*) - Changes or sets the nth texture on models.
* getPipeline() - Returns the current rendering pipeline loaded for the model.
* setPipeline(pipeline) - Sets the current pipeline for the model. Available pipelines:
• Render.PL_NO_LIGHTS_COLORS - Colors and lights disabled.
• Render.PL_NO_LIGHTS_COLORS_TEX - Colors, lights and textures disabled.
• Render.PL_NO_LIGHTS - Lights disabled, colors still working.
• Render.PL_NO_LIGHTS_TEX - Textures and lights disabled, colors still working.
• Render.PL_DEFAULT - Default for textured models. Lights and colors enabled.
• Render.PL_DEFAULT_NO_TEX - Default for non-textured models. Lights and colors enabled.

Properties:

* vertices - A Render.vertex array that can be modified and read.
* size - Vertex quantity.

**Camera**
* Camera.position(x, y, z)
* Camera.rotation(x, y, z)

**Lights**
* Lights.create(count)
* Lights.set(light, dir_x, dir_y, dir_z, r, g, b, type)
• Avaiable light types: AMBIENT, DIRECTIONAL
You have 4 lights to use in 3D scenes, use set to configure them.

* Lights.set(id, attribute, x, y, z)
• Avaiable light attributes: Lights.DIRECTION, Lights.AMBIENT, Lights.DIFFUSE

### Screen module
* Screen.clear(*color*) - Clears screen with the specified color. If you don't specify any argument, it will use black as default.
* Screen.flip() - Run the render queue and jump to the next frame, i.e.: Updates your screen.
* var freevram = Screen.getFreeVRAM() - Returns the total of free Video Memory.
* Screen.setVSync(bool) - Toggles VSync, which makes the framerate stable in 15, 30, 60(depending on the mode) on screen.
* Screen.setFrameCounter(bool) - Toggles frame counting and FPS collecting.
* Screen.waitVblankStart() - Waits for a vertical sync.
* Screen.display(func) - Makes the specified function behave like a main loop, when you don't need to clear or flip the screen because it's done automatically.
* Screen.clearColor(*color*) - Sets a constant clear color for Screen.display function.
* Screen.clear(*color*) - Clears screen with the specified color. If you don't specify any argument, it will use black as default.
* Screen.flip() - Run the render queue and jump to the next frame, i.e.: Updates your screen.
* var freevram = Screen.getFreeVRAM() - Returns the total of free Video Memory.
* Screen.setVSync(bool) - Toggles VSync, which makes the framerate stable in 15, 30, 60(depending on the mode) on screen.
* Screen.setFrameCounter(bool) - Toggles frame counting and FPS collecting.
* Screen.waitVblankStart() - Waits for a vertical sync.
* var fps = Screen.getFPS(frame_interval) - Get Frames per second measure within the specified frame_interval in msec. Dependant on Screen.setFrameCounter(true) to work.
* const canvas = Screen.getMode() - Get actual video mode parameters. Returns an object.
• canvas.mode - Available modes: NTSC, DTV_480p, PAL, DTV_576p, DTV_720p, DTV_1080i.
Expand Down Expand Up @@ -427,27 +470,11 @@ Properties:
* scale - Proportional scale, default: 1.0f

Methods:
* print(x, y, text) - Draw text on screen(call it every frame). Example: font.print(10.0, 10.0, "Hello world!));
* print(x, y, text) - Draw text on screen(call it every frame). Example: font.print(10.0, 10.0, "Hello world!);
* getTextSize(text) - Returns text absolute size in pixels (width, height). Example: const size = font.getTextSize("Hello world!");

### Pads module

* var pad = Pads.get(*port*) - Returns a pad object containing the following properties:
• pad.btns - Buttons
• pad.lx - Left analog horizontal position (left = -127, default = 0, right = 128)
• pad.ly - Left analog vertical position (up = -127, default = 0, down = 128)
• pad.rx - Right analog horizontal position (left = -127, default = 0, right = 128)
• pad.ry - Right analog vertical position (up = -127, default = 0, down = 128)

![analog_graph](https://user-images.githubusercontent.com/47725160/154816009-99d7e5da-badf-409b-9a3b-3618fd372f09.png)

* var type = Pads.getType(*port*) - Gets gamepad type in the specified port.
• Pads.DIGITAL
• Pads.ANALOG
• Pads.DUALSHOCK
* var press = Pads.getPressure(*port*, button) - Get button pressure level.
* Pads.rumble(port, big, small) - Rumble your gamepad.
* var ret = Pads.check(pad, button) - Check if the button was pressed on the specified pad.
* Buttons list:
• Pads.SELECT
• Pads.START
Expand All @@ -465,6 +492,38 @@ Methods:
• Pads.R2
• Pads.L3
• Pads.R3

* var pad = Pads.get(*port*) - Returns a pad object:
Properties:
• pad.btns - Button state on the current check.
• pad.old_btns = Button state on the last check.
• pad.lx - Left analog horizontal position (left = -127, default = 0, right = 128).
• pad.ly - Left analog vertical position (up = -127, default = 0, down = 128).
• pad.rx - Right analog horizontal position (left = -127, default = 0, right = 128).
• pad.ry - Right analog vertical position (up = -127, default = 0, down = 128).

![analog_graph](https://user-images.githubusercontent.com/47725160/154816009-99d7e5da-badf-409b-9a3b-3618fd372f09.png)

Methods:
• update() - Updates all pads pressed and stick positions data.
• pressed(button) - Checks if a button is being pressed (continuously).
• justPressed(button) - Checks if a button was pressed only once.
• setEventHandler() - Sets the pad object to listen events defined by Pads.newEvent, so it doesn't need to be updated.

* let event_id = Pads.newEvent(button, kind, function) - Creates an asynchronous pad event, returns the event id. Remember to set the pad object event handler first!
* Pad event kinds:
• Pads.PRESSED
• Pads.JUST_PRESSED
• Pads.NON_PRESSED
* Pads.deleteEvent(event_id) - Deletes the event created by Pads.newEvent.
* let type = Pads.getType(*port*) - Gets gamepad type in the specified port.
* Pad Types:
• Pads.DIGITAL
• Pads.ANALOG
• Pads.DUALSHOCK

* let press = Pads.getPressure(*port*, button) - Get button pressure level.
* Pads.rumble(port, big, small) - Rumble your gamepad.

### Keyboard module
* Keyboard.init() - Initialize keyboard routines.
Expand All @@ -489,35 +548,15 @@ Methods:

### System module

* var fd = System.openFile(path, type)
* Types list:
• System.FREAD
• System.FWRITE
• System.FCREATE
• System.FRDWR
* var buffer = System.readFile(file, size)
* System.writeFile(fd, data, size)
* System.closeFile(fd)
* System.seekFile(fd, pos, type)
* Types list:
• System.SET
• System.CUR
• System.END
* var size = System.sizeFile(fd)
* System.doesFileExist(path)
* System.CurrentDirectory(path) *if path given, it sets the current dir, else it gets the current dir
* var listdir = System.listDir(*path*)
• listdir[index].name - return file name on indicated index(string)
• listdir[index].size - return file size on indicated index(integer)
• listdir[index].directory - return if indicated index is a file or a directory(bool)
* System.createDirectory(path)
* System.removeDirectory(path)
* System.removeFile(path)
* System.copyFile(source, dest)
* System.moveFile(source, dest)
* System.rename(source, dest)
* System.sleep(sec)
* var freemem = System.getFreeMemory()
* System.exitToBrowser()
* System.setDarkMode(value)
* var temps = System.getTemperature() // It only works with SCPH-500XX and later models.
Expand Down
Loading

0 comments on commit dd31c9b

Please sign in to comment.