tyrav2 init

This commit is contained in:
h4570
2022-07-17 10:21:35 +02:00
parent 44c1ee4fe8
commit c8b22ff331
249 changed files with 18187 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
TARGET := wellinator.elf
ENGINEDIR := ../../engine
#The Directories, Source, Includes, Objects, Binary and Resources
SRCDIR := src
INCDIR := inc
BUILDDIR := obj
TARGETDIR := bin
RESDIR := res
SRCEXT := cpp
VSMEXT := vsm
VCLEXT := vcl
VCLPPEXT := vclpp
DEPEXT := d
OBJEXT := o
#Flags, Libraries and Includes
CFLAGS :=
LIB :=
LIBDIRS :=
INC := -I$(INCDIR)
INCDEP := -I$(INCDIR)
include ../Makefile.samples-base
+50
View File
@@ -0,0 +1,50 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020 - 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Wellington Carvalho <wellcoj@gmail.com>
*/
#pragma once
#include <engine.hpp>
#include <game.hpp>
#include "renderer/3d/pipeline/minecraft/minecraft_pipeline.hpp"
#include "renderer/3d/pipeline/std/std_pipeline.hpp"
namespace Tyra {
class Wellinator : public Game {
public:
Wellinator(Engine* engine);
~Wellinator();
void init();
void loop();
private:
Engine* engine;
Mesh* warrior;
Sprite* picture;
audsrv_adpcm_t* adpcmSample;
Timer adpcmTimer;
Vec4 cameraPosition, cameraLookAt;
MinecraftPipeline mcPip;
StdPipeline stdPip;
StdpipOptions* renderOptions;
Texture* blocksTex;
u32 blocksCount;
McpipBlock* blocks;
M4x4* translations;
M4x4* rotations;
M4x4* scales;
};
} // namespace Tyra
+4
View File
@@ -0,0 +1,4 @@
$ConfigFile = Join-Path $PSScriptRoot '../windows-pcsx2.ps1'
. $ConfigFile
RunPCSX2
+20
View File
@@ -0,0 +1,20 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Wellington Carvalho <wellcoj@gmail.com>
*/
#include "engine.hpp"
#include "wellinator.hpp"
int main() {
Tyra::Engine engine;
Tyra::Wellinator game(&engine);
engine.run(&game);
SleepThread();
return 0;
}
+182
View File
@@ -0,0 +1,182 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Wellington Carvalho <wellcoj@gmail.com>
*/
#include "wellinator.hpp"
#include "file/file_utils.hpp"
#include "loaders/3d/md2/md2_loader.hpp"
namespace Tyra {
Wellinator::Wellinator(Engine* t_engine) { engine = t_engine; }
Wellinator::~Wellinator() {}
Mesh* getWarrior(Renderer* renderer);
StdpipOptions* getRenderingOptions();
Sprite* get2DPicture(Renderer* renderer);
void Wellinator::init() {
// Song
engine->audio.loadSong(FileUtils::fromCwd("mafikizolo-loot.wav"));
engine->audio.setSongLoop(true);
engine->audio.setSongVolume(30);
adpcmSample = engine->audio.loadADPCM(FileUtils::fromCwd("walk.adpcm"));
engine->audio.setADPCMVolume(80, 1);
engine->renderer.setClearScreenColor(Color(64.0F, 64.0F, 64.0F));
warrior = getWarrior(&engine->renderer);
renderOptions = getRenderingOptions();
cameraPosition = Vec4(0.0F, 0.0F, 0.0F, 1.0F);
cameraLookAt = *warrior->getPosition();
blocksTex = engine->renderer.core.texture.repository.add(
FileUtils::fromCwd("blocks.png"));
mcPip.init(&engine->renderer.core);
stdPip.init(&engine->renderer.core);
picture = get2DPicture(&engine->renderer);
u32 rows = 8; // 64
u32 columns = 8; // 64
blocksCount = rows * columns;
float initialCameraZ = -400.0F;
float offset = 40.0F;
blocks = new McpipBlock[blocksCount];
translations = new M4x4[blocksCount];
rotations = new M4x4[blocksCount];
scales = new M4x4[blocksCount];
float center = (rows / 2.0F) * offset;
for (u32 i = 0; i < blocksCount; i++) {
u32 column = i % columns;
u32 row = i / rows;
scales[i].scale(10.0F);
translations[i].translateX(row * offset - center);
translations[i].translateY(column * offset - center);
translations[i].translateZ(initialCameraZ);
u32 randRow = rand() % (rows + 1);
u32 randColumn = rand() % (columns + 1);
blocks[i].textureOffset =
Vec4(mcPip.getTextureOffset() * randRow,
mcPip.getTextureOffset() * randColumn, 0.0F, 1.0F);
blocks[i].color = Color(128.0F, 128.0F, 128.0F, 128.0F);
}
// Vec4 warriorInitPosition = *warrior->getPosition();
engine->audio.playSong();
}
void Wellinator::loop() {
warrior->animate();
if ((engine->pad.getPressed().DpadUp || engine->pad.getPressed().DpadDown ||
engine->pad.getPressed().DpadLeft ||
engine->pad.getPressed().DpadRight) &&
adpcmTimer.getTimeDelta() > 8000) {
adpcmTimer.prime();
engine->audio.playADPCM(adpcmSample, 1);
}
engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt));
{
for (u32 i = 0; i < blocksCount; i++) {
rotations[i].rotateX(0.04F);
rotations[i].rotateY(0.01F);
rotations[i].rotateZ(0.01F);
blocks[i].model = translations[i] * rotations[i] * scales[i];
}
engine->renderer.renderer2D.render(picture);
// Vec4* nextPos = warrior->getPosition();
// if (pad.getPressed().DpadUp) nextPos->y += 0.2;
// if (pad.getPressed().DpadDown) nextPos->y -= 0.2;
// if (pad.getPressed().DpadRight) nextPos->x += 0.2;
// if (pad.getPressed().DpadLeft) nextPos->x -= 0.2;
// if (pad.getLeftJoyPad().v > 200) nextPos->z += 0.2;
// if (pad.getLeftJoyPad().v < 100) nextPos->z -= 0.2;
// warrior->setPosition(*nextPos);
engine->renderer.renderer3D.usePipeline(&stdPip);
{ stdPip.render(warrior, renderOptions); }
engine->renderer.renderer3D.usePipeline(&mcPip);
{ mcPip.render(blocks, blocksCount, blocksTex, false); }
}
engine->renderer.endFrame();
}
Mesh* getWarrior(Renderer* renderer) {
MD2Loader loader;
auto* data = loader.load(FileUtils::fromCwd("warrior.md2"), .08F, false);
auto* result = new Mesh(*data);
result->translation.translateZ(-30.0F);
delete data;
renderer->core.texture.repository.addByMesh(result, FileUtils::getCwd(),
"png");
result->playAnimation(0, result->getFramesCount() - 1);
result->setAnimSpeed(0.15F);
return result;
}
Sprite* get2DPicture(Renderer* renderer) {
auto* sprite = new Sprite;
sprite->size.set(128.0F, 128.0F);
sprite->position.set(500.0F, 280.0F);
renderer->core.texture.repository.add(FileUtils::fromCwd("reward.png"))
->addLink(sprite->getId());
return sprite;
}
StdpipOptions* getRenderingOptions() {
auto* options = new StdpipOptions();
auto* ambientColor = new Color(32.0F, 32.0F, 32.0F, 128.0F);
auto* directionalColors = new Color[3];
for (int i = 0; i < 3; i++) directionalColors[i].set(0.0F, 0.0F, 0.0F, 1.0F);
auto* directionalDirections = new Vec4[3];
for (int i = 0; i < 3; i++)
directionalDirections[i].set(1.0F, 1.0F, 1.0F, 1.0F);
auto* lightingOptions = new StdpipLightingOptions(); // Memory leak!
lightingOptions->ambientColor = ambientColor;
lightingOptions->directionalColors = directionalColors;
lightingOptions->directionalDirections = directionalDirections;
options->shadingType = Tyra::StdpipShadingGouraud;
options->blendingEnabled = true;
options->antiAliasingEnabled = false;
options->lighting = lightingOptions;
directionalDirections[0].set(-1.0F, 0.0F, 0.0F);
directionalColors[0].set(0.0F, 96.0F, 0.0F);
directionalDirections[1].set(1.0F, 0.0F, 0.0F);
directionalColors[1].set(96.0F, 0.0F, 0.0F);
return options;
}
} // namespace Tyra