static game #1

This commit is contained in:
Sandro Sobczyński
2020-11-03 21:49:16 +01:00
parent 9e3ed74b45
commit 5399b1744f
18 changed files with 180 additions and 194 deletions
+2 -2
View File
@@ -66,8 +66,8 @@ void Engine::setDefaultScreen()
void Engine::init(Game *t_game, u32 t_gifPacketSize) void Engine::init(Game *t_game, u32 t_gifPacketSize)
{ {
if (!isScreenInitialized) if (!isScreenInitialized)
PRINT_ERR("Cant init because screen was not set!"); setDefaultScreen();
else if (isInitialized) if (isInitialized)
PRINT_ERR("Already initialized!"); PRINT_ERR("Already initialized!");
else else
{ {
+1 -1
View File
@@ -33,7 +33,7 @@ public:
~GifSender(); ~GifSender();
void initPacket(u8 context); void initPacket(u8 context);
void addObject(RenderData *t_renderData, Mesh *t_objects3D, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer); void addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer);
void addClear(zbuffer_t *t_zBuffer); void addClear(zbuffer_t *t_zBuffer);
void sendPacket(); void sendPacket();
void sendClear(zbuffer_t *t_zBuffer); void sendClear(zbuffer_t *t_zBuffer);
+9 -9
View File
@@ -35,22 +35,22 @@ public:
prim_t prim; prim_t prim;
/** PATH3 Many + lighting */ /** PATH3 Many + lighting */
void drawByPath3(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount); void drawByPath3(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount);
/** PATH3 Single + lighting */ /** PATH3 Single + lighting */
void drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount); void drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
/** PATH3 Many */ /** PATH3 Many */
void drawByPath3(Mesh **t_meshes, u16 t_amount); void drawByPath3(Mesh *t_meshes, u16 t_amount);
/** PATH3 Single */ /** PATH3 Single */
void drawByPath3(Mesh *t_mesh); void drawByPath3(Mesh &t_mesh);
/** PATH1 Many + lighting */ /** PATH1 Many + lighting */
void draw(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount); void draw(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount);
/** PATH1 Single + lighting */ /** PATH1 Single + lighting */
void draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount); void draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
/** PATH1 Many */ /** PATH1 Many */
void draw(Mesh **t_meshes, u16 t_amount); void draw(Mesh *t_meshes, u16 t_amount);
/** PATH1 Single */ /** PATH1 Single */
void draw(Mesh *t_mesh); void draw(Mesh &t_mesh);
void setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes); void setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes);
@@ -59,7 +59,7 @@ public:
TextureRepository *getTextureRepository() { return &textureRepo; }; TextureRepository *getTextureRepository() { return &textureRepo; };
private: private:
void changeTexture(Mesh *t_mesh, u32 t_materialId); void changeTexture(const Mesh &t_mesh, u32 t_materialId);
u32 lastTextureId; u32 lastTextureId;
texbuffer_t textureBuffer; texbuffer_t textureBuffer;
u8 isTextureVRAMAllocated; u8 isTextureVRAMAllocated;
+2 -2
View File
@@ -28,11 +28,11 @@ public:
~VifSender(); ~VifSender();
// TODO refactor // TODO refactor
void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer); void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, const Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer);
void sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation); void sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation);
private: private:
void drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer); void drawVertices(const Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer);
VU1 vu1; // TODO VU1 vu1; // TODO
MATRIX localWorld, localScreen; MATRIX localWorld, localScreen;
VECTOR position, rotation; VECTOR position, rotation;
+6 -6
View File
@@ -129,7 +129,7 @@ void GifSender::addClear(zbuffer_t *t_zBuffer)
* @param objects3D Array of 3D objects pointers * @param objects3D Array of 3D objects pointers
* @param amount Amount of 3D objects * @param amount Amount of 3D objects
*/ */
void GifSender::addObject(RenderData *t_renderData, Mesh *t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer) void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
{ {
if (!isAnyObjectAdded) if (!isAnyObjectAdded)
{ {
@@ -140,14 +140,14 @@ void GifSender::addObject(RenderData *t_renderData, Mesh *t_mesh, u32 vertexCoun
tempDMATag = q; tempDMATag = q;
q++; q++;
q = draw_texture_sampling(q, 0, &t_mesh->lod); q = draw_texture_sampling(q, 0, &t_mesh.lod);
q = draw_texturebuffer(q, 0, textureBuffer, &t_mesh->clut); q = draw_texturebuffer(q, 0, textureBuffer, &t_mesh.clut);
dw = (u64 *)draw_prim_start(q, 0, t_renderData->prim, &t_mesh->color); dw = (u64 *)draw_prim_start(q, 0, t_renderData->prim, &t_mesh.color);
xyz = new xyz_t[vertexCount]; xyz = new xyz_t[vertexCount];
rgbaq = new color_t[vertexCount]; rgbaq = new color_t[vertexCount];
st = new texel_t[vertexCount]; st = new texel_t[vertexCount];
calc3DObject(*t_renderData->perspective, *t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount); calc3DObject(*t_renderData->perspective, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount);
addCurrentCalcs(vertexCount); addCurrentCalcs(vertexCount);
delete[] xyz; delete[] xyz;
delete[] rgbaq; delete[] rgbaq;
@@ -205,7 +205,7 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
colors[i][0] = (t_mesh.color.r * lights[i][0] / 128.0F); colors[i][0] = (t_mesh.color.r * lights[i][0] / 128.0F);
colors[i][1] = (t_mesh.color.g * lights[i][1] / 128.0F); colors[i][1] = (t_mesh.color.g * lights[i][1] / 128.0F);
colors[i][2] = (t_mesh.color.b * lights[i][2] / 128.0F); colors[i][2] = (t_mesh.color.b * lights[i][2] / 128.0F);
vector_clamp(colors[i], colors[i], 0.00f, 1.99f); vector_clamp(colors[i], colors[i], 0.00F, 1.99F);
} }
delete[] lightDirections; delete[] lightDirections;
+27 -27
View File
@@ -81,10 +81,10 @@ void Renderer::deallocateTextureBuffer()
} }
} }
void Renderer::changeTexture(Mesh *t_mesh, u32 t_materialId) void Renderer::changeTexture(const Mesh &t_mesh, u32 t_materialId)
{ {
MeshTexture *tex = textureRepo.getByMesh(t_mesh->getId(), t_materialId); MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_materialId);
if (tex != NULL) if (tex != NULL)
{ {
if (tex->getId() != lastTextureId) if (tex->getId() != lastTextureId)
@@ -161,31 +161,31 @@ void Renderer::allocateBuffers(float t_screenW, float t_screenH)
/// --- Draw: PATH3 /// --- Draw: PATH3
/** PATH3 Many + lighting */ /** PATH3 Many + lighting */
void Renderer::drawByPath3(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount) void Renderer::drawByPath3(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount)
{ {
for (u16 i = 0; i < t_amount; i++) for (u16 i = 0; i < t_amount; i++)
drawByPath3(t_meshes[i], t_bulbs, t_bulbsCount); drawByPath3(t_meshes[i], t_bulbs, t_bulbsCount);
} }
/** PATH3 Single + lighting */ /** PATH3 Single + lighting */
void Renderer::drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
{ {
beginFrameIfNeeded(); beginFrameIfNeeded();
if (!t_mesh->isDataLoaded()) if (!t_mesh.isDataLoaded())
PRINT_ERR("Can't draw, because no mesh data was loaded!"); PRINT_ERR("Can't draw, because no mesh data was loaded!");
if (t_mesh->getCurrentAnimationFrame() != t_mesh->getNextAnimationFrame()) if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame())
t_mesh->animate(); t_mesh.animate();
for (u32 i = 0; i < t_mesh->getMaterialsCount(); i++) for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++)
{ {
if (t_mesh->shouldBeFrustumCulled && !t_mesh->getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh->position)) if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
return; return;
changeTexture(t_mesh, t_mesh->getMaterial(i).getId()); changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
gifSender->initPacket(context); gifSender->initPacket(context);
u32 vertCount = t_mesh->getMaterial(i).getFacesCount(); u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
VECTOR *vertices = new VECTOR[vertCount]; VECTOR *vertices = new VECTOR[vertCount];
VECTOR *normals = new VECTOR[vertCount]; VECTOR *normals = new VECTOR[vertCount];
VECTOR *coordinates = new VECTOR[vertCount]; VECTOR *coordinates = new VECTOR[vertCount];
vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer); gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer);
gifSender->sendPacket(); gifSender->sendPacket();
delete[] vertices; delete[] vertices;
@@ -195,40 +195,40 @@ void Renderer::drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
} }
/** PATH3 Many */ /** PATH3 Many */
void Renderer::drawByPath3(Mesh **t_meshes, u16 t_amount) { drawByPath3(t_meshes, t_amount, NULL, 0); } void Renderer::drawByPath3(Mesh *t_meshes, u16 t_amount) { drawByPath3(t_meshes, t_amount, NULL, 0); }
/** PATH3 Single */ /** PATH3 Single */
void Renderer::drawByPath3(Mesh *t_mesh) { drawByPath3(t_mesh, NULL, 0); } void Renderer::drawByPath3(Mesh &t_mesh) { drawByPath3(t_mesh, NULL, 0); }
/// --- Draw: PATH1 /// --- Draw: PATH1
/** PATH1 Many + lighting */ /** PATH1 Many + lighting */
void Renderer::draw(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount) void Renderer::draw(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount)
{ {
for (u16 i = 0; i < t_amount; i++) for (u16 i = 0; i < t_amount; i++)
draw(t_meshes[i], t_bulbs, t_bulbsCount); draw(t_meshes[i], t_bulbs, t_bulbsCount);
} }
/** PATH1 Single + lighting */ /** PATH1 Single + lighting */
void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
{ {
beginFrameIfNeeded(); beginFrameIfNeeded();
vifSender->sendMatrices(renderData, t_mesh->position, t_mesh->rotation); vifSender->sendMatrices(renderData, t_mesh.position, t_mesh.rotation);
if (!t_mesh->isDataLoaded()) if (!t_mesh.isDataLoaded())
PRINT_ERR("Can't draw, because no mesh data was loaded!"); PRINT_ERR("Can't draw, because no mesh data was loaded!");
if (t_mesh->getCurrentAnimationFrame() != t_mesh->getNextAnimationFrame()) if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame())
t_mesh->animate(); t_mesh.animate();
for (u32 i = 0; i < t_mesh->getMaterialsCount(); i++) for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++)
{ {
if (t_mesh->shouldBeFrustumCulled && !t_mesh->getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh->position)) if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
return; return;
u32 vertCount = t_mesh->getMaterial(i).getFacesCount(); u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
VECTOR *vertices = new VECTOR[vertCount]; VECTOR *vertices = new VECTOR[vertCount];
VECTOR *normals = new VECTOR[vertCount]; VECTOR *normals = new VECTOR[vertCount];
VECTOR *coordinates = new VECTOR[vertCount]; VECTOR *coordinates = new VECTOR[vertCount];
changeTexture(t_mesh, t_mesh->getMaterial(i).getId()); changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer); vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
delete[] vertices; delete[] vertices;
delete[] normals; delete[] normals;
@@ -237,10 +237,10 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
} }
/** PATH1 Many */ /** PATH1 Many */
void Renderer::draw(Mesh **t_objects3D, u16 t_amount) { draw(t_objects3D, t_amount, NULL, 0); } void Renderer::draw(Mesh *t_meshes, u16 t_amount) { draw(t_meshes, t_amount, NULL, 0); }
/** PATH1 Single */ /** PATH1 Single */
void Renderer::draw(Mesh *t_mesh) { draw(t_mesh, NULL, 0); } void Renderer::draw(Mesh &t_mesh) { draw(t_mesh, NULL, 0); }
/// --- /// ---
+14 -14
View File
@@ -46,7 +46,7 @@ void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_po
vu1.sendSingleRefList(0, &localScreen, 4); vu1.sendSingleRefList(0, &localScreen, 4);
} }
void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer) void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, const Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
{ {
// we have to split 3D object into small parts, because of small memory of VU1 // we have to split 3D object into small parts, because of small memory of VU1
for (u32 i = 0; i < vertCount2;) for (u32 i = 0; i < vertCount2;)
@@ -72,7 +72,7 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver
} }
/** Draw using PATH1 */ /** Draw using PATH1 */
void VifSender::drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer) void VifSender::drawVertices(const Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer)
{ {
const u32 vertCount = t_end - t_start; const u32 vertCount = t_end - t_start;
vu1.addListBeginning(); vu1.addListBeginning();
@@ -87,13 +87,13 @@ void VifSender::drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_ver
vu1.add128( // tex -> lod vu1.add128( // tex -> lod
GS_SET_TEX1( GS_SET_TEX1(
t_mesh->lod.calculation, t_mesh.lod.calculation,
t_mesh->lod.max_level, t_mesh.lod.max_level,
t_mesh->lod.mag_filter, t_mesh.lod.mag_filter,
t_mesh->lod.min_filter, t_mesh.lod.min_filter,
t_mesh->lod.mipmap_select, t_mesh.lod.mipmap_select,
t_mesh->lod.l, t_mesh.lod.l,
(int)(t_mesh->lod.k * 16.0F)), (int)(t_mesh.lod.k * 16.0F)),
GS_REG_TEX1); GS_REG_TEX1);
vu1.add128( // tex -> buff + clut vu1.add128( // tex -> buff + clut
@@ -105,11 +105,11 @@ void VifSender::drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_ver
textureBuffer->info.height, textureBuffer->info.height,
textureBuffer->info.components, textureBuffer->info.components,
textureBuffer->info.function, textureBuffer->info.function,
t_mesh->clut.address >> 6, t_mesh.clut.address >> 6,
t_mesh->clut.psm, t_mesh.clut.psm,
t_mesh->clut.storage_mode, t_mesh.clut.storage_mode,
t_mesh->clut.start, t_mesh.clut.start,
t_mesh->clut.load_method), t_mesh.clut.load_method),
GS_REG_TEX0); GS_REG_TEX0);
vu1.add128( vu1.add128(
+74 -86
View File
@@ -16,7 +16,13 @@
// Constructors/Destructors // Constructors/Destructors
// ---- // ----
Ari::Ari() {} const u8 WATER_TILES_COUNT = 64;
Ari::Ari(const Engine &t_engine) : engine(t_engine), camera(&engine.screen)
{
waterFloors = new Mesh[WATER_TILES_COUNT];
spirals = new Point[WATER_TILES_COUNT];
}
Ari::~Ari() {} Ari::~Ari() {}
@@ -24,13 +30,74 @@ Ari::~Ari() {}
// Methods // Methods
// ---- // ----
// TEST START void Ari::onInit()
const u8 WATER_TILES_COUNT = 64; {
Mesh *island, *islandAddons, *skybox, *test;
Mesh **waterFloors;
Point *spirals;
void calcSpiral(int X, int Y) engine.renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
engine.audio.init(0);
engine.audio.setVolume(40);
engine.audio.loadSong("MOV-CIRC.WAV");
engine.audio.play();
texRepo = engine.renderer->getTextureRepository();
island.loadDff("sunnyisl/", "sunnyisl", 0.1F, false);
island.rotation.x = -1.6F;
island.position.set(0.0F, 10.0F, 20.0F);
island.shouldBeBackfaceCulled = true;
island.shouldBeFrustumCulled = false;
islandAddons.loadDff("sunnyisl/", "sunnyisl3", 0.1F, false);
islandAddons.rotation.x = -1.6F;
islandAddons.position.set(0.0F, 10.0F, 20.0F);
skybox.loadObj("skybox/", "skybox", 100.0F, false);
skybox.shouldBeFrustumCulled = false;
waterFloors[0].loadObj("water/", "water", 5.0F, false);
waterFloors[0].position.set(0.0F, 8.0F, 0.0F);
texRepo->addByMesh("water/", waterFloors[0]);
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
{
spirals[i].x = 1.0F;
spirals[i].y = 2.0F;
}
u32 spiralOffset = (u32)Math::sqrt(WATER_TILES_COUNT);
calcSpiral(spiralOffset, spiralOffset);
for (u8 i = 1; i < WATER_TILES_COUNT; i++)
{
waterFloors[i].loadFrom(waterFloors[0]);
waterFloors[i].position.set(10.0F * spirals[i].x, 8.0F, 10.0F * spirals[i].y);
texRepo->getByMesh(waterFloors[0].getId(), waterFloors[0].getMaterial(0).getId())
->addLink(waterFloors[i].getId(), waterFloors[i].getMaterial(0).getId());
}
texRepo->addByMesh("sunnyisl/", island);
texRepo->addByMesh("sunnyisl/", islandAddons);
texRepo->addByMesh("skybox/", skybox);
texRepo->addByMesh("ari/", player.mesh);
}
void Ari::initBulb()
{
bulb.intensity = 15;
bulb.position.set(5.0F, 10.0F, 10.0F);
}
void Ari::onUpdate()
{
if (engine.pad.isCrossClicked)
printf("FPS:%f\n", engine.fps);
camera.update(engine.pad, player.mesh);
engine.renderer->draw(skybox);
engine.renderer->draw(island);
engine.renderer->draw(islandAddons);
engine.renderer->draw(player.mesh);
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
engine.renderer->draw(waterFloors[i]);
}
void Ari::calcSpiral(int X, int Y)
{ {
int x, y, dx; int x, y, dx;
x = y = dx = 0; x = y = dx = 0;
@@ -54,82 +121,3 @@ void calcSpiral(int X, int Y)
y += dy; y += dy;
} }
} }
// TEST END
// TODO 1 - const & in parameters
// TODO 2 - Destructor mesh
void Ari::onInit()
{
player = new Player();
camera = new Camera(&engine.screen);
engine.renderer->setCameraDefinitions(&camera->worldView, &camera->unitCirclePosition, camera->planes);
engine.audio.init(0);
engine.audio.setVolume(40);
engine.audio.loadSong("MOV-CIRC.WAV");
engine.audio.play();
texRepo = engine.renderer->getTextureRepository();
island = new Mesh();
island->loadDff("sunnyisl/", "sunnyisl", 0.1F, false);
island->rotation.x = -1.6F;
island->position.set(0.0F, 10.0F, 20.0F);
island->shouldBeBackfaceCulled = true;
island->shouldBeFrustumCulled = false;
islandAddons = new Mesh();
islandAddons->loadDff("sunnyisl/", "sunnyisl3", 0.1F, false);
islandAddons->rotation.x = -1.6F;
islandAddons->position.set(0.0F, 10.0F, 20.0F);
skybox = new Mesh();
skybox->loadObj("skybox/", "skybox", 100.0F, false);
skybox->shouldBeFrustumCulled = false;
waterFloors = new Mesh *[WATER_TILES_COUNT];
spirals = new Point[WATER_TILES_COUNT];
waterFloors[0] = new Mesh();
waterFloors[0]->loadObj("water/", "water", 5.0F, false);
waterFloors[0]->position.set(0.0F, 8.0F, 0.0F);
texRepo->addByMesh("water/", *waterFloors[0]);
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
{
spirals[i].x = 1.0F;
spirals[i].y = 2.0F;
}
u32 spiralOffset = (u32)Math::sqrt(WATER_TILES_COUNT);
calcSpiral(spiralOffset, spiralOffset);
for (u8 i = 1; i < WATER_TILES_COUNT; i++)
{
waterFloors[i] = new Mesh();
waterFloors[i]->loadFrom(*waterFloors[0]);
waterFloors[i]->position.set(10.0F * spirals[i].x, 8.0F, 10.0F * spirals[i].y);
texRepo->getByMesh(waterFloors[0]->getId(), waterFloors[0]->getMaterial(0).getId())
->addLink(waterFloors[i]->getId(), waterFloors[i]->getMaterial(0).getId());
}
texRepo->addByMesh("sunnyisl/", *island);
texRepo->addByMesh("sunnyisl/", *islandAddons);
texRepo->addByMesh("skybox/", *skybox);
texRepo->addByMesh("ari/", player->mesh);
}
void Ari::initBulb()
{
bulb.intensity = 15;
bulb.position.set(5.0F, 10.0F, 10.0F);
}
void Ari::onUpdate()
{
if (engine.pad.isCrossClicked)
printf("FPS:%f\n", engine.fps);
camera->update(engine.pad, player->mesh);
engine.renderer->draw(skybox);
engine.renderer->draw(island);
engine.renderer->draw(islandAddons);
engine.renderer->draw(&player->mesh);
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
engine.renderer->draw(waterFloors[i]);
}
+7 -3
View File
@@ -23,7 +23,7 @@ class Ari : public Game
{ {
public: public:
Ari(); Ari(const Engine &t_engine);
~Ari(); ~Ari();
void onInit(); void onInit();
@@ -33,9 +33,13 @@ public:
private: private:
void initBulb(); void initBulb();
void calcSpiral(int X, int Y);
LightBulb bulb; LightBulb bulb;
Player *player; Player player;
Camera *camera; Mesh island, islandAddons, skybox;
Mesh *waterFloors;
Point *spirals;
Camera camera;
TextureRepository *texRepo; TextureRepository *texRepo;
}; };
+2 -2
View File
@@ -12,8 +12,8 @@
int main() int main()
{ {
Ari game = Ari(); Engine engine = Engine();
game.engine.setDefaultScreen(); Ari game = Ari(engine);
game.engine.init(&game, 40000); game.engine.init(&game, 40000);
SleepThread(); SleepThread();
return 0; return 0;
+17 -16
View File
@@ -14,7 +14,10 @@
// Constructors/Destructors // Constructors/Destructors
// ---- // ----
Floors::Floors() {} const u8 FLOORS_COUNT = 64; // Temp change it also in floor_manager.hpp
Floors::Floors(const Engine &t_engine)
: engine(t_engine), floorManager(FLOORS_COUNT), camera(&engine.screen) {}
Floors::~Floors() {} Floors::~Floors() {}
@@ -24,21 +27,18 @@ Floors::~Floors() {}
void Floors::onInit() void Floors::onInit()
{ {
player = new Player(); engine.renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
camera = new Camera(&engine.screen);
engine.renderer->setCameraDefinitions(&camera->worldView, &camera->unitCirclePosition, camera->planes);
floorManager = new FloorManager(64); // Temp change it also in floor_manager.hpp
engine.audio.init(2); engine.audio.init(2);
engine.audio.addListener(floorManager); engine.audio.addListener(&floorManager);
engine.audio.addListener(&lightManager); engine.audio.addListener(&lightManager);
engine.audio.loadSong("NF-CHILL.WAV"); engine.audio.loadSong("NF-CHILL.WAV");
engine.audio.play(); engine.audio.play();
texRepo = engine.renderer->getTextureRepository(); texRepo = engine.renderer->getTextureRepository();
texRepo->addByMesh("warrior/", player->mesh); texRepo->addByMesh("warrior/", player.mesh);
texRepo->addByMesh("floor/", *floorManager->meshes[0]); texRepo->addByMesh("floor/", floorManager.floors[0].mesh);
for (size_t i = 1; i < floorManager->floorAmount; i++) for (u32 i = 1; i < floorManager.floorAmount; i++)
texRepo->getByMesh(floorManager->meshes[0]->getId(), floorManager->meshes[0]->getMaterial(0).getId()) texRepo->getByMesh(floorManager.floors[0].mesh.getId(), floorManager.floors[0].mesh.getMaterial(0).getId())
->addLink(floorManager->meshes[i]->getId(), floorManager->meshes[i]->getMaterial(0).getId()); ->addLink(floorManager.floors[i].mesh.getId(), floorManager.floors[i].mesh.getMaterial(0).getId());
} }
void Floors::onUpdate() void Floors::onUpdate()
@@ -46,9 +46,10 @@ void Floors::onUpdate()
if (engine.pad.isCrossClicked) if (engine.pad.isCrossClicked)
printf("FPS:%f\n", engine.fps); printf("FPS:%f\n", engine.fps);
lightManager.update(); lightManager.update();
camera->update(engine.pad, player->mesh); camera.update(engine.pad, player.mesh);
floorManager->update(*player); floorManager.update(player);
player->update(engine.pad, *camera, *floorManager); player.update(engine.pad, camera, floorManager);
engine.renderer->draw(&player->mesh); engine.renderer->draw(player.mesh);
engine.renderer->drawByPath3(floorManager->meshes, floorManager->floorAmount, lightManager.bulbs, lightManager.bulbsCount); for (u8 i = 0; i < FLOORS_COUNT; i++)
engine.renderer->drawByPath3(floorManager.floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount);
} }
+4 -4
View File
@@ -24,7 +24,7 @@ class Floors : public Game
{ {
public: public:
Floors(); Floors(const Engine &t_engine);
~Floors(); ~Floors();
void onInit(); void onInit();
@@ -35,9 +35,9 @@ public:
private: private:
TextureRepository *texRepo; TextureRepository *texRepo;
LightManager lightManager; LightManager lightManager;
FloorManager *floorManager; FloorManager floorManager;
Player *player; Player player;
Camera *camera; Camera camera;
}; };
#endif #endif
+2 -2
View File
@@ -12,8 +12,8 @@
int main() int main()
{ {
Floors game = Floors(); Engine engine = Engine();
game.engine.setDefaultScreen(); Floors game = Floors(engine);
game.engine.init(&game, 40000); game.engine.init(&game, 40000);
SleepThread(); SleepThread();
return 0; return 0;
+7 -13
View File
@@ -33,7 +33,6 @@ FloorManager::FloorManager(int t_floorAmount)
FloorManager::~FloorManager() FloorManager::~FloorManager()
{ {
delete[] spirals; delete[] spirals;
delete[] meshes;
} }
// ---- // ----
@@ -78,17 +77,11 @@ void FloorManager::calcSpiral(int X, int Y)
void FloorManager::initFloors() void FloorManager::initFloors()
{ {
PRINT_LOG("Initializing floors"); PRINT_LOG("Initializing floors");
meshes = new Mesh *[floorAmount]; floors[0].mesh.loadObj("floor/", "floor", 2.0F, false);
floors[0].mesh.shouldBeFrustumCulled = true;
meshes[0] = new Mesh(); floors[0].mesh.shouldBeLighted = true;
meshes[0]->loadObj("floor/", "floor", 2.0F, false); for (u8 i = 1; i < floorAmount; i++)
meshes[0]->shouldBeFrustumCulled = true; floors[i].init(floors[0].mesh, spirals[i], i);
meshes[0]->shouldBeLighted = true;
for (u8 i = 0; i < floorAmount; i++)
{
floors[i].init(meshes[0], spirals[i], i);
meshes[i] = &floors[i].mesh;
}
PRINT_LOG("Floors initialized!"); PRINT_LOG("Floors initialized!");
} }
@@ -113,6 +106,7 @@ void FloorManager::update(Player &t_player)
/** Called by audio thread */ /** Called by audio thread */
void FloorManager::onAudioTick() void FloorManager::onAudioTick()
{ {
printf("Hit!\n");
if (audioTick++ > 16) if (audioTick++ > 16)
{ {
if (audioMode == 0) if (audioMode == 0)
@@ -164,7 +158,7 @@ void FloorManager::onAudioTick()
{ {
for (u8 i = 0; i < floorAmount; i++) for (u8 i = 0; i < floorAmount; i++)
{ {
if (i + 1 > floorAmount / (audioOffset + 1)) if (u8(i + 1) > floorAmount / (audioOffset + 1))
floors[i].isByAudioTriggered = true; floors[i].isByAudioTriggered = true;
else else
floors[i].isByAudioTriggered = false; floors[i].isByAudioTriggered = false;
@@ -27,9 +27,8 @@ public:
FloorManager(int t_floorAmount); FloorManager(int t_floorAmount);
~FloorManager(); ~FloorManager();
Floor floors[64]; // Temp change it also in floors.cpp Floor floors[64]; // Temp change it also in floors.cpp
int floorAmount; u32 floorAmount;
void update(Player &t_player); void update(Player &t_player);
Mesh **meshes;
void onAudioTick(); void onAudioTick();
private: private:
+2 -2
View File
@@ -36,10 +36,10 @@ Floor::~Floor() {}
* @param spiral Spiral position * @param spiral Spiral position
* @param initOffset Number of floor (index) * @param initOffset Number of floor (index)
*/ */
void Floor::init(Mesh *mother, Point &spiral, u8 &initOffset) void Floor::init(const Mesh &mother, const Point &spiral, const u8 &initOffset)
{ {
this->mesh.position.set(0.00F, -10.00F, 0.00F); this->mesh.position.set(0.00F, -10.00F, 0.00F);
this->mesh.loadFrom(*mother); this->mesh.loadFrom(mother);
this->initOffset = initOffset; this->initOffset = initOffset;
this->animTimer = rand() % FLOOR_ANIMATION_LENGTH; this->animTimer = rand() % FLOOR_ANIMATION_LENGTH;
this->mesh.shouldBeLighted = true; this->mesh.shouldBeLighted = true;
+1 -1
View File
@@ -29,7 +29,7 @@ public:
Floor(); Floor();
~Floor(); ~Floor();
void init(Mesh *mother, Point &spiral, u8 &initOffset); void init(const Mesh &mother, const Point &spiral, const u8 &initOffset);
void animate(Player &player); void animate(Player &player);
}; };
+2 -2
View File
@@ -80,7 +80,7 @@ void Player::updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager
this->isCollideFloor = 0; this->isCollideFloor = 0;
Vector3 min = Vector3(); Vector3 min = Vector3();
Vector3 max = Vector3(); Vector3 max = Vector3();
for (int i = 0; i < floorManager.floorAmount; i++) for (u32 i = 0; i < floorManager.floorAmount; i++)
{ {
getMinMax(&floorManager.floors[i].mesh, &min, &max); getMinMax(&floorManager.floors[i].mesh, &min, &max);
this->isCollideFloor = this->playerNextPosition.collidesSquare(min, max); this->isCollideFloor = this->playerNextPosition.collidesSquare(min, max);
@@ -151,7 +151,7 @@ void Player::updateGravity(Pad &pad, FloorManager &floorManager)
this->velocity = this->lift; this->velocity = this->lift;
this->isOnFloor = 0; this->isOnFloor = 0;
for (int i = 0; i < floorManager.floorAmount; i++) for (u32 i = 0; i < floorManager.floorAmount; i++)
{ {
getMinMax(&floorManager.floors[i].mesh, &min, &max); getMinMax(&floorManager.floors[i].mesh, &min, &max);
this->isOnFloor = this->mesh.position.isOnSquare(min, max); this->isOnFloor = this->mesh.position.isOnSquare(min, max);