Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Vita Fix Block Inv -- MP Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Bourgeois committed Jul 27, 2022
1 parent 7c2f72c commit 744ffe0
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 18 deletions.
32 changes: 29 additions & 3 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,44 @@
"cppStandard": "c++17"
},
{
"name": "Linux",
"name": "Vita",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/ext/Stardust-Celeste/ext/glm/glm/"
],
"defines": [
"BUILD_PLAT=1"
"BUILD_PLAT=3"
],
"compilerPath": "/usr/local/vitasdk/bin/arm-vita-eabi-gcc",
"cStandard": "c17",
"intelliSenseMode": "linux-clang-x64",
"cppStandard": "c++17",
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**",
"${workspaceFolder}/ext/Stardust-Celeste/ext/glm/glm/"
],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"cppStandard": "c++17"
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
Expand Down
2 changes: 1 addition & 1 deletion ext/Stardust-Celeste
18 changes: 13 additions & 5 deletions src/Config.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#pragma once
#include <Platform/Platform.hpp>
#include <fstream>
#include <sstream>
#include <string>

namespace CrossCraft {

struct Config {
float sense;
bool compat;
std::string ip;
std::string username;
float sense = 1.50f;
bool compat = true;
std::string ip = "192.168.184.130";
std::string username = "CCC-Client";

inline static auto loadConfig() -> Config {
Config config;
config.sense = 1.0f;

#if BUILD_PLAT != BUILD_VITA
std::ifstream file("config.cfg");

#else
std::ifstream file("ux0:/data/CrossCraft-Classic/config.cfg");
#endif
if (file.is_open()) {
std::string line;

Expand Down Expand Up @@ -45,7 +49,11 @@ struct Config {
}
}
} else {
#if BUILD_PLAT != BUILD_VITA
std::ofstream file2("config.cfg");
#else
std::ofstream file2("ux0:/data/CrossCraft-Classic/config.cfg");
#endif
file2 << "sense:1.50" << std::endl;
file2 << "compat:0" << std::endl;
file2 << "client:0" << std::endl;
Expand Down
9 changes: 8 additions & 1 deletion src/Gamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ void GameState::on_start() {
if (forced_mp) {
#if PSP
Network::NetworkDriver::get().initGUI();
#elif BUILD_PLAT == BUILD_VITA
Network::NetworkDriver::get().init();
#endif
SC_APP_INFO("{}", world->cfg.username);
SC_APP_INFO("{}", world->cfg.ip);
client = create_scopeptr<MP::Client>(world.get(), world->cfg.ip);
world->client = client.get();
world->player->client_ref = client.get();
} else {

#if BUILD_PLAT != BUILD_VITA
FILE *fptr = fopen("save.ccc", "r");
#else
FILE *fptr = fopen("ux0:/data/CrossCraft-Classic/save.ccc", "r");
#endif
if (fptr) {
if (!world->load_world())
if (world->cfg.compat)
Expand Down
16 changes: 13 additions & 3 deletions src/MP/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Client::Client(World *wrld, std::string ip, u16 port) {
#ifdef _WIN32
unsigned long mode = (false) ? 0 : 1;
ioctlsocket(my_socket, FIONBIO, &mode);
#elif BUILD_PLAT == BUILD_VITA
int flag = 1;
sceNetSetsockopt(my_socket, SCE_NET_IPPROTO_TCP, SCE_NET_TCP_NODELAY,
(char *)&flag, sizeof(int));
fcntl(my_socket, F_SETFL, SCE_O_NBLOCK);
#else
int flags = fcntl(my_socket, F_GETFL, 0);

Expand Down Expand Up @@ -370,14 +375,15 @@ void Client::process_packet(RefPtr<Network::ByteBuffer> packet) {
SC_APP_INFO("World Size {} {} {}", data2->XSize, data2->YSize,
data2->ZSize);

wrld->world_size = { data2->XSize, data2->YSize, data2->ZSize };
wrld->world_size = {data2->XSize, data2->YSize, data2->ZSize};

SC_APP_INFO("Decompressed {} bytes. Expected {}", len, expected);

for (auto x = 0; x < 256; x++)
for (auto y = 0; y < 64; y++)
for (auto z = 0; z < 256; z++) {
auto idx_source = (y * data2->XSize * data2->ZSize) + (z * data2->XSize) + x + 4;
auto idx_source = (y * data2->XSize * data2->ZSize) +
(z * data2->XSize) + x + 4;
auto idx_destiny = wrld->getIdx(x, y, z);

wrld->worldData[idx_destiny] = outBuffer[idx_source];
Expand Down Expand Up @@ -632,8 +638,12 @@ auto get_len(Byte type) -> int {
void Client::receive() {
Byte newByte;
int res =
#if BUILD_PLAT != BUILD_VITA
::recv(my_socket, reinterpret_cast<char *>(&newByte), 1, MSG_PEEK);

#else
::recv(my_socket, reinterpret_cast<char *>(&newByte), 1,
SCE_NET_MSG_PEEK);
#endif
if (res <= 0)
return;

Expand Down
42 changes: 39 additions & 3 deletions src/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ auto Player::add_face_to_mesh(std::array<float, 12> data,
std::array<float, 8> uv, uint32_t lightVal,
glm::vec3 mypos, uint8_t type)
-> void { // Create color
#if BUILD_PLAT != BUILD_VITA
Rendering::Color c;
c.color = lightVal;

Expand All @@ -243,9 +244,11 @@ auto Player::add_face_to_mesh(std::array<float, 12> data,
m_index[type].push_back(idx_counter[type] + 3);
m_index[type].push_back(idx_counter[type] + 0);
idx_counter[type] += 4;
#endif
}

auto Player::setup_model(uint8_t type) -> void {
#if BUILD_PLAT != BUILD_VITA
idx_counter[type] = 0;
m_verts[type].clear();
m_verts[type].shrink_to_fit();
Expand Down Expand Up @@ -288,6 +291,13 @@ auto Player::setup_model(uint8_t type) -> void {

blockMesh[type].add_data(m_verts[type].data(), m_verts[type].size(),
m_index[type].data(), idx_counter[type]);
#else
auto uvs = getTexCoord(type, LIGHT_SIDE_X);
blockRep[type] = create_scopeptr<Graphics::G2D::Sprite>(
terrain_atlas, Rendering::Rectangle{{-1.5f, -4.0f}, {16, 16}},
Rendering::Rectangle{{uvs[2], uvs[3]}, {-1.0f / 16.0f, -1.0f / 16.0f}});
blockRep[type]->set_layer(-5);
#endif
}

auto Player::move_reset(std::any d) -> void {
Expand Down Expand Up @@ -851,27 +861,45 @@ auto Player::drawBlk(uint8_t type, int x, int y, float scale) -> void {
Rendering::RenderContext::get().matrix_view(glm::mat4(1));
Rendering::RenderContext::get().matrix_translate(
{153.5f + x * 20, 8 + y * 24, -20});

#if BUILD_PLAT != BUILD_VITA
if (type == 6 || type == 37 || type == 38 || type == 39 || type == 40)
Rendering::RenderContext::get().matrix_rotate({0.0f, 45.0f, 0});
else
Rendering::RenderContext::get().matrix_rotate({30.0f, 45.0f, 0});

Rendering::RenderContext::get().matrix_scale({scale, scale, scale});
#else
Rendering::RenderContext::get().matrix_scale(
{scale / 9.0f, scale / 9.0f, scale / 9.0f});
#endif

// DISABLE CULL
#if BUILD_PC || BUILD_PLAT == BUILD_VITA
#if BUILD_PC
glDisable(GL_CULL_FACE);
#elif BUILD_PLAT == BUILD_VITA
glDisable(GL_DEPTH_TEST);
#else
sceGuDisable(GU_CULL_FACE);
#endif

// Set up texture
Rendering::TextureManager::get().bind_texture(terrain_atlas);
#if BUILD_PLAT != BUILD_VITA
blockMesh[type].draw();

#else
// if (type == Block::Cobblestone && blockRep[type] != nullptr)
// SC_APP_INFO("CBL");
blockRep[type]->texture = terrain_atlas;
blockRep[type]->draw();
#endif

// ENABLE CULL
#if BUILD_PC || BUILD_PLAT == BUILD_VITA
#if BUILD_PC
glEnable(GL_CULL_FACE);
#elif BUILD_PLAT == BUILD_VITA
glEnable(GL_DEPTH_TEST);
#else
sceGuEnable(GU_CULL_FACE);
#endif
Expand Down Expand Up @@ -902,7 +930,9 @@ auto Player::drawBlkHand(uint8_t type) -> void {

// Set up texture
Rendering::TextureManager::get().bind_texture(terrain_atlas);
#if BUILD_PLAT != BUILD_VITA
blockMesh[type].draw();
#endif

// ENABLE CULL
#if BUILD_PC || BUILD_PLAT == BUILD_VITA
Expand Down Expand Up @@ -983,7 +1013,13 @@ auto Player::draw() -> void {
if (in_inventory) {
for (int i = 0; i < 42; i++) {
if (i == selectedBlock)
drawBlk(inventorySelection[i], i % 9, 7 - i / 9, 13.0f);
drawBlk(inventorySelection[i], i % 9, 7 - i / 9,
#if BUILD_PLAT != BUILD_VITA
13.0f
#else
11.0f
#endif
);
else
drawBlk(inventorySelection[i], i % 9, 7 - i / 9, 9.0f);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Player/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ class Player {

// Block Drawing

#if BUILD_PLAT != BUILD_VITA
uint16_t idx_counter[50];
std::vector<Rendering::Vertex> m_verts[50];
std::vector<uint16_t> m_index[50];
Rendering::Mesh blockMesh[50];
#else
ScopePtr<Graphics::G2D::Sprite> blockRep[50];
#endif

ScopePtr<UserInterface> playerHUD;

Expand Down
2 changes: 1 addition & 1 deletion src/World/DigAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ auto DigAction::dig(std::any d) -> void {
if (idx > 41)
return;

#if PSP
#if PSP || BUILD_PLAT == BUILD_VITA
idx = (w->player->in_cursor_x) + (w->player->in_cursor_y * 9);
#endif

Expand Down
10 changes: 9 additions & 1 deletion src/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ World::World(std::shared_ptr<Player> p) {
auto World::spawn() -> void { player->spawn(this); }

auto World::load_world() -> bool {
#if BUILD_PLAT != BUILD_VITA
gzFile save_file = gzopen("save.ccc", "rb");
#else
gzFile save_file = gzopen("ux0:/data/CrossCraft-Classic/save.ccc", "rb");
#endif
gzrewind(save_file);

int version = 0;
Expand Down Expand Up @@ -144,8 +148,12 @@ auto World::save(std::any p) -> void {
auto wrld = std::any_cast<World *>(p);
if (wrld->client == nullptr) {
SC_APP_DEBUG("SAVING!");

#if BUILD_PLAT != BUILD_VITA
gzFile save_file = gzopen("save.ccc", "wb");
#else
gzFile save_file =
gzopen("ux0:/data/CrossCraft-Classic/save.ccc", "wb");
#endif
if (save_file != nullptr) {
const int save_version = 1;
gzwrite(save_file, &save_version, 1 * sizeof(int));
Expand Down

0 comments on commit 744ffe0

Please sign in to comment.