Chara pixelcroft in the shrine of dusty artifacts

Partly a lack of structs/classes, partly because your code is a bit hard to follow
e.g. one or two really long lines, several long/complex expressions, various bits of repetition, using (-x + 59 instead of the equivalent 59 - x, returning 0 and 1 instead of false and true several other things.

Might just be because it’s a draft or because of stylistic difference/preference. If Lua is the only language you have significant experience with that would sort of explain the lack of classes, as would being new to C and C++.

Lua’s a nice language, I learnt Lua to use with ComputerCraft (a Minecraft mod) a few years back. It’s still my favourite scripting language (unless you count C#, but I’ve only seen that used for scripting once).

I meant @adekto :P.
That’s good to know though.

I’m a pretty strong believer in self-education (i.e. learning from internet tutorials and articles), so do not worry about not learning programming at school.

Most of my programming knowledge comes from the internet and practise, my college wasn’t the best for teaching programming.

I had to learn both French and German despite telling them I only wanted to learn French. I don’t know either well enough to hold a conversation but still got a ‘C’ in both.


While we’re at it I may as well say what my background is.

I’ve been programming for about 4-5 years now.
I have varying levels of experience with roughly 10 different languages.
(C# and C++ are my main two, the ones I like most as well as the ones I use most.)

85% to 95% of my programming knowledge has been learned from the internet, lots of practise and occaisionally a book or two.

My college didn’t really teach me that much about programming, the internet was a much better teacher.

1 Like

Oh yea im getting the hang off classes, though my lua natior I usualy put it in a struct (i know i know there basically the same just reverse priorities)

And yes its cuz im live coding it till something works fast fixes add a - here ad a constant value there

I don’t really plan qnd witout knowing what has to happen i dont think about semantics or clean code or even optimized code

Speaking of heavy use of classes I wonder how that compiles and inpacts speed. I was looking at parts of the library and some functions just call another function in another class

natior?

Fair enough.

Personally I try to avoid doing that, I prefer working on the problem first (often on paper) and then writing code afterwards.

C++ is very good for size and speed.

E.g. something like:

struct Vector
{
    int x, y;

    Vector(void) = default;
    Vector(const int & x, const int & y) : x(x), y(y) {}
};
Vector operator +(const Vector & left, const Vector & right)
{
    return Vector(left.x + right.x, left.y + right.y);
}

void main(void)
{
  Vector a = Vector(5, 6);
  Vector b = Vector(6, 7);
  Vector c = a + b;
}

Usually* compiles to the same code as

void main(void)
{
  int ax = 5; int ay = 6;
  int bx = 6; int by = 7;
  int cx = ax + bx; int cy = ay + by;
}

C++ being heavier/slower than C is a myth that was once true when C++'s compilers were young and inexperienced and C’s compilers had a few years of experience behind them, but nowadays two equivalent pieces of code in C and C++ are equal.

Generally C++ does produce small, fast code. There are features that will increase code size and make things run slower (e.g. using virtual functions, using exceptions, using dynamic memory) but those are generally easy to avoid or reduce, and doing the equivalent in C would have the same impact.

In modern C++ it’s even easier because you can do things like specify the size of enums and mark functions as constexpr which indicates to the compiler that it should try to evaluate the variable/function at compile time if possible (failing that there’s the template meta-programming approach which isn’t particularly friendly but gets the job done).

In C++ things are usually* very vigorously inlined, so that would usually compile as if the inner function was being called itself.


* I say “usually” because there are arcane reasons why these might not happen in some circumstances, but with the Pokitto they’re unlikely. Such circumstances include badly made compilers that don’t do thorough optimisations or certain circumstances where it can’t be optimised for some reason, e.g. a call to a function in a .dll (or .so if you’re on Linux) can’t usually be inlined.

1 Like

I have a question about the ledge climbing mentioned a few posts back. One thing that’s not clear to me is how the ledge climbing might look from an animation perspective. I feel like that might influence how it would be implemented. For example, perhaps she would put her arms on the ledge when you are at a certain height, and then clamber on, or perhaps vault herself up so you would sort of leap onto the ledge. Would you lock on to it or sort of bounce up on it?

I am interested in collaborating on making a platforming engine, but I’m not sure my personal preferences would be the best for designing the overall framework. I have been using mostly the C subset of C++ for my personal projects on the Gamebuino and Pokitto. I have plenty of experience with objects, but I think I have been enjoying writing things closer to how they actually assemble among other reasons. Anyway, I think that most people here would prefer to use classes.

1 Like

The easiest way would definitely be the old fashioned ‘jump above the platform and land on it on the way back down’.
In that case you could get away with a simple raycast downwards to detect a platform below the character.

I found a few examples online (but I didn’t like them because they were for Unity :P).
Here’s a nice image pair that summarises the idea:


Taken from this blog.

A proper gripping animation would be possible but more difficult because then you have to consider being under and close to the platform as well. You could probably get away with another raycast, but then the logic for holding the character in place while the ‘pull up’ animation plays would be a bit fiddly because it means interrupting/suspending all the other physics stuff.


Personally I do prefer C++ style with classes that knit together well.

I’ve used high level languages like C# and Lua, and I’ve gone as low as inline assembly.
Higher level stuff might not seem as ‘hackerish’ or ‘old school’, but in my opinion it’s better for productivity and understanding (assuming you understand the features of course).

For example, in C++ you can define your own operators.
I find it much nicer when adding two things to be able to write a + b instead of the C-style thingAdd(a, b).
Also I find that list.add(object) is much easier to read/understand than the C-style listAdd(list, object) - in the former it’s clear that the object is being added to the list because of the syntax, in the latter it’s a matter of convention.

i asume you meant this[quote=“wuuff, post:64, topic:164”]
I have a question about the ledge climbing mentioned a few posts back
[/quote]

i think its mostly an in animation to climb it an then at some frame jump up tiles to keep sprite size to a minimum

@Pharap if your interested in writing this or helping out, your very much welcome to try
@wuuff please by all means join up i prefer the none classes style aswel since its easer to explain, this game is just a sample for the engine wich can and should be used for more then one game, main thing is loading more levels and sprites from sd card still

I’d gladly offer advice here and there (especially about C++ features, error messages, theory or problem solving), but I wouldn’t be ready to go full time just yet, I’m still recovering from my last project (which took 2-3 months on and off).
I also haven’t got round to collecting my Pokitto from the recipient yet, and I’m waiting on a tutorial on how to use the offline IDE.

@Pharap Does you Fixed Point library work on Pokitto? That would be essential in games as floats are too slow.

1 Like

I am planning to release it for Pokitto (sort of).

In fact I’m intending to release a ‘general’ version (which was originally slated to be released alongside the Arduino version) which should compile for all systems.

At the moment the biggest issue that’s stopping me from releasing it is the random function which I need to decide to either solve or to remove it completely.

I’ve been on hiatus from working on the library for the last week or so because 2-3 months of on and off working on it was tiring and I was worried I’d start to hate looking at it if I didn’t take a break :P.
I’ll probably pick it up again in a week or so.

If you’re interested and want to know more about the library (how it works, the history of it, decisions made, the issue with random numbers etc) don’t hesitate to ask, I’d be more than happy to bore you with the details.

One small note:
As the issue on Github notes, there aren’t any benchmarks at the moment.
That’s something I need to get round to.
It’s a hard thing to test because of the nature of fixed points - they have a limited range of values.

Great! Take your time. I am still quite busy with Python implementation, so at least I do not need it for C++ for some time. Hmm…on second thought, fixed points are needed in python as well. Maybe, I should make a python wrapper for your library.

Was that a joke? :P

You’re certainly free to do so when I release it.
Be warned that the underlying implementation is template based, for Python I think you’d have to choose some specific sizes (maybe the common types of SQ8x8, UQ8x8, SQ16x16 etc).
Depending on how Python works internally, you might be better off doing a re-implementation in Python.
I’m not sure which approach would be smaller/faster.

When the time comes to do so I’d be glad to help you.

I didn’t know I was joking :slight_smile: Hopefully that was a good one(?).

I believe C/C++ -implementation would be faster than python code. Actually pyton library uses C only, so I will make a wrapper in Pokitto library side.

It took me a couple of months to get this far. That’s quite a long time.

Hrm. Adapting it to use C would be a fairly big task.
When you say ‘the Python library only uses C’ do you mean that the library has to be compiled as C?
Most C code can be recompiled as C++ so there might be a way around it.

I guess we’ll cross that bridge when we come to it.
If worst comes to worst and I/we had to reimplement all the common types in C it would be a long and arduous task, but it would be doable.

I guess if the data types for the library use a lot of C++ features, it would be hard to just write a C wrapper. I mean, I guess you could have wrapper functions that convert a C struct to a C++ object and vice versa, but converting back and forth would add some overhead.

As for the climbing animation, I was thinking about the original Prince of Persia’s climbing animation. What do you think about this kind of way to handle ledge climbing? If you were thinking of something else, could you give an example?

MicroPython is compiled as C and I would like to keep it that way. All the C++ code is in Pokitto library side. So there is no need to convert the FB library to C, unless we want to avoid extra function call (from C to C++).

Edit: yes, there can be some overhead if conversions are needed. Depends on how FB is implemented. I could imagine the member data is just one integer (?).

One of mine favorite games. That’s probably my target as platform.

Firstly it’s implemented using templates, which are sort of like a blueprint for a class rather than an actual class. (Look them up if you’re not afraid of generic programming or your head exploding.)

The problem isn’t just wrapping the object, it’s wrapping the functions.
C doesn’t support member functions, function overloading or overloadable operators so it would involve converting all the member functions to free functions and any overloaded versions would need a custom name.

Needless to say, it would be long and tedious process.

FB?

You are correct.
The template selects an integer type of the appropriate sign that is the smallest possible type that can contain the desired Q format.
E.g. UQ4x4 is 8 bits, UQ8x8 is 16 bits, UQ16x16 is 32 bits etc.

Converting into something that can be stored isn’t an issue, but there’s a lot of functions to wrap. (The number of which is why there’s a lack of per-function documentation.)

Sorry, Fixed Point , FP. Too busy. :slight_smile:

2 Likes

Thought you probably meant FP, but I it’s better to be certain :P.

I meant wrapper functions for all the functions in the library (creating a set of non-member functions) that would convert any arguments as needed, create objects, etc. I think I looked at your library briefly a while back when you said somewhere you had just finished a big project, but I hadn’t remembered most details, including extensive use of templates. I understand that the use of templates would make it an annoying nightmare to convert. I was just saying that it should be possible to make wrappers, even if it ends up being very tedious and maybe not worth it.