Merge branch 'static-game-try-1'

This commit is contained in:
Sandro Sobczyński
2020-11-04 13:21:08 +01:00
29 changed files with 224 additions and 235 deletions
+19 -17
View File
@@ -30,13 +30,14 @@ extern u32 VU1Draw3D_CodeEnd __attribute__((section(".vudata")));
Engine::Engine()
{
SifInitRpc(0);
srand(time(NULL));
VU1::uploadProgram(0, &VU1Draw3D_CodeStart, &VU1Draw3D_CodeEnd);
audio.startThread();
isInitialized = 0;
isScreenInitialized = 0;
mainThreadId = GetThreadId();
setDefaultScreen();
firePS2();
}
Engine::Engine(const ScreenSettings &t_screen)
{
screen = t_screen;
firePS2();
}
Engine::~Engine() {}
@@ -45,12 +46,6 @@ Engine::~Engine() {}
// Methods
// ----
void Engine::setScreen(ScreenSettings &t_settings)
{
screen = t_settings;
isScreenInitialized = true;
}
void Engine::setDefaultScreen()
{
screen.projectionScale = 4096.0F;
@@ -60,14 +55,11 @@ void Engine::setDefaultScreen()
screen.aspectRatio = 4.0F / 3.0F;
screen.width = 640.0F;
screen.height = 480.0F;
isScreenInitialized = true;
}
void Engine::init(Game *t_game, u32 t_gifPacketSize)
{
if (!isScreenInitialized)
PRINT_ERR("Cant init because screen was not set!");
else if (isInitialized)
if (isInitialized)
PRINT_ERR("Already initialized!");
else
{
@@ -88,6 +80,16 @@ void Engine::wakeup(s32 t_alarmId, u16 t_time, void *t_common)
ExitHandler();
}
void Engine::firePS2()
{
SifInitRpc(0);
srand(time(NULL));
VU1::uploadProgram(0, &VU1Draw3D_CodeStart, &VU1Draw3D_CodeEnd);
audio.startThread();
isInitialized = 0;
mainThreadId = GetThreadId();
}
void Engine::gameLoop()
{
for (;;)
+3 -2
View File
@@ -24,12 +24,12 @@ class Engine
{
public:
Engine(const ScreenSettings &screen);
Engine();
~Engine();
void init(Game *t_game, u32 t_gifPacketSize);
void setDefaultScreen();
void setScreen(ScreenSettings &t_settings);
Renderer *renderer;
Audio audio;
ScreenSettings screen;
@@ -37,9 +37,10 @@ public:
float fps;
private:
void firePS2();
u8 fpsDelayer;
Timer timer;
u8 isInitialized, isScreenInitialized;
u8 isInitialized;
void gameLoop();
Game *game;
s32 mainThreadId;
+1 -1
View File
@@ -35,7 +35,7 @@ public:
void makeZRotation(float t_radians);
void translate(float t_x, float t_y, float t_z);
void setPerspective(ScreenSettings &screen);
void print();
const void print() const;
};
#endif
+1 -1
View File
@@ -27,7 +27,7 @@ public:
void update(Vector3 &a, Vector3 &b, Vector3 &c);
inline float distanceTo(Vector3 &t_vec) { return this->distance + this->normal.innerProduct(t_vec); }
void print();
const void print() const;
};
#endif
+1 -1
View File
@@ -33,7 +33,7 @@ public:
void set(const float &t_x, const float &t_y);
void set(const Point &v);
void print();
const void print() const;
};
#endif
+1 -1
View File
@@ -54,7 +54,7 @@ public:
void set(const float &x, const float &y, const float &z);
void copy(Vector3 &v);
float distanceTo(Vector3 &v);
void print();
const void print() const;
};
#endif
@@ -21,7 +21,6 @@ struct ScreenSettings
float aspectRatio;
float nearPlaneDist;
float farPlaneDist;
/** change it to 4096.0F to check out frustum culling! 😎 */
float projectionScale;
};
+1 -1
View File
@@ -33,7 +33,7 @@ public:
~GifSender();
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 sendPacket();
void sendClear(zbuffer_t *t_zBuffer);
+9 -9
View File
@@ -35,22 +35,22 @@ public:
prim_t prim;
/** 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 */
void drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
void drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
/** PATH3 Many */
void drawByPath3(Mesh **t_meshes, u16 t_amount);
void drawByPath3(Mesh *t_meshes, u16 t_amount);
/** PATH3 Single */
void drawByPath3(Mesh *t_mesh);
void drawByPath3(Mesh &t_mesh);
/** 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 */
void draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
void draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
/** PATH1 Many */
void draw(Mesh **t_meshes, u16 t_amount);
void draw(Mesh *t_meshes, u16 t_amount);
/** PATH1 Single */
void draw(Mesh *t_mesh);
void draw(Mesh &t_mesh);
void setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes);
@@ -59,7 +59,7 @@ public:
TextureRepository *getTextureRepository() { return &textureRepo; };
private:
void changeTexture(Mesh *t_mesh, u32 t_materialId);
void changeTexture(const Mesh &t_mesh, u32 t_materialId);
u32 lastTextureId;
texbuffer_t textureBuffer;
u8 isTextureVRAMAllocated;
+2 -2
View File
@@ -28,11 +28,11 @@ public:
~VifSender();
// 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);
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
MATRIX localWorld, localScreen;
VECTOR position, rotation;
+3 -3
View File
@@ -187,8 +187,8 @@ void Matrix::setPerspective(ScreenSettings &t_screen)
{
float fovYdiv2 = Math::HALF_ANG2RAD * t_screen.fov;
float cotFOV = 1.0F / (Math::sin(fovYdiv2) / Math::cos(fovYdiv2));
float w = cotFOV * (t_screen.width / 4096.0F) / t_screen.aspectRatio;
float h = cotFOV * (t_screen.height / 4096.0F);
float w = cotFOV * (t_screen.width / t_screen.projectionScale) / t_screen.aspectRatio;
float h = cotFOV * (t_screen.height / t_screen.projectionScale);
this->data[0] = w;
this->data[1] = 0.0F;
@@ -253,7 +253,7 @@ void Matrix::lookAt(Vector3 &t_up, Vector3 &t_position, Vector3 &t_target)
data[15] = 1;
}
void Matrix::print()
const void Matrix::print() const
{
printf("MATRIX(\n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n)\n",
data[0], data[1], data[2], data[3],
+1 -1
View File
@@ -44,7 +44,7 @@ void Plane::update(Vector3 &a, Vector3 &b, Vector3 &c)
this->distance = -this->normal.innerProduct(b);
}
void Plane::print()
const void Plane::print() const
{
printf("Plane(Vector3(%f, %f, %f), %f)\n", this->normal.x, this->normal.y, this->normal.z, this->distance);
}
+1 -1
View File
@@ -55,7 +55,7 @@ void Point::set(const Point &v)
y = v.y;
}
void Point::print()
const void Point::print() const
{
printf("Point(%f, %f)\n", x, y);
}
+1 -1
View File
@@ -295,7 +295,7 @@ float Vector3::distanceTo(Vector3 &v)
// (this->z - another.z) * (this->z - another.z));
}
void Vector3::print()
const void Vector3::print() const
{
printf("Vector3(%f, %f, %f)\n", x, y, z);
}
+3 -2
View File
@@ -71,14 +71,15 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position)
{
Vector3 boxCalcTemp;
u8 boxResult = 1, boxIn = 0, boxOut = 0;
for (int i = 0; i < 6; i++)
for (u8 i = 0; i < 6; i++)
{
boxOut = 0;
boxIn = 0;
// for each corner of the box do ...
// get out of the cycle as soon as a box as corners
// both inside and out of the frustum
for (int y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++)
for (u8 y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++)
{
boxCalcTemp.set(
boundingBox[y].x + position.x,
+6 -6
View File
@@ -129,7 +129,7 @@ void GifSender::addClear(zbuffer_t *t_zBuffer)
* @param objects3D Array of 3D objects pointers
* @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)
{
@@ -140,14 +140,14 @@ void GifSender::addObject(RenderData *t_renderData, Mesh *t_mesh, u32 vertexCoun
tempDMATag = q;
q++;
q = draw_texture_sampling(q, 0, &t_mesh->lod);
q = draw_texturebuffer(q, 0, textureBuffer, &t_mesh->clut);
dw = (u64 *)draw_prim_start(q, 0, t_renderData->prim, &t_mesh->color);
q = draw_texture_sampling(q, 0, &t_mesh.lod);
q = draw_texturebuffer(q, 0, textureBuffer, &t_mesh.clut);
dw = (u64 *)draw_prim_start(q, 0, t_renderData->prim, &t_mesh.color);
xyz = new xyz_t[vertexCount];
rgbaq = new color_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);
delete[] xyz;
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][1] = (t_mesh.color.g * lights[i][1] / 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;
+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->getId() != lastTextureId)
@@ -161,31 +161,31 @@ void Renderer::allocateBuffers(float t_screenW, float t_screenH)
/// --- Draw: PATH3
/** 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++)
drawByPath3(t_meshes[i], t_bulbs, t_bulbsCount);
}
/** 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();
if (!t_mesh->isDataLoaded())
if (!t_mesh.isDataLoaded())
PRINT_ERR("Can't draw, because no mesh data was loaded!");
if (t_mesh->getCurrentAnimationFrame() != t_mesh->getNextAnimationFrame())
t_mesh->animate();
for (u32 i = 0; i < t_mesh->getMaterialsCount(); i++)
if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame())
t_mesh.animate();
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;
changeTexture(t_mesh, t_mesh->getMaterial(i).getId());
changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
gifSender->initPacket(context);
u32 vertCount = t_mesh->getMaterial(i).getFacesCount();
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
VECTOR *vertices = new VECTOR[vertCount];
VECTOR *normals = 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->sendPacket();
delete[] vertices;
@@ -195,40 +195,40 @@ void Renderer::drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
}
/** 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 */
void Renderer::drawByPath3(Mesh *t_mesh) { drawByPath3(t_mesh, NULL, 0); }
void Renderer::drawByPath3(Mesh &t_mesh) { drawByPath3(t_mesh, NULL, 0); }
/// --- Draw: PATH1
/** 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++)
draw(t_meshes[i], t_bulbs, t_bulbsCount);
}
/** 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();
vifSender->sendMatrices(renderData, t_mesh->position, t_mesh->rotation);
if (!t_mesh->isDataLoaded())
vifSender->sendMatrices(renderData, t_mesh.position, t_mesh.rotation);
if (!t_mesh.isDataLoaded())
PRINT_ERR("Can't draw, because no mesh data was loaded!");
if (t_mesh->getCurrentAnimationFrame() != t_mesh->getNextAnimationFrame())
t_mesh->animate();
for (u32 i = 0; i < t_mesh->getMaterialsCount(); i++)
if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame())
t_mesh.animate();
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;
u32 vertCount = t_mesh->getMaterial(i).getFacesCount();
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
VECTOR *vertices = new VECTOR[vertCount];
VECTOR *normals = new VECTOR[vertCount];
VECTOR *coordinates = new VECTOR[vertCount];
changeTexture(t_mesh, t_mesh->getMaterial(i).getId());
vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
changeTexture(t_mesh, t_mesh.getMaterial(i).getId());
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);
delete[] vertices;
delete[] normals;
@@ -237,10 +237,10 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
}
/** 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 */
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);
}
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
for (u32 i = 0; i < vertCount2;)
@@ -72,7 +72,7 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver
}
/** 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;
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
GS_SET_TEX1(
t_mesh->lod.calculation,
t_mesh->lod.max_level,
t_mesh->lod.mag_filter,
t_mesh->lod.min_filter,
t_mesh->lod.mipmap_select,
t_mesh->lod.l,
(int)(t_mesh->lod.k * 16.0F)),
t_mesh.lod.calculation,
t_mesh.lod.max_level,
t_mesh.lod.mag_filter,
t_mesh.lod.min_filter,
t_mesh.lod.mipmap_select,
t_mesh.lod.l,
(int)(t_mesh.lod.k * 16.0F)),
GS_REG_TEX1);
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.components,
textureBuffer->info.function,
t_mesh->clut.address >> 6,
t_mesh->clut.psm,
t_mesh->clut.storage_mode,
t_mesh->clut.start,
t_mesh->clut.load_method),
t_mesh.clut.address >> 6,
t_mesh.clut.psm,
t_mesh.clut.storage_mode,
t_mesh.clut.start,
t_mesh.clut.load_method),
GS_REG_TEX0);
vu1.add128(
+74 -86
View File
@@ -16,7 +16,13 @@
// Constructors/Destructors
// ----
Ari::Ari() {}
const u8 WATER_TILES_COUNT = 64;
Ari::Ari(Engine *t_engine) : engine(t_engine), camera(&engine->screen)
{
waterFloors = new Mesh[WATER_TILES_COUNT];
spirals = new Point[WATER_TILES_COUNT];
}
Ari::~Ari() {}
@@ -24,13 +30,74 @@ Ari::~Ari() {}
// Methods
// ----
// TEST START
const u8 WATER_TILES_COUNT = 64;
Mesh *island, *islandAddons, *skybox, *test;
Mesh **waterFloors;
Point *spirals;
void Ari::onInit()
{
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;
x = y = dx = 0;
@@ -54,82 +121,3 @@ void calcSpiral(int X, int Y)
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]);
}
+8 -4
View File
@@ -23,19 +23,23 @@ class Ari : public Game
{
public:
Ari();
Ari(Engine *t_engine);
~Ari();
void onInit();
void onUpdate();
Engine engine;
Engine *engine;
private:
void initBulb();
void calcSpiral(int X, int Y);
LightBulb bulb;
Player *player;
Camera *camera;
Player player;
Mesh island, islandAddons, skybox;
Mesh *waterFloors;
Point *spirals;
Camera camera;
TextureRepository *texRepo;
};
+3 -3
View File
@@ -12,9 +12,9 @@
int main()
{
Ari game = Ari();
game.engine.setDefaultScreen();
game.engine.init(&game, 40000);
Engine engine = Engine();
Ari game = Ari(&engine);
game.engine->init(&game, 40000);
SleepThread();
return 0;
}
+25 -23
View File
@@ -14,7 +14,10 @@
// Constructors/Destructors
// ----
Floors::Floors() {}
const u8 FLOORS_COUNT = 64; // Temp change it also in floor_manager.hpp
Floors::Floors(Engine *t_engine)
: engine(t_engine), floorManager(FLOORS_COUNT), camera(&t_engine->screen) {}
Floors::~Floors() {}
@@ -24,31 +27,30 @@ Floors::~Floors() {}
void Floors::onInit()
{
player = new Player();
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.addListener(floorManager);
engine.audio.addListener(&lightManager);
engine.audio.loadSong("NF-CHILL.WAV");
engine.audio.play();
texRepo = engine.renderer->getTextureRepository();
texRepo->addByMesh("warrior/", player->mesh);
texRepo->addByMesh("floor/", *floorManager->meshes[0]);
for (size_t i = 1; i < floorManager->floorAmount; i++)
texRepo->getByMesh(floorManager->meshes[0]->getId(), floorManager->meshes[0]->getMaterial(0).getId())
->addLink(floorManager->meshes[i]->getId(), floorManager->meshes[i]->getMaterial(0).getId());
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
engine->audio.init(2);
engine->audio.addListener(&floorManager);
engine->audio.addListener(&lightManager);
engine->audio.loadSong("NF-CHILL.WAV");
engine->audio.setVolume(1);
engine->audio.play();
texRepo = engine->renderer->getTextureRepository();
texRepo->addByMesh("warrior/", player.mesh);
texRepo->addByMesh("floor/", floorManager.floors[0].mesh);
for (u32 i = 1; i < floorManager.floorAmount; i++)
texRepo->getByMesh(floorManager.floors[0].mesh.getId(), floorManager.floors[0].mesh.getMaterial(0).getId())
->addLink(floorManager.floors[i].mesh.getId(), floorManager.floors[i].mesh.getMaterial(0).getId());
}
void Floors::onUpdate()
{
if (engine.pad.isCrossClicked)
printf("FPS:%f\n", engine.fps);
if (engine->pad.isCrossClicked)
printf("FPS:%f\n", engine->fps);
lightManager.update();
camera->update(engine.pad, player->mesh);
floorManager->update(*player);
player->update(engine.pad, *camera, *floorManager);
engine.renderer->draw(&player->mesh);
engine.renderer->drawByPath3(floorManager->meshes, floorManager->floorAmount, lightManager.bulbs, lightManager.bulbsCount);
camera.update(engine->pad, player.mesh);
floorManager.update(player);
player.update(engine->pad, camera, floorManager);
engine->renderer->draw(player.mesh);
for (u8 i = 0; i < FLOORS_COUNT; i++)
engine->renderer->drawByPath3(floorManager.floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount);
}
+5 -5
View File
@@ -24,20 +24,20 @@ class Floors : public Game
{
public:
Floors();
Floors(Engine *t_engine);
~Floors();
void onInit();
void onUpdate();
Engine engine;
Engine *engine;
private:
TextureRepository *texRepo;
LightManager lightManager;
FloorManager *floorManager;
Player *player;
Camera *camera;
FloorManager floorManager;
Player player;
Camera camera;
};
#endif
+3 -3
View File
@@ -12,9 +12,9 @@
int main()
{
Floors game = Floors();
game.engine.setDefaultScreen();
game.engine.init(&game, 40000);
Engine engine = Engine();
Floors game = Floors(&engine);
game.engine->init(&game, 40000);
SleepThread();
return 0;
}
+6 -13
View File
@@ -33,7 +33,6 @@ FloorManager::FloorManager(int t_floorAmount)
FloorManager::~FloorManager()
{
delete[] spirals;
delete[] meshes;
}
// ----
@@ -78,17 +77,11 @@ void FloorManager::calcSpiral(int X, int Y)
void FloorManager::initFloors()
{
PRINT_LOG("Initializing floors");
meshes = new Mesh *[floorAmount];
meshes[0] = new Mesh();
meshes[0]->loadObj("floor/", "floor", 2.0F, false);
meshes[0]->shouldBeFrustumCulled = true;
meshes[0]->shouldBeLighted = true;
for (u8 i = 0; i < floorAmount; i++)
{
floors[i].init(meshes[0], spirals[i], i);
meshes[i] = &floors[i].mesh;
}
floors[0].mesh.loadObj("floor/", "floor", 2.0F, false);
floors[0].mesh.shouldBeFrustumCulled = true;
floors[0].mesh.shouldBeLighted = true;
for (u8 i = 1; i < floorAmount; i++)
floors[i].init(floors[0].mesh, spirals[i], i);
PRINT_LOG("Floors initialized!");
}
@@ -164,7 +157,7 @@ void FloorManager::onAudioTick()
{
for (u8 i = 0; i < floorAmount; i++)
{
if (i + 1 > floorAmount / (audioOffset + 1))
if (u8(i + 1) > floorAmount / (audioOffset + 1))
floors[i].isByAudioTriggered = true;
else
floors[i].isByAudioTriggered = false;
@@ -27,9 +27,8 @@ public:
FloorManager(int t_floorAmount);
~FloorManager();
Floor floors[64]; // Temp change it also in floors.cpp
int floorAmount;
u32 floorAmount;
void update(Player &t_player);
Mesh **meshes;
void onAudioTick();
private:
+2 -2
View File
@@ -36,10 +36,10 @@ Floor::~Floor() {}
* @param spiral Spiral position
* @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.loadFrom(*mother);
this->mesh.loadFrom(mother);
this->initOffset = initOffset;
this->animTimer = rand() % FLOOR_ANIMATION_LENGTH;
this->mesh.shouldBeLighted = true;
+1 -1
View File
@@ -29,7 +29,7 @@ public:
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);
};
+2 -2
View File
@@ -80,7 +80,7 @@ void Player::updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager
this->isCollideFloor = 0;
Vector3 min = 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);
this->isCollideFloor = this->playerNextPosition.collidesSquare(min, max);
@@ -151,7 +151,7 @@ void Player::updateGravity(Pad &pad, FloorManager &floorManager)
this->velocity = this->lift;
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);
this->isOnFloor = this->mesh.position.isOnSquare(min, max);