Skip to content

Commit

Permalink
Eugh
Browse files Browse the repository at this point in the history
  • Loading branch information
EPICGameGuy committed Dec 4, 2023
1 parent a3f67a7 commit 9a3b361
Show file tree
Hide file tree
Showing 19 changed files with 377 additions and 186 deletions.
Binary file added assets/levels/new_level.lvl
Binary file not shown.
8 changes: 5 additions & 3 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This script downloads everything and compiles it on ubuntu

sudo apt install build-essential binutils-dev git cmake genisoimage libassimp-dev
#!/usr/bin/bash

# sudo apt install build-essential binutils-dev git cmake genisoimage libassimp-dev

make deploy_iso -j16
28 changes: 13 additions & 15 deletions dependencies/egg-library/include/egg/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
{ \
if (!(expr)) \
{ \
init_scr(); \
printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \
__FILE__, __func__, __LINE__); \
init_scr(); \
print_stack_trace(); \
scr_printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \
__FILE__, __func__, __LINE__); \
SleepThread(); \
Expand All @@ -27,11 +27,11 @@
{ \
if (!(expr)) \
{ \
init_scr(); \
printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \
__FILE__, __func__, __LINE__); \
printf("Check msg: %s\n", (msg)); \
init_scr(); \
print_stack_trace(); \
scr_printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \
__FILE__, __func__, __LINE__); \
scr_printf("Check msg: %s\n", (msg)); \
Expand All @@ -46,14 +46,12 @@
}
#define checkf(expr, msg) \
{ \
expr; \
{ \
expr; \
}
#endif
static void print_stack_trace()
{
return;

unsigned int* stackTrace[256];
int i = 0;

Expand Down Expand Up @@ -82,15 +80,15 @@ static void print_stack_trace()
} \
}

#define checkf(expr, msg) \
{ \
if (!(expr)) \
{ \
printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \
__FILE__, __func__, __LINE__); \
printf("Check msg: %s\n", (msg)); \
throw std::runtime_error("Check failed!\n"); \
} \
#define checkf(expr, msg) \
{ \
if (!(expr)) \
{ \
printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \
__FILE__, __func__, __LINE__); \
printf("Check msg: %s\n", (msg)); \
throw std::runtime_error("Check failed!\n"); \
} \
}
#else
#define check(expr) \
Expand Down
88 changes: 2 additions & 86 deletions dependencies/egg-library/include/egg/asset.hpp
Original file line number Diff line number Diff line change
@@ -1,88 +1,4 @@
#pragma once

#include <cstdint>
#include <vector>
#include <unordered_set>

#include "egg/filesystem.hpp"
#include "egg/hashmap.hpp"
#include "egg/offset_pointer.hpp"

namespace Asset
{
// Reference to an on-disk asset. This is just a hash of it's ISO 9660 8.3
// filepath (see Filesystem::convert_to_iso_path)
struct Reference
{
uint32_t hash;

constexpr Reference()
: hash(0)
{
}

constexpr Reference(uint32_t in_hash)
: hash(in_hash)
{
}

constexpr Reference(const Filesystem::Path& path)
: hash(0)
{
hash = path.hash();
}

constexpr Reference(const char* path, bool convert_to_iso_path = true)
: hash(0)
{
hash = Filesystem::Path(path, convert_to_iso_path).hash();
}

constexpr bool operator==(const Reference& other) const
{
return hash == other.hash;
}
};

constexpr size_t asset_hashmap_size = 128;
using AssetHashMapT = HashMap<asset_hashmap_size, Reference, Filesystem::Path>;

// Note: this will crash if the path does not exist
const Filesystem::Path& lookup_path(Reference reference);

// Returns true if it succesfully added the path
bool add_path(Reference reference, const Filesystem::Path& path);

// Returns true if it succesfully added the path
// This version hashes the path before adding it
bool add_path(const Filesystem::Path& path);

bool add_path(Reference reference, const char* path, bool convert_path);

// Copies the passed in asset table bytes to the global asset table
// Checks to make sure length matches the length of the global asset table
void load_asset_table(std::byte* bytes, size_t length);

// Writes out the global asset table
void serialize_asset_table(std::vector<std::byte>& out_bytes);

AssetHashMapT& get_asset_table();
} // namespace Asset

template <>
struct std::hash<Asset::Reference>
{
std::size_t operator()(const Asset::Reference& k) const
{
return k.hash;
}
};

// Overload this to add reference collection to your own types
static void collect_references(std::unordered_set<Asset::Reference>& references, const ::OffsetArray<Asset::Reference>& arr)
{
for (Asset::Reference ref : arr)
{
references.insert(ref);
}
}
// Asset namespace was moved to filesystem
#include "egg/filesystem.hpp"
103 changes: 101 additions & 2 deletions dependencies/egg-library/include/egg/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

#include <cstddef>
#include <vector>
#include <string.h>
#include <string>
#include <string_view>
#include <memory>
#include <functional>
#include <array>
#include <string.h>
#include <cstdint>
#include <unordered_set>

#include "egg/assert.hpp"
#include "egg/hashing.hpp"
#include "egg/string.hpp"
#include "egg/hashmap.hpp"
#include "egg/offset_pointer.hpp"

#ifdef _MSC_VER
#include <stdlib.h> // for WCSTOMBS
Expand Down Expand Up @@ -258,4 +262,99 @@ struct std::hash<Filesystem::Path>
{
return k.hash();
}
};
};

namespace Asset
{
// Reference to an on-disk asset. This is just a hash of it's ISO 9660 8.3
// filepath (see Filesystem::convert_to_iso_path)
struct Reference
{
uint32_t hash;

constexpr Reference()
: hash(0)
{
}

constexpr Reference(uint32_t in_hash)
: hash(in_hash)
{
}

constexpr Reference(const Filesystem::Path& path)
: hash(0)
{
hash = path.hash();
}

constexpr Reference(const char* path, bool convert_to_iso_path = true)
: hash(0)
{
hash = Filesystem::Path(path, convert_to_iso_path).hash();
}

constexpr bool operator==(const Reference& other) const
{
return hash == other.hash;
}
};

constexpr size_t asset_hashmap_size = 128;
using AssetHashMapT = HashMap<asset_hashmap_size, Reference, Filesystem::Path>;

// Note: this will crash if the path does not exist
const Filesystem::Path& lookup_path(Reference reference);

// Returns true if it succesfully added the path
bool add_path(Reference reference, const Filesystem::Path& path);

// Returns true if it succesfully added the path
// This version hashes the path before adding it
bool add_path(const Filesystem::Path& path);

bool add_path(Reference reference, const char* path, bool convert_path);

// Copies the passed in asset table bytes to the global asset table
// Checks to make sure length matches the length of the global asset table
void load_asset_table(std::byte* bytes, size_t length);

// Writes out the global asset table
void serialize_asset_table(std::vector<std::byte>& out_bytes);

AssetHashMapT& get_asset_table();
} // namespace Asset

template <>
struct std::hash<Asset::Reference>
{
std::size_t operator()(const Asset::Reference& k) const
{
return k.hash;
}
};

// Overload this to add reference collection to your own types
static void collect_references(std::unordered_set<Asset::Reference>& references, const ::OffsetArray<Asset::Reference>& arr)
{
for (Asset::Reference ref : arr)
{
references.insert(ref);
}
}

// Asset literal constructor
//
// Converts the path to a asset reference hash
constexpr Asset::Reference operator""_asset(const char* p, std::size_t)
{
return Asset::Reference(p, true);
}

namespace Filesystem
{
static bool load_file(Asset::Reference reference, std::unique_ptr<std::byte[]>& out_bytes, size_t& size, size_t alignment = 1)
{
return load_file(Asset::lookup_path(reference), out_bytes, size, alignment);
}
} // namespace Filesystem
5 changes: 5 additions & 0 deletions dependencies/egg-library/src/asset.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "egg/asset.hpp"

static bool hashmap_loaded = false;
static HashMap<Asset::asset_hashmap_size, Asset::Reference, Filesystem::Path> asset_paths;

const Filesystem::Path& Asset::lookup_path(Reference reference)
{
check(hashmap_loaded);
return asset_paths[reference];
}

Expand All @@ -29,16 +31,19 @@ void Asset::load_asset_table(std::byte* bytes, size_t length)
check(sizeof(AssetHashMapT) == length);

memcpy(&asset_paths, bytes, sizeof(AssetHashMapT));
hashmap_loaded = true;
}

void Asset::serialize_asset_table(std::vector<std::byte>& out_bytes)
{
check(hashmap_loaded);
out_bytes.resize(sizeof(AssetHashMapT));

memcpy(out_bytes.data(), &asset_paths, sizeof(AssetHashMapT));
}

Asset::AssetHashMapT& Asset::get_asset_table()
{
check(hashmap_loaded);
return asset_paths;
}
7 changes: 6 additions & 1 deletion include/objects/mesh_object.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#pragma once

#include "renderer/renderable.hpp"
#include "utils/debuggable.hpp"
#include "components/transform_component.hpp"
#include "components/collision_component.hpp"
#include "egg/filesystem.hpp"

class MeshObject: public Renderable
class MeshObject: public Renderable, public Debuggable
{
public:
MeshObject();
MeshObject(const Filesystem::Path& mesh_path);
MeshObject(Asset::Reference mesh_reference);
virtual void on_gs_init() override;
virtual void render(const GS::GSState& gs_state) override;
TransformComponent transform;
class Mesh* mesh;

virtual const char* get_name() const override;
virtual const char* get_type_name() const { return typeid(MeshObject).name(); }
};
5 changes: 4 additions & 1 deletion include/objects/teapot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

#include "tick.hpp"
#include "renderer/renderable.hpp"
#include "utils/debuggable.hpp"
#include "components/transform_component.hpp"
#include "components/collision_component.hpp"

class Teapot: public Renderable
class Teapot: public Renderable, public Debuggable
{
public:
Teapot();
Expand All @@ -14,4 +15,6 @@ class Teapot: public Renderable
collision_component collision;

class teapot_render_proxy* render_proxy;

virtual const char* get_type_name() const override { return typeid(Teapot).name(); }
};
Loading

0 comments on commit 9a3b361

Please sign in to comment.