Ejemplo n.º 1
0
        public virtual void readValue(Reader reader)
        {
            EntrySize currentSize   = getEntrySize();
            int       currentOffset = getOffset();

            switch (currentSize)
            {
            case EntrySize._8Bits:
                break;

            case EntrySize._16Bits:
                this.value = parseValue((ushort)reader.readInt16(currentOffset));
                break;

            case EntrySize._32Bits:
                this.value = parseValue(reader.readInt32(currentOffset));
                break;

            case EntrySize._64Bits:
                // NOTHING NOW
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
 public FormGroupContext(IHtmlString contents, string additionalCssClasses = null, EntrySize displayWidth = EntrySize.Full, IDictionary <string, object> htmlAttributes = null)
 {
     Contents             = contents;
     AdditionalCssClasses = additionalCssClasses;
     DisplayWidth         = displayWidth;
     HtmlAttributes       = htmlAttributes;
 }
Ejemplo n.º 3
0
 public DataEntry(List <Entry> list,
                  bool is32bit,
                  string name,
                  int offset,
                  int count,
                  EntrySize size) : base(list, is32bit, name, offset, size)
 {
     this.count = count;
 }
Ejemplo n.º 4
0
        public override void readValue(Reader reader)
        {
            EntrySize currentSize   = getEntrySize();
            int       currentOffset = getOffset();

            // init the right buffer
            switch (currentSize)
            {
            case EntrySize._8Bits:
                this.values8 = new byte[this.count];
                break;

            case EntrySize._16Bits:
                this.values16 = new Int16[this.count];
                break;

            case EntrySize._32Bits:
                this.values32 = new Int32[this.count];
                break;

            case EntrySize._64Bits:
                this.values64 = new long[this.count];
                break;

            default:
                break;
            }

            for (int i = 0; i < this.count; i++)
            {
                switch (currentSize)
                {
                case EntrySize._8Bits:
                    this.values8[i] = reader.readByte(currentOffset + i);
                    break;

                case EntrySize._16Bits:
                    this.values16[i] = reader.readInt16(currentOffset + (i * ((int)currentSize / 8)));
                    break;

                case EntrySize._32Bits:
                    this.values32[i] = reader.readInt32(currentOffset + (i * ((int)currentSize / 8)));
                    break;

                case EntrySize._64Bits:
                    this.values64[i] = reader.readInt64(currentOffset + (i * ((int)currentSize / 8)));
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a standard form entry field with validation.
        /// </summary>
        /// <typeparam name="TModel">The type of the model containing the field or property to create the entry for.</typeparam>
        /// <typeparam name="TValue">The type of the field or property to create the entry for.</typeparam>
        /// <param name="htmlHelper">An HtmlHelper that will be used to construct the enty components.</param>
        /// <param name="expression">An expression that selects the field or property on the model to create the entry for.</param>
        /// <param name="@class">One or more CSS class names to add to the form group wrapper.</param>
        /// <param name="labelClass">One or more CSS class names to add to the label.</param>
        /// <param name="whatsThisClass">One or more CSS class names to add to the what's this.</param>
        /// <param name="whatsThisOverride">String value that, if !null, will be used in place of the field what's this Data Attribute.</param>
        /// <param name="editorClass">One or more CSS class names to add to the editor.</param>
        /// <param name="validationMessageClass">One or more CSS class names to add to the validation message.</param>
        /// <param name="feedbackClass">One or more CSS class names to add to the validation feedback.</param>
        /// <param name="descriptionClass">One or more CSS class names to add to the field description.</param>
        /// <param name="descriptionOverride">String value that, if !null, will be used in place of the field description Data Attribute.</param>
        public static IHtmlString EditorEntryFor <TModel, TValue>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TValue> > expression,
            string @class                 = null,
            string labelClass             = null,
            string whatsThisClass         = null,
            string whatsThisOverride      = null,
            string editorClass            = null,
            string validationMessageClass = null,
            string feedbackClass          = null,
            string descriptionClass       = null,
            string descriptionOverride    = null,
            EntrySize displayWidth        = EntrySize.Full,
            IDictionary <string, object> editorHtmlAttributes = null)
        {
            var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            if (typeof(bool).IsAssignableFrom(metaData.ModelType))
            {
                return(CheckboxEditor(
                           htmlHelper,
                           expression,
                           @class,
                           labelClass,
                           whatsThisClass,
                           whatsThisOverride,
                           editorClass,
                           validationMessageClass,
                           feedbackClass,
                           descriptionClass,
                           descriptionOverride,
                           editorHtmlAttributes));
            }

            return(StandardEditor(
                       htmlHelper,
                       expression,
                       @class,
                       labelClass,
                       whatsThisClass,
                       whatsThisOverride,
                       editorClass,
                       validationMessageClass,
                       feedbackClass,
                       descriptionClass,
                       descriptionOverride,
                       displayWidth,
                       editorHtmlAttributes));
        }
Ejemplo n.º 6
0
        public TypeEntry(List <Entry> list, bool is32bit, string name, int offset, EntrySize size32, EntrySize size64)
        {
            this.name = name;

            this.is32bit = is32bit;

            if (list == null)
            {
                this.offset = offset;
            }
            else
            {
                if (list.Count < 1)
                {
                    this.offset = offset;
                }

                // insure conditions check order
                else
                {
                    Entry lastEntry = ((Entry)list[list.Count - 1]);

                    if (lastEntry.GetType().Equals(typeof(DataEntry)))
                    {
                        DataEntry lastEntryData = (DataEntry)lastEntry;

                        this.offset = lastEntryData.getOffset() + lastEntryData.getSize();
                    }
                    else
                    {
                        this.offset = lastEntry.getOffset() + ((int)lastEntry.getSize() / 8);
                    }
                }

                list.Add(this);
            }

            this.size   = size32;
            this.size64 = size64;

            this.changeFor64 = true;
        }
Ejemplo n.º 7
0
        public static List <Primitive> ExtractPrimitives(MDL0Polygon *polygon)
        {
            List <Primitive> list = new List <Primitive>();

            VoidPtr dataAddr = polygon->PrimitiveData;
            //ElementFlags e = new ElementFlags(polygon->_elemFlags, polygon->_texFlags);
            EntrySize e = new EntrySize(polygon->_vertexFormat);

            int nodeIndex = 0;

            ushort[]  nodeBuffer = new ushort[16];
            Primitive p;

            while ((p = ExtractPrimitive(ref dataAddr, e, nodeBuffer, ref nodeIndex)) != null)
            {
                list.Add(p);
            }

            return(list);
        }
Ejemplo n.º 8
0
        public StructEntry(List <Entry> list, bool is32bit, string name, int offset, EntrySize size)
        {
            this.name = name;

            this.is32bit = is32bit;

            if (list.Count < 1)
            {
                this.offset = offset;
            }
            else
            {
                Entry lastEntry = list[list.Count - 1];
                this.offset = lastEntry.getOffset() + ((int)lastEntry.getSize() / 8);
            }

            this.size = size;

            list.Add(this);
        }
Ejemplo n.º 9
0
        string GetSizeClass(EntrySize displayWidth)
        {
            if (displayWidth == EntrySize.ExtraSmall)
            {
                return("form-group-xsmall");
            }

            if (displayWidth == EntrySize.Small)
            {
                return("form-group-small");
            }

            if (displayWidth == EntrySize.Medium)
            {
                return("form-group-medium");
            }

            if (displayWidth == EntrySize.Large)
            {
                return("form-group-large");
            }

            return("form-group-full");
        }
        void GotNewBar(string symbol, int interval)
        {
            // get current barlist for this symbol+interval
            BarList bl = track_barlists[symbol, interval];

            // issue an event (todo: should I put this functionality into MessageResponseTemplate.cs? or should I get rid of GotNewBar at all? hmm...) will stay here for a while..
            BsonDocument bson_doc = new BsonDocument();

            bson_doc             = new BsonDocument();
            bson_doc["Symbol"]   = bl.RecentBar.Symbol;
            bson_doc["High"]     = bl.RecentBar.High.ToString();
            bson_doc["Low"]      = bl.RecentBar.Low.ToString();
            bson_doc["Open"]     = bl.RecentBar.Open.ToString();
            bson_doc["Close"]    = bl.RecentBar.Close.ToString();
            bson_doc["Volume"]   = bl.RecentBar.Volume.ToString();
            bson_doc["isNew"]    = bl.RecentBar.isNew;
            bson_doc["Bartime"]  = bl.RecentBar.Bartime;
            bson_doc["Bardate"]  = bl.RecentBar.Bardate;
            bson_doc["isValid"]  = bl.RecentBar.isValid;
            bson_doc["Interval"] = bl.RecentBar.Interval;
            bson_doc["time"]     = bl.RecentBar.time;

            //send_event(MimeType.got_new_bar, "bar", bson_doc.ToString());
            log_file.WriteLine("got_new_bar" + bson_doc.ToString());

            // get index for symbol
            int idx = track_symbols.getindex(symbol);

            string dbg_msg = "GotNewBar(" + symbol + ", " + interval + "):";

            // check for first cross on first interval
            if (interval == _response_barsize_s)
            {
                decimal ema = Calc.Avg(Calc.EndSlice(bl.Close(), _ema_bar));

                track_ema[symbol].Add(ema);

                // drawings...
                if (bl.Close().Length > _ema_bar)
                {
                    // draw 2 sma lines:
                    sendchartlabel(ema, time, System.Drawing.Color.FromArgb(0xff, 0x01, 0x01));

                    // do the trade (if required)
                    decimal[] ema_arr = track_ema[symbol].ToArray();

                    decimal prev_ema  = ema_arr[ema_arr.Length - 2];
                    decimal curr_ema  = ema_arr[ema_arr.Length - 1];
                    decimal delta_ema = curr_ema - prev_ema;

                    // sma just crossed?
                    bool should_buy  = track_positions[symbol].isFlat && delta_ema >= 0.002m;
                    bool should_sell = false;

                    dbg_msg += " delta_ema=" + delta_ema.ToString("000.000");

                    /*
                     * dbg_msg += " fast=" + curr_sma_fast.ToString("000.000");
                     * dbg_msg += " pr_slow=" + prev_sma_slow.ToString("000.000");
                     * dbg_msg += " pr_fast=" + prev_sma_fast.ToString("000.000");
                     * dbg_msg += " [" + symbol + "].isFlat=" + track_positions[symbol].isFlat.ToString();
                     * dbg_msg += " track_positions[symbol].ToString=" + track_positions[symbol].ToString();
                     * dbg_msg += " should_buy=" + should_buy.ToString();
                     * dbg_msg += " should_sell=" + should_sell.ToString();
                     */

                    //senddebug("GotNewBar(): " + debug_position_tracker(symbol));

                    if (should_buy)
                    {
                        // come buy some! (c) Duke Nukem
                        string comment = " BuyMarket(" + symbol + ", " + EntrySize.ToString() + ")";
                        sendorder(new BuyMarket(symbol, EntrySize, comment));
                        log_file.WriteLine("close position: " + comment);
                        dbg_msg += comment;
                    }

                    if (false)                                              // we do all the selling on tick()
                    {
                        if (!track_positions[symbol].isFlat && should_sell) // we don't short, so also check if !flat
                        //if ( should_sell) // we don't short, so also check if !flat
                        {
                            sendorder(new SellMarket(symbol, EntrySize));
                            dbg_msg += " SellMarket(" + symbol + ", " + EntrySize.ToString() + ")";
                        }
                    }
                }
            }
            //else
            //{
            //    //
            //    dbg_msg += "GotNewBar() other interval=" + interval;
            //}

            // spit out one dbg message line per bar
            D(dbg_msg);

            // nice way to notify of current tracker values
            sendindicators(gt.GetIndicatorValues(idx, gens()));
            return;
        }
Ejemplo n.º 11
0
 public StructEntry(string name, int offset, EntrySize size)
 {
     this.name   = name;
     this.offset = offset;
     this.size   = size;
 }
        void GotNewBar(string symbol, int interval)
        {
            //if (symbol.ToUpper() != "ABX") return;

            // get current barlist for this symbol+interval
            BarList bl = track_barlists[symbol, interval];

            // get index for symbol
            int idx = track_symbols.getindex(symbol);

            string dbg_msg = "GotNewBar(" + symbol + ", " + interval + "):";

            // check for first cross on first interval
            if (interval == (int)BarInterval.Minute)
            {
                decimal no_tracker_slow_ma = Calc.Avg(Calc.EndSlice(bl.Close(), _slow_ma_bar));
                decimal no_tracker_fast_ma = Calc.Avg(Calc.EndSlice(bl.Close(), _fast_ma_bar));

                track_sma_slow[symbol].Add(no_tracker_slow_ma);
                track_sma_fast[symbol].Add(no_tracker_fast_ma);

                // drawings...
                if (bl.Close().Length > 1)
                {
                    // this is how we draw line, which connects all bars close.
                    //decimal val = bl.Close()[bl.Close().Length - 2]; // length-1 would be last, so length-2 is our previus bar
                    //int time_prev = bl.Time()[bl.Time().Length - 2];
                    //sendchartlabel(val, time_prev, System.Drawing.Color.Green);

                    // draw 2 sma lines:
                    sendchartlabel(no_tracker_slow_ma, time, System.Drawing.Color.Blue);
                    sendchartlabel(no_tracker_fast_ma, time, System.Drawing.Color.FromArgb(0xff, 0x01, 0x01)); // wtf? why red line multiplies after each sell order?!

                    //sendchartlabel(bl.Close()[bl.Close().Length - 2],
                    //    time,
                    //    (time - 60).ToString(),
                    //    System.Drawing.Color.Green);

                    // do the trade (if required)
                    decimal[] sma_slow = track_sma_slow[symbol].ToArray();
                    decimal[] sma_fast = track_sma_fast[symbol].ToArray();

                    decimal prev_sma_slow = sma_slow[sma_slow.Length - 2];
                    decimal prev_sma_fast = sma_fast[sma_fast.Length - 2];

                    decimal curr_sma_slow = sma_slow[sma_slow.Length - 1]; // imho quite ugly..
                    decimal curr_sma_fast = sma_fast[sma_fast.Length - 1]; // todo: read more on how to work with Lists

                    // sma just crossed?
                    bool should_buy = prev_sma_slow > prev_sma_fast && curr_sma_slow < curr_sma_fast;
                    bool should_sell = prev_sma_slow <prev_sma_fast && curr_sma_slow> curr_sma_fast;

                    dbg_msg += " slow=" + curr_sma_slow.ToString("000.000");
                    dbg_msg += " fast=" + curr_sma_fast.ToString("000.000");
                    dbg_msg += " pr_slow=" + prev_sma_slow.ToString("000.000");
                    dbg_msg += " pr_fast=" + prev_sma_fast.ToString("000.000");
                    dbg_msg += " [" + symbol + "].isFlat=" + track_positions[symbol].isFlat.ToString();
                    dbg_msg += " track_positions[symbol].ToString=" + track_positions[symbol].ToString();
                    dbg_msg += " should_buy=" + should_buy.ToString();
                    dbg_msg += " should_sell=" + should_sell.ToString();

                    //senddebug("GotNewBar(): " + debug_position_tracker(symbol));

                    if (should_buy)
                    {
                        // come buy some! (c) Duke Nukem
                        sendorder(new BuyMarket(symbol, EntrySize));
                        dbg_msg += " BuyMarket(" + symbol + ", " + EntrySize.ToString() + ")";
                    }

                    if (!track_positions[symbol].isFlat && should_sell) // we don't short, so also check if !flat
                    //if ( should_sell) // we don't short, so also check if !flat
                    {
                        sendorder(new SellMarket(symbol, EntrySize));
                        dbg_msg += " SellMarket(" + symbol + ", " + EntrySize.ToString() + ")";
                    }
                }
            }
            //else
            //{
            //    //
            //    dbg_msg += "GotNewBar() other interval=" + interval;
            //}

            // spit out one dbg message line per bar
            //senddebug(dbg_msg);

            // nice way to notify of current tracker values
            sendindicators(gt.GetIndicatorValues(idx, gens()));
            return;
        }
Ejemplo n.º 13
0
 static IHtmlString StandardEditor <TModel, TValue>(
     this HtmlHelper <TModel> htmlHelper,
     Expression <Func <TModel, TValue> > expression,
     string @class                 = null,
     string labelClass             = null,
     string whatsThisClass         = null,
     string whatsThisOverride      = null,
     string editorClass            = null,
     string validationMessageClass = null,
     string feedbackClass          = null,
     string descriptionClass       = null,
     string descriptionOverride    = null,
     EntrySize displayWidth        = EntrySize.Full,
     IDictionary <string, object> editorHtmlAttributes = null)
 {
     return(new FormGroupEntryComponent().Build(
                htmlHelper: htmlHelper,
                expression: expression,
                context: new FormGroupContext(
                    additionalCssClasses: @class,
                    displayWidth: displayWidth,
                    contents: CombineHtmlStrings(
                        new LabelEntryComponent().Build(
                            htmlHelper: htmlHelper,
                            expression: expression,
                            context: new LabelContext(
                                additionalCssClasses: labelClass)),
                        new WhatsThisEntryComponent().Build(
                            htmlHelper: htmlHelper,
                            expression: expression,
                            context: new WhatsThisContext(
                                whatsThisOverride: whatsThisOverride,
                                additionalCssClasses: whatsThisClass)),
                        new WrapperEntryComponent().Build(
                            htmlHelper: htmlHelper,
                            expression: expression,
                            context: new WrapperContext(
                                tag: "div",
                                @class: "entry-feedback-wrapper",
                                contents: CombineHtmlStrings(
                                    new EditorEntryComponent().Build(
                                        htmlHelper: htmlHelper,
                                        expression: expression,
                                        context: new EditorContext(
                                            additionalCssClasses: editorClass,
                                            htmlAttributes: editorHtmlAttributes)),
                                    new FeedbackEntryComponent().Build(
                                        htmlHelper: htmlHelper,
                                        expression: expression,
                                        context: new FeedbackContext(
                                            additionalCssClasses: feedbackClass))))),
                        new ValidationMessageEntryComponent().Build(
                            htmlHelper: htmlHelper,
                            expression: expression,
                            context: new ValidationMessageContext(
                                additionalCssClasses: validationMessageClass)),
                        new DescriptionEntryComponent().Build(
                            htmlHelper: htmlHelper,
                            expression: expression,
                            context: new DescriptionContext(
                                descriptionOverride: descriptionOverride,
                                additionalCssClasses: descriptionClass))))));
 }
Ejemplo n.º 14
0
        void ReleaseDesignerOutlets()
        {
            if (EntryDate != null)
            {
                EntryDate.Dispose();
                EntryDate = null;
            }

            if (EntryPrice != null)
            {
                EntryPrice.Dispose();
                EntryPrice = null;
            }

            if (EntrySetup != null)
            {
                EntrySetup.Dispose();
                EntrySetup = null;
            }

            if (EntrySize != null)
            {
                EntrySize.Dispose();
                EntrySize = null;
            }

            if (EntryType != null)
            {
                EntryType.Dispose();
                EntryType = null;
            }

            if (ExitDate != null)
            {
                ExitDate.Dispose();
                ExitDate = null;
            }

            if (ExitPrice != null)
            {
                ExitPrice.Dispose();
                ExitPrice = null;
            }

            if (Fees != null)
            {
                Fees.Dispose();
                Fees = null;
            }

            if (ProfitLoss != null)
            {
                ProfitLoss.Dispose();
                ProfitLoss = null;
            }

            if (StopLoss != null)
            {
                StopLoss.Dispose();
                StopLoss = null;
            }

            if (TakeProfit != null)
            {
                TakeProfit.Dispose();
                TakeProfit = null;
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns max entry size of legend
        /// </summary>
        /// <returns>EntrySize</returns>
        private EntrySize GetMaxSymbolAndColumnWidth()
        {   
            EntrySize entrySize = new EntrySize();

            foreach (LegendEntry labelAndSymbol in Entries)
            {
                TextBlock t = new TextBlock();
                t.Text = labelAndSymbol.Labels[0];
                ApplyFontProperty(t);
                Size labelSize = TextBlockActualSize(t);
                entrySize.TextSize.Width = (labelSize.Width > entrySize.TextSize.Width) ? labelSize.Width : entrySize.TextSize.Width;
                entrySize.TextSize.Height = (labelSize.Height > entrySize.TextSize.Height) ? labelSize.Height : entrySize.TextSize.Height;
                (labelAndSymbol.Marker as Marker).Margin = EntryMargin;

                (labelAndSymbol.Marker as Marker).CreateVisual();
                entrySize.SymbolSize.Width = ((labelAndSymbol.Marker as Marker).MarkerActualSize.Width > entrySize.SymbolSize.Width) ? (labelAndSymbol.Marker as Marker).MarkerActualSize.Width : entrySize.SymbolSize.Width;
                entrySize.SymbolSize.Height = ((labelAndSymbol.Marker as Marker).MarkerActualSize.Height > entrySize.SymbolSize.Height) ? (labelAndSymbol.Marker as Marker).MarkerActualSize.Height : entrySize.SymbolSize.Height;
            }

            return entrySize;
        }
Ejemplo n.º 16
0
 public DisplayWidthAttribute(EntrySize size)
 {
     Size = size;
 }
Ejemplo n.º 17
0
    public static IEnumerator GetSimpleTemple()
    {
        GenData temple = new GenData(Random.Range(TempleWidth.start, TempleWidth.end), Random.Range(TempleHeight.start, TempleHeight.end));

        List <GenRoom> AutoFillRoom = new List <GenRoom>();

        // list of all rooms that are not allowed to be used for door placement
        List <GenRoom> NoAutoDoor  = new List <GenRoom>();
        List <GenRoom> SecretRooms = new List <GenRoom>();

        GenTile Chest = GenTile.GetEmpty();

        Chest.Details.Add(new GenDetail()
        {
            Char = '=', Type = GenDetail.DetailType.Entity, Entity = GenDetail.EntityType.Chest
        });

        GenTile pillar = GenTile.GetEmpty();

        //pillar.Details.Add(new GenDetail() { Char = '\u01C1', Type = GenDetail.DetailType.Decoration });
        pillar.Details.Add(new GenDetail()
        {
            Char = 'O', Type = GenDetail.DetailType.Decoration
        });

        GenTile[,] pillars = new GenTile[, ]
        {
            { GenTile.Copy(pillar), GenTile.Copy(pillar) },
            { GenTile.Copy(pillar), GenTile.Copy(pillar) }
        };

        GenTile Door = GenTile.GetEmpty();

        Door.Details.Add(new GenDetail()
        {
            Char = '+', Type = GenDetail.DetailType.Door, Entity = GenDetail.EntityType.Door
        });


        GenRoom outer = GenRoom.Sized(temple.Width, temple.Height);

        outer.FillFloor('+');
        outer.SpacePriority = -2;
        temple.PlaceRoom(0, 0, outer);
        temple.EdgeWalls('#', outer);


        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------


        int w = Random.Range(9, 12);
        int h = Random.Range(10, 16);

        // EntryHall
        temple.TryGrowRect(1, outer.Outer.GetCenter().y, w, h, out GenRect EntrySize, false);
        GenRoom EntryHall = GenRoom.At(EntrySize.MinX, EntrySize.MinY, EntrySize.WidthT, EntrySize.HeightT);

        EntryHall.FillFloor('.');
        temple.PlaceRoom(EntrySize.MinX, EntrySize.MinY, EntryHall);
        temple.EdgeWalls('#');
        EntryHall.GetAtWorldspaceG(
            EntrySize.MinX + 1, EntrySize.GetCenter().y)
        .Details
        .Add(new GenDetail()
        {
            Char = '>', Type = GenDetail.DetailType.Entity, Entity = GenDetail.EntityType.StairsDown
        });


        int posX = EntrySize.MinX + 2;
        int posy = EntrySize.MinY + 2;

        GenTile[,] sym = GenUtil.GetSymetry(pillars.GetCopy(), ref posX, ref posy, EntryHall, GenUtil.Axis.Horizontal | GenUtil.Axis.Vertical);

        EntryHall.PlaceDetailsAt(posX, posy, sym);
        temple.FixOverlap();

        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        // hall to big thing
        int whall = Random.Range(10, 25);
        int hhall = Random.Range(5, 7);
        int space = Random.Range(2, 4);

        temple.TryGrowRect(EntrySize.MaxX + 1, EntrySize.GetCenter().y, whall, hhall, out GenRect HallSize);
        GenRoom PillarHall = GenRoom.Sized(HallSize.WidthT, HallSize.HeightT);

        PillarHall.FillFloor('.');
        PillarHall.SpacePriority = 3;
        temple.PlaceRoom(HallSize.MinX, HallSize.MinY, PillarHall);
        temple.EdgeWalls('#', PillarHall);

        NoAutoDoor.Add(PillarHall);

        // place doors to the entry
        if (hhall == 5)
        {
            // a single door in the middle
            PillarHall.AddDetails(HallSize.MinX, HallSize.MinY + 2, GenTile.Copy(Door));
            PillarHall.AddDetails(HallSize.MaxX, HallSize.MinY + 2, GenTile.Copy(Door));
        }
        else
        {
            // place symetric doors
            PillarHall.AddDetails(HallSize.MinX, HallSize.MinY + 2, GenTile.Copy(Door));
            PillarHall.AddDetails(HallSize.MinX, HallSize.MinY + 3, GenTile.Copy(Door));

            PillarHall.AddDetails(HallSize.MaxX, HallSize.MinY + 2, GenTile.Copy(Door));
            PillarHall.AddDetails(HallSize.MaxX, HallSize.MinY + 3, GenTile.Copy(Door));
        }

        int currBar = HallSize.MinX + space;

        GenTile[,] singlePillar = new GenTile[, ] {
            { GenTile.Copy(pillar) }
        };
        while (temple.IsInsideRoom(currBar, HallSize.MinY + 1, PillarHall))
        {
            int fx = currBar;
            int fy = HallSize.MinY + 1;
            GenTile[,] feature = GenUtil.GetSymetry(singlePillar, ref fx, ref fy, PillarHall, GenUtil.Axis.Vertical);
            PillarHall.PlaceDetailsAt(fx, fy, feature);
            currBar += space;
        }
        temple.FixOverlap();

        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        // holy water or something

        int waterHeight      = Random.Range(2, 4);
        int waterWidth       = Random.Range(2, 4);
        int waterPillarWidth = Random.Range(2, 3);

        int waterRoomHeight = waterHeight + 4 + waterPillarWidth * 2;
        int waterRoomWidth  = waterWidth + 6 + waterPillarWidth * 2;

        temple.TryGrowRect(HallSize.MaxX + 1, HallSize.GetCenter().y, waterRoomWidth, waterRoomHeight, out GenRect WaterSize, false, GenUtil.Direction4.Top);

        GenRoom waterRoom = GenRoom.Sized(WaterSize.WidthT, WaterSize.HeightT);

        waterRoom.FillFloor();
        waterRoom.SpacePriority = 2;
        temple.PlaceRoom(WaterSize.MinX, WaterSize.MinY, waterRoom);
        temple.EdgeWalls('#', waterRoom);


        int BackDoorWater = Random.Range(1, waterRoom.Height / 2);

        waterRoom.AddDetails(WaterSize.MaxX, WaterSize.MinY + BackDoorWater, GenTile.Copy(Door));
        waterRoom.AddDetails(WaterSize.MaxX, WaterSize.MaxY - BackDoorWater, GenTile.Copy(Door));


        GenTile waterSingle = GenTile.GetEmpty();

        waterSingle.Details.Add(new GenDetail()
        {
            Char = '~', Type = GenDetail.DetailType.Background
        });
        GenTile[,] water = GenUtil.Fill(waterWidth, waterHeight, waterSingle);

        waterRoom.PlaceDetailsAt(WaterSize.MinX + 3 + waterPillarWidth, WaterSize.MinY + 2 + waterPillarWidth, water);

        int waterPX = WaterSize.MinX + 3;
        int waterPY = WaterSize.MinY + 2;

        GenTile[,] waterPillarPlace = GenUtil.GetSymetry(pillars.GetCopy(), ref waterPX, ref waterPY, waterRoom, GenUtil.Axis.Horizontal | GenUtil.Axis.Vertical);
        waterRoom.PlaceDetailsAt(waterPX, waterPY, waterPillarPlace);


        temple.FixOverlap();

        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        // pillar spam
        int spamWidth  = Random.Range(10, 20);
        int spamHeight = WaterSize.HeightT + Random.Range(8, 15);

        temple.TryGrowRect(WaterSize.MaxX + 1, WaterSize.GetCenter().y, spamWidth, spamHeight, out GenRect SpamSize, true, GenUtil.Direction4.Top);
        GenRoom Spam = GenRoom.Sized(SpamSize.WidthT, SpamSize.HeightT);

        Spam.FillFloor();
        Spam.SpacePriority = 1;
        temple.PlaceRoom(SpamSize.MinX, SpamSize.MinY, Spam);
        temple.EdgeWalls('#', Spam);

        int spamPX = SpamSize.MinX + 2;
        int spamPY = SpamSize.MinY + 2;

        for (int x = spamPX; temple.IsInsideRoom(x, spamPY, Spam); x += 2)
        {
            for (int y = spamPY; temple.IsInsideRoom(x, y, Spam); y += 2)
            {
                GenTile p = GenTile.Copy(pillar);
                Spam.AddDetails(x, y, p);
            }
        }
        Spam.AddDetail(
            SpamSize.MaxX - 1,
            SpamSize.GetCenter().y,
            new GenDetail()
        {
            Char = '<', Type = GenDetail.DetailType.Entity, Entity = GenDetail.EntityType.StairsUp
        });

        temple.FixOverlap();

        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        //temple.Rooms.Remove(outer); // we dont have boundries
        for (int x = outer.Inner.MinX; x < outer.Outer.MaxX; x++)
        {
            for (int y = outer.Inner.MinY; y < outer.Outer.MaxY; y++)
            {
                outer.RemoveTileAtG(x, y);
            }
        }


        //GenRoom Mark = GenRoom.Sized(0, 0);
        //Mark.FillFloor('X');
        //Mark.SpacePriority = 100;


        // lets go ham with randomly sized rooms
        int spawnAttemptsRemaining = 1000;

        while (spawnAttemptsRemaining-- > 0)// lol the arrow
        {
            int rWidth  = Random.Range(RandomWidth.start, RandomWidth.end);
            int rHeight = Random.Range(RandomHeight.start, RandomHeight.end);

            int     rX        = Random.Range(2, temple.Width - 2);
            int     rY        = Random.Range(2, temple.Height - 2);
            GenRect rHopeSize = new GenRect(rX, rX + rWidth + 1, rY, rY + rWidth - 1);


            if (temple.IsInsideRoom(rX, rY) || temple.GetTile(rX, rY) != null)
            {
                continue;
            }

            temple.TryGrowRect(rX, rY, rWidth, rHeight, out GenRect rSize, true);

            GenRoom add = GenRoom.Sized(rSize.WidthT, rSize.HeightT);
            add.FillFloor();
            add.SpacePriority = 01;

            temple.PlaceRoom(rSize.MinX, rSize.MinY, add);

            AutoFillRoom.Add(add);

            temple.EdgeWalls('#', add);

            temple.FixOverlap();

            /*
             * if (rWidth * 2 < rHeight || rHeight * 2 < rWidth)
             * {
             *  if (Random.Range(0,10)>4)
             *  {
             *      // we are making a hallway
             *
             *      //TODO: hallway
             *
             *      temple.PlaceRoom(rX, rY, Mark);
             *      Log(temple);
             *      if (Logging!=null)
             *  {
             *      yield return new WaitForSeconds(0.25f);
             *  }
             *      temple.Rooms.Remove(Mark);
             *      continue;
             *  }
             * }
             */

            /*
             * int randomChance = Random.Range(0, 4);
             * switch (randomChance)
             * {
             *  case 0:
             *      // random pillars in the room
             *
             *      for (int i = 0; i < 7 + (rSize.WidthT + rSize.HeightT)/5; i++)
             *      {
             *          int px = Random.Range(rSize.MinX + 1, rSize.MaxX);
             *          int py = Random.Range(rSize.MinY + 1, rSize.MaxY);
             *          add.AddDetails(px, py, pillar);
             *      }
             *
             *      break;
             *  case 1:
             *      // random water
             *      for (int i = 0; i < 15 + (rSize.WidthT + rSize.HeightT)/3; i++)
             *      {
             *          int px = Random.Range(rSize.MinX + 1, rSize.MaxX);
             *          int py = Random.Range(rSize.MinY + 1, rSize.MaxY);
             *          GenDetail littleWater= new GenDetail() { Char = '~', Type = GenDetail.DetailType.Background};
             *          add.AddDetail(px, py, littleWater);
             *      }
             *      break;
             *  case 2:
             *      // random room inside if possible else empty
             *      if (rSize.WidthT>=7&& rSize.HeightT >= 7)
             *      {
             *          int insideX = rSize.GetCenter().x;
             *          int insideY = rSize.GetCenter().y;
             *
             *          temple.TryGrowRect(insideX, insideY, 100, 100, out GenRect insideSize, false);
             *          GenRoom inside = GenRoom.Sized(insideSize.WidthT, insideSize.HeightT);
             *          inside.FillFloor();
             *          inside.SpacePriority = 2;
             *          temple.PlaceRoom(insideSize.MinX, insideSize.MinY, inside);
             *          temple.EdgeWalls('#',inside);
             *          temple.FixOverlap();
             *
             *      }
             *      else
             *      {
             *          for (int i = 0; i < 7; i++)
             *          {
             *              int px = Random.Range(rSize.MinX + 1, rSize.MaxX);
             *              int py = Random.Range(rSize.MinY + 1, rSize.MaxY);
             *              add.AddDetails(px, py, pillar);
             *          }
             *      }
             *      break;
             *  default:
             *      break;
             * }
             *
             * Log(temple);
             * if (Logging!=null)
             *  {
             *      yield return new WaitForSeconds(0.25f);
             *  }
             */
        }

        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        // now fill the rooms with things

        var adjList = temple.GetAdjacentRoomMap();
        // remove any Room that is too small and have no connections

        List <GenRoom> tooSmall = new List <GenRoom>();

        foreach (var room in temple.Rooms)
        {
            if (room.Width >= 5 && room.Height == 3)
            {
                tooSmall.Add(room);
                continue;
            }
            if (room.Height >= 5 && room.Width == 3)
            {
                tooSmall.Add(room);
                continue;
            }
            if (room.Height <= 3 && room.Width <= 3)
            {
                tooSmall.Add(room);
                continue;
            }
            if (adjList[room].Count == 0)
            {
                tooSmall.Add(room);
                continue;
            }
        }
        foreach (var room in tooSmall)
        {
            temple.Rooms.Remove(room);
        }

        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        List <GenRoom> PotentialSecret = new List <GenRoom>();

        foreach (var room in temple.Rooms)
        {
            if (room.Width + room.Height <= 12)
            {
                PotentialSecret.Add(room);
            }
        }

        Debug.Log("potential " + PotentialSecret.Count + "Secret rooms");

        // 1 room --> 0,1,2,3
        // 2 room --> 4,5
        int SecretCount = Mathf.Min(Mathf.FloorToInt(Mathf.Sqrt(Random.Range(1, 6))), PotentialSecret.Count); // this goes to 5

        Debug.Log(SecretCount + " Secret rooms chosen");
        foreach (var secret in PotentialSecret.GetRandom(SecretCount))
        {
            // we get random door
            // add a chest
            // remove it from door spawn
            GenPositionTile entry = temple.GetDoorableTiles(secret.GetAllTiles()).GetRandom();
            secret.AddDetail(entry.PositionG.x, entry.PositionG.y,
                             new GenDetail()
            {
                Char = '*', Entity = GenDetail.EntityType.Door, Type = GenDetail.DetailType.Door
            });

            GenPositionTile myChest = secret
                                      .GetAllTiles()
                                      .Where(t => temple.IsInsideRoom(t.PositionG.x, t.PositionG.y, secret) && temple.IsCornerGR(t.PositionG.x, t.PositionG.y, secret))
                                      .ToList()
                                      .GetRandom();
            secret.AddDetails(myChest.PositionG.x, myChest.PositionG.y, GenTile.Copy(Chest));

            AutoFillRoom.Remove(secret);
            SecretRooms.Add(secret);
            NoAutoDoor.Add(secret);
        }
        // -----------
        Log(temple);
        if (Logging != null)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        // -----------

        // go through all other rooms and determin what they are

        foreach (GenRoom room in AutoFillRoom)
        {
            // -----------
            Log(temple);
            if (Logging != null)
            {
                yield return(new WaitForSeconds(0.25f));
            }
            // -----------

            // pillar hallway
            if (room.Height <= 7 && room.Height >= 5 && room.Width > 6)
            {
                // potential horizontal hallway
                if (Random.value < 0.4f)
                {
                    // hallway confirmed
                    // left to right

                    GenTile[,] p = new GenTile[, ]
                    {
                        { GenTile.Copy(pillar) }
                    };
                    int spacing = Random.Range(2, 5);

                    int tmpX = room.Outer.MinX + spacing;
                    int tmpY = room.Outer.MinY + 1;


                    p = GenUtil.GetSymetry(p, ref tmpX, ref tmpY, room, GenUtil.Axis.Vertical);

                    while (temple.IsInsideRoom(tmpX, tmpY, room))
                    {
                        room.PlaceDetailsAt(tmpX, tmpY, p);

                        tmpX = tmpX + spacing;
                    }
                    int enemyCount = Random.Range(0, 4);
                    for (int i = 0; i < enemyCount; i++)
                    {
                        SpawnEnemy(temple, room);
                    }
                    int itemCount = Random.Range(-1, 3);
                    for (int i = 0; i < itemCount; i++)
                    {
                        SpawnItem(temple, room, true);
                    }
                    int chestCount = Random.Range(-2, 2);
                    for (int i = 0; i < chestCount; i++)
                    {
                        SpawnChest(temple, room, true);
                    }
                    continue;
                }
            }
            if (room.Width <= 7 && room.Width >= 5 && room.Height > 6)
            {
                // potential horizontal hallway
                if (Random.value < 0.4f)
                {
                    // hallway confirmed
                    // left to right

                    GenTile[,] p = new GenTile[, ]
                    {
                        { GenTile.Copy(pillar) }
                    };
                    int spacing = Random.Range(2, 5);

                    int tmpX = room.Outer.MinX + 1;
                    int tmpY = room.Outer.MinY + spacing;


                    p = GenUtil.GetSymetry(p, ref tmpX, ref tmpY, room, GenUtil.Axis.Horizontal);

                    while (temple.IsInsideRoom(tmpX, tmpY, room))
                    {
                        room.PlaceDetailsAt(tmpX, tmpY, p);

                        tmpY = tmpY + spacing;
                    }
                    int enemyCount = Random.Range(0, 4);
                    for (int i = 0; i < enemyCount; i++)
                    {
                        SpawnEnemy(temple, room);
                    }
                    int itemCount = Random.Range(-1, 3);
                    for (int i = 0; i < itemCount; i++)
                    {
                        SpawnItem(temple, room, true);
                    }
                    int chestCount = Random.Range(-2, 2);
                    for (int i = 0; i < chestCount; i++)
                    {
                        SpawnChest(temple, room, true);
                    }
                    continue;
                }
            }

            if (room.Height >= 8 && room.Width >= 8)
            {
                // can either be pillar spam or room in room

                if (Random.value < 0.6f)
                {
                    if (Random.value < 0.7f && room.Width % 2 == 1 && room.Height % 2 == 1)
                    {
                        // pillar spam

                        for (int x = 2; x < room.Width - 2; x += 2)
                        {
                            for (int y = 2; y < room.Height - 2; y += 2)
                            {
                                room.AddDetails(room.PosX + x, room.PosY + y, GenTile.Copy(pillar));
                            }
                        }
                        int enemyCount = Random.Range(0, 5);
                        for (int i = 0; i < enemyCount; i++)
                        {
                            SpawnEnemy(temple, room);
                        }
                        int itemCount = Random.Range(-1, 3);
                        for (int i = 0; i < itemCount; i++)
                        {
                            SpawnItem(temple, room, true);
                        }
                        int chestCount = Random.Range(-3, 3);
                        for (int i = 0; i < chestCount; i++)
                        {
                            SpawnChest(temple, room, true);
                        }
                    }
                    else
                    {
                        // room in room

                        // find where to put the inner room
                        temple.TryGrowRect(room.Inner.GetCenter().x, room.Inner.GetCenter().y, 100, 100, out GenRect InnerSize);


                        if (InnerSize.WidthT >= 4 && InnerSize.HeightT >= 4)
                        {
                            if (InnerSize.WidthT >= 10 || InnerSize.HeightT >= 10)
                            {
                                if (Mathf.Abs(InnerSize.WidthT - InnerSize.HeightT) > 3)
                                {
                                    // we want to divide
                                    if (InnerSize.WidthT > InnerSize.HeightT)
                                    {
                                        // divide left and right
                                        int singleWidth = InnerSize.WidthT / 2 - 2;
                                        // left
                                        GenRect LeftRoom = new GenRect(InnerSize.MinX, InnerSize.MinX + singleWidth, InnerSize.MinY, InnerSize.MaxY);
                                        // right
                                        GenRect RightRoom = new GenRect(InnerSize.MaxX - singleWidth, InnerSize.MaxX, InnerSize.MinY, InnerSize.MaxY);

                                        GenRoom left = GenRoom.Sized(LeftRoom.WidthT, LeftRoom.HeightT);
                                        left.FillFloor();
                                        left.SpacePriority = 4;
                                        GenRoom right = GenRoom.Sized(RightRoom.WidthT, RightRoom.HeightT);
                                        right.FillFloor();
                                        right.SpacePriority = 4;
                                        temple.PlaceRoom(LeftRoom.MinX, LeftRoom.MinY, left);
                                        temple.PlaceRoom(RightRoom.MinX, RightRoom.MinY, right);

                                        NoAutoDoor.Add(left);
                                        NoAutoDoor.Add(right);

                                        temple.EdgeWalls('#', left);
                                        temple.EdgeWalls('#', right);

                                        temple.FixOverlap();
                                        // -----------
                                        Log(temple);
                                        if (Logging != null)
                                        {
                                            yield return(new WaitForSeconds(0.25f));
                                        }
                                        // -----------

                                        var leftDoor  = temple.GetDoorableTiles(left.GetAllTiles()).GetRandom(1);
                                        var rightDoor = temple.GetDoorableTiles(right.GetAllTiles()).GetRandom(1);

                                        for (int i = 0; i < leftDoor.Count; i++)
                                        {
                                            left.AddDetails(leftDoor[i].PositionG.x, leftDoor[i].PositionG.y, GenTile.Copy(Door));
                                        }
                                        for (int i = 0; i < rightDoor.Count; i++)
                                        {
                                            right.AddDetails(rightDoor[i].PositionG.x, rightDoor[i].PositionG.y, GenTile.Copy(Door));
                                        }
                                        SpawnItem(temple, left);
                                        SpawnItem(temple, right);
                                        if (Random.value < 0.4f)
                                        {
                                            SpawnItem(temple, right);
                                        }
                                        if (Random.value < 0.4f)
                                        {
                                            SpawnItem(temple, left);
                                        }
                                        if (Random.value < 0.2f)
                                        {
                                            SpawnChest(temple, left, true);
                                        }
                                        if (Random.value < 0.2f)
                                        {
                                            SpawnChest(temple, left, true);
                                        }
                                    }
                                    else
                                    {
                                        // divide top bot
                                        Debug.Log("currently not implemented, sorry");
                                    }
                                }
                            }
                            else
                            {
                                // one single room
                                if (InnerSize.WidthT > 5)
                                {
                                    InnerSize = InnerSize.Transform(-1, 0, -1, 0);
                                }
                                if (InnerSize.HeightT > 5)
                                {
                                    InnerSize = InnerSize.Transform(0, -1, 0, -1);
                                }

                                Debug.Log("HERE");

                                GenRoom single = GenRoom.Sized(InnerSize.WidthT, InnerSize.HeightT);
                                single.SpacePriority = 4;
                                single.FillFloor();
                                NoAutoDoor.Add(single);

                                temple.PlaceRoom(InnerSize.MinX, InnerSize.MinY, single);
                                temple.EdgeWalls('#', single);
                                temple.FixOverlap();
                                // -----------
                                Log(temple);
                                if (Logging != null)
                                {
                                    yield return(new WaitForSeconds(0.25f));
                                }
                                // -----------



                                // double doors
                                var doorables = single.GetAllTiles();// single.GetEdge().ToList();
                                var theDoors  = temple.GetDoorableTiles(doorables).GetRandom(2);

                                for (int i = 0; i < theDoors.Count; i++)
                                {
                                    single.AddDetails(theDoors[i].PositionG.x, theDoors[i].PositionG.y, GenTile.Copy(Door));
                                }

                                SpawnItem(temple, single);

                                if (Random.value < 0.2f)
                                {
                                    SpawnChest(temple, single, true);
                                }
                                if (Random.value < 0.2f)
                                {
                                    SpawnChest(temple, single, true);
                                }
                            }
                        }

                        SpawnEnemy(temple, room);
                        if (Random.value < 0.5f)
                        {
                            SpawnEnemy(temple, room);
                        }
                        if (Random.value < 0.2f)
                        {
                            SpawnEnemy(temple, room);
                        }
                    }
                    continue;
                }
            }
            // something random
            //room.FillFloor('~');

            SpawnEnemy(temple, room);
            SpawnEnemy(temple, room);

            if (Random.value < 0.5f)
            {
                SpawnEnemy(temple, room);
            }
            if (Random.value < 0.2f)
            {
                SpawnEnemy(temple, room);
            }
            SpawnItem(temple, room);
            if (Random.value < 0.3f)
            {
                SpawnItem(temple, room);
            }
            if (Random.value < 0.3f)
            {
                SpawnItem(temple, room);
            }
            if (Random.value < 0.4f)
            {
                SpawnChest(temple, room);
            }
            if (Random.value < 0.1f)
            {
                SpawnChest(temple, room);
            }
        }


        List <GenRoom> RequireDoor = new List <GenRoom>(temple.Rooms);

        foreach (var doo in NoAutoDoor)
        {
            RequireDoor.Remove(doo);
        }
        List <GenRoom> DoorIteration = new List <GenRoom>(RequireDoor);
        GenRoom        start         = EntryHall;

        Dictionary <GenRoom, List <GenRoom> > adj = temple.GetAdjacentRoomMap();

        void RandomDoorTo(GenRoom a, GenRoom b)
        {
            var tiles    = temple.GetDoorableTiles(temple.GetConnectingTiles(a, b));
            var location = tiles.GetRandom();

            a.AddDetails(location.PositionG.x, location.PositionG.y, GenTile.Copy(Door));
        }

        while (RequireDoor.Count > 0)
        {
            DoorIteration.Clear();
            DoorIteration.AddRange(RequireDoor);
            foreach (var room in DoorIteration)
            {
                if (temple.IsReachable(start, room))
                {
                    // reachable so we dont have to do a thing
                    RequireDoor.Remove(room);
                }
                else
                {
                    // place random door
                    var available = adj[room];
                    RandomDoorTo(room, available.GetRandom());
                }
                // -----------
                Log(temple);
                if (Logging != null)
                {
                    yield return(new WaitForSeconds(0.1f));
                }

                // -----------
            }
        }


        foreach (var room in adj[Spam].GetRandom(2))
        {
            RandomDoorTo(Spam, room);
        }

        Log(temple);
        Debug.Log("Done");


        LastOutput = GenUtil.Print(temple, false);
        Done?.Invoke();
    }
Ejemplo n.º 18
0
        //public static GLPrimitive ExtractPrimitive(ref VoidPtr address, EntrySize entryInfo, GLPolygon parent, ushort[] nodeBuffer, ref int nodeIndex)
        //{
        //Top:
        //    PrimitiveHeader* header = (PrimitiveHeader*)address;
        //    GLPrimitiveType type;
        //    switch (header->Type)
        //    {
        //        case WiiPrimitiveType.PosMtx: //0x20
        //            {
        //                if (*(bushort*)header->Data == 0xB000)
        //                    nodeIndex = 0;
        //                nodeBuffer[nodeIndex++] = header->Entries;

        //                //nodeBuffer[(*(bushort*)header->Data - 0xB000) / 0x0C] = header->Entries;
        //                address += 5;
        //                goto Top;
        //            }
        //        case WiiPrimitiveType.NorMtx: //0x28
        //        case WiiPrimitiveType.TexMtx: //0x30
        //        case WiiPrimitiveType.LightMtx: //0x38
        //            { address += 5; goto Top; }
        //        case WiiPrimitiveType.Lines: { type = GLPrimitiveType.Lines; break; } //0xA8
        //        case WiiPrimitiveType.LineStrip: { type = GLPrimitiveType.LineStrip; break; } //0xB0
        //        case WiiPrimitiveType.Points: { type = GLPrimitiveType.Points; break; } //0xB8
        //        case WiiPrimitiveType.Quads: { type = GLPrimitiveType.Quads; break; } //0x80
        //        case WiiPrimitiveType.TriangleFan: { type = GLPrimitiveType.TriangleFan; break; } //0xA0
        //        case WiiPrimitiveType.Triangles: { type = GLPrimitiveType.Triangles; break; } //0x90
        //        case WiiPrimitiveType.TriangleStrip: { type = GLPrimitiveType.TriangleStrip; break; } //0x98
        //        default:
        //            return null;
        //    }

        //    GLPrimitive primitive = new GLPrimitive();
        //    primitive._type = type;
        //    primitive._elements = header->Entries;
        //    primitive._parent = parent;

        //    int entries = primitive._elements;
        //    int stride = entryInfo._totalLen;
        //    VoidPtr data = header->Data;

        //    //Weight indices
        //    primitive._nodeIndices = ParseWeights(data, entries, entryInfo._extraLen, stride, nodeBuffer);
        //    data += entryInfo._extraLen;

        //    //Vertex Data
        //    primitive._vertexIndices = ParseIndices(data, entries, entryInfo._vertexLen, stride);
        //    data += entryInfo._vertexLen;

        //    //Normal Data
        //    primitive._normalIndices = ParseIndices(data, entries, entryInfo._normalLen, stride);
        //    data += entryInfo._normalLen;

        //    //Color Data
        //    for (int i = 0; i < 2; data += entryInfo._colorLen[i++])
        //        primitive._colorIndices[i] = ParseIndices(data, entries, entryInfo._colorLen[i++], stride);

        //    //UV Data
        //    for (int i = 0; i < 8; data += entryInfo._uvLen[i++])
        //        primitive._uvIndices[i] = ParseIndices(data, entries, entryInfo._uvLen[i], stride);

        //    address += (entryInfo._totalLen * entries) + 3;

        //    return primitive;
        //}

        private static Primitive ExtractPrimitive(ref VoidPtr address, EntrySize entryInfo, ushort[] nodeBuffer, ref int nodeIndex)
        {
Top:
            PrimitiveHeader * header = (PrimitiveHeader *)address;
            GLPrimitiveType type;

            switch (header->Type)
            {
            case WiiPrimitiveType.PosMtx:     //0x20
            {
                if (*(bushort *)header->Data == 0xB000)
                {
                    nodeIndex = 0;
                }
                nodeBuffer[nodeIndex++] = header->Entries;

                //nodeBuffer[(*(bushort*)header->Data - 0xB000) / 0x0C] = header->Entries;
                address += 5;
                goto Top;
            }

            case WiiPrimitiveType.NorMtx:     //0x28
            case WiiPrimitiveType.TexMtx:     //0x30
            case WiiPrimitiveType.LightMtx:   //0x38
            { address += 5; goto Top; }

            case WiiPrimitiveType.Lines: { type = GLPrimitiveType.Lines; break; }                 //0xA8

            case WiiPrimitiveType.LineStrip: { type = GLPrimitiveType.LineStrip; break; }         //0xB0

            case WiiPrimitiveType.Points: { type = GLPrimitiveType.Points; break; }               //0xB8

            case WiiPrimitiveType.Quads: { type = GLPrimitiveType.Quads; break; }                 //0x80

            case WiiPrimitiveType.TriangleFan: { type = GLPrimitiveType.TriangleFan; break; }     //0xA0

            case WiiPrimitiveType.Triangles: { type = GLPrimitiveType.Triangles; break; }         //0x90

            case WiiPrimitiveType.TriangleStrip: { type = GLPrimitiveType.TriangleStrip; break; } //0x98

            default:
                return(null);
            }

            Primitive primitive = new Primitive();

            primitive._type = type;

            int     entries = primitive._elementCount = header->Entries;
            int     stride  = entryInfo._totalLen;
            VoidPtr data    = header->Data;

            //Weight indices
            primitive._weightIndices = ParseWeights(data, entries, entryInfo._extraLen, stride, nodeBuffer);
            data += entryInfo._extraLen;

            //Vertex Data
            primitive._vertexIndices = ParseIndices(data, entries, entryInfo._vertexLen, stride);
            data += entryInfo._vertexLen;

            //Normal Data
            primitive._normalIndices = ParseIndices(data, entries, entryInfo._normalLen, stride);
            data += entryInfo._normalLen;

            //Color Data
            for (int i = 0; i < 2; data += entryInfo._colorLen[i++])
            {
                primitive._colorIndices[i] = ParseIndices(data, entries, entryInfo._colorLen[i], stride);
            }

            //UV Data
            for (int i = 0; i < 8; data += entryInfo._uvLen[i++])
            {
                primitive._uvIndices[i] = ParseIndices(data, entries, entryInfo._uvLen[i], stride);
            }

            address += (entryInfo._totalLen * entries) + 3;

            return(primitive);
        }
Ejemplo n.º 19
0
 public NumericUnsignedEntry(List <Entry> list, bool is32bit, string name, int offset, EntrySize size)
     : base(list, is32bit, name, offset, size)
 {
 }
Ejemplo n.º 20
0
 public NumericEntry(string name, int offset, EntrySize size)
 {
     this.name   = name;
     this.offset = offset;
     this.size   = size;
 }
Ejemplo n.º 21
0
 public NumericEntry(EntrySize size)
 {
     this.size = size;
 }