diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 76b7614..4a604ba 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -94,7 +94,7 @@ void Engine::gameLoop() fps = timer.getFPS(); fpsDelayer = 0; } - timer.primeTimer(); + timer.prime(); renderer->endFrame(fps); /** -6~ FPS */ SetAlarm(150, &Engine::wakeup, &mainThreadId); diff --git a/src/engine/include/models/math/vector3.hpp b/src/engine/include/models/math/vector3.hpp index a4bb4e0..55f392c 100644 --- a/src/engine/include/models/math/vector3.hpp +++ b/src/engine/include/models/math/vector3.hpp @@ -44,8 +44,8 @@ public: Vector3 operator-(void); static u8 shouldBeBackfaceCulled(const Vector3 *t_cameraPos, const Vector3 *v0, const Vector3 *v1, const Vector3 *v2); - u8 collidesSquare(Vector3 &t_min, Vector3 &t_max); - u8 isOnSquare(Vector3 &t_min, Vector3 &t_max); + u8 collidesSquare(const Vector3 &t_min, const Vector3 &t_max) const; + u8 isOnSquare(const Vector3 &t_min, const Vector3 &t_max) const; float length(); void normalize(); void setByLerp(const Vector3 &v1, const Vector3 &v2, const float &t_interp, const float &t_scale); diff --git a/src/engine/include/modules/timer.hpp b/src/engine/include/modules/timer.hpp index 424e8ca..6e9dcd2 100644 --- a/src/engine/include/modules/timer.hpp +++ b/src/engine/include/modules/timer.hpp @@ -12,6 +12,7 @@ #define _TYRA_TIMER_ #include +#include /** Class responsible for fps counting */ class Timer @@ -22,7 +23,7 @@ public: ~Timer(); u32 getTimeDelta(); - void primeTimer(); + inline void prime() { lastTime = *T3_COUNT; } float getFPS(); private: diff --git a/src/engine/models/math/vector3.cpp b/src/engine/models/math/vector3.cpp index e05b36c..fbb772e 100644 --- a/src/engine/models/math/vector3.cpp +++ b/src/engine/models/math/vector3.cpp @@ -170,13 +170,13 @@ u8 Vector3::shouldBeBackfaceCulled(const Vector3 *t_cameraPos, const Vector3 *v0 } /** Checks intersection with given square */ -u8 Vector3::collidesSquare(Vector3 &t_min, Vector3 &t_max) +u8 Vector3::collidesSquare(const Vector3 &t_min, const Vector3 &t_max) const { return ((this->x <= t_max.x && this->x >= t_min.x) && (this->y < t_max.y && this->y >= t_min.y) && (this->z <= t_max.z && this->z >= t_min.z)) ? 1 : 0; } /** Checks is this vector is on given square */ -u8 Vector3::isOnSquare(Vector3 &t_min, Vector3 &t_max) +u8 Vector3::isOnSquare(const Vector3 &t_min, const Vector3 &t_max) const { return ((this->x <= t_max.x && this->x >= t_min.x) && (this->y >= t_max.y) && (this->z <= t_max.z && this->z >= t_min.z)) ? 1 : 0; } diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index cd8b484..c5b2a8e 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -123,12 +123,14 @@ void Renderer::draw(Sprite &t_sprite) packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048)); packet2_utils_gif_add_set(packet2, 1); packet2_utils_gs_add_texbuff_clut(packet2, &textureBuffer, &t_sprite.clut); + draw_enable_blending(); packet2_update(packet2, draw_rect_textured(packet2->next, 0, &rect)); packet2_update(packet2, draw_primitive_xyoffset( packet2->next, 0, (2048 - (screen->width / 2)), (2048 - (screen->height / 2)))); + draw_disable_blending(); packet2_update(packet2, draw_finish(packet2->next)); dma_channel_wait(DMA_CHANNEL_GIF, 0); dma_channel_send_packet2(packet2, DMA_CHANNEL_GIF, true); diff --git a/src/engine/modules/timer.cpp b/src/engine/modules/timer.cpp index e62f76e..ac20ba8 100644 --- a/src/engine/modules/timer.cpp +++ b/src/engine/modules/timer.cpp @@ -10,16 +10,11 @@ #include "../include/modules/timer.hpp" -#include - // ---- // Constructors/Destructors // ---- -Timer::Timer() -{ - this->lastTime = *T3_COUNT; -} +Timer::Timer() { prime(); } Timer::~Timer() {} @@ -29,20 +24,13 @@ Timer::~Timer() {} u32 Timer::getTimeDelta() { - this->time = *T3_COUNT; + time = *T3_COUNT; - if (this->time < this->lastTime) // The counter has wrapped - this->change = this->time + (65536 - this->lastTime); + if (time < lastTime) // The counter has wrapped + change = time + (65536 - lastTime); else - this->change = this->time - this->lastTime; - - this->lastTime = this->time; - return this->change; -} - -void Timer::primeTimer() -{ - lastTime = *T3_COUNT; + change = time - lastTime; + return change; } float Timer::getFPS() diff --git a/src/samples/ari/.gitignore b/src/samples/ari/.gitignore deleted file mode 100644 index 23c6dd9..0000000 --- a/src/samples/ari/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.vscode/ -bin/** -fonts/** \ No newline at end of file diff --git a/src/samples/ari/Makefile b/src/samples/ari/Makefile deleted file mode 100644 index af3f457..0000000 --- a/src/samples/ari/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -EE_BIN = ari.elf - -TYRA_DIR = ./../../engine - -EE_OBJS = \ - camera.o \ - objects/player.o \ - ari.o \ - main.o - -EE_LIBS = -ltyra - -all: $(EE_BIN) - $(EE_STRIP) --strip-all $(EE_BIN) - mv $(EE_BIN) bin/$(EE_BIN) - rm $(EE_OBJS) - -rebuild-engine: - cd $(TYRA_DIR) && make clean && make - -clean: - rm -f $(EE_OBJS) - -run: $(EE_BIN) - killall -v ps2client || true - ps2client reset - ps2client reset - $(EE_STRIP) --strip-all $(EE_BIN) - mv $(EE_BIN) bin/$(EE_BIN) - rm $(EE_OBJS) - cd bin/ && ps2client execee host:$(EE_BIN) - -include $(TYRA_DIR)/Makefile.pref diff --git a/src/samples/ari/README.MD b/src/samples/ari/README.MD deleted file mode 100644 index 46f3cdd..0000000 --- a/src/samples/ari/README.MD +++ /dev/null @@ -1,19 +0,0 @@ -## Ari sample - -### Description - -* .obj (skybox, water) -* .dff (island) -* .md2 (ari) -* mesh cloning (water) - -Testing demo. In future there will be Ariana Grande demo. - -### Assets -[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.1.0/samples/ari/assets.zip) - -### Screenshot - -[![Ari screenshot][ari-screenshot]](#) - -[ari-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.1.0/samples/ari/ari.gif diff --git a/src/samples/ari/ari.cpp b/src/samples/ari/ari.cpp deleted file mode 100644 index 3c33919..0000000 --- a/src/samples/ari/ari.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "ari.hpp" - -#include "utils/math.hpp" - -// ---- -// Constructors/Destructors -// ---- - -const u8 WATER_TILES_COUNT = 64; - -Ari::Ari(Engine *t_engine) : engine(t_engine), camera(&engine->screen) -{ - waterFloors = new Mesh[WATER_TILES_COUNT]; - spirals = new Point[WATER_TILES_COUNT]; -} - -Ari::~Ari() {} - -// ---- -// Methods -// ---- - -void Ari::onInit() -{ - engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes); - engine->audio.setSongVolume(40); - // engine->audio.loadSong("MOV-CIRC.WAV"); - engine->audio.loadSong("nob-else.wav"); - - adpcm1 = engine->audio.loadADPCM("ziobro1.adpcm"); - adpcm2 = engine->audio.loadADPCM("ziobro2.adpcm"); - - texRepo = engine->renderer->getTextureRepository(); - engine->renderer->disableVSync(); - island.loadDff("sunnyisl/", "sunnyisl", 0.1F, false); - island.rotation.x = -1.6F; - island.position.set(0.0F, 10.0F, 20.0F); - island.shouldBeBackfaceCulled = true; - island.shouldBeFrustumCulled = false; - - fist.size.set(100.0F, 100.0F); - Texture *fistTex = texRepo->add("2d/", "fist", PNG); - fistTex->addLink(fist.getId()); - - islandAddons.loadDff("sunnyisl/", "sunnyisl3", 0.1F, false); - islandAddons.shouldBeBackfaceCulled = true; - islandAddons.rotation.x = -1.6F; - islandAddons.position.set(0.0F, 10.0F, 20.0F); - - skybox.loadObj("skybox/", "skybox", 100.0F, false); - skybox.shouldBeFrustumCulled = false; - - waterFloors[0].loadObj("water/", "water", 5.0F, false); - waterFloors[0].position.set(0.0F, 8.0F, 0.0F); - texRepo->addByMesh("water/", waterFloors[0], BMP); - for (u8 i = 0; i < WATER_TILES_COUNT; i++) - { - spirals[i].x = 1.0F; - spirals[i].y = 2.0F; - } - u32 spiralOffset = (u32)Math::sqrt(WATER_TILES_COUNT); - calcSpiral(spiralOffset, spiralOffset); - for (u8 i = 1; i < WATER_TILES_COUNT; i++) - { - waterFloors[i].loadFrom(waterFloors[0]); - waterFloors[i].position.set(10.0F * spirals[i].x, 8.0F, 10.0F * spirals[i].y); - texRepo->getByMesh(waterFloors[0].getId(), waterFloors[0].getMaterial(0).getId()) - ->addLink(waterFloors[i].getId(), waterFloors[i].getMaterial(0).getId()); - } - - texRepo->addByMesh("sunnyisl/", island, BMP); - texRepo->addByMesh("sunnyisl/", islandAddons, BMP); - texRepo->addByMesh("skybox/", skybox, BMP); - texRepo->addByMesh("ari/", player.mesh, BMP); - // engine->audio.playSong(); -} - -void Ari::initBulb() -{ - bulb.intensity = 15; - bulb.position.set(5.0F, 10.0F, 10.0F); -} - -void Ari::onUpdate() -{ - if (engine->pad.isCrossClicked) - { - // engine->audio.loadSong("nob-else.wav"); - engine->audio.playADPCM(adpcm1); - printf("FPS:%f\n", engine->fps); - } - if (engine->pad.isCircleClicked) - engine->audio.playADPCM(adpcm2); - camera.update(engine->pad, player.mesh); - engine->renderer->draw(skybox); - engine->renderer->draw(fist); - engine->renderer->draw(island); - engine->renderer->draw(islandAddons); - engine->renderer->draw(player.mesh); - for (u8 i = 0; i < WATER_TILES_COUNT; i++) - engine->renderer->draw(waterFloors[i]); -} - -void Ari::calcSpiral(int X, int Y) -{ - int x, y, dx; - x = y = dx = 0; - int dy = -1; - int t = X > Y ? X : Y; - int maxI = t * t; - for (int i = 0; i < maxI; i++) - { - if ((-X / 2 <= x) && (x <= X / 2) && (-Y / 2 <= y) && (y <= Y / 2)) - { - spirals[i].x = x; - spirals[i].y = y; - } - if ((x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1 - y))) - { - t = dx; - dx = -dy; - dy = t; - } - x += dx; - y += dy; - } -} diff --git a/src/samples/ari/ari.hpp b/src/samples/ari/ari.hpp deleted file mode 100644 index 549d7dc..0000000 --- a/src/samples/ari/ari.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#ifndef _ARI_ -#define _ARI_ - -#include -#include -#include -#include -#include "objects/player.hpp" -#include -#include -#include -#include "./camera.hpp" - -class Ari : public Game -{ - -public: - Ari(Engine *t_engine); - ~Ari(); - - void onInit(); - void onUpdate(); - - Engine *engine; - -private: - void initBulb(); - void calcSpiral(int X, int Y); - LightBulb bulb; - Player player; - Mesh island, islandAddons, skybox; - Mesh *waterFloors; - Sprite fist; - audsrv_adpcm_t *adpcm1, *adpcm2; - Point *spirals; - Camera camera; - TextureRepository *texRepo; -}; - -#endif diff --git a/src/samples/ari/camera.cpp b/src/samples/ari/camera.cpp deleted file mode 100644 index 9c506a0..0000000 --- a/src/samples/ari/camera.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "camera.hpp" - -#include -#include - -const float CAMERA_Y = 15.0F; - -// ---- -// Constructors/Destructors -// ---- - -Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up) -{ - PRINT_LOG("Initializing camera"); - verticalLevel = 80.0F; - up.x = 0.0F; - up.y = 1.0F; - up.z = 0.0F; - PRINT_LOG("Camera initialized!"); -} - -Camera::~Camera() {} - -// ---- -// Methods -// ---- - -void Camera::update(Pad &t_pad, Mesh &t_mesh) -{ - rotate(t_pad); - followBy(t_mesh); - Vector3 lookPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z); - lookAt(lookPos); -} - -/** Set camera rotation by pad right joy and update unit circle - * https://en.wikipedia.org/wiki/Unit_circle - * https://www.desmos.com/calculator/3e7iypw4ow - */ -void Camera::rotate(Pad &t_pad) -{ - if (t_pad.rJoyH <= 50) - horizontalLevel -= 0.08; - else if (t_pad.rJoyH >= 200) - horizontalLevel += 0.04; - if (t_pad.rJoyV <= 50 && verticalLevel > 25.0F) - verticalLevel -= 0.9F; - else if (t_pad.rJoyV >= 200 && verticalLevel < 80.0F) - verticalLevel += 0.9F; - unitCirclePosition.x = (Math::sin(horizontalLevel) * verticalLevel); - unitCirclePosition.y = CAMERA_Y; - unitCirclePosition.z = (Math::cos(horizontalLevel) * verticalLevel); -} - -/** Rotate camera around 3D object */ -void Camera::followBy(Mesh &t_mesh) -{ - position.x = unitCirclePosition.x + t_mesh.position.x; - position.y = unitCirclePosition.y + t_mesh.position.y; - position.z = unitCirclePosition.z + t_mesh.position.z; - - if (position.x > (-0.04F * verticalLevel) && - position.x < 0.0F && - position.z > (0.998F * verticalLevel)) - { - // TODO - // position.x = 0.0F; - // position.y = 0.0F; - // position.z = 0.0F; - // horizontalLevel = 0.0F; - } -} diff --git a/src/samples/ari/camera.hpp b/src/samples/ari/camera.hpp deleted file mode 100644 index 4d6adf8..0000000 --- a/src/samples/ari/camera.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#ifndef _CAMERA_ -#define _CAMERA_ - -#include -#include -#include -#include -#include -#include - -/** 3D camera which follow by 3D object. Can be rotated via pad */ -class Camera : public CameraBase -{ - -public: - Vector3 up, position, unitCirclePosition; - float horizontalLevel, verticalLevel; - - Camera(ScreenSettings *t_screen); - ~Camera(); - - void update(Pad &t_pad, Mesh &t_mesh); - void rotate(Pad &t_pad); - void followBy(Mesh &t_mesh); - -protected: - Vector3 *getPosition() { return &position; }; - Vector3 *getUp() { return &up; }; - ScreenSettings screen; -}; - -#endif diff --git a/src/samples/ari/main.cpp b/src/samples/ari/main.cpp deleted file mode 100644 index f76ae54..0000000 --- a/src/samples/ari/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "ari.hpp" - -int main() -{ - Engine engine = Engine(); - Ari game = Ari(&engine); - game.engine->init(&game, 128); - SleepThread(); - return 0; -} diff --git a/src/samples/ari/objects/player.cpp b/src/samples/ari/objects/player.cpp deleted file mode 100644 index 2f7da88..0000000 --- a/src/samples/ari/objects/player.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#include "player.hpp" - -#include -#include -#include -#include -#include - -// ---- -// Constructors/Destructors -// ---- - -Player::Player() -{ - PRINT_LOG("Creating player object"); - this->gravity = 0.1F; - this->lift = -1.0F; - this->mesh.loadMD2("ari/", "ari", 0.0001F, true); - this->mesh.position.set(0.0F, 10.0F, 0.0F); - this->mesh.shouldBeBackfaceCulled = true; - this->mesh.shouldBeFrustumCulled = false; - this->mesh.shouldBeLighted = true; - this->mesh.setAnimSpeed(0.05F); - this->mesh.playAnimation(0, 1); - PRINT_LOG("Player object created!"); -} - -Player::~Player() -{ -} - -// ---- -// Methods -// ---- diff --git a/src/samples/ari/objects/player.hpp b/src/samples/ari/objects/player.hpp deleted file mode 100644 index 0ffb771..0000000 --- a/src/samples/ari/objects/player.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Sandro Sobczyński -*/ - -#ifndef _PLAYER_ -#define _PLAYER_ - -#include "../camera.hpp" -#include -#include - -/** Player 3D object class */ -class Player -{ - -public: - float gravity, velocity, lift; - u8 isOnFloor, isCollideFloor, indexOfCurrentFloor; - Mesh mesh; - Player(); - ~Player(); - -private: - Vector3 playerNextPosition; -}; - -// TODO Rysowanie idzie wg tekstur - -// 2 Graczy, 1 mesh 2 tekstury -// sharedFrames = objLoader.load("meshes/", "block", 1.0F); -// var addedTextures = texturesRepo.addByMaterialNames("textures/dirt/", sharedFrames); -// var addedTexture = texturesRepo.add("textures/blocks/sand.bmp"); -// dirt = new Mesh(sharedFrames); -// sand = new Mesh(sharedFrames); -// addedTextures[0].addUsage(dirt.Id, sharedFrames.getMaterialId(0)); -// addedTexture.addUsage(sand.Id, sand.getMaterialId(0)); - -// 1 gracz, 2 dynamic tekstury -// sharedFrames = objLoader.load("meshes/", "block", 1.0F); -// var addedTexture1 = texturesRepo.add("textures/blocks/sand.bmp"); -// var addedTexture2 = texturesRepo.add("textures/blocks/sand_damaged.bmp"); -// sand = new Mesh(sharedFrames); -// addedTexture1.removeUsage(sand.Id, sand.getMaterialId(0)); -// draw() -// addedTexture2.addUsage(sand.Id, sand.getMaterialId(0)); - -// 2 różne obj, te same tekstury -// frames1 = objLoader.load("meshes/", "island", 1.0F); -// frames2 = objLoader.load("meshes/", "islandAddons", 1.0F); -// island = new Mesh(frames1); -// islandAddons = new Mesh(frames2); -// var addedTextures1 = texturesRepo.addByMaterialNames("textures/island/",frames1); -// var addedTextures2 = texturesRepo.addByMaterialNames("textures/island/",frames2); -// texturesRepo.remove(addedTextures2[0]); // duplicate -// addedTextures1[0].addUsage(islandAddons.Id, islandAddons.getMaterialId(0)); - -// Mesh -> position, rotation, color, scale, shouldBeLighted, clut, lod - -#endif