Skip to main content

News

Topic: Sphere SFML v0.90 (Read 106865 times) previous topic - next topic

0 Members and 2 Guests are viewing this topic.
  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #15
OH MY GOD GUYS. Test driven development is awesome! I just found a quirky bug in Surface.getPixel() because of it. Otherwise I would have _never_ spotted it until it was too late!

I've been creating many, tests against the Sphere API. Still not done, but 100% of my effort is going into these tests. Once the tests are done, I'll start to implement features until I get a 100% green-light. :) That will mean all features work and are implemented.

But it is not a silver bullet. Other things that I did not test for may indeed still creep up, but I hope to get the entire API down first. :)
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: Sphere SFML
Reply #16
I never had the patience for TDD.  I get why it's a good thing, but if I can't see the results of my efforts in some practical form (for example, when developing a game, I want to see something playable, not just "oh, all these tests passed, yay") I get bored very quickly.  If I were to spend all my time writing unit tests, it'd take me so long to get to that point that I'd end up giving up.

Out of curiosity though, what was the quirky bug?
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #17

Out of curiosity though, what was the quirky bug?


The JS environment doesn't like bytes, but SFML's colors were in bytes. That means I have to cast to int going between the JS side of things and SFML. The Property setters took objects tho, so I forgot to cast to a byte when creating a new instance with a color in the constructor.

A new feature in my Sphere version: CreateColor(copy);

TDD does take a lot of time. I cannot create the tests I want too it'll be too exhausting. I only made tests that test against Sphere's API. Does toColor return [object color]? Do images have .blit, .blitMask, etc. implemented? You can download the source and run the tests yourself and get a good idea how far along I've implemented the Sphere API.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: Sphere SFML
Reply #18

A new feature in my Sphere version: CreateColor(copy);


Yay, cloning colors!  I could never figure out why Sphere's color object is non-enumerable, this prevents my clone() method from working on them.  I managed to find a neat trick to clone them in Sphere 1.5 though:
Code: (javascript) [Select]
var copy = BlendColors(color, color);
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #19
Well, in Sphere-sfml you can't clone the objects I give you. The reason for this has to do with the fact that the underlying color object is a type of color instance that contains with it a SFML color object. If I move to a pure object instance, then colors have to be recreated each time they get used, which is a tad slower. So it's a trade-off: speed vs cloning power. To mitigate the cloning tho I can do things like CreateColor(copy) which returns a copy of the color and it being a color instance.

However there is one freedom I do give you: in sphere-sfml you can tack on properties whenever you like, the objects are mutable and enumerable. :)

I just tested this, you can do this:
Code: (javascript) [Select]

var col1 = CreateColor(255, 0, 0);
var col2 = CreateColor(255, 255, 255);

for (var i in col1) col2[i] = col1[i];

image.blitMask(0, 0, col2); // will be red.
  • Last Edit: July 08, 2013, 04:25:31 pm by Radnen
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: Sphere SFML
Reply #20
What's your procedure for writing tests, just visiting the API list (either in doc_functions or the wiki page) and going down the list or do you concentrate on specific areas at a time like "all Image API" then "all Surface API" then "all Sound API" etc?

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #21

What's your procedure for writing tests, just visiting the API list (either in doc_functions or the wiki page) and going down the list or do you concentrate on specific areas at a time like "all Image API" then "all Surface API" then "all Sound API" etc?


I'm concentrating on areas at a time, but there's no way I can do all of the surfaceblits in a reasonable amount of time, so I'm aiming for a good subset of these areas. Some of the methods I don't think are possible to implement in Sphere SFML. And I'm being a bit selfish and trying to implement all of the functions my sphere game Blockman uses, as because I think its a good candidate for a well-established game in the Sphere API. If you have an editor with NUnit (Xamarin Studio (the new name for MonoDevelop)), you can check out the code and see for yourself :).

Edit I can't get gradient triangle implemented because this line is not possible in C#. There are too many args!
Code: (csharp) [Select]

            engine.SetGlobalFunction("GradientTriangle", new Action<double, double, double, double, double, double, ColorInstance, ColorInstance, ColorInstance>(GlobalPrimitives.GradientTriangle));


:P

I'm going to have to do a different style in which you pass point objects to the drawing methods. A required JS file can then link the two for backwards compatibility. Anyways who would put in so many arguments? These days all primitives are drawn with (x, y) vertices.
  • Last Edit: July 08, 2013, 05:42:30 pm by Radnen
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: Sphere SFML
Reply #22

I just tested this, you can do this:
Code: (javascript) [Select]

var col1 = CreateColor(255, 0, 0);
var col2 = CreateColor(255, 255, 255);

for (var i in col1) col2[i] = col1[i];

image.blitMask(0, 0, col2); // will be red.



I assume you mean that works in sphere-sfml, right?  Because it definitely doesn't work in Sphere 1.5, I know because I had to hack a special case into to my tween scenelet in Scenario to handle tweening CreateColor()'d colors, otherwise it didn't work.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #23
No, yeah I meant Sphere-Sfml. :)

I just got basic input in. I thought it would be a nightmare to try and cover all of the key constants, but I was able to make a mapping between SFML's keyboard constants and the KEY_* fields. However, they may not be the same as Sphere 1.5. Therefore if you have a saved game that saved your key mappings from Sphere 1.5 they'll change if you switch over to sphere-sfml! I'll have to individually remap each key... to fix that.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #24
Alright, latest version now at github. This one can play most games that do not use the map engine or system scripts. So if you have a graphics only tech demo that doesn't utilize the surface object (as it is incomplete), then you can run your game in it.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Sphere SFML
Reply #25

I just got basic input in. I thought it would be a nightmare to try and cover all of the key constants, but I was able to make a mapping between SFML's keyboard constants and the KEY_* fields. However, they may not be the same as Sphere 1.5. Therefore if you have a saved game that saved your key mappings from Sphere 1.5 they'll change if you switch over to sphere-sfml! I'll have to individually remap each key... to fix that.


I've got the same issue with SDL (and now SDL 2) key constants. One night I just bit the bullet and wrote all 130 SDL Key Constants into the input plugin, which was *not* fun, nor would I wish it on anyone else.

I did figure out a better way, though. I can just loop from 32 to 130 (100? Something like that?), bind the variable as the number, and then call SDL_ScanCodeToKeyCode (or maybe it was KeyCodeToScanCode? Either way it changed in SDL 2) and then call the SDL Key Name function on that number. I'll certainly get a bunch of garbage values in there, but I'd also get all the codes needed. And it would be prettier code, easier to write, simpler in general, and better to maintain.

I'm just writing the changes in key constant literal values off as a loss of compatibility, myself. The code will work the same if you actually used the key constants as you should. The only problems would show up in game saves...but in that case, it should be relatively simple to just edit the save.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #26

I did figure out a better way, though. I can just loop from 32 to 130 (100? Something like that?), bind the variable as the number, and then call SDL_ScanCodeToKeyCode (or maybe it was KeyCodeToScanCode? Either way it changed in SDL 2) and then call the SDL Key Name function on that number. I'll certainly get a bunch of garbage values in there, but I'd also get all the codes needed. And it would be prettier code, easier to write, simpler in general, and better to maintain.


I did a similar approach too! But some of the key nnames were different. There were 'Left/Right Alt/Control/Shift', (yeah ctrl was spelled control) 'Return' instead of 'Enter', etc. So some string conversion had to be done. I am left with invalid key references for saved games tho. Maybe a JS script convert from * to Sphere and Sphere to *? That might take some work, lol. I wonder if it's a constant off or altogether mixed up? I'm tempted to do something like: "key_code + n = sphere_key_code"

Alright, I just added joysticks. It can support up to 8 (currently), joysticks at a time. It can also auto-detect a plugged-in joystick. Vanilla Sphere could not: you had to restart the game engine.

Also, my windowstyle test crashes in Sphere v1.6 and in Sphere v1.5 but not my my sphere-sfml. It has to do with WindowStyle.clone();

Code: (javascript) [Select]

// Purpose: Tests the speed and efficiency of images.

function TestWindows()
{
var done = false;
var wind = LoadWindowStyle("main.rws");

var wind2 = wind.clone();

var blue = CreateColor(0, 0, 255);
var white = CreateColor(255, 255, 255);
var time = 0, i = 1, x = 0, y = 0;

while (!done) {
wind.drawWindow(32, 32, 80, 80);

wind.setColorMask(blue);
wind.drawWindow(128, 32, 80, 80);

wind2.drawWindow(32, 128, 80 + x, 80 + y);

wind.setColorMask(white);

if (time + 25 < GetTime()) {
if (x == 100 || x == -4) i *= -1;
x += 4 * i;
y += i;
time = GetTime();
}

FlipScreen();

while (AreKeysLeft()) {
if (GetKey() == KEY_ENTER) done = true;
}
}
}


I cannot believe Sphere does not have a clone method for windowstyles when it does have one for most other objects. Removing the offending windowstyles makes it run in Sphere 1.5, but it crashes after 5 seconds in sphere 1.6. There you have it folks: Sphere 1.6 is very unstable. Oh! Now I know why Blockman randomly crashes, it too grows and shrinks windowstyles.
  • Last Edit: July 13, 2013, 09:53:54 pm by Radnen
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Sphere SFML
Reply #27
Makes me want to check how TS handles hot-plugged joysticks! I honestly don't know if it can see them, and it's hard for me to properly test that properly--especially considering most of my testing has been with a slightly hokey userspace XBox controller driver on Linux, and a re-wired original XBox duke controller.

Perhaps we should write up the new functions and behahiour for WindowStyles, they obviously haven't had as much love as the other Sphere objects. Having getImage() and Clone() members would go a long way to making them more usable, and much more similar to how other Sphere objects work.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Sphere SFML
Reply #28
I don't know why but .NET code always take 30,000+ K of memory. Sphere has a very light footprint, which I guess is something I can't really try to change. The good news is that my engine can use more than a single core. On my quad core it's usually in the mid 30's of CPU usage, rather than stuck at 25%.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Sphere SFML
Reply #29
I say don't worry about it, considering how most peoples' systems have plenty of RAM nowadays. What I'd worry about more is how much space the engine would take up when converting it into an HTML app.

Also, it can run games already? Nice!
  • Last Edit: July 14, 2013, 04:10:11 pm by DaVince