Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Doc Block
Apr 15, 2003
Fun Shoe

beauty queen breakdown posted:

Seconding the notes above on Godot 3.0, but adding a question --

Coming from an enterprise perspective, I've found Godot doesn't die to version control with `git`, but there's still a lot of point-click-&c in the interface. As an impatient person, this drives me crazy but I'm trying to stick with it on the basis of cross-platform dev on the quick.

I really want to use something like libGDX where I can develop a game on the JVM, but I've found virtually no tooling support for builds / getting started -- the docs are a mishmash of what they were doing a few years ago with maven and doing now with gradle...

Am I the only person with this kind of thought process? Am I terrible? I have to presume so.


( edit : I'm only interested in 2D development in this context )

Do you mean it doesn't do version control with git? While Godot doesn't handle version control for you, there's nothing stopping you from putting your Godot-based game in version control yourself, including git.

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

nolen posted:

I'm trying to build a Quarth clone for funsies and am kinda stuck on the logic that determines when a set of combined shapes equals a rectangle.

Has anyone built something similar and would have some insight?
I'm guessing single column/row doesn't count as a rectangle?
What if you had something like a 5x5 inverted-U shape with a 3x3 inverted-U shape inside it, and then filled those last two squares, does it kill the big square or the small square?
Also seems like it would be possible to complete two rectangles at the same time, one wide and one tall, what should happen in that case? Destroy both? Destroy the larger one? Is it not possible for some reason?

Anyway, given that you only need to check when a new cell is added, this seems like a job for a simple brute-force-ish algorithm, where you don't consider the shapes at all, you just consider individual cells and boundaries.

1. starting from your new cell (x, y) you extend out to the largest distance you can in each cardinal direction until you hit an empty cell (keep left, right, top, bottom).
2. four way nested loop (testLeft in range left...x) (testRight in range right...x) (testTop in range top...y) (testBot in range bottom...y)
3. if testLeft == testRight || testTop == testBot skip it.
4. check that every cell in the described test rectangle is occupied - skip out as soon as you find one that's not.
5. check the boundaries of the cells of the described rectangle - if eg. any cell of testLeft is connected to testLeft-1 skip out.
6. save the rectangle you've found here, it's ready to disappear.
7. end the loop
8. disappear all the cells in any of the rectangles you saved.

This seems horrifying because it's an O(n^6) algorithm, but all the 'n' are very very small and you don't do it very frequently, so it's almost certainly not worth trying to optimize beyond this.

This method presupposes that the data structure is comprised of a grid of cells and whether they are connected horizontally/vertically, and not a data structure of shapes.

If instead the data structure is shapes, you could do an O(n!) in the number of shapes solution, wherein you first take every combination of shapes that includes the newly updated shape, and then calculate:
1. (left, right, top, bottom) = the leftmost coordinate, rightmost coordinate, etc. of all the shapes selected for comparison.
2. sum of the total number of cells in all the selected shapes.
3. if (right-left) * (bottom-top) == sum, you have a rectangle ready to disappear.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

roomforthetuna posted:

I'm guessing single column/row doesn't count as a rectangle?
What if you had something like a 5x5 inverted-U shape with a 3x3 inverted-U shape inside it, and then filled those last two squares, does it kill the big square or the small square?
Also seems like it would be possible to complete two rectangles at the same time, one wide and one tall, what should happen in that case? Destroy both? Destroy the larger one? Is it not possible for some reason?

Anyway, given that you only need to check when a new cell is added, this seems like a job for a simple brute-force-ish algorithm, where you don't consider the shapes at all, you just consider individual cells and boundaries.

1. starting from your new cell (x, y) you extend out to the largest distance you can in each cardinal direction until you hit an empty cell (keep left, right, top, bottom).
2. four way nested loop (testLeft in range left...x) (testRight in range right...x) (testTop in range top...y) (testBot in range bottom...y)
3. if testLeft == testRight || testTop == testBot skip it.
4. check that every cell in the described test rectangle is occupied - skip out as soon as you find one that's not.
5. check the boundaries of the cells of the described rectangle - if eg. any cell of testLeft is connected to testLeft-1 skip out.
6. save the rectangle you've found here, it's ready to disappear.
7. end the loop
8. disappear all the cells in any of the rectangles you saved.

This seems horrifying because it's an O(n^6) algorithm, but all the 'n' are very very small and you don't do it very frequently, so it's almost certainly not worth trying to optimize beyond this.

This method presupposes that the data structure is comprised of a grid of cells and whether they are connected horizontally/vertically, and not a data structure of shapes.

If instead the data structure is shapes, you could do an O(n!) in the number of shapes solution, wherein you first take every combination of shapes that includes the newly updated shape, and then calculate:
1. (left, right, top, bottom) = the leftmost coordinate, rightmost coordinate, etc. of all the shapes selected for comparison.
2. sum of the total number of cells in all the selected shapes.
3. if (right-left) * (bottom-top) == sum, you have a rectangle ready to disappear.

code:
55555
53335
53x35
53x35
5xxx5
Not op but a fan of quarth. You would need to fill 5 squares for the two U’s described; all of it would be cleared at once. If you filled the middle before extending a side, the interior U would clear before the exterior.

You can improve the algorithm by realizing utilizing the fact that only one rectangle can be cleared at a time (along with any number of extensions). E.g you only need to look for extensions to a rectangle after you’ve completed the base rectangle.

Stick100
Mar 18, 2003

Portland Sucks posted:

I don't know much about game/graphics development, but I've got a use case at work that I think might call for Unity and just want to verify that it may be a good option before wasting too much time chasing down a hole for nothing.

I work for a manufacturing company and our team is in charge of putting out tools, HMIs, and visualization platforms for our operators and laborers that work in a plant. I'm restricted to using C# for development purposes (less I become the only one capable of maintaining it) and have been put in charge of our next product. It needs to be a touch screen, interactive HMI that's going to be mounted in some heavy equipment. Everything we've built so far has been in WinForms or WPF but the specifications and requirements for these interfaces continue to increase in complexity every time we put out a new tool so I'm thinking that maybe a game engine might be better suited for what we're doing? Something that's more than a menu driven desktop application but not quite a full on game. I'm thinking Unity just because of the C# requirement, but I don't know the first thing about graphics development outside of desktop apps so if that's overkill I'm open to other options. Basically I'm just looking for something to develop highly graphical custom 2D interfaces.

Unity could work for you, but it will use more of your CPU than other solutions. 2 other things to consider are HTML + Javascript, or GoDot. If you do end up using Unity make sure to turn on VSync so that the system doesn't waste a ton of rendering 1000fps.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

leper khan posted:

Not op but a fan of quarth. You would need to fill 5 squares for the two U’s described; all of it would be cleared at once. If you filled the middle before extending a side, the interior U would clear before the exterior.
Oops, yeah, I meant 5x5 with 4x3 inside it. But I guess the answer is "the bigger one" in this case.
Now that you've given me a way to describe a thing, what about this then, vs. the "only one rectangle at a time" rule?
code:
AAA
ABBC
ABBC
AXBC
If you add the X cell, should this destroy the A+B shape, the B+C shape, or both? Or is it impossible because CCC already disappeared because a 1x3 rectangle is still a rectangle?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Stick100 posted:

Unity could work for you, but it will use more of your CPU than other solutions. 2 other things to consider are HTML + Javascript, or GoDot. If you do end up using Unity make sure to turn on VSync so that the system doesn't waste a ton of rendering 1000fps.
Both Unity and Godot will use a bunch of CPU constantly rendering, neither has a "this is static now, don't do anything until the user does something" mode. Vsync will make it 60fps instead of 1000fps, but for a UI you probably really want 0fps waiting for input. This is an especially annoying trait for phone support where one might particularly like to conserve battery by rendering nothing while a game is paused, for example. The best you can do for that is reduce the frame rate, but that also reduces how quickly it will respond.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
My idea for Quarth:

Edit: Nevermind, after watching a gameplay video I see the rules are different than I thought they were. I didn't realize it was possible to have "holes" in the rectangles. I'll leave this here anyway.

My terminology is there are pieces (just 1x1) and groups (the groups are the collections of pieces with the boundaries)

For groups, keep track of their bounding boxes (max_x, max_y, min_x, min_y) and how many pieces are in them. Update these values accordingly when a piece is added to a group.

To find if a set of groups makes a rectangle, find the total bounding box for the whole set (pretty straightforward, for example the max_x value of the set is the maximum of the groups' max_x values) and the total number of pieces in the set (just the sum of the pieces in each group). It's a rectangle if the area of the bounding box matches the total number of pieces (I'm guessing 1xN rectangles don't count either, so check for that). This is a very cheap calculation.

You can probably just brute force through all sets of groups touching the newly added piece and take the largest set. It's n! but n is pretty small. You can speed up the search by always including the group of the newly added piece (since this must be part of the resulting rectangle, if it exists) so it's (n-1)!

There's probably a better approach than the brute force method but I like the method of comparing the area of the bounding box to the total number of pieces in determining rectangles.

HappyHippo fucked around with this message at 15:32 on Apr 17, 2018

Obsurveyor
Jan 10, 2003

roomforthetuna posted:

Both Unity and Godot will use a bunch of CPU constantly rendering, neither has a "this is static now, don't do anything until the user does something" mode. Vsync will make it 60fps instead of 1000fps, but for a UI you probably really want 0fps waiting for input. This is an especially annoying trait for phone support where one might particularly like to conserve battery by rendering nothing while a game is paused, for example. The best you can do for that is reduce the frame rate, but that also reduces how quickly it will respond.

This sucks so much about Unity, now that I'm doing a mobile app that's a mostly UI game(laser tag interface for hardware blaster). I thought I had figured out a way to do 60fps input and saving some battery by disabling the camera every other frame but I had a bug and it wasn't actually doing anything. Still wondering if maybe rendering to a render texture and just re-rendering it every X frames will save something, but I suspect not much if anything for the extra work to get it going.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

roomforthetuna posted:

Oops, yeah, I meant 5x5 with 4x3 inside it. But I guess the answer is "the bigger one" in this case.
Now that you've given me a way to describe a thing, what about this then, vs. the "only one rectangle at a time" rule?
code:
AAA
ABBC
ABBC
AXBC
If you add the X cell, should this destroy the A+B shape, the B+C shape, or both? Or is it impossible because CCC already disappeared because a 1x3 rectangle is still a rectangle?

Judging from gameplay videos there are no shapes like C, the pieces always come with a "hook" at minimum, although maybe I haven't watched enough

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Obsurveyor posted:

This sucks so much about Unity, now that I'm doing a mobile app that's a mostly UI game(laser tag interface for hardware blaster). I thought I had figured out a way to do 60fps input and saving some battery by disabling the camera every other frame but I had a bug and it wasn't actually doing anything. Still wondering if maybe rendering to a render texture and just re-rendering it every X frames will save something, but I suspect not much if anything for the extra work to get it going.

Would that happen to be for Recoil or a competitor?

beauty queen breakdown
Dec 21, 2010

partially cromulent posting.
"2021's worst kept secret"


Doc Block posted:

Do you mean it doesn't do version control with git? While Godot doesn't handle version control for you, there's nothing stopping you from putting your Godot-based game in version control yourself, including git.

What I meant was that Godot does allow me to do version-control with git from the command line (as I prefer) -- I used the phrase "doesn't die to," which in retrospect was a bit confusing.

The main issue I have with it is adding things inside the interface involves a lot of point, click, &c. I'm doing my best to stick with it but coming from an enterprise dev perspective I'd way rather just write the code elsewhere and verify the results in the interface (if I have to use the interface at all).

Doc Block
Apr 15, 2003
Fun Shoe
You can do pretty much everything in code in Godot, it’s just that most people don’t want to.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Would Godot be good for somebody with severe NIH syndrome (me)??

KillHour
Oct 28, 2007


Might I suggest writing your game completely in assembly?

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
If it worked for Roller Coaster Tycoon it can work for you!

Obsurveyor
Jan 10, 2003

HiriseSoftware posted:

Would that happen to be for Recoil or a competitor?

The former

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Obsurveyor posted:

The former

Finally, a use for those AR marker cards!

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

baby puzzle posted:

Would Godot be good for somebody with severe NIH syndrome (me)??
I'm quite NIH, and I prefer Godot over most of the viable alternatives, assuming your goal is cross-platform-ness.

SDL might be acceptable, because you have more control, but as far as I could tell SDL is a giant pain in the rear end to *really* build cross-platform. It's fairly painful to even get it to build properly on one platform. And even then it already abstracts input away too much and requires it to be on the same thread as rendering which is really loving annoying when you're that close to being bare-metal.

The nice thing about Godot is that it's not very pushy at all - if you don't want to use some feature, you don't have to jump through hoops to avoid it, you can just not use it. Also, most of the features are actually good and work well, so the impetus to not use them is much smaller than with other engines.

Linear Zoetrope
Nov 28, 2011

A hero must cook
Only issue I have is at present Godot doesn't have the full shader pipeline, only vert and frag right now. The issue about adding Tess or Geom stages is kind of stalled because nobody seems to want to do it right now.

xgalaxy
Jan 27, 2004
i write code

roomforthetuna posted:

SDL might be acceptable, because you have more control, but as far as I could tell SDL is a giant pain in the rear end to *really* build cross-platform. It's fairly painful to even get it to build properly on one platform. And even then it already abstracts input away too much and requires it to be on the same thread as rendering which is really loving annoying when you're that close to being bare-metal.

Does this matter if you aren’t using SDL rendering and only need it for input and window creation and some other misc. stuff? Just init the ‘video system’ from your input thread and you are good.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Linear Zoetrope posted:

Only issue I have is at present Godot doesn't have the full shader pipeline, only vert and frag right now. The issue about adding Tess or Geom stages is kind of stalled because nobody seems to want to do it right now.

tess and geom are useless so that's fine.

Casaval
Aug 25, 2003

Newtype
I want to make a Sim/Tycoon type game, but I'm basically stuck on the application architecture/design/pattern/whatever. You know, like having customers walk around like in Roller Coaster Tycoon and they feel like buying stuff or riding attractions. I'm not trying to be overly ambitious, I swear. I'd be happy with making something along the lines of one of the Kairosoft games or Tiny Tower were you can make like a mall or a school and people are wandering around doing stuff.

Does anyone have any recommendations for any books or articles that would help me wrap my head around building such a game?

I am web developer by trade so figuring out how to structure a game that isn't like a basic 2d platformer escapes me.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
The most important part of that kind of game is how you define the rules that govern your Sims. In RCT they basically wander pretty aimlessly and decide what to do when they bounce up against something (so if they walk up to a food stall they decide then and there if they're hungry and if they are they buy something and if they aren't they don't, based on the price). Sometimes they decide they actually want something enough to pathfind to it (when they want to ride a ride again, or if they're really hungry, or if they want to leave the park, etc.).

Performance can be important because you're potentially simulating and rendering hundreds if not thousands of Sims so it's important to keep them as simple as possible. Their collectively behaviour is more important than having their individual behavior be super realistic, if that makes sense.

The architecture doesn't have to be more elaborate than an update-render game loop. You'll want to look up efficient pathfinding, and maybe finite state machines for the Sims (although that certainly isn't the only approach to take).

HappyHippo fucked around with this message at 20:24 on Apr 18, 2018

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde
People designing open world games. How do you deal with "important enemies" (i.e. Enemies that are stalking the player character) but are too far from the player? In most games enemies get despawned and then maybe respawned, do you still update the ai for some enemies even if you despawned the world around them?

Casaval
Aug 25, 2003

Newtype

HappyHippo posted:

The most important part of that kind of game is how you define the rules that govern your Sims. In RCT they basically wander pretty aimlessly and decide what to do when they bounce up against something (so if they walk up to a food stall they decide then and there if they're hungry and if they are they buy something and if they aren't they don't, based on the price). Sometimes they decide they actually want something enough to pathfind to it (when they want to ride a ride again, or if they're really hungry, or if they want to leave the park, etc.).

Performance can be important because you're potentially simulating and rendering hundreds if not thousands of Sims so it's important to keep them as simple as possible. Their collectively behaviour is more important than having their individual behavior be super realistic, if that makes sense.

The architecture doesn't have to be more elaborate than an update-render game loop. You'll want to look up efficient pathfinding, and maybe finite state machines for the Sims (although that certainly isn't the only approach to take).

Ah, so just have a collection of sims objects and loop over them each update and process their behaviors/stats/movement?

Your explanation is getting the gears turning in my brain so thanks for that :)

Linear Zoetrope
Nov 28, 2011

A hero must cook

Suspicious Dish posted:

tess and geom are useless so that's fine.

I want to play with experimental geometry (e.g. geometry that changes shape based on perspective) so Tess is helpful for that. Otherwise you get a nest of dummy objects and obfuscation tricks to hide you subbing out models.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Casaval posted:

Ah, so just have a collection of sims objects and loop over them each update and process their behaviors/stats/movement?

Your explanation is getting the gears turning in my brain so thanks for that :)

Yeah that's the idea.

One of the biggest performance costs are when sims have to interact, because you don't want each sim to loop over each other sim to detect collisions, etc. You'll notice RCT gets away with this simply by letting the sims walk right through each other - they don't interact at all.
The other big performance cost can be pathfinding. Pathfinding for hundreds of sims in real time can be expensive. In RCT the sims often wander aimlessly, avoiding pathfinding althogether. When they do pathfind they likely perform a single pathfind and save the path - this is made easier by the fact that they're allowed to walk through each other, so the path doesn't have to avoid moving obstacles.

Good luck!

HappyHippo fucked around with this message at 22:23 on Apr 18, 2018

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I now want a duo of crafty characters named Tess and Geom.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Linear Zoetrope posted:

I want to play with experimental geometry (e.g. geometry that changes shape based on perspective) so Tess is helpful for that. Otherwise you get a nest of dummy objects and obfuscation tricks to hide you subbing out models.

use compute or cpu

Colonel J
Jan 3, 2008
Note that sims in rct don't try really hard to find a viable path to the exit, and if they fail the game will warn you with a "beep". I remember being driven to tears of anger as a child cause I would get that beep like 10 times a second in my park.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Yeah those park goers were dumb as hell

KoRMaK
Jul 31, 2012



I have what seems to be a terribly optimized method, in Unity, that is drawing to the screen every frame.

I'm using physics objects to get some raw data, projecting their position to the screen, and using that to populate voxel data that I then run marching squares on and draw the marched data to the screen. It's running badly, I drop from like 250fps or 120fps to 30 when I turn the marching cubes rendering on.

I feel like I should do this drawing as a shader but I'm not really sure, I've also never written a shader before as much as I want to/need to.

Here's my code, there's 3 nested for loops that I'm pretty sure aren't helping, but I'm not sure how to optimize it. I'd like to hear what suggestions for optimizations you here could offer. Any would be appreciated! I implemented a quad tree to help cut down on areas that I don't have to render, and that helped a bunch but not enough. I ideally want to have like 50 physics objects on screen at once and keep my fps above 60, or at least 30.

https://github.com/KoRMaK/IsometricLiquid/blob/c75a4a95b8e5b758772763857e9b4fc530ea9c41/Assets/src/ScreenDrawer.cs#L82 Comment out lines 81-85 and you get a huge fps jump. Comment out line 81 and 82 or 83 separately and you get a big fps jump.


If you clone this repo, you should be able to open it in Unity and start running it, so feel free to play around in it if you want to see the heck I've created for myself.

KoRMaK fucked around with this message at 03:36 on Apr 19, 2018

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

limaCAT posted:

People designing open world games. How do you deal with "important enemies" (i.e. Enemies that are stalking the player character) but are too far from the player? In most games enemies get despawned and then maybe respawned, do you still update the ai for some enemies even if you despawned the world around them?

I can't imagine these enemies can do anything with the world around them if you unloaded the world representation. Are they literally stalking the player? Presumably they are doing a bad job! Or if you are trying to represent them, say, catching wind of you from the other side of the world, then it just has to be scripted with an approximation.

Cheston
Jul 17, 2012

(he's got a good thing going)
Funnily enough, S.T.A.L.K.E.R is an excellent example of how to do that. Within a certain radius of the player, AI is fully represented in the game world. Elsewhere it's just graphs and such. The term is "A-Life" and it got modded heavily, especially in the original game.

Here's a good summation

Cheston fucked around with this message at 18:21 on Apr 19, 2018

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I was trying to delegate more work into InkScript to call back into game logic, and I discovered this was very much poopoo'd by the developers; the functions would get called during parsing and cause havoc. I am wondering now with Unity supporting .net 4.6 if I should just go back to playing with IronPython. Has anybody bit that bullet yet?

Khorne
May 1, 2002
Godot engine's page not found thing looks like goatse to me:

code:
        \          SORRY            /
         \                         /
          \    This page does     /
           ]   not exist yet.    [    ,'|
           ]                     [   /  |
           ]___               ___[ ,'   |
           ]  ]\             /[  [ |:   |
           ]  ] \           / [  [ |:   |
           ]  ]  ]         [  [  [ |:   |
           ]  ]  ]__     __[  [  [ |:   |
           ]  ]  ] ]\ _ /[ [  [  [ |:   |
           ]  ]  ] ] (#) [ [  [  [ :===='
           ]  ]  ]_].nHn.[_[  [  [
           ]  ]  ]  HHHHH. [  [  [
           ]  ] /   `HH("N  \ [  [
           ]__]/     HHH  "  \[__[
           ]         NNN         [
           ]         N/"         [
           ]         N H         [
          /          N            \
         /           q,            \
        /                           \
It took me ages of staring at it to figure out what it actually was. I was thinking "wow did I just get goatsed by a real game engine website, that's real weird and not very expected in 2018".

xzzy
Mar 5, 2009

Good job outing yourself as being born after 1990. :v:

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Rocko Bonaparte posted:

I was trying to delegate more work into InkScript to call back into game logic, and I discovered this was very much poopoo'd by the developers; the functions would get called during parsing and cause havoc. I am wondering now with Unity supporting .net 4.6 if I should just go back to playing with IronPython. Has anybody bit that bullet yet?

I'm starting to think the fact that people don't really have anything to say about me and this scripting stuff is telling me I'm very, very alone here.

But if somebody wants to join the "trying to use IronPython in Unity with .NET 4.6" clubhouse:
code:
using UnityEngine;
using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;

public class IronPythonExperiment : MonoBehaviour
{
    private ScriptEngine m_engine = Python.CreateEngine();
    private ScriptScope m_scope = null;

    void Start()
	{
        m_scope = m_engine.CreateScope();
        m_engine.Runtime.LoadAssembly(typeof(UnityEngine.GameObject).Assembly);
        m_scope.SetVariable("world", "Embedding Python Example!");
        string code = 
            "from UnityEngine import Debug\n" +
            "Debug.Log('Hello' + world)\n";
        ScriptSource source = m_engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
        source.Execute(m_scope);
    }
}

Mooey Cow
Jan 27, 2018

by Jeffrey of YOSPOS
Pillbug

Rocko Bonaparte posted:

I'm starting to think the fact that people don't really have anything to say about me and this scripting stuff is telling me I'm very, very alone here.

I think most people would be a bit confused as to why you would want to do such a thing, but I assume it's to be able to do some runtime scripting stuff?

I often find it useful to be able to add arithmetic expressions that can be stored as a string per object and compiled and evaluated on the fly, and I briefly considered adding a general scripting engine like Javascript or something for that. But 1) it turns out they always use JIT for everything with no fallbacks, which will not work on a lot of platforms (iOS, consoles, etc) and 2) they are huge. So I always opt for a simple domain specific language that only does what I need. Hell, I've written so many parsers in my days it's pretty much trivial by now (protip: look up "Pratt parser" if you haven't heard of it; it's really neat).

Recently I wrote a little language for our text files, which sometimes need to be tweaked in cumbersome ways to accommodate the quirks of various real-life languages. But since the majority of lines won't need special numeral reordering or whatever, it would be waste to put all text in like Lisp or something, so I wrote a thing that's optimized for storing and retrieving regular key-value pairs, but can also handle this
code:
PartLess<v=[a]>: [a < p ? v : []]
PartLess<v=[a, ...Tail]>: [ [@PartLess<p, v:[a]>..., @PartLess<p, v: Tail>...] ]
PartLess: [[]]
PartGreater<v=[a]>: [a >= p ? v : []]
PartGreater<v=[a, ...Tail]>: [ [@PartGreater<p, v:[a]>..., @PartGreater<p, v:Tail>...] ]
PartGreater: [[]]

QSort<v=[]>: [v]
QSort<v=[a]>: [v]
QSort<v=[p, ...Tail]>: [ [@QSort<v: @PartLess<p, v: Tail>>..., p, @QSort<v: @PartGreater<p, v: Tail>>...] ]
Don't know if you can figure out what it does, but it's Quicksort in basically 1 line, plus a few helper functions for partitioning lists and termination conditions. Stuff inside [ ] is treated as an expression, and @ "calls" a different keyed value, and sends in the parameters named inside the < ... >. [ ] inside an expression creates a list, and ellipses expand a list in place. It does pattern matching based on the variables sent to values with the same key, so QSort<v=[a]> matches a list-variable of size 1, named "v", and injects that value into the matched string's scope as a variable named "a" (v will also be there, but as the original list). QSort<v=[p, ...Tail]>, matches a list of at least size 1, names the first value "p" and puts the rest into a list called "Tail". You could also write <v=[a, ...Middle, b]> if you wanted to get the first and last elements, or <v=[...Head, middle, ...Tail]>, to get the middle. There are no real restrictions, but stuff like a middle element might not always be well-defined (although the selection algorithm always produces a consistent result)...
You can also do string operations of course (that's mainly what it's for), and build up a new string, and then you can @ that too, so stuff like [ @("Hello" + "World")<p: "what up"> ], would get the string with the key HelloWorld, and send it the parameter p.

(Obviously you wouldn't want to use it for complicated stuff like sorting lists though, but I thought the list expansion and matching operators were neat)

Mooey Cow fucked around with this message at 15:18 on Apr 21, 2018

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Mooey Cow posted:

I think most people would be a bit confused as to why you would want to do such a thing, but I assume it's to be able to do some runtime scripting stuff?

I'm trying to do a "small action RPG" (lol I know I'm dumb) and I had to deal with NPC interactions and triggers. It was rapidly getting tedious to vomit that logic out in C#. I went with Ink Script first because I was preoccupied with basic dialogs and choices. Then I started to implement a shopkeeper with a buy/sell option and a generating a second menu. This got real clumsy to do in Ink Script. Because calling back with functions that affect state is poo-poo'd, I have to instead observe some boolean variables like a giant switch board, extract state and then map to the function I wanted to call. It's that or embed the call as some tagged metadata in the dialogs or something. Either way was getting gross.

quote:

I often find it useful to be able to add arithmetic expressions that can be stored as a string per object and compiled and evaluated on the fly, and I briefly considered adding a general scripting engine like Javascript or something for that. But 1) it turns out they always use JIT for everything with no fallbacks, which will not work on a lot of platforms (iOS, consoles, etc)
I don't understand the problem here. Do you mean using Unity's own JavaScript stuff? I never even touched it so I don't know how it works. Do you mean they're compiling that beforehand and then locking it down?

I just looked at DLR JavaScript implementations and... yeap that sucks.

quote:

So I always opt for a simple domain specific language that only does what I need. Hell, I've written so many parsers in my days it's pretty much trivial by now (protip: look up "Pratt parser" if you haven't heard of it; it's really neat).
I made a rule for myself to avoid inventing programming languages as I had basically done that accidentally at least once with metadata files. Given the shopkeeper example, I'd be reinventing a lot of constructs I that are available in any existing language, and on top of that I am quite sure the rudimentary error handling I'd have would be lucky to express "it not of the working" as the error message versus something more descriptive from a more robust parser.

But I'm not making GBS threads on you; if you do that a lot then I imagine your kung fu has gotten a bit more strong and true.

Edit: A big thing I think I need is to be re-entrant. That's a tricky one with embedding Python here. Ink was nice to be able to pick up the conversation where I left off, and I could shoehorn some logic to reset if that's what I actually wanted.

Rocko Bonaparte fucked around with this message at 17:49 on Apr 21, 2018

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply