129 lines
4.5 KiB
C++
129 lines
4.5 KiB
C++
#include <iostream>
|
|
#include <raylib.h>
|
|
#include "Morault_Resources.h"
|
|
#include "Morault_Player.h"
|
|
#include "Morault_UDMF.h"
|
|
#include <raymath.h>
|
|
#include <rlgl.h>
|
|
|
|
#define MORAULT_MAP_RENDER_SCALE 0.1f
|
|
int main(int argc, char** argv) {
|
|
InitWindow(1280, 720, "ProjectMorault");
|
|
// SetTargetFPS(60);
|
|
SetExitKey(0);
|
|
|
|
// if (!std::get<bool>(Morault::Resources::Models(Morault::Resources::load("data/baseblock.glb")))) throw std::runtime_error("couldn't load baseblock");
|
|
|
|
|
|
DisableCursor();
|
|
|
|
Morault::Gameplay::Player player;
|
|
player.data.playerName = "TestPlayer0001";
|
|
player.data.hp = 100;
|
|
player.data.xp = 0;
|
|
bool gamePaused = false;
|
|
|
|
|
|
Vector2 offset = { 0,0 };
|
|
|
|
|
|
/*Morault::Resources::WAD wad("data/testmall.wad");
|
|
|
|
Morault::UDMF::UDMFMap map;
|
|
map.LoadMap(wad.getLumps()[1].data);
|
|
|
|
Model mapModel = Morault::UDMF::LoadModelUDMFWalls(map);
|
|
mapModel.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = LoadTextureFromImage(Morault::Resources::GenTestImage());
|
|
// Model mapFlatModel = Morault::UDMF::LoadModelUDMFFlats(map);
|
|
*/
|
|
while (!WindowShouldClose()) {
|
|
player.controller.UpdatePlayerController(!gamePaused);
|
|
|
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
|
offset = Vector2Add(offset, GetMouseDelta());
|
|
}
|
|
std::vector<Model> floorModels;
|
|
BeginDrawing();
|
|
ClearBackground(BLACK);
|
|
BeginMode3D(player.controller.camera);
|
|
DrawGrid(100, 10);
|
|
EndMode3D();
|
|
/*DrawModel(mapModel, {0,0,0}, MORAULT_MAP_RENDER_SCALE, WHITE);
|
|
|
|
for (int sc = 0; sc < map.sectors.size(); sc++) {
|
|
std::vector<Morault::UDMF::Vertex>* verticesVector = new std::vector<Morault::UDMF::Vertex>();
|
|
std::vector<Vector3> meshVector;
|
|
for (int sd = 0; sd < map.sidedefs.size(); sd++) {
|
|
if (map.sidedefs[sd].sector == sc) {
|
|
for (int ld = 0; ld < map.linedefs.size(); ld++) {
|
|
|
|
if (map.linedefs[ld].sidefront == sd) {
|
|
verticesVector->push_back(map.vertexes[map.linedefs[ld].v1]);
|
|
verticesVector->push_back(map.vertexes[map.linedefs[ld].v2]);
|
|
}
|
|
if (map.linedefs[ld].sideback == sd) { // you, in theory, shouldn't be able to have both the back and front of a linedef be the same.
|
|
verticesVector->push_back(map.vertexes[map.linedefs[ld].v1]);// invert vertices if sideback
|
|
verticesVector->push_back(map.vertexes[map.linedefs[ld].v2]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < verticesVector->size(); i++) {
|
|
meshVector.push_back({
|
|
(float)verticesVector->at(i).x * -1 * MORAULT_MAP_RENDER_SCALE,
|
|
(float)map.sectors[sc].heightfloor * MORAULT_MAP_RENDER_SCALE,
|
|
(float)verticesVector->at(i).y * MORAULT_MAP_RENDER_SCALE
|
|
});
|
|
}
|
|
|
|
DrawTriangleStrip3D(meshVector.data(), meshVector.size(), {((unsigned char)((float)255*(float)(sc/map.sectors.size()))), 255, 255, 255});
|
|
|
|
/*Mesh fMesh = {
|
|
.vertexCount = (int)verticesVector->size(),
|
|
.triangleCount = 1,
|
|
.vertices = (float*)MemAlloc(verticesVector->size() * 3 * sizeof(float)),
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < verticesVector->size(); i++) {
|
|
fMesh.vertices[i * 3 + 0] = verticesVector->at(i).x * MORAULT_MAP_RENDER_SCALE * -1;
|
|
fMesh.vertices[i * 3 + 1] = map.sectors[sc].heightfloor * MORAULT_MAP_RENDER_SCALE;
|
|
fMesh.vertices[i * 3 + 2] = verticesVector->at(i).y * MORAULT_MAP_RENDER_SCALE;
|
|
}
|
|
UploadMesh(&fMesh, false);
|
|
floorModels.push_back(LoadModelFromMesh(fMesh));
|
|
delete verticesVector;
|
|
}
|
|
/*for (int i = 0; i < floorModels.size(); i++) DrawModel(floorModels[i], { 0,0,0 }, 1, WHITE);
|
|
|
|
//DrawModel(std::get<Model>(Morault::Resources::Models(Morault::Resources::get("data/baseblock.glb"))), { 0,0,0 }, 1, WHITE);
|
|
|
|
/*DrawText(TextFormat("Camera offset: %i;%i", (int)offset.x, (int)offset.y), 0, 30, 20, WHITE);
|
|
DrawText(TextFormat("Mouse pos on map: %i;%i", (int)offset.x + GetMouseX(), (int)offset.y + GetMouseY()), 0, 50, 20, WHITE);
|
|
DrawText(TextFormat("Camera offset: %i;%i", (int)player.controller.camera.position.x, (int)player.controller.camera.position.z), 0, 30, 20, WHITE);
|
|
DrawText(TextFormat("Linedefs: %i", map.linedefs.size()), 0, 70, 20, WHITE);
|
|
DrawText(TextFormat("Sidedefs: %i", map.sidedefs.size()), 0, 90, 20, WHITE);
|
|
DrawText(TextFormat("Vertices: %i", map.vertexes.size()), 0, 110, 20, WHITE);
|
|
DrawText(TextFormat("Sectors: %i", map.sectors.size()), 0, 130, 20, WHITE);
|
|
|
|
*/
|
|
DrawFPS(0, 0);
|
|
EndDrawing();
|
|
|
|
/*for (int i = 0; i < floorModels.size(); i++) UnloadModel(floorModels[i]);
|
|
floorModels.clear();*/
|
|
|
|
if (IsKeyPressed(KEY_P)) {
|
|
int x, y;
|
|
std::cin >> x >> y;
|
|
player.controller.camera.position.x = x;
|
|
player.controller.camera.position.z = y;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
CloseWindow();
|
|
} |