Push, pop functions outside stack class - function

I'm fairly new to computer science, and when I first learned about push and pop, I was told that they are methods inside the stack class. So, if you had a stack called stack1, then you would do stack1.push(3) or stack1.pop(). However, I've recently come across an example where push and pop are functions defined outside the stack class, so you would have to do push(3, stack1), or pop(stack1). What is the advantage of writing push and pop in the latter way? I.e. why have stack1 as an argument into the push/pop functions; isn't this less object oriented? Thanks.

Related

Make JVM dialog a child window of native top-level window

I have a legacy, X/Motif, C++ application for which new windows have been added using Java/JNI.
New Java windows have been either top level windows or dialogs with no parent.
Is there any reasonable way to get a child window created by the JVM, such as a JDialog, to have as its parent a window created on the native side using X/Motif, and if yes then how? This would still be useful even if Java AWT/Swing is not aware of the parenting structure and the window manager just kept the dialog on top of the top-level window (of course, having all the normal control over windows in Java would be preferable, just not strictly necessary for all uses of my question).
I am thinking the answer might be "No, not in any reasonable way. You would have to do epic surgery on both your native side and within the JVM." If that is the answer, then so be it. But I am hoping someone has an answer along the lines of "If you make this X call or that window manager call, you can get the window manager to supply certain dialog properties with the argument top-level window as the parent."
Essentially, I am looking to increase the integration between the C++ and Java user interfaces as much as possible. Right now, they are run as one application by using JNI, but the GUI windows/components are essentially separate, despite sharing data.
One benefit of this, already mentioned, is having dialogs not show up behind what the user perceives as the top level window.
Another thing I have considered, though I probably will not do (tell me how crazy you think it is), is to make it appear as though Java components are in the C++ window by getting the screen coordinates of a component on the C++ side, displaying a borderless window on the Java side at that screen location, so it looks like it's part of the C++ application. I can think of so many negative side effects of this, though, that I would not do it unless there was a simple way to negate them (focus issues, a window displaying between this dummy window and the real top level window, and other things would affect user experience). Even avoiding this, though, there are still benefits to an affirmative answer to my question.
If you're using the XToolkit (Java 1.7+), you can proceed as follows:
Get the numeric id of the native peer of a java.awt.Window instance (see this answer).
Find the corresponding X11 Window struct by its id by iterating the clients of the X server (see the sources of xwininfo and xlsclients utilities, also Select_Window_Args(int*, char**)).
Use XReparentWindow().

What is the best practice for displaying huge chat logs or console logs in a scrollable window? (AS3)

I'm writing a graphic console that highlights different entries and stores things when you input them (in AS3) but I've found that once there are thousands of entries, the program starts lagging and scrolling is slow. If I want scrolling to be animated with acceleration it gets even slower.
How do I move the giant block of objects that are my stored entries up and down?
Do I have to progressively load messages around where the user is looking? How does the scrollbar handle this, then?
you should create a custom container instead TextField, it would be easier to build an accelerated scrolling too,
each log entry would be an extended DisplayObject that holds anything you want just like inflating layouts in android.
the most important part should be reducing Memory usage:
you may only store plain text of log enteries in something like a global array and when scroll position is close enough, generate this layouts, then adding them in container to show, and vice versa for removing far behind chats.
however this proccess stills using much memory during runtime.
so, just according the concept of android's DiskLruCache, it is possible to storing some part of our invisible data which would be too far from our scroll position to disk instead memory, using SharedObject's.
How do I move the giant block of objects that are my stored entries up
and down?
You don't. As you have noticed, when the number Display Objectson the DisplayList greatly increases, the memory overhead increases and the housekeeping details of managing the Display Objectseventually causes performance to suffer. You don't mention any details of how you are implementing what you have so far so my comments will be general.
The way this is handled by various platform list components in Flex, iOS and I assume, Flash, is to only display the minimum number of objects needed, and as the user scrolls, objects are shuffled in and out of the render list. A further optimization is to use a "pool" of "template" objects which are reused so you don't pay a initialization time penalty. There is probably an actual name for this ("...buffering...") technique but I don't know what it is (hopefully some kind person will provide it and a link to a fuller description for how it works).
And as for how it works – you can DIY it, figuring out, as the user scrolls, which objects are moving off-screen and can be recycled, which are going to move on-screen, etc. Of course this all assumes that you have your objects stored in a data structure like and Array, ArrayList or ArrayCollection. As an alternative to coding all this from scratch, you might see if the DataGrid or List components will meet your needs – they manage all of this for you.
Flash Tutorial: The DataGrid Component (youTube video)
Customize the List component
Lots of other examples and resources out there.
(again, I work in Flex where the DataGrid and other list-based components can customized extensively using "skins" and custom item renderers for visual style – not sure if it is the same in Flash)

Why aren't Camera.unproject() and Camera.project() inverses of each other in libGdx?

It's even written in the doc that Camera.unproject() assumes that the screen has it'origin in the top left corner, on the other hand Camera.project() assumes that the screen has its origin in the bottom left corner. This is so annoying. Is this intentional? Am I not getting something?
tmp3.x = selected.pos.x;
tmp3.y = selected.pos.y;
camera.unproject(tmp3);
camera.project(tmp3);
This flips the vector, where it should return the same vector.
EDIT:
First I was trying to use Viewport.project() and Viewport.unproject() to convert points from one viewport to another (to position a context menu over a game element).They also inherit this naming confusion, and it's not even mentioned in the javadocs there.
PS. I really like libGdx. I've just written this to maybe spare some headache for someone in the future as I didn't find this anywhere on the web pointed out directly.
The Javadoc for the project method explains why. I think the assumption is that the most common reason to project a point is to line something up with the UI which will also be Y-up. But when I projecting, it is most likely to convert a touch coordinate to world coordinates.
Or in another way of looking at it, everything you do in OpenGL is Y-up so everything's designed to be Y-up or to get you there.
Not saying this is necessarily the best way; just trying to guess at the thought process. It probably wouldn't hurt to submit a PR for another type of project method of you need one, or you could subclass whichever type of camera you're using and add the additional method.

sequencing things in document class Actionscript 3

I just recently switched from doing timeline code to documentclass and I am having some trouble figuring this out...
I am making a choice based game so I have a lot of choices that needs to take place...
in the time line what I did was had each frame with choice. if the user picked a choice it would assign that choice a variable and at the end of the game it would run a switch case to pick out the one with that variable and adds it to the screen...
but as soon as I got to the document class to try to do the same things just using code; I couldn't figure out what to do...
I mean i couldn't operate it the same way, otherwise I would have if loops with in if loops with in if loops and I would have to write down each possibility manually. so I decided to use the bitmap screenshots instead but now I can't figure out...that how do I exactly sequence things inside the document class?...I mean how do I tell it to show me these choice after the previous ones are done? and not have to gointo never ending if loops. with timeline I was able to sequence things using frames but without accessing frames how can I sequence things based on, if a choice is clicked, remove those objects and add new ones but not getting locked within functions of functions? can somebody show me the light by providing a clear example please? I am really new at this and really lost,too...

Dynamic UI window drawing in Flash?

Wasn't sure if this question belongs here, but I'll try. So I'm about to move my project from Director | Shockwave Player (if you ever heard of these) to Flash Player for numerous reasons and while I'm thinking how to better start off I got a question which really made me wonder. To the point.
Currently in Director each game window in the user interface (like small alerts or large windows with lot of elements in them) is drawn upon need - meaning that the actual window's graphical image is being put together from configuration (all sorts of properties like width, height and all elements and their properties) from numerous pieces of graphics (e.g. window background is made from 9 small pieces like the 4 corners, 4 middle pieces between corners for dynamic width and height and 1 central piece to fill the window) and then added to stage. This approach makes it easy to edit each graphical element without having to redraw the actual windows and everything in them if we would like to change the color scheme or improve something in a element. It also saves the resources as windows are being drawn only when requested.
Now I got to figure out if it's worth writing such code in Flash too as opposite to just creating all the windows and placing them in the library and adding to stage when they are requested. What do you think? Is it worth writing such implementation?
IMO, it depends on 1) How comfortable you are with Flash's drawing API / graphics class, and 2) How flexible each window/dialog needs to be.
If it's easier to just throw them together as static objects -- and if they don't necessarily need the flexibility to change dimensions/style much (can you count on one hand how many times they've needed to change since it was originally done in Director many years ago?), it's obviously easier to do this than going through the time/energy to recreate them dynamically, especially if you're not very comfortable with Flash's drawing API.
That said, a lot can be accomplished dynamically with Flash's drawing API, so if you have the time/interest I'd certainly suggest digging in and doing it the "right" way if you want to familiarize yourself with the drawing API.
My method for doing this sort of thing usually goes like this:
Create a separate class that extends Sprite/MovieClip; something like 'Dialog.as'.
Create public init(), show(), and hide() methods, and a private build() method.
init() is called just once upon initialization of your app, and takes some global parameters to hold on to internally (padding, colors, etc).
show() takes an argument of either text (a String), or even a Sprite/MovieClip -- whatever it is you want to show in this dialog. When called (when you want to spawn a window), it uses this -- plus whatever init parameters were originally passed in during init() -- to draw itself, and then unhides itself (tween the .alpha property, or simply set the .visible property).
When you want to close the dialog, make sure to invoke the hide() method, which first hides itself, and then cleans up whatever was created (removing listeners, etc) so that the next time it is called upon it can draw itself fresh.
It might also make sense to pass into this object a reference to the Stage (in the original init() call), so that it can center and size itself accordingly on the stage, and also addChild itself to the top of the display list so that it's always above everything else.
I hope this helps.
If is 2D you can check this:
http://pushbuttonengine.com/
if is 3D you can start here:
http://alternativaplatform.com/en/alternativa3d/
I can suggest you also Unity3D but this is outside of flash
Hope it helps