• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

TheBluMage

Members
  • Content count

    306
  • Joined

  • Last visited

Community Reputation

372 Neutral

About TheBluMage

  • Rank
    Member
  1. I finally figured it out! Or at least I've managed to make it work. Placing the MarshalAs(UnmanagedType.I2) attribute in front of the char in my struct makes it work. My best guess is that it was getting marshaled as though it was an ANSI char, one byte long. Previously, I had assumed that it would be marshaled as a wchar, since the default behavior for strings is to use that type of character, but I guess I was mistaken. (I'm still somewhat confused as to why I could pass the struct as input and have it work okay, but not have it return from the function, but I guess it doesn't really matter.)
  2. Tried specifying the size and the other calling convention, but neither resolves the problem. And, yes, the returned ulong contains all the correct data and can be converted to an SValue like so: SValue v = *((SValue*) &returnedLong); I just wish this ugly cast wasn't needed and I can't come up with any reason why it is. Anyway, thanks for trying. :(
  3. I suspected this might be the case, but if that were so, casting the ulong to the struct wouldn't work. I've also used the function in C and the documented signature is correct.
  4. I seem to run into all the weird problems. Anyway, I'll cut to the chase. Here's the C struct that the function is supposed to return: struct AVS_Value { short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong // for some function e'rror short array_size; union { void * clip; // do not use directly, use avs_take_clip char boolean; int integer; float floating_pt; const char * string; const AVS_Value * array; } d; }; And here's the signature of the function that returns it: AVSC_API(AVS_Value) avs_invoke(AVS_ScriptEnvironment *, const char * name, AVS_Value args, const char** arg_names); AVSC_API basically just says that the function using the stdcall convention and that it's a dllexport function. Here's my C# translation of the C struct: [StructLayout(LayoutKind.Explicit)] public struct SValue { [FieldOffset(0)] public char Type; [FieldOffset(2)] public short ArrayLength; [FieldOffset(4)] public IntPtr Data; [FieldOffset(4)] public int Integer; [FieldOffset(4)] public float Float; } When the pointer is used I do all the translations manually, since you can't have a string in the same place as a value type. Anyway, that works fine. Finally, here's the imported DLL function: [DllImport("avisynth.dll", EntryPoint = "avs_invoke", CallingConvention = CallingConvention.StdCall)] public static extern SValue _Invoke(IntPtr env, [MarshalAs(UnmanagedType.LPStr)] string name, SValue args, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] argNames); The problem is, calling this function in my program makes the application crash. (No exception, it just crashes. "AppName.exe has encountered a problem and needs to close... yada yada yada.") But, I can make it work if I have the imported function return a ulong (which is an 8-byte value type, just like my struct) instead of an SValue, like so: [DllImport("avisynth.dll", EntryPoint = "avs_invoke", CallingConvention = CallingConvention.StdCall)] public static extern ulong _Invoke(IntPtr env, [MarshalAs(UnmanagedType.LPStr)] string name, SValue args, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] argNames); When I do this, the function call executes just fine and it behaves just the way it's supposed to. I can cast the returned ulong to an SVideo and it works fine. But... why is there a problem returning a struct from the function?
  5. This is really weird. I created a sorta dummy program that just sends blank frames to stdout and prints some information to stderr. It works fine in my front-end and I can read the info from stderr. So, I went back to Avs2YUV. When I run it from the console, redirecting nothing, I always see the information from stderr and stdout. However, when I redirect stderr to a file, sometimes it works and sometimes I get a blank file. It seems that the current directory has something to do with it. If the current directory is on the C: drive and I redirect stderr to a file on the C: drive, it works. Likewise, if the current directory is on the G: drive and I redirect stderr to a file on the G: drive, it works. But, if the current directory is on the G: drive and I redirect stderr to a file on the C: drive, or vice versa, I get a blank file! My dummy program doesn't exhibit the same behavior. (It works no matter what.) I'm lost, and this doesn't really seem like a Java problem anymore; I don't know what kind of problem this is.
  6. Yeah, I know the name is wrong, but I was torn between naming an OutputStream stdin and using the proper term. That, and I'm a tad dyslexic. :P The getFrame method works fine - I don't know if I made that clear or not, but I can get video frames just fine, since they come from stdout. I also tried reading from stderr in the same thread (just using reader.run() instead of reader.start()) but still got nothing. Later this evening I'll write up a quick app in C to spit some data out of stdout and stderr and see if I can get my front-end to read it.
  7. Howdy, long time no see! I've been working on a front end for Avs2YUV, designed to detect and mark certain scene changes in video. The video stream is sent out of Avs2YUV via the stdout stream, and my program reads the data and decides what to do with it, which is all well and good. The problem is, I can't read anything from stderr, which is where the information about the video (particularly what I need is the video's length in frames) gets sent. I know from running Avs2YUV in the console that it does send that information to stderr - I can redirect it to a file if I like, but nothing shows up at my program's end of the stream. Here's the relevant code: import java.io.*; public class Avs2YuvSession { //Path to Avs2YUV public static String AVS2YUV_PATH = ...; private Thread reader; private InputStream stderr; private OutputStreamWriter stdout; private Process proc; private Yuv4Mpeg2Stream video; public Avs2YuvSession(String scriptPath) throws IOException, Yuv4Mpeg2StreamException { //Start Avs2YUV proc = Runtime.getRuntime().exec(new String[] {AVS2YUV_PATH, "-slave", scriptPath, "-o", "-"}); stderr = new BufferedInputStream(proc.getErrorStream()); stdout = new OutputStreamWriter(proc.getOutputStream(), "US-ASCII"); //Starts a thread that *should* print info from stderr, but never prints anything (see StderrReader class below) reader = new StderrReader(); reader.start(); //Wraps stdout from Avs2YUV in a YUV4MPEG stream parser video = new Yuv4Mpeg2Stream(new BufferedInputStream(proc.getInputStream())); } //Sends a frame number to Avs2YUV and puts the returned frame into the given buffer public synchronized void getFrame(int frame, I420Frame buffer) throws IOException, Yuv4Mpeg2StreamException { stdout.write(Integer.toString(frame)); stdout.write('\n'); stdout.flush(); video.readFrame(buffer); } //Creates a buffer that can store a video frame public I420Frame createFrameBuffer() { return video.createFrameBuffer(); } //Closes stdin and stdout public void close() { try { stdout.close(); } catch(Exception e) {} try { video.close(); } catch(Exception e) {} } //This class extends thread and just reads the stderr stream and prints its output private class StderrReader extends Thread { public void run() { try { //I should be getting the information from stderr printed out here, but no such luck int ch; for(;;) { //If end-of-stream was reached, clean things up and return if((ch = stderr.read()) < 0) { System.out.println("End of stream"); try { stderr.close(); } catch(Exception e) {} return; } //Print the character read from stderr System.out.print((char) ch); } } catch(Exception e) { //If there was an exception reading stderr System.out.println("UH-OH!!! :P"); try { stderr.close(); } catch(Exception ex) {} } } } } I don't think the parser (Yuv4Mpeg2Stream) is relevant, since it just operates on the given stream (stdout), but if you like I can post its code. Any idea why stderr produces output when running Avs2YUV from the console, but doesn't spit out a single char when run from a Java program with exactly the same parameters?
  8. Wow I wasn't even aware there were patches for dual-core processors. As far as I can tell, that fixed the problem! I can't thank you enough for pointing them out! Sorry this ended up not being much of a programming question.
  9. Yep, no effect on the problem.
  10. I have a wavetable software synthesizer (Yamaha S-YXG50) that I've been using for the past several years on a PC I bought back in '02. A few months ago I built myself a new PC, but the synthesizer driver does not work properly on it (polyphony will drop to 0 every couple seconds, causing instruments to cut out before they should). I found that the problem seems to be linked to my having a dual-core processor, as rebooting Windows with one of the cores disabled allowed the driver to function correctly. The driver has a throttler that automatically reduces polyphony when CPU usage gets too high and my guess (and it is just a guess, so if you have a better one, I'm all ears) is that the driver does not accurately read CPU usage when there are multiple processors. I lack the expertise to test this theory though. :) Anyway, that's where I need help; is there any way to intercept whatever method the driver uses to determine CPU usage and return my own values (just force the driver to think the CPU is idle)? I don't have a whole lot of Windows programming experience, so I'm not sure if this is doable or not, but I'd love to have use of the (now discontinued and unsupported, of course) synthesizer again. So if you guys can point me in the right direction (or let me know that this isn't possible if it's not) I'd be most grateful!
  11. Well I kinda combined your ideas. (My real classes were a bit more complicated than the examples I posted.) The constructor in the base class would normally throw a NoSuchAlgorithmException (if someone extending the class messed up their input, that is) but I decided to catch it and rethrow it as an IllegalArgumentException, which won't require the throws clause since it's a runtime exception. Thanks for the help!
  12. I've been out of practice in Java for a little while, so this should be easy to answer (I hope). I'm trying to extend an abstract class that has no parameter-less constructor and all its other constructors can throw exceptions. I want to (well, I have to) call one of the constructors that can throw exceptions, but I want to catch the exception (which should never occur given the arguments I give the super constructor) in my constructor rather than have my class's constructor throw them. But when I wrap the call to super in a try block the compiler complains since the call to super isn't the very first statement. Is there any way to get around this? Basic example: //BaseClass.java: public abstract class BaseClass { protected BaseClass(String someData) throws IckyDataException { //Do constructor stuff and throw an exception if data is bad } } //MyClass.java: public class MyClass extends BaseClass { public MyClass() { //Compiler complains here because there's no parameter-less constructor in BaseClass try { super("Good data"); //Compiler complains here because super is not the first statement } catch(IckyDataException e) {} //Can't happen given "Good data" } } So is there any way, other than changing BaseClass, to avoid adding throws IckyDataException to the constructor in MyClass?
  13. If the property is just a simple field accessor, it should automatically get inlined and there should be no performance penalty.
  14. Yes, the get/set RGB methods are terribly slow for frequent changes to image data. Manually change the buffer data as Lotuspec suggested.