TweetFollow Us on Twitter

Oct 94 Tips
Volume Number:10
Issue Number:10
Column Tag:Tips &Tidbits

Related Info: Color Quickdraw

Tips &Tidbits

By Scott T Boyd, Editor

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Tip Of The Month

Faster Color

RGBForeColor and RGBBackColor can take a surprising amount of time, especially if your main drawing loop calls both routines before most drawing operations. Even if you call RGBForeColor with the color that’s currently foremost, it still recalculates the best possible foreground color! By remembering the results of RGBForeColor and RGBBackColor, you can significantly increase your drawing speed; this example program shows a drawing speed increase of 20%!

The program is written to be pasted into a brand new Think C Project; no MacTraps library is required here. It dumps you into MacsBug at the end with location $40 holding the unoptimized time and $44 holding the optimized time. You can use locations $40 through $5B, inclusive, for debugging purposes.


/* 1 */
#include <QuickDraw.h>
#include <Windows.h>
#include <Palettes.h>
#include <Events.h>

void main(void) {
    CWindowRecord   cwr;
    WindowPtr       wp;
    Rect            bounds = {100, 50, 100 + 256, 50 + 100};
    RGBColor        theColor;
    unsigned short  i, lp;
    unsigned short  start, stop, inc;
    long            startT, stopT;
    long            ColorIndex[1000];
    short           optimized;

    InitGraf( NewPtr(2000) + 1000);
    InitCursor();
    InitFonts();
    InitWindows();
    InitMenus();
    TEInit();
    InitDialogs(0);

    wp = NewCWindow(&cwr,&bounds,"\pFill",TRUE,zoomDocProc,0,TRUE,237);
    SetPort(wp);
    OffsetRect(&bounds, -bounds.left, -bounds.top);

    for (optimized = 0; optimized <= 1; optimized++) {
        startT = TickCount();
    
        if (optimized) {
            for (i = 0; i < 256 * 255; i += 256) {
                theColor.red = i;
                theColor.green = i;
                theColor.blue = i;
                RGBForeColor(&theColor);
                ColorIndex[i >> 8] = cwr.port.fgColor;
            }
        } 
        PenPat((Pattern *)"\xF0\xF0\xF0\xF0\xF0\xF0\xF0\xF0");
        for (lp = 0; lp < 99; lp++) {
            MoveTo(0, 0);
            if (lp & 1) {
                start = 0;
                inc = 256;
                stop = 256 * 255;
            } else {
                stop = 0;
                start = 256 * 255;
                inc = -256;
            }
            for (i = start; i != stop; i += inc) {
                if (!optimized) {
                    theColor.red = theColor.green 
 = theColor.blue 
 = i;
                    RGBForeColor(&theColor);
                    theColor.red   = theColor.green 
 = theColor.blue 
 = 65536 - 256 - i;
                    RGBBackColor(&theColor);
                } else {
                    cwr.port.rgbFgColor.red 
 = cwr.port.rgbFgColor.green 
 = cwr.port.rgbFgColor.blue 
 = i;
                    cwr.port.fgColor =
                        ColorIndex[cwr.port.rgbFgColor.red >> 8];
                    cwr.port.rgbBkColor.red 
 = cwr.port.rgbBkColor.green 
 = cwr.port.rgbBkColor.blue 
 = 65536 - 256 - i;
                    cwr.port.bkColor =
                        ColorIndex[cwr.port.rgbBkColor.red >> 8];
                }
                Line(100, 0);
                Move(-100, 1);
            }
        }
        stopT = TickCount();
        if (!optimized) {
            *(long *)0x40 = stopT - startT;
        } else {
            *(long *)0x44 = stopT - startT;
        }
    }
    DebugStr("\p;dm 40");
    CloseWindow(wp);
}

- Jörg ‘jbx’ Brown

San Francisco, CA

Got a developer tip you’ve been keeping to yourself but really need to share? Think you have a better trick up your sleeve? Send us your tips and tricks, especially programming-related tips, but don’t hold back if you’ve got programmer’s user tips.

We want your tips! We pay $25 for every tip used, and $50 for Tip of the Month. You can take your award in orders or subscriptions if you prefer.

Make sure code compiles, and send tips by e-mail. See page two for our addresses.

Not Such A Drag After All

The drag manager is really cool and can make apps a lot more intuitive, but it’s a pain to debug since process switches are disabled while drags occur. Since both Think C’s and Metrowerks’ debugger require these, you cannot use them. Never fear! You can use The Debugger!

While we’re on the subject, here’s a gotcha for you. Watch out for a bug that causes deadlock if you call WaitNextevent from a drag receive handler.

- Rod Magnuson,

Cupertino, CA

Going Faster with Symantec TPM

Symantec C++, both versions 6.0 and 7.0, do not have the compilers as part of Think Project Manager. Instead, they are kept as quasi-standalone applications inside the Translators folder (located in the Symantec C++ folder). This goes for the C, C++, and rez compilers, as well as the .o converter. When the user tells Think Project Manager to compile a file, TPM looks at the file’s extension (such as .cp for a C++ file), and launches the appropriate compiler (or translator, as Symantec calls them). This is documented in the Symantec manuals.

What isn’t documented, however, is the process by which TPM launches the translators. As it is shipped from the factory, when TPM is launched, it turns around and launches the C++ translator and keeps it in memory. The C translator is left on the disk, and called when necessary. This works great if you do most of your work in C++. But if you’re like me, and work mostly in C, this slows down the compilation process because every time a C file is to be compiled, the C translator must launched and loaded into memory, while the C++ translator sits there in memory with nothing to do.

What’s a C user to do? Simply modify the C and C++ translators to work the way you want them to. Using ResEdit (or resource editor of your choice), open ‘INFO’ resource number 0 in the translator named Think C (Symantec graciously includes a ResEdit template for this). Change the setting of Memory Resident Translator? from 0 to 1. Close and save your changes. Voila! The C translator will now be loaded and kept in memory by TPM when it is launched. In one simple step, C compiles are now speeded up. The more files that are being compiled, the greater the speed increase. For instance, a one-file compile is not speeded up much, but if you’re working with large projects, the speed increase can be significant.

If you want to free up some memory, you can also modify the C++ translator (named Symantec C++) to not be memory resident.

- Chris Hawk

San Francisco, CA

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »

Price Scanner via MacPrices.net

Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more
Every version of Apple Pencil is on sale toda...
Best Buy has all Apple Pencils on sale today for $79, ranging up to 39% off MSRP for some models. Sale prices for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.