Spherical forums

Sphere Development => Sphere Support => Topic started by: Miscreant on August 09, 2017, 01:54:49 pm

Title: Sphere 1.5 vs miniSphere
Post by: Miscreant on August 09, 2017, 01:54:49 pm
I wrote this simple function to Activate the armos statues. If you bump into one it comes to life and moves around the screen.

In Sphere 1.5: You walk into a statue, it comes to life and moves around the screen.

In miniSphere: You walk into a statue, it comes to life and moves around the screen. If the now activated statue touches another statue, that statue comes to life and moves around.

In Sphere 1.5 that does not occur. if a statue touches another statue that statue does not come to life.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on August 09, 2017, 02:08:10 pm
Hehe, I can answer this one right away. :))

Interestingly enough, you're relying on a bug in the Sphere 1.x map engine: the engine only calls the touch script if the input person touches the NPC.  miniSphere fixes the bug and calls the touch script any time any person touches the NPC, which is the intended behavior.  That gives you more flexibility for collision detection.

In order to work correctly in both engines, the Armos Statue touch scripts should look like:
Code: [Select]
if (GetVersion() < 2.0 || GetActingPerson() == "Link")
    ActivateArmos();

The version check is needed because Sphere 1.x doesn't have GetActingPerson().
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on August 09, 2017, 02:12:14 pm
By the way, what's up with that Foo() function?  Sphere has a function to set person X/Y simultaneously: SetPersonXYFloat().
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on August 09, 2017, 02:32:37 pm
Quote
Code: [Select]
if (GetVersion() < 2.0 || GetActingPerson() != "Link")
    ActivateArmos();

I added in that line of code and in Sphere 1.5 ActivateArmos runs, in miniSphere when I bump into an Armos nothing happens.

Quote
By the way, what's up with that Foo() function?  Sphere has a function to set person X/Y simultaneously: SetPersonXYFloat().

I was unaware of that when I first started using Sphere, before I discovered api.txt. Now, I use it because it's just more for consistency of code.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on August 09, 2017, 02:34:48 pm
Quote
Code: [Select]
if (GetVersion() < 2.0 || GetActingPerson() != "Link")
    ActivateArmos();

I added in that line of code and in Sphere 1.5 ActivateArmos runs, in miniSphere when I bump into an Armos nothing happens.

Yeah, sorry, that should have been GetActingPerson() == "Link" and replace "Link" with whatever you named the player character in its CreatePerson() call.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on August 09, 2017, 02:46:03 pm
Quote
replace "Link" with whatever you named the player character

In the code the PC is actually called "UrNoLink".
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on August 09, 2017, 02:50:17 pm
is there a way to keep the NPCs from walking off the maps that does not involve using map layers?

In an early npc town test I did i wound up having 2 layers. When you entered the town all of the npcs were on the second layer with an obstructed transparent tile bordering the map. When the player went to leave the map there was a trigger set swapping the player to the unobstructed layer.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on August 09, 2017, 03:18:27 pm
Hm... I'm not sure there is, actually.  At least not while still letting the engine handle input for you.  You would have to DetachInput() and then handle all the movement input yourself.  There's no way to "plug in" to the collision detection system with the 1.x map engine that I'm aware of. :(

Did my fixed code work?
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on August 09, 2017, 03:57:41 pm
Quote
Did my fixed code work?

ActivateArmos now functions properly in Sphere 1.5 & miniSphere. Thank you.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on August 10, 2017, 03:05:12 pm
Yet another difference between Sphere & miniSphere.

The message box was created using the fademessage system script.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on August 10, 2017, 05:22:05 pm
Fun fact: It's equally broken in Sphere 1.5 when using the OpenGL video plugin.  A possible workaround is to call RenderMap before displaying the menu, but I can't promise that will work.

tl;dr: Known compatibility issue, contemplating how to fix.

This is a very interesting case where technically the Sphere 1.5 behavior is a bug, but so many games depend on it that it's probably worth emulating anyway.  There's a perfect storm of circumstances that allow things to work in a default 1.5 configuration:


As luck would have it, miniSphere is in a perfect position to emulate the bug, even under OpenGL, as the engine uses an intermediate backbuffer that isn't required to be cleared every frame.

So I'll see what I can do in miniSphere 4.8. :)
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on August 11, 2017, 03:25:28 am
Update: I "fixed" it. :D

Fix will be in miniSphere 4.8.0.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 07, 2017, 02:53:31 pm
Whoa.... What the....?

miniSphere on the left, Sphere 1.5 on the right.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 07, 2017, 03:13:50 pm
The map is smaller than the screen.

miniSphere centers and letterboxes small maps, because it's usually more aesthetically pleasing than Sphere 1.5 which aligns them to the top-left.  It seems you found a use for the "bad" behavior though, so maybe I could change it back :)
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 07, 2017, 03:32:52 pm
Yeah, the player_info() is not part of the map but drawn in a space below it.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 09, 2017, 12:33:06 pm
@Fat Cerberus Is there a way to not center the map with miniSphere?

Also: I put a different graphic card in the machine and miniSphere is no longer slow and choppy. I did, however, lose my dual monitor ability (for the time being).
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 09, 2017, 12:43:23 pm
Oh good, you'll be able to use the debugger now. :)

For the map, I'll change it for 5.0 to not center it, but for now a workaround would be to add an extra row or two of black tiles along the bottom of the map so it fills the screen.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 09, 2017, 12:56:36 pm
Oh good, you'll be able to use the debugger now. :)

For the map, I'll change it for 5.0 to not center it, but for now a workaround would be to add an extra row or two of black tiles along the bottom of the map so it fills the screen.

Tried that on a couple of maps.
1. I'd have to do it to every map and the Overworld alone is comprised of 112 maps. Underworld is the same. That's 224 already not counting the various levels I've created that range in overall size.

2. It throws off the map exits especially "On Leave Map South". I'd probably have to add in zones or something just for a southern map exit.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 09, 2017, 01:12:10 pm
Alright, then here's what I'll do: since mS 5.0 is not ready yet, I'll post a 4.8.5 patch later that changes the map behavior.  ;)
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 09, 2017, 01:31:42 pm
Oh good, you'll be able to use the debugger now. :)

Indeed. Right now, I'm trying to see if there is a way to re-enable my integrated HDMI so I can use my 2 monitors again. It makes for a nicer development environment.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 09, 2017, 02:07:20 pm
Wait, your dual-monitor setup didn't use the same GPU for both monitors?  That might have been the cause of all the slowdown...
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 09, 2017, 03:32:14 pm
No, it did. The motherboard has an integrated nvidia 7100 with vga & hdmi support. I just put in a geforce 8400 PCIe and it turned off the integrated graphics. The 8400 has support for vga & dvi but I have no dvi cable to utilize the port. I was trying to see if I could get the integrated graphics and the PCIe to function together but from what I am finding it does not appear to be a possibility.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 10, 2017, 12:22:39 am
@Miscreant miniSphere 4.8.5 changes the map rendering behavior to match Sphere 1.5 (i.e. aligned to top left).  Let me know if there are any other compatibility issues.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 10, 2017, 03:09:18 am
Thank you for patching it. In future Sphere projects, I'll design maps accordingly.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 10, 2017, 09:45:52 am
No problem.  Changing the map rendering behavior to centered was a conscious decision on my part, but I admittedly didn't account for the possibility that render scripts might depend on the Sphere 1.x behavior.  :-[
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 10, 2017, 09:50:45 am
TBH, when I first started P:ZeC, I just started making my own version of Hyrule. I never even thought about the player info area until much much later.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 11, 2017, 02:39:52 pm
Found a new difference between Sphere and miniSphere. miniSphere on left, Sphere on right.

Triangles outlining the Triforce Segments...
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 03:32:05 pm
Now that makes no sense at all, can you post the code that's drawing that?
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 11, 2017, 03:56:12 pm
@Rhuan I know the code looks a bit much with all the different variables... It is actually 2 functions condensed into 1. When I started with the inventory, I created the function to draw the triforce and then just called it from the inventory function. As I created the scrolling inventory I needed to pass the x,y to drawTriforce().  So the drawTriforce() became this huge drawTriforce(long line of variables); it was a pain.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 04:37:20 pm
I'm pretty sure you could make that neater, at least use an array of coordinates rather than separate vars for each one.

Simple answer to your error though - three of your coordinates have decimal places, drawing to fractional coordinates is not possible, both sphere 1.5 and minisphere have functions to force the inputs to be integers, a few simple tests suggest that sphere 1.5's method rounds down whereas minisphere's rounds up.

Strictly speaking round up is correct here as the value is 0.5 - so if this can be called an engine error it's a 1.5 error not a minisphere error.

That said you shouldn't be giving decimal places to render functions :)
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 11, 2017, 04:44:55 pm
Typically coercion to integer is a truncation, so minISphere's behavior here is indeed a bug.  Easy enough to fix, but yeah, just floor the values first for now.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 04:46:45 pm
Hmm more tests show that miniSphere rounds up even if given 0.1.

So looks like Sphere 1.5 floors pixel coordinates and miniSphere ceils them.

@Fat Cerberus if relevant for you - I tested with the chakracore version of miniSphere, so if this is a bug it has persisted into your new jsal.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 05:01:19 pm
@Miscreant suggested alternate triangles code for you:
Code: [Select]
   var t_coords = [86, 269];

  Triangle(t_coords[0] + 47, t_coords[1],     t_coords[0],      t_coords[1] + 48, t_coords[0] + 96, t_coords[1] + 48, White);
  Triangle(t_coords[0] + 47, t_coords[1] + 1, t_coords[0] + 2,  t_coords[1] + 47, t_coords[0] + 94, t_coords[1] + 47, Black);
  Triangle(t_coords[0] + 47, t_coords[1] + 8, t_coords[0] + 12, t_coords[1] + 44, t_coords[0] + 84, t_coords[1] + 44, White);
  Triangle(t_coords[0] + 47, t_coords[1] + 9, t_coords[0] + 14, t_coords[1] + 43, t_coords[0] + 82, t_coords[1] + 43, Black);

  if (LVL1C === true){TSE.blit(t_coords[0] + 32, t_coords[1] + 11);}
  if (LVL2C === true){TSW.blit(t_coords[0] + 48, t_coords[1] + 11);}
  if (LVL3C === true){TSE.blit(t_coords[0] + 16, t_coords[1] + 27);}
  if (LVL4C === true){TNW.blit(t_coords[0] + 32, t_coords[1] + 27);}
  if (LVL5C === true){TSE.blit(t_coords[0] + 32, t_coords[1] + 27);}
  if (LVL6C === true){TNW.blit(t_coords[0] + 48, t_coords[1] + 27);}
  if (LVL7C === true){TSE.blit(t_coords[0] + 48, t_coords[1] + 27);}
  if (LVL8C === true){TSW.blit(t_coords[0] + 64, t_coords[1] + 27);}

changes:
1. I've floored the coordinates
2. I've put the coordinates into an array so you only have one variable to remember and update
3. as I assume the dimensions don't change I've used just one coordinate pair then added some known offsets in the drawing function calls.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 11, 2017, 05:11:42 pm
I'll give that a try. Trying to get these to line up properly has been such a gorram pain.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 05:22:26 pm
I'll give that a try. Trying to get these to line up properly has been such a gorram pain.
If you set complex graphical objects out with one set of coordinates and a lot of offsets it's much easier to line things up.

The one time I'd used variables for the offsets is if I wanted the object to be able to change size, but even then it would probably be only 2 variable offsets (width and height).

The other time I'd need more variables for an arrangement like the above would be if I wanted the triangles to slide onto the screen from different sides or something fancy like that - but I assume you just keep them as a unit all the time?
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 11, 2017, 05:25:43 pm
It does slide...
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 05:29:19 pm
It does slide...
Can't see what you mean from that image - seems to be a still frame?

And when you say it slides do you mean each triangle slides separately, or the set slides together?

What I wrote above was based on the assumption that the set would slide together.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 11, 2017, 05:38:01 pm
I misunderstood. Obviously, the triforce pieces only appear upon level completion but yes it all scrolls as a unit.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 11, 2017, 05:40:03 pm
@Miscreant Your animated gifs haven't been playing recently, they just show up as still images.  Not sure if something broke with the forums or what...
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 11, 2017, 05:45:01 pm
oh gorram it, guess i need to find a different way to animate my gifs.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 11, 2017, 06:09:40 pm
I misunderstood. Obviously, the triforce pieces only appear upon level completion but yes it all scrolls as a unit.
Then with the above code all you'd need to do is update t_coords[0] and t_coords[1] to move it around. functionally it's the same as what you already had just with a lot less variables and with the numbers rounded down so it will draw the same way on minisphere as it was on sphere 1.5.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 11, 2017, 10:15:18 pm
So it turns out that nothing's wrong with miniSphere's handling of integer coordinates after all, they are indeed rounded down internally.

In the end, nothing I did to the Triangle() function could coax it to render the triangles the same way.  Interestingly, Sphere 1.5 with the OpenGL plugin is broken in a similar way, see screenshot attached.  I think this one is just down to differences between software rendering (Sphere with the standard32 plugin) vs. hardware rendering.  It isn't something I can fix :(
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 12, 2017, 02:57:05 am
@Miscreant Your animated gifs haven't been playing recently, they just show up as still images.  Not sure if something broke with the forums or what...

I'm not sure what the issue is, I've check the gifs on 3 different platforms and they all display properly. I don't really know that much about ElkArte, could it possibly be something with the forums??
Title: Re: Sphere 1.5 vs miniSphere
Post by: Rhuan on September 12, 2017, 03:32:13 am
So it turns out that nothing's wrong with miniSphere's handling of integer coordinates after all, they are indeed rounded down internally.

In the end, nothing I did to the Triangle() function could coax it to render the triangles the same way.  Interestingly, Sphere 1.5 with the OpenGL plugin is broken in a similar way, see screenshot attached.  I think this one is just down to differences between software rendering (Sphere with the standard32 plugin) vs. hardware rendering.  It isn't something I can fix :(
That's bizarre - simply rounding down before calling the draw functions got the right result for me.

Similarly rounding up before calling them resulted in repeating what miniSphere was already drawing.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 12, 2017, 05:33:23 am
So it turns out that nothing's wrong with miniSphere's handling of integer coordinates after all, they are indeed rounded down internally.

In the end, nothing I did to the Triangle() function could coax it to render the triangles the same way.  Interestingly, Sphere 1.5 with the OpenGL plugin is broken in a similar way, see screenshot attached.  I think this one is just down to differences between software rendering (Sphere with the standard32 plugin) vs. hardware rendering.  It isn't something I can fix :(
That's bizarre - simply rounding down before calling the draw functions got the right result for me.

Similarly rounding up before calling them resulted in repeating what miniSphere was already drawing.

If it's software vs hardware rendering, maybe I should just turn the outling triangles into an image and blit that to the screen instead. That would keep everything aligned properly and shouldn't display those errors as it is drawn.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 12, 2017, 06:54:25 am
Just turned the Triforce Outlines into a static image. It now displays properly in Sphere & miniSphere. Also, eliminated the need for all the triangle coordinates. The function is more streamlined this way too.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 12, 2017, 08:42:03 am
You probably would have been better to draw the triangles as LineSeries(), but this works too.  For some reason Sphere doesn't have an OutlinedTriangle function...
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 15, 2017, 12:47:17 am
Well here's a new one for Sphere vs miniSphere
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 15, 2017, 01:54:52 am
That's interesting.  You might have found an actual bug!  What does your code to activate the passageway look like?
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 15, 2017, 08:00:27 am
@Fat Cerberus It's a rough draft...
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 15, 2017, 10:12:04 am
Okay, so looking at the code, I have a question:

If it's the former, then that means SetTile() is bugged.  If it's the latter, than something else is going wrong because that means name is always "block" (since the condition to unlock the secret is for name to not be "block").
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 15, 2017, 10:47:17 am
hmm, Let me try something real quick

Edit: Edited the north directional only for testing purposes.

Changed the code to read
Code: [Select]
if (y == (yn+1))
{
  if (name != "block")
  {
    PlaySound(Secret);
  }
SetTile(tileX, tileY, tileL, tile);
}

Now, it should only play the sound if the name is not "block" but set the tile in either case.

When I tried it in miniSphere the tile still did not change yet functions in Sphere.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 15, 2017, 11:15:42 am
That means there's a problem with SetTile.  I'll look into it.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 15, 2017, 02:02:58 pm
That means there's a problem with SetTile.  I'll look into it.

Mathematical error in my code. The tile now appears in both Sphere and miniSphere. Not an issue with SetTile.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 15, 2017, 02:08:42 pm
That's still curious that the behavior differed between the two engines.  What was the mistake?
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 15, 2017, 02:18:33 pm
 I started by commenting out different parts of the code. "// this out, test with sphere, functions, miniSphere still broken. Ok, so i don't even need this line." After that it was just "let's check the math", which was literally off by 1.

On a side note: I keep forgetting to add this line
Code: [Select]
if (GetVersion() < 2 || GetActingPerson() == MainChar){//code here}
to certain entities on the map. As a result I just watched an Armos kick a headstone across the screen.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 15, 2017, 02:38:33 pm
What I mean though, is why did the off-by-one math not break things in Sphere 1.5?  That indicates some imperfect emulation on my part, and I'd really like to fix that ;)
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 15, 2017, 03:48:51 pm
ah, that is an interesting question. I'm not sure why the errored version would process correctly in Sphere. Now, with no slow down in graphics, testing and debugging in miniSphere are a regular task of creating ZeC.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Miscreant on September 17, 2017, 03:31:46 am
Now here's one I don't understand...

In miniSphere it functions. In Sphere 1.5, on touching the triforce it just pauses and warps the player outside the level...

Triforce 'On Touch'
Code: [Select]
LVL1C = true;
CollectTriforce();
QueuePersonScript("Triforce", "LevelComplete(119, 87, D3)", false);

Code: [Select]
function CollectTriforce();
{
DetachInput(MainChar);
Foo("Triforce", 127, 71, "north", 0); //Fooing again
ClearPersonQueue(MainChar);
Foo(MainChar, 127, 92, "collect", 0); //always with the Fooing
PlaySound("ItemCollected.ogg"); //To be changed to something more appropriate for the Triforce later
}

Code: [Select]
function LevelComplete(x, y, map);
{
Delay(1500); // adjust for future sound file length
DestroyPerson("Triforce");
AttachInput(MainChar);
FancyWarp(x, y, "south", map, 1500); //I think this came from sphere.chm. Nothing actually fancy just FadeOut() & FadeIn().
}

There are no ifs, no switch, no anything. The code is just straight forward commands.
Title: Re: Sphere 1.5 vs miniSphere
Post by: Fat Cerberus on September 17, 2017, 03:50:19 pm
That's interesting, there seems to be a bug in Sphere 1.5's handling of queued person scripts from the looks of things.  Not sure what's wrong yet, I can look into that later.