Skip to content

Commit

Permalink
#15 3DS port (WIP); split atlas to rooms, sprites, objects and glyphs…
Browse files Browse the repository at this point in the history
…; rename osGetTime to osGetTimeMS; reverberation effect optimizations;
  • Loading branch information
XProger committed Mar 9, 2019
1 parent a412d13 commit 3ed6c98
Show file tree
Hide file tree
Showing 28 changed files with 1,552 additions and 176 deletions.
75 changes: 60 additions & 15 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
#undef OS_FILEIO_CACHE

extern int WEBGL_VERSION;
#elif _3DS
#define _OS_3DS 1
#define _GAPI_C3D 1

#undef OS_PTHREAD_MT
#elif _PSP
#define _OS_PSP 1
#define _GAPI_GU 1
Expand All @@ -82,10 +87,10 @@

#undef OS_PTHREAD_MT
#elif __SWITCH__
#define _OS_NX 1
#define _GAPI_GL 1
#define _OS_SWITCH 1
#define _GAPI_GL 1

#undef OS_PTHREAD_MT
#undef OS_PTHREAD_MT
#endif

#ifndef _OS_PSP
Expand Down Expand Up @@ -117,7 +122,7 @@ extern void osMutexFree (void *obj);
extern void osMutexLock (void *obj);
extern void osMutexUnlock (void *obj);

extern int osGetTime ();
extern int osGetTimeMS ();

extern bool osJoyReady (int index);
extern void osJoyVibrate (int index, float L, float R);
Expand Down Expand Up @@ -190,6 +195,7 @@ namespace Core {
struct Support {
int maxVectors;
int maxAniso;
int texMinSize;
bool shaderBinary;
bool VAO;
bool depthTexture;
Expand Down Expand Up @@ -291,7 +297,7 @@ namespace Core {
bool isQuit;

int getTime() {
return osGetTime();
return osGetTimeMS();
}

void resetTime() {
Expand All @@ -304,6 +310,24 @@ namespace Core {
}
}

#ifdef PROFILE
struct TimingCPU {
int &result;

TimingCPU(int &result) : result(result) {
result = Core::getTime();
}

~TimingCPU() {
result = Core::getTime() - result;
}
};

#define PROFILE_CPU_TIMING(result) TimingCPU timingCPU(result)
#else
#define PROFILE_CPU_TIMING(result)
#endif

#include "input.h"
#include "sound.h"

Expand Down Expand Up @@ -556,6 +580,10 @@ namespace Core {
Vertex *vBuffer;
#endif

#ifdef _GAPI_C3D
void *VAO;
#endif

int32 basisCount;
Basis *basis;
} active;
Expand All @@ -571,6 +599,7 @@ namespace Core {
int fpsTime;
#ifdef PROFILE
int tFrame;
int video;
#endif

Stats() : frame(0), frameIndex(0), fps(0), fpsTime(0) {}
Expand All @@ -584,6 +613,8 @@ namespace Core {
LOG("FPS: %d DIP: %d TRI: %d RT: %d CB: %d\n", fps, dips, tris, rt, cb);
#ifdef PROFILE
LOG("frame time: %d mcs\n", tFrame / 1000);
LOG("sound: mix %d rev %d ren %d/%d ogg %d\n", Sound::stats.mixer, Sound::stats.reverb, Sound::stats.render[0], Sound::stats.render[1], Sound::stats.ogg);
LOG("video: %d\n", video);
#endif
fps = frame;
frame = 0;
Expand All @@ -600,8 +631,8 @@ namespace Core {
#include "gapi_gl.h"
#elif _GAPI_D3D9
#include "gapi_d3d9.h"
#elif _GAPI_GX
#include "gapi_gx.h"
#elif _OS_3DS
#include "gapi_c3d.h"
#elif _GAPI_GU
#include "gapi_gu.h"
#elif _GAPI_GXM
Expand Down Expand Up @@ -654,10 +685,13 @@ namespace Core {
}

void init() {
memset(&support, 0, sizeof(support));
LOG("OpenLara (%s)\n", version);

x = y = 0;

memset(&support, 0, sizeof(support));
support.texMinSize = 1;

#ifdef USE_INFLATE
tinf_init();
#endif
Expand Down Expand Up @@ -697,12 +731,14 @@ namespace Core {
}
eye = 0.0f;

{ // init 1x1 textures
uint32 data = 0xFFFFFFFF;
whiteTex = new Texture(1, 1, 1, FMT_RGBA, OPT_NEAREST, &data);
whiteCube = new Texture(1, 1, 1, FMT_RGBA, OPT_CUBEMAP, &data);
data = 0;
blackTex = new Texture(1, 1, 1, FMT_RGBA, OPT_NEAREST, &data);
{ // init dummy textures
uint32 *data = new uint32[SQR(support.texMinSize)];
memset(data, 0xFF, SQR(support.texMinSize) * sizeof(data[0]));
whiteTex = new Texture(support.texMinSize, support.texMinSize, 1, FMT_RGBA, OPT_NEAREST, data);
whiteCube = new Texture(support.texMinSize, support.texMinSize, 1, FMT_RGBA, OPT_CUBEMAP, data);
memset(data, 0x00, SQR(support.texMinSize) * sizeof(data[0]));
blackTex = new Texture(support.texMinSize, support.texMinSize, 1, FMT_RGBA, OPT_NEAREST, data);
delete[] data;
}

{ // generate dithering texture
Expand Down Expand Up @@ -813,6 +849,15 @@ namespace Core {
settings.detail.setLighting (Core::Settings::MEDIUM);
#endif

#ifdef _OS_3DS
settings.detail.setFilter (Core::Settings::MEDIUM);
settings.detail.setLighting (Core::Settings::LOW);
settings.detail.setShadows (Core::Settings::LOW);
settings.detail.setWater (Core::Settings::LOW);

settings.audio.reverb = false;
#endif

#ifdef FFP
settings.detail.setFilter (Core::Settings::MEDIUM);
settings.detail.setLighting (Core::Settings::LOW);
Expand Down Expand Up @@ -1006,7 +1051,7 @@ namespace Core {
Core::active.basis = basis;
Core::active.basisCount = count;

Core::active.shader->setParam(uBasis, basis[0], count);
Core::active.shader->setParam(uBasis, *(vec4*)basis, count * 2);
}

void setMaterial(float diffuse, float ambient, float specular, float alpha) {
Expand Down
43 changes: 42 additions & 1 deletion src/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3010,7 +3010,7 @@ namespace TR {
((uint64)((const char*)(str))[4] << 32) | ((uint64)((const char*)(str))[5] << 40) | ((uint64)((const char*)(str))[6] << 48) | ((uint64)((const char*)(str))[7] << 56))

void readSAT(Stream &stream) {
#ifndef _OS_PSP
#if !defined(_OS_PSP) && !defined(_OS_3DS)
Room *room = NULL;

while (stream.pos < stream.size) {
Expand Down Expand Up @@ -3843,6 +3843,7 @@ namespace TR {
initAnimTex();
initExtra();
initCutscene();
initTextureTypes();

gObjectTextures = objectTextures;
gSpriteTextures = spriteTextures;
Expand Down Expand Up @@ -3986,6 +3987,46 @@ namespace TR {
}
}

void initTextureTypes() {
// rooms geometry
for (int roomIndex = 0; roomIndex < roomsCount; roomIndex++) {
TR::Room &room = rooms[roomIndex];
TR::Room::Data &data = room.data;
for (int i = 0; i < data.fCount; i++) {
Face &f = data.faces[i];
ASSERT(!f.colored);
ASSERT(f.flags.texture < objectTexturesCount);
TR::TextureInfo &t = objectTextures[f.flags.texture];
t.type = TEX_TYPE_ROOM;
}
}

// rooms static meshes
for (int staticMeshIndex = 0; staticMeshIndex < staticMeshesCount; staticMeshIndex++) {
TR::StaticMesh *staticMesh = &staticMeshes[staticMeshIndex];
if (!meshOffsets[staticMesh->mesh]) continue;
TR::Mesh &mesh = meshes[meshOffsets[staticMesh->mesh]];

for (int i = 0; i < mesh.fCount; i++) {
TR::Face &f = mesh.faces[i];
ASSERT(f.colored || f.flags.texture < objectTexturesCount);
if (f.colored) continue;
TR::TextureInfo &t = objectTextures[f.flags.texture];
t.type = TEX_TYPE_ROOM;
}
}

// animated textures
for (int animTextureIndex = 0; animTextureIndex < animTexturesCount; animTextureIndex++) {
AnimTexture &animTex = animTextures[animTextureIndex];

for (int j = 0; j < animTex.count; j++) {
TextureInfo &t = objectTextures[animTex.textures[j]];
t.type = TEX_TYPE_ROOM;
}
}
}

static Entity::Type convToInv(Entity::Type type) {
for (int j = 0; j < COUNT(ITEM_TO_INV); j++)
if (type == ITEM_TO_INV[j].src) {
Expand Down
6 changes: 1 addition & 5 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,7 @@ namespace Game {
void frameEnd() {
if (Core::settings.version == SETTINGS_READING) return;

if (level) {
level->setupBinding();
level->glyphs->bind(sDiffuse);
UI::renderTouch();
}
UI::renderTouch();
Core::endFrame();
}

Expand Down
Loading

0 comments on commit 3ed6c98

Please sign in to comment.