Skip to content

Commit

Permalink
Move VoxelObject into its own header
Browse files Browse the repository at this point in the history
  • Loading branch information
ZivDero committed Nov 18, 2024
1 parent 783f131 commit 80a0d46
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/foot.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "ftimer.h"
#include "ilocomotion.h"
#include "vector.h"
#include "voxelobj.h"


class TeamClass;
Expand Down
1 change: 1 addition & 0 deletions src/objecttype.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "abstracttype.h"
#include "search.h"
#include "voxelobj.h"


class ObjectClass;
Expand Down
1 change: 1 addition & 0 deletions src/techno.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "facing.h"
#include "ttimer.h"
#include "ftimer.h"
#include "voxelobj.h"
#include "search.h"


Expand Down
6 changes: 0 additions & 6 deletions src/tibsun/tibsun_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -2801,12 +2801,6 @@ struct ShapeFileStruct
#pragma pack()


struct VoxelObject {
VoxelLibraryClass* VoxelLibrary;
MotionLibraryClass* MotionLibrary;
};


#pragma pack(4)
struct IsoTileHeaderStruct
{
Expand Down
103 changes: 103 additions & 0 deletions src/voxel/voxelobj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
/* O P E N S O U R C E -- T S + + **
/*******************************************************************************
*
* @project TS++
*
* @file VOXELOBJ.H
*
* @authors ZivDero
*
* @brief Compound voxel object struct.
*
* @license TS++ is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* TS++ is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#pragma once

#include "always.h"
#include "ccfile.h"
#include "voxellib.h"
#include "motionlib.h"

struct VoxelObject
{
public:
~VoxelObject()
{
delete VoxelLibrary;
VoxelLibrary = nullptr;
delete MotionLibrary;
MotionLibrary = nullptr;
}

void Clear()
{
VoxelLibrary = nullptr;
MotionLibrary = nullptr;
}

/**
* Loads a voxel object from files.
*
* @author: ZivDero
*/
bool Load(VoxelIndexClass& index, const char* graphic_name)
{
char buffer[260];
bool success = true;

_makepath(buffer, nullptr, nullptr, graphic_name, ".VXL");
CCFileClass vxl(buffer);

if (vxl.Is_Available()) {
delete VoxelLibrary;
VoxelLibrary = new VoxelLibraryClass(&vxl);

if (!VoxelLibrary || VoxelLibrary->Load_Failed()) {
success = false;
}

_makepath(buffer, nullptr, nullptr, graphic_name, ".HVA");
CCFileClass hva(buffer);

delete MotionLibrary;
MotionLibrary = new MotionLibraryClass(&hva);

if (!MotionLibrary || MotionLibrary->Load_Failed()) {
success = false;
}
else {
MotionLibrary->Scale(VoxelLibrary->Get_Layer_Info(0, 0)->Scale);
}
}
else {
success = false;
}

if (success) {
index.Clear();
}
else {
this->~VoxelObject();
this->Clear();
}

return success;
}

VoxelLibraryClass* VoxelLibrary;
MotionLibraryClass* MotionLibrary;
};

0 comments on commit 80a0d46

Please sign in to comment.