overloads, tutorial 04 init

This commit is contained in:
h4570
2022-08-21 19:44:47 +02:00
parent 409ee294eb
commit 4fa65fc535
25 changed files with 232 additions and 77 deletions
-1
View File
@@ -29,7 +29,6 @@ class Tutorial02 : public Game {
Engine* engine;
Sprite sprite;
Texture* texture;
};
} // namespace Tyra
+3 -13
View File
@@ -13,20 +13,10 @@
namespace Tyra {
Tutorial02::Tutorial02(Engine* t_engine) : engine(t_engine) {
/** Lets set default value, to prevent nullptr bugs */
texture = nullptr;
}
Tutorial02::Tutorial02(Engine* t_engine) : engine(t_engine) {}
Tutorial02::~Tutorial02() {
if (texture != nullptr) {
/**
* free() function in texture repository is
* removing texture from repository and calling
* texture destructor
*/
engine->renderer.core.texture.repository.free(texture);
}
engine->renderer.getTextureRepository().freeBySprite(sprite);
}
void Tutorial02::init() {
@@ -111,7 +101,7 @@ void Tutorial02::loadTexture() {
* 8bpp and 4bpp are the fastest.
* All of these formats can be easily exported via GIMP.
*/
texture = textureRepository.add(filepath);
auto* texture = textureRepository.add(filepath);
/** Let's assign this texture to sprite. */
texture->addLink(sprite.id);
+2 -1
View File
@@ -14,12 +14,13 @@
namespace Tyra {
Tutorial03::Tutorial03(Engine* t_engine) : engine(t_engine) {
/** Lets set default value, to prevent nullptr bugs */
textureAtlas = nullptr;
}
Tutorial03::~Tutorial03() {
if (textureAtlas != nullptr) {
engine->renderer.core.texture.repository.free(textureAtlas);
engine->renderer.getTextureRepository().free(textureAtlas);
}
}
+24
View File
@@ -0,0 +1,24 @@
TARGET := tutorial_04.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.tutorials-base
+4
View File
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
+35
View File
@@ -0,0 +1,35 @@
/*
# _____ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licensed under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <tyra>
#include <memory.h>
namespace Tyra {
class Tutorial04 : public Game {
public:
Tutorial04(Engine* engine);
~Tutorial04();
void init();
void loop();
private:
void loadMesh();
Engine* engine;
std::unique_ptr<StaticMesh> mesh;
StaPipOptions renderOptions;
};
} // namespace Tyra
+4
View File
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
+4
View File
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
+4
View File
@@ -0,0 +1,4 @@
$ConfigFile = Join-Path $PSScriptRoot '../../windows-pcsx2.ps1'
. $ConfigFile
RunPCSX2
+26
View File
@@ -0,0 +1,26 @@
/*
# _____ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licensed under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "engine.hpp"
#include "tutorial_04.hpp"
/**
* In this tutorial we will learn:
* - How to get pad input and move the camera
* - What is static pipeline and how to use it
* - What is mesh (StaticMesh) and how to load it from .obj file
*/
int main() {
Tyra::Engine engine;
Tyra::Tutorial04 game(&engine);
engine.run(&game);
return 0;
}
+39
View File
@@ -0,0 +1,39 @@
/*
# _____ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licensed under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include <tyra>
#include "tutorial_04.hpp"
namespace Tyra {
Tutorial04::Tutorial04(Engine* t_engine) : engine(t_engine) {}
Tutorial04::~Tutorial04() {
engine->renderer.getTextureRepository().freeByMesh(mesh.get());
}
void Tutorial04::init() { loadMesh(); }
void Tutorial04::loop() {}
void Tutorial04::loadMesh() {
ObjLoader loader;
ObjLoaderOptions options;
options.flipUVs = true;
options.scale = 200.0F;
auto data = loader.load(FileUtils::fromCwd("de_dust2/de_dust2.obj"), options);
mesh = std::make_unique<StaticMesh>(data.get());
engine->renderer.getTextureRepository().addByMesh(
mesh.get(), FileUtils::fromCwd("de_dust2/"), "png");
}
} // namespace Tyra