1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-08 14:16:52 +02:00

win_fixed start working on GL1 renderer, ARM FIQ test

This commit is contained in:
XProger
2022-04-18 01:07:03 +03:00
parent dc86146886
commit 017446b9f7
19 changed files with 1263 additions and 129 deletions

View File

@@ -1593,4 +1593,61 @@ void dmaCopy(const void* src, void* dst, uint32 size)
memcpy(dst, src, size); memcpy(dst, src, size);
#endif #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 #endif

View File

@@ -8,13 +8,47 @@
// #define PROFILE_SOUNDTIME // #define PROFILE_SOUNDTIME
#endif #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 <windows.h>
#elif defined(__GBA_WIN__)
#define USE_DIV_TABLE #define USE_DIV_TABLE
#define MODE4 #define MODE4
#define FRAME_WIDTH 240 #define FRAME_WIDTH 240
#define FRAME_HEIGHT 160 #define FRAME_HEIGHT 160
#define USE_FMT (LVL_FMT_PKD)
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#include <windows.h> #include <windows.h>
#elif defined(__GBA__) #elif defined(__GBA__)
@@ -27,6 +61,8 @@
#define FRAME_WIDTH 240 #define FRAME_WIDTH 240
#define FRAME_HEIGHT 160 #define FRAME_HEIGHT 160
#define USE_FMT (LVL_FMT_PKD)
#include <tonc.h> #include <tonc.h>
#elif defined(__NDS__) #elif defined(__NDS__)
#define USE_DIV_TABLE #define USE_DIV_TABLE
@@ -35,6 +71,8 @@
#define FRAME_WIDTH 256 #define FRAME_WIDTH 256
#define FRAME_HEIGHT 192 #define FRAME_HEIGHT 192
#define USE_FMT (LVL_FMT_PSX)
#include <nds.h> #include <nds.h>
#include <fat.h> #include <fat.h>
#include <filesystem.h> #include <filesystem.h>
@@ -45,6 +83,8 @@
#define FRAME_WIDTH 320 #define FRAME_WIDTH 320
#define FRAME_HEIGHT 240 #define FRAME_HEIGHT 240
#define USE_FMT (LVL_FMT_PKD)
#include <os.h> #include <os.h>
#elif defined(__DOS__) #elif defined(__DOS__)
#define USE_DIV_TABLE #define USE_DIV_TABLE
@@ -53,6 +93,8 @@
#define FRAME_WIDTH 320 #define FRAME_WIDTH 320
#define FRAME_HEIGHT 200 #define FRAME_HEIGHT 200
#define USE_FMT (LVL_FMT_PKD)
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <conio.h> #include <conio.h>
@@ -68,6 +110,8 @@
#define FRAME_WIDTH 320 #define FRAME_WIDTH 320
#define FRAME_HEIGHT 240 #define FRAME_HEIGHT 240
#define USE_FMT (LVL_FMT_PKD)
#include <displayutils.h> #include <displayutils.h>
#include <debug.h> #include <debug.h>
#include <nodes.h> #include <nodes.h>
@@ -100,11 +144,19 @@
#define FRAME_WIDTH 320 #define FRAME_WIDTH 320
#define FRAME_HEIGHT 224 #define FRAME_HEIGHT 224
#define USE_FMT (LVL_FMT_PKD)
#include "32x.h" #include "32x.h"
#else #else
#error unsupported platform #error unsupported platform
#endif #endif
#ifdef _DEBUG
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
#if !defined(__3DO__) #if !defined(__3DO__)
#include <string.h> #include <string.h>
#endif #endif
@@ -116,6 +168,10 @@
#define VRAM_WIDTH (FRAME_WIDTH/2) // in shorts #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 ========================================================= // Optimization flags =========================================================
#ifdef __GBA__ #ifdef __GBA__
// hide dead enemies after a while to reduce the number of polygons on the screen // 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 #define EWRAM_CODE
#endif #endif
#if defined(_WIN32) #if defined(__WIN32__) || defined(__GBA_WIN__)
#define ASSERT(x) { if (!(x)) { DebugBreak(); } } #define ASSERT(x) { if (!(x)) { DebugBreak(); } }
#else #else
#define ASSERT(x) #define ASSERT(x)
@@ -271,7 +327,7 @@ X_INLINE int32 abs(int32 x) {
#define IME_ENABLE() #define IME_ENABLE()
#endif #endif
#if defined(_WIN32) #if defined(__GBA__WIN__)
extern uint16 fb[VRAM_WIDTH * FRAME_HEIGHT]; extern uint16 fb[VRAM_WIDTH * FRAME_HEIGHT];
#elif defined(__GBA__) #elif defined(__GBA__)
extern uint32 fb; extern uint32 fb;
@@ -342,7 +398,7 @@ extern void* osLoadLevel(const char* name);
#define PROFILE_STOP(value) {\ #define PROFILE_STOP(value) {\
value += (osGetSystemTimeMS() - g_timer);\ value += (osGetSystemTimeMS() - g_timer);\
} }
#elif defined(_WIN32) #elif defined(__WIN32__) || defined(__GBA_WIN__)
extern LARGE_INTEGER g_timer; extern LARGE_INTEGER g_timer;
extern LARGE_INTEGER g_current; extern LARGE_INTEGER g_current;
@@ -352,7 +408,7 @@ extern void* osLoadLevel(const char* name);
#define PROFILE_STOP(value) {\ #define PROFILE_STOP(value) {\
QueryPerformanceCounter(&g_current);\ QueryPerformanceCounter(&g_current);\
value += (g_current.QuadPart - g_timer.QuadPart);\ value += uint32(g_current.QuadPart - g_timer.QuadPart);\
} }
#elif defined(__GBA__) #elif defined(__GBA__)
#ifdef PROFILE_SOUNDTIME #ifdef PROFILE_SOUNDTIME
@@ -431,7 +487,15 @@ extern int32 fps;
#define SND_VOL_SHIFT 6 #define SND_VOL_SHIFT 6
#define SND_PITCH_SHIFT 7 #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_SAMPLES 1024
#define SND_OUTPUT_FREQ 22050 #define SND_OUTPUT_FREQ 22050
#define SND_SAMPLE_FREQ 22050 #define SND_SAMPLE_FREQ 22050
@@ -831,8 +895,11 @@ struct RoomVertex
{ {
#if defined(__3DO__) #if defined(__3DO__)
uint16 xyz565; uint16 xyz565;
#else #elif defined(__GBA__) || defined(__32X__)
uint8 x, y, z, g; uint8 x, y, z, g;
#else
uint8 x, y, z;
uint8 cR, cG, cB;
#endif #endif
}; };
@@ -2063,9 +2130,17 @@ struct CameraFrame
int16 roll; int16 roll;
}; };
enum Version
{
VER_TR1_GBA,
VER_TR1_3DO,
VER_TR1_32X,
VER_TR1_PC
};
struct Level struct Level
{ {
uint32 magic; uint32 version;
uint16 tilesCount; uint16 tilesCount;
uint16 roomsCount; 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 matrixSetView(const vec3i &pos, int32 angleX, int32 angleY);
void renderInit(); void renderInit();
void renderFree();
void renderSwap();
void renderLevelInit();
void renderLevelFree();
void setViewport(const RectMinMax &vp); void setViewport(const RectMinMax &vp);
void setPaletteIndex(int32 index); void setPaletteIndex(int32 index);
void clear(); void clear();
@@ -2805,6 +2884,8 @@ int32 getTextWidth(const char* text);
void drawInit(); void drawInit();
void drawFree(); void drawFree();
void drawLevelInit();
void drawLevelFree();
void drawText(int32 x, int32 y, const char* text, TextAlign align); void drawText(int32 x, int32 y, const char* text, TextAlign align);
void drawModel(const ItemObj* item); void drawModel(const ItemObj* item);
void drawItem(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 dmaFill(void* dst, uint8 value, uint32 count);
void dmaCopy(const void* src, void* dst, uint32 size); 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 #endif

View File

@@ -14,6 +14,8 @@ RoomTriangle roomTri[64];
void drawInit() void drawInit()
{ {
renderInit();
for (int32 i = 0; i < MAX_RAND_TABLE; i++) for (int32 i = 0; i < MAX_RAND_TABLE; i++)
{ {
gRandTable[i] = (rand_draw() >> 5) - 511; gRandTable[i] = (rand_draw() >> 5) - 511;
@@ -40,7 +42,17 @@ void drawInit()
void drawFree() void drawFree()
{ {
// renderFree();
}
void drawLevelInit()
{
renderLevelInit();
}
void drawLevelFree()
{
renderLevelFree();
} }
void calcLightingDynamic(const Room* room, const vec3i &point) void calcLightingDynamic(const Room* room, const vec3i &point)

View File

@@ -695,7 +695,7 @@ struct Enemy : ItemObj
sg->vSpeed = vSpeed; sg->vSpeed = vSpeed;
sg->hSpeed = hSpeed; sg->hSpeed = hSpeed;
sg->health = health; sg->health = health;
sg->mood = mood; sg->mood = uint8(mood);
sg->waterState = waterState; sg->waterState = waterState;
return data + sizeof(EnemySave); return data + sizeof(EnemySave);

95
src/fixed/fmt/phd.h Normal file
View File

@@ -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

124
src/fixed/fmt/pkd.h Normal file
View File

@@ -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

View File

@@ -85,7 +85,7 @@ bool gameLoad()
void gameInit(const char* name) void gameInit(const char* name)
{ {
renderInit(); drawInit();
gSaveGame.dataSize = 0; gSaveGame.dataSize = 0;
@@ -104,6 +104,12 @@ void gameInit(const char* name)
startLevel(name); startLevel(name);
} }
void gameFree()
{
drawLevelFree();
drawFree();
}
void resetLara(int32 index, int32 roomIndex, const vec3i &pos, int32 angleY) void resetLara(int32 index, int32 roomIndex, const vec3i &pos, int32 angleY)
{ {
Lara* lara = players[index]; Lara* lara = players[index];
@@ -123,7 +129,7 @@ void resetLara(int32 index, int32 roomIndex, const vec3i &pos, int32 angleY)
void gameLoadLevel(const void* data) void gameLoadLevel(const void* data)
{ {
drawFree(); drawLevelFree();
memset(&gSaveGame, 0, sizeof(gSaveGame)); memset(&gSaveGame, 0, sizeof(gSaveGame));
memset(enemiesExtra, 0, sizeof(enemiesExtra)); 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 //resetLara(0, 44, _vec3i(73798, 2304, 9819), ANGLE_90); // uw gears
} }
drawInit(); drawLevelInit();
} }
void startLevel(const char* name) void startLevel(const char* name)

View File

@@ -2745,7 +2745,7 @@ struct Lara : ItemObj
if (keys & IK_X) input |= IN_WALK; if (keys & IK_X) input |= IN_WALK;
if (keys & IK_Y) input |= IN_UP | IN_DOWN; if (keys & IK_Y) input |= IN_UP | IN_DOWN;
if (keys & IK_Z) input |= IN_LOOK; if (keys & IK_Z) input |= IN_LOOK;
#elif defined(__GBA__) || defined(_WIN32) #elif defined(__GBA__) || defined(__GBA_WIN__) || defined(__WIN32__)
int32 ikA, ikB; int32 ikA, ikB;
if (gSettings.controls_swap) { if (gSettings.controls_swap) {

View File

@@ -2,7 +2,6 @@
#define H_LEVEL #define H_LEVEL
#include "common.h" #include "common.h"
#include "camera.h"
Level level; Level level;
@@ -33,121 +32,21 @@ EWRAM_DATA ItemObj* ItemObj::sFirstFree;
EWRAM_DATA int32 gBrightness; EWRAM_DATA int32 gBrightness;
void readLevel_GBA(const uint8* data) #if (USE_FMT & (LVL_FMT_PHD | LVL_FMT_PSX))
{ uint8 gLevelData[1024 * 1024];
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 #endif
// prepare models // TODO prerocess #if (USE_FMT & LVL_FMT_PKD)
memset(models, 0, sizeof(models)); #include "fmt/pkd.h"
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 #endif
#ifdef __3DO__ #if (USE_FMT & LVL_FMT_PHD)
for (int32 i = 0; i < level.texturesCount; i++) #include "fmt/phd.h"
{ #endif
Texture* tex = level.textures + i;
tex->data += intptr_t(RAM_TEX); #if (USE_FMT & LVL_FMT_PSX)
} #include "fmt/psx.h"
#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 #endif
}
void readLevel(const uint8* data) void readLevel(const uint8* data)
{ {
@@ -155,9 +54,27 @@ void readLevel(const uint8* data)
dynSectorsCount = 0; dynSectorsCount = 0;
//#endif //#endif
readLevel_GBA(data); memset(&level, 0, sizeof(level));
gAnimTexFrame = 0; 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() void animTexturesShift()

250
src/fixed/render/gl1.cpp Normal file
View File

@@ -0,0 +1,250 @@
#ifndef H_GL1
#define H_GL1
#include <common.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#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

View File

@@ -22,6 +22,7 @@
<ClCompile Include="..\..\fixed\common.cpp" /> <ClCompile Include="..\..\fixed\common.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="render.iwram.cpp" /> <ClCompile Include="render.iwram.cpp" />
<ClCompile Include="render_span.cpp" />
<ClCompile Include="sound.cpp" /> <ClCompile Include="sound.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -289,7 +289,14 @@ rasterizeGT_asm:
.scanline_end: .scanline_end:
ldmfd sp!, {Lx, Lg, Lt} 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} ldmia sp, {sLdx, sLdg, sLdt, sRdx, sRdg}
add Lx, sLdx add Lx, sLdx

Binary file not shown.

View File

@@ -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

View File

@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6935E070-59B8-418A-9241-70BACB4217B5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>OpenLara</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\..\..\bin\</OutDir>
<IncludePath>..\..\fixed;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86)</LibraryPath>
<ExcludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(FxCopDir);$(MSBuild_ExecutablePath);$(VC_LibraryPath_x86);$(SystemRoot)</ExcludePath>
<ExecutablePath>$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\..\..\bin\</OutDir>
<GenerateManifest>false</GenerateManifest>
<LibraryPath>..\..\libs\openvr\;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);</LibraryPath>
<IncludePath>..\..\libs\;..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<ExcludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(FxCopDir);$(MSBuild_ExecutablePath);$(VC_LibraryPath_x86);$(SystemRoot)</ExcludePath>
<ExecutablePath>$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>__WIN32__;NOMINMAX;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FloatingPointModel>Strict</FloatingPointModel>
<AdditionalOptions>
</AdditionalOptions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>MINIMAL;NOMINMAX;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FloatingPointModel>Strict</FloatingPointModel>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<AdditionalOptions>/d2noftol3 %(AdditionalOptions)</AdditionalOptions>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>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)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AssemblyDebug>true</AssemblyDebug>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\fixed\common.cpp" />
<ClCompile Include="..\..\fixed\render\gl1.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="sound.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="OpenLara.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="icon.ico" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\fixed\camera.h" />
<ClInclude Include="..\..\fixed\common.h" />
<ClInclude Include="..\..\fixed\draw.h" />
<ClInclude Include="..\..\fixed\enemy.h" />
<ClInclude Include="..\..\fixed\fmt\phd.h" />
<ClInclude Include="..\..\fixed\fmt\pkd.h" />
<ClInclude Include="..\..\fixed\game.h" />
<ClInclude Include="..\..\fixed\inventory.h" />
<ClInclude Include="..\..\fixed\item.h" />
<ClInclude Include="..\..\fixed\lang\en.h" />
<ClInclude Include="..\..\fixed\lara.h" />
<ClInclude Include="..\..\fixed\level.h" />
<ClInclude Include="..\..\fixed\nav.h" />
<ClInclude Include="..\..\fixed\object.h" />
<ClInclude Include="..\..\fixed\room.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="..\..\fixed\common.cpp" />
<ClCompile Include="..\..\fixed\render\gl1.cpp" />
<ClCompile Include="sound.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="OpenLara.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="icon.ico" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\fixed\camera.h" />
<ClInclude Include="..\..\fixed\common.h" />
<ClInclude Include="..\..\fixed\draw.h" />
<ClInclude Include="..\..\fixed\enemy.h" />
<ClInclude Include="..\..\fixed\game.h" />
<ClInclude Include="..\..\fixed\inventory.h" />
<ClInclude Include="..\..\fixed\item.h" />
<ClInclude Include="..\..\fixed\lara.h" />
<ClInclude Include="..\..\fixed\level.h" />
<ClInclude Include="..\..\fixed\nav.h" />
<ClInclude Include="..\..\fixed\object.h" />
<ClInclude Include="..\..\fixed\room.h" />
<ClInclude Include="..\..\fixed\lang\en.h">
<Filter>lang</Filter>
</ClInclude>
<ClInclude Include="..\..\fixed\fmt\pkd.h">
<Filter>fmt</Filter>
</ClInclude>
<ClInclude Include="..\..\fixed\fmt\phd.h">
<Filter>fmt</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="lang">
<UniqueIdentifier>{1d3e6f64-05d8-42b8-b2c6-c5bba7798936}</UniqueIdentifier>
</Filter>
<Filter Include="fmt">
<UniqueIdentifier>{f297223e-368f-46b9-9f41-3e8075cbc5c2}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -0,0 +1,302 @@
#include "game.h"
int FRAME_WIDTH = 1280;
int FRAME_HEIGHT = 720;
int32 fps;
int32 frameIndex = 0;
int32 fpsCounter = 0;
uint32 curSoundBuffer = 0;
const void* TRACKS_IMA;
const void* TITLE_SCR;
const void* levelData;
HWND hWnd;
HDC hDC;
LARGE_INTEGER g_timer;
LARGE_INTEGER g_current;
void osSetPalette(const uint16* palette)
{
//
}
int32 osGetSystemTimeMS()
{
return GetTickCount();
}
bool osSaveSettings()
{
FILE* f = fopen("settings.dat", "wb");
if (!f) return false;
fwrite(&gSettings, sizeof(gSettings), 1, f);
fclose(f);
return true;
}
bool osLoadSettings()
{
FILE* f = fopen("settings.dat", "rb");
if (!f) return false;
uint8 version;
fread(&version, 1, 1, f);
if (version != gSettings.version) {
fclose(f);
return false;
}
fread((uint8*)&gSettings + 1, sizeof(gSettings) - 1, 1, f);
fclose(f);
return true;
}
bool osCheckSave()
{
FILE* f = fopen("savegame.dat", "rb");
if (!f) return false;
fclose(f);
return true;
}
bool osSaveGame()
{
FILE* f = fopen("savegame.dat", "wb");
if (!f) return false;
fwrite(&gSaveGame, sizeof(gSaveGame), 1, f);
fwrite(&gSaveData, gSaveGame.dataSize, 1, f);
fclose(f);
return true;
}
bool osLoadGame()
{
FILE* f = fopen("savegame.dat", "rb");
if (!f) return false;
uint32 version;
fread(&version, sizeof(version), 1, f);
if (SAVEGAME_VER != version)
{
fclose(f);
return false;
}
fread(&gSaveGame.dataSize, sizeof(gSaveGame) - sizeof(version), 1, f);
fread(&gSaveData, gSaveGame.dataSize, 1, f);
fclose(f);
return true;
}
void osJoyVibrate(int32 index, int32 L, int32 R) {}
uint8 soundBuffer[2 * SND_SAMPLES + 32]; // 32 bytes of silence for DMA overrun while interrupt
HWAVEOUT waveOut;
WAVEFORMATEX waveFmt = { WAVE_FORMAT_PCM, 1, SND_OUTPUT_FREQ, SND_OUTPUT_FREQ, 1, 8, sizeof(waveFmt) };
WAVEHDR waveBuf[2];
void soundInit()
{return;
sndInit();
if (waveOutOpen(&waveOut, WAVE_MAPPER, &waveFmt, (INT_PTR)hWnd, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR)
return;
memset(&waveBuf, 0, sizeof(waveBuf));
for (int i = 0; i < 2; i++)
{
WAVEHDR *waveHdr = waveBuf + i;
waveHdr->dwBufferLength = 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;
}

View File

@@ -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
}