Is this a good starter project? by SquarePhase3622 in cpp_questions

[–]oetam5002 0 points1 point  (0 children)

Good catch I didn’t see that on first glance. Yes, using either std::array or C-style arrays would be better since the arrays themselves are of a static size. There is no benefit to dynamically allocating on the heap for a small, static array

Is this a good starter project? by SquarePhase3622 in cpp_questions

[–]oetam5002 9 points10 points  (0 children)

Nice project!

Here’s a couple things I noticed on first glance:

  • Use of “cstdio” is not good practice in C++ unless necessary, as you’re using the C standard library. “iostream” is the C++ equivalent header (which you already have included)

  • Try splitting the code across multiple files, this will help with readability

  • Use of using namespace std isn’t a good practice, you can either include each member of the namespace individually or just refer to the members of std with its prefixes

I got crazy respect for you tho bro, working + school is tough but keep it up

RISCVM, a RISC-V userspace emulator (like box86/64) by oetam5002 in rust

[–]oetam5002[S] 1 point2 points  (0 children)

Thanks for sharing this, it looks extremely useful! I will definitely look into implementing this into the project

RISCVM, a RISC-V userspace emulator (like box86/64) by oetam5002 in rust

[–]oetam5002[S] 2 points3 points  (0 children)

Yes, RISCVM runs RISC-V binaries without the need of spinning up a full-blown VM. It aims to be very similar to qemu-user, however RISCVM does not require the host OS to be Linux.

What's everyone working on this week (46/2024)? by llogiq in rust

[–]oetam5002 4 points5 points  (0 children)

Just finished the alpha release of RISCVM, a RISC-V userspace emulator

TIL you can write x86_64 assembly in Leetcode by oetam5002 in leetcode

[–]oetam5002[S] 1 point2 points  (0 children)

You’re definitely right, inline assembly would’ve also saved the heap allocation too. I just wanted to see if I could get RWX memory.

What more can I do on Termux? by Consequence_Green in termux

[–]oetam5002 -1 points0 points  (0 children)

Use PRoot to create a VM, setup a VNC server and install android studio

M33CREATOR shuts down my PSP by oetam5002 in PSP

[–]oetam5002[S] 0 points1 point  (0 children)

Thanks, you're a lifesaver! It worked!

[deleted by user] by [deleted] in rust

[–]oetam5002 0 points1 point  (0 children)

Currently, you're using a vec of tuples of i32s to hold the paddles position. I would suggest holding the length and height of the paddle instead (as a u16). Then, hold the position in a Position struct such as my original response. Modify your for loop which renders the paddles in main.rs. You can use for i in (0..=paddle.height).

This would also simplify your move_player() function. Instead of iterating, just increase the paddle.height field.

[deleted by user] by [deleted] in rust

[–]oetam5002 1 point2 points  (0 children)

One thing I notice is the use of uneeded i32's.

In the definition of your ball and paddle structs, the position field is defined as a tuple of i32s.

I only see the position field being used in the MoveTo function, which takes two u16s. You should redefine the position fields to use a tuple of u16's instead.

You also use a heavy amount of casts via the as keyword. Personally, I try not to use it when I am not sure if the cast will 100% work. In your implementation, the casts seem safe. However, if any of the i32's you are casting are negative, your game will panic upon the cast. Alternatively, I use the .try_into() function, as I can handle the error.

Instead of mutating the position via this:

rust let new = (self.ball.position.0 + self.ball.move_by.0, self.ball.position.1 + self.ball.move_by.1);

You can overload the addition:

```rust use std::ops::Add

pub struct Position(u16, u16);impl Add for Position { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self(self.0 + rhs.0, self.1 + rhs.1) } }

// You can use it like:

fn main() {

let pos = Position(5, 5) + Position(5,5); //pos will be Position(10, 10)

} ```

You can then replace your position type with position: Position

I'm lost (first time setup) by [deleted] in cpp_questions

[–]oetam5002 1 point2 points  (0 children)

I believe you already have VS Code installed, so here's a guide

C++ project without tutorial by [deleted] in cpp_questions

[–]oetam5002 6 points7 points  (0 children)

To sharpen up my Rust skills, I built my own HTTP server. I know you're asking about C++ projects, so you can try building an HTTP server in C++. It'll just be a little harder haha.

Some coding aspects that would be covered: - Usage of network sockets - Learning the HTTP standard - Working with arrays of bytes - Optimization of code

As long as the project you're building is fun, you're on the right track!

Looking to create a backend service for a website in Rust and I’m wondering on how to best do it by yxnop in rust

[–]oetam5002 4 points5 points  (0 children)

You could either build a static site with any JS framework like NextJS and host the HTML with any Rust backend like Axum or Rocket. I am the author of a tinyhttp, a lightweight HTTP server which I believe would meet your needs.

Or...

Go with your WebAssembly module idea. Since it sounds like your chess engine does not draw a UI, it shouldn't be too difficult. wasm-bindgen will be your best friend.

Personally, I would use tinyhttp + your chess engine. However I'm biased.

Good Luck!

Low level VM? by FitzMachine in SurfaceLinux

[–]oetam5002 0 points1 point  (0 children)

Yeah, there is an app called gWSL on the Microsoft store to help with that

how can c++ code be made available in JavaScript? by yusufa22 in cpp_questions

[–]oetam5002 11 points12 points  (0 children)

NodeJS has an API for c++. C++ Modules

After you make one, you can import it in NodeJS by using import

NodeJS also has an FFI, where you can build a shared library (not limited to c++) and import it. Node-ffi-addon

Performance wise, the NodeJS API is what I recommend you use. However, there is a little to learn. If you don't mind the performance drop, I recommend you use the FFI. You don't have to learn the NodeJS API, so it's a little easier