News:

Herr Otto Partz says you're all nothing but pipsqueaks!

Main Menu

Restunts repository - Git mirror

Started by dreadnaut, March 19, 2021, 12:00:36 AM

Previous topic - Next topic

llm

#135
test

    const int16_t min = -2;
    const int16_t max = +2;
   
    for(int i = min; i < max; ++i)
    {
      printf("[%d](x=0,y=0) a: %d, c: %d\n", i, int_atan2_asm(0, 0),int_atan2(0, 0));
    }

    for (int16_t x = min; x < max; ++x)
    {
        for (int16_t y = min; y < max; ++y)
        {
            int16_t a = int_atan2_asm(x, y);
            int16_t c = int_atan2(x, y);
            printf("x=%d, y=%d -> C=%d, ASM=%d\n", x, y, c, a);
        }
    }

result

[-2](x=0,y=0) a: 0, c: 0
[-1](x=0,y=0) a: 0, c: 0
[0](x=0,y=0) a: 0, c: 0
[1](x=0,y=0) a: 0, c: 0
x=-2, y=-2 -> C=-384, ASM=-384
x=-2, y=-1 -> C=-332, ASM=-332
x=-2, y=0 -> C=-256, ASM=-256
x=-2, y=1 -> C=-180, ASM=-180
x=-1, y=-2 -> C=-436, ASM=-436
x=-1, y=-1 -> C=-384, ASM=-384
x=-1, y=0 -> C=-256, ASM=-256
x=-1, y=1 -> C=-128, ASM=-128
x=0, y=-2 -> C=512, ASM=512
x=0, y=-1 -> C=512, ASM=512
x=0, y=0 -> C=0, ASM=28 <======= ???
x=0, y=1 -> C=0, ASM=0
x=1, y=-2 -> C=436, ASM=436
x=1, y=-1 -> C=384, ASM=384
x=1, y=0 -> C=256, ASM=256
x=1, y=1 -> C=128, ASM=128

the asm code returns also 0 if i rotate the calls so first C then asm or the result-value of asm changes if i disable the C call complete

            int16_t c = int_atan2(x, y);
            int16_t a = int_atan2_asm(x, y);

maybe im calling the asm-code the wrong way but it only fails for 1 of thousands of calls?

llm

#136
what i can see so far:

ax seems to be undefined if x and y = 0 in the asm routine

   
    int16_t a;
    __asm{
        mov ax,0
        push ax
        push ax
        mov ax,1234
        call int_atan2_asm
        add sp,4
        mov a,ax
    }
    printf("a:%d\n", a);
    return 0;

returns 1234

so the question is: does Stunts rely on this "random" behavior? and if - how to fake it in C?

- bx is not safed (could that be problematic in combination with C code calls?)


Cas

@dstien - That's amazing. Yeah, I'd like to be able to write a function that performs exactly the same and the physics engine and compare the car positions. Your porting will be a lot more optimal, of course. I just want to be able to see that I understand it and have it in my mind analytically, not just copying the code.

But mostly yes, my interest is on putting that in the core and build shells out from scratch. I wonder how much is in the core that limits what can be added outside. For example, if there are references to the current memory distribution of track elements, maybe it isn't possible to make a bigger map without modifying the core. But perhaps the required changes would be minimal. I don't know.

@Matei - I think here is a misunderstanding. I'm going to get a little philosophical here, but just to clarify... Yes, my engine is a proof of concept. I wrote it to build and see that it actually did the thing and I didn't make any effort to make it fast enough or to perfectly render things without glitches, so it's not ready be to put on a game.

Now, this unfinished nature of it has nothing to do with it being FreeBasic. Because it is a graphical engine, it is impossible to port it to C, as C has no graphics functions. What you surely mean is to port it to SDL. I don't have much interest in doing that as there are tons of SDL-based 3D graphics engines out there already. They're not bad, but why reinvent the wheel?  I would like to create a new painter's algorithm based engine analog to Stunts' original and software based, like that of Stunts, that runs natively on modern systems and allows for adding some more things. That's it.

There's a difference between translating code between two programming languages and porting code between two compilers. Porting is about creating a source code that can be compiled with another tool chain and result in a different binary that can be run on a different platform. Translating has to do with the syntax, with the language. Libraries play no role in translation and there's no software efficiency optimisation in translating code. In terms of languages, considering the functions that are present in FreeBasic and C and their definitions, there is no superiority in one on the other. Maybe we could say FB is superior because it can do graphics comprehensively, while see cannot (as a language). In terms of the compiler, there are many C compilers, most of which have had much more work on than FreeBasic's and are likely to be more efficient, but when talking about graphics code, since C does not include that, the C compiler will just "copy and paste" from the 3rd party library, say, SDL, so if you make a game in FreeBasic or in C that uses SDL, efficiency will be the same as regards graphics.

Beyond superiority, there's a trend of preference towards the C language (syntactically) because it's more commonly used and you have more compiler options. This makes a lot of sense and I would recommend to follow suit for non-graphical projects.
Earth is my country. Science is my religion.

Matei

Quote from: Cas on October 10, 2025, 04:52:28 PMthere are tons of SDL-based 3D graphics engines out there already.

Any example that can be used for Stunts? I mean besides the one I know about.

Quotebut when talking about graphics code, since C does not include that,

C compilers sometimes do, but using SDL is much better and also much better than what functions FreeBASIC offers. I don't understand what's your problem with SDL. DosBOX uses it as well as OpenTTD, Simutrans, TyrQuake, Fuse, practically all games that work on GNU/Linux and even NetSurf.

https://matei.one/idxchess.html

QuoteThe version above uses SDL for graphics, but the version for DOS/DOSBox, which is available below, uses some graphical functions available with Open Watcom, as SDL has no support for DOS.

Daniel3D

I know what why CAS doesn't want to use an SDL, and I'll try to give a simple example.

I like to fly RC planes, and there are several kind of people who fly planes at my club.
Two main groups are,
* those who built a plane piece by piece, cut and glue and paint for months to get is just the way they want..
And
* Those who buy a whole plane, mod it and go flying.

CAS is a programmer of the first kind.
He doesn't use libraries, if he needs one he will probably write it himself.
Takes more time but is more satisfying.

Simple DirectMedia Layer (SDL) is a cross-platform library providing low-level access to hardware via OpenGL and Direct3D, supporting Windows, macOS, Linux, ...
Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Cas

I don't really have a problem with SDL. I think it's good. It just doesn't do what I want to do. It's good for SDL to exist because it makes a standard instead of letting tons of different libraries take over. That's a very good thing. But programming for SDL feels very different to me from programming in a language. The library takes over and you really are no longer writing the graphics code. I was a low level programmer in DOS. Now, for GNU/Linux, that's practically banned, so I try to do the closest to it that is possible and SDL is not it. SDL is not C... it's SDL. With SDL, I'd feel that I'm no longer writing programs for the OS, but I'm writing scripts for some program. "SavePNG" (or whatever it's called) -> Boom!  You have a PNG file. I don't like that. Then wanting to copy and run a 2MB program and having to download half a gigabyte from the internet for it to run.... Also not my type.
Earth is my country. Science is my religion.

Matei

Quote from: Cas on October 10, 2025, 10:28:15 PMBut programming for SDL feels very different to me from programming in a language. The library takes over and you really are no longer writing the graphics code.

Excuse me, but I wrote the graphics code with SDL more than you did in FreeBASIC.

https://sourceforge.net/projects/simple3d/files/SDL_grf/

You never looked at that. SDL has a little problem, however. It's at version 3 and if you didn't start with it at version 1 like I did, you might get some wrong ideas about it.

llm

#142
@Matei

CAS explained his views on third-parties serveral times over the years, he don't like (someway hates) 3rd-party dependencies (and the deployment/dependecy "burden" - he preferse tiny single exe builds without dependencies - like in the old times, 40 years ago) and FreeBasic is giving him an enviroment were he can get that and still be productive - its just the way he personally wants to do coding, and he wants to do it in a Basic-Language, and he wants the FreeBasic graphics interface - even if its nearly the same as SDL (its just a tiny fraction of less functions needed to get it running)

its clear for everyone that using third-parties, install and deploy them is just as normal in professional developing buisness as drinking water, writing non trivial multi-platform applications without third-parties just don't work anymore - you can do it but no one will pay you re-inventing wheels and consuming endless time doing it

maybe CAS does not work in professional software development, in a very small (lucky) niche were he could prevent using third-parties over a very long time or he choosed that way for his hobby-time - he chooses FreeBasic because it fits his needs fully out-of-the-box

it makes no sense to argue about it - he choose it for reasons we don't see as problematic as he do

but still, he creates nice tools for the community :-*

Matei

I always want the source code to compile it myself, so that single exe without dependencies, which has a lot of dependencies, is not very useful for me.

https://drv.nu/freebasic/building/freebsd/

Besides, I already used BASIC (for ZX Spectrum) and Pascal, so I know what we're referring to. Example:

https://matei.one/oprog.html

Click on "Power on", then on "Open" and select "Civil Engineering". JavaScript required, but the emulator and all the used files can be downloaded and used offline. Also, I wrote the BASIC program with Fuse, not when I was using a ZX Spectrum; I'm not that old.

I downloaded Cas's track viewer, it worked now and it's not actually that slow. How do I look up and down?

dstien

#144
Quote from: llm on October 10, 2025, 02:00:01 PMax seems to be undefined if x and y = 0 in the asm routine

so the question is: does Stunts rely on this "random" behavior? and if - how to fake it in C?

clvn implemented this by just doing return result; before assigning any value to result. Since this type of randomness isn't portable, I did some (probably too brief) testing and determined that AX is always 0 in the game in these situations. But now that you brought it up I started wondering whether the case could be otherwise in certain circumstances. If I recall correctly, Stunts have a type of bug where a replay can't be fast-forwarded, because the simulation outcome is different than when it's played through, indicating that there's undefined behaviour that changes when the graphics code is involved. I did a repldump batch run on 100s of replays from the Zak Stunts archive, and it turns out that atan(0/0) happens frequently. But every occurrence that I tested in-game has AX=0, for example for @Duplode on ZCT289:

(The replay controls aren't redrawn on every frame, so printf debugging kinda works.)

Does anyone remember some particular replays that has the "can't fast-forward" bug? If not, I guess we should be able to find them automatically. All competition replays are supposed to finish successfully, while a bugged run would either crash or never cross the finish line in repldump.

Edit: Found a bunch of files don't register as finished in the last frame, but the only one I have confirmed with this behaviour so far is zct244/02-ROT.RPL. Haven't found any connection to atan(0/0) though. Looks like hitting water ends the joyride in the pure analysis, while the playback let the car continue straight over the surface.

HerrNove

Quote from: dstien on October 11, 2025, 03:22:42 PM(The replay controls aren't redrawn on every frame, so printf debugging kinda works.)

This was a funny part in my writeup :) If you need something more sophisticated, I recommend intro_draw_text which does the job quite nicely (example)

If you are analysing conformance, I remind you that the ported `update_car_speed` is currently disabled because it leads to desyncs with respect to the original game.





Duplode

Quote from: dstien on October 11, 2025, 03:22:42 PMDoes anyone remember some particular replays that has the "can't fast-forward" bug? If not, I guess we should be able to find them automatically. All competition replays are supposed to finish successfully, while a bugged run would either crash or never cross the finish line in repldump.

I have attached a collection of unstable replays, which I had assembled last time we were doing in-game experiments about this behaviour.

(Side note: While we have eventually settled on taking the fast-forward/repldump outcome as canonical, because it is the one that's consistent across machines, competitions at times were more liberal than that about unstable replays. That being so, the collection includes two examples of replays that can finish successfully on a straight in-game replaying but not on repldump: 13gutix.rpl and C232OVE.RPL.) 

llm

#147
@dstien

do you test/compare 16- and 32bit (with wcl386 on DOS or even gcc/clang on Linux?) built results of the pure C functions tests?
to make clear that they give the same results

im currently doing wcl/wcl386 for dos,clang-32/64bit,msvc-32/64bit for windows and gcc/clang on linux builds for my simple test - thanks to your switch to "fixed-width integer" makes it easy to build the code, also using clang-tidy on it :)