From 017446b9f799e48549db0e028f0fffcc0b5b66e4 Mon Sep 17 00:00:00 2001 From: XProger Date: Mon, 18 Apr 2022 01:07:03 +0300 Subject: [PATCH] win_fixed start working on GL1 renderer, ARM FIQ test --- src/fixed/common.cpp | 57 ++++ src/fixed/common.h | 121 ++++++- src/fixed/draw.h | 14 +- src/fixed/enemy.h | 2 +- src/fixed/fmt/phd.h | 95 ++++++ src/fixed/fmt/pkd.h | 124 +++++++ src/fixed/game.h | 12 +- src/fixed/lara.h | 2 +- src/fixed/level.h | 141 ++------ src/fixed/render/gl1.cpp | 250 +++++++++++++++ src/platform/gba/OpenLara.vcxproj | 1 + src/platform/gba/asm/rasterizeGT.s | 9 +- src/platform/win_fixed/OpenLara.rc | Bin 0 -> 120 bytes src/platform/win_fixed/OpenLara.sln | 25 ++ src/platform/win_fixed/OpenLara.vcxproj | 140 ++++++++ .../win_fixed/OpenLara.vcxproj.filters | 46 +++ src/platform/win_fixed/icon.ico | Bin 0 -> 7406 bytes src/platform/win_fixed/main.cpp | 302 ++++++++++++++++++ src/platform/win_fixed/sound.cpp | 51 +++ 19 files changed, 1263 insertions(+), 129 deletions(-) create mode 100644 src/fixed/fmt/phd.h create mode 100644 src/fixed/fmt/pkd.h create mode 100644 src/fixed/render/gl1.cpp create mode 100644 src/platform/win_fixed/OpenLara.rc create mode 100644 src/platform/win_fixed/OpenLara.sln create mode 100644 src/platform/win_fixed/OpenLara.vcxproj create mode 100644 src/platform/win_fixed/OpenLara.vcxproj.filters create mode 100644 src/platform/win_fixed/icon.ico create mode 100644 src/platform/win_fixed/main.cpp create mode 100644 src/platform/win_fixed/sound.cpp diff --git a/src/fixed/common.cpp b/src/fixed/common.cpp index 6d6fba3..9f1930a 100644 --- a/src/fixed/common.cpp +++ b/src/fixed/common.cpp @@ -1593,4 +1593,61 @@ void dmaCopy(const void* src, void* dst, uint32 size) memcpy(dst, src, size); #endif } + +Stream::Stream(const uint8* data, int32 size) : data(data), size(size), pos(0) +{ + // +} + +const void* Stream::getPtr() +{ + return data + pos; +} + +uint8 Stream::read8u() +{ + return data[pos++]; +} + +uint16 Stream::read16u() +{ + uint32 a = data[pos++]; + uint32 b = data[pos++]; + + if (bigEndian) { + return b | (a << 8); + } else { + return a | (b << 8); + } +} + +uint32 Stream::read32u() +{ + uint32 a = data[pos++]; + uint32 b = data[pos++]; + uint32 c = data[pos++]; + uint32 d = data[pos++]; + + if (bigEndian) { + return d | (c << 8) | (b << 16) | (a << 24); + } else { + return a | (b << 8) | (c << 16) | (d << 24); + } +} + +int8 Stream::read8s() +{ + return (int8)read8u(); +} + +int16 Stream::read16s() +{ + return (int16)read16u(); +} + +int32 Stream::read32s() +{ + return (int32)read32u(); +} + #endif diff --git a/src/fixed/common.h b/src/fixed/common.h index 7779954..cb4bab7 100644 --- a/src/fixed/common.h +++ b/src/fixed/common.h @@ -8,13 +8,47 @@ // #define PROFILE_SOUNDTIME #endif -#if defined(_WIN32) +// supported formats +// level +#define LVL_FMT_PHD (1 << 0) +#define LVL_FMT_PSX (1 << 1) +#define LVL_FMT_SAT (1 << 2) +#define LVL_FMT_TR2 (1 << 3) +#define LVL_FMT_TR4 (1 << 4) +#define LVL_FMT_PKD (1 << 5) +// video +#define FMV_FMT_RPL (1 << 6) +#define FMV_FMT_STR (1 << 7) +#define FMV_FMT_MP1 (1 << 8) +// audio +#define SND_FMT_PCM (1 << 9) +#define SND_FMT_ADPCM (1 << 10) +#define SND_FMT_IMA (1 << 11) +#define SND_FMT_VAG (1 << 12) +#define SND_FMT_XA (1 << 13) +#define SND_FMT_OGG (1 << 14) +#define SND_FMT_MP3 (1 << 15) + +#if defined(__WIN32__) + #define USE_DIV_TABLE + #define MODEHW + + extern int FRAME_WIDTH; + extern int FRAME_HEIGHT; + + #define USE_FMT (LVL_FMT_PHD) + + #define _CRT_SECURE_NO_WARNINGS + #include +#elif defined(__GBA_WIN__) #define USE_DIV_TABLE #define MODE4 #define FRAME_WIDTH 240 #define FRAME_HEIGHT 160 + #define USE_FMT (LVL_FMT_PKD) + #define _CRT_SECURE_NO_WARNINGS #include #elif defined(__GBA__) @@ -27,7 +61,9 @@ #define FRAME_WIDTH 240 #define FRAME_HEIGHT 160 - #include + #define USE_FMT (LVL_FMT_PKD) + +#include #elif defined(__NDS__) #define USE_DIV_TABLE @@ -35,7 +71,9 @@ #define FRAME_WIDTH 256 #define FRAME_HEIGHT 192 - #include + #define USE_FMT (LVL_FMT_PSX) + +#include #include #include #elif defined(__TNS__) @@ -45,6 +83,8 @@ #define FRAME_WIDTH 320 #define FRAME_HEIGHT 240 + #define USE_FMT (LVL_FMT_PKD) + #include #elif defined(__DOS__) #define USE_DIV_TABLE @@ -53,6 +93,8 @@ #define FRAME_WIDTH 320 #define FRAME_HEIGHT 200 + #define USE_FMT (LVL_FMT_PKD) + #include #include #include @@ -68,6 +110,8 @@ #define FRAME_WIDTH 320 #define FRAME_HEIGHT 240 + #define USE_FMT (LVL_FMT_PKD) + #include #include #include @@ -100,11 +144,19 @@ #define FRAME_WIDTH 320 #define FRAME_HEIGHT 224 + #define USE_FMT (LVL_FMT_PKD) + #include "32x.h" #else #error unsupported platform #endif +#ifdef _DEBUG + #define LOG(...) printf(__VA_ARGS__) +#else + #define LOG(...) +#endif + #if !defined(__3DO__) #include #endif @@ -116,6 +168,10 @@ #define VRAM_WIDTH (FRAME_WIDTH/2) // in shorts +#ifndef USE_FMT + #define USE_FMT (LVL_FMT_PHD | LVL_FMT_PSX | LVL_FMT_SAT | LVL_FMT_TR2 | LVL_FMT_TR4) +#endif + // Optimization flags ========================================================= #ifdef __GBA__ // hide dead enemies after a while to reduce the number of polygons on the screen @@ -257,7 +313,7 @@ X_INLINE int32 abs(int32 x) { #define EWRAM_CODE #endif -#if defined(_WIN32) +#if defined(__WIN32__) || defined(__GBA_WIN__) #define ASSERT(x) { if (!(x)) { DebugBreak(); } } #else #define ASSERT(x) @@ -271,7 +327,7 @@ X_INLINE int32 abs(int32 x) { #define IME_ENABLE() #endif -#if defined(_WIN32) +#if defined(__GBA__WIN__) extern uint16 fb[VRAM_WIDTH * FRAME_HEIGHT]; #elif defined(__GBA__) extern uint32 fb; @@ -342,7 +398,7 @@ extern void* osLoadLevel(const char* name); #define PROFILE_STOP(value) {\ value += (osGetSystemTimeMS() - g_timer);\ } - #elif defined(_WIN32) + #elif defined(__WIN32__) || defined(__GBA_WIN__) extern LARGE_INTEGER g_timer; extern LARGE_INTEGER g_current; @@ -352,7 +408,7 @@ extern void* osLoadLevel(const char* name); #define PROFILE_STOP(value) {\ QueryPerformanceCounter(&g_current);\ - value += (g_current.QuadPart - g_timer.QuadPart);\ + value += uint32(g_current.QuadPart - g_timer.QuadPart);\ } #elif defined(__GBA__) #ifdef PROFILE_SOUNDTIME @@ -431,7 +487,15 @@ extern int32 fps; #define SND_VOL_SHIFT 6 #define SND_PITCH_SHIFT 7 -#if defined(_WIN32) +#if defined(__WIN32__) + #define SND_SAMPLES 1024 + #define SND_OUTPUT_FREQ 22050 + #define SND_SAMPLE_FREQ 22050 + #define SND_ENCODE(x) ((x) + 128) + #define SND_DECODE(x) ((x) - 128) + #define SND_MIN -128 + #define SND_MAX 127 +#elif defined(__GBA_WIN__) #define SND_SAMPLES 1024 #define SND_OUTPUT_FREQ 22050 #define SND_SAMPLE_FREQ 22050 @@ -831,8 +895,11 @@ struct RoomVertex { #if defined(__3DO__) uint16 xyz565; -#else +#elif defined(__GBA__) || defined(__32X__) uint8 x, y, z, g; +#else + uint8 x, y, z; + uint8 cR, cG, cB; #endif }; @@ -2063,9 +2130,17 @@ struct CameraFrame int16 roll; }; +enum Version +{ + VER_TR1_GBA, + VER_TR1_3DO, + VER_TR1_32X, + VER_TR1_PC +}; + struct Level { - uint32 magic; + uint32 version; uint16 tilesCount; uint16 roomsCount; @@ -2788,6 +2863,10 @@ void matrixFrameLerp(const void* pos, const void* anglesA, const void* anglesB, void matrixSetView(const vec3i &pos, int32 angleX, int32 angleY); void renderInit(); +void renderFree(); +void renderSwap(); +void renderLevelInit(); +void renderLevelFree(); void setViewport(const RectMinMax &vp); void setPaletteIndex(int32 index); void clear(); @@ -2805,6 +2884,8 @@ int32 getTextWidth(const char* text); void drawInit(); void drawFree(); +void drawLevelInit(); +void drawLevelFree(); void drawText(int32 x, int32 y, const char* text, TextAlign align); void drawModel(const ItemObj* item); void drawItem(const ItemObj* item); @@ -2852,4 +2933,24 @@ void updateFading(int32 frames); void dmaFill(void* dst, uint8 value, uint32 count); void dmaCopy(const void* src, void* dst, uint32 size); +struct Stream +{ + const uint8* data; + int32 size; + int32 pos; + bool bigEndian; + + Stream(const uint8* data, int32 size); + + const void* getPtr(); + + uint8 read8u(); + uint16 read16u(); + uint32 read32u(); + + int8 read8s(); + int16 read16s(); + int32 read32s(); +}; + #endif diff --git a/src/fixed/draw.h b/src/fixed/draw.h index c41f57d..93d233b 100644 --- a/src/fixed/draw.h +++ b/src/fixed/draw.h @@ -14,6 +14,8 @@ RoomTriangle roomTri[64]; void drawInit() { + renderInit(); + for (int32 i = 0; i < MAX_RAND_TABLE; i++) { gRandTable[i] = (rand_draw() >> 5) - 511; @@ -40,7 +42,17 @@ void drawInit() void drawFree() { - // + renderFree(); +} + +void drawLevelInit() +{ + renderLevelInit(); +} + +void drawLevelFree() +{ + renderLevelFree(); } void calcLightingDynamic(const Room* room, const vec3i &point) diff --git a/src/fixed/enemy.h b/src/fixed/enemy.h index 7d1047f..70db0fe 100644 --- a/src/fixed/enemy.h +++ b/src/fixed/enemy.h @@ -695,7 +695,7 @@ struct Enemy : ItemObj sg->vSpeed = vSpeed; sg->hSpeed = hSpeed; sg->health = health; - sg->mood = mood; + sg->mood = uint8(mood); sg->waterState = waterState; return data + sizeof(EnemySave); diff --git a/src/fixed/fmt/phd.h b/src/fixed/fmt/phd.h new file mode 100644 index 0000000..f487f2b --- /dev/null +++ b/src/fixed/fmt/phd.h @@ -0,0 +1,95 @@ +#ifndef H_PHD +#define H_PHD + +#include "common.h" + +struct PHD +{ + struct RoomVertex + { + int16 x, y, z; + uint16 lighting; + }; + + struct RoomQuad + { + uint16 indices[4]; + uint16 flags; + }; + + struct RoomTriangle + { + uint16 indices[3]; + uint16 flags; + }; + + struct RoomSprite + { + uint16 index; + uint16 texture; + }; + + struct RoomPortal + { + int16 roomIndex; + vec3s normal; + vec3s vertices[4]; + }; +}; + +RoomInfo roomsInfo_phd[MAX_ROOMS]; + +bool read_PHD(const uint8* data) +{ +/* TODO + Stream stream(data, 0); + + uint32 magic = stream.read32u(); + if (magic != 0x00000020) + { + LOG("Unsupported level format\n"); + return; + } + + level.version = VER_TR1_PC; + + level.tilesCount = stream.read32u(); + level.tiles = (uint8*)stream.getPtr(); + stream.pos += 4; + + level.roomsCount = stream.read16u(); + level.roomsInfo = phd_roomsInfo; + + for (uint32 i = 0; i < level.roomsCount; i++) + { + RoomInfo* info = phd_roomsInfo + i; + + info->x = stream.read32s(); + info->z = stream.read32s(); + info->yBottom = stream.read32s(); + info->yTop = stream.read32s(); + + info->verticesCount = stream.read16u(); + info->data.vertices = (RoomVertex*)stream.getPtr(); + stream.pos += sizeof(PHD::RoomVertex) * info->verticesCount; + + info->quadsCount = stream.read16u(); + info->data.quads = (RoomQuad*)stream.getPtr(); + stream.pos += sizeof(PHD::RoomQuad) * info->quadsCount; + + info->trianglesCount = stream.read16u(); + info->data.triangles = (RoomTriangle*)stream.getPtr(); + stream.pos += sizeof(PHD::RoomTriangle) * info->trianglesCount; + + info->spritesCount = stream.read16u(); + info->data.sprites = (RoomSprite*)stream.getPtr(); + stream.pos += sizeof(PHD::RoomSprite) * info->spritesCount; + + info->portalsCount = stream.read16u(); + info->data.portals = (RoomPortal*)stream.getPtr(); + stream.pos += sizeof(PHD::RoomPortal) * info->portalsCount; + } +*/ + return false; +} +#endif diff --git a/src/fixed/fmt/pkd.h b/src/fixed/fmt/pkd.h new file mode 100644 index 0000000..e7ed88a --- /dev/null +++ b/src/fixed/fmt/pkd.h @@ -0,0 +1,124 @@ +#ifndef H_PKD +#define H_PKD + +#include "common.h" + +bool read_PKD(const uint8* data) +{ + memcpy(&level, data, sizeof(level)); + + { // fix level data offsets + uint32* ptr = (uint32*)&level.palette; + while (ptr <= (uint32*)&level.soundOffsets) + { + *ptr++ += (uint32)data; + } + } + + { // prepare rooms + for (int32 i = 0; i < level.roomsCount; i++) + { + Room* room = rooms + i; + room->info = level.roomsInfo + i; + room->data = room->info->data; + + for (uint32 j = 0; j < sizeof(room->data) / 4; j++) + { + int32* x = (int32*)&room->data + j; + *x += (int32)data; + } + + room->sectors = room->data.sectors; + room->firstItem = NULL; + } + } + +#ifndef MODEHW + // initialize global pointers + gBrightness = -128; + palSet(level.palette, gSettings.video_gamma << 4, gBrightness); + memcpy(gLightmap, level.lightmap, sizeof(gLightmap)); +#endif + + // prepare models // TODO prerocess + memset(models, 0, sizeof(models)); + for (int32 i = 0; i < level.modelsCount; i++) + { + const Model* model = level.models + i; + ASSERT(model->type < MAX_MODELS); + models[model->type] = *model; + } + level.models = models; + + // prepare meshes + for (int32 i = 0; i < level.meshesCount; i++) + { + meshes[i] = (Mesh*)((uint8*)level.meshes + level.meshOffsets[i]); + } + level.meshes = meshes; + + // prepare static meshes // TODO preprocess + memset(staticMeshes, 0, sizeof(staticMeshes)); + for (int32 i = 0; i < level.staticMeshesCount; i++) + { + const StaticMesh* staticMesh = level.staticMeshes + i; + + ASSERT(staticMesh->id < MAX_STATIC_MESHES); + staticMeshes[staticMesh->id] = *staticMesh; + } + level.staticMeshes = staticMeshes; + + // prepare sprites // TODO preprocess + for (int32 i = 0; i < level.spriteSequencesCount; i++) + { + const SpriteSeq* spriteSeq = level.spriteSequences + i; + + if (spriteSeq->type >= TR1_ITEM_MAX) // WTF? + continue; + + Model* m = models + spriteSeq->type; + m->count = int8(spriteSeq->count); + m->start = spriteSeq->start; + } + +#ifdef ROM_READ + // prepare textures (required by anim tex logic) + memcpy(textures, level.textures, level.texturesCount * sizeof(Texture)); + level.textures = textures; + + // prepare sprites (TODO preprocess tile address in packer) + memcpy(sprites, level.sprites, level.spritesCount * sizeof(Sprite)); + level.sprites = sprites; + + // prepare boxes + memcpy(boxes, level.boxes, level.boxesCount * sizeof(Box)); + level.boxes = boxes; + + // prepare fixed cameras + memcpy(cameras, level.cameras, level.camerasCount * sizeof(FixedCamera)); + level.cameras = cameras; +#endif + +#ifdef __3DO__ + for (int32 i = 0; i < level.texturesCount; i++) + { + Texture* tex = level.textures + i; + tex->data += intptr_t(RAM_TEX); + } +#else + // TODO preprocess in packer + for (int32 i = 0; i < level.texturesCount; i++) + { + level.textures[i].tile += (uint32)level.tiles; + } + + for (int32 i = 0; i < level.spritesCount; i++) + { + level.sprites[i].tile += (uint32)level.tiles; + } +#endif + + return true; +} + +#endif diff --git a/src/fixed/game.h b/src/fixed/game.h index 4d45533..f19e3c4 100644 --- a/src/fixed/game.h +++ b/src/fixed/game.h @@ -85,7 +85,7 @@ bool gameLoad() void gameInit(const char* name) { - renderInit(); + drawInit(); gSaveGame.dataSize = 0; @@ -104,6 +104,12 @@ void gameInit(const char* name) startLevel(name); } +void gameFree() +{ + drawLevelFree(); + drawFree(); +} + void resetLara(int32 index, int32 roomIndex, const vec3i &pos, int32 angleY) { Lara* lara = players[index]; @@ -123,7 +129,7 @@ void resetLara(int32 index, int32 roomIndex, const vec3i &pos, int32 angleY) void gameLoadLevel(const void* data) { - drawFree(); + drawLevelFree(); memset(&gSaveGame, 0, sizeof(gSaveGame)); memset(enemiesExtra, 0, sizeof(enemiesExtra)); @@ -217,7 +223,7 @@ void gameLoadLevel(const void* data) //resetLara(0, 44, _vec3i(73798, 2304, 9819), ANGLE_90); // uw gears } - drawInit(); + drawLevelInit(); } void startLevel(const char* name) diff --git a/src/fixed/lara.h b/src/fixed/lara.h index 7bf8ca5..b26abd0 100644 --- a/src/fixed/lara.h +++ b/src/fixed/lara.h @@ -2745,7 +2745,7 @@ struct Lara : ItemObj if (keys & IK_X) input |= IN_WALK; if (keys & IK_Y) input |= IN_UP | IN_DOWN; if (keys & IK_Z) input |= IN_LOOK; - #elif defined(__GBA__) || defined(_WIN32) + #elif defined(__GBA__) || defined(__GBA_WIN__) || defined(__WIN32__) int32 ikA, ikB; if (gSettings.controls_swap) { diff --git a/src/fixed/level.h b/src/fixed/level.h index 0769749..f2cb3b9 100644 --- a/src/fixed/level.h +++ b/src/fixed/level.h @@ -2,7 +2,6 @@ #define H_LEVEL #include "common.h" -#include "camera.h" Level level; @@ -33,121 +32,21 @@ EWRAM_DATA ItemObj* ItemObj::sFirstFree; EWRAM_DATA int32 gBrightness; -void readLevel_GBA(const uint8* data) -{ - memcpy(&level, data, sizeof(level)); - - { // fix level data offsets - uint32* ptr = (uint32*)&level.palette; - while (ptr <= (uint32*)&level.soundOffsets) - { - *ptr++ += (uint32)data; - } - } - - { // prepare rooms - for (int32 i = 0; i < level.roomsCount; i++) - { - Room* room = rooms + i; - room->info = level.roomsInfo + i; - room->data = room->info->data; - - for (uint32 j = 0; j < sizeof(room->data) / 4; j++) - { - int32* x = (int32*)&room->data + j; - *x += (int32)data; - } - - room->sectors = room->data.sectors; - room->firstItem = NULL; - } - } - -#ifndef MODEHW - // initialize global pointers - gBrightness = -128; - palSet(level.palette, gSettings.video_gamma << 4, gBrightness); - memcpy(gLightmap, level.lightmap, sizeof(gLightmap)); +#if (USE_FMT & (LVL_FMT_PHD | LVL_FMT_PSX)) + uint8 gLevelData[1024 * 1024]; #endif - // prepare models // TODO prerocess - memset(models, 0, sizeof(models)); - for (int32 i = 0; i < level.modelsCount; i++) - { - const Model* model = level.models + i; - ASSERT(model->type < MAX_MODELS); - models[model->type] = *model; - } - level.models = models; - - // prepare meshes - for (int32 i = 0; i < level.meshesCount; i++) - { - meshes[i] = (Mesh*)((uint8*)level.meshes + level.meshOffsets[i]); - } - level.meshes = meshes; - - // prepare static meshes // TODO preprocess - memset(staticMeshes, 0, sizeof(staticMeshes)); - for (int32 i = 0; i < level.staticMeshesCount; i++) - { - const StaticMesh* staticMesh = level.staticMeshes + i; - - ASSERT(staticMesh->id < MAX_STATIC_MESHES); - staticMeshes[staticMesh->id] = *staticMesh; - } - level.staticMeshes = staticMeshes; - - // prepare sprites // TODO preprocess - for (int32 i = 0; i < level.spriteSequencesCount; i++) - { - const SpriteSeq* spriteSeq = level.spriteSequences + i; - - if (spriteSeq->type >= TR1_ITEM_MAX) // WTF? - continue; - - Model* m = models + spriteSeq->type; - m->count = int8(spriteSeq->count); - m->start = spriteSeq->start; - } - -#ifdef ROM_READ - // prepare textures (required by anim tex logic) - memcpy(textures, level.textures, level.texturesCount * sizeof(Texture)); - level.textures = textures; - - // prepare sprites (TODO preprocess tile address in packer) - memcpy(sprites, level.sprites, level.spritesCount * sizeof(Sprite)); - level.sprites = sprites; - - // prepare boxes - memcpy(boxes, level.boxes, level.boxesCount * sizeof(Box)); - level.boxes = boxes; - - // prepare fixed cameras - memcpy(cameras, level.cameras, level.camerasCount * sizeof(FixedCamera)); - level.cameras = cameras; +#if (USE_FMT & LVL_FMT_PKD) + #include "fmt/pkd.h" #endif -#ifdef __3DO__ - for (int32 i = 0; i < level.texturesCount; i++) - { - Texture* tex = level.textures + i; - tex->data += intptr_t(RAM_TEX); - } -#else - // TODO preprocess in packer - for (int32 i = 0; i < level.texturesCount; i++) - { - level.textures[i].tile += (uint32)level.tiles; - } - - for (int32 i = 0; i < level.spritesCount; i++) - { - level.sprites[i].tile += (uint32)level.tiles; - } +#if (USE_FMT & LVL_FMT_PHD) + #include "fmt/phd.h" +#endif + +#if (USE_FMT & LVL_FMT_PSX) + #include "fmt/psx.h" #endif -} void readLevel(const uint8* data) { @@ -155,9 +54,27 @@ void readLevel(const uint8* data) dynSectorsCount = 0; //#endif - readLevel_GBA(data); + memset(&level, 0, sizeof(level)); gAnimTexFrame = 0; + +#if (USE_FMT & LVL_FMT_PKD) + if (read_PKD(data)) + return; +#endif + +#if (USE_FMT & LVL_FMT_PHD) + if (read_PHD(data)) + return; +#endif + +#if (USE_FMT & LVL_FMT_PSX) + if (read_PSX(data)) + return; +#endif + + LOG("Unsupported level format\n"); + ASSERT(false); } void animTexturesShift() diff --git a/src/fixed/render/gl1.cpp b/src/fixed/render/gl1.cpp new file mode 100644 index 0000000..65d3691 --- /dev/null +++ b/src/fixed/render/gl1.cpp @@ -0,0 +1,250 @@ +#ifndef H_GL1 +#define H_GL1 + +#include +#include +#include + +#define FIX2FLT (1.0f / 0x4000) + +#ifdef __WIN32__ +extern HWND hWnd; +extern HDC hDC; +HGLRC hRC; + +void renderInit() +{ + PIXELFORMATDESCRIPTOR pfd; + memset(&pfd, 0, sizeof(pfd)); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.cColorBits = 32; + pfd.cRedBits = 8; + pfd.cGreenBits = 8; + pfd.cBlueBits = 8; + pfd.cAlphaBits = 8; + pfd.cDepthBits = 24; + + int format = ChoosePixelFormat(hDC, &pfd); + SetPixelFormat(hDC, format, &pfd); + hRC = wglCreateContext(hDC); + + wglMakeCurrent(hDC, hRC); + + glClearColor(0, 0, 0, 1); + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + + + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.25f); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0f, float(FRAME_WIDTH) / float(FRAME_HEIGHT), 0.1f, VIEW_DIST); + glScalef(1, -1, 1); + glMatrixMode(GL_MODELVIEW); +} + +void renderFree() +{ + wglMakeCurrent(0, 0); + wglDeleteContext(hRC); + ReleaseDC(hWnd, hDC); +} + +void renderSwap() +{ + SwapBuffers(hDC); +} +#endif + +void renderLevelInit() +{ + // +} + +void renderLevelFree() +{ + // +} + +void setViewport(const RectMinMax &vp) +{ + //glViewport(vp.x0, vp.y0, vp.x1 - vp.x0, vp.y1 - vp.y0); + //glScissor() +} + +void setPaletteIndex(int32 index) +{ + +} + +void clear() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +void updateProjMatrix() +{ + glMatrixMode(GL_PROJECTION); + // + glMatrixMode(GL_MODELVIEW); +} + +void updateViewMatrix() +{ + const Matrix &m = matrixGet(); + float f[4][4]; + f[0][0] = m.e00 * FIX2FLT; + f[0][1] = m.e10 * FIX2FLT; + f[0][2] = -m.e20 * FIX2FLT; + f[0][3] = 0.0f; + + f[1][0] = m.e01 * FIX2FLT; + f[1][1] = m.e11 * FIX2FLT; + f[1][2] = -m.e21 * FIX2FLT; + f[1][3] = 0.0f; + + f[2][0] = m.e02 * FIX2FLT; + f[2][1] = m.e12 * FIX2FLT; + f[2][2] = -m.e22 * FIX2FLT; + f[2][3] = 0.0f; + + f[3][0] = m.e03 * FIX2FLT; + f[3][1] = m.e13 * FIX2FLT; + f[3][2] = -m.e23 * FIX2FLT; + f[3][3] = 1.0f; + + glLoadMatrixf(&f[0][0]); +} + +void renderRoom(const Room* room) +{ + updateViewMatrix(); + + const RoomVertex* vertices = room->data.vertices; + + glBegin(GL_QUADS); + for (int32 i = 0; i < room->info->quadsCount; i++) + { + const RoomQuad* f = room->data.quads + i; + for (int32 j = 0; j < 4; j++) + { + const RoomVertex* v = vertices + f->indices[j]; + glColor3ub(v->cR, v->cG, v->cB); + glVertex3s(v->x << 10, v->y << 8, v->z << 10); + } + } + glEnd(); + + glBegin(GL_TRIANGLES); + for (int32 i = 0; i < room->info->trianglesCount; i++) + { + const RoomTriangle* f = room->data.triangles + i; + for (int32 j = 0; j < 3; j++) + { + const RoomVertex* v = vertices + f->indices[j]; + glColor3ub(v->cR, v->cG, v->cB); + glVertex3s(v->x << 10, v->y << 8, v->z << 10); + } + } + glEnd(); +} + +void renderMesh(const Mesh* mesh) +{ + updateViewMatrix(); + + const uint8* ptr = (uint8*)mesh + sizeof(Mesh); + + const MeshVertex* vertices = (MeshVertex*)ptr; + ptr += mesh->vCount * sizeof(MeshVertex); + + MeshQuad* q = (MeshQuad*)ptr; + ptr += mesh->rCount * sizeof(MeshQuad); + + MeshTriangle* t = (MeshTriangle*)ptr; + + glBegin(GL_QUADS); + for (int32 i = 0; i < mesh->rCount + mesh->crCount; i++) + { + const MeshQuad* f = q + i; + for (int32 j = 0; j < 4; j++) + { + const MeshVertex* v = vertices + f->indices[j]; + glColor3ub(255, 255, 255); + glVertex3s(v->x, v->y, v->z); + } + } + glEnd(); + + glBegin(GL_TRIANGLES); + for (int32 i = 0; i < mesh->tCount + mesh->ctCount; i++) + { + const MeshTriangle* f = t + i; + for (int32 j = 0; j < 3; j++) + { + const MeshVertex* v = vertices + f->indices[j]; + glColor3ub(255, 255, 255); + glVertex3s(v->x, v->y, v->z); + } + } + glEnd(); +} + +void renderShadow(int32 x, int32 z, int32 sx, int32 sz) +{ + +} + +void renderSprite(int32 vx, int32 vy, int32 vz, int32 vg, int32 index) +{ + +} + +void renderGlyph(int32 vx, int32 vy, int32 index) +{ + +} + +void renderBorder(int32 x, int32 y, int32 width, int32 height, int32 shade, int32 color1, int32 color2, int32 z) +{ + +} + +void renderBar(int32 x, int32 y, int32 width, int32 value, BarType type) +{ + +} + +void renderBackground(const void* background) +{ + +} + +void* copyBackground() +{ + return NULL; +} + +int32 boxIsVisible_c(const AABBs* box) +{ + return 1; +} + +int32 sphereIsVisible_c(int32 x, int32 y, int32 z, int32 r) +{ + return 1; +} + +void flush_c() +{ + +} + +#endif diff --git a/src/platform/gba/OpenLara.vcxproj b/src/platform/gba/OpenLara.vcxproj index 26297ce..f90452d 100644 --- a/src/platform/gba/OpenLara.vcxproj +++ b/src/platform/gba/OpenLara.vcxproj @@ -22,6 +22,7 @@ + diff --git a/src/platform/gba/asm/rasterizeGT.s b/src/platform/gba/asm/rasterizeGT.s index 0e4c9d7..9a596cb 100644 --- a/src/platform/gba/asm/rasterizeGT.s +++ b/src/platform/gba/asm/rasterizeGT.s @@ -289,7 +289,14 @@ rasterizeGT_asm: .scanline_end: ldmfd sp!, {Lx, Lg, Lt} - +/* TEST FIQ + mrs r1, cpsr // save current program status reg + msr cpsr, #0x11 // switch to FIQ mode with extra r8-r14 regs + mov r8, #0 // trash FIQ regs and + mov r10, #0 // it shouldn't affect normal mode regs +// mov r11, r11 + msr cpsr, r1 // restore current program status reg +*/ ldmia sp, {sLdx, sLdg, sLdt, sRdx, sRdg} add Lx, sLdx diff --git a/src/platform/win_fixed/OpenLara.rc b/src/platform/win_fixed/OpenLara.rc new file mode 100644 index 0000000000000000000000000000000000000000..9f444cf0b3468779a5623b28f604e12354ea9188 GIT binary patch literal 120 wcmezW&zHfG!IQxch@BbyfwTf%NSrE!8A=S949N`n40#NCP?iz{F9R0?0ENd5LI3~& literal 0 HcmV?d00001 diff --git a/src/platform/win_fixed/OpenLara.sln b/src/platform/win_fixed/OpenLara.sln new file mode 100644 index 0000000..2079fe9 --- /dev/null +++ b/src/platform/win_fixed/OpenLara.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1022 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenLara", "OpenLara.vcxproj", "{6935E070-59B8-418A-9241-70BACB4217B5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6935E070-59B8-418A-9241-70BACB4217B5}.Debug|Win32.ActiveCfg = Debug|Win32 + {6935E070-59B8-418A-9241-70BACB4217B5}.Debug|Win32.Build.0 = Debug|Win32 + {6935E070-59B8-418A-9241-70BACB4217B5}.Release|Win32.ActiveCfg = Release|Win32 + {6935E070-59B8-418A-9241-70BACB4217B5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {969CCE82-3511-4643-9273-4B4554C4E782} + EndGlobalSection +EndGlobal diff --git a/src/platform/win_fixed/OpenLara.vcxproj b/src/platform/win_fixed/OpenLara.vcxproj new file mode 100644 index 0000000..29ded2d --- /dev/null +++ b/src/platform/win_fixed/OpenLara.vcxproj @@ -0,0 +1,140 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {6935E070-59B8-418A-9241-70BACB4217B5} + Win32Proj + OpenLara + 10.0 + + + + Application + true + v142 + NotSet + + + Application + false + v142 + true + NotSet + + + + + + + + + + + + + true + ..\..\..\bin\ + ..\..\fixed;$(VC_IncludePath);$(WindowsSDK_IncludePath) + $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86) + $(VC_IncludePath);$(WindowsSDK_IncludePath);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(FxCopDir);$(MSBuild_ExecutablePath);$(VC_LibraryPath_x86);$(SystemRoot) + $(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH); + + + false + ..\..\..\bin\ + false + ..\..\libs\openvr\;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86); + ..\..\libs\;..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + $(VC_IncludePath);$(WindowsSDK_IncludePath);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(FxCopDir);$(MSBuild_ExecutablePath);$(VC_LibraryPath_x86);$(SystemRoot) + $(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH); + + + + + + Level3 + Disabled + __WIN32__;NOMINMAX;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + Strict + + + MultiThreadedDebug + + + Console + true + glu32.lib;wsock32.lib;d3d9.lib;d3d11.lib;opengl32.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + Full + true + true + MINIMAL;NOMINMAX;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + false + false + MultiThreaded + Strict + false + Size + /d2noftol3 %(AdditionalOptions) + true + + + Windows + true + true + true + wcrt.lib;wsock32.lib;d3d9.lib;d3d11.lib;opengl32.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + true + false + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/platform/win_fixed/OpenLara.vcxproj.filters b/src/platform/win_fixed/OpenLara.vcxproj.filters new file mode 100644 index 0000000..795ae15 --- /dev/null +++ b/src/platform/win_fixed/OpenLara.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lang + + + fmt + + + fmt + + + + + {1d3e6f64-05d8-42b8-b2c6-c5bba7798936} + + + {f297223e-368f-46b9-9f41-3e8075cbc5c2} + + + \ No newline at end of file diff --git a/src/platform/win_fixed/icon.ico b/src/platform/win_fixed/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..7a5aed3341a523d0cfcb33802e456fc86bec6d0c GIT binary patch literal 7406 zcmeHLEl?dX5Z>JJE_e4Xm*;AqtVC6J@OWgWn3|%grt>_K4z7r*qKht?3UpOlgJ^3Q zQ0Z>|UUHW^z;p)YcIJMP{mJIr{A>ciAcxIOKq}!=3-AK}mP=bM0ls71VqwZ}W&o>a z0MD^VDzETisHdqiAN^+drUz+jYYVoww_#^z2X;tKcB+c zmoxZwaRHZ?m+7-n}lC5kI$ z7nCluUuFv}ztQKUYm9ki*RixrP;1Src~Cd@Yt1XYh>i&ok1TR_1JweN4ImOsz8QEVUO+W0a24v0ToJ=Iky#VC>Xa0#9TFjF#T#DYFEkE zJOoIVtb5dW1!{B_aGXil5R0Hy*MguJH7YrV@>aDzgjRuE+)xB*ig28H9GLM5 z4OBt99W5LQ9%j=*1sHB`q$5tQ`cP0zk${ga5;RXt=iDgbbLDaFnFq+wqz2nh$c1u& zOo-!L#6FNfFsMCfNd=NDX@ohtbIJ>B!MTr0L-WM9M$lJ&ffx#w7muCq54BLx{`=*p z%q0 zP{>UD+X%PAgTJF>MqD#67dygOG##$*EpHqW_x1-7YMRl>)%VFA01}+3YC_(E9uJUoa)c0Z_OEXwOYa9;URoDI*QJ!=U>nL`SkYo77a}_Auu8E7!kmI zyyx~z%F)xQkW!8$N2o64NIFF7GMSf?Co@iLDF<@F%y6BDdDoBH@lAHpbos60V-I+3 zkC?glmU%Yv(UwgSgmc&P$^3ksZa1Pd`P|$Zz|&0@f`s)ZJ+ThrGAyE_QXyw8(4>yPj5;5RG*SpzcjFdFWSNkoxoU;}4GbS`Mu%Xe0Udz>_sM`B1S5Q) z9**&6tw^9BbkT3iQQcE5P@Y0Z#U(yIPYL5g|F%r`>6E8XZbEs<@$s?FP3Zod?#|u4 zIciKaAuu8EL=Xt`6dtE6c(D~O7CGLoxb2!cPq%3`FkFur?ZEo%&wdwBufferLength = SND_SAMPLES; + waveHdr->lpData = (LPSTR)(soundBuffer + i * SND_SAMPLES); + waveOutPrepareHeader(waveOut, waveHdr, sizeof(WAVEHDR)); + waveOutWrite(waveOut, waveHdr, sizeof(WAVEHDR)); + } +} + +void soundFill() +{return; + WAVEHDR *waveHdr = waveBuf + curSoundBuffer; + waveOutUnprepareHeader(waveOut, waveHdr, sizeof(WAVEHDR)); + sndFill((uint8*)waveHdr->lpData, SND_SAMPLES); + waveOutPrepareHeader(waveOut, waveHdr, sizeof(WAVEHDR)); + waveOutWrite(waveOut, waveHdr, sizeof(WAVEHDR)); + curSoundBuffer ^= 1; +} + +LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_ACTIVATE: + { + keys = 0; + break; + } + + case WM_DESTROY : + { + PostQuitMessage(0); + break; + } + + case WM_KEYDOWN : + case WM_KEYUP : + case WM_SYSKEYUP : + case WM_SYSKEYDOWN : + { + InputKey key = IK_NONE; + switch (wParam) { + case VK_UP : key = IK_UP; break; + case VK_RIGHT : key = IK_RIGHT; break; + case VK_DOWN : key = IK_DOWN; break; + case VK_LEFT : key = IK_LEFT; break; + case 'A' : key = IK_B; break; + case 'S' : key = IK_A; break; + case 'Q' : key = IK_L; break; + case 'W' : key = IK_R; break; + case VK_RETURN : key = IK_START; break; + case VK_SPACE : key = IK_SELECT; break; + } + + if (wParam == '1') players[0]->extraL->goalWeapon = WEAPON_PISTOLS; + if (wParam == '2') players[0]->extraL->goalWeapon = WEAPON_MAGNUMS; + if (wParam == '3') players[0]->extraL->goalWeapon = WEAPON_UZIS; + if (wParam == '4') players[0]->extraL->goalWeapon = WEAPON_SHOTGUN; + + if (msg != WM_KEYUP && msg != WM_SYSKEYUP) { + keys |= key; + } else { + keys &= ~key; + } + break; + } + + case MM_WOM_DONE : + { + soundFill(); + break; + } + + case WM_SIZE : + { + FRAME_WIDTH = LOWORD(lParam); + FRAME_HEIGHT = HIWORD(lParam); + break; + } + + default : + return DefWindowProc(hWnd, msg, wParam, lParam); + } + return 0; +} + +void* osLoadLevel(const char* name) +{ + // level1 + char buf[32]; + + delete[] levelData; + + sprintf(buf, "data/%s.PKD", name); + + FILE *f = fopen(buf, "rb"); + + if (!f) + return NULL; + + { + fseek(f, 0, SEEK_END); + int32 size = ftell(f); + fseek(f, 0, SEEK_SET); + uint8* data = new uint8[size]; + fread(data, 1, size, f); + fclose(f); + + levelData = data; + } + +// tracks + if (!TRACKS_IMA) + { + FILE *f = fopen("data/TRACKS.IMA", "rb"); + if (!f) + return NULL; + + fseek(f, 0, SEEK_END); + int32 size = ftell(f); + fseek(f, 0, SEEK_SET); + uint8* data = new uint8[size]; + fread(data, 1, size, f); + fclose(f); + + TRACKS_IMA = data; + } + + if (!TITLE_SCR) + { + FILE *f = fopen("data/TITLE.SCR", "rb"); + if (!f) + return NULL; + + fseek(f, 0, SEEK_END); + int32 size = ftell(f); + fseek(f, 0, SEEK_SET); + uint8* data = new uint8[size]; + fread(data, 1, size, f); + fclose(f); + + TITLE_SCR = data; + } + + return (void*)levelData; +} + +int main(void) +{ + RECT r = { 0, 0, FRAME_WIDTH, FRAME_HEIGHT }; + + AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false); + int wx = (GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2; + int wy = (GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2; + + hWnd = CreateWindow("static", "OpenLara", WS_OVERLAPPEDWINDOW, wx + r.left, wy + r.top, r.right - r.left, r.bottom - r.top, 0, 0, 0, 0); + hDC = GetDC(hWnd); + + SetWindowLong(hWnd, GWL_WNDPROC, (LONG)&wndProc); + ShowWindow(hWnd, SW_SHOWDEFAULT); + + soundInit(); + + gameInit(gLevelInfo[gLevelID].name); + + MSG msg; + + int32 startTime = GetTickCount() - 33; + int32 lastFrame = 0; + + do { + if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } else { + int32 frame = (GetTickCount() - startTime) / 33; + if (GetAsyncKeyState('R')) frame /= 10; + + int32 count = frame - lastFrame; + if (GetAsyncKeyState('T')) count *= 10; + gameUpdate(count); + lastFrame = frame; + + gameRender(); + + renderSwap(); + } + } while (msg.message != WM_QUIT); + + gameFree(); + + return 0; +} diff --git a/src/platform/win_fixed/sound.cpp b/src/platform/win_fixed/sound.cpp new file mode 100644 index 0000000..2512df5 --- /dev/null +++ b/src/platform/win_fixed/sound.cpp @@ -0,0 +1,51 @@ +#include "common.h" + +void sndInit() +{ + // TODO +} + +void sndInitSamples() +{ + // TODO +} + +void sndFreeSamples() +{ + // TODO +} + +void* sndPlaySample(int32 index, int32 volume, int32 pitch, int32 mode) +{ + return NULL; // TODO +} + +void sndPlayTrack(int32 track) +{ + // TODO +} + +void sndStopTrack() +{ + // TODO +} + +bool sndTrackIsPlaying() +{ + return false; // TODO +} + +void sndStopSample(int32 index) +{ + // TODO +} + +void sndStop() +{ + // TODO +} + +void sndFill(uint8* buffer, int32 count) +{ + // TODO +}